Finding 0days in embedded systems with code coverage guided fuzzing

Nguyen Anh Quynh (Researcher · Nanyang Technological University), Lau Kai Jern (IoT/Blockchain Researcher · JD Security)

BruCON 0x0A · Day 2

Overview

This talk, presented by Nguyen Anh Quynh and Lau Kai Jern, delves into the challenging yet critical domain of finding zero-day vulnerabilities in embedded systems using coverage-guided fuzzing. As the proliferation of IoT devices and other embedded technologies continues, securing these often closed-source and resource-constrained systems has become paramount. The speakers highlight the significant gaps in existing vulnerability research methodologies when applied to non-x86 architectures and proprietary firmware.

Watch on YouTube

Visual summary for Finding 0days in embedded systems with code coverage guided fuzzing by Nguyen Anh Quynh, Lau Kai Jern
Visual summary for Finding 0days in embedded systems with code coverage guided fuzzing by Nguyen Anh Quynh, Lau Kai Jern

Key moments

  1. 0:00 Introduction: Fuzzing embedded systems challenges
  2. 6:00 Three major problems fuzzing embedded systems
  3. 10:00 Firmware emulation: overcoming hardware limitations
  4. 28:00 Dynamic Binary Instrumentation (DBI) for no source
  5. 40:00 SKORPIO: Cross-platform, cross-architecture DBI framework
  6. 48:00 Integrating SKORPIO with AFL for embedded fuzzing
  7. 52:00 Fuzzing results: RCE in a WiFi router
  8. 56:00 Q&A: Automating static analysis for hook placement

Finding 0days in embedded systems with code coverage guided fuzzing

Speakers: Nguyen Anh Quynh (Researcher, Nanyang Technological University); Lau Kai Jern (IoT/Blockchain Researcher, JD Security)

Conference: BruCON

YouTube: https://www.youtube.com/watch?v=tTycvw01IRM

Overview

This talk, presented by Nguyen Anh Quynh and Lau Kai Jern, delves into the challenging yet critical domain of finding zero-day vulnerabilities in embedded systems using coverage-guided fuzzing. As the proliferation of IoT devices and other embedded technologies continues, securing these often closed-source and resource-constrained systems has become paramount. The speakers highlight the significant gaps in existing vulnerability research methodologies when applied to non-x86 architectures and proprietary firmware.

The core of their presentation outlines a novel, three-pronged approach to overcome these limitations. They detail the necessity of robust firmware emulation, the development of a custom, cross-platform, and cross-architecture Dynamic Binary Instrumentation (DBI) framework named SKORPIO, and an American Fuzzy Lop (AFL)-compatible fuzzer tailored for binary-only embedded targets. This integrated solution empowers researchers to effectively apply modern fuzzing techniques to systems previously considered out of reach for automated vulnerability discovery.

The work presented is highly relevant to the current security landscape, where embedded systems frequently serve as entry points for sophisticated attacks. By demonstrating a practical method to uncover deep-seated bugs in proprietary firmware, Quynh and Kai Jern provide invaluable insights for both offensive and defensive security practitioners. Their research not only addresses the technical hurdles but also underscores the inherent security challenges posed by the diverse and often overlooked world of embedded devices.

Background

▶ Watch: Introduction: Fuzzing embedded systems challenges (0:00)

Automated software testing, specifically fuzzing, has proven to be an indispensable technique for uncovering bugs and vulnerabilities. The fundamental principle involves feeding crafted input data to a target program in a loop while monitoring for anomalies such as crashes, hangs, or memory leaks. When focusing on exploitable issues like memory corruption or information leakage, fuzzing becomes a potent tool for vulnerability research. A critical aspect of effective fuzzing is the ability to generate "good" inputs that maximize code coverage, exercising as many code paths as possible within the target program.

Historically, fuzzers have evolved through three main types:

  • Blackbox fuzzing: Simple and easy to implement, this approach feeds random input without any knowledge of the program's internal structure. While effective for shallow bugs, it's often too "dumb" to reach deeper, more complex code paths.
  • Whitebox fuzzing: This method employs heavy, complicated techniques to analyze the program's structure before testing, allowing for the generation of highly targeted inputs. While theoretically powerful, the complexity and computational overhead of static analysis often make whitebox fuzzing too slow and impractical for real-world application.
  • Graybox fuzzing (or coverage-guided fuzzing): Striking a balance between the previous two, this approach instruments the target program to gain insights into its execution progress at runtime. Based on this feedback, the fuzzer intelligently generates new inputs to explore previously unreached code. American Fuzzy Lop (AFL) revolutionized this space, demonstrating remarkable effectiveness and ease of use in finding numerous bugs over the past years.

However, existing coverage-guided fuzzers like AFL were primarily designed for powerful PC systems and typically relied on the availability of source code. AFL, for instance, uses a custom compiler to automatically inject instrumentation into the program during compilation. This dependency on source code, coupled with a dominant focus on x86 architectures, created significant barriers to applying these advanced techniques to embedded systems.

The speakers identified three major issues preventing the direct application of guided fuzzing to embedded targets:

  1. Restricted Embedded Environments: Embedded systems often lack basic development facilities such as compilers, debuggers, or even shell access. Introducing new tools or fuzzers directly onto these systems is frequently impossible.
  2. Binary-Only Firmware: A vast majority of embedded systems, especially commercial IoT devices, come with proprietary firmware for which no source code is available. While AFL offers a QEMU emulation mode for binary fuzzing, it is notoriously slow, unreliable, and limited in its capabilities, rendering it impractical for extensive research.
  3. Poor Hardware Support: Most existing fuzzers and DBI frameworks are built predominantly for Intel x86 CPUs. Dynamic Binary Instrumentation tools like Pin (from Intel) and DynamoRIO offer limited or experimental support for ARM, and virtually no support for other common embedded architectures such as ARM64, MIPS, or PowerPC. This architectural disparity means that the critical instrumentation layer required for coverage guidance is largely absent for embedded targets.

These challenges underscored the need for a fundamentally new approach to bring the power of coverage-guided fuzzing to the embedded world.

Key Findings

▶ Watch: Firmware emulation: overcoming hardware limitations (10:00)

The central finding of this research is the successful development and demonstration of a comprehensive methodology for finding zero-day vulnerabilities in binary-only embedded systems using coverage-guided fuzzing. The speakers effectively addressed the inherent limitations of existing fuzzing techniques and tools when applied to resource-constrained, closed-source, and non-x86 architectures.

Their key contributions and findings include:

  • Necessity of Firmware Emulation: They established that a robust and flexible firmware emulation environment is crucial. This environment must overcome the resource limitations and lack of development tools on physical embedded hardware, allowing for the installation of fuzzing infrastructure and the execution of proprietary firmware in a controlled, debuggable, and scalable manner. This involves tackling complex issues like library dependencies, NVRAM emulation, and inter-process communication.
  • Development of SKORPIO DBI Framework: Recognizing the severe lack of cross-platform and cross-architecture DBI tools for binary-only instrumentation, they developed SKORPIO. This low-level framework is a significant technical achievement, supporting a wide array of operating systems (Windows, Mac, Linux, BSD, Android) and CPU architectures (x86, ARM, ARM64, MIPS, SPARC, PowerPC). SKORPIO's flexibility in supporting various hooking mechanisms and allowing instrumentation at any arbitrary address is critical for effective coverage-guided fuzzing of unknown binaries.
  • AFL-Compatible Embedded Fuzzer: They successfully integrated SKORPIO with the powerful AFL fuzzer. By using SKORPIO for runtime binary instrumentation, they bypassed AFL's source code dependency, enabling it to fuzz closed-source embedded firmware. The resulting fuzzer operates at near-native speed due to SKORPIO's lightweight design and is compatible with advanced AFL features like persistent mode and selective fuzzing.
  • Proof of Concept: Real-World 0-Day Discovery: As a concrete validation of their approach, the speakers demonstrated the discovery of Remote Code Execution (RCE) vulnerabilities, specifically a buffer overflow, in a popular WiFi router (identified as a Tenda router). This finding highlighted not only the effectiveness of their fuzzer but also revealed interesting discrepancies between international and Chinese versions of the same firmware, where different exploitable bugs were present.

In essence, the key finding is that by combining intelligent firmware emulation, a custom-built, highly flexible DBI framework, and an adapted coverage-guided fuzzer, it is entirely possible and practical to uncover significant vulnerabilities in complex, binary-only embedded systems across diverse hardware platforms. This work provides a powerful new toolset for embedded security research.

Technical Deep Dive

▶ Watch: SKORPIO: Cross-platform, cross-architecture DBI framework (40:00)

The solution presented by Quynh and Kai Jern to enable coverage-guided fuzzing on embedded systems is a sophisticated integration of three core components: robust firmware emulation, a custom Dynamic Binary Instrumentation (DBI) framework called SKORPIO, and an AFL-compatible fuzzer.

Firmware Emulation

Kai Jern elaborated on the critical need for firmware emulation due to the highly restricted nature of embedded systems. Unlike MCUs (Microcontroller Units), the focus here is on SoCs (System-on-Chips), which are more complex and often found in Wi-Fi routers, smart speakers, and IoT cameras. Physical hardware offers limited resources (e.g., 8MB, 16MB, 32MB, 256MB flash memory), lacks development tools (compilers, debuggers), and makes installing additional libraries or a fuzzer impractical.

The process begins with firmware extraction. This can be achieved by downloading from official websites, extracting from Android APKs, sniffing network traffic, or even performing chip-off to physically read the flash memory.

Initial attempts to use single-board computers like Raspberry Pi Zero (for ARM) or Raspberry Pi 3 (for ARM64) proved problematic due to libc incompatibility issues arising from different compilation versions, platforms, and SDKs. This highlighted the need for a universal, virtualized platform.

The solution pivoted to QEMU-based virtualization with a hypervisor, offering several advantages:

  • Increased Resources: Virtualization allows for dynamic allocation of more CPU cores, RAM, and storage space, overcoming the hardware limitations of actual embedded devices.
  • Development Environment: It provides a Linux environment where apt-get and other essential tools can be installed, eliminating the tedious process of cross-compilation for each target architecture.
  • Universal Platform: A virtualized setup ensures consistency, allowing researchers to work collaboratively without shipping physical hardware.

A crucial aspect of running embedded firmware is understanding its process model. Typically, there's a main process that spawns listening services (web servers, Telnet, etc.) and a supportive process that interacts with hardware components, like the NVRAM (Non-Volatile RAM) for configuration storage. Running only the main process in isolation (e.g., using qemu-static) is insufficient, as it breaks the vital inter-process communication, especially for hardware-dependent configurations.

Several challenges were encountered when booting full firmware images:

  • Firmadyne Limitations: Existing solutions like Firmadyne were found to be heavily reliant on SquashFS and proved inflexible for diverse modem models or non-standard firmware structures.
  • chroot Inadequacy: While chroot can isolate library environments, it complicates the attachment of debugging and analysis tools like GDB. The goal was to run the firmware as natively as possible within QEMU without additional chroot layers.
  • "File not found" Errors: When attempting to run binaries (e.g., bin/bash or bin/sh from BusyBox), the system would report "file not found" even if the binary existed. This was traced to missing core shared objects (.so files). The fix involved soft linking the required libraries, a process often requiring iterative strace analysis to identify all dependencies.
  • NVRAM Emulation: Emulating NVRAM proved difficult. The solution involved emulating the process that communicates with NVRAM. This communication often occurs via Unix Domain Sockets (UDS). A simple Python script could be used to create a fake NVRAM service, providing necessary configuration data to the main binary. If the main process didn't find NVRAM, it would often self-create a default configuration, simplifying the emulation task.
  • Wireless Device Emulation: For devices requiring wireless configurations (WPA), full hardware emulation was unnecessary. Simply renaming eth0 to wlan0 in the virtual environment often sufficed to trick the firmware into believing wireless hardware was present, allowing the main process to spawn.
  • Last Resort: Patching: If all else failed, direct binary patching of the firmware was employed to bypass unfulfillable hardware dependencies or specific checks within QEMU.

Once the firmware could reliably run in this virtualized environment, the platform was ready for dynamic binary instrumentation.

Dynamic Binary Instrumentation (DBI) - SKORPIO

To apply coverage-guided fuzzing to binary-only embedded systems, a custom DBI framework was essential. Quynh explained that DBI involves injecting extra code into a running application to analyze or modify its behavior at runtime without altering its original context.

Two main DBI techniques exist:

  1. Just-in-Time (JIT) Translation: This technique translates the original code into an intermediate language or native code, executing the translated version. Examples include Valgrind and DynamoRIO. While offering fine-grained control, JIT translation is exceptionally complex, heavy, and typically takes over a decade of development, often supporting only a limited number of CPUs (primarily x86).
  2. Hooking: A lighter and simpler approach, hooking involves patching the original code to redirect execution to instrumentation code. While offering less control and requiring prior knowledge of hook points, its ease of implementation made it suitable for this project.

Within hooking, inline hooking (inserting instrumentation directly into the code stream) was dismissed due to its complexity in handling code shifts and relative addressing. The chosen method was detour hooking, where a small patch in the original code branches out to a trampoline buffer (a stepping-stone executable memory) which then calls the actual instrumentation callback.

SKORPIO supports four main detour hooking mechanisms:

  • Jump-trampoline: Overwrites the original instruction to jump to a trampoline. The trampoline saves context, calls the user-provided callback, restores context, executes the relocated original instruction (copied from its original location and adjusted for relative addresses), and then jumps back to the original code flow.
  • Jump-callback: Directly jumps to the callback without a trampoline.
  • Call-trampoline: Uses a CALL instruction to the trampoline, preserving the return address.
  • Call-callback: Directly calls the callback.

Existing DBI frameworks (Pin, DynamoRIO, Valgrind) were found to be inadequate due to:

  • Limited Platform Support: E.g., Pin works well on Windows/Linux but poorly on Mac; Valgrind doesn't work on Windows.
  • Limited Architecture Support: Primarily x86, with some experimental ARM support, but no comprehensive support for ARM64, MIPS, PowerPC, etc.
  • Limited Instrumentation Techniques: They often hide implementation details and don't expose flexible hooking mechanisms.
  • Limited Optimization: Their black-box nature restricts fine-tuning for performance.

To overcome these, SKORPIO was designed as a low-level, highly flexible, and performant DBI framework:

  • Cross-Platform & Cross-Architecture: Supports Windows, Mac, Linux, BSD, Android, and CPUs including x86, ARM, ARM64, MIPS, SPARC, PowerPC. This is achieved by abstracting OS and architecture-specific details into plugins.
  • Flexible Instrumentation: Allows instrumentation at any address, not just function entry points, and exposes all four hooking mechanisms.
  • Optimizable: Provides APIs for optimizing callbacks, trampolines, scratch register usage, and context saving/restoring, leading to performance gains of up to "100 times faster" in certain setups.
  • Implementation Details:
  • Memory Management: Handles OS-specific memory allocation, permission changes (read-write to executable), and memory patching.
  • Context Management: Manages CPU-specific register saving/restoring and OS-specific calling conventions. PowerPC, for instance, required specific tricks due to its indirect branch limitations.
  • Scratch Registers: For CPUs like ARM64, MIPS, SPARC, and PowerPC that cannot branch to indirect memory targets, SKORPIO uses a temporary "scratch register" to store the target address before jumping.
  • Cache Flushing: Unlike x86, many CPUs require explicit instruction cache flushing after patching memory to ensure the CPU recognizes the new instructions.
  • Instruction Handling: SKORPIO relies on Capstone disassembler to determine instruction boundaries (especially for variable-length instruction sets like x86) and identify relative instructions. It then uses Keystone assembler to relocate these relative instructions, rewriting them to function correctly within the trampoline buffer. This dependency on Capstone and Keystone (both cross-platform/architecture frameworks maintained by Quynh) is key to SKORPIO's broad compatibility.

AFL-Compatible Fuzzer for Embedded Systems

With SKORPIO providing the necessary instrumentation capabilities, the final step was to build a coverage-guided fuzzer. Instead of building from scratch, the team opted to extend AFL. The core design of AFL was reused without modification. The crucial adaptation was to replace AFL's source-code-based instrumentation with SKORPIO's binary-only instrumentation.

Key features of this fuzzer:

  • Pure Software-Based: No reliance on CPU-specific hardware features for instrumentation.
  • Cross-Platform & Cross-Architecture: Inherits SKORPIO's broad support.
  • Binary-Only Support: The primary goal, achieved through SKORPIO.
  • Fast and Stable: SKORPIO's lightweight nature allows the fuzzer to run at "near-native speed."
  • Selective Fuzzing: Allows researchers to focus fuzzing efforts on specific parts of a large binary (e.g., a web server backend) after initial static analysis.
  • Persistent Mode & Advanced Techniques: Compatible with AFL's persistent mode for faster execution and can be combined with symbolic execution or static analysis for deeper penetration.
  • ASLR/Threading Compatible: Designed to handle modern operating system security features.

The workflow involves an initial static analysis step to identify target areas for fuzzing (e.g., basic blocks of interest). This information is then passed to SKORPIO, which injects hooks at runtime. These hooks, in turn, update AFL's shared memory with execution context information, allowing AFL to guide the fuzzing process effectively.

Demo / Proof of Concept

▶ Watch: Integrating SKORPIO with AFL for embedded fuzzing (48:00)

While no live demonstration was conducted during the talk, the speakers presented a compelling proof of concept by detailing a real-world vulnerability discovery. They successfully fuzzed a popular WiFi router in China, identified as a Tenda router, using their developed methodology.

The fuzzing campaign led to the discovery of multiple interesting findings, including a Remote Code Execution (RCE) vulnerability stemming from a buffer overflow. The team was able to craft specific shellcodes to exploit this vulnerability.

A particularly noteworthy observation was the difference in vulnerabilities between the international and Chinese versions of the router's firmware. The international version was found to contain a "quite obvious" exploitable bug. In contrast, the Chinese edition of the firmware did not have this specific flaw but harbored a different, less obvious yet still exploitable vulnerability. This highlights the importance of testing regional variants of embedded devices, as security postures and implemented features can differ significantly.

As an example of the RCE, they showed how their crafted input could inject commands into the system, specifically demonstrating the ability to turn on Telnet on port 4444, gaining interactive access to the compromised device. This concrete example validated the effectiveness of their firmware emulation, SKORPIO DBI, and integrated fuzzer in identifying and exploiting critical vulnerabilities in real-world, closed-source embedded systems.

Defensive Implications

▶ Watch: Q&A: Automating static analysis for hook placement (56:00)

The research presented by Quynh and Kai Jern carries significant defensive implications for manufacturers, security teams, and end-users of embedded systems.

  1. Mandate Robust Security Testing: The primary takeaway for manufacturers is the urgent need to integrate rigorous security testing, including advanced fuzzing techniques, into their development lifecycle. The discovery of 0-day RCEs in widely used WiFi routers underscores that current practices are often insufficient. Relying solely on internal QA or basic blackbox testing is no longer adequate for complex, network-connected devices.
  2. Adopt Advanced Fuzzing Methodologies: Security teams within organizations that develop or deploy embedded systems should investigate and adopt methodologies akin to what was presented. This includes investing in or developing capabilities for firmware emulation and dynamic binary instrumentation for non-x86 architectures. Moving beyond simple static analysis or generic fuzzing is crucial for uncovering deep-seated vulnerabilities.
  3. Cross-Architectural Security Expertise: Defenders need to cultivate expertise in security for diverse CPU architectures (ARM, ARM64, MIPS, PowerPC). The x86-centric nature of many existing security tools and knowledge bases creates blind spots for embedded systems. Understanding the nuances of memory management, calling conventions, and cache behavior across these architectures is vital.
  4. Beware of Firmware Version Discrepancies: The finding that international and regional firmware versions can have different vulnerabilities is a critical insight. Organizations deploying embedded devices globally must ensure that all localized firmware variants undergo thorough security assessments, as fixes or vulnerabilities in one version may not be present or identical in another.
  5. Secure Coding Practices for Embedded Development: While the talk focuses on binary analysis, the underlying cause of vulnerabilities like buffer overflows points to fundamental insecure coding practices. Developers of embedded firmware must adopt secure coding principles, perform regular code reviews, and utilize static analysis tools designed for low-level languages and specific architectures to prevent common pitfalls.
  6. Supply Chain Security for IoT: As embedded systems often integrate components from various vendors, the security of the entire supply chain becomes relevant. Manufacturers should demand evidence of robust security testing from their suppliers and consider incorporating emulation and fuzzing as part of their inbound quality assurance for third-party modules or firmware.
  7. Patching and Update Mechanisms: The ability to find vulnerabilities highlights the need for robust and reliable over-the-air (OTA) update mechanisms for embedded devices. Manufacturers must ensure they can quickly distribute patches to address discovered vulnerabilities, and users should be vigilant about applying these updates.

In summary, the research serves as a stark reminder that embedded systems are not impenetrable black boxes and that sophisticated, automated techniques can and will uncover critical flaws. Defenders must evolve their strategies to meet this challenge by embracing advanced tooling and a comprehensive, architecture-agnostic approach to security.

Key Takeaways

  • Coverage-guided fuzzing is highly effective for embedded systems: Despite the challenges of closed-source firmware and diverse architectures, modern fuzzing techniques can be successfully adapted to uncover critical vulnerabilities in embedded devices.
  • Robust firmware emulation is foundational: A flexible, virtualized environment (e.g., QEMU with hypervisor) is essential to overcome hardware limitations, provide necessary resources, and enable installation of development/analysis tools for proprietary firmware.
  • Custom DBI is critical for binary-only instrumentation: Existing DBI tools are insufficient for the cross-platform and cross-architecture requirements of embedded systems. A purpose-built framework like SKORPIO is necessary for effective runtime instrumentation of unknown binaries.
  • Integration with existing fuzzers accelerates discovery: Reusing mature fuzzers like AFL and integrating them with custom DBI allows researchers to leverage proven fuzzing logic while tackling binary-only targets, leading to faster and more stable vulnerability discovery.
  • Embedded systems harbor significant vulnerabilities: The discovery of RCEs in a popular WiFi router serves as a concrete example that many embedded devices, even from major vendors, contain exploitable flaws, emphasizing the need for increased security scrutiny.
  • Firmware variants require independent assessment: Regional or international versions of firmware can contain different vulnerabilities, necessitating comprehensive security testing across all deployed variants.

About the Speaker(s)

Nguyen Anh Quynh is a distinguished researcher affiliated with Nanyang Technological University in Singapore. His research primarily focuses on low-level systems, encompassing operating systems, virtual machines, and binary analysis. Quynh is widely recognized in the reverse engineering community as the founder and maintainer of several influential open-source frameworks, including the Capstone disassembler, the Unicorn emulator, and the Keystone assembler. His work on these projects has significantly advanced the capabilities for analyzing and manipulating binary code across various architectures.

Lau Kai Jern is an IoT/Blockchain Researcher at JD Security and a prominent member of the Hack in the Box (HITB) crew. With a strong background in hardware, PCB design, and chip-level operations, Kai Jern brings invaluable expertise in the physical aspects of embedded systems. His experience extends to designing security conference badges and organizing HITB events globally, showcasing his deep involvement in the security community and practical understanding of embedded hardware challenges.

Reviews

  • Dr. Zero (Offensive Security Researcher) — MUST SEE ★★★★★

→ Top-rated talks at BruCON 0x0A

All talks from BruCON 0x0A