Getting started with Firmware Emulation for IoT Devices

In this post, we will have a look at how we can perform Firmware Emulation of a given IoT device.

Firmware Emulation can serve a number of different purposes such as analyzing the firmware in a better way, performing exploitation, performing remote debugging and so on.

With this technique, you can emulate a Firmware originally meant to be run on a different architecture, and interact with it, even without having a physical IoT device.

One of the earlier ways of performing Firmware Emulation was to create a Qemu image and then copy the firmware file system's contents on to the Qemu image and then launch the image.

However, there exists a much simpler alternative which is also prone to give you lesser issues while emulating firmware. Let's have a look.

Tools that you would require:

Setting things up

Once you have all three of the above components, the first step is to set up Firmware Analysis Toolkit.

Firmware Analysis Toolkit is simply a wrapper around the actual project Firmadyne and automates the process of emulating a new firmware.

To download and install FAT, simply clone the git repository recursively as shown below:

git clone --recursive https://github.com/attify/firmware-analysis-toolkit.git

Cloning-Firmware-Analysis-Toolkit

Next, we will need to setup the individual tools such as Binwalk, Firmadyne and Firmware-Mod-Kit.

Set up Binwalk

To Set Up Binwalk, simply install the dependencies as below and then go ahead and install the tool :

cd firmware-analysis-toolkit/binwalk
sudo ./deps.sh
sudo python setup.py install 

If everything went well, you would be able to run binwalk and receive an output as shown below.

Binwalk

Set up Firmadyne

To setup Firmadyne, navigate to the Firmadyne folder and open up firmadyne.config. It should look as shown in the picture below.

firmadyne-configuration

Uncomment the line saying FIRMWARE_DIR=/home/vagrant/firmadyne/ and modify the address to the current path of Firmadyne. The updated line in my case looks like as shown below.

new-firmadyne-config

Once you have updated the path, the next step is to download the additional binaries required for Firmadyne to work. This might take a while (1-2 mins on a good internet connection) - so have a coffee (or beer) at this point of time.

firmadyne-downloading-additional-binaries

Once it is done, the next step is to install the remaining depencies for Firmadyne to function properly:

sudo -H pip install git+https://github.com/ahupp/python-magic
sudo -H pip install git+https://github.com/sviehb/jefferson
sudo apt-get install qemu-system-arm qemu-system-mips qemu-system-x86 qemu-utils

Also set up a PostgreSQL database at this point following the instructions from the official Firmadyne wiki:

sudo apt-get install postgresql
sudo -u postgres createuser -P firmadyne
sudo -u postgres createdb -O firmadyne firmware
sudo -u postgres psql -d firmware < ./firmadyne/database/schema

The password for the database when prompted should be firmadyne (to avoid any later issues).

That is all for the setup of Firmadyne.

Set up Firmware Analysis Toolkit

The first thing that we will do is move the fat.py and reset.py to inside firmadyne folder.

Once that is done, open up fat.py and modify the root password (so that it won't ask you for password while running the script) and specify the path of firmadyne as shown below.

firmware-analysis-toolkit

That's all for the setup. Make sure that your postgresql database is up and running

postgresql-running

.. and we are good to go.

Emulating a firmware image

All you need to do in order to now emulate a firmware is run ./fat.py and specify the firmware name. In this case, we are running the WNAP320.zip firmware, so we will specify that.

For the Brand, you can specify any brand, as that is used for purely database purposes.

Your output should be as shown below:

running-firmware-analysis-toolkit

Once it has completed the initial setup process for the firmware, it will provide you with an IP address. In case the firmware runs a web server, you should be able to access the web interface, as well as interact with the firmware over SSH and perform additional network based exploitation.

network-config

Let's now open up Firefox and see if we are able to access the web interface.

web-interface-of-the-firmware

Congratulations!!! - we have successfully emulated a firmware (which was originally meant for MIPS Big Endian architecture) and even have the web server from within the firmware accessible!

That is all for this blog post. For any further queries, feel free to reach out to us using our contact page .

IoT Penetration Testing and Exploitation training

Redesign_grande-1

You can also now sign up for one of our public training bootcamps where you can learn all about IoT Exploitation (Embedded, Firmware, Radio, BLE, ZigBee, Binary etc.) - https://www.attify-store.com/collections/real-world-training/products/offensive-iot-exploitation-live-training



comments powered by Disqus
Tags
Android android application security android hands on security and exploitation training android security Apktool application auditing application security auditing appsec usa appwatch attify attify badge attify training binwalk blackberry pentesting blackhat ble BLE hacking and exploitation BLE sniffing box brut Exception chroot cloud based mobile application security scanner consulting CTF Damn Vulnerable iOS App devops dumping memory embedded hacking exploitation exploiting smart devices Firmware hacking frida hackfest hacking smart devices how to secure iot device IDA internet of things Internet of Things Security ios application security ios security iot iot device IoT Exploitation iot hacking iot pentest iot pentesting iot security iot security training iotsecurity jtag jtag debugging mobile app mobile application security mobile application security testing mobile security ninja recon technique offensive iot exploitation ola cabs owasp owasp appsec penetration testing pentesting pentesting mobile apps powerofcommunity PrinterSecurity qemu quizup radio communication protocol radio coomunication Reversing sdr secure coding guidelines security security issue security services security training security vulnerability smart devices social networking spi threat modeling training uart vulnerability writeups xposed hooking zigbee zigbee exploitation zigbee security zwave firmware reverse engineering firmware emulation firmware analysis toolkit firmadyne getting started with firmware hacking iot penetration testing

Instagram