Fuzzing Dictionary

作者 trailofbits82fe82262526無授權條款7.4K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

Builds and applies fuzzing dictionaries so a fuzzer can produce the keywords, magic bytes, and tokens a target expects. Covers extracting tokens from source, headers, binaries, and specifications, dictionary syntax, and wiring one into libFuzzer or AFL++. Use when fuzzing a parser, protocol, or file format, when coverage stalls at input validation, or when a target compares against fixed strings.

AI 產生的概覽

建立包含關鍵字、魔術位元組與權杖的模糊測試字典,並接入 libFuzzer、AFL++ 或 cargo-fuzz。

功能
此技能說明如何建立模糊測試字典檔案,內容包含加引號的權杖、鍵值對與十六進位轉義,用來引導模糊測試器產生有意義的輸入。內容涵蓋從原始碼標頭檔、man 手冊、二進位字串、規格或大型語言模型產生字典項目,以及如何把字典傳給 libFuzzer、AFL++、cargo-fuzz 或 go-fuzz。另外也列出通訊協定關鍵字、檔案格式魔術位元組與設定關鍵字等常見模式,以及反模式和疑難排解建議。
適用情境
適用於對解析器、通訊協定實作或檔案格式處理程式進行模糊測試時,覆蓋率在輸入驗證處停滯時,或目標程式碼會與固定字串、魔術值比較時。若目標是沒有格式預期的純演算法,或語料庫已能達到高覆蓋率,則不需要使用。
執行需求
僅為說明性內容,未附帶指令碼。依其中指引操作需要模糊測試工具鏈,例如 libFuzzer、AFL++(自動字典需 afl-clang-lto)、cargo-fuzz 或 go-fuzz,以及 grep、strings、sed 等用來擷取權杖的 shell 工具。

Fuzzing Dictionary

A fuzzing dictionary provides domain-specific tokens to guide the fuzzer toward interesting inputs. Instead of purely random mutations, the fuzzer incorporates known keywords, magic numbers, protocol commands, and format-specific strings that are more likely to reach deeper code paths in parsers, protocol handlers, and file format processors.

Overview

Dictionaries are text files containing quoted strings that represent meaningful tokens for your target. They help fuzzers bypass early validation checks and explore code paths that would be difficult to reach through blind mutation alone.

Key Concepts

ConceptDescription
Dictionary EntryA quoted string (e.g., "keyword") or key-value pair (e.g., kw="value")
Hex EscapesByte sequences like "\xF7\xF8" for non-printable characters
Token InjectionFuzzer inserts dictionary entries into generated inputs
Cross-Fuzzer FormatDictionary files work with libFuzzer, AFL++, and cargo-fuzz

When to Apply

Apply this technique when:

  • Fuzzing parsers (JSON, XML, config files)
  • Fuzzing protocol implementations (HTTP, DNS, custom protocols)
  • Fuzzing file format handlers (PNG, PDF, media codecs)
  • Coverage plateaus early without reaching deeper logic
  • Target code checks for specific keywords or magic values

Skip this technique when:

  • Fuzzing pure algorithms without format expectations
  • Target has no keyword-based parsing
  • Corpus already achieves high coverage

Quick Reference

TaskCommand/Pattern
Use with libFuzzer./fuzz -dict=./dictionary.dict ...
Use with AFL++afl-fuzz -x ./dictionary.dict ...
Use with cargo-fuzzcargo fuzz run fuzz_target -- -dict=./dictionary.dict
Extract from headergrep -o '".*"' header.h > header.dict
Generate from binarystrings ./binary | sed 's/^/"&/; s/$/&"/' > strings.dict

Step-by-Step

Step 1: Create Dictionary File

Create a text file with quoted strings on each line. Use comments (#) for documentation.

Example dictionary format:

conf
# Lines starting with '#' and empty lines are ignored.
# Adds "blah" (w/o quotes) to the dictionary.kw1="blah"# Use \\ for backslash and \" for quotes.kw2="\"ac\\dc\""# Use \xAB for hex valueskw3="\xF7\xF8"# the name of the keyword followed by '=' may be omitted:"foo\x0Abar"

Step 2: Generate Dictionary Content

Choose a generation method based on what's available:

From LLM: Prompt ChatGPT or Claude with:

text
A dictionary can be used to guide the fuzzer. Write me a dictionary file for fuzzing a <PNG parser>. Each line should be a quoted string or key-value pair like kw="value". Include magic bytes, chunk types, and common header values. Use hex escapes like "\xF7\xF8" for binary values.

From header files:

bash
grep -o '".*"' header.h > header.dict

From man pages (for CLI tools):

bash
man curl | grep -oP '^\s*(--|-)\K\S+' | sed 's/[,.]$//' | sed 's/^/"&/; s/$/&"/' | sort -u > man.dict

From binary strings:

bash
strings ./binary | sed 's/^/"&/; s/$/&"/' > strings.dict

Step 3: Pass Dictionary to Fuzzer

Use the appropriate flag for your fuzzer (see Quick Reference above).

Common Patterns

Pattern: Protocol Keywords

Use Case: Fuzzing HTTP or custom protocol handlers

Dictionary content:

conf
# HTTP methods"GET""POST""PUT""DELETE""HEAD"
# Headers"Content-Type""Authorization""Host"
# Protocol markers"HTTP/1.1""HTTP/2.0"

Pattern: Magic Bytes and File Format Headers

Use Case: Fuzzing image parsers, media decoders, archive handlers

Dictionary content:

conf
# PNG magic bytes and chunkspng_magic="\x89PNG\r\n\x1a\n"ihdr="IHDR"plte="PLTE"idat="IDAT"iend="IEND"
# JPEG markersjpeg_soi="\xFF\xD8"jpeg_eoi="\xFF\xD9"

Pattern: Configuration File Keywords

Use Case: Fuzzing config file parsers (YAML, TOML, INI)

Dictionary content:

conf
# Common config keywords"true""false""null""version""enabled""disabled"
# Section headers"[general]""[network]""[security]"

Advanced Usage

Tips and Tricks

TipWhy It Helps
Combine multiple generation methodsLLM-generated keywords + strings from binary covers broad surface
Include boundary values"0", "-1", "2147483647" trigger edge cases
Add format delimiters:, =, {, } help fuzzer construct valid structures
Keep dictionaries focused50-200 entries perform better than thousands
Test dictionary effectivenessRun with and without dict, compare coverage

Auto-Generated Dictionaries (AFL++)

When using afl-clang-lto compiler, AFL++ automatically extracts dictionary entries from string comparisons in the binary. This happens at compile time via the AUTODICTIONARY feature.

Enable auto-dictionary:

bash
export AFL_LLVM_DICT2FILE=auto.dictafl-clang-lto++ target.cc -o target# Dictionary saved to auto.dictafl-fuzz -x auto.dict -i in -o out -- ./target

Combining Multiple Dictionaries

Some fuzzers support multiple dictionary files:

bash
# AFL++ with multiple dictionariesafl-fuzz -x keywords.dict -x formats.dict -i in -o out -- ./target

Anti-Patterns

Anti-PatternProblemCorrect Approach
Including full sentencesFuzzer needs atomic tokens, not proseBreak into individual keywords
Duplicating entriesWastes mutation budgetUse sort -u to deduplicate
Over-sized dictionariesSlows fuzzer, dilutes useful tokensKeep focused: 50-200 most relevant entries
Missing hex escapesNon-printable bytes become mangledUse \xXX for binary values
No commentsHard to maintain and auditDocument sections with # comments

Tool-Specific Guidance

libFuzzer

bash
clang++ -fsanitize=fuzzer,address harness.cc -o fuzz./fuzz -dict=./dictionary.dict corpus/

Integration tips:

  • Dictionary tokens are inserted/replaced during mutations
  • Combine with -max_len to control input size
  • Use -print_final_stats=1 to see dictionary effectiveness metrics
  • Dictionary entries longer than -max_len are ignored

AFL++

bash
afl-fuzz -x ./dictionary.dict -i input/ -o output/ -- ./target @@

Integration tips:

  • AFL++ supports multiple -x flags for multiple dictionaries
  • Use AFL_LLVM_DICT2FILE with afl-clang-lto for auto-generated dictionaries
  • Dictionary effectiveness shown in fuzzer stats UI
  • Tokens are used during deterministic and havoc stages

cargo-fuzz (Rust)

bash
cargo fuzz run fuzz_target -- -dict=./dictionary.dict

Integration tips:

  • cargo-fuzz uses libFuzzer backend, so all libFuzzer dict flags work
  • Place dictionary file in fuzz/ directory alongside harness
  • Reference from harness directory: cargo fuzz run target -- -dict=../dictionary.dict

go-fuzz (Go)

go-fuzz does not have built-in dictionary support, but you can manually seed the corpus with dictionary entries:

bash
# Convert dictionary to corpus filesgrep -o '".*"' dict.txt | while read line; do    echo -n "$line" | base64 > corpus/$(echo "$line" | md5sum | cut -d' ' -f1)done
go-fuzz -bin=./target-fuzz.zip -workdir=.

Troubleshooting

IssueCauseSolution
Dictionary file not loadedWrong path or format errorCheck fuzzer output for dict parsing errors; verify file format
No coverage improvementDictionary tokens not relevantAnalyze target code for actual keywords; try different generation method
Syntax errors in dict fileUnescaped quotes or invalid escapesUse \\ for backslash, \" for quotes; validate with test run
Fuzzer ignores long entriesEntries exceed -max_lenKeep entries under max input length, or increase -max_len
Too many entries slow fuzzerDictionary too largePrune to 50-200 most relevant entries

Related Skills

Tools That Use This Technique

SkillHow It Applies
libfuzzerNative dictionary support via -dict= flag
aflppNative dictionary support via -x flag; auto-generation with AUTODICTIONARIES
cargo-fuzzUses libFuzzer backend, inherits -dict= support

Related Techniques

SkillRelationship
fuzzing-corpusDictionaries complement corpus: corpus provides structure, dictionary provides keywords
coverage-analysisUse coverage data to validate dictionary effectiveness
harness-writingHarness structure determines which dictionary tokens are useful

Resources

Key External Resources

AFL++ Dictionaries Pre-built dictionaries for common formats (HTML, XML, JSON, SQL, etc.). Good starting point for format-specific fuzzing.

libFuzzer Dictionary Documentation Official libFuzzer documentation on dictionary format and usage. Explains token insertion strategy and performance implications.

Additional Examples

OSS-Fuzz Dictionaries Real-world dictionaries from Google's continuous fuzzing service. Search project directories for *.dict files to see production examples.

來源與署名

來源:trailofbits/skills位於plugins/testing-handbook-skills/skills/fuzzing-dictionary提交82fe822

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架