×
Copy
Open
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Slide 1
Slide 1 text
1st Reproducing Vulnerability in IoT YJK@HackerSir
Slide 2
Slide 2 text
Table of contents 01 03 02 04 IoT Security Get Firmware Firmware Emulation CVE-2024-2897 實作
Slide 3
Slide 3 text
IoT Security 01
Slide 4
Slide 4 text
Why learn IoT Security
Slide 5
Slide 5 text
Everything Can PWN ● C/C++ ● Browser ● Blockchain ● Kernel ● Mobile ● Virtualization ● IoT
Slide 6
Slide 6 text
Everything Can PWN ● C/C++ ● Browser ● Blockchain ● Kernel ● Mobile ● Virtualization ● IoT
Slide 7
Slide 7 text
Why learn IoT Security ● I use many IoT device ■ router ■ nas ■ light ■ fan ■ …
Slide 8
Slide 8 text
Why learn IoT Security
Slide 9
Slide 9 text
Why learn IoT Security ● code base 相對小 ● firmware 以實用為優先 ● 保護機制有時會比較神奇
Slide 10
Slide 10 text
Get Firmware 02
Slide 11
Slide 11 text
How To Get Firmware? ● 下載網站 ● 資安公告 ● 尋找同一系列產品 ● 都找不到?
Slide 12
Slide 12 text
How To Get Firmware? ● dump using UART ● dump using Bus-Pirate ● during OTA Upgrade
Slide 13
Slide 13 text
Extract Firmware ● 7z ■ get image file or file system ● binwalk ● dd ● squashfs-tools ● lzma
Slide 14
Slide 14 text
排雷 ● 建議 binwalk 可以載 source code compile ● 直接 apt install 會有某些 dependencies 載不好 ● Compile From Source
Slide 15
Slide 15 text
dd ● 只想拿特定區段檔案 ● dd if=[] bs=[] skip=[] count=[] of=[] ■ if:input file ■ bs:block size ■ skip:from which start reading ■ count:read bytes size ■ of:output file ● skip 預設會直接讀到檔案尾端
Slide 16
Slide 16 text
Firmware Encrypt ● binwalk –E [file] 可以觀察 entropy ● 需要往前看前面版本是否有解密函式 ● 從 u-boot 尋找:通常無法加密
Slide 17
Slide 17 text
Firmware Analysis ● 建議可以使用 Ghidra ● 相對 ida free 支援更多的架構 ● 後面需要 patch binary 好使用 (可以 patch instruction) ● 可以用 BinDiff 觀察與前一版 firmware 的差異 ● Free!!Free!!Free!!
Slide 18
Slide 18 text
目標 ● 拿到 file system ● 獲得 binary 分析 ● 直接模擬 file system ● 重點還是實際找漏洞並且寫 PoC 測試
Slide 19
Slide 19 text
Firmware Emulation 03
Slide 20
Slide 20 text
Tools ● chroot、systemd-nspawn ● QEMU ● Firmadyne ● Firmware Analysis Toolkit ● Qiling ● Unicorn Engine
Slide 21
Slide 21 text
chroot、systemd-nspawn ● dynamically linked 的程式會有 library 路徑問題 ● 需要包住整個 filesystem ● 如果有找到啟動 script 也可以直接執行 ● /etc/init.d 可以優先看
Slide 22
Slide 22 text
QEMU ● virtual machine monitor ● System Emulation/User Mode ● System Emulation 會較接近真實系統 ● User Mode 可以只執行一個 binary ● 支援多種架構 ■ 包含 IoT 會見到的 mips、arm…
Slide 23
Slide 23 text
Firmadyne ● https://github.com/firmadyne/firmadyne ● 自動模擬 & 分析 ● 可以進行漏洞測試 ● 需進行基礎設定 ● Based on QEMU
Slide 24
Slide 24 text
Firmadyne ● 解壓縮 firmware ● 分析架構 ● 採集資訊 ● 建立模擬鏡像 ● 識別韌體網路設定 ● 運行 firmware
Slide 25
Slide 25 text
Firmware Analysis Toolkit ● 自動化 Firmadyne 的 script ● 處理 Firmadyne 中的初始設定工作 ● 只需要給 root 密碼跟 Firmadyne 路徑
Slide 26
Slide 26 text
Firmware Analysis Toolkit ● 自動化 Firmadyne 的 script ● 處理 Firmadyne 中的初始設定工作 ● 只需要給 root 密碼跟 Firmadyne 路徑 ● 目前與 Firmadyne 相同皆只有 sample 可以成功執行
Slide 27
Slide 27 text
Unicorn Engine ● CPU emulator framework ● 支援多種架構 ● 可以只執行一個 function ■ 用來解加密 firmware ● 需要先 mapping 每一個 Section 到模擬的記憶體區塊 ● hook 程式流程
Slide 28
Slide 28 text
Qiling ● https://github.com/qilingframework/qiling ● 支援多種架構 ● 可以動態 patch ● 透過 unicorn 模擬 instruction ● 有 loader、linker,並可以處理 IO
Slide 29
Slide 29 text
Now ● chroot、systemd-nspawn 掛起來跑 script ● QEMU ● Qiling
Slide 30
Slide 30 text
CVE-2024-2897 實作 04
Slide 31
Slide 31 text
firmware ● https://www.tenda.com.cn/download/detail-2776.html ● 沒有加密 ● 直接 binwalk 或是 7z 就可以解開 filesystem
Slide 32
Slide 32 text
漏洞點 ● https://nvd.nist.gov/vuln/detail/CVE-2024-2897 ● network service ● binary:/bin/httpd ● function:formWriteFacMac ● file:/goform/WriteFacMac ● argument:mac
Slide 33
Slide 33 text
分析 ● 未經驗證直接將參數帶入 doSystemCmd function
Slide 34
Slide 34 text
分析 ● 事實上最後會直接跑 system
Slide 35
Slide 35 text
模擬 ● 確認檔案類型 ■ MIPS, MIPS32 rel2 version 1 (SYSV) ● cp /usr/bin/qemu-mipsel-static . ● sudo chroot ./ ./qemu-mipsel-static ./bin/httpd
Slide 36
Slide 36 text
模擬
Slide 37
Slide 37 text
模擬 ● 逆向分析會發現有幾個部分需要 patch ● IoT firmware 會有某些部份需要跟硬體做交互 ● 根據結果有兩種方式 (將驗證部分直接修改為相反邏輯) ■ == -> != ■ < -> >= ■ ...
Slide 38
Slide 38 text
模擬 ● 逆向分析會發現有幾個部分需要 patch ● IoT firmware 會有某些部份需要跟硬體做交互 ● 根據結果有兩種方式 (直接給回傳值) ■ init_core_dump 需要回傳 0 ■ apmib_init 需要回傳 1 ■ check_network 需要回傳 1 ■ ConnectCfm 需要回傳 1
Slide 39
Slide 39 text
模擬 ● 逆向分析會發現有幾個部分需要 patch ● IoT firmware 會有某些部份需要跟硬體做交互 ● 根據結果有兩種方式 (直接給回傳值) ■ init_core_dump 需要回傳 0 ■ apmib_init 需要回傳 1 ■ check_network 需要回傳 1 ■ ConnectCfm 需要回傳 1 ● 稍微看一下 mips 的 instruction 做 patch,非本日重點
Slide 40
Slide 40 text
模擬 ● 沒有 listen 到正常 port
Slide 41
Slide 41 text
模擬 ● 沒有 listen 到正常 port ● 逆向發現應該是會去拿 br0 這張網卡的 ip
Slide 42
Slide 42 text
模擬 ● 加一張網卡 ● sudo brctl addbr br0 ● sudo ifconfig br0 192.168.132.169/24
Slide 43
Slide 43 text
模擬
Slide 44
Slide 44 text
PoC ● 依照分析結果應該只需要一次請求 ● 直接用 firefox 送 GET 請求 ● http://192.168.132.169/goform/WriteFacMac?mac=;ls
Slide 45
Slide 45 text
PoC
Slide 46
Slide 46 text
PoC PWNED!!!!!!
Slide 47
Slide 47 text
結論 ● 超基本 command injection 爛洞 ● Tenda 有一整排這種 command injection ● IoT 這種洞不少見 ● 希望下次不是復現可以有新的漏洞點
Slide 48
Slide 48 text
No content