InRouter3XX V3.5.117 -- Predictable Session Tokens (Auth Bypass, Zero Credentials)
Firmware: InRouter3XX-V3.5.117.bin -- SHA256 c2b77c44036dcdec2be637015655bd0e28d1eda4996ea994e8a5bff9167c24a1
Class: CWE-338/CWE-340 (predictable session token from non-cryptographic PRNG)
Access needed: network access to the web UI + the timestamp of an admin
login + the admin's source IP (see binding, \xa72). No password, no serial.
Impact: forged web_session cookie = a live session -- but only from the
same source IP the session was minted from (same host, or on-path TCP
spoofing). Remote attackers from other IPs are stopped by the IP binding.
Status: proven in the QEMU lab (2026-10-16) -- computed cookies were accepted
by the router and were byte-identical to the real admin cookies (all lab
connections share one IP, which is why the demos pass; see \xa76)
1. The bug in one minute
Every web login mints the session cookie like this:
srand(time(NULL)); // seed = wall clock, seconds
sprintf(cookie, "%x", rand() + uptime); // PRNG output + device uptime
Both inputs are quantities an attacker can know:
- time(NULL) -- the current time. Attacker's own clock (\xb11-2s).
- uptime -- kernel seconds since boot. Learnable (see attack modes).
The PRNG is the standard glibc/uClibc TYPE-3 generator -- reproducible offline:
r[0] = seed
r[i] = 16807 * r[i-1] mod 2147483647 for i = 1..30
r[i] = r[i-31] for i = 31..33
r[i] = (r[i-31] + r[i-3]) mod 2^32 for i = 34..344
first rand() output = r[344] >> 1
So cookie = hex(F(login_second) + uptime) -- a formula, not a secret.
2. Exact code path and function trace
Login request -> token mint:
GET/POST /check_auth.jsp?_username=..&_passwd=..
\u2502
\u251c\u2500 route table 0x4385d0: check_auth.jsp (auth flag = 0, public)
\u2502 input 0x40cf1c (shared body reader / webcgi_init)
\u2502
\u251c\u2500 wo_checkauth @ 0x4147e8
\u2502 \u251c\u2500 webcgi_get("_username") / ("_passwd") (keys @ 0x422860/0x42287c)
\u2502 \u251c\u2500 web_auth_pam @ 0x4140c0 (via GOT 0x438dd4) -> 0 = success
\u2502 \u251c\u2500 get_uptime() \u2510
\u2502 \u251c\u2500 time(0); srand(time) \u2502 the mint
\u2502 \u251c\u2500 rand(); sprintf(token, "%x", rand + uptime) \u2502 (fmt @ 0x426780)
\u2502 \u2514\u2500 update_web_user_info(token, username, ...) \u2518 (call @ 0x414994)
\u2502
\u2514\u2500 response: Set-Cookie: web_session=<token> (+ "OK" for _ajax=1)
Decompiled mint block (r2ghidra pdg, annotated):
// wo_checkauth @ 0x4147e8 -- success path of the web login
iVar4 = web_auth_pam(_username, _passwd, ...); // 0x4140c0
if (iVar4 == 0) {
iVar4 = get_uptime(); // kernel seconds
uVar3 = time(0); // wall clock
srand(uVar3); // seed = wall clock!
iVar5 = strstr(req, "username:"); // API syntax check
if (iVar5 == 0 || strstr(req, "password:") == 0) {
iVar5 = rand(); // 1st rand() after seed
sprintf(token, "%x", iVar5 + iVar4); // <- THE COOKIE
} else { // API branch (port 4444)
do { iVar4 = rand(); } while (iVar4 % 10000 < 1000);
sprintf(token, "%d", iVar4); // pure rand -- weaker still
}
update_web_user_info(token, username, ...);
syslog(6, "%s login from %s", username, ...);
}
Session storage -- update_web_user_info (called via GOT 0x438df8):
snprintf(slot, 0x40, "_web_session_%d", N); // N = 0..9, LRU slot
snprintf(line, 0x80, "%s,%s,%d,%s,%s,%d,%d", // fmt @ 0x426768
token, username, priv, ..., uptime, uptime);
nvram_set(slot, line); // runtime nvram key
Session validation -- get_web_user_info + the auth gate 0x40392c
(every authenticated request). The stored line is
token,username,priv,client_ip,host_header,created,last_active;
get_web_user_info strseps off the token (strcmp vs the presented cookie)
and returns the remainder. The gate then enforces all of:
identity = field2 (username) -> g_cgi_user
priv = atoi(field3)
peer_ip == field4 // socket peer (inet_ntoa in main; no XFF)
Host_hdr == field5 // exact string match incl. port
now - field6 <= login_timeout // nvram 'login_timeout', default 300 s
Note what is not there: no HMAC, no secret, no per-request entropy in the token itself -- but the token is additionally bound to the client IP and the exact Host string, which constrains exploitation of the prediction (\xa76).
3. Attack modes (all verified or derived)
| Mode | Attacker has | Uptime source | Cost |
|---|---|---|---|
| Probe | any valid account (even read-only) | 2 of their own logins: uptime = cookie \u2212 F(time); two logins must agree on elapsed time |
~1-5 candidate cookies |
| Brute | nothing but the login timestamp | guessed 0..N, one cookie per uptime-second | 1 h uptime ~ 3.6k reqs; lab rate 189 req/s |
| Reboot-watch | observes a reboot (power/watchdog/crash) + login timestamp | uptime = login_time \u2212 boot_time -- exact |
~5 candidates (analytical; reboot also wipes sessions, forcing the admin to relogin soon) |
Verification oracle (the router's own verdict): auth-gated page returns 302 -> login for an invalid cookie, 200 for a valid session. No lockout exists on cookie checks -- the PAM shield counts failed logins only (~2,400 bad cookies in a row had no effect).
4. Verification results (2026-10-16)
- Formula: 5/5 logins reproduced exactly, with uptime read from
/proc/uptime(independent source, not derived from tokens). - Clean forge: isolated time window -> computed cookie byte-identical to the real admin cookie, accepted by the server (~15 candidates).
- Brute runs: 2,732 reqs / 14.4 s and 10,771 reqs / 56.9 s (uptime grew between runs) -- both hit the exact admin cookie.
- Token is user-independent: logins in the same second receive the identical token -- two users logging in within one second share a cookie value (session confusion on its own).
5. What this enables
Forged session -> upload.cgi + status-wlanclients.jsp -> the RCE chain of
REPORT-RCE.md executes as root -- when the attacker shares the victim's
source IP (the binding in \xa72). Realistic scenarios: malware on the admin's
machine, or on-path attackers who can inject with the admin's source IP.
A remote attacker on a different IP predicts a valid token that the gate
still rejects. The chained PoC (poc-rce-nocreds.py) was validated
step-by-step in the lab (single shared IP); its final end-to-end run is
pending.
6. Scope and limits
- IP + Host binding (verified 2026-10-16): replaying a valid token from
the same IP but with a different
Hostheader -> 302; the UA is not checked. All lab connections share the slirp gateway IP, so every demo implicitly satisfied the IP check. - Sessions idle out after
login_timeout(default 300 s), refreshed on use. - Lab guest clock == host clock (QEMU default); on hardware, NTP drift only widens the seed window by a few candidates per second of drift.
- The API-port login is now fully reversed (2026-10-16): request grammar
GET /username:<USER>password:<PASS> HTTP/1.0on TCP 4444 ->token=<%d> ... success!. The API token isrand(time(NULL)) % 10000(verified live: predicted 5299 =rand_first(T)%10000) -- only ~9,000 possible values, single-candidate prediction per login second, or a <=9,000-request brute (session checks have no lockout). Tokens are injected pre-auth into the session global via+<token>in the path (getinfo_process, strlcpy 16) or theweb_sessioncookie (dispatcher, strlcpy 16 -- bounded, no overflow). Validation still runs through the same gate: token + peer IP + exact Host + 300 s idle -- the API mint is weaker, the binding unchanged. - First-seen-at
verify-auth-bypass.pylesson: an oracle hit proves "some live session", not "the admin's session" -- isolate the time window or verify admin capability before claiming identity. - Auth-path components audited and found clean (no bypass there):
web_auth_pam(strict PAM chain),pam.conf(allrequired pam_unix, no empty passwords),logout.cgi(clears only the caller's own session), noX-Forwarded-Forhandling anywhere,init.jspmerely skips the session refresh.
7. Fix recommendations
- Generate session tokens from
/dev/urandom(>=128 bits) -- neverrand()/time()/uptime. - Rate-limit or flag repeated failed session validations (today only failed logins are shielded).
- Rotate/invalidate all
_web_session_*on reboot and on privilege changes; bind sessions to more than a bare predictable 32-bit value.
8. Artifacts
| File | Purpose |
|---|---|
poc-auth-bypass.py |
bypass PoC -- probe mode + --admin-time (observed login) |
poc-auth-brute.py |
zero-credential uptime brute-force (threaded, measured rate) |
verify-auth-bypass.py |
formula/oracle/forge verification with independent uptime source |
poc-rce-nocreds.py |
bypass + RCE chained (final run pending) |
/tmp/opencode/wca.c |
raw r2ghidra decompile of wo_checkauth |