使用 firmware-analysis-plus 一鍵模擬固件

Firmadyne 是一個自動化和可擴展的系統,用於對基於 Linux 的嵌入式固件執行仿真和動態分析。詳細說明見:基於Firmadyne的固件模擬環境搭建。奈何該工具實際配置較爲複雜,後來 attify 製作了開源工具 firmware-analysis-toolkit 整合相關流程,進一步降低了該工具的使用難度。

儘管 firmware-analysis-toolkit 還在不斷更新,然而其中包含的諸多 bug,加上國內網絡不通暢,導致此工具在現實場景中很難真正安裝起來。爲此,筆者查看了firmware-analysis-toolkit 的部分源碼,修改了其中存在的 bug,在此基礎上重寫腳本,改成了一個新的項目,即 firmware-analysis-plus

firmware-analysis-plus

  • 項目說明:本項目依賴於 firmadyne 以及 firmware-analysis-toolkit,修復了其中的大量bug,可直接運行固件。
  • 項目地址https://github.com/liyansong2018/firmware-analysis-plus
  • 項目依賴:要求系統中,已經安裝 python2 python3 以及 binwalk。Kali 自帶 binwalk,但是仍然需要用源碼安裝的方式安裝 binwalk,因其自帶 binwalk 缺少很多依賴。

安裝 binwalk

設置 python 源,加快 python 模塊下載速度

找到 ~/.pip/pip.conf,如果不存在就創建,這一步是爲了加快下載 binwalk 依賴,添加以下內容

[global]
timeout = 10
index-url =  http://mirrors.aliyun.com/pypi/simple/
extra-index-url= http://pypi.douban.com/simple/
[install]
trusted-host=
    mirrors.aliyun.com
    pypi.douban.com

安裝 binwalk

$ git clone https://github.com/ReFirmLabs/binwalk.git
$ cd binwalk
$ sudo ./deps.sh
$ sudo python setup.py install

./deps.sh 命令,不能出錯,某些依賴沒有安裝可能會導致解包失敗
在這裏插入圖片描述
遇到此類問題,刪除 ./deps.sh 中的上述幾個包,繼續安裝。
在這裏插入圖片描述

如果報錯,先進行下面的步驟,安裝 firmware-analysis-plus ,在這個過程中,會自從安裝 python-pip 包,安裝完成之後,再回來安裝 binwalk。

安裝

運行 ./setup.sh ,如果報錯,請使用備用文件 ./setup2kali.sh,國內網路不通暢,如果更新卡住,終止程序,多試幾次就好了

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support                                          
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting python-magic
  Downloading https://mirrors.aliyun.com/pypi/packages/42/a1/76d30c79992e3750dac6790ce16f056f870d368ba142f83f75f694d93001/python_magic-0.4.15-py2.py3-none-any.whl (5.5 kB)
Installing collected packages: python-magic
Successfully installed python-magic-0.4.15
Setting up firmware analysis plus
=====================================================
Firmware Analysis Plus installed successfully!
Before running fat.py for the first time,
please edit fat.config and provide your sudo password

配置

修改 fat.config 文件中的密碼,改爲 root 系統用戶的密碼

運行

python3 fat.py -q /root/Documents/firmware-analysis-toolkit/qemu-builds/2.5.0/ /root/Documents/test/WNAP320_V3.7.11.4.zip

運行成功!
在這裏插入圖片描述
可登錄路由器網頁管理界面
在這裏插入圖片描述
終端輸入回車鍵,可進入 shell,賬號 root,密碼 password
在這裏插入圖片描述

總結

模擬固件的方式有多種,很難有一種工具可以完成對所有固件的模擬,如果是 CTF 中的一些固件,或者國外路由器的固件,其定製化程度往往較低,很容易使用我們的工具運行起來。但是,對於國內的主流廠商,想使用單一的工具搭建環境,模擬固件,還是較爲困難的。因此,最好的方式,還是分析固件的各個組成部分,提取內核和文件系統,這纔是最爲關鍵的部分。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章