TRENDnet TEW-657BRM 1.00.1 upgrade_flash.cgi: strncpy of the multipart first line into a 128-byte frame buffer (ra +192), delimiter unchecked -> wild-size SIGSEGV. Hash-verified CGI re-hosted under qemu-mips; bounds-patch side passes. EOL device.
upgrade_flash.cgi authenticated stack overflow: the multipart first line overflows a 128-byte strncpy| CVE | CVE-2026-129352 (VulDB) |
| Component | TRENDnet TEW-657BRM v1.0R, firmware 1.00.1 — /usr/sbin/upgrade_flash.cgi (the firmware-upload handler) |
| Affected | TEW-657BRM v1.0R firmware 1.00.1 — EOL, no vendor fix will be released |
| Fixed in | nothing; the product is end-of-life. This repository's differential uses a bounds-enforcing binary patch instead (see §2) |
| CWE | CWE-121 (Stack-based Buffer Overflow), CWE-120 (Classic Buffer Overflow) |
| Impact | Authenticated (LAN-administrator) memory corruption of the upload CGI: an unbounded strncpy of the multipart first line over a 128-byte frame buffer (saved registers and $ra 192 bytes above it), plus an unchecked delimiter search whose absence makes the copy size go wild — an immediate pre-body SIGSEGV |
| Vector | A firmware-restore/upload request whose multipart first line exceeds 128 bytes, or whose body contains no CR/LF at all |
| Trigger | first line ≥ 192 bytes reaches the saved $ra with attacker bytes (witnessed in the CGI's own trace); a body without CR/LF crashes immediately at 0x40801000 |
| Credit | ruanyi (VulDB user ruanyi101) — original research advisory (documented saved-metadata overwrite and PC control in an image-accepted emulated flow) |
The upload handler reads the request body, finds the end of the first
line with strstr, and copies that line into a 128-byte stack buffer
using the line's length as the strncpy size. Neither the delimiter
result nor the length is bounded or checked. One authenticated request
with an over-long first line overwrites the frame — the CGI's own debug
trace logs a boundary string longer than the destination buffer — and a
body without any CR/LF makes the pointer subtraction produce a wild size
that kills the CGI immediately. This laboratory re-hosts the real
firmware CGI (MIPS big-endian, hash-verified image) under qemu-mips
with mini_httpd's CGI model, reproduces both primitives, and contrasts
the shipped binary with the same binary carrying a six-instruction
bounds cap on exactly that strncpy call site.
main of upgrade_flash.cgi (Ghidra 12.1.4 decompilation, function at
0x00403780; the frame uses $s8):
buf = malloc(0x800);
read(0, buf, 0x800); /* the request body */
local_34 = strstr(buf, "\r\n"); /* end of first line — result NOT checked */
strncpy(auStack_c8, buf, local_34 - buf); /* dst = char[128] @ $s8+0x2f8, size = line length */
...
sep = strstr(buf, "Content-Disposition"); /* later markers ARE checked */
...
sep = strstr(buf, "\r\n\r\n"); /* checked */
check_updata(...); /* image validation */
Two consequences, both reproduced:
strstr returns NULL, the subtraction yields a
~4 GB size, and the strncpy faults immediately (SIGSEGV si_addr=0x40801000, the copy walking off the mapping). This is the
reliable crash primitive (the CGI's error paths call exit() directly,
so the overlong-line overwrite does not pop $ra on those paths).$ra sit 192 bytes above the
destination, and every byte of the first line is attacker-chosen. The
CGI's own trace (written to /var/cgitest) logs the boundary string it
copied — for an 800-byte first line it logs 804 bytes, proving the
write continued far past the 128-byte destination. The upstream
research documented program-counter control at main's epilogue in a
flow whose body carried a valid vendor image (so the handler returns
normally); this lab demonstrates the unbounded write and the wild-size
crash instead, and states that boundary honestly.The handler is reached only after the CGI authorises the client by
resolving its MAC with SIOCGARP — the LAN-administrator position
(see §2 for how the lab reproduces it).
| service | image | role |
|---|---|---|
upg-vuln | cve-2026-129352:lab with LAB_BOUNDS_SHIM=0 | the firmware rootfs (extracted at build from the hash-verified vendor image) chroot'd; each request forks /usr/sbin/upgrade_flash.cgi under qemu-mips-static with mini_httpd's CGI environment |
upg-fixed | cve-2026-129352:lab with LAB_BOUNDS_SHIM=1 | the same CGI with lab/patch.py's bounds patch: the one strncpy call site jumps to a six-instruction stub capping the length at 128 (the destination's size) |
poc | cve-2026-129352-poc:local | stdlib-only Python driver |
The TEW-657BRM is end-of-life; no vendor patch exists or will exist.
This firmware's uClibc loader does not support LD_PRELOAD at all (even
its own pppoe.so is rejected), so the remediation cannot be an
interposed library as in the sibling DIR-600L labs — it is a minimal
binary patch applied at image build with hash-checked preconditions
(lab/patch.py):
SIOCGARP authorisation fills a big-endian arpreq; qemu-user passes
guest buffers to the host kernel unconverted, so on a little-endian
host the sockaddr family is byte-swapped and every conforming host
kernel rejects the request. The device's own Linux 2.4 kernel accepted
it. Patch A NOPs the call and the auth-failed branch identically on
both sides, reproducing the authorised position without touching the
vulnerable code path.0x00403b84: jalr t9 (the
strncpy call) becomes j 0x00403304, where a stub over the now-dead
getMAC body caps $a2 at 128 and tail-jumps to the real strncpy.Provenance: the firmware package TEW-657BRMv1.0R(1.00.1).zip (md5
0e2104c9259073e0a1e3bbdb6d740840) is fetched at image build from
TRENDnet's server; the inner image and ad1006.bin are hash-gated, the
vendor sqlz squashfs is unpacked with sasquatch, and
usr/sbin/upgrade_flash.cgi is verified (md5
7561a1758fe08011906c86d416104820). The front end
(lab/service.py) reproduces mini_httpd's CGI model — body on stdin,
CONTENT_LENGTH, REMOTE_ADDR — and returns the child's fate as JSON,
including the tail of the CGI's own /var/cgitest trace.
./run-lab.sh build # firmware fetch+verify, extraction, lab + PoC images
./run-lab.sh up # cve129352lab network, upg-vuln, upg-fixed (NET_ADMIN for the ARP entry)
./run-lab.sh sweep # check / exploit / probe / mitigation on both sides
./run-lab.sh down
Single mode against one side:
podman run --rm --network cve129352lab cve-2026-129352-poc:local \
exploit --host=upg-vuln
poc/poc.py (stdlib only; check / exploit / probe / mitigation):
si_addr. Exit 1 vulnerable, 0 safe, 3 no
worker, 2 unreachable.strncpy SIGSEGV;
stage 2 sends an over-long first line and proves the frame overwrite
through the CGI's own logged boundary length.$ra distance, LF-only bodies, missing marker bodies, and
the no-delimiter form.