CVE-2024-39781,CVE-2024-39783,CVE-2024-39782
Multiple OS command injection vulnerabilities exist in the adm.cgi sch_reboot() functionality of Wavlink AC3000 M33A8.V5030.210505. A specially crafted HTTP request can lead to a arbitrary code execution. An attacker can make an authenticated HTTP request to trigger these vulnerabilities.
The versions below were either tested or verified to be vulnerable by Talos or confirmed to be vulnerable by the vendor.
Wavlink AC3000 M33A8.V5030.210505
Wavlink AC3000 - https://www.wavlink.com/en_us/product/WL-WN533A8.html
9.1 - CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H
CWE-77 - Improper Neutralization of Special Elements used in a Command (‘Command Injection’)
The Wavlink AC3000 wireless router is predominately one of the most popular gigabit routers in the US, in part due to both its potential wireless and wired speed capabilities and extremely low price point (costing at the time of this writing ~$60 USD). Among the configuration options, it’s also able to act as a standalone wireless gateway, a basic network router, or a wireless repeater.
When interacting with and configuring the Wavlink AC3000 wifi router, as is typical of most wifi routers, an administrator logs in via some web portal and configures appropriate options via the HTTP interface. In the case of this particular router, and in another somewhat common execution pattern, these HTML pages can invoke .cgi binaries due to how the lighttpd server is configured. Since all of these .shtml and .cgi files are located in the web root, anyone with network access to the device doesn’t actually need to log in to the device to interact with these .cgi files, and it usually is the responsibility of the .cgi binary to check if the authentication is completed successfully. On this device, one will see a check_valid_user()
function in each individual .cgi binary which will check the session
cookie of the HTTP request to see if it’s coming from a validly logged in user.
Assuming that we’ve passed this check in the adm.cgi
binary, we then run into a set of functions that we can call based off of what we pass for the page=
parameter in our HTTP POST request. Of the available commands, we only focus on the following:
00401a60 else if (strcmp(webget_page, "sch_reboot") == 0)
00401b5c sch_reboot(contlen_buf)
If we provide page=sch_reboot
, we enter the sch_reboot
function and our provided POST data is further parsed therein:
004133fc int32_t sch_reboot(int32_t arg1)
0041342c char var_90
0041342c memset(&var_90, 0, 0x80)
00413454 var_90 = 0x30
00413468 int32_t $v0_1 = strdup(web_get("restart_hour", arg1, 0)) // [1]
004134a0 int32_t $v0_3 = strdup(web_get("restart_min", arg1, 0)) // [2]
004134d8 int32_t $v0_5 = strdup(web_get("restart_week", arg1, 0)) // [3]
004134f8 if (sx.d(*$v0_1) == 0 || (sx.d(*$v0_1) != 0 && sx.d(*$v0_3) == 0))
00413514 nvram_bufset(0, "SCH_Reboot", 0x41628c)
004134f8 if (sx.d(*$v0_1) != 0 && sx.d(*$v0_3) != 0)
004135e0 snprintf(&var_90, 0x80, "%s %s * * %s /sbin/sch_reboot.sh reboot", $v0_3, $v0_1, $v0_5, 0x439d20) // [4]
004135fc nvram_bufset(0, "SCH_Reboot", &var_90) //[5]
00413624 if (access("/tmp/web_log", 0) == 0)
00413638 int32_t $v0_8 = fopen("/dev/console", &data_415758)
00413644 if ($v0_8 != 0)
00413678 fprintf($v0_8, "%s:%s:%d:SCH_Reboot = %s \n\n", "adm.c", "sch_reboot", 0x10ae, &var_90)
00413690 fclose($v0_8)
0041352c nvram_commit(0)
00413544 do_system("killall schedule.sh")
0041355c sleep(1)
00413574 do_system("schedule.sh init") // [6]
0041358c sleep(1)
004135c0 return free_all(2, $v0_1, $v0_3)
Our provided restart_hour
[1] ,restart_min
[2], and restart_week
[3] POST parameters are all combined into a buffer [4], and then written to the SCH_Reboot
nvram item at [5]. This buffer resembles a crontab item and as we will soon see within further scripts, this line will indeed be added to a crontab and run. To see this we must look at the system call to schedule.sh init
at [6]:
// [...]
echo "0 12 * * * echo 3 > /proc/sys/vm/drop_caches" >> /var/spool/cron/crontabs/"$user"
echo "0 23 * * * echo 3 > /proc/sys/vm/drop_caches" >> /var/spool/cron/crontabs/"$user"
echo "0 23 * * * killall lighttpd" >> /var/spool/cron/crontabs/"$user"
echo "1 23 * * * lighttpd -f /etc_ro/lighttpd/lighttpd.conf -m /etc_ro/lighttpd/lib" >> /var/spool/cron/crontabs/"$user"
echo "*/2 * * * * monitor_process.sh" >> /var/spool/cron/crontabs/"$user"
echo "0 5 * * * echo 0 > /tmp/url_filter_lib_state" >> /var/spool/cron/crontabs/"$user"
if [ N`nvram_get 2860 MeshMode` == "N1" ]
then
echo "*/1 * * * * generate_arp.sh" >> /var/spool/cron/crontabs/"$user"
fi
# echo "0 3 * * * init_system restart" >> /var/spool/cron/crontabs/"$user"
crond
#check current time
while true
do
ntp_year=`date "+%Y"`
[ $ntp_year -gt 2000 ] && break
sleep 20
done
killall crond
sleep 1
Inside of this script we can see a crontab being created for the adm2860
user and eventually written to /var/spool/cron/crontabs/adm2860
. The script then waits until the ntp service is running and there is a correct date in place. Assuming so, it continues on with the following:
// [...]
echo "excute shc_reboot.sh"
sch_reboot.sh init
// [...]
Continuing into the /sbin/sch_reboot.sh
script:
#!/bin/sh
# schedule reboot
user=`nvram_get 2860 Login`
SCH_Reboot=`nvram_get 2860 SCH_Reboot`
echo "$1"
if [ "$1" = "init" ]; then
if [ "$SCH_Reboot" != "" ]; then
echo "$SCH_Reboot" >> /var/spool/cron/crontabs/"$user"
fi
fi
if [ "$1" = "reboot" ]; then
reboot
fi
We clearly see our SCH_Reboot
nvram item get read in and written into the adm2860
crontab. Thus, as long as our original restart_hour
[1] ,restart_min
[2], or restart_week
[3] variables are formatted correctly, we can inject crontab configuration into the crontab and quickly establish code execution.
004133fc int32_t sch_reboot(int32_t arg1)
0041342c char var_90
0041342c memset(&var_90, 0, 0x80)
00413454 var_90 = 0x30
00413468 int32_t $v0_1 = strdup(web_get("restart_hour", arg1, 0))
// [...]
004134f8 if (sx.d(*$v0_1) != 0 && sx.d(*$v0_3) != 0)
004135e0 snprintf(&var_90, 0x80, "%s %s * * %s /sbin/sch_reboot.sh reboot", $v0_3, $v0_1, $v0_5, 0x439d20)
004133fc int32_t sch_reboot(int32_t arg1)
0041342c char var_90
0041342c memset(&var_90, 0, 0x80)
00413454 var_90 = 0x30
// [...]
004134a0 int32_t $v0_3 = strdup(web_get("restart_min", arg1, 0))
// [...]
004134f8 if (sx.d(*$v0_1) != 0 && sx.d(*$v0_3) != 0)
004135e0 snprintf(&var_90, 0x80, "%s %s * * %s /sbin/sch_reboot.sh reboot", $v0_3, $v0_1, $v0_5, 0x439d20)
0041342c char var_90
0041342c memset(&var_90, 0, 0x80)
00413454 var_90 = 0x30
// [...]
004134d8 int32_t $v0_5 = strdup(web_get("restart_week", arg1, 0)) // [3]
// [...]
004134f8 if (sx.d(*$v0_1) != 0 && sx.d(*$v0_3) != 0)
004135e0 snprintf(&var_90, 0x80, "%s %s * * %s /sbin/sch_reboot.sh reboot", $v0_3, $v0_1, $v0_5, 0x439d20) // [4]
2024-07-25 - Initial Vendor Contact
2024-07-29 - Requesting reply from vendor
2024-07-30 - Vendor confirms receipt
2024-07-30 - Vendor Disclosure
2024-07-30 - Vendor confirms receipt
2024-09-02 - Status update request sent
2024-10-15 - Status update request. Upcoming expiration date announced.
2024-10-22 - Vendor replies product has been discontinued, but patches are being worked on
2024-11-04 - Status update request for patch release dates
2024-11-12 TALOS advisory release date announced
2025-01-14 - Public Release
Discovered by Lilith >_> of Cisco Talos.