本文主要是介绍Firmware Analysis Toolkit 模拟固件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、前言
1、系统:Ubuntu 18.04.5下载:http://mirrors.ustc.edu.cn/ubuntu-releases/2、工具:2.1、Firmadyne项目地址:GitHub - firmadyne/firmadyne: Platform for emulation and dynamic analysis of Linux-based firmwareREADME.md中有详细的配置和安装步骤2.2、Firmware Analysis Toolkit项目地址:https://github.com/attify/firmware-analysis-toolkit.git该工具集包含了binwalk、Firmadyne等必须的工具。这里我们只需要克隆该仓库到本地即可。
二、安装Firmadyne
2.1 克隆Firmware Analysis Toolkit工具集仓库
# 1. 安装依赖
sudo apt-get install busybox-static fakeroot git dmsetup kpartx netcat-openbsd nmap python-psycopg2 python3-psycopg2 snmp uml-utilities util-linux vlan
# 2. clone
cd /home
git clone --recursive https://github.com/firmadyne/firmadyne.git
2.2、Extractor--安装binwalk
# 1. 安装依赖和binwalk
git clone https://github.com/ReFirmLabs/binwalk.git
cd binwalk
sudo ./deps.sh
sudo python ./setup.py install# 2. 对于 python2.x,还需要安装以下的库
sudo -H pip install git+https://github.com/ahupp/python-magic
sudo -H pip install git+https://github.com/sviehb/jefferson# 3. 测试是否安装成功
$ binwalk
Binwalk v2.1.2-c036535
Craig Heffner, ReFirmLabs
https://github.com/ReFirmLabs/binwalkUsage: binwalk [OPTIONS] [FILE1] [FILE2] [FILE3] ...Disassembly Scan Options:-Y, --disasm Identify the CPU architecture of a file using the capstone disassembler... ...-s, --status=<int> Enable the status server on the specified port
2.3、安装配置postgresql数据库
sudo apt-get install postgresql
# 用户的密码设置为:firmadyne
sudo -u postgres createuser -P firmadyne
sudo -u postgres createdb -O firmadyne firmware
# 注意这里的数据库文件是在firmadyne/目录下,也就是该命令要在根目录firmadyne/目录下执行
sudo -u postgres psql -d firmware < /home/firmadyne/database/schemasudo service postgresql start
sudo service postgresql status
2.4、安装Firmadyne
sh ./download.sh
vi /home/firmadyne/firmadyne.config
# 以下为firmadyne.config中的内容
# uncomment and specify full path to FIRMADYNE repository
FIRMWARE_DIR=/home/firmadyne/ # 重点修改
# specify full paths to other directories
BINARY_DIR=${FIRMWARE_DIR}/binaries/
TARBALL_DIR=${FIRMWARE_DIR}/images/
SCRATCH_DIR=${FIRMWARE_DIR}/scratch/
SCRIPT_DIR=${FIRMWARE_DIR}/scripts/
# functions to safely compute other paths
... ...
2.5、安装qemu
- 直接通过apt-get安装:sudo apt-get install qemu-system-arm qemu-system-mips qemu-system-x86 qemu-utils
- 编译安装
git clone git://git.qemu.org/qemu.git
cd qemu
git submodule init
git submodule update --recursive
apt install libglib2.0 libglib2.0-dev
apt install autoconf automake libtool
./configure
make
make install
三、安装FAT(firmware-analysis-toolkit)
3.1、clone并执行./setup.sh
git clone https://github.com/attify/firmware-analysis-toolkit
cd firmware-analysis-toolkit
./setup.sh
3.2、编辑fat.config
3.3、安装qemu
cd qemu-builds
wget -O qemu-system-static-2.5.0.zip "https://github.com/attify/firmware-analysis-toolkit/files/4244529/qemu-system-static-2.5.0.zip"
unzip -qq qemu-system-static-2.5.0.zip && rm qemu-system-static-2.5.0.zip
cd ..
四、测试运行FAT
4.1、运行FAT
- 提供固件文件名作为脚本的参数。
- 该脚本将显示分配给创建的网络接口的 IP 地址。 记下来。
- 最后,它会说运行固件。 按 ENTER 并等待固件启动。 Ping 上一步中显示的 IP,或在浏览器中打开。
4.2、下载要模拟的路由器固件
4.3、测试运行
root@node1:/home/firmware-analysis-toolkit# ./fat.py /home/firmware-analysis-toolkit/'WNAP320 Firmware Version 2.0.3.zip'
firmadyne_path0:/home/firmadyne
sudo_pass:firmadyne__ _/ _| | || |_ __ _ | |_| _| / _` | | __|| | | (_| | | |_|_| \__,_| \__|Welcome to the Firmware Analysis Toolkit - v0.3Offensive IoT Exploitation Training http://bit.do/offensiveiotexploitationBy Attify - https://attify.com | @attifyme
args.firm_path:/home/firmware-analysis-toolkit/WNAP320 Firmware Version 2.0.3.zip
[+] Firmware: WNAP320 Firmware Version 2.0.3.zip
[+] Extracting the firmware...
firmadyne_path:/home/firmadyne
extractor_cmd:/home/firmadyne/sources/extractor/extractor.py, extractor_args:['-np', '-nk', '/home/firmware-analysis-toolkit/WNAP320 Firmware Version 2.0.3.zip', '/home/firmadyne/images']
tag:WNAP320 Firmware Version 2.0.3.zip_51eddc7046d77a752ca4b39fbda50aff
image_tgz:/home/firmadyne/images/WNAP320 Firmware Version 2.0.3.zip_51eddc7046d77a752ca4b39fbda50aff.tar.gz
[+] Image ID: 7
[+] Identifying architecture...
[+] Architecture: mipseb
[+] Building QEMU disk image...
[+] Setting up the network connection, please standby...
[+] Network interfaces: [('brtrunk', '192.168.0.100')]
[+] All set! Press ENTER to run the firmware... #空格键
[+] When running, press Ctrl + A X to terminate qemu
[+] Command line: /home/firmadyne/scratch/7/run.sh
Creating TAP device tap7_0...
Set 'tap7_0' persistent and owned by uid 0
Bringing up TAP device...
Adding route to 192.168.0.100...
Starting firmware emulation... use Ctrl-a + x to exit
firmadyne
.........................................................
System initilization is .. [DONE...]
Welcome to SDK.
Have a lot of fun...
netgear123456 login: [ 25.872000] brtrunk: port 1(eth0) entering forwarding state
[ 31.376000] eth0: no IPv6 routers present
[ 31.784000] brtrunk: no IPv6 routers present
从[+] Network interfaces : [('brtrunk', '192.168.0.100')]可以看到,启动了一个服务,可以通过http://192.168.0.100/访问
五、制作firmware-analysis-toolkit镜像
docker pull 1162886013/simulation:1.0
docker run -it --rm --privileged -p 8066:80 -v /dev:/dev -v /home/firmware_run/input:/root/input 1162886013/simulation:1.0 ./fat.py /root/input/"WNAP320 Firmware Version 2.0.3.zip"
端口映射以便可以访问Netgear 固件的网页:
在docker容器内(IP:172.17.0.2)添加端口映射
```shell
root@30f4fcce93c7:~/firmware-analysis-toolkit# iptables -t nat -A POSTROUTING -j MASQUERADE
root@30f4fcce93c7:~/firmware-analysis-toolkit# iptables -t nat -A PREROUTING -d 172.17.0.2 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.100:80
root@30f4fcce93c7:~/firmware-analysis-toolkit# iptables -t nat -A POSTROUTING -d 192.168.0.100 -p tcp --dport 80 -j SNAT --to 172.17.0.2web访问地址:http://宿主机hostip:8066 # admin/password
六、参考
https://github.com/firmadyne/firmadyne 安装可行
https://github.com/attify/firmware-analysis-toolkit
https://github.com/leiwuhen92/firmware-analysis-toolkit_docker
安装postgres后状态不对_无痕的博客-CSDN博客
这篇关于Firmware Analysis Toolkit 模拟固件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!