Skip to content
AtomicScript
Go back

From Multimeter to Ghidra: My First Six Labs in Hardware Hacking

Edit page

I have requested AI (Grok) to generate labs to learn hardware hacking from and understand concepts in depth by adding theory questions and inferences. Six labs later I had a full flash dump, a decoded boot banner, a partition table, strings, a Ghidra project, and a carved NVS partition.

This post is the map of that path and the ideas that made each step make sense. The goal was never to hack the ESP32. It was to build a repeatable process that works on other future boards I will actually own later — such as a router or a cat toy.

The Roadmap

The sequence was deliberate and cumulative:

  1. Power and basic signals — prove the board is alive and that I can see UART at the pin level.
  2. Boot control — force the chip into the ROM and measure the real baud from the wire.
  3. Firmware extraction — dump the flash over the same UART path the ROM already uses.
  4. Physical bus awareness — know where the bytes live (even when the chip is under a metal can).
  5. Offline static analysis — headers, segments, entry point, strings.
  6. Deeper views — disassembly in Ghidra (Xtensa) and stored data in the NVS partition.

No soldering was required. The ESP32-S was chosen because it is well documented and safe to experiment on. The same process should transfer.

Lab 1 — Power Rails and UART Reality

Theory: A board has more than one voltage. VIN is the unregulated input to the onboard regulator. 3V3 is the regulated output the chip actually uses. GND is a shared copper plane, not a collection of separate grounds.

On an unpowered board, continuity mode between the two GND pins beeped. That confirmed they are the same net. Diode-test mode on a pin often shows the ESD protection diode’s forward drop (~1.1 V), not a logic level. Sustained current through a protection diode designed only for brief ESD events will overheat and damage it; a short pulse does not give heat time to accumulate.

UART has two different views:

  • Serial Monitor shows decoded ASCII. The CP2102 USB-UART bridge already did the bit-to-byte conversion.
  • Logic analyzer shows raw edges. You must apply the decoder yourself (8N1 at a known baud).

The loopback (TX0 tied to RX0) proved the UART hardware worked at the pin level. The analyzer capture showed the actual frame. That distinction matters later: on an unknown device you often only have the wires.

Lab 2 — Boot UART and Strapping Pins

Theory: On reset the ESP32 ROM runs first. It samples a few pins (strapping pins) at the exact moment EN rises and decides which path to take. IO0 low = download mode. IO0 high = normal boot from flash. The sample is latched in hardware; changing the pin a moment later is too late.

I measured the baud rate from the wire before telling PulseView what it was. On a 1 MHz capture the first bit after reset measured ~8.999 µs, giving roughly 111125 baud. The expected width at 115200 is 8.68 µs. The difference was one sample on the 1 MHz grid, not a slow crystal. Decoder baud used after the measurement: 115200.

The banner that appeared contained the ROM’s view of the chip, the reset reason, and the flash it found. Holding IO0 low through the EN rising edge changed the banner and made the ROM wait for esptool.

This is the first real hardware-hacking move: the chip is talking even when no sketch is running.

Lab 3 — Flash Dump

Theory: The ROM can talk to the external SPI flash for you. Once you are in download mode, esptool read_flash simply asks the ROM to copy the flash contents over UART. The result is a byte-for-byte image of what is stored. Firmware contents are irrelevant to flash_id; the ROM just sends the JEDEC Read ID command.

On this board:

  • Chip: ESP32-D0WD-V3 (revision v3.1)
  • MAC: 70:4b:ca:6d:d1:bc
  • Flash manufacturer: 0x5E, device: 0x4016
  • Size: 4 MB

A full-chip dump is safer than “just the app.” You keep the bootloader, the partition table at 0x8000, NVS, and everything else. The partition table is how the ROM knows which image to jump to. Without it you have a blob; with it you have named regions.

If flash_id fails while the chip connects, the problem is between the ROM and the flash (power, voltage strap, SPI lines). If the chip itself does not connect, the problem is download mode or the USB-UART path.

Lab 4 — The SPI Bus (and the Can)

Theory: On a WROOM-style module the SPI flash is wired to GPIO6–11 (CLK, MISO, MOSI, etc.). Those pins are deliberately not broken out to the DevKit headers. Driving them from user code contends with the flash controller and can prevent the board from booting. The designer isolates them so ordinary sketches cannot accidentally destroy the only storage the chip has.

On this board the flash chip is under the metal RF can. No discrete package is visible and no test points are labeled. The bus is not accessible without opening the can. That was expected and did not stop the earlier UART dump. A UART read_flash and a direct SPI dump of the same chip should return the same bytes; both are reading the same physical NOR.

Lab 5 — Static Analysis of the Image

Theory: An ESP32 application image has a known format. It starts with a magic byte (0xE9), a header that describes segments, and then the segments themselves (IRAM, IROM, DRAM, DROM). The entry point is in the header. The magic byte is an integrity/sanity check the loader performs before parsing the rest of the header. Erased flash reads 0xFF; a missing or wrong magic stops the boot process before the CPU jumps into garbage.

From the extracted app image:

  • Magic: 0xE9
  • Segment count: 6
  • SPI mode: DIO (0x02)
  • Entry point: 0x40081A7C

The entry point sits in IRAM, not in the factory ROM (0x40000000) and not in external flash mapped as data. Once the header is parsed you know where the CPU will start and which regions contain code versus data. This is the bridge between “I have a dump” and “I can read the program.”

Lab 6A — Ghidra and Xtensa

Theory: The ESP32 uses the Xtensa LX6. The processor module matters more than the file format. Importing the same bytes as ARM or x86 produces meaningless disassembly because the instruction encodings are different. The module supplies the language.

I imported the app image as a raw binary with the Xtensa little-endian processor and the correct base address from the segment table. Selecting the wrong endianness made the entry point display incorrectly. Once loaded, disassembling from the entry point and following calls recovers the start of the program. Strings found in Lab 5 often cross-reference into logging or app_main-style functions.

This is still static. Nothing is running. You are reading the machine code the ROM would have jumped to.

Lab 6B — NVS Partition

Theory: NVS (Non-Volatile Storage) is the ESP-IDF key-value store. It lives in its own partition and holds small pieces of structured data that persist across power cycles — Wi-Fi credentials, device names, calibration, configuration flags.

From the partition table the NVS region was at offset 0x9000, size 0x5000 (20 KB, five 4 KB pages). Extracting it and looking at the first bytes showed the partition was empty (all 0xFF). That is a valid result. On a fresh DevKit there is often nothing stored yet. On a real device this is frequently the most interesting partition to carve first.

The two labs (6A and 6B) are independent; either can be done first.

What Changed

Before these labs I treated the board as a black box that ran sketches. After them I treat it as:

  • A set of power rails I can measure.
  • A boot ROM I can force into different modes by controlling a strapping pin at the right moment.
  • A flash image I can copy without writing, then parse offline.
  • A file format whose magic, entry point, and segments I can read.
  • A binary I can load into a disassembler with the correct processor and addresses.
  • A data store (NVS) I can carve even when the code is still opaque.

The same sequence works on almost any device that has a debug UART or a recoverable flash. The ESP32-S was only the training target.

Next

The next target is a device I already own. The process stays the same: open it, photograph the board, identify power and any serial pins, see whether a dump path exists, then decide whether soldering is required. The soldering station can wait. The analysis does not.

The labs are done. The method is what remains.



Previous Post
Why IoT devices are easily hacked