Exploit database

GH-902802652dcfaa7c26490b7d67facd72

martinfabianionut/cve-2025-55315

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-55315

7 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files4
martinfabianionut/cve-2025-55315Revision b61acbedb054

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

PythonProxy/proxy_server.py

Suggested starting filePython · 4,265 bytes
import socket
import threading
import os

TARGET_HOST = os.getenv('TARGET_HOST', 'unsafe-api')  # Docker service name
TARGET_PORT = int(os.getenv('TARGET_PORT', '5001'))
PROXY_LISTEN_PORT = int(os.getenv('PROXY_LISTEN_PORT', '5027'))

BUFFER_SIZE = 4096


def log(msg):
    print(f'[Proxy LOG] {msg}')

def forbidden_response():
    body = b"Access to /passwords/admin is forbidden.\n"
    resp = (
        b"HTTP/1.1 403 Forbidden\r\n"
        b"Content-Type: text/plain\r\n"
        b"Content-Length: " + str(len(body)).encode() + b"\r\n"
        b"\r\n" + body
    )
    return resp



def handle_client(client_sock):
    request = b""
    while b"\r\n\r\n" not in request:
        data = client_sock.recv(BUFFER_SIZE)
        if not data:
            client_sock.close()
            return
        request += data

    try:
        headers, rest = request.split(b"\r\n\r\n", 1)
        headers_str = headers.decode("iso-8859-1")
        lines = headers_str.split("\r\n")
        first_line = lines[0]
        method, path, proto = first_line.split()
        headers_dict = {
            k.lower(): v for line in lines[1:]
            if ":" in line and (k:=line.split(":",1)[0].strip()) and (v:=line.partition(":")[2].strip())
        }

        log(f"Received request: {method} {path}")
        log(f"Headers: {headers_dict}")

        # BLOCK /passwords/admin (no backend connection)
        if path == "/passwords/admin":
            log("🚫 Blocked request to /passwords/admin, sending 403 Forbidden.")
            client_sock.sendall(forbidden_response())
            client_sock.close()
            return

        cl = int(headers_dict.get('content-length', '0'))
        te = headers_dict.get('transfer-encoding', '').lower()
        log(f"Content-Length: {cl}, Transfer-Encoding: {te}")

        use_content_length = bool(cl) and te

        # FAVOR Content-Length if both present (bad practice!)
        if use_content_length:
            log("⚠️  Both Content-Length and Transfer-Encoding found. FAVORING Content-Length over Transfer-Encoding! (Vulnerable behavior)")
            body = rest
            while len(body) < cl:
                body += client_sock.recv(BUFFER_SIZE)
            all_data = headers + b"\r\n\r\n" + body[:cl]
            log(f"Forwarding {cl} bytes of body (Content-Length): {repr(body[:cl][:50])}...")
        elif te.startswith("chunked"):
            log("Parsing as Transfer-Encoding: chunked")
            body = rest
            while b'0\r\n\r\n' not in body:
                chunk = client_sock.recv(BUFFER_SIZE)
                if not chunk:
                    break
                body += chunk
            all_data = headers + b"\r\n\r\n" + body
            log(f"Forwarding chunked body (first 50 bytes): {repr(body[:50])}...")
        else:
            log("No/other body encoding. Forwarding as received.")
            all_data = request

    except Exception as e:
        log(f"Error parsing request: {e}")
        client_sock.close()
        return

    # --- Forward to backend ---
    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_sock:
            server_sock.connect((TARGET_HOST, TARGET_PORT))
            server_sock.sendall(all_data)
            while True:
                reply = server_sock.recv(BUFFER_SIZE)
                if not reply:
                    break
                client_sock.sendall(reply)
            log(f"Response proxied back to client.")
    except Exception as e:
        log(f"Error forwarding to backend: {e}")

    client_sock.close()

def main():
    print(f"Proxy listening on 0.0.0.0:{PROXY_LISTEN_PORT}, forwarding to {TARGET_HOST}:{TARGET_PORT} (favoring Content-Length over Transfer-Encoding!)")
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listen_sock:
        listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen_sock.bind(('0.0.0.0', PROXY_LISTEN_PORT))
        listen_sock.listen(5)
        while True:
            client_sock, addr = listen_sock.accept()
            log(f"Accepted connection from {addr}")
            t = threading.Thread(target=handle_client, args=(client_sock,))
            t.daemon = True
            t.start()

if __name__ == "__main__":
    main()