diff --git a/.github/workflows/nginx-http2-linux.yml b/.github/workflows/nginx-http2-linux.yml new file mode 100644 index 0000000..5ce40bd --- /dev/null +++ b/.github/workflows/nginx-http2-linux.yml @@ -0,0 +1,72 @@ +name: nginx (CVE-2026-123007, CVE-2026-123633, CVE-2026-123634) bash detector + +on: + push: + paths: + - "CVE-2026-123633.CVE-2026-123007/linux/**" + - ".github/workflows/nginx-http2-linux.yml" + pull_request: + paths: + - "CVE-2026-123633.CVE-2026-123007/linux/**" + - ".github/workflows/nginx-http2-linux.yml" + workflow_dispatch: + +permissions: + contents: read + +env: + DIR: CVE-2026-123633.CVE-2026-123007/linux + # Pinned by digest. nginx:1.30.6 / 1.30.6-alpine are the last releases + # before the fix; the distro images get nginx from their own repositories. + IMG_ORG: nginx@sha256:42c68eab6f7e22611786a9fe1d1c019e275c50185bd54b8f75dc2b9184322703 + IMG_ALPINE: nginx@sha256:901e593c95dc85f5a729f5765516321366ef4ac401821431d408897e95287d0a + IMG_OPENRESTY: openresty/openresty@sha256:8dddb7eef46975651752294138269b2c450ce89d1810113997df254725f5fa9a + IMG_DEBIAN: debian@sha256:9c6e381421d0f48d1b8133e573f33c185ee16cbf505eda9c4a8a4791b25ea8a6 + IMG_UBUNTU: ubuntu@sha256:73b999393d07f2bf65a40373778a44dc9a6d54ad7718d29247d8ff9413c4d6a8 + IMG_ALMA: almalinux@sha256:02df05719ef287ebd0df0a1eedb9172a00bd70703aed7b25660e426b8e0d6047 + +jobs: + shellcheck: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: shellcheck + run: >- + shellcheck -S warning + "$DIR/detect-nginx-http2.sh" "$DIR/ssh-nginx-http2.sh" + "$DIR/tests/run-tests.sh" "$DIR/tests/fake-nginx" + + test-linux: + name: bash on ${{ matrix.os }} (with Docker) + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, ubuntu-22.04] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Pull container images + run: | + for i in "$IMG_ORG" "$IMG_ALPINE" "$IMG_OPENRESTY" "$IMG_DEBIAN" "$IMG_UBUNTU" "$IMG_ALMA"; do + docker pull -q "$i" + done + - name: Run tests + run: ./"$DIR"/tests/run-tests.sh + + # macOS ships bash 3.2; the decision-logic tests run there without Docker. + test-macos: + name: bash 3.2 on macos-latest + runs-on: macos-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Run tests + run: /bin/bash "$DIR/tests/run-tests.sh" --no-docker diff --git a/CVE-2026-123633.CVE-2026-123007/README.md b/CVE-2026-123633.CVE-2026-123007/README.md new file mode 100644 index 0000000..13b1eaf --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/README.md @@ -0,0 +1,310 @@ +# CVE-2026-123007, CVE-2026-123633 and CVE-2026-123634 (nginx) detection + +Fleet checks for three nginx worker memory-corruption bugs that were fixed +together in nginx 1.30.7 and 1.31.9 on 2026-11-18. Each one is reached +through a feature the config has to turn on: + +| CVE | nginx.org title | Severity (nginx.org) | Feature | Affected | Fixed | +|---|---|---|---|---|---| +| CVE-2026-123007 | Memory corruption in HTTP/2 flow control | major | HTTP/2 | 1.9.5-1.31.8 | 1.30.7+, 1.31.9+ | +| CVE-2026-123633 | Use-after-free in HTTP/2 | medium | HTTP/2 | 1.19.7-1.31.8 | 1.30.7+, 1.31.9+ | +| CVE-2026-123634 | Use-after-free during response processing in resolver | medium | `resolver` | 0.6.18-1.31.8 | 1.30.7+, 1.31.9+ | + +**The HTTP/2 pair.** Wiz rates both CVSS 4.0 9.2 and shows remote code +execution in a worker process. +- CVE-2026-123007 is a send-window overflow reached with many + `WINDOW_UPDATE` frames. Wiz tested it over TLS on 64-bit builds. +- CVE-2026-123633 is a use-after-free that occurs when `worker_connections` + run out. Wiz says it is easiest to exploit in reverse-proxy setups. + +**The resolver bug.** CVE-2026-123634 is not in the Wiz write-up. The nginx +changelog says that "if the "resolver" directive was used and the same name +was simultaneously resolved in subrequests", a worker can use memory after +freeing it. The stated impact is a segmentation fault in a worker process, +"or might have potential other impact". Turning HTTP/2 off does nothing for +this one; it needs an upgrade. + +The same releases fix seven other CVEs, including CVE-2026-121810, a similar +use-after-free in HTTP/3. These scripts check only the three CVEs above; see +the nginx.org advisories page for the others. + +## Directory contents + +`linux/` holds bash scripts for Linux and macOS hosts. + +| File | Purpose | +|---|---| +| `linux/detect-nginx-http2.sh` | Host detector (bash 3.2+). The name predates CVE-2026-123634; it checks all three CVEs. | +| `linux/ssh-nginx-http2.sh` | Fleet run over plain SSH | +| `linux/k8s-nginx-http2.yaml` | Fleet run as a privileged Kubernetes DaemonSet | + +The SSH wrapper finds the detector next to itself, so keep the files +together. `linux/tests/` holds the maintainers' test harness. It is not needed +to run any script. + +## What counts as impacted + +A CVE applies to an nginx when its version, backport and feature checks all +show `[!]`. An nginx is impacted when at least one CVE applies, and the +result line lists the CVEs that do (`=> [!] impacted: CVE-2026-123634`). + +1. **version**: `nginx -V` reports a version that has at least one of the bugs. + - nginx open source: from 0.6.18 (CVE-2026-123634), 1.9.5 + (CVE-2026-123007) or 1.19.7 (CVE-2026-123633), through 1.31.8. 1.30.7 + and later 1.30.x releases are fixed. + - NGINX Plus (read from `(nginx-plus-r...)` in the version string): + - R-series (R36 and earlier): affected; no R-series fix exists. + - PLS.37.0.x LTS: all three before 37.0.7; CVE-2026-123007 and + CVE-2026-123634 in 37.0.7; fixed from 37.0.8. + - PLS.37.x CR: all three in 37.1.x; CVE-2026-123007 and CVE-2026-123634 + in 37.2.x; fixed from 37.3.0. + - 38 and later: not affected. + - OpenResty: judged on its nginx core (`openresty/1.27.1.2` → 1.27.1). A + fixed core is `OK`; an affected core is `[?]`, because OpenResty may ship + its own patches. + - Angie, Tengine, freenginx and other forks: always `[?]`; check the + vendor's advisory. +2. **backport**: the package that owns the binary records no fix. Debian, + Ubuntu and RHEL-family vendors patch without changing the upstream version + and name each CVE in the package changelog. The script looks for each CVE + ID separately, so a package that fixes some of them is still checked for + the rest: + - **dpkg:** `/usr/share/doc//changelog.Debian.gz`. + - **rpm:** `rpm -q --changelog`. + - **Alpine:** apk packages have no changelog on disk. A vendor Alpine + package is `[?]`; check [secdb](https://secdb.alpinelinux.org). + - **Judged on version alone:** binaries no package owns, nginx.org + packages (maintainer "NGINX Packaging", Debian, RPM or Alpine), and + NGINX Plus. + + If the package on disk carries a fix but a running master still runs the + binary it replaced, the result is `[!]` with "restart nginx". +3. **feature**: the config uses what the bug is in. + - **http/2** (CVE-2026-123007, CVE-2026-123633): the binary was built with + `--with-http_v2_module`, and HTTP/2 is on for at least one server: + - the `http2` parameter of a `listen` directive, or + - `http2 on;` in that `server {}`, or inherited from `http {}`. + + A server with `http2 off;` does not inherit an `http`-level `http2 on;`. + - **resolver** (CVE-2026-123634): a `resolver` directive anywhere in + `http {}`: at the `http`, `server` or `location` level, or in an + `upstream` block (1.27.3+). Resolvers in `stream {}` and `mail {}` do not + count, because the bug needs HTTP subrequests. Subrequests come from many + modules (`auth_request`, SSI, `mirror`, `slice`, `addition`, njs, Lua), + so the script does not try to rule them out: a configured resolver counts + as exposed. + +The script reads the config files itself, starting at the master's `-c` file +(or the binary's built-in `--conf-path`) and following `include` directives, +globs and symlinks. It skips comments, quoted strings and the Lua code in +`*_by_lua_block` blocks. It does **not** run `nginx -t`/`nginx -T`, so it +needs no TLS keys, does not resolve upstream hostnames, and writes nothing. +The only command it runs from an nginx install is `nginx -V`. Inside a +container, rpm-based images are an exception: the script runs the container's +own `rpm` to read the package changelog. + +The config files on disk are what nginx loads on its next reload. If someone +edited them without reloading, the running config may differ. + +## Output + +``` +nginx check: CVE-2026-123007, CVE-2026-123633 (HTTP/2) and CVE-2026-123634 (resolver) +legend: [!] impacted | OK not impacted | [?] could not check | n/a not checked +checks: version, backport, then http/2 (CVE-2026-123007, CVE-2026-123633) or resolver (CVE-2026-123634). + A CVE applies only if version, backport and its own check all show [!]. +host: Linux x86_64 + +/usr/sbin/nginx (pid 812) + version: nginx/1.24.0 (Ubuntu): CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 [!] + backport: nginx 1.24.0-2ubuntu7.19 (dpkg), changelog does not list CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 [!] + http/2: on, listen 443 ssl http2 (/etc/nginx/sites-enabled/default) [!] + resolver: not set (/etc/nginx/nginx.conf) OK + => [!] impacted: CVE-2026-123007 CVE-2026-123633 + +/usr/sbin/nginx (pid 40211, container web-6c9f7d8b5-x2x7q) + version: nginx/1.30.6: CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 [!] + backport: nginx 1.30.6-1~trixie (dpkg), nginx.org package: fixed only by upgrading [!] + http/2: off (/etc/nginx/nginx.conf) OK + resolver: on, resolver 10.96.0.10 valid=10s (/etc/nginx/conf.d/default.conf) [!] + => [!] impacted: CVE-2026-123634 + +impacted +``` + +Each nginx instance gets one block. Each check ends in one of four markers: + +- `[!]`: points to impacted. +- `OK`: rules this instance out. +- `[?]`: could not check. +- `n/a`: not checked, because no open CVE depends on it. For example, the + feature checks are `n/a` once the version or the backport rules out every + CVE they gate. + +The title line names the binary and where it came from: + +- `installed`: found on disk, not running. +- `pid N`: a running master process. +- `container `: a master in a container. In Kubernetes the hostname + is the pod name; in Docker it is the short container ID. +- `-n`: a binary passed on the command line. + +The http/2 and resolver lines name the file and directive that turned the +feature on. `-q` prints only the verdict line. + +## Exit codes + +| Code | Last line | Meaning | +|---|---|---| +| 0 | `not impacted` | no CVE applies to any nginx, or no nginx was found | +| 1 | `impacted` | at least one CVE applies to at least one nginx | +| 2 | `unknown` | at least one nginx could not be evaluated and none is impacted | +| 3 | (usage) | bad arguments | + +## Usage + +```sh +sudo ./linux/detect-nginx-http2.sh # per-instance blocks, then the verdict +sudo ./linux/detect-nginx-http2.sh -q # verdict only +./linux/detect-nginx-http2.sh -n /opt/app/sbin/nginx -c /opt/app/conf/nginx.conf +sudo ./linux/detect-nginx-http2.sh --no-disk # running instances only +``` + +Run as root. Without root, the script cannot read the master process (it +usually runs as root), containers, or root-only config files. Those instances +come out `[?]`. + +## Coverage + +| | bash (Linux) | bash (macOS) | +|---|---|---| +| nginx/openresty/angie on PATH and common install dirs | yes | yes (incl. Homebrew) | +| Running master processes, with their `-c`/`-p` | yes | yes | +| Masters in containers (Docker, containerd, Kubernetes pods) | yes, root + `nsenter` | no | +| Package backports: dpkg, rpm | yes (rpm in containers needs the container's `rpm`) | n/a | +| Running binary replaced on disk since start | detected; the old binary is checked through `/proc/PID/exe` | no | + +Not covered: +- Windows nginx builds. +- `-g` directives given on the command line. +- Configs generated at start-up that are not on disk. + +The scripts also do not reach managed services that run nginx for you, such +as cloud load balancers or a CDN. Check those vendors' advisories. + +### Kubernetes ingress + +`ingress-nginx` controller pods run nginx with HTTP/2 enabled by default and +set `resolver` to the cluster DNS, so expect the detector to report all three +CVEs for them. The DaemonSet below checks them like any other container. The +`kubernetes/ingress-nginx` project ended maintenance in March 2026 and +releases no security fixes +([Kubernetes blog](https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/)). +Turning HTTP/2 off does not cover CVE-2026-123634, so plan a migration rather +than waiting for an update. F5's NGINX Ingress Controller ships with NGINX +open source or NGINX Plus and follows their releases. + +## Fleet runs + +### SSH + +`ssh-nginx-http2.sh` runs the detector across Linux/macOS hosts with no Ansible +and nothing installed: `detect-nginx-http2.sh` is piped to each host's bash +over stdin and run there, so nothing is copied to or left on the target. + +```sh +sh linux/ssh-nginx-http2.sh hosts.txt results # one host or user@host per line +PARALLEL=20 sh linux/ssh-nginx-http2.sh hosts.txt +DETECT_ARGS="-q" sh linux/ssh-nginx-http2.sh hosts.txt # save just the verdict line +SUDO="" sh linux/ssh-nginx-http2.sh hosts.txt # run as the login user (less coverage) +``` + +It needs key-based SSH and, for full coverage, passwordless sudo and bash on +the targets. +- Each host's output goes to `results/.txt`. +- The per-host exit code is the verdict (`0/1/2`, or `255`/other for an SSH + failure). A `0/1/2` counts only when the detector's last line agrees with + it; otherwise the host is an error. sudo and the remote shell also exit `1` + when they fail (for example `sudo: a password is required`), and that + would otherwise read as impacted. +- A roll-up of impacted / unknown / not impacted / error hosts prints at the + end. +- The wrapper exits `1` if any host is impacted, else `2` if any host is + unknown or errored, else `0`. + +### Kubernetes + +`k8s-nginx-http2.yaml` is a DaemonSet: one pod per node, with `hostPID` and +`privileged`, so the detector checks every nginx on the node, including those +in other pods (through its own `nsenter` path, as root). Nothing is copied +into workloads. The detector is mounted from a ConfigMap: + +```sh +kubectl create namespace nginxh2 +kubectl -n nginxh2 create configmap detect --from-file=linux/detect-nginx-http2.sh +kubectl apply -f linux/k8s-nginx-http2.yaml +kubectl -n nginxh2 rollout status daemonset/nginxh2 +kubectl -n nginxh2 logs -l app=nginxh2 --tail=-1 --prefix --max-log-requests=500 +kubectl delete namespace nginxh2 +``` + +The pod is privileged by design. Review the manifest and delete the namespace +when you have your results. The base image installs `util-linux` (for +`nsenter`) at start; for air-gapped clusters, bake bash + util-linux + the +script into your own image. + +## Remediation + +1. **Upgrade.** This is the only fix that covers all three CVEs. + - Install nginx 1.30.7 / 1.31.9 or later, NGINX Plus PLS.37.0.8.1 LTS / + PLS.37.3.0.1 CR, or your distribution's patched package. + - Then make sure the old master is gone: a binary upgrade or a restart. + `nginx -s reload` alone does not replace the binary. + - Re-run the detector: a master still running a replaced binary is reported + with "restart nginx". +2. **Until you can upgrade, CVE-2026-123007 and CVE-2026-123633:** turn HTTP/2 + off. + - nginx 1.25.1 and later: set `http2 off;` in the affected `server` blocks + (or in `http {}`), and remove `http2` from every `listen` directive. + - Older versions: remove `http2` from every `listen` directive. + + Reload, confirm the old workers have exited, and re-run the detector: the + http/2 line names the file and directive it still finds. Clients fall back + to HTTP/1.1. gRPC proxying (`grpc_pass`) and any client that requires + HTTP/2 will stop working, so check those first. +3. **Until you can upgrade, CVE-2026-123634:** nginx publishes no workaround. + Removing every `resolver` directive avoids the bug only if nothing depends + on resolving names while nginx runs. These depend on it: + - `proxy_pass` (or `fastcgi_pass`, `grpc_pass` and similar) with a + variable in the address. + - `server ... resolve` in an upstream. + - OCSP stapling (`ssl_stapling`). + + Without a resolver, those fail. In most setups that use a resolver, + upgrading is the practical fix. + +## Sources + +- nginx.org security advisories: + + - CVE-2026-123007: "Vulnerable: 1.9.5-1.31.8. Not vulnerable: 1.31.9+, + 1.30.7+". + - CVE-2026-123633: "Vulnerable: 1.19.7-1.31.8. Not vulnerable: 1.31.9+, + 1.30.7+". + - CVE-2026-123634: "Vulnerable: 0.6.18-1.31.8. Not vulnerable: 1.31.9+, + 1.30.7+". +- Changelogs: `CHANGES` for 1.31.9 and `CHANGES-1.30` for 1.30.7, both dated + 18 Nov 2026. +- F5 advisories: K000163926 (CVE-2026-123007), K000163928 (CVE-2026-123633) + and K000163925 (CVE-2026-123634). +- NGINX Plus fix versions: the release notes at + . CVE-2026-123634 is listed under + PLS.37.0.8.1 LTS and PLS.37.3.0.1 CR. +- `resolver` contexts: the `ngx_http_core_module` and + `ngx_http_upstream_module` docs on nginx.org. +- Wiz Research write-up (HTTP/2 CVEs only): + . + +As of 2026-11-18, no Debian, Ubuntu or AlmaLinux package changelog listed any +of the three CVEs. When vendors ship fixes, the backport check picks them up +with no script change. diff --git a/CVE-2026-123633.CVE-2026-123007/linux/detect-nginx-http2.sh b/CVE-2026-123633.CVE-2026-123007/linux/detect-nginx-http2.sh new file mode 100755 index 0000000..284639a --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/linux/detect-nginx-http2.sh @@ -0,0 +1,971 @@ +#!/usr/bin/env bash +# +# detect-nginx-http2.sh +# +# Checks whether this host has an nginx exposed to three worker memory- +# corruption bugs fixed in nginx 1.30.7 and 1.31.9 (2026-11-18), each reached +# through a feature the config has to turn on: +# +# CVE-2026-123007 HTTP/2 flow-control window overflow nginx 1.9.5-1.31.8 +# CVE-2026-123633 HTTP/2 use-after-free when worker nginx 1.19.7-1.31.8 +# connections run out +# CVE-2026-123634 resolver use-after-free when the same nginx 0.6.18-1.31.8 +# name is resolved in subrequests +# +# All three are fixed in nginx 1.30.7+ (stable) and 1.31.9+ (mainline), and +# in NGINX Plus PLS.37.0.8.1 LTS / PLS.37.3.0.1 CR. (PLS.37.0.7.1 and +# PLS.37.2.0.1 fix CVE-2026-123633 only.) +# +# A CVE applies to an nginx when all three checks hold for it: +# 1. version The version is in the CVE's affected range. Forks with their +# own release numbers (Angie, Tengine, freenginx, and OpenResty +# on an affected core) are unknown: check the vendor. +# 2. backport The package that owns the binary records no fix for it. +# Debian, Ubuntu and RHEL-family packages keep the upstream +# version when they patch, and name the CVE in the package +# changelog. Binaries not owned by a package, nginx.org +# packages and NGINX Plus are judged on version alone. +# 3. exposure The config uses the feature the bug is in: +# http/2 (CVE-2026-123007, CVE-2026-123633) built with +# --with-http_v2_module, and "http2 on;" in http{} +# or server{}, or the http2 parameter of a listen +# directive. +# resolver (CVE-2026-123634) a "resolver" directive anywhere +# in http{}, including upstream{}. Subrequests, the +# other trigger, come from too many modules +# (auth_request, ssi, mirror, slice, njs, Lua) to +# rule out, so they are assumed. +# An nginx is impacted when at least one CVE applies. +# +# What gets checked: +# - every running nginx master process, including processes in containers +# (Linux, as root, through nsenter and /proc/PID/root) +# - nginx, openresty and angie on PATH and in common install directories +# - any binary passed with -n +# +# The script reads the config files itself, following include directives. +# It does not run "nginx -t" or "nginx -T", so it needs no TLS keys, no DNS +# for upstream names, and writes nothing. The only command it runs from an +# nginx install is "nginx -V". +# +# Exit codes, for fleet tooling: +# 0 not impacted +# 1 impacted: at least one CVE applies to at least one nginx +# 2 unknown: at least one nginx could not be evaluated and none is impacted +# 3 usage error +# +# The last line of output is always exactly one of: +# impacted | not impacted | unknown +# +# Works with bash 3.2 (macOS) and later. Run as root for full coverage of +# master processes, containers and root-only config files. + +set -u +set -f + +PROBE_TIMEOUT="${NGINX_HTTP2_PROBE_TIMEOUT:-15}" +CVE_WIN=CVE-2026-123007 +CVE_UAF=CVE-2026-123633 +CVE_RES=CVE-2026-123634 + +QUIET=0 +VERBOSE=0 +SCAN_PROCS=1 +SCAN_DISK=1 +EXTRA_BINS="" +EXTRA_CONF="" + +usage() { + cat <<'EOF' +usage: detect-nginx-http2.sh [-q] [-v] [-n /path/to/nginx]... [-c /path/to/nginx.conf] + [--no-procs] [--no-disk] + + -q, --quiet print only the verdict line + -v, --verbose print diagnostic detail + -n, --nginx PATH also check this nginx binary (repeatable) + -c, --conf PATH config file for installed (not running) and -n binaries; + default: the binary's built-in --conf-path + --no-procs skip running processes + --no-disk skip installed binaries on disk + +Exit: 0 not impacted, 1 impacted, 2 unknown, 3 usage error. +Env: NGINX_HTTP2_PROBE_TIMEOUT=15 (seconds allowed for each "nginx -V") +EOF +} + +while [ $# -gt 0 ]; do + case "$1" in + -q|--quiet) QUIET=1 ;; + -v|--verbose) VERBOSE=1 ;; + -n|--nginx) + [ $# -ge 2 ] || { usage >&2; exit 3; } + EXTRA_BINS="$EXTRA_BINS$2 +" + shift ;; + -c|--conf) + [ $# -ge 2 ] || { usage >&2; exit 3; } + EXTRA_CONF="$2" + shift ;; + --no-procs) SCAN_PROCS=0 ;; + --no-disk) SCAN_DISK=0 ;; + -h|--help) usage; exit 0 ;; + *) echo "unknown argument: $1" >&2; usage >&2; exit 3 ;; + esac + shift +done + +TMP=$(mktemp -d 2>/dev/null || mktemp -d -t nginxh2) || { echo unknown; exit 2; } +trap 'rm -rf "$TMP"' EXIT +: > "$TMP/cands" +: > "$TMP/procs" + +TO="" +if command -v timeout >/dev/null 2>&1; then + TO="timeout $PROBE_TIMEOUT" +elif command -v gtimeout >/dev/null 2>&1; then + TO="gtimeout $PROBE_TIMEOUT" +fi + +TAB=$(printf '\t') +US=$(printf '\037') + +N_IMPACTED=0 +N_UNKNOWN=0 +N_OK=0 + +say() { [ "$QUIET" -eq 1 ] || printf '%s\n' "$*"; } +dbg() { [ "$VERBOSE" -eq 1 ] && printf 'debug: %s\n' "$*" >&2; return 0; } + +tally() { + case "$1" in + impacted) N_IMPACTED=$((N_IMPACTED + 1)) ;; + unknown) N_UNKNOWN=$((N_UNKNOWN + 1)) ;; + *) N_OK=$((N_OK + 1)) ;; + esac +} + +# State -> marker. [!] impacted, OK not impacted, [?] unknown, n/a not checked. +mark() { + case "$1" in + impacted) echo "[!]" ;; + ok) echo "OK" ;; + unknown) echo "[?]" ;; + *) echo "n/a" ;; + esac +} + +# result_line STATE [CVES] +result_line() { + case "$1" in + impacted) say " => [!] impacted${2:+: $2}" ;; + ok) say " => OK" ;; + *) say " => [?] unknown" ;; + esac +} + +# One check line: name, value, state. +line() { say " $1: $2 $(mark "$3")"; } + +# An nginx that could not be probed: title, check name, value, state. +single() { + say "" + say "$1" + line "$2" "$3" "$4" + result_line "$4" + tally "$4" +} + +header() { + say "nginx check: $CVE_WIN, $CVE_UAF (HTTP/2) and $CVE_RES (resolver)" + say "legend: [!] impacted | OK not impacted | [?] could not check | n/a not checked" + say "checks: version, backport, then http/2 ($CVE_WIN, $CVE_UAF) or resolver ($CVE_RES)." + say " A CVE applies only if version, backport and its own check all show [!]." +} + +finish() { + if [ "$N_IMPACTED" -gt 0 ]; then + say "" + echo "impacted"; exit 1 + elif [ "$N_UNKNOWN" -gt 0 ]; then + say "" + echo "unknown"; exit 2 + fi + [ "$N_OK" -eq 0 ] && { say ""; say "no nginx found"; } + say "" + echo "not impacted"; exit 0 +} + +HOST_OS=$(uname -s) +IS_ROOT=0 +[ "$(id -u)" = 0 ] && IS_ROOT=1 + +# --- versions --------------------------------------------------------------- + +# "1.24.0", "1.27.1.2", "1.31.9-rc" -> sortable integer of the first three parts +ver_key() { + local v IFS=. + v=$(printf '%s' "$1" | sed 's/[^0-9.].*$//') + # shellcheck disable=SC2086 + set -- $v + echo $(( 10#${1:-0} * 1000000 + 10#${2:-0} * 1000 + 10#${3:-0} )) +} + +K_FIRST_RES=$(ver_key 0.6.18) # CVE-2026-123634 from here +K_FIRST_WIN=$(ver_key 1.9.5) # HTTP/2 module added; CVE-2026-123007 from here +K_FIRST_UAF=$(ver_key 1.19.7) # CVE-2026-123633 from here +K_FIXED_STABLE=$(ver_key 1.30.7) +K_NEXT_MAIN=$(ver_key 1.31.0) +K_FIXED_MAIN=$(ver_key 1.31.9) + +# from_base KEY -> the CVEs present in code based on that open source version, +# ignoring fixes. +from_base() { + local out="" + [ "$1" -ge "$K_FIRST_WIN" ] && out="$CVE_WIN" + [ "$1" -ge "$K_FIRST_UAF" ] && out="$out $CVE_UAF" + [ "$1" -ge "$K_FIRST_RES" ] && out="$out $CVE_RES" + echo "${out# }" +} + +# affected_oss VERSION -> CVEs nginx open source VERSION has, space separated. +affected_oss() { + local k + k=$(ver_key "$1") + if [ "$k" -ge "$K_FIXED_MAIN" ]; then echo ""; return; fi + if [ "$k" -ge "$K_FIXED_STABLE" ] && [ "$k" -lt "$K_NEXT_MAIN" ]; then echo ""; return; fi + from_base "$k" +} + +# affected_plus TAG BASE -> CVEs, or "?" if the release is not recognized. +# TAG: what follows "nginx-plus-r" in "nginx -V", e.g. 37.0.8, 36-p8, 36 +# BASE: the open source version it is built on, e.g. 1.29.8 +# The R-series (R36 and older) got no fix. PLS.37: LTS track 37.0.P, CR track +# 37.M.P (M >= 1). 37.0.7 / 37.2.0 fixed CVE-2026-123633; 37.0.8 / 37.3.0 +# fixed CVE-2026-123007 and CVE-2026-123634 as well. +affected_plus() { + local tag=$1 major rest minor patch out="" + major=${tag%%[!0-9]*} + case "$major" in ''|*[!0-9]*) echo "?"; return ;; esac + if [ "$major" -lt 37 ]; then + case "$2" in [0-9]*.[0-9]*) from_base "$(ver_key "$2")" ;; *) echo "?" ;; esac + return + fi + if [ "$major" -gt 37 ]; then echo ""; return; fi + rest=${tag#37.} + case "$rest" in [0-9]*.[0-9]*) ;; *) echo "?"; return ;; esac + minor=${rest%%.*} + patch=${rest#*.}; patch=${patch%%[!0-9]*} + case "$minor" in ''|*[!0-9]*) echo "?"; return ;; esac + case "$patch" in ''|*[!0-9]*) echo "?"; return ;; esac + if ! { [ "$minor" -eq 0 ] && [ "$patch" -ge 8 ]; } && [ "$minor" -lt 3 ]; then + out="$CVE_WIN" + fi + if ! { [ "$minor" -eq 0 ] && [ "$patch" -ge 7 ]; } && [ "$minor" -lt 2 ]; then + out="$out $CVE_UAF" + fi + if ! { [ "$minor" -eq 0 ] && [ "$patch" -ge 8 ]; } && [ "$minor" -lt 3 ]; then + out="$out $CVE_RES" + fi + echo "${out# }" +} + +# --- files as an instance sees them ------------------------------------------ + +# rpath ROOT PATH: the path, as seen from here, of PATH as seen by a process +# whose root directory is ROOT (empty for this host, /proc/PID/root for a +# container). Symlinks inside ROOT are followed by hand so that absolute +# targets stay inside ROOT. +rpath() { + local root=$1 rest=$2 done="" comp t n=0 + if [ -z "$root" ]; then printf '%s\n' "$rest"; return 0; fi + rest=${rest#/} + while [ -n "$rest" ]; do + comp=${rest%%/*} + if [ "$comp" = "$rest" ]; then rest=""; else rest=${rest#*/}; fi + case "$comp" in + ''|.) continue ;; + ..) done=${done%/*}; continue ;; + esac + if [ -L "$root$done/$comp" ]; then + n=$((n + 1)) + [ "$n" -le 40 ] || return 1 + t=$(readlink "$root$done/$comp") || return 1 + case "$t" in /*) done="" ;; esac + t=${t#/} + rest="$t${rest:+/$rest}" + else + done="$done/$comp" + fi + done + printf '%s\n' "$root${done:-/}" +} + +# --- config ------------------------------------------------------------------ + +# Splits one nginx config file into statements, one per line: +# ";wordword..." a directive +# "{wordword..." a block opens +# "}" a block closes +# Handles comments, quotes, ${var} and the Lua code in *_by_lua_block blocks. +# shellcheck disable=SC2016 +TOKENIZE=' +function endword() { if (inw) { w[++nw] = cur; cur = ""; inw = 0 } } +function emit(t, k, s) { + s = t "\t" + for (k = 1; k <= nw; k++) s = s (k > 1 ? US : "") w[k] + print s + lua = (t == "{" && nw > 0 && w[1] ~ /_by_lua_block$/) + nw = 0 +} +function longopen(i, j) { + j = i + 1 + while (substr(buf, j, 1) == "=") j++ + if (substr(buf, j, 1) != "[") return 0 + lvl = j - i - 1 + return j + 1 +} +function longclose(i, cl, k, p) { + cl = "]" + for (k = 0; k < lvl; k++) cl = cl "=" + cl = cl "]" + p = index(substr(buf, i), cl) + return p ? i + p - 1 + length(cl) : L + 1 +} +function skiplua(i, depth, c, q, j) { + depth = 1 + while (i <= L) { + c = substr(buf, i, 1) + if (c == "-" && substr(buf, i + 1, 1) == "-") { + if (substr(buf, i + 2, 1) == "[" && (j = longopen(i + 2))) { i = longclose(j); continue } + while (i <= L && substr(buf, i, 1) != "\n") i++ + continue + } + if (c == "[" && (j = longopen(i))) { i = longclose(j); continue } + if (c == "\"" || c == "\047") { + q = c; i++ + while (i <= L) { + c = substr(buf, i, 1) + if (c == "\\") { i += 2; continue } + i++ + if (c == q || c == "\n") break + } + continue + } + if (c == "{") depth++ + else if (c == "}") { depth--; if (depth == 0) return i + 1 } + i++ + } + return i +} +BEGIN { US = sprintf("%c", 31) } +{ buf = buf $0 "\n" } +END { + L = length(buf); i = 1; nw = 0; inw = 0; cur = "" + while (i <= L) { + c = substr(buf, i, 1) + if (c == " " || c == "\t" || c == "\n" || c == "\r") { endword(); i++; continue } + if (c == "#" && !inw) { while (i <= L && substr(buf, i, 1) != "\n") i++; continue } + if (c == ";") { endword(); emit(";"); i++; continue } + if (c == "{") { + endword(); emit("{"); i++ + if (lua) { i = skiplua(i); print "}\t" } + continue + } + if (c == "}") { endword(); emit("}"); i++; continue } + if ((c == "\"" || c == "\047") && !inw) { + q = c; i++; s = "" + while (i <= L) { + c = substr(buf, i, 1) + if (c == "\\" && i < L) { s = s substr(buf, i + 1, 1); i += 2; continue } + i++ + if (c == q) break + s = s c + } + w[++nw] = s + continue + } + if (c == "$" && substr(buf, i + 1, 1) == "{") { + j = index(substr(buf, i), "}") + if (j) { cur = cur substr(buf, i, j); inw = 1; i += j; continue } + } + cur = cur c; inw = 1; i++ + } + endword() +}' + +# Reads FILETYPEWORDS lines from conf_stream and prints two lines, +# "h2STATEWHERE" and "resSTATEWHERE", where STATE is +# on the feature is used; WHERE names the directive and its file +# off it is not +# unknown it is not used in what could be read, but WHERE could not be read +# HTTP/2 is on for a server when a listen directive has the http2 parameter, +# or "http2 on;" is set in that server{} or inherited from http{}. +# The resolver is on when a "resolver" directive appears anywhere in http{} +# (http, server, location or upstream level). stream{} and mail{} resolvers +# do not count: the bug needs HTTP subrequests. +# shellcheck disable=SC2016 +EVALUATE=' +BEGIN { FS = "\t"; US = sprintf("%c", 31); d = 0; ns = 0; hv = ""; hf = ""; on = ""; res = ""; bad = "" } +$1 == "!" { if (bad == "") bad = $2; next } +{ + f = $1; t = $2; nw = split($3, w, US) + if (t == "{") { + d++; ctx[d] = (nw ? w[1] : "") + if (d == 2 && ctx[1] == "http" && ctx[2] == "server") { ns++; sv[ns] = ""; sf[ns] = "" } + next + } + if (t == "}") { if (d > 0) d--; next } + if (d >= 1 && ctx[1] == "http" && w[1] == "resolver" && res == "") { + res = "resolver" + for (k = 2; k <= nw; k++) res = res " " w[k] + res = res " (" f ")" + } + if (d == 1 && ctx[1] == "http" && w[1] == "http2") { hv = w[2]; hf = f } + if (d == 2 && ctx[1] == "http" && ctx[2] == "server") { + if (w[1] == "http2") { sv[ns] = w[2]; sf[ns] = f } + if (w[1] == "listen" && on == "") { + h = 0 + for (k = 2; k <= nw; k++) if (w[k] == "http2") h = 1 + if (h) { + on = "listen" + for (k = 2; k <= nw; k++) on = on " " w[k] + on = on " (" f ")" + } + } + } +} +END { + for (s = 1; s <= ns && on == ""; s++) { + if (sv[s] == "on") on = "http2 on (" sf[s] ")" + else if (sv[s] == "" && hv == "on") on = "http2 on (" hf ")" + } + if (on != "") print "h2\ton\t" on + else if (bad != "") print "h2\tunknown\t" bad + else print "h2\toff\t" + if (res != "") print "res\ton\t" res + else if (bad != "") print "res\tunknown\t" bad + else print "res\toff\t" +}' + +# conf_glob ROOT PATTERN: the files an include PATTERN names, one per line, +# as the instance sees them. A pattern without wildcards is printed as is. +conf_glob() { + local root=$1 pat=$2 dir base hd f + case "$pat" in *[*?[]*) ;; *) printf '%s\n' "$pat"; return 0 ;; esac + dir=${pat%/*} + base=${pat##*/} + case "$dir" in + *[*?[]*) + set +f + # shellcheck disable=SC2086 + for f in $root$pat; do + if [ -e "$f" ] || [ -L "$f" ]; then printf '%s\n' "${f#"$root"}"; fi + done + set -f + return 0 ;; + esac + hd=$(rpath "$root" "${dir:-/}") || return 0 + set +f + # shellcheck disable=SC2086 + for f in "$hd"/$base; do + if [ -e "$f" ] || [ -L "$f" ]; then printf '%s\n' "$dir/${f##*/}"; fi + done + set -f +} + +# conf_stream ROOT FILE CONFDIR DEPTH: FILE's statements with includes +# expanded in place, as FILETYPEWORDS lines. Relative includes are +# taken from CONFDIR, the main config file's directory, as nginx does. A +# file that cannot be read is reported as "!FILE". +conf_stream() { + local root=$1 file=$2 cdir=$3 depth=$4 host t w arg f + if [ "$depth" -gt 16 ]; then + printf '!\t%s (includes nested too deep)\n' "$file" + return + fi + host=$(rpath "$root" "$file") || host="" + if [ -z "$host" ] || [ ! -f "$host" ] || [ ! -r "$host" ]; then + printf '!\t%s\n' "$file" + return + fi + awk "$TOKENIZE" "$host" | while IFS="$TAB" read -r t w; do + case "$t$TAB$w" in + ";${TAB}include$US"*) + arg=${w#include"$US"} + arg=${arg%%"$US"*} + case "$arg" in /*) ;; *) arg="$cdir/$arg" ;; esac + conf_glob "$root" "$arg" | while IFS= read -r f; do + conf_stream "$root" "$f" "$cdir" $((depth + 1)) + done ;; + *) printf '%s\t%s\t%s\n' "$file" "$t" "$w" ;; + esac + done +} + +# --- packages ---------------------------------------------------------------- + +# backport ROOT PREFIX EXE CVES: looks for fixes recorded by the package that +# owns EXE (the binary path as the instance sees it). Sets +# BP_STATE ok (all CVES fixed), impacted, or unknown (cannot tell) +# BP_VAL what to print +# BP_REMAIN the CVES not recorded as fixed +# BP_HAVE the CVES recorded as fixed +# Arguments: +# ROOT where the instance's files are seen from here ("" or /proc/PID/root) +# PREFIX command prefix that runs a program inside the instance, or "" +# CVES the CVEs its version is affected by +backport() { + local root=$1 prefix=$2 exe=$3 cves=$4 + local db f pkg="" ver="" maint="" info text="" have_text=0 c have="" miss="" rpmc="" + BP_STATE=impacted + BP_VAL="not owned by a package" + BP_REMAIN=$cves + BP_HAVE="" + + # dpkg (Debian, Ubuntu, and the nginx.org Debian/Ubuntu repositories) + db=$(rpath "$root" /var/lib/dpkg/info) || db="" + if [ -n "$db" ] && [ -d "$db" ]; then + set +f + f=$(grep -lxF -- "$exe" "$db"/*.list 2>/dev/null | head -1) + set -f + if [ -n "$f" ]; then + pkg=${f##*/}; pkg=${pkg%.list}; pkg=${pkg%%:*} + info=$(awk -v p="$pkg" ' + BEGIN { RS = "" } + { + n = split($0, l, "\n"); pk = ""; st = ""; v = ""; m = "" + for (i = 1; i <= n; i++) { + if (l[i] ~ /^Package: /) pk = substr(l[i], 10) + else if (l[i] ~ /^Status: /) st = l[i] + else if (l[i] ~ /^Version: /) v = substr(l[i], 10) + else if (l[i] ~ /^Maintainer: /) m = substr(l[i], 13) + } + if (pk == p && st ~ / installed$/) { print v "\t" m; exit } + }' "$(rpath "$root" /var/lib/dpkg/status)" 2>/dev/null) + ver=${info%%"$TAB"*} + maint=${info#*"$TAB"} + BP_VAL="$pkg $ver (dpkg)" + f=$(rpath "$root" "/usr/share/doc/$pkg/changelog.Debian.gz") || f="" + if [ -n "$f" ] && [ -r "$f" ]; then + text=$(gzip -dc < "$f" 2>/dev/null) && have_text=1 + fi + fi + fi + + # rpm (RHEL, Rocky, Alma, Oracle Linux, Amazon Linux, Fedora, SUSE) + if [ -z "$pkg" ]; then + if [ -z "$root" ]; then + command -v rpm >/dev/null 2>&1 && rpmc=rpm + else + f=$(rpath "$root" /usr/bin/rpm) && [ -x "$f" ] && rpmc="$prefix rpm" + fi + if [ -n "$rpmc" ]; then + # shellcheck disable=SC2086 + if info=$($TO $rpmc -qf --qf '%{NAME}\t%{VERSION}-%{RELEASE}\t%{VENDOR}\n' "$exe" 2>/dev/null /dev/null /dev/null) + if [ -n "$info" ]; then + pkg=${info%%"$TAB"*} + ver=${info#*"$TAB"}; ver=${ver%%"$TAB"*} + maint=${info##*"$TAB"} + BP_VAL="$pkg $ver (apk)" + fi + fi + fi + + [ -n "$pkg" ] || return 0 + + # nginx.org builds the upstream release as is: the version tells it all. + case "$maint" in + *nginx-packaging@*|*"NGINX Packaging"*) + BP_VAL="$BP_VAL, nginx.org package: fixed only by upgrading" + return 0 ;; + esac + + if [ "$have_text" -eq 0 ]; then + BP_STATE=unknown + case "$BP_VAL" in + *"(apk)") BP_VAL="$BP_VAL: Alpine records fixes outside the package, check secdb.alpinelinux.org" ;; + *) BP_VAL="$BP_VAL: changelog not on disk, check the vendor's advisory" ;; + esac + return 0 + fi + for c in $cves; do + if grep -qF "$c" <<<"$text"; then have="$have $c"; else miss="$miss $c"; fi + done + BP_REMAIN=${miss# } + BP_HAVE=${have# } + if [ -z "$miss" ]; then + BP_STATE=ok + BP_VAL="$BP_VAL, changelog lists$have" + elif [ -n "$have" ]; then + BP_VAL="$BP_VAL, changelog lists$have but not$miss" + else + BP_VAL="$BP_VAL, changelog does not list$miss" + fi +} + +# --- probing ----------------------------------------------------------------- + +# probe TITLE PREFIX BIN ROOT EXE CONF PFX REPLACED +# TITLE: how the instance is shown +# PREFIX: command prefix such as "nsenter -t PID --mount --root", or empty +# BIN: binary to run with -V (the path, or /proc/PID/exe) +# ROOT: where the instance's files are seen from here, or empty +# EXE: the binary's path as the instance sees it +# CONF/PFX: -c and -p from its command line, or empty for the defaults +# REPLACED: 1 if the running binary has been replaced on disk +probe() { + local title=$1 prefix=$2 bin=$3 root=$4 exe=$5 conf=$6 pfx=$7 replaced=$8 + local out vline vstr prod ver tag cargs aff core plus=0 ev result + local remain c g need_h2=0 need_rs=0 imp="" unk=0 + local s_ver v_ver s_bp v_bp s_h2 v_h2 s_rs v_rs + + # shellcheck disable=SC2086 + out=$($TO $prefix "$bin" -V 2>&1 /dev/null || realpath "$1" 2>/dev/null || printf '%s\n' "$1" +} + +# add_cand KIND PATH +add_cand() { + local r + [ -f "$2" ] && [ -x "$2" ] || return 0 + r=$(resolve "$2") + grep -qxF -- "$1:$r" "$TMP/cands" || printf '%s:%s\n' "$1" "$r" >> "$TMP/cands" +} + +discover_disk() { + local n p + for n in nginx openresty angie; do + p=$(command -v "$n" 2>/dev/null) && add_cand disk "$p" + done + set +f + for p in /usr/sbin/nginx /usr/bin/nginx /usr/local/sbin/nginx /usr/local/bin/nginx \ + /usr/local/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx \ + /usr/local/tengine/sbin/nginx /usr/sbin/angie /usr/local/angie/sbin/angie \ + /opt/*/sbin/nginx /opt/*/nginx/sbin/nginx /opt/*/*/sbin/nginx \ + /opt/homebrew/bin/nginx /opt/homebrew/bin/openresty; do + add_cand disk "$p" + done + set -f +} + +# parse_args ARGS: sets P_CONF and P_PFX from an nginx command line. +parse_args() { + P_CONF="" + P_PFX="" + # shellcheck disable=SC2086 + set -- $1 + [ $# -gt 0 ] && shift + while [ $# -gt 0 ]; do + case "$1" in + -c) P_CONF=${2:-}; [ $# -gt 1 ] && shift ;; + -c?*) P_CONF=${1#-c} ;; + -p) P_PFX=${2:-}; [ $# -gt 1 ] && shift ;; + -p?*) P_PFX=${1#-p} ;; + esac + shift + done +} + +# One line per instance: fields separated by \037. +proc_line() { + local IFS="$US" + printf '%s\n' "$*" >> "$TMP/procs" +} + +is_nginx_name() { + case "$1" in nginx|openresty|angie|tengine|freenginx) return 0 ;; esac + return 1 +} + +scan_procs_linux() { + local d pid exe title base args prefix root bin ns self_ns note replaced pids hn + self_ns=$(readlink /proc/self/ns/mnt 2>/dev/null) || self_ns="" + pids=$(set +f; printf '%s\n' /proc/[0-9]*) + for d in $pids; do + pid=${d#/proc/} + [ "$pid" = "$$" ] && continue + [ -r "$d/cmdline" ] || continue + title=$(tr '\0' ' ' < "$d/cmdline" 2>/dev/null) || continue + title=${title% } + # Workers and helpers belong to a master, which is checked instead. + case "$title" in + *": worker process"*|*": cache manager process"*|*": cache loader process"*|*": privileged agent process"*) + continue ;; + esac + exe=$(readlink "$d/exe" 2>/dev/null) || exe="" + base=${exe% (deleted)} + base=${base##*/} + if [ -z "$base" ]; then + case "$title" in + *": master process"*) + if is_nginx_name "${title%%:*}"; then + single "$title (pid $pid)" "binary" "path unreadable, run as root" unknown + fi ;; + esac + continue + fi + is_nginx_name "$base" || continue + + args=$title + case "$args" in *": master process "*) args=${args#*: master process } ;; esac + parse_args "$args" + + prefix=""; root=""; note=""; replaced=0 + bin=${exe% (deleted)} + ns=$(readlink "$d/ns/mnt" 2>/dev/null) || ns="" + if [ -n "$ns" ] && [ -n "$self_ns" ] && [ "$ns" != "$self_ns" ]; then + if [ "$IS_ROOT" -eq 1 ] && command -v nsenter >/dev/null 2>&1; then + prefix="nsenter -t $pid --mount --root" + root="/proc/$pid/root" + # The container's hostname: the pod name in Kubernetes, the + # short container ID in Docker. + hn=$(head -1 "$(rpath "$root" /etc/hostname)" 2>/dev/null | tr -cd 'A-Za-z0-9._-') + note=", container${hn:+ $hn}" + else + single "$bin (pid $pid, container)" "binary" "in a container, run as root with nsenter" unknown + continue + fi + fi + case "$exe" in + *" (deleted)") + if [ -n "$root" ]; then + single "$bin (pid $pid, container)" "binary" "replaced on disk after start, restart it" unknown + continue + fi + # The kernel keeps the old binary reachable: ask it directly. + replaced=1 + note="$note, binary replaced on disk since start" ;; + esac + if [ "$replaced" -eq 1 ]; then + proc_line "$pid" "" "/proc/$pid/exe" "" "$bin" "$P_CONF" "$P_PFX" 1 "$note" + else + proc_line "$pid" "$prefix" "$bin" "$root" "$bin" "$P_CONF" "$P_PFX" 0 "$note" + fi + done +} + +scan_procs_darwin() { + local all pid ppid comm + all=$(ps -axo pid=,ppid=,comm= 2>/dev/null | awk '{ + c = $3; for (i = 4; i <= NF; i++) c = c " " $i + n = c; sub(/.*\//, "", n) + if (n ~ /^(nginx|openresty|angie|tengine|freenginx)$/) print $1, $2, c + }') + while read -r pid ppid comm; do + [ -n "$pid" ] || continue + [ "$pid" = "$$" ] && continue + # nginx on macOS keeps its argv, so workers look like the master: + # keep only processes whose parent is not nginx. + if awk -v p="$ppid" '$1 == p { f = 1 } END { exit !f }' <<<"$all"; then continue; fi + case "$comm" in + /*) ;; + *) single "$comm (pid $pid)" "binary" "path not shown by ps" unknown; continue ;; + esac + parse_args "$(ps -o args= -p "$pid" 2>/dev/null)" + proc_line "$pid" "" "$comm" "" "$comm" "$P_CONF" "$P_PFX" 0 "" + done <<<"$all" +} + +# --- main -------------------------------------------------------------------- + +header +say "host: $HOST_OS $(uname -m)" + +[ "$SCAN_DISK" -eq 1 ] && discover_disk +while IFS= read -r j; do + [ -n "$j" ] || continue + if [ -f "$j" ] && [ -x "$j" ]; then add_cand arg "$j"; else printf 'missing:%s\n' "$j" >> "$TMP/cands"; fi +done <<<"$EXTRA_BINS" + +# Running instances are collected before any probe starts. +if [ "$SCAN_PROCS" -eq 1 ]; then + case "$HOST_OS" in + Linux) scan_procs_linux ;; + Darwin) scan_procs_darwin ;; + *) say "note: process scan not supported on $HOST_OS" ;; + esac + [ "$IS_ROOT" -eq 1 ] || say "note: not root; master processes, containers and root-only configs may be missed" +fi + +while IFS= read -r c; do + kind=${c%%:*} + j=${c#*:} + case "$kind" in + missing) single "$j (-n)" "binary" "not an executable file" unknown; continue ;; + disk) + # Already covered by a running instance on this host. + if awk -F "$US" -v e="$j" '$2 == "" && $5 == e { f = 1 } END { exit !f }' "$TMP/procs"; then + dbg "$j: running instance found, skipping the installed copy" + continue + fi + probe "$j (installed)" "" "$j" "" "$j" "$EXTRA_CONF" "" 0 ;; + arg) probe "$j (-n)" "" "$j" "" "$j" "$EXTRA_CONF" "" 0 ;; + esac +done < "$TMP/cands" + +while IFS="$US" read -r pid prefix bin root exe conf pfx replaced note; do + [ -n "$pid" ] || continue + probe "$exe (pid $pid$note)" "$prefix" "$bin" "$root" "$exe" "$conf" "$pfx" "$replaced" +done < "$TMP/procs" + +finish diff --git a/CVE-2026-123633.CVE-2026-123007/linux/k8s-nginx-http2.yaml b/CVE-2026-123633.CVE-2026-123007/linux/k8s-nginx-http2.yaml new file mode 100644 index 0000000..92fae97 --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/linux/k8s-nginx-http2.yaml @@ -0,0 +1,87 @@ +# k8s-nginx-http2.yaml -- check every nginx on every Linux node with one DaemonSet. +# +# One pod per node, with host process visibility (hostPID) and privileged + nsenter, +# so the detector can run each container's own `nginx -V` and read its config and +# package files inside that container's filesystem. This covers ingress controllers +# (ingress-nginx, NGINX Ingress Controller) and any other pod that runs nginx, for +# all three CVEs: CVE-2026-123007 and CVE-2026-123633 (HTTP/2) and CVE-2026-123634 +# (resolver). +# Nothing is copied into, or changed in, any workload pod. Self-contained: it runs +# this repo's own detect-nginx-http2.sh, mounted from a ConfigMap. +# +# privileged: true is required: nsenter into other pods' mount namespaces and +# /proc/PID/root reads need it. Review this manifest before applying it, run it +# for as long as you need results, then delete the namespace. +# +# The detector needs bash and nsenter, which the base image here (debian:stable-slim) +# provides after a one-time util-linux install at start (needs registry/apt access; +# for air-gapped clusters, bake bash + util-linux + the script into your own image +# and drop the apt line). The pod runs: detect-nginx-http2.sh --no-disk, so it +# reports the node's running nginx masters and skips the detector pod's own +# filesystem. Each block names the container's hostname, which in Kubernetes is +# the pod name. +# +# Run: +# kubectl create namespace nginxh2 +# kubectl -n nginxh2 create configmap detect --from-file=detect-nginx-http2.sh +# kubectl apply -f k8s-nginx-http2.yaml +# kubectl -n nginxh2 rollout status daemonset/nginxh2 +# kubectl -n nginxh2 logs -l app=nginxh2 --tail=-1 --prefix --max-log-requests=500 +# Remove: +# kubectl delete namespace nginxh2 +# +# The last line of each pod's log section is that node's verdict +# (impacted / unknown / not impacted). +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: nginxh2 + namespace: nginxh2 +spec: + selector: + matchLabels: + app: nginxh2 + template: + metadata: + labels: + app: nginxh2 + spec: + hostPID: true + nodeSelector: + kubernetes.io/os: linux + tolerations: + - operator: Exists + terminationGracePeriodSeconds: 1 + containers: + - name: detect + image: debian:stable-slim + securityContext: + privileged: true + env: + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + command: ["/bin/sh", "-c"] + args: + - | + command -v nsenter >/dev/null 2>&1 || \ + (apt-get update && apt-get install -y --no-install-recommends util-linux) >/dev/null 2>&1 || true + echo "=== node: ${NODE_NAME} ===" + bash /scripts/detect-nginx-http2.sh --no-disk || true + echo "=== end node: ${NODE_NAME} ===" + sleep infinity + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + memory: 512Mi + volumeMounts: + - name: detect + mountPath: /scripts + readOnly: true + volumes: + - name: detect + configMap: + name: detect diff --git a/CVE-2026-123633.CVE-2026-123007/linux/ssh-nginx-http2.sh b/CVE-2026-123633.CVE-2026-123007/linux/ssh-nginx-http2.sh new file mode 100755 index 0000000..32a6840 --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/linux/ssh-nginx-http2.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# ssh-nginx-http2.sh -- run the nginx (CVE-2026-123007, CVE-2026-123633, CVE-2026-123634) detector across Linux/macOS hosts over SSH. +# +# No agent, no install: detect-nginx-http2.sh is piped to each host's bash over +# stdin and run there, so nothing is copied to or left on the target. Read-only; +# the detector only runs `nginx -V` and reads config and package files. +# +# Usage: +# sh ssh-nginx-http2.sh hosts.txt [results_dir] # one host or user@host per line, # comments ok +# PARALLEL=20 sh ssh-nginx-http2.sh hosts.txt +# DETECT_ARGS="-q" sh ssh-nginx-http2.sh hosts.txt +# SUDO="" sh ssh-nginx-http2.sh hosts.txt # run as the login user (less coverage) +# +# Needs key-based SSH; for full coverage, passwordless sudo on the targets and +# bash present there (the detector requires bash). Each host's output goes to +# results_dir/.txt. The detector's exit code is the verdict (their contract): +# 0 not impacted 1 impacted 2 unknown 3 usage 255/other = SSH/transport error +# An impacted / unknown / not impacted / error roll-up prints at the end; this +# script exits 1 if any host is impacted, else 2 if any unknown/error, else 0. +set -u + +SCRIPT=${DETECT:-$(dirname "$0")/detect-nginx-http2.sh} +HOSTS=${1:?usage: ssh-nginx-http2.sh hosts.txt [results_dir]} +OUT=${2:-results} +PARALLEL=${PARALLEL:-10} +SUDO=${SUDO-sudo -n} +DETECT_ARGS=${DETECT_ARGS:-} + +[ -f "$SCRIPT" ] || { echo "detector not found at $SCRIPT (set DETECT=/path/to/detect-nginx-http2.sh)" >&2; exit 3; } +[ -f "$HOSTS" ] || { echo "hosts file not found: $HOSTS" >&2; exit 3; } +mkdir -p "$OUT" || exit 3 +rm -f "$OUT"/.status.* 2>/dev/null + +safe() { printf '%s' "$1" | tr -c 'A-Za-z0-9._@-' '_'; } + +one() { + h=$1 + s=$(safe "$h") + f="$OUT/$s.txt" + if ssh -o BatchMode=yes -o ConnectTimeout=15 "$h" "$SUDO bash -s -- $DETECT_ARGS" < "$SCRIPT" > "$f" 2>"$f.err"; then + rc=0 + else + rc=$? + fi + case "$rc" in + 0) v="not impacted" ;; + 1) v="impacted" ;; + 2) v="unknown" ;; + 3) v="error (usage)" ;; + 255) v="error (ssh/connection)" ;; + *) v="error (rc=$rc)" ;; + esac + # sudo and the remote shell exit 1 on their own failures ("a password is + # required", "bash: command not found"), which collides with "impacted". + # Trust 0/1/2 only when the detector's last line agrees with it. + case "$rc" in + 0|1|2) + last=$(sed '/^[[:space:]]*$/d' "$f" | tail -n 1) + if [ "$last" != "$v" ]; then + if grep -q 'password is required' "$f.err" 2>/dev/null; then + v="error (sudo needs a password)" + elif grep -q '^sudo:' "$f.err" 2>/dev/null; then + v="error (sudo)" + else + v="error (no verdict, rc=$rc)" + fi + fi ;; + esac + printf '%s\t%s\n' "$v" "$h" > "$OUT/.status.$s" + [ -s "$f.err" ] || rm -f "$f.err" +} + +n=0 +while IFS= read -r h || [ -n "$h" ]; do + case "$h" in ''|\#*) continue ;; esac + one "$h" & + n=$((n + 1)) + [ $((n % PARALLEL)) -eq 0 ] && wait +done < "$HOSTS" +wait + +cat "$OUT"/.status.* 2>/dev/null > "$OUT/.all" || true +echo "nginx CVE-2026-123007/123633/123634 fleet detection ($n host(s))" +for v in impacted unknown "not impacted"; do + hs=$(awk -F'\t' -v V="$v" '$1==V{print $2}' "$OUT/.all" 2>/dev/null | sort | tr '\n' ' ') + printf ' %-13s %s\n' "$v:" "${hs:-(none)}" +done +errs=$(awk -F'\t' '$1 ~ /^error/{printf "%s(%s) ", $2, $1}' "$OUT/.all" 2>/dev/null) +[ -n "$errs" ] && printf ' %-13s %s\n' "error:" "$errs" +if grep -q 'sudo needs a password' "$OUT/.all" 2>/dev/null; then + echo " hint: sudo -n needs passwordless sudo on the target. Use root@host," + echo " or SUDO=\"\" to run as the login user (less coverage, often unknown)." +fi +echo "per-host output in $OUT/" + +if awk -F'\t' '$1=="impacted"{f=1} END{exit !f}' "$OUT/.all" 2>/dev/null; then exit 1; fi +if awk -F'\t' '$1=="unknown" || $1 ~ /^error/{f=1} END{exit !f}' "$OUT/.all" 2>/dev/null; then exit 2; fi +exit 0 diff --git a/CVE-2026-123633.CVE-2026-123007/linux/tests/fake-nginx b/CVE-2026-123633.CVE-2026-123007/linux/tests/fake-nginx new file mode 100755 index 0000000..2dfd553 --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/linux/tests/fake-nginx @@ -0,0 +1,25 @@ +#!/bin/sh +# Fake nginx for exercising detect-nginx-http2.sh decision logic on any host. +# Prints what "nginx -V" prints, on stderr like the real binary. +# Knobs: +# FAKE_VLINE version line (default "nginx version: nginx/1.24.0") +# FAKE_CONF --conf-path value (default /etc/nginx/nginx.conf) +# FAKE_PREFIX --prefix value (default /usr/share/nginx) +# FAKE_NO_H2 set: build without --with-http_v2_module +# FAKE_FAIL set: fail to run +case "${1:-}" in + -V) ;; + *) echo "fake-nginx: only -V is supported" >&2; exit 1 ;; +esac +if [ -n "${FAKE_FAIL:-}" ]; then + echo "fake-nginx: error while loading shared libraries: libssl.so.3" >&2 + exit 127 +fi +mods="--with-http_ssl_module --with-http_v2_module --with-http_v3_module" +[ -n "${FAKE_NO_H2:-}" ] && mods="--with-http_ssl_module" +{ + echo "${FAKE_VLINE:-nginx version: nginx/1.24.0}" + echo "built with OpenSSL 3.0.13 30 Jan 2024" + echo "TLS SNI support enabled" + echo "configure arguments: --prefix=${FAKE_PREFIX:-/usr/share/nginx} --conf-path=${FAKE_CONF:-/etc/nginx/nginx.conf} --with-cc-opt='-g -O2 -fstack-protector-strong' $mods" +} >&2 diff --git a/CVE-2026-123633.CVE-2026-123007/linux/tests/run-tests.sh b/CVE-2026-123633.CVE-2026-123007/linux/tests/run-tests.sh new file mode 100755 index 0000000..1ec2370 --- /dev/null +++ b/CVE-2026-123633.CVE-2026-123007/linux/tests/run-tests.sh @@ -0,0 +1,597 @@ +#!/usr/bin/env bash +# +# Tests detect-nginx-http2.sh. +# +# 1. Decision logic: tests/fake-nginx and generated configs drive every +# version, Plus, fork, build and config-parsing branch. Runs anywhere +# (Linux or macOS, bash 3.2+), no root, no Docker. +# 2. Real nginx in Docker containers: the nginx.org Debian and Alpine +# images, OpenResty, and the Debian, Ubuntu and AlmaLinux packages. The +# detector runs inside each container, as the SSH wrapper would run it. +# Expected verdicts for distro packages come from an independent read of +# each package changelog, so the tests keep passing after vendors ship +# their fixes. +# 3. Container scan: the detector runs as root in a privileged --pid=host +# container and must check every container's nginx through nsenter, +# which is what the Kubernetes DaemonSet does. +# +# usage: run-tests.sh [--no-docker] +# Image overrides (CI pins digests): IMG_ORG IMG_ALPINE IMG_OPENRESTY IMG_DEBIAN +# IMG_UBUNTU IMG_ALMA + +set -u + +HERE=$(cd "$(dirname "$0")" && pwd) +S="$HERE/../detect-nginx-http2.sh" +FAKE="$HERE/fake-nginx" +DOCKER=1 +[ "${1:-}" = "--no-docker" ] && DOCKER=0 +command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1 || DOCKER=0 + +IMG_ORG=${IMG_ORG:-nginx:1.30.6} +IMG_ALPINE=${IMG_ALPINE:-nginx:1.30.6-alpine} +IMG_OPENRESTY=${IMG_OPENRESTY:-openresty/openresty:bookworm} +IMG_DEBIAN=${IMG_DEBIAN:-debian:trixie} +IMG_UBUNTU=${IMG_UBUNTU:-ubuntu:24.04} +IMG_ALMA=${IMG_ALMA:-almalinux:9} + +PASS=0 +FAIL=0 +WORK=$(mktemp -d) +CPFX="nh2t-$$" +CONTAINERS="" + +cleanup() { + for c in $CONTAINERS; do docker rm -f "$c" >/dev/null 2>&1; done + rm -rf "$WORK" +} +trap cleanup EXIT + +verdict() { + case "$1" in + 0) echo "not impacted" ;; + 1) echo "impacted" ;; + 2) echo "unknown" ;; + *) echo "" ;; + esac +} + +# run CMD... : sets OUT, CODE, LAST +run() { + OUT=$("$@" 2>&1) + CODE=$? + LAST=$(printf '%s\n' "$OUT" | sed '/^[[:space:]]*$/d' | tail -1) +} + +# check NAME WANT_CODE [MUST_CONTAIN]... (a "!text" argument must be absent) +check() { + local name=$1 want=$2 ok=1 c + shift 2 + [ "$CODE" = "$want" ] || ok=0 + if [ "$want" != 3 ] && [ "$LAST" != "$(verdict "$want")" ]; then ok=0; fi + for c in "$@"; do + case "$c" in + !*) printf '%s\n' "$OUT" | grep -qF -- "${c#!}" && ok=0 ;; + *) printf '%s\n' "$OUT" | grep -qF -- "$c" || ok=0 ;; + esac + done + # Fleet agents often run scripts with SIGPIPE ignored; stray write + # errors on stderr are a failure. + if printf '%s\n' "$OUT" | grep -qE 'Broken pipe|write error|syntax error|command not found'; then ok=0; fi + if [ "$ok" -eq 1 ]; then + PASS=$((PASS + 1)) + echo "PASS $name" + else + FAIL=$((FAIL + 1)) + echo "FAIL $name (want exit $want '$(verdict "$want")' containing [$*]; got exit $CODE)" + printf '%s\n' "$OUT" | sed 's/^/ | /' + fi +} + +# conf NAME: writes stdin to $WORK/NAME and prints the path +conf() { + mkdir -p "$(dirname "$WORK/$1")" + cat > "$WORK/$1" + printf '%s\n' "$WORK/$1" +} + +echo "bash: $BASH_VERSION ($(uname -sm))" + +# --- 1. Decision logic ----------------------------------------------------------- + +echo +echo "## Decision logic (fake nginx)" + +H2ON=$(conf on/nginx.conf <<'EOF' +events {} +http { + server { listen 443 ssl; http2 on; } +} +EOF +) +H2OFF=$(conf off/nginx.conf <<'EOF' +events {} +http { + server { listen 80; } +} +EOF +) +F=(bash "$S" --no-procs --no-disk -n "$FAKE") +V() { FAKE_VLINE="nginx version: $1"; export FAKE_VLINE; } + +RES=$(conf res/nginx.conf <<'EOF' +events {} +http { + resolver 10.0.0.2 valid=30s; + server { listen 80; location / { proxy_pass http://$host; } } +} +EOF +) +ALL3="CVE-2026-123007 CVE-2026-123633 CVE-2026-123634" + +run "${F[@]}" -c "$H2ON"; check "default fake 1.24.0, http2 on -> impacted" 1 \ + "legend: [!] impacted" "checks: version, backport, then http/2 (CVE-2026-123007, CVE-2026-123633) or resolver (CVE-2026-123634)." \ + " version: nginx/1.24.0: $ALL3 [!]" \ + " backport: not owned by a package [!]" " http/2: on, http2 on ($H2ON) [!]" \ + " resolver: not set ($H2ON) OK" " => [!] impacted: CVE-2026-123007 CVE-2026-123633" +run "${F[@]}" -c "$H2ON" -q; check "quiet prints verdict only" 1 +[ "$(printf '%s\n' "$OUT" | wc -l | tr -d ' ')" -eq 1 ] || { FAIL=$((FAIL + 1)); echo "FAIL quiet printed more than one line"; } +run "${F[@]}" -c "$H2OFF"; check "http2 off, no resolver -> not impacted" 0 " http/2: off ($H2OFF) OK" " resolver: not set ($H2OFF) OK" " => OK" +run "${F[@]}" -c "$RES"; check "http2 off, resolver set -> impacted by CVE-2026-123634 only" 1 \ + " http/2: off ($RES) OK" " resolver: on, resolver 10.0.0.2 valid=30s ($RES) [!]" " => [!] impacted: CVE-2026-123634" + +for spec in \ + "0.6.17|0|nginx/0.6.17 (older than 0.6.18) OK" \ + "0.6.18|0|nginx/0.6.18: CVE-2026-123634 [!]" \ + "1.9.4|0|nginx/1.9.4: CVE-2026-123634 [!]" \ + "1.9.5|1|nginx/1.9.5: CVE-2026-123007 CVE-2026-123634 [!]" \ + "1.19.6|1|nginx/1.19.6: CVE-2026-123007 CVE-2026-123634 [!]" \ + "1.19.7|1|nginx/1.19.7: $ALL3 [!]" \ + "1.29.8|1|nginx/1.29.8: $ALL3 [!]" \ + "1.30.6|1|nginx/1.30.6: $ALL3 [!]" \ + "1.30.7|0|nginx/1.30.7 (fixed) OK" \ + "1.30.12|0|nginx/1.30.12 (fixed) OK" \ + "1.31.0|1|nginx/1.31.0: $ALL3 [!]" \ + "1.31.8|1|nginx/1.31.8: $ALL3 [!]" \ + "1.31.9|0|nginx/1.31.9 (fixed) OK" \ + "1.32.0|0|nginx/1.32.0 (fixed) OK" \ + "1.24.0 (Ubuntu)|1|nginx/1.24.0 (Ubuntu): $ALL3 [!]"; do + v=${spec%%|*}; rest=${spec#*|}; want=${rest%%|*}; text=${rest#*|} + V "nginx/$v"; run "${F[@]}" -c "$H2ON"; check "version $v (http2 on)" "$want" "$text" +done +V "nginx/0.6.18"; run "${F[@]}" -c "$RES"; check "0.6.18 with a resolver -> impacted" 1 "http/2: - n/a" "=> [!] impacted: CVE-2026-123634" +V "nginx/1.19.6"; run "${F[@]}" -c "$H2ON"; check "1.19.6: only CVE-2026-123007 applies" 1 "=> [!] impacted: CVE-2026-123007" +V "nginx/1.30.7"; run "${F[@]}" -c "$H2ON"; check "fixed: later checks not run" 0 " backport: - n/a" " http/2: - n/a" " resolver: - n/a" +V "nginx/1.31.9"; run "${F[@]}" -c "$RES"; check "fixed, resolver set -> ok" 0 " resolver: - n/a" + +echo +echo "## NGINX Plus" +for spec in \ + "nginx/1.27.4 (nginx-plus-r34-p1)|1|$ALL3 [!]" \ + "nginx/1.29.3 (nginx-plus-r36-p8)|1|$ALL3 [!]" \ + "nginx/1.19.5 (nginx-plus-r23)|1|nginx/1.19.5 (nginx-plus-r23): CVE-2026-123007 CVE-2026-123634 [!]" \ + "nginx/1.29.8 (nginx-plus-r37.0.0)|1|$ALL3 [!]" \ + "nginx/1.29.8 (nginx-plus-r37.0.6)|1|$ALL3 [!]" \ + "nginx/1.29.8 (nginx-plus-r37.0.7)|1|(nginx-plus-r37.0.7): CVE-2026-123007 CVE-2026-123634 [!]" \ + "nginx/1.29.8 (nginx-plus-r37.0.8)|0|(nginx-plus-r37.0.8) (fixed) OK" \ + "nginx/1.29.8 (nginx-plus-r37.0.10)|0|(fixed) OK" \ + "nginx/1.31.4 (nginx-plus-r37.1.1)|1|$ALL3 [!]" \ + "nginx/1.31.6 (nginx-plus-r37.2.0)|1|(nginx-plus-r37.2.0): CVE-2026-123007 CVE-2026-123634 [!]" \ + "nginx/1.31.9 (nginx-plus-r37.3.0)|0|(fixed) OK" \ + "nginx/1.33.1 (nginx-plus-r38.0.0)|0|(fixed) OK" \ + "nginx/1.29.8 (nginx-plus-r37)|2|(NGINX Plus release not recognized) [?]" \ + "nginx/1.29.8 (nginx-plus-rX)|2|(NGINX Plus release not recognized) [?]"; do + v=${spec%%|*}; rest=${spec#*|}; want=${rest%%|*}; text=${rest#*|} + V "$v"; run "${F[@]}" -c "$H2ON"; check "plus $v" "$want" "$text" +done +V "nginx/1.29.8 (nginx-plus-r37.0.6)"; run "${F[@]}" -c "$H2ON"; check "plus: no package lookup" 1 "backport: NGINX Plus: fixed only by upgrading [!]" +V "nginx/1.29.8 (nginx-plus-r37.0.6)"; run "${F[@]}" -c "$H2OFF"; check "plus, http2 off, no resolver -> ok" 0 "http/2: off" "resolver: not set" +V "nginx/1.29.8 (nginx-plus-r37.0.7)"; run "${F[@]}" -c "$RES"; check "plus 37.0.7, resolver -> CVE-2026-123634" 1 "=> [!] impacted: CVE-2026-123634" +V "nginx/1.29.8 (nginx-plus-r37)"; run "${F[@]}" -c "$H2OFF"; check "plus unrecognized, nothing exposed -> ok" 0 "http/2: off" "resolver: not set" + +echo +echo "## Forks" +V "openresty/1.27.1.2"; run "${F[@]}" -c "$H2ON"; check "openresty affected core, h2 on -> unknown" 2 "openresty/1.27.1.2 (nginx 1.27.1 core; check OpenResty's advisory) [?]" "backport: - n/a" "http/2: on" +V "openresty/1.27.1.2"; run "${F[@]}" -c "$H2OFF"; check "openresty affected core, h2 off, no resolver -> ok" 0 "http/2: off" "resolver: not set" +V "openresty/1.27.1.2"; run "${F[@]}" -c "$RES"; check "openresty affected core, resolver -> unknown" 2 "resolver: on" +V "openresty/1.31.9.1"; run "${F[@]}" -c "$H2ON"; check "openresty fixed core -> ok" 0 "openresty/1.31.9.1 (nginx 1.31.9 core, fixed) OK" +V "Angie/1.10.2"; run "${F[@]}" -c "$H2ON"; check "angie -> unknown" 2 "Angie/1.10.2 (nginx fork; check the vendor's advisory) [?]" +V "freenginx/1.29.0"; run "${F[@]}" -c "$H2ON"; check "freenginx -> unknown" 2 "freenginx/1.29.0 (nginx fork" +unset FAKE_VLINE + +echo +echo "## Build and run" +run env FAKE_NO_H2=1 "${F[@]}" -c "$H2ON"; check "no http_v2 module -> ok" 0 "http/2: not built (no --with-http_v2_module) OK" +run env FAKE_NO_H2=1 "${F[@]}" -c "$RES"; check "no http_v2 module, resolver -> CVE-2026-123634" 1 "http/2: not built" "=> [!] impacted: CVE-2026-123634" +run env FAKE_FAIL=1 "${F[@]}" -c "$H2ON"; check "binary fails to run -> unknown" 2 " run: fake-nginx: error while loading shared libraries: libssl.so.3 [?]" +run bash "$S" --no-procs --no-disk -n "$WORK/nope"; check "missing -n binary -> unknown" 2 "$WORK/nope (-n)" "binary: not an executable file [?]" +run bash "$S" --bogus; check "unknown argument -> usage" 3 "usage: detect-nginx-http2.sh" +run bash "$S" -n; check "-n without a value -> usage" 3 +run bash "$S" --help +if [ "$CODE" = 0 ]; then PASS=$((PASS + 1)); echo "PASS --help exits 0"; else FAIL=$((FAIL + 1)); echo "FAIL --help exit $CODE"; fi +run bash "$S" --no-procs --no-disk; check "nothing to check -> not impacted" 0 "no nginx found" + +echo +echo "## Config parsing" +P=$(conf p1/nginx.conf <<'EOF' +events {} +http { + server { listen 443 ssl http2; } # listen parameter +} +EOF +); run "${F[@]}" -c "$P"; check "listen ... http2" 1 "http/2: on, listen 443 ssl http2 ($P) [!]" + +P=$(conf p2/nginx.conf <<'EOF' +http { + http2 on; + server { listen 443 ssl; } +} +EOF +); run "${F[@]}" -c "$P"; check "http-level http2 on inherited" 1 "http/2: on, http2 on ($P) [!]" + +P=$(conf p3/nginx.conf <<'EOF' +http { + server { listen 443 ssl; http2 off; } + http2 on; + server { listen 8443 ssl; http2 off; } +} +EOF +); run "${F[@]}" -c "$P"; check "http-level on, every server off -> off" 0 "http/2: off" + +P=$(conf p4/nginx.conf <<'EOF' +http { + server { listen 80; http2 off; } + server { listen 81; http2 "on"; } +} +EOF +); run "${F[@]}" -c "$P"; check "quoted on in a second server" 1 "http/2: on, http2 on ($P) [!]" + +P=$(conf p5/nginx.conf <<'EOF' +http { + # http2 on; + server { + listen 80; # listen 443 ssl http2; + add_header X-Note "http2 on;"; + return 200 'listen 1 http2;'; + } +} +EOF +); run "${F[@]}" -c "$P"; check "comments and strings ignored" 0 "http/2: off" + +P=$(conf p6/nginx.conf <<'EOF' +http { + server { + listen 80; + location / { + content_by_lua_block { + local t = { a = "}", b = [[ } ]] } -- a } in a comment + if #t == 0 then ngx.say("http2 on;") end + --[==[ long comment with } and {{ ]==] + local s = '{' .. "\"}" + } + } + } +} +EOF +); run "${F[@]}" -c "$P"; check "lua block skipped, no false positive" 0 "http/2: off" + +P=$(conf p7/nginx.conf <<'EOF' +http { + server { + listen 80; + access_by_lua_block { if ngx.var.x == "}" then return end } + set $p "${uri}x"; + http2 on; + } +} +EOF +); run "${F[@]}" -c "$P"; check "directive after a lua block and \${var}" 1 "http/2: on, http2 on ($P) [!]" + +P=$(conf p8/nginx.conf <<'EOF' +stream { + server { listen 12345; } +} +mail { + server { listen 25; } +} +http { + upstream b { server 127.0.0.1:8080; } + server { listen 80; location / { proxy_pass http://b; } } +} +EOF +); run "${F[@]}" -c "$P"; check "stream, mail and upstream servers ignored" 0 "http/2: off" + +P=$(conf r1/nginx.conf <<'EOF' +stream { + resolver 1.1.1.1; + server { listen 53 udp; proxy_pass dns.example:53; } +} +mail { + resolver 1.1.1.1; + server { listen 25; } +} +http { + # resolver 8.8.8.8; + server { listen 80; return 200 "resolver 8.8.8.8;"; } +} +EOF +); run "${F[@]}" -c "$P"; check "stream, mail, commented and quoted resolvers ignored" 0 "resolver: not set ($P) OK" + +P=$(conf r2/nginx.conf <<'EOF' +http { + server { + listen 80; + location /api/ { + resolver 127.0.0.11 ipv6=off; + set $b api.internal; + proxy_pass http://$b; + } + } +} +EOF +); run "${F[@]}" -c "$P"; check "resolver in a location" 1 "resolver: on, resolver 127.0.0.11 ipv6=off ($P) [!]" "=> [!] impacted: CVE-2026-123634" + +P=$(conf r3/nginx.conf <<'EOF' +http { + upstream backend { + zone backend 64k; + resolver 10.96.0.10 valid=10s; + server backend.svc.cluster.local:8080 resolve; + } + server { listen 80; location / { proxy_pass http://backend; } } +} +EOF +); run "${F[@]}" -c "$P"; check "resolver in an upstream" 1 "resolver: on, resolver 10.96.0.10 valid=10s ($P) [!]" + +mkdir -p "$WORK/r4/conf.d" +P=$(conf r4/nginx.conf <<'EOF' +http { + include conf.d/*.conf; +} +EOF +) +conf r4/conf.d/resolver.conf >/dev/null <<'EOF' +resolver 169.254.169.253; +EOF +run "${F[@]}" -c "$P"; check "resolver in an included file" 1 "resolver 169.254.169.253 ($WORK/r4/conf.d/resolver.conf) [!]" + +mkdir -p "$WORK/inc/conf.d" "$WORK/inc/snippets" "$WORK/inc/sites-available" "$WORK/inc/sites-enabled" +P=$(conf inc/nginx.conf <<'EOF' +events {} +http { + include mime.types*; + include conf.d/*.conf; + include sites-enabled/*; +} +EOF +) +conf inc/conf.d/a.conf >/dev/null <<'EOF' +server { listen 80; } +EOF +run "${F[@]}" -c "$P"; check "includes, no http2 -> off" 0 "http/2: off" +conf inc/snippets/listen.conf >/dev/null <<'EOF' +listen 443 ssl http2; +EOF +conf inc/sites-available/site >/dev/null < unknown" 2 "http/2: config unreadable: $WORK/miss/absent.conf" "resolver: config unreadable: $WORK/miss/absent.conf" + +run "${F[@]}" -c "$WORK/none/nginx.conf"; check "missing main config -> unknown" 2 "http/2: config unreadable: $WORK/none/nginx.conf" + +P=$(conf loop/nginx.conf <<'EOF' +http { + include nginx.conf; +} +EOF +); run "${F[@]}" -c "$P"; check "include loop terminates -> unknown" 2 "includes nested too deep" + +P=$(conf builtin/nginx.conf <<'EOF' +http { server { listen 443 ssl http2; } } +EOF +); run env FAKE_CONF="$P" bash "$S" --no-procs --no-disk -n "$FAKE"; check "built-in --conf-path used" 1 "($P) [!]" +mkdir -p "$WORK/pfx/conf"; cp "$P" "$WORK/pfx/conf/nginx.conf" +run env FAKE_PREFIX="$WORK/pfx/" FAKE_CONF=conf/nginx.conf bash "$S" --no-procs --no-disk -n "$FAKE"; check "relative --conf-path under --prefix" 1 "($WORK/pfx/conf/nginx.conf) [!]" + +echo +echo "## SSH wrapper (stub ssh and sudo)" + +# The ssh stub runs the remote command locally. The sudo stub fails the way +# "sudo -n" does without passwordless sudo when STUB_SUDO=deny, and otherwise +# runs the command. +STUB="$WORK/stub" +mkdir -p "$STUB" +cat > "$STUB/ssh" <<'EOF' +#!/bin/sh +while [ $# -gt 1 ]; do shift; done +exec sh -c "$1" +EOF +cat > "$STUB/sudo" <<'EOF' +#!/bin/sh +[ "${1:-}" = -n ] && shift +if [ "${STUB_SUDO:-}" = deny ]; then echo "sudo: a password is required" >&2; exit 1; fi +exec "$@" +EOF +printf 'exit 1\n' > "$WORK/no-verdict.sh" +chmod +x "$STUB/ssh" "$STUB/sudo" +printf 'host-a\n' > "$WORK/hosts" +W="$HERE/../ssh-nginx-http2.sh" + +# wrap CONF [VAR=value]...: runs the wrapper on one host against the fake nginx +wrap() { + local c=$1 + shift + run env PATH="$STUB:$PATH" FAKE_VLINE="nginx version: nginx/1.24.0" \ + DETECT_ARGS="-q --no-procs --no-disk -n $FAKE -c $c" "$@" sh "$W" "$WORK/hosts" "$WORK/res" +} +# wcheck NAME WANT_CODE WANT_STATUS [MUST_CONTAIN]... +wcheck() { + local name=$1 want=$2 st=$3 ok=1 c got + shift 3 + got=$(cut -f1 "$WORK/res/.all" 2>/dev/null) + [ "$CODE" = "$want" ] && [ "$got" = "$st" ] || ok=0 + for c in "$@"; do printf '%s\n' "$OUT" | grep -qF -- "$c" || ok=0; done + if [ "$ok" -eq 1 ]; then + PASS=$((PASS + 1)) + echo "PASS $name" + else + FAIL=$((FAIL + 1)) + echo "FAIL $name (want exit $want '$st'; got exit $CODE '$got')" + printf '%s\n' "$OUT" | sed 's/^/ | /' + fi +} + +wrap "$H2ON"; wcheck "wrapper: impacted host" 1 "impacted" "impacted: host-a" +wrap "$H2OFF"; wcheck "wrapper: not impacted host" 0 "not impacted" "not impacted: host-a" +wrap "$H2ON" STUB_SUDO=deny; wcheck "wrapper: sudo needs a password -> error, not impacted" 2 \ + "error (sudo needs a password)" "impacted: (none)" "hint: sudo -n needs passwordless sudo" +wrap "$H2ON" STUB_SUDO=deny SUDO=""; wcheck "wrapper: SUDO=\"\" skips sudo" 1 "impacted" +wrap "$H2ON" DETECT="$WORK/no-verdict.sh"; wcheck "wrapper: exit 1 without a verdict line -> error" 2 "error (no verdict, rc=1)" + +# --- 2. Real nginx in containers ---------------------------------------------------- + +# in CONTAINER [ARGS...]: runs the detector inside CONTAINER as root +in_c() { local c=$1; shift; docker exec -i "$c" bash -s -- "$@" < "$S"; } +# in_as USER CONTAINER [ARGS...] +in_as() { local u=$1 c=$2; shift 2; docker exec -i -u "$u" "$c" bash -s -- "$@" < "$S"; } +sh_in() { docker exec "$1" sh -c "$2"; } + +# changelog_fixed CONTAINER: 0 if the distro nginx changelog lists all three CVEs +changelog_fixed() { + local t + t=$(sh_in "$1" 'if [ -d /var/lib/dpkg ]; then zcat /usr/share/doc/nginx/changelog.Debian.gz; else rpm -q --changelog nginx-core; fi' 2>/dev/null) + printf '%s' "$t" | grep -q CVE-2026-123007 && printf '%s' "$t" | grep -q CVE-2026-123633 && + printf '%s' "$t" | grep -q CVE-2026-123634 +} + +if [ "$DOCKER" -eq 0 ]; then + echo + echo "## Docker not available: skipping real nginx and container scan tests" +else + echo + echo "## Real nginx in containers" + C_ORG=$CPFX-org; C_ALP=$CPFX-alp; C_OR=$CPFX-or; C_DEB=$CPFX-deb; C_UBU=$CPFX-ubu; C_ALMA=$CPFX-alma + CONTAINERS="$C_ORG $C_ALP $C_OR $C_DEB $C_UBU $C_ALMA" + docker run -d --name "$C_ORG" --hostname "$C_ORG" "$IMG_ORG" >/dev/null + docker run -d --name "$C_ALP" --hostname "$C_ALP" "$IMG_ALPINE" >/dev/null + docker run -d --name "$C_OR" --hostname "$C_OR" "$IMG_OPENRESTY" >/dev/null + docker run -d --name "$C_DEB" --hostname "$C_DEB" "$IMG_DEBIAN" sleep infinity >/dev/null + docker run -d --name "$C_UBU" --hostname "$C_UBU" "$IMG_UBUNTU" sleep infinity >/dev/null + docker run -d --name "$C_ALMA" --hostname "$C_ALMA" "$IMG_ALMA" sleep infinity >/dev/null + echo "installing distro nginx packages..." + (sh_in "$C_ALP" 'apk add -q bash' >/dev/null 2>&1) & + (sh_in "$C_DEB" 'apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx' >/dev/null 2>&1) & + (sh_in "$C_UBU" 'apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx' >/dev/null 2>&1) & + (sh_in "$C_ALMA" 'dnf -y -q install nginx' >/dev/null 2>&1) & + wait + + run in_c "$C_ORG"; check "nginx.org image, stock config -> ok" 0 \ + "/usr/sbin/nginx (pid 1)" "nginx.org package: fixed only by upgrading [!]" "http/2: off (/etc/nginx/nginx.conf) OK" + sh_in "$C_ORG" 'printf "server {\n listen 8443;\n http2 on;\n}\n" > /etc/nginx/conf.d/h2.conf && nginx -s reload' 2>/dev/null + run in_c "$C_ORG"; check "nginx.org image, http2 on -> impacted" 1 "http/2: on, http2 on (/etc/nginx/conf.d/h2.conf) [!]" + + run in_c "$C_ALP"; check "nginx.org alpine, stock config -> ok" 0 "(apk), nginx.org package" "resolver: not set" + # HTTP/2 off, resolver on: CVE-2026-123634 alone, which turning HTTP/2 off does not mitigate. + sh_in "$C_ALP" 'printf "resolver 127.0.0.11 valid=10s;\n" > /etc/nginx/conf.d/01-resolver.conf && nginx -s reload' 2>/dev/null + run in_c "$C_ALP"; check "nginx.org alpine, resolver only -> CVE-2026-123634" 1 \ + "http/2: off (/etc/nginx/nginx.conf) OK" "resolver: on, resolver 127.0.0.11 valid=10s (/etc/nginx/conf.d/01-resolver.conf) [!]" \ + "=> [!] impacted: CVE-2026-123634" + sh_in "$C_ALP" 'printf "http2 on;\n" > /etc/nginx/conf.d/00-h2.conf && nginx -s reload' 2>/dev/null + run in_c "$C_ALP"; check "nginx.org alpine, http2 and resolver -> all three" 1 "http/2: on, http2 on (/etc/nginx/conf.d/00-h2.conf) [!]" \ + "=> [!] impacted: CVE-2026-123007 CVE-2026-123633 CVE-2026-123634" + + run in_c "$C_OR"; check "openresty, stock config -> ok" 0 "check OpenResty's advisory) [?]" "http/2: off" + docker exec -i "$C_OR" sh -c 'cat > /etc/nginx/conf.d/lua.conf && openresty -s reload' 2>/dev/null <<'EOF' +server { + listen 8081; + location / { + content_by_lua_block { + local t = { a = "}" , b = [[ } ]] } -- a } in a comment + if #t == 0 then ngx.say("http2 on;") end + } + } + http2 on; +} +EOF + run in_c "$C_OR"; check "openresty, http2 on after lua -> unknown" 2 "http/2: on, http2 on (/etc/nginx/conf.d/lua.conf) [!]" + + run in_c "$C_DEB"; check "debian package installed, not running -> ok" 0 "/usr/sbin/nginx (installed)" "(dpkg)" "http/2: off" + for c in "$C_DEB" "$C_UBU" "$C_ALMA"; do + sh_in "$c" ' + printf "server {\n listen 8080 http2;\n}\n" > /etc/nginx/h2site + if [ -d /etc/nginx/sites-enabled ]; then + mv /etc/nginx/h2site /etc/nginx/sites-available/h2site + ln -sf /etc/nginx/sites-available/h2site /etc/nginx/sites-enabled/h2site + else + mv /etc/nginx/h2site /etc/nginx/conf.d/h2site.conf + fi + nginx' >/dev/null 2>&1 + done + for c in "$C_DEB" "$C_UBU" "$C_ALMA"; do + if changelog_fixed "$c"; then + run in_c "$c"; check "$c: distro fix in changelog -> ok" 0 "changelog lists CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 OK" + else + run in_c "$c"; check "$c: no fix in changelog, listen http2 -> impacted" 1 "backport: " "changelog " "/usr/sbin/nginx (pid " "!(installed)" + fi + done + run in_c "$C_DEB"; check "debian: absolute sites-enabled symlink followed" "$CODE" "listen 8080 http2 (/etc/nginx/sites-enabled/h2site)" + run in_c "$C_ALMA"; check "alma: rpm package" "$CODE" "nginx-core " "(rpm)" + + # Vendor backports: prepend changelog entries naming some or all CVEs. + sh_in "$C_DEB" 'cd /usr/share/doc/nginx && { printf "nginx (9:1) trixie-security; urgency=high\n\n * Fix CVE-2026-123007, CVE-2026-123633, CVE-2026-123634\n\n"; zcat changelog.Debian.gz; } | gzip -9n > c.gz && mv c.gz changelog.Debian.gz' + sh_in "$C_UBU" 'cd /usr/share/doc/nginx && { printf "nginx (9:1) noble-security; urgency=medium\n\n * SECURITY UPDATE: CVE-2026-123007\n\n"; zcat changelog.Debian.gz; } | gzip -9n > c.gz && mv c.gz changelog.Debian.gz' + run in_c "$C_DEB"; check "debian: backport of all three -> ok" 0 "changelog lists CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 OK" "http/2: - n/a" "resolver: - n/a" + if ! changelog_fixed "$C_UBU"; then + run in_c "$C_UBU"; check "ubuntu: backport of one -> impacted by the rest" 1 \ + "changelog lists CVE-2026-123007 but not CVE-2026-123633 CVE-2026-123634 [!]" "=> [!] impacted: CVE-2026-123633" + fi + + # Upgraded on disk, not restarted: the running binary is the old one. + sh_in "$C_DEB" 'cp -p /usr/sbin/nginx /usr/sbin/nginx.new && mv /usr/sbin/nginx.new /usr/sbin/nginx' + run in_c "$C_DEB"; check "debian: binary replaced, not restarted -> impacted" 1 \ + "binary replaced on disk since start" "this process still runs the binary it replaced: restart nginx [!]" + sh_in "$C_DEB" 'nginx -s stop; sleep 1; nginx' >/dev/null 2>&1 + run in_c "$C_DEB"; check "debian: restarted -> ok" 0 "changelog lists CVE-2026-123007 CVE-2026-123633 CVE-2026-123634 OK" + + # A master started with -c: that file is read, not the built-in default. + # (nginx 1.20 predates the "http2" directive, so use the listen parameter.) + sh_in "$C_ALMA" 'nginx -s stop; sleep 1; mkdir -p /srv && printf "events {}\nhttp {\n server { listen 8090 http2; }\n}\n" > /srv/alt.conf && nginx -c /srv/alt.conf' >/dev/null 2>&1 + if ! changelog_fixed "$C_ALMA"; then + run in_c "$C_ALMA"; check "alma: master started with -c" 1 "http/2: on, listen 8090 http2 (/srv/alt.conf) [!]" "/usr/sbin/nginx (pid " + fi + + # Not root: the master's binary cannot be read. (The installed copy can, + # and is OK after the backport above, so the master decides the verdict.) + run in_as nobody "$C_DEB"; check "not root -> master unreadable, unknown" 2 \ + "not root" "nginx: master process" "path unreadable, run as root [?]" "/usr/sbin/nginx (installed)" + + echo + echo "## Container scan (privileged --pid=host, like the DaemonSet)" + C_SCAN=$CPFX-scan + CONTAINERS="$CONTAINERS $C_SCAN" + run docker run --rm -i --name "$C_SCAN" --privileged --pid=host "$IMG_DEBIAN" bash -s -- --no-disk < "$S" + check "every container found through nsenter" 1 \ + "http/2: on, http2 on (/etc/nginx/conf.d/h2.conf) [!]" \ + "http/2: on, http2 on (/etc/nginx/conf.d/00-h2.conf) [!]" \ + "http/2: on, http2 on (/etc/nginx/conf.d/lua.conf) [!]" \ + "changelog lists CVE-2026-123007 but not CVE-2026-123633 CVE-2026-123634" \ + "(/etc/nginx/conf.d/01-resolver.conf) [!]" \ + "(/srv/alt.conf)" "(apk)" "(rpm)" ", container $C_ORG)" ", container $C_ALMA)" "!in a container, run as root" + n=$(printf '%s\n' "$OUT" | grep -cE ', container [A-Za-z0-9._-]+\)$') + if [ "$n" -ge 6 ]; then PASS=$((PASS + 1)); echo "PASS six or more containerized masters ($n)"; else FAIL=$((FAIL + 1)); echo "FAIL expected >= 6 containerized masters, got $n"; fi +fi + +echo +echo "passed: $PASS failed: $FAIL" +[ "$FAIL" -eq 0 ] diff --git a/README.md b/README.md index ee1c55d..f1584bc 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,4 @@ Where possible, detections are written to be fleet-policy compatible - known una | Directory | What it detects | |---|---| | `CVE-2026-114938/` | JVMs exposed to the HotSpot x86-64 AVX-512 Base64 decode heap overwrite (CVE-2026-114938, JDK-8392044) | +| `CVE-2026-123633.CVE-2026-123007/` | nginx exposed to the HTTP/2 flow-control overflow (CVE-2026-123007) or use-after-free (CVE-2026-123633) with HTTP/2 on, or to the resolver use-after-free (CVE-2026-123634) with a `resolver` configured |