
Containerized differential PoC and lab for CVE-2026-76954, a pre-auth SQL injection in Synology DSM Auth API caused by a 4095-byte escape truncation, with real DSM libraries.
SynoPamKeyImpl::DBEscapeStrings| CVE | CVE-2026-76954 |
| Component | Synology DiskStation Manager, Auth API — libsyno-pam-login.so.7.0, SynoPamKeyImpl::DBEscapeStrings (syno-pam-key-impl.cpp) against the real libsynodb.so |
| Affected | DSM ≤ 7.2.1-69057-12 · 7.2.2-72806 · 7.3.2-86009 · 7.4.1-90080 |
| Fixed in | 7.2.1-69057-13 · 7.2.2-72806-10 · 7.3.2-86009-5 · 7.4.1-90080-1 (Synology-SA-26:19) |
| CWE | CWE-89 — Improper Neutralization of Special Elements used in an SQL Command |
| Impact | Arbitrary SQL execution in syno-pam-key.db with stacked statements; per the vendor advisory this allows reading and writing arbitrary files and denial of service |
| Vector | Network, unauthenticated, pre-auth (device_id of the Auth API login) |
| Trigger | An escaped field whose %q-escaped form exceeds 4095 bytes, with a quote split by the truncation boundary |
| CVSS3 | 9.8 Critical — CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |
| Credit | Nguyễn Bá Nam Dũng (@greengrass19000) and Hà Thế Long (LongHT), Viettel Cyber Security Research Lab (@vcslab); Warisse Valentin (Aytio) |
| Advisory | https://www.synology.com/en-global/security/advisory/Synology_SA_26_19 |
| Repository | https://github.com/googlesky/CVE-2026-76954 |
The Auth API stores per-device login keys in a SQLite database through
libsyno-pam-login.so.7.0. Every column value is escaped by
SynoPamKeyImpl::DBEscapeStrings, which in the affected builds calls
SYNODBEscapeStringEX with a fixed 4096-byte global buffer. The SQLite
backend of libsynodb.so implements that escape as
sqlite3_mprintf("%q", input) followed by snprintf(out, 4096, "%s", escaped),
which silently truncates the escaped text to 4095 bytes. A field crafted so
that its escaped form is exactly 4096 bytes loses the second quote of a
doubled pair at the cut, leaving an odd quote count inside the INSERT
statement that the library builds next. The statement template then re-pairs
that dangling quote with its own, swallows the comma separator, and the next
attacker-controlled field is parsed as raw SQL. SYNODBExecute runs the
statement through sqlite3_get_table, so stacked statements execute. The
attacker reaches this path before authentication: the device_id parameter of
the Auth API login flows through SynoPAMLogin_V2, the
syno-otp-trust-device-id PAM environment, the pam_syno_otp.so module of the
webui stack, and into SynoPamKey::SetID / SynoPamKey::Save. The fix
replaces the fixed-buffer escape with SYNODBEscapeStrAllocEX, which
allocates 2*len+1 bytes and never truncates.
This repository contains a containerised differential laboratory that runs the real, unmodified Synology libraries of every affected branch, a standard-library-only proof of concept, the captured evidence of the differential, and a 0-day sweep of the fixed line.
SynoPamKeyImpl::DBEscapeStrings, vulnerable build
(libsyno-pam-login.so.7.0, 7.2.2-72806, sha256 90992ce1…, function at
+0x122bb0). For each of the seven string fields (id, user, scope,
key, attribute1, attribute2, extrainfo):
for (lVar9 = 0x200; lVar9 != 0; lVar9 = lVar9 + -1) { // zero the 4096-byte buffer
*puVar12 = 0;
}
iVar4 = SYNODBEscapeStringEX(*(undefined8 *)(this + 0x20), // db handle
&DAT_001faf00, // one global .bss buffer
0x1000, // fixed size: 4096
local_128); // attacker-controlled field
...
Json::Value::Value(local_148, (char *)&DAT_001faf00); // statement uses the buffer
The fixed build (7.2.2-72806-10, sha256 41fd4452…, function at
+0x122bd0) replaces the fixed-buffer call:
pcVar13 = SYNODBEscapeStrAllocEX(*(undefined8 *)(this + 0x20), local_128);
... SYNODBFreemem(pcVar13);
A full function-by-function comparison of both builds (385 named functions, Ghidra decompilation) shows this escape API swap is the entire fix; the five SQL builders are semantically identical apart from syslog line shifts.
libsynodb.soSYNODBEscapeStringEX dispatches through the connection's engine table to
SQLITEEscapeString (sqlite.c), verified in the shipped libsynodb.so
(format string %q at virtual address 0x10706a):
lVar1 = sqlite3_mprintf("%q", param_3); // doubles ' — output is 2*len+1 worst case
snprintf(param_1, (long)param_2, "%s", lVar1); // silent truncation at 4095 bytes
sVar2 = strlen(param_1); // returns the truncated length
The arithmetic that breaks: an input of 4094 A characters plus one '
escapes to A×4094 + '' = 4096 bytes; snprintf keeps 4095 bytes =
A×4094 + '. One quote of the doubled pair survives alone. The lab probe
(evidence/escape-probe.txt) confirms this on the real library: input length
4095 returns rc=4095 with the escaped output ending in a lone ', while the
fixed API SYNODBEscapeStrAllocEX returns all 4096 bytes.
SynoPamKeyImpl::Save builds (template constants verified in .rodata and by
tracing sqlite3_get_table):
INSERT OR REPLACE INTO key( id,user,scope,key,attribute1,attribute2,extrainfo,enabled)
VALUES ('<escaped id>','<escaped user>',...,'<escaped extrainfo>',<enabled>);
With the truncated id ending in a lone ' and the attacker choosing user
freely, the generated statement becomes:
VALUES ('AAAA…AAAA'',' ,1,1,1,1,1,1,1); CREATE TABLE poc_marker(x); --','webui',...
The template quote after the dangling ' forms an escaped '' inside the
literal, the comma separator is swallowed, the literal closes on the next
template quote, and the user body is parsed as raw SQL. The injected text
completes the eight-column VALUES list with seven fillers, terminates the
INSERT with );, executes a stacked CREATE TABLE poc_marker(x);, and
comments out the remaining template with --. The full statements captured
from both builds are in evidence/sql-vulnerable.txt and
evidence/sql-fixed.txt.
SynoPAMLogin_V2 (decompiled at +0x117060) maps its sixth parameter to a
PAM environment entry:
SYNO::PamConf::SetEnv(conf, "syno-otp-trust-device-id", param_6);
pam_syno_otp.so, part of the webui PAM stack
(/etc.defaults/pam.d/webui), reads that environment entry and stores the
device through the exported API of the same library:
_ZN10SynoPamKey5SetIDERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE,
_ZN10SynoPamKey4SaveEv, _ZN10SynoPamKey4LoadEv,
_ZN10SynoPamKey5PurgeEl (verified in its dynamic symbol table). Every field
of the database row is therefore attacker-controlled before authentication
succeeds. The database is opened at the hardcoded path
/usr/syno/etc/private/session/syno-pam-key.db by
SynoPamKeyImpl::DBContact (syno-pam-key-impl.cpp:0xd1).