ARM-X Firmware Emulation Framework

by Saumil Shah @therealsaumil

November 2019

ARMX

The ARM-X Firmware Emulation Framework is a collection of scripts, kernels and filesystems to be used with QEMU to emulate ARM/Linux IoT devices. ARM-X is aimed to facilitate IoT research by virtualising as much of the physical device as possible. It is the closest we can get to an actual IoT VM.

Devices successfully emulated with ARM-X so far:

Precursors of ARM-X have been used in Saumil Shah's popular ARM IoT Exploit Laboratory training classes where students have found four 0-day vulnerabilities in various ARM/Linux IoT devices.

ARM-X Architecture and Operations

ARM-X is a collection of scripts, kernels and filesystems residing in the /armx directory. It uses qemu-system-arm to boot up a virtual ARM/Linux environment. The /armx directory is exported over NFS to also make the contents available within the QEMU guest.

The host system running qemu-system-arm is assigned the IP address 192.168.100.1 and the QEMU guest is assigned 192.168.100.2 via tap0 interface.

Architecture

The /armx directory is organised as follows:

Directory Structure

Each emulated device contains the following files/directories:

The diagram below describes each stage of ARM-X:

ARM-X Operations

  1. Invoke /armx/run/launcher. This will display a menu as shown below. In this example, we select the Trivision TRI227WF Wireless IP Camera.

ARM-X Launcher

  1. Selecting one of the devices will launch it under QEMU. The kernel which is included in the kernel/ directory of the Trivision IP Camera's device configuration, is booted in qemu-system-arm and uses a pre-built Buildroot filesystem, which is referred to as hostfs.ext2. Host and guest IP addresses are assigned to 192.168.100.1 and 192.168.100.2 respectively.

ARM-X Kernel Boot Up

  1. hostfs.ext2 contains several scripts and tools useful for running and dynamic analysis of the emulated device. The init scripts in hostfs.ext2 mount the /armx directory over NFS. Thus, the contents of /armx are shared by both the host and the QEMU guest.

  2. To kick off the rest of the device startup, connect to the QEMU guest using SSH ssh root@192.168.100.2. This brings up a menu as shown below:

ARM-X Trivision Init

  1. Selecting the option to launch the userland init scripts of the device results in run-init being invoked from the corresponding device configuration directory within /armx. First, the contents of nvram.ini are loaded into the kernel's emulated nvram driver. Next, a chroot jail is created using the rootfs of the device. Lastly, the registered initialisation commands are invoked in the newly chrooted rootfs, bringing up the device's services and init scripts.

ARM-X Trivision Started

  1. Once the device has fully "booted up" in ARM-X, it is available for testing and analysis. The image below shows the administration interface of the IP Camera loaded in a browser:

ARM-X Admin Interface

Creating your own emulated IoT Device

Before you begin to emulate an IoT device, you will need the following:

The following diagram outlines the overall process of IoT device emulation.

Adding a new device

Steps involved:

  1. Copy the template directory to make a new device configuration.
  2. Compile a matching kernel from source, and place it in the kernel/ directory.
  3. Copy the extracted rootfs from the device's firmware into the rootfs/ directory. Typically these would be SquashFS or CramFS filesystems, uncompressed using binwalk or unsquashfs or cramfsck.
  4. Place the contents of extracted nvram in nvram.ini
  5. Edit the config file with the newly populated device firmware contents.
  6. Create a new device record in the devices file. Pay close attention to QEMU command line options.

The following sample kernels are provided with the template.

However, it is encouraged to build a compatible kernel from source.

ARM-X Presentations

Presentation at Countermeasure 2019 on 7 November 2019.

INSIDE ARM-X - Countermeasure 2019 from Saumil Shah

Release presentation at HITB+Cyberweek on 16 October 2019.

Introducing ARM-X from Saumil Shah

The ARM IoT Firmware Laboratory - NEW TRAINING

An all new class where the ARM IoT EXPLOIT LABORATORY leaves off. The ARM IoT Firmware Laboratory dives into analysis, extraction and emulation of IoT device firmware, using a variety of techniques. Students shall be given ample hands on practice in emulating a variety of IoT devices. Lab exercises feature firmware extraction directly from the hardware, building a custom kernel and buildroot environment, extracting contents of nvram and emulating the device under ARM-X. The class also goes on to fuzzing and exploit development exercises for the emulated devices.

Upcoming classes:

  1. OffensiveCon 2020, Berlin: [SOLD OUT] https://www.offensivecon.org/trainings/2020/the-arm-iot-firmware-laboratory-2020.html

  2. HITB2020AMS, Amsterdam: (3 day class) https://conference.hitb.org/hitbsecconf2020ams/sessions/3-day-training-1-the-arm-iot-laboratory/

  3. Ringzer0 2020, Las Vegas: (4 day class) https://ringzer0.training/arm-iot-firmwarelab.html

Downloads

Pre-built VM with ARM-X installed

VMware VM: https://app.box.com/s/3iyi5f6vpakngh8ti3ir2zzukgdu0j2q

The ARM-X VM is compressed using 7-Zip. The archive is split into multiple files of 200MB each, because several cloud hosting providers impose a maximum limit. To extract the VM, use the 7z command line utility:

7z e armx-november2019.7z.001

SHA 256 Checksums:

562144c896ec586ef3676efdc44957b28638dde9c14e48bef54aeb16c01714e2  armx-november2019.7z.001
9755449202e8c7677a6987a8bb2b84b72320446813b4c9fafcefe0f135eded37  armx-november2019.7z.002

2fa814609c86b2ecf331508f38d4b24834d814cf2f203f499a6ffd7681f7ef26  armx-alpine.vmx
c491a8d0181b4af5df4a8cd0009cbf392e534fba7ea1e5dc5524c631fe37d08e  armx-s001.vmdk
f5d961585bd4b3911f2394a0ee49eb7b928b7f22e20fcdd759b74786dafacff3  armx.vmdk

VirtualBox VM: (coming soon, but don't hold your breath)

ARM-X Code

Github: https://github.com/therealsaumil/armx/

ARM-X Documentation

Tutorial: Debugging With ARM-X

END

ARM-X is licensed under the Mozilla Public License v2.0 (MPLv2).