
Servizio XPC macOS/iOS simulato vulnerabile alla deserializzazione di NSKeyedUnarchiver, con dimostrazione dell'exploit e payload plist ad hoc per RCE tramite deserializzazione non sicura.
#!/usr/bin/env python3
# vulnerable_xpc_service.py - Simulated XPC service using unsafe plist deserialization
import plistlib, subprocess, socketserver, struct
# Mach message simulation: we just accept a binary plist over TCP.
class XPCHandler(socketserver.BaseRequestHandler):
def handle(self):
raw = self.request.recv(4096)
# Insecure: using plistlib.loads on untrusted data without sanitization
plist_data = plistlib.loads(raw) # In real macOS, NSKeyedUnarchiver can execute code
# Simulate a command being embedded in the plist
command = plist_data.get("runCommand")
if command:
subprocess.Popen(command, shell=True)
self.request.sendall(b"Success")
server = socketserver.TCPServer(('localhost', 8888), XPCHandler)
print("Vulnerable XPC service on :8888")
server.serve_forever()
Un servizio XPC su macOS/iOS deserializza i messaggi Mach in arrivo utilizzando NSKeyedUnarchiver senza una allowlist di codifica sicura. Un attaccante può creare un grafo di oggetti serializzato che esegue codice arbitrario al momento della deserializzazione.
NSKeyedUnarchiver viene utilizzato con dati non attendibili e senza whitelist di classi, consentendo l'istanziazione di oggetti che innescano l'esecuzione di codice (ad es., NSInvocation).python vulnerable_xpc_service.py
python exploit_xpc.py