Reverse Engineering Firmware: How to Crack Password Checks with Assembly Patching & Ghidra + Video

Listen to this Post

Featured Image

Introduction:

Firmware reverse engineering is the process of extracting machine code from embedded devices and translating it back into human-readable logic to uncover vulnerabilities. When developers compile C code—such as a password validation function—the resulting assembly instructions can be analyzed with tools like Ghidra or IDA Pro, allowing security researchers to identify weak comparisons like `strcmp` and even patch the binary to bypass authentication entirely.

Learning Objectives:

  • Understand how a C password function compiles to assembly and why `strcmp` becomes a critical target for bypass attacks.
  • Use Ghidra and Linux command-line tools (objdump, radare2) to disassemble firmware and locate comparison logic.
  • Patch a live firmware binary by modifying conditional jump instructions (JNZ to JMP) to defeat password checks.

You Should Know:

  1. Extracting and Disassembling Firmware – A Step‑by‑Step Guide

Firmware is often distributed as a binary blob (e.g., firmware.bin). Before you can reverse engineer it, you must extract the filesystem and identify the executable sections.

Step 1 – Identify firmware type

On Linux, use `file` and `binwalk`:

file firmware.bin
binwalk firmware.bin

If it contains a compressed filesystem (squashfs, uImage), extract it:

binwalk -e firmware.bin

Step 2 – Locate the binary that contains the password function
Embedded systems often run an ELF executable or a raw ARM/Thumb binary. Use `strings` to search for clues:

strings firmware.bin | grep -i password
strings firmware.bin | grep -i strcmp

Step 3 – Disassemble with objdump (Linux)

Assuming you have an ARM ELF file:

arm-none-eabi-objdump -d ./extracted/password_check.elf > disassembly.txt

For raw binary, specify architecture:

arm-none-eabi-objdump -D -b binary -m arm ./extracted/password_check.bin

Step 4 – Load into Ghidra

Create a new project, import the binary, and run the auto-analysis. Ghidra will show you decompiled C code alongside assembly. Look for a function containing `strcmp` – it will resemble:

if (strcmp(input, stored_password) == 0) grant_access();
else deny_access();

Step 5 – Identify the conditional jump in assembly
In ARM or x86 assembly, a typical comparison followed by a branch:

bl strcmp ; call strcmp, result in r0
cmp r0, 0 ; test if equal
bne deny_label ; jump to deny if not equal

The `bne` (branch not equal) is your target. Changing it to an unconditional branch (b or jmp) will always grant access.

  1. Patching the Firmware Binary – Live Bypass on Linux

Once you’ve located the critical branch instruction, patch the binary directly.

Step 1 – Note the offset of the branch instruction
In Ghidra, check the address (e.g., 0x00001234) or file offset. Use `objdump` to confirm:

objdump -d password_check.elf | grep -A5 -B5 "bne"

Step 2 – Convert the instruction to a no‑operation or unconditional jump
– On ARM: `bne` opcode is typically 0x1A00000x. Change to `b` (0xEA00000x).
– On x86: `75 xx` (JNZ) → `EB xx` (JMP).

Use a hex editor (e.g., `xxd` or `hexedit`):

cp firmware.bin firmware_patched.bin
xxd firmware_patched.bin > firmware.hex
 Edit the hex file, change the bytes, then convert back:
xxd -r firmware.hex > firmware_patched.bin

Step 3 – Reflash (if on real hardware)

Use `dd` or vendor-specific tools:

dd if=firmware_patched.bin of=/dev/sdX bs=1M

Warning: Only patch firmware you own or have explicit permission to test.

  1. Using radare2 to Patch Interactively (No Hex Editor Needed)

Radare2 is a powerful command‑line reverse engineering framework.

Step 1 – Open the binary in write mode

r2 -w firmware.bin

Step 2 – Seek to the address and analyze

[bash]> s 0x1234
[bash]> pd 1 ; print disassembly at that address

Step 3 – Patch the instruction

For x86 JNZ → JMP:

[bash]> wa jmp 0x1236 ; overwrite with unconditional jump

For ARM `bne` → `b`:

[bash]> wa b 0x1238

Step 4 – Write changes and quit

[bash]> wq
  1. Simulating Firmware with QEMU to Test the Patch

Before flashing hardware, emulate the patched binary.

Step 1 – Install QEMU user‑mode

sudo apt install qemu-user-static

Step 2 – Run the patched binary

qemu-arm-static -L /usr/arm-linux-gnueabihf ./password_check_patched

Provide any input – if the patch succeeded, it should grant access regardless of the password.

5. Mitigation: Hardening Firmware Against Patch Attacks

Developers can prevent these trivial bypasses.

Step 1 – Use cryptographic hashing instead of plaintext `strcmp`
Store a salted hash of the password. Compare hashes in constant time to avoid timing side‑channels.

Step 2 – Implement code integrity checks

Compute a CRC or digital signature over the firmware’s critical section. On boot, verify the signature; if patched, refuse to run.

Step 3 – Obfuscate control flow

Insert junk instructions or use indirect jumps to make locating the comparison branch difficult. Tools like Tigress can automate this.

Example Linux command to hash a password securely:

echo -n "mypassword" | sha256sum | cut -d' ' -f1 > hash.txt

Then in C, compare the computed hash of user input with the stored hash using `memcmp` with a constant‑time wrapper.

What Undercode Say:

  • Key Takeaway 1: A simple `strcmp` in C becomes a predictable conditional branch in assembly – easily patched from `bne` to `b` using tools as basic as `xxd` or radare2.
  • Key Takeaway 2: Security researchers must look beyond source code; firmware reverse engineering reveals hidden vulnerabilities that static analysis misses, making it essential for IoT penetration testing.
  • Analysis: The post highlights a fundamental truth – compiled code is not safe by obscurity. Even without source access, an attacker with physical device access or a firmware dump can bypass authentication in minutes. This is why modern embedded systems need secure boot, code signing, and runtime integrity checks. The ease of patching assembly underscores the shift towards hardware‑rooted security (TPM, secure enclaves) and remote attestation. For defenders, learning reverse engineering is no longer optional – it’s the baseline for understanding real attack surfaces.

Prediction:

As IoT and edge devices proliferate, automated reverse engineering using AI‑assisted decompilers (like Ghidra’s sleigh with machine learning) will become mainstream. Attackers will move from manual patching to automated firmware modification at scale. Consequently, we will see a rise in anti‑reverse‑engineering techniques such as control‑flow flattening, virtualization obfuscation, and polymorphic code inside firmware. The arms race will force hardware manufacturers to adopt fully encrypted firmware images with per‑device keys, making generic patching ineffective. Within three years, certification standards like PSA Certified will require firmware encryption and authenticated boot as baseline for any connected device.

▶️ Related Video (82% Match):

🎯Let’s Practice For Free:

IT/Security Reporter URL:

Reported By: Maximilianfeldthusen Understanding – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow UndercodeTesting & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky