TExcelTAD

Security Research Exercises

These exercises revisit every section of the course. Try each one before opening the answer; the answers link back to the lessons that explain them. One exercise runs code: a crash-bucketing script on synthetic reports, where you predict the buckets before reading the output.

Process and scope

1. You want to fuzz the image decoder of a popular open-source viewer. Write the first three lines of your research notebook.

Answer

Target and version (with the exact commit you build), the authorisation basis (open-source code built and fuzzed on your own machine; the project's security policy for reporting), and the first hypothesis with its test ("the decoder trusts the chunk length for its buffers; fuzz decode_chunk with ASan for 24 h"). See The Research Workflow and Introduction and Scope.

2. A finding is a stack overflow in a command-line converter that only the build system runs, on files from the repository. Vulnerability or not?

Answer

Not by default: nobody outside can reach it, so it is a bug to fix as hardening. It becomes a vulnerability if the converter ever processes files from contributors or users, for example in a CI job that builds pull requests. Argue reachability and boundary explicitly (What Vulnerability Research Is).

Fuzzing

3. A parser checks an 8-byte magic value with memcmp. Why does libFuzzer usually get past it quickly, while the djb2-hashed keywords of the dictionary lesson stopped it completely?

Answer

libFuzzer traces the arguments of memcmp and comparison instructions and inserts the operands it sees into inputs. A comparison of hashes shows only numbers, from which the keyword can't be derived; a dictionary supplies the tokens directly (Why Fuzzing Works, Corpus, Dictionaries and Minimisation).

4. Your Python fuzzer's corpus stays at one entry for 50,000 runs. Name three possible causes.

Answer

The coverage tracer doesn't see the target's code (wrong code object or the target runs in another function); every mutation fails an early check such as a checksum, so no new arcs appear; the mutations can't produce the needed values (as the bit-flip strategy in the lab). Check the tracer on a known-different input first (Build a Coverage-Guided Fuzzer).

5. Which fuzzing family fits each target best: (a) a SQL query planner, (b) a PNG decoder, (c) a run-length codec whose bug is a wrong result, not a crash?

Answer

(a) grammar-based or structure-aware generation, because inputs must be valid SQL; (b) coverage-guided mutation with a seed corpus of small PNGs and a dictionary of chunk names, with the CRC check disabled in the fuzzing build; (c) property-based testing or a fuzz harness with a round-trip assertion as the oracle (Fuzzing Strategies, Property-Based Testing).

6. A UBSan build reports signed integer overflow but the fuzzer keeps running and saves no input. What is missing?

Answer

-fno-sanitize-recover=undefined (or UBSAN_OPTIONS=halt_on_error=1): without it, UBSan prints and continues, so libFuzzer never sees a crash (libFuzzer Harnesses and Sanitizers as Oracles).

7. AFL++ shows 64% stability. What does that mean, and what do you do before fuzzing further?

Answer

About a third of the coverage-map entries the target touches do not behave the same way when the same input is run again: the target is non-deterministic (uninitialised memory, global state, time, randomness, threads). Find and remove the cause (or reset state in the harness); otherwise the coverage feedback is noise (AFL++, OSS-Fuzz and ClusterFuzz).

Triage and root cause

8. Run it. Seven crash summaries from a campaign on a toy archive reader. The script ignores library frames (memcpy, crc32_update) and buckets the crashes by kind, access and the top 1, 2 or 3 frames of the reader's own code. Predict the number of buckets for each depth first:

python · try it yourself
import hashlib

# Seven crash summaries from a weekend campaign on a toy archive reader (synthetic).
crashes = [
    ("a1", "heap-buffer-overflow", "WRITE", ["memcpy", "read_entry", "extract_all", "main"]),
    ("a2", "heap-buffer-overflow", "WRITE", ["memcpy", "read_entry", "list_entries", "main"]),
    ("a3", "heap-buffer-overflow", "READ",  ["crc32_update", "verify_entry", "extract_all", "main"]),
    ("a4", "SEGV",                 "READ",  ["read_header", "open_archive", "main"]),
    ("a5", "heap-buffer-overflow", "WRITE", ["memcpy", "read_entry", "extract_all", "main"]),
    ("a6", "heap-use-after-free",  "READ",  ["entry_name", "list_entries", "main"]),
    ("a7", "heap-buffer-overflow", "READ",  ["crc32_update", "verify_entry", "extract_all", "main"]),
]
LIBRARY = {"memcpy", "crc32_update"}         # library code: skip it when building the key

def key(kind, access, frames, n):
    own = [f for f in frames if f not in LIBRARY][:n]
    return hashlib.sha1("|".join([kind, access] + own).encode()).hexdigest()[:8]

for n in (1, 2, 3):
    buckets = {}
    for cid, kind, access, frames in crashes:
        buckets.setdefault(key(kind, access, frames, n), []).append(cid)
    print(f"top {n} frame(s): {len(buckets)} buckets: {sorted(buckets.values())}")
top 1 frame(s): 4 buckets: [['a1', 'a2', 'a5'], ['a3', 'a7'], ['a4'], ['a6']]
top 2 frame(s): 5 buckets: [['a1', 'a5'], ['a2'], ['a3', 'a7'], ['a4'], ['a6']]
top 3 frame(s): 5 buckets: [['a1', 'a5'], ['a2'], ['a3', 'a7'], ['a4'], ['a6']]
Answer

With one frame, the three memcpy writes from read_entry fall into one bucket, although a2 came through list_entries; with two or more frames a2 gets its own bucket. Is that right? Only root-cause analysis can say: if read_entry has a single wrong length, it is one bug reached from two callers, and depth 1 was the better choice for this code. That is why the key depth is tuned per project and buckets are merged after root-cause analysis (Crash Deduplication). a3/a7 (a read in verify_entry), a4 (a SEGV on a read: check the faulting address, a near-null one usually means denial of service) and a6 (use-after-free, look at it early) are separate at every depth.

9. Delta debugging at byte level stops at 140 bytes for a crash in a length-prefixed format. What do you change?

Answer

The units: split the input into records (or tokens) and minimise those first, then minimise bytes inside the survivors. Removing single bytes breaks the framing, so the test passes for the wrong reason (Delta Debugging).

10. In gdb, the crash is in memcpy and the length is 300. Which two questions lead to the root cause?

Answer

Where did 300 come from (walk up the stack: which function read or computed it), and which check should have compared it with the destination buffer but didn't (or compared it with the wrong limit)? A conditional breakpoint before the copy shows the state (Root-Cause Analysis with gdb).

Static and variant analysis

11. Write the source, sink and sanitizer for a path-traversal taint rule in a web app.

Answer

Source: request parameters and uploaded file names. Sink: open, send_file, os.path.join results passed to file APIs. Sanitizer: canonicalise the joined path and check that it is inside the allowed directory (not a string filter on ..) (Code Review, Taint Analysis, Semgrep and CodeQL).

12. After fixing rec_name, your variant search reports three copies with checks. Why read each check?

Answer

A check against the wrong limit (rec_title compared with 64 for a 24-byte buffer) or with the wrong operator (> where >= is needed) is still a bug. Presence of an if proves nothing (Variant Analysis).

Kernel, browser, protocol, hardware

13. Match each mitigation with what it stops: SMEP, SMAP, KPTI, seccomp.

Answer

SMEP: the kernel executing user pages. SMAP: the kernel reading or writing user pages outside copy routines. KPTI: Meltdown-style reads of kernel memory from user mode. seccomp: a process reaching system calls outside its allow-list at all (The Kernel as a Target).

14. Why does an eBPF verifier bug count as a kernel vulnerability even though the program it accepts was written by a user?

Answer

The verifier is the boundary: it promises that accepted programs can't access kernel memory out of bounds. A verifier that accepts an unsafe program lets a (possibly unprivileged) user run out-of-bounds accesses in kernel mode (Kernel Fuzzing with syzkaller and the eBPF Verifier).

15. A browser renderer sends "read cookies for bank.lab.test" but is locked to ads.lab.test. What should happen, and why can't the browser trust the message?

Answer

The browser process treats it as a bad message and kills the renderer. The renderer runs untrusted content and may be compromised, so every field it sends is attacker-controlled; only the browser's record of the process's site lock is trustworthy (Browser Architecture).

16. A protocol implementation passes every message-format fuzz test. Which bug class can still hide, and how do you test for it?

Answer

State-machine bugs: valid messages accepted in the wrong state (data before authentication). Fuzz message order with a security property as the oracle, search short sequences exhaustively, or model-check the design (Protocol State Machines, Model Checking).

17. Why does adding a random delay not fix a timing leak in a token comparison?

Answer

The attacker averages many measurements; random noise averages out while the data-dependent difference stays. Use a constant-time comparison such as hmac.compare_digest (Timing Side Channels).

18. What is the difference between what secure boot and measured boot do with a modified bootloader?

Answer

Secure boot refuses to run it (signature check fails). Measured boot runs it but records its hash in a PCR; a remote verifier or a sealed key then detects the change (Firmware, Secure Boot and TPMs).

AI security, supply chain and disclosure

19. An LLM assistant summarises web pages and can send e-mail. Name the two OWASP LLM risks involved and the defence that holds even if the model obeys an injected instruction.

Answer

LLM01 Prompt Injection and LLM06 Excessive Agency. Privilege separation: the component that reads web pages has no send tool, and sending requires code-enforced recipient checks and user confirmation (Prompt Injection).

20. A spam filter's accuracy is unchanged after retraining on new crowd data, but one rare token now makes any spam pass. What is it, and how do you find the rows responsible?

Answer

A backdoor from data poisoning. Look for rare features with extreme label purity, group the matching rows by contributor (provenance), remove the source and retrain; test the model with candidate triggers (Data Poisoning and Backdoors).

21. Which mechanical check would have flagged the xz-utils release's build-script change?

Answer

Comparing the release tarball with the tagged source (or building from the tag): the modified build-to-host.m4 existed only in the tarball (Supply Chain as Research).

22. List the parts of an advisory that a deployer needs to act, and one thing that must not be in it.

Answer

Affected and fixed versions, severity with the CVSS vector, a short summary with the CWE, impact (including whether exploitation is known), workarounds, references. Not in it: exploitation details such as offsets, payload layouts or chains (Writing an Advisory, Coordinated Disclosure).

Test yourself

In exercise 8, why does a2 move to its own bucket at depth 2?

  1. It is a different bug kind
  2. Its second own frame is list_entries instead of extract_all
  3. It has a different size
  4. It is a READ

Which oracle finds a codec that silently corrupts data?

  1. ASan
  2. A round-trip property: decode(encode(x)) == x
  3. Code coverage
  4. A timeout

Which ISO/IEC standard covers vulnerability disclosure to the outside world?

  1. ISO/IEC 27001
  2. ISO/IEC 29147
  3. ISO/IEC 30111
  4. ISO/IEC 15408