Skip to content

0. Before you start

Goal: know what this track does, why, and the rules that come with it.

You will learn

  • what a hardware security assessment looks at
  • the usual path from a serial console to a firmware finding
  • what you may and may not do with these techniques

In your terminal: hwn learn 0 (how)

What is hardware hacking?

Routers, cameras, drones and robots are small Linux computers. Their makers leave debug interfaces on the board for the factory: a UART serial console (two or three pins that print the boot log), a JTAG/SWD debug port, and a SPI flash chip that holds the firmware. In an assessment you use those interfaces to answer one question: if an attacker has the device in their hands, what can they get? Often the answer is "a root shell, every password in the firmware, and the keys the device uses to talk to the cloud".

A typical first day looks like this, and the lessons follow the same order:

Step Lesson Real hardware In this track
Find the serial pins and read the boot log 1 USB-UART adapter on TX/RX/GND SimTube to a fake console
Find the baud rate 2 try rates until text appears autobaud() with a simulated port
Stop the bootloader 3 press a key during the countdown UBoot.interrupt()
Copy the firmware out 4 sf read + md.b over serial the same commands, on FakeUBoot
Look for weaknesses 5 unpack, grep, audit hwn fw analyze
Get a shell 6 log in or use init=/bin/sh LinuxShell on a fake console
Other interfaces 7 flash clip, JTAG debugger Flashrom, OpenOCD with stand-ins

hwntools turns each step into a few lines of Python, with the same recvuntil / sendline feel as pwntools, so the first day becomes a script you can rerun on the next unit.

The rules

Authorized use only

Only test devices you own, or devices whose owner has given you written permission to test, within that permission. Pulling firmware, passwords or keys out of a device can be restricted by contract and by law even for hardware you bought. Report what you find to the vendor responsibly. The full text is in Safety and legal.

Two habits that keep hardware alive:

  • Read before you write. Dumping is safe; saveenv, flash writes and erases are not. hwntools refuses them unless you pass force=True (you will see this in lessons 3 and 7).
  • Check the voltage. Most consoles are 3.3 V; some are 1.8 V. Connecting a 3.3 V adapter to a 1.8 V pin can kill the chip. Never connect the adapter's VCC pin unless you mean to power the board from it.

None of that can go wrong in this track: everything is simulated.

What the simulator can and cannot do

The simulator models what matters for scripting: echo, prompts, the autoboot countdown, printenv/setenv, md.b output, login prompts and a real shell for commands. It is not an emulator: no CPU runs the firmware, booting stops after the kernel command line, and the "Linux console" in lesson 6 runs commands on your own computer. The lessons point out where that matters.

Try it

Try it

Check that your setup works: in your hwn-learn folder, run python -c "import hwntools; from hwntools.learn import lab; print(hwntools.__version__, len(lab.firmware()))".

Solution
$ python -c "import hwntools; from hwntools.learn import lab; print(hwntools.__version__, len(lab.firmware()))"
0.3.0 32768

lab.firmware() is the 32 KiB firmware image of the simulated router. If you see ModuleNotFoundError: No module named 'hwntools.learn', your hwntools is older than 0.3.0: run pip install -U hwntools.

In a terminal, hwn learn 0 does the same check and walks you through the rest of the track (see Learn in your terminal).

Next: Talk to a UART