Created
October 23, 2026 09:57
-
-
Save peterhellberg/6f41ada11cb14156aea46d64fe662182 to your computer and use it in GitHub Desktop.
Checks whether a Docker image trusts the compromised eMudhra intermediate CAs described at https://emudhra.we-have-a-problem.com/
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
| #!/bin/sh | |
| # Verifies the eMudhra advisory's published chains against the CA bundle in a docker image, | |
| # and that its Go toolchain (if any) has the crypto/x509 denylist from go1.26.10/go1.27.3. | |
| # Usage: emudhra-check.sh <image> (exit 1: vulnerable, 2: no CA bundle, 3: inconclusive) | |
| set -eu | |
| img=${1:?usage: $0 <image>} | |
| tmp=$(mktemp -d) | |
| trap 'rm -rf "$tmp"' EXIT | |
| curl -sSfLo "$tmp/chains.zip" https://emudhra.we-have-a-problem.com/chains.zip | |
| unzip -q "$tmp/chains.zip" -d "$tmp/chains" | |
| cid=$(docker create "$img" x) | |
| for p in /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/cert.pem; do | |
| docker cp -L "$cid:$p" "$tmp/ca.pem" 2>/dev/null && break | |
| done | |
| docker rm "$cid" >/dev/null | |
| [ -s "$tmp/ca.pem" ] || { echo "no CA bundle found in $img" >&2; exit 2; } | |
| red= green= off= | |
| [ -t 1 ] && red=$(printf '\033[31m') green=$(printf '\033[32m') off=$(printf '\033[0m') | |
| total=0 trusted=0 odd=0 | |
| for f in $(find "$tmp/chains" -name '*.pem' | sort); do | |
| rm -f "$tmp/leaf.pem" "$tmp/inter.pem" | |
| awk -v d="$tmp" '/BEGIN CERT/{n++} {print > (d "/" (n==1 ? "leaf" : "inter") ".pem")}' "$f" | |
| u=; [ -s "$tmp/inter.pem" ] && u="-untrusted $tmp/inter.pem" | |
| name=$(basename "$f" .pem); name=${name%.we-have-a-problem.com} | |
| total=$((total + 1)) | |
| if out=$(openssl verify -CAfile "$tmp/ca.pem" $u "$tmp/leaf.pem" 2>&1); then | |
| printf '%s✗ TRUSTED %s%s\n' "$red" "$name" "$off"; trusted=$((trusted + 1)) | |
| elif echo "$out" | grep -q 'error 20 '; then | |
| printf '%s✓%s rejected %s\n' "$green" "$off" "$name" | |
| else | |
| printf '? unexpected %s: %s\n' "$name" "$(echo "$out" | grep -m1 error)"; odd=$((odd + 1)) | |
| fi | |
| done | |
| gobad=0 | |
| if v=$(docker run --rm --entrypoint go -e GOTOOLCHAIN=local "$img" env GOVERSION 2>/dev/null); then | |
| echo | |
| minor=$(echo "$v" | cut -d. -f2); minor=${minor%%[!0-9]*} | |
| patch=$(echo "$v" | cut -d. -f3); patch=${patch%%[!0-9]*}; patch=${patch:-0} | |
| if [ "$minor" -ge 28 ] || { [ "$minor" -eq 27 ] && [ "$patch" -ge 3 ]; } || { [ "$minor" -eq 26 ] && [ "$patch" -ge 10 ]; }; then | |
| printf '%s✓%s patched %s\n' "$green" "$off" "$v" | |
| else | |
| printf '%s✗ UNPATCHED %s, needs go1.26.10 or go1.27.3+%s\n' "$red" "$v" "$off"; gobad=1 | |
| fi | |
| fi | |
| if [ "$trusted" -gt 0 ] || [ "$gobad" -eq 1 ]; then | |
| printf '\n%s%s: VULNERABLE%s\n' "$red" "$img" "$off"; exit 1 | |
| fi | |
| if [ "$odd" -gt 0 ]; then | |
| printf "\n%s: inconclusive, %d of %d chains failed for another reason\n" "$img" "$odd" "$total"; exit 3 | |
| fi | |
| printf '\n%s%s: not vulnerable, all %d chains rejected%s\n' "$green" "$img" "$total" "$off" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment