Skip to content

CLI reference

Installing hwntools puts the hwn command on your PATH (python -m hwntools works too). It covers the most common one-shot jobs; everything else is a few lines of Python.

The help texts below are generated from the real argument parser when this site is built.

Global options

$ hwn --help
usage: hwn [-h] [--version] [-v] [-q] [--timeout TIMEOUT]
           {uboot,console,autobaud,hexdump,entropy,sigs,fw,learn} ...

hwntools: scripting toolkit for authorized hardware security assessments

positional arguments:
  {uboot,console,autobaud,hexdump,entropy,sigs,fw,learn}
    uboot               U-Boot console helpers
    console             interactive serial console with session logging
    autobaud            guess the baud rate of a live UART
    hexdump             hexdump a file ('-' for stdin)
    entropy             entropy map of a firmware image
    sigs                scan a firmware image for known signatures
    fw                  firmware extraction and analysis
    learn               interactive tutorial: hardware hacking on the built-in
                        simulator

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v, --verbose         debug logging
  -q, --quiet           only warnings and errors
  --timeout TIMEOUT     default I/O timeout (s)

Global options go before the subcommand: hwn -v uboot env ..., hwn --timeout 30 uboot dump .... --timeout sets context.timeout, the default I/O timeout in seconds.

Exit codes

Code Meaning
0 success
1 hwn fw analyze --fail-on: a finding at or above the threshold exists; hwn autobaud: no output on any rate
2 an error (device, file, tool or argument), printed as [-] ...
130 interrupted with Ctrl-C

Ports

--port takes a serial device (/dev/ttyUSB0, COM3), a pyserial URL (rfc2217://host:port, socket://host:port) or tcp:HOST:PORT for a raw TCP console such as ser2net. Serial ports need pip install "hwntools[serial]".

hwn console

An interactive serial console, like miniterm or picocom, with a session log for your report. Keys go to the target one at a time, so Ctrl-C reaches U-Boot instead of closing the console. See the console guide for the keys and the log format.

$ hwn console /dev/ttyUSB0 -b 115200 --log session.log --timestamps
$ hwn console tcp:10.0.0.5:3001 --log session.log      # ser2net
$ hwn console /dev/ttyUSB0 -b auto                     # run autobaud first
$ hwn console --sim                                    # a simulated U-Boot, no hardware

Ctrl-] quits. Ctrl-T then b sends BREAK, h toggles the hex view, e toggles local echo, ? lists the keys.

$ hwn console --help
usage: hwn console [-h] [--port PORT_OPT] [--baud BAUD] [--sim] [--log LOG]
                   [--timestamps] [--echo] [--eol {cr,lf,crlf}] [--hex]
                   [port]

Interactive serial console. Ctrl-] quits; Ctrl-T then b sends BREAK, h toggles the hex
view, e toggles local echo, ? lists the keys.

positional arguments:
  port                  serial device, pyserial URL, or tcp:HOST:PORT (ser2net)

options:
  -h, --help            show this help message and exit
  --port PORT_OPT, -p PORT_OPT
                        same as PORT
  --baud BAUD, -b BAUD  baud rate, or 'auto' to run autobaud first
  --sim                 connect to a simulated U-Boot instead
  --log LOG, -l LOG     append everything received to this file
  --timestamps, -t      timestamp every line in the log
  --echo, -e            local echo of typed characters
  --eol {cr,lf,crlf}    what Enter sends (default cr)
  --hex                 start in hex view

hwn learn

An interactive tutorial on the built-in simulator: lessons, exercise files, checks, hints and saved progress. See Learn in your terminal.

$ hwn learn                 # lessons and progress
$ hwn learn next            # start the next lesson
$ hwn learn check --watch   # re-check on every save
$ hwn learn --help
usage: hwn learn [-h] [--dir DIR] [--watch] [--yes] [--no-color] [action] [lesson]

Learn hwntools in your terminal, lesson by lesson, on a simulated router. No hardware and no network needed.

positional arguments:
  action             list | next | N | start | check | verify | watch | hint |
                     solution | reset | console
  lesson             lesson number (0 to 8)

options:
  -h, --help         show this help message and exit
  --dir DIR, -d DIR  workspace folder (default ./hwn-learn)
  --watch, -w        with check: re-check on save
  --yes, -y          do not ask before solution/reset
  --no-color         plain output

hwn learn                    list the lessons and your progress
hwn learn next               start the next unfinished lesson
hwn learn N                  start lesson N (0 to 8); same as `hwn learn start N`
hwn learn check [N]          check your exercise (default: the current lesson)
hwn learn check --watch      re-check on every save and move on when it passes
hwn learn verify N           same as `hwn learn check N`
hwn learn hint [N]           one more hint for the lesson
hwn learn solution N         show the reference solution (asks first; --yes skips)
hwn learn reset [N]          restore exercise files and forget progress (asks first)
hwn learn console            lesson 3 hands-on: stop the lab router's U-Boot by hand

Exercise files and progress live in the workspace: --dir DIR, $HWN_LEARN_DIR, the current
folder if it already is one, or ./hwn-learn. Everything runs on the built-in simulator,
offline.

hwn uboot env

Print the U-Boot environment, sorted, as key=value lines or JSON.

$ hwn uboot env --port /dev/ttyUSB0 --interrupt --json

With --interrupt, hwn sends the stop key (--key, Ctrl-C by default) until a prompt appears: start the command, then power-cycle the target. Without it, the console must already be sitting at a U-Boot prompt.

$ hwn uboot env --help
usage: hwn uboot env [-h] --port PORT [--baud BAUD] [--prompt PROMPT] [--interrupt]
                     [--key KEY] [--json] [--interrupt-timeout INTERRUPT_TIMEOUT]

options:
  -h, --help            show this help message and exit
  --port PORT, -p PORT  serial device, pyserial URL, or tcp:HOST:PORT (ser2net)
  --baud BAUD, -b BAUD
  --prompt PROMPT       U-Boot prompt (auto-detected by default)
  --interrupt           spam the stop key until a prompt appears (power-cycle the
                        target)
  --key KEY             autoboot stop key or string (default Ctrl-C)
  --json
  --interrupt-timeout INTERRUPT_TIMEOUT

hwn uboot dump

Dump memory with md.b into a file. Rerun the same command after an interruption and it resumes where the file ends (unless --no-resume). It only reads memory, so copy flash to RAM first (sf probe; sf read ...); see the U-Boot guide.

$ hwn uboot dump --port /dev/ttyUSB0 --addr 0x82000000 --size 0x1000000 -o spi.bin
$ hwn uboot dump --port tcp:10.0.0.5:3001 --addr 0x82000000 --size 0x1000000 -o spi.bin

Numbers accept any Python integer literal (0x82000000, 16777216, 0o100).

$ hwn uboot dump --help
usage: hwn uboot dump [-h] --port PORT [--baud BAUD] [--prompt PROMPT] [--interrupt]
                      [--key KEY] --addr ADDR --size SIZE --out OUT [--chunk CHUNK]
                      [--no-resume] [--interrupt-timeout INTERRUPT_TIMEOUT]

options:
  -h, --help            show this help message and exit
  --port PORT, -p PORT  serial device, pyserial URL, or tcp:HOST:PORT (ser2net)
  --baud BAUD, -b BAUD
  --prompt PROMPT       U-Boot prompt (auto-detected by default)
  --interrupt           spam the stop key until a prompt appears (power-cycle the
                        target)
  --key KEY             autoboot stop key or string (default Ctrl-C)
  --addr ADDR
  --size SIZE
  --out OUT, -o OUT
  --chunk CHUNK
  --no-resume
  --interrupt-timeout INTERRUPT_TIMEOUT

hwn autobaud

Guess the baud rate of a live UART (experimental). Prints the best candidates with their score and a sample of what was received; see Find the baud rate.

$ hwn autobaud --port /dev/ttyUSB0
$ hwn autobaud --port /dev/ttyUSB0 --bauds 115200,57600,1500000 --listen --time 3
$ hwn autobaud --help
usage: hwn autobaud [-h] --port PORT [--bauds BAUDS] [--time TIME] [--listen]
                    [--top TOP] [--all]

options:
  -h, --help            show this help message and exit
  --port PORT, -p PORT
  --bauds BAUDS         comma separated list (default: common rates)
  --time TIME           seconds to sample per rate
  --listen              do not send a probe CRLF
  --top TOP
  --all                 try every rate instead of stopping at clean output

hwn hexdump

$ hwn hexdump firmware.bin -s 0x40 -n 0x100
$ head -c 64 /dev/urandom | hwn hexdump -

Repeated lines are collapsed to * unless you pass --all.

$ hwn hexdump --help
usage: hwn hexdump [-h] [--offset OFFSET] [--length LENGTH] [--width WIDTH] [--all]
                   file

positional arguments:
  file

options:
  -h, --help            show this help message and exit
  --offset OFFSET, -s OFFSET
  --length LENGTH, -n LENGTH
  --width WIDTH, -w WIDTH
  --all, -a             do not collapse repeated lines

hwn entropy

$ hwn entropy firmware.bin --plot
$ hwn entropy firmware.bin --block 0x10000

Without --plot, one line per block: offset, entropy (0 to 8 bits per byte) and high (above 7.5, compressed or encrypted) or low (below 1.0, padding or erased flash).

$ hwn entropy --help
usage: hwn entropy [-h] [--block BLOCK] [--plot] [--width WIDTH] file

positional arguments:
  file

options:
  -h, --help     show this help message and exit
  --block BLOCK
  --plot         one-line sparkline
  --width WIDTH

hwn sigs

$ hwn sigs firmware.bin
0x00001140  uimage     uImage "Linux-4.4.60", data size 200, load 0x80008000, compression none
0x000015c1  fdt        Flattened device tree / FIT, size 91, version 17
$ hwn sigs firmware.bin --align 4 --json
$ hwn sigs --help
usage: hwn sigs [-h] [--align ALIGN] [--json] file

positional arguments:
  file

options:
  -h, --help     show this help message and exit
  --align ALIGN
  --json

hwn fw unpack

Extract a firmware image with the best available backend; see Unpack.

$ hwn fw unpack firmware.bin -o out/ --backend python --json
$ hwn fw unpack firmware.bin --force                  # redo an earlier unpack
$ hwn -q fw unpack firmware.bin --backend python --tree
backend: python  outdir: /work/firmware.bin.extracted  files: 13
  rootfs   00001348.uimage-ramdisk/tar-root
  kernel   00001140.uimage-kernel/kernel.bin
  dtb      000015d5.fit.dtb
  env      00000040.uboot-env.bin
  kconfig  ikconfig.config
info: U-Boot env (single, 0x1000 bytes) found at 0x40
warning: cpio: skipped unsafe member: path traversal in member name '../cpio-escape'
00001140.uimage-kernel/
  kernel.bin
  uimage-name.txt
00001348.uimage-ramdisk/
  tar-root/
    bin/
      busybox
      sh -> busybox
    etc/
      inittab
      passwd
      shadow
    sbin/
      init
  uimage-name.txt
...

info: lines are plain information; warning: lines are problems worth a look (missing tools, skipped data). The output directory must be new or empty; --force empties it first, but only if an earlier hwn fw unpack created it.

$ hwn fw unpack --help
usage: hwn fw unpack [-h] [--outdir OUTDIR]
                     [--backend {auto,unblob,docker,binwalk,python}] [--tree] [--json]
                     [--force]
                     image

positional arguments:
  image

options:
  -h, --help            show this help message and exit
  --outdir OUTDIR, -o OUTDIR
                        default: <image>.extracted
  --backend {auto,unblob,docker,binwalk,python}
  --tree                print the extracted tree
  --json
  --force, -f           replace an earlier hwn unpack in the output directory (other
                        dirs are refused)

hwn fw analyze

Unpack, then run fwsift and bootlint on what was found; see Findings with fwsift and bootlint.

$ hwn fw analyze firmware.bin
$ hwn fw analyze firmware.bin --json > triage.json
$ hwn fw analyze firmware.bin --fail-on high          # exit 1 on high or critical findings
$ hwn fw analyze --help
usage: hwn fw analyze [-h] [--outdir OUTDIR]
                      [--backend {auto,unblob,docker,binwalk,python}] [--osv] [--json]
                      [--force] [--limit LIMIT]
                      [--fail-on {info,low,medium,high,critical}]
                      image

positional arguments:
  image

options:
  -h, --help            show this help message and exit
  --outdir OUTDIR, -o OUTDIR
                        default: <image>.extracted
  --backend {auto,unblob,docker,binwalk,python}
  --osv                 query OSV for known CVEs (network)
  --json
  --force, -f           replace an earlier hwn unpack in the output directory (other
                        dirs are refused)
  --limit LIMIT         findings shown in the text report
  --fail-on {info,low,medium,high,critical}
                        exit 1 if a finding at or above this severity exists