CVE-2023-35055,CVE-2023-35056
A buffer overflow vulnerability exists in the httpd next_page functionality of Yifan YF325 v1.0_20221108. A specially crafted network request can lead to command execution. An attacker can send a network request to trigger this vulnerability.
The versions below were either tested or verified to be vulnerable by Talos or confirmed to be vulnerable by the vendor.
Yifan YF325 v1.0_20221108
8.8 - CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
CWE-121 - Stack-based Buffer Overflow
The Yifan YF325 is an industrial cellular router. This device is designed for M2M and IOT applications, allowing remote management, offering several VPN services and many other features.
The YF325 offers several APIs. A few of them offer the possibility of redirecting the client to a specific page after the API is performed. The piece of code that does this is the following:
[...]
next_page = (char *)websGetVar(fd,"next_page",0);
if (next_page != (char *)0x0) {
strcpy(URL_path,next_page);
}
[...]
The URL_path
is a char pointer to a static buffer that lives in the stack of the first function that receives the HTTP request.
Because the next_page
is fetched from the request’s data and then used directly in a strcpy
, this pattern is vulnerable to a stack buffer overflow.
The gozila_cgi
function is affected by this vulnerable pattern. Following the API function that calls the gozila_cgi
function:
void cgi_handler(undefined mime,char *URL_path,dword fd,char *query_string)
{
[...]
if (post == 1) {
request_data = POST_DATA;
}
else {
request_data = URL_path;
query_string = strsep(&request_data,"?");
if (query_string != (char *)0x0) {
URL_path = query_string;
}
init_cgi(request_data);
}
request_data_ = request_data;
need_reboot = (char *)websGetVar(fd,"need_reboot","0");
need_rebot_value = atoi(need_reboot);
change_action = (char *)websGetVar(fd,"change_action","");
if ((change_action != (char *)0x0) && (is_gozila = strcmp(change_action,"gozila_cgi"), is_gozila == 0)) {
gozila_cgi(fd,0,URL_path); [1]
goto RET;
}
[...]
}
At [1]
the gozila_cgi
function is called, and eventually the pattern shown above is reached:
int gozila_cgi(undefined4 fd,undefined param_2,char *URL_path)
{
[...]
nvram_set("gozila_action","1");
next_page = '\0';
submit_button = websGetVar(fd,"submit_button",0);
submit_type = websGetVar(fd,"submit_type",0);
godzila_ptr = (godzila_object *)handle_gozila_action(submit_button,submit_type);
[...]
next_page = (char *)websGetVar(fd,"next_page",0);
if (next_page != (char *)0x0) {
strcpy(URL_path,next_page);
}
[...]
}
This vulnerability can be reached without authentication.
The cgi_handler
function is the entry point for different APIs. This function is affected by this vulnerable pattern:
void cgi_handler(undefined mime,char *URL_path,dword fd,char *query_string)
{
[...]
if (post == 1) {
request_data = POST_DATA;
}
else {
request_data = URL_path;
query_string = strsep(&request_data,"?");
if (query_string != (char *)0x0) {
URL_path = query_string;
}
init_cgi(request_data);
}
request_data_ = request_data;
need_reboot = (char *)websGetVar(fd,"need_reboot","0");
need_rebot_value = atoi(need_reboot);
change_action = (char *)websGetVar(fd,"change_action","");
if ((change_action != (char *)0x0) && (is_gozila = strcmp(change_action,"gozila_cgi"), is_gozila == 0)) {
gozila_cgi(fd,0,URL_path);
goto RET;
}
[...]
next_page = (char *)websGetVar(fd,"next_page",0);
if (next_page != (char *)0x0) {
strcpy(URL_path,next_page);
}
[...]
}
This vulnerability can be reached without authentication.
2023-06-28 - Initial Vendor Contact
2023-07-06 - Vendor Disclosure
2023-10-11 - Public Release
2023-10-24 - Vendor Patch Release
Discovered by Francesco Benvenuto of Cisco Talos.