Created
October 22, 2026 02:12
-
-
Save ivan/fee528ac3970a9683cd6384ed37d37e1 to your computer and use it in GitHub Desktop.
LLM-authored slop script to scan NixOS for bundled brotli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Model-output: Claude Opus 5.5 | |
| # | |
| # Read-only triage for CVE-2026-111497 (brotli decoder out-of-bounds write, fixed upstream in | |
| # google/brotli@0ed4268a): which running or installed binaries carry an unfixed decoder, and | |
| # whether anything crashed the way a failed exploit attempt would. | |
| # | |
| # Usage: ssh root@HOST bash -s -- [--closure] [SINCE] < check-brotli-cve.sh | |
| # --closure also scan the /run/current-system closure (about 1 minute per 2000 store paths) | |
| # SINCE start of the crash search; default 2026-02-27, when the upstream fix went public | |
| set -u | |
| export LC_ALL=C # byte-wise grep; several times faster on binaries | |
| # Every brotli decoder's error table contains the first name; fixed ones also contain the second. | |
| # Known false positive: the Rust port (deno) carries the names but not the vulnerable C code. | |
| decoder_marker=_ERROR_FORMAT_BLOCK_LENGTH_1 | |
| fixed_marker=_ERROR_FORMAT_BLOCK_SWITCH | |
| # Process names (comm, max 15 chars) of runtimes whose fetch() decodes brotli with an affected decoder. | |
| runtime_comms='node|bun|claude|[.]claude-wrapped' | |
| # Print "fixed" or "UNFIXED" for an ELF file that contains a brotli decoder; fail otherwise. | |
| # $1: readable path to the file (may be a /proc/PID/map_files/ entry) | |
| classify() { | |
| [[ $(head -c4 "$1" 2>/dev/null) == $'\x7fELF' ]] || return 1 | |
| grep -qaF "$decoder_marker" "$1" || return 1 | |
| if grep -qaF "$fixed_marker" "$1"; then echo fixed; else echo UNFIXED; fi | |
| } | |
| # Print "PID<TAB>readable path<TAB>mapped path" once per file a process has mapped executable. | |
| # As root, the readable path goes through /proc/PID/map_files, which also reaches files that were | |
| # deleted (garbage-collected store paths) or live in another mount namespace (containers). | |
| exec_mappings() { | |
| local maps pid | |
| for maps in /proc/[0-9]*/maps; do | |
| pid=${maps#/proc/} | |
| pid=${pid%/maps} | |
| awk -v pid="$pid" -v root=$((EUID == 0)) '$2 ~ /x/ && $6 ~ /^\// { | |
| path = substr($0, index($0, $6)) | |
| if (!seen[path]++) print pid "\t" (root ? "/proc/" pid "/map_files/" $1 : path) "\t" path | |
| }' "$maps" 2>/dev/null | |
| done | |
| } | |
| # Describe a process on one line: PID, user, systemd unit (cgroup), start time and command line. | |
| # $1: PID | |
| describe_process() { | |
| local cgroup | |
| cgroup=$(sed -n 's/^0:://p' "/proc/$1/cgroup" 2>/dev/null) | |
| ps -o pid=,user=,lstart=,args= -p "$1" | awk -v cg="${cgroup:-?}" '{ $1 = $1 " " cg; print substr($0, 1, 220) }' | |
| } | |
| # For each running process that maps an unfixed decoder, describe it and its child processes | |
| # (a shell or downloader spawned by a network service is the classic sign of code execution). | |
| check_processes() { | |
| local -A verdict pids | |
| local pid readable path child | |
| while IFS=$'\t' read -r pid readable path; do | |
| [[ -v verdict[$path] ]] || verdict[$path]=$(classify "$readable") | |
| [[ ${verdict[$path]} == UNFIXED ]] && pids[$path]+=" $pid" | |
| done < <(exec_mappings) | |
| for path in "${!pids[@]}"; do | |
| echo "UNFIXED $path" | |
| for pid in ${pids[$path]}; do | |
| describe_process "$pid" | sed 's/^/ /' | |
| for child in $(ps -o pid= --ppid "$pid"); do | |
| describe_process "$child" | sed 's/^/ child /' | |
| done | |
| done | |
| done | |
| } | |
| # List every ELF file with a brotli decoder in the current system closure, with its verdict. | |
| check_closure() { | |
| local f v | |
| nix-store -qR /run/current-system | xargs grep -rlaF "$decoder_marker" 2>/dev/null | sort -u | | |
| while read -r f; do | |
| v=$(classify "$f") && echo "$v $f" | |
| done | |
| } | |
| # Show journal evidence of memory-corruption crashes: kernel segfault reports (which name the | |
| # faulting library), fatal signals and heap-corruption aborts in services, and core dumps | |
| # whose stack trace passes through brotli. Crashes inside Nix builds are left out. | |
| # $1: journalctl --since value | |
| check_crashes() { | |
| local nixbld_gid | |
| nixbld_gid=$(getent group nixbld | cut -d: -f3) | |
| echo "journal coverage starts $(journalctl -q -o short-iso --no-pager | head -n1 | cut -d' ' -f1)" | |
| echo "-- kernel: segfaults and traps" | |
| journalctl -q -o short-iso --no-pager --since "$1" _TRANSPORT=kernel \ | |
| -g 'segfault at|general protection|traps:' | tail -n 50 | |
| echo "-- services: core dumps, fatal signals, heap corruption, V8 fatal errors" | |
| journalctl -q -o short-iso --no-pager --since "$1" \ | |
| -g 'code=dumped|status=(4/ILL|6/ABRT|7/BUS|11/SEGV)|double free|corrupted (size|top|double-linked)|malloc\(\): |free\(\): invalid|FATAL ERROR:' | | |
| grep -vF ' execsnoop[' | tail -n 50 | |
| echo "-- core dumps" | |
| # Columns: weekday date time zone PID UID GID SIG ... | |
| coredumpctl list -q --no-pager --since "$1" 2>/dev/null | awk -v g="${nixbld_gid:--1}" '$7 != g' | tail -n 30 | |
| echo "-- core dumps with brotli in the stack" | |
| journalctl -q -o cat --no-pager --since "$1" -t systemd-coredump -g '[Bb]rotli' | tail -n 50 | |
| } | |
| # If execsnoop logs to the journal, count programs started by runtime processes, by parent and | |
| # child name. A server-side runtime that starts sh, curl or python is what code execution looks like. | |
| # $1: journalctl --since value | |
| check_runtime_execs() { | |
| if [[ -z $(journalctl -q -n1 -t execsnoop --no-pager 2>/dev/null) ]]; then | |
| echo "(no execsnoop logs)" | |
| return | |
| fi | |
| # Columns: time UID COMM PID PCOMM PPID ... | |
| journalctl -q -o cat --no-pager --since "$1" -t execsnoop | | |
| awk -v re="^($runtime_comms)\$" '$5 ~ re { n[$5 " -> " $3]++ } END { for (k in n) print n[k], k }' | | |
| sort -rn | head -n 40 | |
| } | |
| main() { | |
| local closure=0 | |
| [[ ${1-} == --closure ]] && { closure=1; shift; } | |
| local since=${1:-2026-02-27} | |
| echo "== $(hostname): $(readlink /run/current-system); booted $(readlink /run/booted-system)" | |
| ((EUID == 0)) || echo "warning: not root; other users' processes and journal entries are missing" | |
| echo "== running processes that map an unfixed brotli decoder" | |
| check_processes | |
| if ((closure)); then | |
| echo "== brotli decoders in /run/current-system" | |
| check_closure | |
| fi | |
| echo "== crash traces since $since" | |
| check_crashes "$since" | |
| echo "== programs started by $runtime_comms processes since $since" | |
| check_runtime_execs "$since" | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment