TExcelTAD
Home › Security Projects, Study Plan, Certifications & Careers › Projects 7-8: A Fuzzing Campaign and an IoT Device Review

Projects 7-8: A Fuzzing Campaign and an IoT Device Review

The last two schools of the career lesson, reverse engineering and research, need projects that look inward at code and devices rather than outward at networks. Project 7 is a fuzzing campaign: point a fuzzer at a parser, find crashes, triage them, fix them, and show that the fuzzer no longer finds them. Project 8 is a review of an IoT device you own: its network exposure, its firmware, its update mechanism, written up as a vendor-ready report. Both are as close as this track comes to vulnerability research, and both stay on the safe side of the line by construction: the fuzzer runs against code you wrote or a toy you control, and the device is yours.

Project 7: a fuzzing campaign on a toy parser

Goal. Fuzz a small binary-format parser (written by you, or a deliberately buggy one from the track) with a coverage-guided fuzzer, find and triage its crashes, fix the bugs, and keep the fuzzer running as a regression test.

Builds on. Memory Safety: reading sanitizer reports, out-of-bounds reads, sanitizers and fuzzing in CI; Security Research for the fuzzer itself (AFL++ and libFuzzer, corpus and triage); the C parser of the starting-priorities lesson as a target idea.

Scope. Your own code only. Fuzzing third-party software is research: usually legal for a copy you run on your own machine (check its licence), but it comes with disclosure duties; keep it for after this project, and read the research course's disclosure lessons first.

The idea fits in a page of Python. The parser below reads a small record format, and version 2 of the format has a "long length" form whose second byte is never checked. Two fuzzers attack it with the same budget of 20,000 inputs: one sends random bytes, the other mutates inputs from a corpus and keeps any input that reaches a branch it has not seen before:

python · try it yourself
import random

def parse(data, cov):
    """Toy record parser: magic 'TD', version, count, then count records of (len, bytes)."""
    if len(data) < 4:
        cov.add("short"); return "short"
    if data[:2] != b"TD":
        cov.add("magic"); return "bad magic"
    cov.add("magic ok")
    if data[2] not in (1, 2):
        cov.add("version"); return "bad version"
    cov.add(f"v{data[2]}")
    pos, out = 4, []
    for i in range(data[3]):
        cov.add(f"record {min(i, 3)}")
        if pos >= len(data):
            cov.add("truncated"); return "truncated"
        n = data[pos]
        if data[2] == 2 and n > 0x7f:
            cov.add("v2 long length")
            n = ((n & 0x7f) << 8) | data[pos + 1]   # BUG: no check that data[pos + 1] exists
            pos += 1
        out.append(data[pos + 1:pos + 1 + n])
        pos += 1 + n
    cov.add("done")
    return out

def mutate(rng, data):
    data = bytearray(data)
    for _ in range(rng.randint(1, 3)):
        op = rng.randrange(3)
        if op == 0 and data:
            data[rng.randrange(len(data))] = rng.randrange(256)
        elif op == 1:
            data.insert(rng.randrange(len(data) + 1), rng.randrange(256))
        elif data:
            del data[rng.randrange(len(data))]
    return bytes(data)

def fuzz(guided, runs=20000, seed=1):
    rng = random.Random(seed)
    corpus, seen = [b"TD\x01\x01\x03abc"], set()
    for i in range(1, runs + 1):
        if guided:
            data = mutate(rng, rng.choice(corpus))
        else:
            data = bytes(rng.randrange(256) for _ in range(rng.randint(1, 10)))
        cov = set()
        try:
            parse(data, cov)
        except IndexError:
            return i, len(seen | cov), data
        if guided and not cov <= seen:
            corpus.append(data)          # new coverage: keep this input
        seen |= cov
    return None, len(seen), None

for guided in (False, True):
    crash_at, edges, data = fuzz(guided)
    name = "coverage-guided" if guided else "random bytes"
    result = f"crash after {crash_at} runs, input {data.hex()}" if crash_at else "no crash in 20000 runs"
    print(f"{name:16} {edges:2} branches seen; {result}")
random bytes      2 branches seen; no crash in 20000 runs
coverage-guided  11 branches seen; crash after 9753 runs, input 54440261b4

Random bytes almost never begin with the two magic bytes TD, so they only ever see the two rejection branches. The guided fuzzer starts from one valid input, keeps every mutation that reaches new code (version 2, more records, the long-length branch) and crashes the parser after 9,753 runs with a 5-byte input: magic, version 2, a record count, and a length byte with the high bit set and nothing after it. That input is the triage result: minimal, reproducible, and pointing straight at the missing check. The fix is a bounds check before reading the second length byte (and before slicing the value); the retest is the same campaign running clean, with the crashing input added to the corpus as a regression test.

The fuzzing lab shows the same race on a larger scale, including what a dictionary of magic values does:

target: parse(b, len)if (len < 4) return;if (b[0] == 'T') { if (b[1] == 'A') { if (b[2] == 'D') { if (b[3] == '!') crash();}}}if (b[len-1] == '\n') …dots: branch taken, random | guidedbranch edges covered (of 12)036912110^110^210^310^4executions (log scale)✕crash at 14,416randomguided: havocexecutions: 50,000random: 7 edges, crash not foundguided: 12 edges, crash at 14,416corpus: 8 inputs keptrandom: 1 crash in ≈ 6.9e9 runsa deterministic simulation with a fixed seed; toy target, no real program is fuzzed

In the lab. Port the parser to C, build it with AddressSanitizer and a libFuzzer or AFL++ harness, and run the campaign for an hour. Record coverage over time, every unique crash (deduplicated by stack trace), its sanitizer report and its fix.

Deliverables. The harness and build commands; the campaign log (executions, coverage, time); a crash table (input, sanitizer report summary, root cause, fix); the fixed parser with the crash inputs as regression tests; a one-page write-up.

Rubric specifics. Technical work 3: sanitizers on, crashes deduplicated and minimised, root cause explained at the level of the code. Detection: the fuzzer and sanitizers are the detection; 3 means they run in CI. Fix and retest: every crash fixed and the campaign rerun clean.

Stretch goal. Add a dictionary of the format's magic values and compare time-to-crash with and without it; then write a structure-aware mutator for the record format.

Project 8: a security review of an IoT device you own

Goal. Review one connected device that you own (a camera, a smart plug, a router you no longer use), as a vendor would want it reviewed: its network exposure, its firmware, its update mechanism, its companion app's traffic, and a report with fixes the vendor could make.

Builds on. Wireless, IoT & Mobile: radio law and scope, IoT threat model, firmware analysis, debug ports and secure boot, update security, MQTT and CoAP, IoT segmentation; Reverse Engineering for the firmware.

Scope, carefully. The device itself, on an isolated lab network or a dedicated access point, with firmware obtained from the device or the vendor's public download page. Out of scope: the vendor's cloud services and other customers' devices (they are not yours, whatever the app talks to); any radio transmission beyond what the device normally does; anything that would violate your local radio regulations. If you find a real vulnerability, the disclosure lesson applies: report it to the vendor, not to the Internet.

Firmware review starts with looking at the image as data. This starter builds a synthetic firmware image for a fictional lab camera and runs the checks a first pass makes: hard-coded credentials, debug services, embedded private keys, the update configuration, and entropy (high-entropy regions are compressed or encrypted and need unpacking first):

python · try it yourself
import hashlib, math, random, re
from collections import Counter

# A synthetic firmware image for a fictional lab camera: header, a small file table, files, padding.
rng = random.Random(7)
FILES = {
    "etc/passwd": b"root:$1$lab$Q3RkYXRhLWxhYi1vbmx5:0:0:root:/root:/bin/sh\n",
    "etc/inittab": b"::sysinit:/etc/init.d/rcS\n::respawn:/usr/sbin/telnetd -l /bin/sh\n",
    "etc/update.conf": b"server=http://update.lab.test/fw/camera.bin\nverify_signature=0\n",
    "etc/ssl/device.key": b"-----BEGIN PRIVATE KEY-----\nLAB-ONLY-NOT-A-REAL-KEY\n-----END PRIVATE KEY-----\n",
    "www/blob.bin": bytes(rng.randrange(256) for _ in range(4096)),   # stands in for compressed data
}
image = b"LABCAMv1.0\x00\x00"
for name, data in FILES.items():
    image += name.encode().ljust(32, b"\x00") + len(data).to_bytes(4, "big") + data
image += b"\xff" * 1024

CHECKS = [
    ("hard-coded password hash", rb"root:\$1\$[^:]+:"),
    ("telnet started at boot", rb"telnetd"),
    ("private key in the image", rb"-----BEGIN [A-Z ]*PRIVATE KEY-----"),
    ("update over plain HTTP", rb"server=http://"),
    ("update signature check off", rb"verify_signature=0"),
]

def entropy(chunk):
    counts = Counter(chunk)
    return -sum(c / len(chunk) * math.log2(c / len(chunk)) for c in counts.values())

print(f"image {len(image)} bytes, sha256 {hashlib.sha256(image).hexdigest()[:16]}...")
findings = [(m.start(), name) for name, pattern in CHECKS for m in re.finditer(pattern, image)]
for off in range(0, len(image), 1024):
    h = entropy(image[off:off + 1024])
    if h > 7.5:
        findings.append((off, f"high entropy {h:.2f} bits/byte: unpack it and look inside"))
for off, what in sorted(findings):
    print(f"  0x{off:05x}  {what}")
image 5574 bytes, sha256 838befc59ab373ca...
  0x00030  hard-coded password hash
  0x000ba  telnet started at boot
  0x000f1  update over plain HTTP
  0x0011d  update signature check off
  0x00154  private key in the image
  0x00400  high entropy 7.82 bits/byte: unpack it and look inside
  0x00800  high entropy 7.83 bits/byte: unpack it and look inside
  0x00c00  high entropy 7.80 bits/byte: unpack it and look inside

Five findings and a region to unpack, from a 5.5 KB image. Each is a real class of IoT weakness with a known fix: a hard-coded root password hash (unique per-device credentials set at first boot), a telnet shell started at boot (remove it from release builds), a private key shared by every device that runs this image (generate keys on the device), and an update channel over plain HTTP with signature checking turned off (signed updates over TLS, verified before flashing). In a real image the high-entropy block would be a compressed filesystem, and the next step is to extract it with a firmware unpacker in your lab and repeat the checks on the files inside.

Deliverables. The device's threat model; network exposure (open ports, services, their versions, from your lab); firmware findings with offsets and evidence; the update mechanism's analysis; the companion app's traffic summary (from your own phone, captured on your lab access point); a report with severity, fix and detection per finding; a disclosure note if anything real was found.

Rubric specifics. Scope and safety 3: the device is yours, the cloud is explicitly out of scope, and the network is isolated. Fix and retest: for a device you can't patch, the fix is a vendor recommendation plus a compensating control you apply (segmentation, blocking the update server, disabling a service) and retest.

Stretch goal. If the device has a UART or JTAG header, document it (photos, pin-out) and whether it gives a shell, following the hardware lesson's safety notes.

Pitfalls

  • Fuzzing without sanitizers. Many memory bugs don't crash; without AddressSanitizer the fuzzer can't see them.
  • Counting crashes instead of bugs. A hundred crashing inputs are often one bug; deduplicate by stack trace.
  • Following the device to the cloud. The app's API is someone else's server. Note what it talks to; don't test it.

Practice

1. Fix the toy parser so the guided fuzzer finds no crash. What changes in the output?

Before reading data[pos + 1], add if pos + 1 >= len(data): cov.add("truncated"); return "truncated". The guided line becomes "no crash in 20000 runs", and its branch count may change because the new branch is counted and the corpus evolves differently (rerun to see the exact number).

2. Which of the firmware findings could an attacker exploit without physical access, and which detection would a network defender add?

Telnet at boot (any host on the same network can try the root password, which is the same on every device) and the unsigned HTTP update (anyone who can intercept or redirect the device's traffic can serve modified firmware). Detection: alert on telnet connections to IoT segments and on the device fetching updates from any server other than the expected one.

Test yourself

Why does the random-bytes fuzzer see only two branches?

  1. It runs fewer times
  2. Random inputs almost never start with the magic bytes TD, so they are rejected immediately
  3. The parser crashes at once
  4. It has no seed

What does the coverage-guided fuzzer keep in its corpus?

  1. Every input
  2. Inputs that crashed
  3. Inputs that reached a branch not seen before
  4. Only valid inputs

In the IoT review, which system is explicitly out of scope?

  1. The device you own
  2. Its firmware from the vendor's public page
  3. The vendor's cloud services the companion app talks to
  4. Your lab access point

Why is a private key inside a firmware image a finding even if it is never used to attack anything?

  1. Keys make images bigger
  2. Every device running the image shares the same key, so anyone who downloads the firmware has it
  3. Keys must be in PEM format
  4. It is not a finding