#!/usr/bin/env bash # # Containerised differential driver for CVE-2026-76954. # # Synology DSM Auth API pre-auth SQL injection (CWE-89): the truncating # SYNODBEscapeStringEX escape used by SynoPamKeyImpl::DBEscapeStrings writes a # %q-escaped field into a fixed 4096-byte buffer with snprintf. A payload whose # escaped form exceeds 4095 bytes splits a doubled quote, leaves an unbalanced # quote in the INSERT statement, and turns the next attacker-controlled field # into raw SQL executed against syno-pam-key.db. # # The lab runs the REAL, unmodified Synology libraries inside containers: # the vulnerable libsyno-pam-login.so.7.0 of 7.2.2-72806 and the fixed build # shipped in 7.2.2-72806-10, against the real libsynodb.so of the same rootfs. # # ./run-lab.sh prepare download/decrypt public firmware, stage the libraries # ./run-lab.sh build build the lab image and the PoC runner image # ./run-lab.sh up start the vulnerable and fixed services # ./run-lab.sh down stop both services # ./run-lab.sh check classify both services without side effects beyond the probe row # ./run-lab.sh exploit run the full injection chain against both services # ./run-lab.sh probe boundary/field sweep (0-day sweep on the fixed line) # ./run-lab.sh mitigation verify the vendor mitigation and edge filters # ./run-lab.sh matrix version matrix: all four affected branches, vuln vs fixed # ./run-lab.sh evidence capture every artefact into evidence/ # ./run-lab.sh all prepare + build + up + evidence + down # set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$HERE" # ---------------------------------------------------------------- variables NETWORK="${NETWORK:-cve202676954lab}" LAB_IMAGE="${LAB_IMAGE:-cve-2026-76954:vuln}" FIXED_IMAGE="${FIXED_IMAGE:-cve-2026-76954:fixed}" POC_IMAGE="${POC_IMAGE:-cve-2026-76954-poc:local}" VULN_C="${VULN_C:-cve202676954-vuln}" FIXED_C="${FIXED_C:-cve202676954-fixed}" VULN_HOST="${VULN_HOST:-cve202676954-vuln}" FIXED_HOST="${FIXED_HOST:-cve202676954-fixed}" PORT="${PORT:-8080}" CPU="${CPU:-2}" MEM="${MEM:-4g}" EVIDENCE="${EVIDENCE:-$HERE/evidence}" mkdir -p "$EVIDENCE" log() { printf '\n=== %s ===\n' "$*"; } lab_image_exists() { podman image exists "$LAB_IMAGE"; } poc_image_exists() { podman image exists "$POC_IMAGE"; } # ------------------------------------------------------------------ prepare do_prepare() { if [ -f "$HERE/lab/harness/lib/libsyno-pam-login-vuln.so" ] && [ -f "$HERE/lab/harness/lib/libsyno-pam-login-fixed.so" ] && [ -f "$HERE/lab/harness/lib/libsynodb.so" ]; then log "prepare: libraries already staged (delete lab/harness/lib to redo)" return 0 fi bash "$HERE/lab/firmware/prepare.sh" } # -------------------------------------------------------------------- build do_build() { log "building lab image" podman build -q -t "$LAB_IMAGE" -f lab/harness/Dockerfile lab/harness podman tag "$LAB_IMAGE" "$FIXED_IMAGE" if ! poc_image_exists; then log "building PoC runner image" podman build -q -t "$POC_IMAGE" -f poc/Dockerfile poc fi } # ---------------------------------------------------------------------- up do_up() { log "starting services" podman network exists "$NETWORK" 2>/dev/null || podman network create "$NETWORK" podman rm -f "$VULN_C" "$FIXED_C" >/dev/null 2>&1 || true podman run -d --name "$VULN_C" --cpus "$CPU" --memory "$MEM" \ --network "$NETWORK" --hostname "$VULN_HOST" \ -e "PAMLOGIN_LIB=/opt/dsm/lib/libsyno-pam-login-vuln.so" \ -e "LAB_PORT=$PORT" \ --entrypoint python3 "$LAB_IMAGE" /opt/service.py podman run -d --name "$FIXED_C" --cpus "$CPU" --memory "$MEM" \ --network "$NETWORK" --hostname "$FIXED_HOST" \ -e "PAMLOGIN_LIB=/opt/dsm/lib/libsyno-pam-login-fixed.so" \ -e "LAB_PORT=$PORT" \ --entrypoint python3 "$FIXED_IMAGE" /opt/service.py } do_down() { log "stopping services" podman rm -f "$VULN_C" "$FIXED_C" >/dev/null 2>&1 || true } # ------------------------------------------------------------------ poc run poc() { # poc -> echoes the PoC exit code local mode="$1" host="$2" out="$3" rc log "poc $mode -> $host" set +e podman run --rm --cpus "$CPU" --memory 1g --network "$NETWORK" \ -v "$EVIDENCE:/evidence" "$POC_IMAGE" "$mode" "http://$host:$PORT" \ 2>&1 | tee "$out" rc="${PIPESTATUS[0]}" set -e { echo "poc $mode exit code: $rc"; } | tee -a "$out" >/dev/null echo "poc $mode exit code: $rc" return 0 } sql_dump() { # sql_dump podman run --rm --cpus "$CPU" --memory 1g --network "$NETWORK" \ -v "$EVIDENCE:/evidence" --entrypoint python3 "$POC_IMAGE" \ /poc/dump_sql.py "http://$1:$PORT" 2>&1 | tee "$2" } # ----------------------------------------------------------------- evidence poc_rc() { grep -oE "exit code: [0-9]+" "$1" | tail -1 | grep -oE "[0-9]+"; } do_check() { poc check "$VULN_HOST" "$EVIDENCE/check-vulnerable.txt" poc check "$FIXED_HOST" "$EVIDENCE/check-fixed.txt" local vrc frc vrc=$(poc_rc "$EVIDENCE/check-vulnerable.txt") frc=$(poc_rc "$EVIDENCE/check-fixed.txt") log "check exit codes: vulnerable=$vrc (expect 1) fixed=$frc (expect 0)" [ "$vrc" = "1" ] && [ "$frc" = "0" ] } do_exploit() { poc exploit "$VULN_HOST" "$EVIDENCE/exploit-vulnerable.txt" poc exploit "$FIXED_HOST" "$EVIDENCE/exploit-fixed.txt" local vrc frc vrc=$(poc_rc "$EVIDENCE/exploit-vulnerable.txt") frc=$(poc_rc "$EVIDENCE/exploit-fixed.txt") log "exploit exit codes: vulnerable=$vrc (expect 0) fixed=$frc (expect 1)" [ "$vrc" = "0" ] && [ "$frc" = "1" ] } do_probe() { poc probe "$VULN_HOST" "$EVIDENCE/probe-vulnerable.txt" poc probe "$FIXED_HOST" "$EVIDENCE/probe-fixed.txt" } do_mitigation() { poc mitigation "$VULN_HOST" "$EVIDENCE/mitigation-vulnerable.txt" } do_matrix() { log "version matrix (all four branches)" python3 "$HERE/lab/version-matrix.py" > "$EVIDENCE/version-matrix.txt" tail -n +1 "$EVIDENCE/version-matrix.txt" } do_sql() { sql_dump "$VULN_HOST" "$EVIDENCE/sql-vulnerable.txt" sql_dump "$FIXED_HOST" "$EVIDENCE/sql-fixed.txt" } do_escape_ground_truth() { log "escape ground truth (real libsynodb probe)" podman run --rm --cpus "$CPU" --memory 2g "$LAB_IMAGE" escape \ > "$EVIDENCE/escape-probe.txt" 2>&1 cat "$EVIDENCE/escape-probe.txt" } do_versions() { log "capturing versions" python3 - "$HERE/lab/harness/lib" > "$EVIDENCE/versions.txt" <<'PY' import hashlib, sys from pathlib import Path libdir = Path(sys.argv[1]) names = ["libsyno-pam-login-vuln.so", "libsyno-pam-login-fixed.so", "pair-7.2.1-vuln.so", "pair-7.2.1-fixed.so", "pair-7.3.2-vuln.so", "pair-7.3.2-fixed.so", "pair-7.4.1-vuln.so", "pair-7.4.1-fixed.so", "libsynodb.so"] print("# target library versions staged into the lab image (sha256, escape API)") for n in names: p = libdir / n if not p.exists(): print(f"(absent) {n}") continue data = p.read_bytes() api = "SYNODBEscapeStrAllocEX" if b"SYNODBEscapeStrAllocEX" in data else "SYNODBEscapeStringEX" print(f"{hashlib.sha256(data).hexdigest()} {api:24s} {n}") PY cat "$EVIDENCE/versions.txt" } do_evidence() { do_escape_ground_truth do_check do_exploit do_probe do_mitigation do_sql do_versions do_matrix log "evidence captured into $EVIDENCE" } case "${1:-all}" in prepare) do_prepare ;; build) do_build ;; up) do_up ;; down) do_down ;; check) do_check ;; exploit) do_exploit ;; probe) do_probe ;; mitigation) do_mitigation ;; matrix) do_matrix ;; evidence) do_evidence ;; versions) do_versions ;; sql) do_sql ;; all) do_prepare do_build do_up do_evidence do_down ;; *) echo "usage: $0 {prepare|build|up|down|check|exploit|probe|mitigation|matrix|evidence|all}"; exit 2 ;; esac