FAT 旨在帮助安全研究人员分析和识别物联网及嵌入式设备固件中的漏洞。该工具也用于由 Attify 举办的“Offensive IoT Exploitation”培训课程。
注意:
目前,它只是一个用于自动化 Firmadyne 的脚本,Firmadyne 是一款用于固件仿真的工具。如果实际仿真遇到问题,请将问题提交到 firmadyne issues。
如果你遇到问题,可以尝试 AttifyOS,它预装了固件分析工具包和其他工具,开箱即用。
固件分析工具包(以下简称 FAT)基于 Firmadyne 并做了一些改动。Firmadyne 使用 PostgreSQL 数据库来存储仿真镜像的信息。但仅就固件仿真的核心功能而言,实际上并不需要 PostgreSQL。因此 FAT 没有使用它。
FAT 使用 Python 3 开发。不过你需要同时安装 Python 3 和 Python 2,因为 Firmadyne 及其部分依赖使用 Python 2。强烈建议在虚拟机内安装 FAT。
安装只需克隆仓库并运行脚本 ./setup.sh。
git clone https://github.com/attify/firmware-analysis-toolkit
cd firmware-analysis-toolkit
./setup.sh
安装完成后,编辑文件 fat.config,按如下格式提供 sudo 密码。Firmadyne 的部分操作需要 sudo 权限。提供 sudo 密码是为了实现流程自动化。
[DEFAULT]
sudo_password=attify123
firmadyne_path=/home/attify/firmadyne
$ ./fat.py <固件文件>
将固件文件名作为参数提供给脚本。
脚本会显示所创建网络接口的 IP 地址。请记下这些地址。
最后,它会提示正在运行固件。按下 ENTER 键,等待固件启动。用上一步显示的 IP 地址执行 ping 操作,或在浏览器中打开。
恭喜!固件已成功仿真。
要清除所有已分析的固件镜像,请运行
$ ./reset.py
$ ./fat.py DIR-601_REVB_FIRMWARE_2.01.BIN
__ _
/ _| | |
| |_ __ _ | |_
| _| / _` | | __|
| | | (_| | | |_
|_| \__,_| \__|
Welcome to the Firmware Analysis Toolkit - v0.3
Offensive IoT Exploitation Training http://bit.do/offensiveiotexploitation
By Attify - https://attify.com | @attifyme
[+] Firmware: DIR-601_REVB_FIRMWARE_2.01.BIN
[+] Extracting the firmware...
[+] Image ID: 1
[+] Identifying architecture...
[+] Architecture: mipseb
[+] Building QEMU disk image...
[+] Setting up the network connection, please standby...
[+] Network interfaces: [('br0', '192.168.0.1')]
[+] All set! Press ENTER to run the firmware...
[+] When running, press Ctrl + A X to terminate qemu
Asciicast
$ ./fat.py DIR890A1_FW103b07.bin --qemu 2.5.0
__ _
/ _| | |
| |_ __ _ | |_
| _| / _` | | __|
| | | (_| | | |_
|_| \__,_| \__|
Welcome to the Firmware Analysis Toolkit - v0.3
Offensive IoT Exploitation Training http://bit.do/offensiveiotexploitation
By Attify - https://attify.com | @attifyme
[+] Firmware: DIR890A1_FW103b07.bin
[+] Extracting the firmware...
[+] Image ID: 2
[+] Identifying architecture...
[+] Architecture: armel
[+] Building QEMU disk image...
[+] Setting up the network connection, please standby...
[+] Network interfaces: [('br0', '192.168.0.1'), ('br1', '192.168.7.1')]
[+] Using qemu-system-arm from /home/attify/firmware-analysis-toolkit/qemu-builds/2.5.0
[+] All set! Press ENTER to run the firmware...
[+] When running, press Ctrl + A X to terminate qemu
目前,ARM firmadyne 内核 无法与 Ubuntu 18.04 官方仓库中的最新版 Qemu (2.11.1) 配合使用。不过,Ubuntu 16.04 上的 Qemu (2.5.0) 可以正常工作。你也可以像示例 2 那样使用 firmadyne 自带的 Qemu (2.5.0)。
如果没有检测到网络接口,请尝试增大 scripts/inferNetwork.sh 中的超时时间(默认 60 秒),修改如下:
echo "Running firmware ${IID}: terminating after 60 secs..."
timeout --preserve-status --signal SIGINT 60 "${SCRIPT_DIR}/run.${ARCH}.sh" "${IID}"
仓库中已经包含了 Qemu 2.0.0、2.5.0 和 3.0.0 的静态构建(在 Releases 中),但如果你想自行构建,请按照以下步骤操作。
在一个干净的 Ubuntu 16.04 虚拟机中运行。(务必使用 16.04,更高版本在静态编译方面存在问题。)
sudo apt update && sudo apt build-dep qemu -y
wget https://download.qemu.org/qemu-2.0.0.tar.bz2
tar xf qemu-2.0.0.tar.bz2
mkdir qemu-2.0.0-build
cd qemu-2.0.0
./configure --prefix=$(realpath ../qemu-2.0.0-build) --static --target-list=arm-softmmu,mips-softmmu,mipsel-softmmu --disable-smartcard-nss --disable-spice --disable-libusb --disable-usb-redir
make
make install
编译后的二进制文件位于 qemu-2.0.0-build 目录中。
sudo apt update && sudo apt build-dep qemu -y
wget https://download.qemu.org/qemu-2.5.0.tar.bz2
tar xf qemu-2.5.0.tar.bz2
mkdir qemu-2.5.0-build
cd qemu-2.5.0
./configure --prefix=$(realpath ../qemu-2.5.0-build) --static --target-list=arm-softmmu,mips-softmmu,mipsel-softmmu --disable-smartcard --disable-libusb --disable-usb-redir
make
make install
编译后的二进制文件位于 qemu-2.5.0-build 目录中。
sudo apt update && sudo apt build-dep qemu -y
wget https://download.qemu.org/qemu-3.0.0.tar.bz2
tar xf qemu-3.0.0.tar.bz2
mkdir qemu-3.0.0-build
cd qemu-3.0.0
./configure --prefix=$(realpath ../qemu-3.0.0-build) --static --target-list=arm-softmmu,mips-softmmu,mipsel-softmmu --disable-smartcard --disable-libusb --disable-usb-redir
make
make install
编译后的二进制文件位于 qemu-3.0.0-build 目录中。
注意:也可以在 Alpine 系统上静态编译 Qemu,但此方法尚未经过测试。通常更倾向于在 Alpine 而非 Ubuntu 上进行编译,因为 Alpine 使用 musl libc,其在静态链接方面优于 Ubuntu 上的 glibc。