Recently, researchers uncovered evidence that an Android TV box manufacturer had intentionally embedded a backdoor in its device firmware. Known as XCPE, this backdoor allows the manufacturer to remotely execute arbitrary commands on affected Android TV boxes, potentially gaining extensive control over the devices. This includes installing or removing applications, modifying system configurations, collecting device information, and executing malicious payloads without the owner’s knowledge.
This discovery raises serious concerns about the security of low-cost Android devices, particularly those manufactured by lesser-known vendors with limited transparency and security oversight. Unlike conventional malware that users might unknowingly install, firmware-level backdoors can operate with elevated privileges, survive factory resets, and remain hidden from ordinary security scans. More importantly, users may have no practical way to verify whether the firmware running on their devices is trustworthy.
So, in this article, we’ll focus on learning how to inspect firmware and independently verify what a device actually does, rather than waiting to discover its hidden functionality through security news.
1. What is Firmware?
First, let’s see the firmware’s position in the diagram below. This diagram illustrates the common design of almost every device, from cameras and Wi-Fi routers to phones and computers.
USER
|
v
+---------------------------+
| APPLICATIONS |
| Browser, Camera App, etc. |
+---------------------------+
|
v
+---------------------------+
| OPERATING SYSTEM |
| Android, Linux, Windows |
+---------------------------+
|
v
+---------------------------+
| DEVICE DRIVERS |
| Hardware Communication |
+---------------------------+
|
v
+---------------------------+
| FIRMWARE |
| Hardware Initialization |
| Device Control |
| Low-level Operations |
+---------------------------+
|
v
+---------------------------+
| HARDWARE |
| CPU, RAM, Flash, Sensors, |
| Network Chip, Camera |
+---------------------------+
Conceptually, firmware sits between software and hardware, acting as a bridge between the two. It provides low-level instructions to initialize, configure, and control hardware components such as CPUs, memory, network chips, and wireless radios. At the same time, it exposes interfaces that allow higher-level software, such as operating systems and device drivers, to interact with these hardware resources without needing to understand every low-level hardware operation.
In simple terms, hardware provides the physical capabilities, firmware makes those capabilities accessible, and the operating system and applications use them to deliver features that users interact with.
When developing a device, manufacturers write firmware and embed it in non-volatile memory, typically flash storage, inside the device. When the device is powered on, its processor begins executing initial instructions stored in this memory to initialize essential hardware components, such as the CPU, RAM, storage controllers, and peripheral interfaces.
This initial startup process is known as the boot process. A small piece of firmware called the bootloader plays an important role in this process. It prepares the hardware environment, initializes memory, and locates and loads the operating system into RAM.
Once the operating system starts running, it takes control of system resources, initializes additional hardware through device drivers, and starts essential system services. Finally, it provides the environment in which applications can execute.
This process allows a device to transition from powered-off hardware into a fully functional system ready for users to interact with.
2. How to obtain a firmware?
To inspect a firmware, the first step is to obtain its firmware image, typically distributed as a binary file (such as .bin or .img) or packaged in a compressed archive (such as .zip or .tar.gz). These files contain the data that will eventually be written to the device’s flash memory, including bootloaders, operating systems, device drivers, configuration files, and other software components.
Depending on the device, there are three main ways to obtain its firmware: extracting it directly from the device’s flash memory, intercepting the firmware upgrade process, or simply downloading it from a publicly available repository or the manufacturer’s website.
Once we have obtained the firmware image, we can begin examining its internal structure to identify the filesystems, executable files, libraries, and other components embedded inside it.
2.1. Read the Flash Storage (the hard way)
The most direct way to obtain firmware is to read it directly from the device’s flash memory. This usually requires opening the device and locating its flash storage chip on the circuit board. Depending on the chip and device design, we can use several techniques, such as connecting a programmer through SPI or UART interfaces, using a dedicated flash memory reader, or attaching clips directly to the chip’s pins without removing it from the board. For some devices, we may need to desolder the chip before reading its contents.
Although this approach requires additional hardware, technical knowledge, and sometimes soldering skills, it has one significant advantage: we can retrieve the firmware currently installed on the device, rather than relying on files provided by the manufacturer. This is particularly useful when investigating older devices, modified firmware, or suspicious devices whose firmware versions are no longer publicly available.
However, this method also carries risks. Incorrect connections, voltage mismatches, or electrical interference can damage the flash chip or other components. Reading the chip while it is still connected to the board may also produce corrupted data if other components interfere with communication. In addition, some manufacturers implement hardware encryption, read protection, or secure boot mechanisms that make firmware extraction more difficult.
Despite these challenges, reading flash storage is one of the most direct approaches to obtaining the actual firmware running on a device.
2.2. Intercept Upgrade Firmware Process (less hard, but still hard)
When interacting with the circuit board is not an option, another approach is to intercept the device’s firmware upgrade process. When manufacturers release an update, the device typically downloads a firmware image from an update server before installing it into flash memory. By capturing this download process, we may be able to obtain the firmware image without physically opening the device.
One approach is to configure a proxy between the device and the internet to monitor its network traffic during an update. Tools such as Wireshark or Burp Suite can help us inspect the communication and identify firmware download requests. Alternatively, if the device downloads updates over an unencrypted HTTP connection, we may be able to capture the firmware file directly from the network traffic.
However, this method is not always straightforward. Many devices use HTTPS, certificate pinning, encrypted update packages, or proprietary update protocols. Some devices also download updates through dedicated applications, making it harder to identify the actual download process.
Another limitation is that this approach usually retrieves the firmware version provided by the update server, which may differ from the version currently installed on the device.
Nevertheless, if we can successfully capture the download, this method saves us from physically accessing the flash memory and potentially damaging the device.
2.3. Download upgrade package from manufacture homepage (the easy way, but not always possible)
When interacting with the circuit board or intercepting the firmware download process is not an option, one option left is to download the firmware upgrade package directly from the manufacturer’s website. This is the easiest approach because we do not need any specialized hardware or complicated network interception techniques. However, it is not guaranteed to work for every device for several reasons:
- Not publicly available: Some manufacturers do not provide firmware downloads to end users, distributing updates only through automatic update mechanisms.
- Limited device support: Some manufacturers only publish firmware for selected models or hardware revisions.
- Proprietary formats: Downloaded packages may be encrypted, digitally signed, or packaged in proprietary formats, making them difficult to inspect.
- Version differences: The available package may contain a newer firmware version than the one currently installed on our device.
Fortunately, there are also open-source firmware repositories that provide downloadable firmware images for a wide range of devices.
In this article, we will examine a firmware image available on the OpenWrt website: https://openwrt.org/ . OpenWrt is an open-source project that develops a Linux-based operating system for embedded devices, particularly wireless routers. Its official website provides downloadable firmware images for many supported router models, making it a convenient source for our firmware analysis exercise.
3. Inspect a Firmware
For educational purposes only, here we go with the the easy way. Go to https://firmware-selector.openwrt.org/, enter a router model name, for example, TP-Link Archer C2 v3, and download the factory image. After downloading it, you will have a .bin file. This is firmware that can be installed on the router’s flash storage. However, we will not install it on a TP-Link router here; we will only examine it.
3.1. Convert BIN File To A Readable Filesystem
The first step is to inspect the .bin file and identify its internal structure. Our goal is to recover the filesystem in a form that we can explore and understand.
Firmware images can contain several filesystem formats. Some of the most common in embedded Linux devices are SquashFS, JFFS2, UBIFS, and CramFS. Among these, SquashFS is particularly popular because it provides a compressed, read-only filesystem that is well suited to devices with limited flash storage, such as Wi-Fi routers and IP cameras.
To determine which format our firmware uses, we can use Binwalk, a firmware analysis tool that scans binary files for recognizable signatures. Run the following command:
binwalk tplink_archer-c7-v2-squashfs-factory.bin
Binwalk examines the file and reports the locations of recognized components, including compressed data, Linux kernels, and embedded filesystems. Look for a SquashFS signature in the output. Its reported offset tells us where the filesystem begins within the firmware image. For example:
Note: This is illustrative output, not a real scan. Actual offsets, filesystem types, compression algorithms, and extraction results depend on the firmware image. Also, Binwalk may extract nested components into separate directories rather than producing exactly the layout shown below.
$ binwalk openwrt-router.binDECIMAL HEXADECIMAL DESCRIPTION--------------------------------------------------------------------------------0 0x0 uImage header, header size: 64 bytes, header CRC: 0xA12B45C8, created: 2025-10-15 08:30:00, image size: 8126464 bytes, image type: Firmware Image, compression type: none64 0x40 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 10485760 bytes1048576 0x100000 Squashfs filesystem, little endian, version 4.0, compression: xz, size: 5242880 bytes, 1024 inodes, blocksize: 262144 bytes6291456 0x600000 JFFS2 filesystem, little endian8126464 0x7C0000 End of firmware image
Once we identify the filesystem format and its location, we can extract it like so:
$ binwalk -e openwrt-router.binDECIMAL HEXADECIMAL DESCRIPTION--------------------------------------------------------------------------------64 0x40 LZMA compressed data1048576 0x100000 Squashfs filesystem6291456 0x600000 JFFS2 filesystem$ ls -la _openwrt-router.bin.extracted/-rw-r--r-- 1 user user 5242880 squashfs-rootdrwxr-xr-x 8 user user 4096 squashfs-root
3.2. Understand Linux Filesystem
OpenWrt is a Linux-based operating system, so its filesystem structure will look familiar to anyone who has worked with Linux. Before investigating the extracted firmware, let’s briefly review some fundamental Linux filesystem concepts.
Linux organizes files and directories into a hierarchical structure, starting from the root directory (/). Unlike Windows, which commonly uses separate drive letters such as C: and D:, Linux places system files, applications, configurations, and other resources under a single directory tree.
Here are some important directories you will encounter when exploring an OpenWrt filesystem:
| Directory | Role | Examples |
|---|---|---|
/bin | Essential user commands and executable programs required for basic system operation. | sh, ash, busybox |
/sbin | System administration and maintenance utilities. | reboot, ifconfig, init |
/etc | System-wide configuration files and service startup scripts. | passwd, shadow, init.d/, config/ |
/lib | Essential shared libraries and kernel modules required by system programs. | libc.so, modules/ |
/usr | Additional applications, libraries, and utilities. | usr/bin/, usr/sbin/, usr/lib/ |
/root | Home directory of the root administrator. | Shell configuration files |
/home | Home directories for regular users, if supported and configured. | /home/user/ |
/dev | Device files representing hardware and virtual devices. | null, console, tty |
/proc | Virtual filesystem exposing information about running processes and the Linux kernel. | /proc/cpuinfo, /proc/meminfo |
/sys | Virtual filesystem exposing kernel and hardware information through sysfs. | /sys/class/, /sys/devices/ |
/tmp | Temporary files, often stored in RAM. | Temporary logs and runtime files |
/var | Variable data such as logs, caches, and runtime information. | /var/log/ |
/mnt | Conventional mount point for temporarily mounted filesystems. | External storage |
/www | Web server document root, commonly used for the router’s administration interface. | index.html, cgi-bin/ |
Note that some directories, such as /proc, /sys, and /dev, are virtual filesystems created or populated at runtime. They may appear empty, incomplete, or contain only placeholders when examining an extracted firmware image offline.
Recommended inspecting order:
| Order | File or folder | What to look for |
|---|---|---|
| 1 | /etc/preinit | Early initialization before the normal startup process. |
| 2 | /sbin/init | The first userspace process (PID 1), responsible for starting the system’s init process. |
| 3 | /etc/inittab | Defines how the init process handles system initialization and console sessions. |
| 4 | /etc/init.d/ | Startup scripts for system services, such as networking, firewall, and system logging. |
| 5 | /etc/rc.d/ | Links that determine which initialization scripts run and in what order. |
| 6 | /etc/rc.common | Common functions used by OpenWrt service scripts. |
| 7 | /etc/config/ | Configuration files that determine how services behave, such as network, wireless, firewall, and DHCP settings. |
| 8 | /lib/ | Shared libraries and system components required by executables and services. |
| 9 | /usr/sbin/ and /usr/bin/ | User-space programs and utilities launched during startup or when requested. |
| 10 | /www/ | Web interface files, if the device includes a web management interface such as LuCI. |
Another important detail is that OpenWrt commonly uses a read-only SquashFS filesystem combined with a writable overlay filesystem. Therefore, the extracted firmware represents the original read-only system image, not necessarily the complete filesystem currently running on the router.
With this basic knowledge, we can start exploring the extracted filesystem and understand what each component does, rather than treating the firmware as an unfamiliar collection of binary files.
3.3. Reverse Engineer Executable Files
Executable files on OpenWrt also follow conventional Linux executable formats and conventions. Linux executables can include several types:
- ELF (Executable and Linkable Format): The standard format for compiled Linux programs, shared libraries (
.so), and object files. ELF executables contain machine code that can be executed directly by the CPU. - Shell Scripts: Text files containing commands interpreted by a shell, such as
/bin/shor Bash. They typically begin with a shebang (#!/bin/sh) to specify the interpreter. - Shared Libraries: Dynamically linked libraries, commonly using the
.soextension. They provide reusable functions that multiple executable programs can load and use. - Object Files: Compiled code that has not yet been linked into a complete executable. They commonly use the
.oextension. - Other Executable Formats and Scripts: Programs written in interpreted languages such as Python, Lua, or Perl. They require their respective interpreters to execute.
When inspecting OpenWrt firmware, you will encounter ELF executables extensively, particularly in directories such as /bin, /sbin, /usr/bin, and /usr/sbin. Unlike shell scripts and interpreted-language programs written in Python, Perl, or Lua, which are typically stored as human-readable text files, ELF executables contain compiled machine code and are stored in binary format. Therefore, we cannot simply open them in a text editor to understand their implementation. Instead, we need reverse engineering tools such as IDA or Ghidra to disassemble machine instructions and decompile them into C-like pseudocode, making their underlying logic easier to understand.
3.3.1. Conventional Tools
Below is a set of popular tools for reverse-engineering Linux executable files.
| Tool | Purpose | What you can discover |
|---|---|---|
file | Identify executable format | ELF format, CPU architecture, bitness |
strings | Extract readable strings | URLs, IPs, error messages, commands |
readelf | Inspect ELF structure | Headers, sections, symbols, dependencies |
objdump | Disassemble machine code | Assembly instructions and function contents |
nm | List executable symbols | Function and variable names |
Ghidra | Disassemble and decompile | Reconstruct C-like source code |
IDA Pro | Advanced disassembly and decompilation | Control flow, functions, cross-references |
radare2 | Binary analysis framework | Disassembly, function analysis, debugging |
Cutter | GUI for radare2 | Visual binary analysis |
Binary Ninja | Interactive reverse engineering | Intermediate representation and decompilation |
3.3.2. AI Agents
In the past, reverse engineering was a time-consuming process that required engineers to manually inspect and analyze thousands of lines of disassembled code to understand a program’s behavior. Today, advances in LLM-based AI have significantly reduced this workload. AI agents can assist in scanning executables, mapping functions and their relationships, and explaining decompiled pseudocode in human-readable terms. This allows engineers to spend less time understanding routine code and more time identifying suspicious functions, abnormal behaviors, and potential security vulnerabilities.
One example of this approach is REA (Reverse Engineering Anything), an AI agent which brings LLM capabilities directly into the reverse engineering workflow. Rather than manually navigating every function in a disassembler, engineers can use this AI agent to analyze code, explain its purpose, and help identify areas that deserve closer investigation.
For example, the console output below illustrates how to reverse an ELF file:
# 1. Identify the executable$ file /bin/ls/bin/ls: ELF 64-bit LSB pie executable, x86-64,dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,for GNU/Linux# 2. Extract assembly instructions$ objdump -d /bin/ls > ls.asm$ head -n 20 ls.asm/bin/ls: file format elf64-x86-64Disassembly of section .init:0000000000002000 <_init>: 2000: 48 83 ec 08 sub $0x8,%rsp 2004: 48 8b 05 ... mov ... 200b: 48 85 c0 test %rax,%rax 200e: 74 02 je 2012 <_init+0x12> 2010: ff d0 call *%rax 2012: 48 83 c4 08 add $0x8,%rsp 2016: c3 ret# 3. Open the executable in Ghidra$ ghidraRun /bin/ls# Analyze the binary and generate decompiled pseudocode.# 4. Use REA to analyze the executable$ rea analyze /bin/ls[REA] Reverse Engineering Agent[INFO] Loading ELF executable: /bin/ls[INFO] Architecture: x86-64[INFO] Binary format: ELF64[INFO] Importing analysis results...[INFO] Scanning functions...[INFO] Discovered 247 functions[INFO] Mapping function relationships...[INFO] Generating pseudocode explanations...[INFO] Analyzing function: main[REA] Function: main[REA] Decompiled pseudocode: int main(int argc, char **argv) { initialize_locale(); initialize_program(); parse_command_line_arguments(argc, argv); if (list_directory_contents) { open_directory(); read_directory_entries(); sort_entries(); print_entries(); } cleanup(); return exit_status; }[REA] Explanation: The main function initializes the program environment, processes command-line arguments, and determines how directory contents should be displayed. It then reads directory entries, sorts them according to the requested options, and prints the results.[INFO] Analysis completed.
