attify / firmware-analysis-toolkit

Toolkit to emulate firmware and analyse it for security vulnerabilities
MIT License
1.29k stars 251 forks source link

Given No IP #83

Closed yhsnihao closed 1 year ago

yhsnihao commented 1 year ago

Hey there, I used Attify OS v3.0,and the firmwork is download from https://www.zhiwanyuzhou.com/download/Firmware/Router/Xiaomi/%E5%B0%8F%E7%B1%B3%E8%B7%AF%E7%94%B1%E5%99%A84A%E5%8D%83%E5%85%86%E7%89%88%EF%BC%88R4A%EF%BC%89/ when I run it like following:

iot@attifyos ~/t/firmware-analysis-toolkit> 
./fat.py ~/Desktop/Route/miwifi_r4a_firmware_72d65_2.28.62.bin 

                           __           _
                          / _|         | |
                         | |_    __ _  | |_
                         |  _|  / _` | | __|
                         | |   | (_| | | |_
                         |_|    \__,_|  \__|

            Welcome to the Firmware Analysis Toolkit - v0.3
Offensive IoT Exploitation Training http://bit.do/offensiveiotexploitation
              By Attify - https://attify.com  | @attifyme

[+] Firmware: miwifi_r4a_firmware_72d65_2.28.62.bin
[+] Extracting the firmware...
[+] Image ID: 2
[+] Identifying architecture...
[+] Architecture: mipsel
[+] Building QEMU disk image...
[+] Setting up the network connection, please standby...
[+] Network interfaces: []
[+] All set! Press ENTER to run the firmware...
[+] When running, press Ctrl + A X to terminate qemu

There's no Network interfaces given. I had referenced #https://github.com/attify/firmware-analysis-toolkit/issues/46 ,and increased the timeout value to 180 in scripts/inferNetwork.sh It doesn't work! I check the file: firmadyne/scratch/2/qemu.initial.serial.log

Dec 29 17:36:53 taskDaemon[383]: taskDaemon[5s check] service[/usr/sbin/taskmonitorServer] Abnormal exit!
[  175.016000] firmadyne: sys_socket[PID: 7892 (taskmonitorServ)]: family:1, type:2, protocol:0
[  175.024000] firmadyne: sys_socket[PID: 7892 (taskmonitorServ)]: family:1, type:1, protocol:0
[  175.024000] firmadyne: sys_socket[PID: 7892 (taskmonitorServ)]: family:1, type:2, protocol:0
[  175.024000] firmadyne: sys_socket[PID: 7892 (taskmonitorServ)]: family:1, type:1, protocol:0
[  175.028000] firmadyne: sys_socket[PID: 7892 (taskmonitorServ)]: family:1, type:2, protocol:0
[  176.656000] firmadyne: sys_socket[PID: 2224 (netapi)]: family:2, type:2, protocol:0
[  177.300000] firmadyne: sys_socket[PID: 2070 (messagingagent)]: family:2, type:2, protocol:6
[  177.300000] firmadyne: sys_setsockopt[PID: 2070 (messagingagent)]: fd:5, level:65535, optname:8
[  177.300000] firmadyne: sys_setsockopt[PID: 2070 (messagingagent)]: fd:5, level:6, optname:4
[  177.300000] firmadyne: sys_setsockopt[PID: 2070 (messagingagent)]: fd:5, level:6, optname:5

I don't know what wrong caused this error

jheysel-r7 commented 1 year ago

I'm facing the same issue trying to run the following firmware: VMG1312-T20B

[+] Setting up the network connection, please standby...
[+] Network interfaces: []
[+] All set! Press ENTER to run the firmware...

I also tried increasing the timeout in inferNetwork.sh which didn't work for me either.

extremecoders-re commented 1 year ago

@yhsnihao Just tested on a Ubuntu 20.04 VM. It's working fine and also accessible from the browser.

image

image Tunneled with localhost.run.

Contents of run.sh

#!/bin/bash

set -u

ARCHEND=mipsel
IID=2

if [ -e ./firmadyne.config ]; then
    source ./firmadyne.config
elif [ -e ../firmadyne.config ]; then
    source ../firmadyne.config
elif [ -e ../../firmadyne.config ]; then
    source ../../firmadyne.config
else
    echo "Error: Could not find 'firmadyne.config'!"
    exit 1
fi

IMAGE=`get_fs ${IID}`
KERNEL=`get_kernel ${ARCHEND}`
QEMU=`get_qemu ${ARCHEND}`
QEMU_MACHINE=`get_qemu_machine ${ARCHEND}`
QEMU_ROOTFS=`get_qemu_disk ${ARCHEND}`
WORK_DIR=`get_scratch ${IID}`

TAPDEV_0=tap${IID}_0
HOSTNETDEV_0=${TAPDEV_0}
echo "Creating TAP device ${TAPDEV_0}..."
sudo tunctl -t ${TAPDEV_0} -u ${USER}

echo "Bringing up TAP device..."
sudo ip link set ${HOSTNETDEV_0} up
sudo ip addr add 192.168.31.2/24 dev ${HOSTNETDEV_0}

echo "Adding route to 192.168.31.1..."
sudo ip route add 192.168.31.1 via 192.168.31.1 dev ${HOSTNETDEV_0}

function cleanup {
    pkill -P $$

echo "Deleting route..."
sudo ip route flush dev ${HOSTNETDEV_0}

echo "Bringing down TAP device..."
sudo ip link set ${TAPDEV_0} down

echo "Deleting TAP device ${TAPDEV_0}..."
sudo tunctl -d ${TAPDEV_0}

}

trap cleanup EXIT

echo "Starting firmware emulation... use Ctrl-a + x to exit"
sleep 1s

 ${QEMU} -m 256 -M ${QEMU_MACHINE} -kernel ${KERNEL} \
    -drive if=ide,format=raw,file=${IMAGE} -append "root=${QEMU_ROOTFS} console=ttyS0 nandsim.parts=64,64,64,64,64,64,64,64,64,64 rdinit=/firmadyne/preInit.sh rw debug ignore_loglevel print-fatal-signals=1 user_debug=31 firmadyne.syscall=0" \
    -nographic \
    -netdev tap,id=nettap0,ifname=${TAPDEV_0},script=no -device e1000,netdev=nettap0 -netdev socket,id=net1,listen=:2001 -device e1000,netdev=net1 -netdev socket,id=net2,listen=:2002 -device e1000,netdev=net2 -netdev socket,id=net3,listen=:2003 -device e1000,netdev=net3 | tee ${WORK_DIR}/qemu.final.serial.log
extremecoders-re commented 1 year ago

@jheysel-r7 Unfortunately the firmware VMG1312-T20B doesn't seem to be properly emulating. I would suggest to try qemu user mode emulation and run the /bin/zhttpd binary.

$ sudo chroot . ./qemu-mips-static -E LD_LIBRARY_PATH=/lib/private/ ./bin/zhttpd
Initial http with port(80), SSL disable.
2023-01-04 14:29:46 zhttpd<47922>, zcfg_msg.c:798, zcfg_msg_sendAndGetReply(), ERROR: fail to bind address. errno = 2, No such file or directory
2023-01-04 14:29:46 zhttpd<47922>, zcfg_msg.c:592, zcfg_msg_serverInit(), ERROR: bind message socket error. errno = 2, No such file or directory
http daemon exit....

It exits on startup and you can research more on this.

yhsnihao commented 1 year ago

@extremecoders-re Thank you. I build a clean Ubuntu 22.04 VM,It worked! 图片

But there's something wrong on Ubuntu 20.04. 图片 I think I may need more research.