-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The trust boundary is a `strstr` in `libcgi.so`\n\nWhen ipTIME wants to find its upstream IGD, `libcgi.so`'s `discover_upper_upnp_igd` does this:\n\n```c\nsnprintf(cmd, 0x100, \"/sbin/upnpc -m %s -P\", ip);\nfs = popen(cmd, \"r\");\n...\ndo {\n idx = fgets(fs_buf, 4000, fs);\n if (idx == NULL) { success = 0xffffffff; goto cleanup; }\n iVar1 = strncmp(fs_buf, \"Found valid IGD\", 0xf);\n} while (iVar1 != 0);\nidx = strstr(fs_buf, \"http\");\nif (idx != NULL) {\n snprintf(igd_url, 0x100, \"%s\", idx);\n istatus_set_value_direct(&igd, igd_url);\n}\n```\n\nThe function execs the firmware's bundled `/sbin/upnpc` binary, pipes its stdout back, scans the output line by line, looks for the first line that begins with the literal string `Found valid IGD`, finds the first occurrence of the substring `http` on that line, and `snprintf`s from there to the end of the line into a 256-byte slot called `igd_url`. That value is stored via `istatus_set_value_direct` so any other libcgi handler can read it back.\n\nThis is `libcgi`'s protocol for \"who is my upstream IGD.\" The protocol is \"the substring of `/sbin/upnpc`'s stdout that begins at the first `http` of the first line starting with `Found valid IGD`.\" There is no schema. There is no length validation. There is no character-class restriction. The grammar is documentation by example, and the example is the happy path.\n\nThe stored `igd_url` is read back here, in `upnp_relay`:\n\n```c\nistatus_get_value_direct(&igd, buf);\n...\nsnprintf(bufCopied, 0x100, \"-u %s\", buf);\n...\nsystem2(\"/sbin/upnpc %s -m %s -d %s %s\", bufCopied, wanip, port, proto);\n```\n\n`buf` is the stored `igd_url`. It is formatted into `-u ` and passed as the first variadic argument to `system2`. `system2` is `libcgi`'s shell-out helper:\n\n```c\nvoid system2(char *fmt, ...) {\n vsnprintf(scratch, 0x3ef, fmt, args);\n strcat(scratch, \" >/dev/null 2>&1\");\n system(scratch);\n}\n```\n\n`vsnprintf` substitutes `bufCopied` into the format. `strcat` appends `>/dev/null 2>&1`. `system()` hands the whole string to `/bin/sh -c`. The shell metacharacters in `igd_url` are unescaped because nothing in this chain ever thought of `igd_url` as an attacker-controlled string. The function that wrote `igd_url` read it from `/sbin/upnpc`'s stdout, and to `libcgi.so`, its own bundled helper binary's stdout is private IPC.\n\n## `/sbin/upnpc`'s stdout is in fact what the WAN said\n\n`/sbin/upnpc` is ipTIME's vendored copy of `miniupnpc`'s example client. The `-m ` flag binds SSDP multicast to that interface IP; the `-P` flag asks the discovered IGD for its presentation URL. Both flags happen to drive a full IGD-discovery sequence inside `UPNP_GetValidIGD` before anything is printed.\n\nThe sequence reads in five steps. Every value on the path is supplied by whoever answered the M-SEARCH:\n\n1. `ssdpDiscoverDevices` multicasts `M-SEARCH * HTTP/1.1` and reads back replies with `parseMSEARCHReply`, which lifts the `LOCATION:`, `ST:`, and `USN:` header values out of each response. Each reply becomes a `UPNPDev` node in a `devlist`.\n2. For each device in the list, `miniwget_getaddr` performs an HTTP GET on the URL that arrived in `LOCATION:`. The response body is treated as the device description XML.\n3. `parserootdesc` parses that XML and populates `data->first.controlurl` with the value of the first `` element.\n4. `UPNPIGD_IsConnected` POSTs a `GetStatusInfo` SOAP call to `data->first.controlurl` and reads the response's `NewConnectionStatus`. If the value is `Up` or `Connected`, the device is accepted as a live IGD.\n5. `UPNP_GetExternalIPAddress` POSTs `GetExternalIPAddress` and checks that the returned IP is not in a reserved range.\n\nOn success, `upnpc` prints to its own stdout:\n\n```c\nprintf(\"Found valid IGD : %s\\n\", urls.controlURL);\n```\n\nThe PoC's [`attacker.xml`](https://github.com/logis11/CVE-2025-55423-analysis-and-reproduction/blob/main/exploits/attacker.xml) sets the first `` to `/87895a19/upnp/control/WANIPConn1;PWNED`. The PoC's [`http_server.py`](https://github.com/logis11/CVE-2025-55423-analysis-and-reproduction/blob/main/exploits/http_server.py) returns `Up` to `GetStatusInfo` and `8.8.8.8` to `GetExternalIPAddress`. `upnpc` runs the full IGD-validation flow against the attacker's listener, decides the listener is a live IGD with a non-reserved external IP, and prints:\n\n```\nFound valid IGD : http://10.0.11.234:8080/87895a19/upnp/control/WANIPConn1;PWNED\n```\n\nThat line is what `libcgi`'s `discover_upper_upnp_igd` is waiting for. The `strncmp(fs_buf, \"Found valid IGD\", 0xf)` matches. The `strstr(fs_buf, \"http\")` finds the substring. The `snprintf` copies from there. `igd_url` is now `http://10.0.11.234:8080/87895a19/upnp/control/WANIPConn1;PWNED`. The semicolon is the shell separator.\n\nThe next time a LAN client triggers `upnp_relay`, `system()` receives a command line the PoC captured at the entry to `system` with gdb on a MIPS user-mode harness:\n\n```\nA0 = '/sbin/upnpc -u http://1.2.3.4/x;echo hello world > /tmp/pwn;# -m 1.2.3.4 -d 8080 tcp >/dev/null 2>&1'\nsystem+24 beqz $a0, system+48\n```\n\nBy the MIPS calling convention, `A0` is `system`'s first argument. `/bin/sh -c` parses that string as two statements separated by the semicolon: `/sbin/upnpc -u http://1.2.3.4/x` and `echo hello world > /tmp/pwn`. The `#` after the second statement comments out the rest of the command (`-m 1.2.3.4 -d 8080 tcp >/dev/null 2>&1`) that `libcgi` itself appended via `system2`. The attacker writes the payload, the shell parses it, the `#` cleans up after `libcgi`'s own variadic continuation.\n\n## The protocol is a substring of a printf\n\nThis is **content-is-command** with three process boundaries between the content channel and the interpreter. The content channel is the `` element of an SSDP description XML returned to a WAN-side responder. The interpreter is `/bin/sh -c`. The bridge between them runs across three programs, gets re-encoded twice, and passes through one global key-value store, and the value at the end is byte-identical to the value at the start.\n\nThe boundaries the bytes cross:\n\n1. The attacker's TCP listener returns the XML. `parserootdesc` inside `/sbin/upnpc` reads the first `` into `data->first.controlurl`.\n2. `GetUPNPUrls` resolves it into `urls.controlURL` as an absolute URL.\n3. `printf(\"Found valid IGD : %s\\n\", urls.controlURL)` writes it onto `/sbin/upnpc`'s stdout. The format specifier is `%s`. No encoding.\n4. `popen` in libcgi pipes that stdout. `fgets` reads a line. `strstr(line, \"http\")` finds the substring. `snprintf(igd_url, 0x100, \"%s\", idx)` copies it. The format specifier is again `%s`.\n5. `istatus_set_value_direct(&igd, igd_url)` writes the value into the libcgi-wide key-value store. `istatus_get_value_direct(&igd, buf)` reads it back.\n6. `snprintf(bufCopied, 0x100, \"-u %s\", buf)` wraps it. `system2`'s `vsnprintf` substitutes it. `system()` hands it to `/bin/sh`.\n\nEach layer treats its input as authoritative output from the layer above. The XML parser was answered by an upstream router. The upstream router was discovered by SSDP. The SSDP discovery was launched by `libcgi`. `libcgi` is reading its own bundled helper binary's stdout. The kernel-level view of the trust boundary, where the file descriptor was created, who is the writing process, agrees with that chain at every layer. The protocol-level view, who controls the bytes, disagrees with it at the top.\n\n`/sbin/upnpc`'s stdout is `libcgi`'s **internal-only-by-convention** channel. The framework treats the popen pipe as internal IPC because it forked the child. The convention says \"only my own helper binary writes to this stdout.\" The convention is true about the writer and false about the bytes. Every previous exhibit of this pattern has been an HTTP header or a query parameter the framework wrote to itself, like Next.js's [`x-middleware-subrequest`](/posts/next-middleware-cve-2025-29927-recursion-guard-was-the-bypass) or Zimbra's [`javax.servlet.include.servlet_path`](/posts/zimbra-restfilter-javax-servlet-include-was-a-form-field). The shape generalizes below HTTP: a Unix pipe from `popen` to `fgets` is the same trust shape with a different transport. The framework's internal channel reads attacker input every time the helper binary it wraps reads from the network.\n\n## The WAN-side M-SEARCH is the design\n\nThe thing that makes this CVE specifically ipTIME's bug and not generic miniupnpc behavior is the decision to send the discovery M-SEARCH out the WAN interface in the first place. UPnP was designed for LAN-side discovery between trusted devices on the same broadcast domain. The protocol's threat model is \"anyone who can hear my multicast can claim to be a printer.\" That model is acceptable on a LAN because the LAN is by assumption owned by one party. ipTIME's double-NAT delegation pattern reuses the same primitive on a WAN segment whose ownership boundary the protocol does not address. In a typical Korean fiber-to-the-home installation, the ipTIME's WAN sits on an ONU's downstream LAN that is shared with ISP management equipment and, in apartment deployments, with adjacent units' ONUs. The WAN-side broadcast domain is not assumed-trusted by anything except `libcgi`.\n\nThe trigger from the LAN side is a UPnP port-mapping request. uTorrent at startup is the documented example. Once the LAN client requests a mapping, `upnp_relay` runs, `discover_upper_upnp_igd` runs if `igd_url` is unset, the M-SEARCH goes out the WAN, the first WAN-side responder wins. The PoC's [docs/02-attack-scenario.md](https://github.com/logis11/CVE-2025-55423-analysis-and-reproduction/blob/main/docs/02-attack-scenario.md) walks the broader MITM steps that get the attacker to the responder seat (ARP spoofing the upstream router, hijacking the T1 DHCP renewal to plant an attacker-controlled gateway, dropping IP-forwarding to induce a LAN-side reboot so uTorrent re-requests its port mapping). The PoC deliberately does not implement those steps because they are generic MITM, not properties of this CVE. The CVE is what happens after the attacker has won the SSDP race. Everything from there is `strstr(line, \"http\")` and `snprintf`.\n\n## Why the structural shape exists\n\nThe developer wrote no escape because the developer's mental model of the data path is \"I am reading my own helper binary's stdout.\" The model is correct at the kernel level and wrong at the protocol level, and the gap between those two correctnesses is where bugs of this class live.\n\n`libcgi.so` is a SOHO-router shared library that absorbs HTTP parsing, UPnP handling, web-UI dispatch, CGI parameter extraction, and several daemons' command logic into one `.so`. The codebase is glued together with `popen` and `system`. The same `upnp_relay` function calls `system(\"/sbin/iptables -P INPUT ACCEPT\")` and `system(\"/sbin/iptables -P INPUT DROP\")` to bracket its own work. `system2` exists specifically because most of what libcgi does is `vsnprintf` a command, append `>/dev/null 2>&1`, and shell out. In a codebase where `/bin/sh` is the universal IPC mechanism, the boundary between attacker-controlled and trusted bytes has to live in the developers' heads, because neither the language nor the helper libraries provide help with it. When the developer writes `popen(\"/sbin/upnpc ...\")`, they are thinking about which line of the output they need, not about who controls the bytes upnpc will print.\n\nThe deeper move is the repurposing of debug output as a wire format. miniupnpc's `printf(\"Found valid IGD : %s\\n\", urls.controlURL)` was a human-readable status line, meant for an operator running `upnpc` by hand to introspect their LAN. ipTIME repurposed it as a programmatic IGD-discovery channel by scraping its output. The text-after-the-colon-on-the-line-starting-with-\"Found valid IGD\" is the protocol ipTIME invented. That protocol carries `urls.controlURL` verbatim because miniupnpc's format string is `%s` and `controlURL` is the field the WAN responder controls. Every embedded codebase that scrapes the stdout of another binary has the same boundary problem; this one happens to terminate the scrape in `system()`.\n\n## The patched advisory does not say \"stdout\"\n\nThe CVE record will name this as a command injection in `upnp_relay`. That is true at the line where the bug fires, `system2(..., bufCopied, ...)`, and it is also where a defender reading the advisory will stop looking. The injection sink is in `upnp_relay`. The injection source is the line of `/sbin/upnpc` stdout that begins `Found valid IGD : `. The validator that would have stopped the chain has to live in `discover_upper_upnp_igd`, where the line is read, not in `upnp_relay`, where it is used. A patch in `upnp_relay` that escapes `igd_url` before `snprintf`-ing it would close this CVE and leave the boundary unchanged. Any other libcgi handler that reads `igd` via `istatus_get_value_direct` and shells out with the value would still inherit a shell-controllable string.\n\nThe bug is not a missing escape. The bug is that `/sbin/upnpc`'s stdout is treated as a trusted oracle for what the upstream router's `controlURL` is, when in fact `/sbin/upnpc`'s stdout is the most recent thing a WAN-side SSDP responder caused it to print.\n\nPoC: [logis11/CVE-2025-55423-analysis-and-reproduction](https://github.com/logis11/CVE-2025-55423-analysis-and-reproduction).","closing_line":"The interpreter at the bottom is `/bin/sh`. The interpreter in the middle is `strstr(line, \"http\")`.","hook_md":"The ipTIME A604M is a Korean SOHO router that most home installs put in a double-NAT topology: a fiber ONU upstream doing NAT, then ipTIME doing its own NAT, then the LAN. When a LAN client opens a UPnP port mapping, uTorrent at startup, an IPTV box, a NAS, ipTIME has to delegate the mapping up to whatever IGD is sitting on its WAN. So `libcgi.so` multicasts SSDP `M-SEARCH` out the WAN interface. The protocol designed for trusted LAN discovery runs on the side of the box that faces a shared segment the box does not own. Whoever answers first becomes ipTIME's upstream IGD. CVE-2025-55423 is what `libcgi.so` does with that answer, and the answer reaches `system()` through `strstr(line, \"http\")` on the stdout of ipTIME's own bundled `/sbin/upnpc`.","post_id":437,"slug":"iptime-cve-2025-55423-upnpc-stdout-is-the-protocol","title":"CVE-2025-55423: ipTIME's libcgi Reads upnpc's Stdout as a Wire Format. The WAN Writes the Stdout.","type":"initial","unreadable_sentence":"The trust boundary between an attacker's XML and `system()` is `strstr(line, \"http\")` on the stdout of ipTIME's own bundled helper binary."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCameaaQAKCRDeZjl4jgkQ JhRaAQDEPiMb828VGKBu4HskQJASQpI2fB8FNP6b51APGj/SaQD/UZPSIer2TSgD B1dzhvpa4RqmmHbmCXatCFhvdPpVrA4= =ocv+ -----END PGP SIGNATURE-----