Fuzzing (Fuzz Testing) là gì?
Fuzzing là kỹ thuật **kiểm thử hộp đen (black-box)** tự động hoặc bán tự động, cung cấp **dữ liệu đầu vào bất hợp lệ, ngẫu nhiên, không mong đợi (fuzz data)** cho chương trình/mạng/hệ thống để kích hoạt lỗi: crash, memory leak, assertion failure, logic error, security vulnerability (buffer overflow, use-after-free, injection...).
1. Tại sao Fuzzing quan trọng?
- Tìm lỗ hổng **Zero-day** (chưa biết, chưa có signature).
- Phát hiện lỗi **logic sâu** mà unit test/integration test bỏ lỡ.
- Đánh giá **độ bền (robustness)** của parser, protocol handler, file format processor, API.
- Tự động hóa, mở rộng quy mô lớn (thousands of inputs/second).
- Bổ sung cho SAST/DAST/Manual Review.
2. Phân loại Fuzzing
| Loại | Đặc điểm | Ví dụ công cụ |
| Black-box (Generative/Random) | Không biết cấu trúc nội bộ. Sinh input ngẫu nhiên hoặc dựa trên spec/grammar. | Radamsa, zzuf, Peach Fuzzer (generation), AFL (dumb mode) |
| White-box (Coverage-guided / Grey-box) | Có source code / binary instrumentation. Theo dõi code coverage (path) để hướng sinh input mới覆盖 mới. Hiệu quả nhất. | AFL/AFL++, libFuzzer (LLVM), Honggfuzz, WinAFL, Jackalope |
| Structure-aware / Grammar-based | Sinh input tuân theo grammar/schema (XML, JSON, Protobuf, SQL, WASM, PDF, Image format). | Peach Fuzzer, Nautilus, AFLSmart, libprotobuf-mutator, Domato (Google) |
| Stateful / Protocol Fuzzing | Fuzzing giao thức có trạng thái (TLS, HTTP/2, SSH, RDP, SMB, 802.11). Cần maintain session state. | Boofuzz, Kitty, StateAFL, AFLNet, Nyx (hypervisor-level) |
| In-process / Library Fuzzing | Fuzz trực tiếp function/API (fuzz target) trong process. Rất nhanh, không IPC overhead. | libFuzzer (C/C++/Rust), go-fuzz (Go), Jazzer (JVM), cargo-fuzz (Rust), Atheris (Python) |
3. Quy trình Fuzzing chuẩn (Fuzzing Loop)
- Identify Target: Chọn chương trình/thư viện/giao thức cần test (parser, codec, kernel driver, smart contract...).
- Define Input Format: Grammar, Schema, Dictionary, Seed Corpus (mẫu input hợp lệ).
- Instrumentation: Compile target với coverage instrumentation (Clang `-fsanitize=fuzzer,address -fno-omit-frame-pointer` cho libFuzzer/AFL).
- Fuzzing Loop:
- Mutate input (bitflip, arithmetic, insertion, deletion, splicing, dictionary, structure-aware).
- Execute target với input.
- Monitor: Crash (ASAN/MSAN/TSAN/UBSAN), Timeout, Memory leak, Custom oracle (assertion, diff).
- New coverage? → Add to corpus.
- Crash? → Save testcase, minimize, deduplicate, triage.
- Triage & Root Cause Analysis: Minimize testcase, debug (GDB/lldb/WinDbg), phân loại CWE, báo cáo vendor.
4. Sanitizers (Bộ phát hiện lỗi tại runtime) - Đối tác không tách rời của Fuzzing
- AddressSanitizer (ASAN): Buffer overflow, use-after-free, double-free, stack-use-after-return. Bắt buộc.
- MemorySanitizer (MSAN): Uninitialized memory read.
- ThreadSanitizer (TSAN): Data race.
- UndefinedBehaviorSanitizer (UBSAN): Signed integer overflow, null pointer dereference, misalignment, v.v.
- Hardware-assisted: Intel PT, ARM MTE, HWASAN (Android).
5. Fuzzing trong Network Security (Network Protocol Fuzzing)
- Mục tiêu: TCP/IP stack, TLS (OpenSSL, BoringSSL, mbedTLS), HTTP/2/3 (nghttp2, quiche), DNS, DHCP, SMB, RDP, SSH, VPN, 5G/4G (NAS, RRC), Industrial Protocols (Modbus, DNP3, IEC 61850).
- Thách thức: Stateful, Cryptography (handshake), Performance (throughput), False positives.
- Công cụ: **AFLNet, AFLNwe, StateAFL, Nyx, Boofuzz, Snort/Zeek fuzzing mode**.
6. Fuzzing Web Application (Web Fuzzing)
- Thường gọi là **Dynamic Analysis / DAST** nhưng kỹ thuật fuzzing áp dụng cho: Parameter fuzzing (SQLi, XSS, LFI, RCE), API fuzzing (OpenAPI/Swagger spec), Header fuzzing, File upload fuzzing.
- Công cụ: **wfuzz, ffuf, feroxbuster, dirsearch** (content discovery), **RESTler, Schemathesis, Pynt** (API spec-based fuzzing), **OWASP ZAP Active Scan**, **Burp Suite Intruder/Scanner**.
7. Ưu / Nhược điểm
| Ưu điểm | Nhược điểm |
| Tự động hóa cao, scale tốt | False positives (crash do sanitizer nhưng không exploitable) |
| Tìm được bug sâu, zero-day | Khó fuzzing stateful/crypto (TLS handshake) |
| Không cần source code (black-box) | Path explosion, coverage plateau |
| Tích hợp CI/CD tốt (OSS-Fuzz, ClusterFuzz) | Cần seed corpus tốt, dictionary, grammar |
| Chứng minh được bug (có testcase reproduce) | Tốn tài nguyên CPU/RAM (thường chạy cluster) |
8. Hệ sinh thái Fuzzing hiện đại (2024)
- OSS-Fuzz (Google): Fuzzing miễn phí cho open source (25k+ projects, 10k+ bugs fixed). Dùng ClusterFuzz (backend), libFuzzer/AFL++.
- ClusterFuzz / ClusterFuzzLite: Infra fuzzing tại scale (corpus management, deduplication, bisect, reporting).
- Fuzz Introspector: Phân tích coverage, bottleneck, function reachability để cải thiện fuzzing.
- CIFuzz / oss-fuzz-gen: Tự động sinh fuzz target từ code.
- AI/ML for Fuzzing: LLM sinh seed/testcase, hướng mutation (WhiteFox, Fuzz4All, LLM-AFL).
9. Bắt đầu Fuzzing hôm nay (Quickstart libFuzzer C++)
// fuzz_target.cc
#include
#include
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size > 0 && data[0] == 'F') {
if (size > 1 && data[1] == 'U') {
if (size > 2 && data[2] == 'Z') {
if (size > 3 && data[3] == 'Z') {
// Trigger bug: null pointer deref
*(volatile int*)0 = 0;
}
}
}
}
return 0;
}
Compile: clang++ -fsanitize=fuzzer,address -g fuzz_target.cc -o fuzzer
Chạy: ./fuzzer (sinh corpus trong thư mục, crash lưu file `crash-`).
Tóm lại: Fuzzing là **vũ khí mạnh nhất tìm zero-day memory corruption & logic bug**. Kết hợp **Coverage-guided fuzzing (AFL++/libFuzzer) + Sanitizers (ASAN) + Structure-aware mutation + CI/CD (OSS-Fuzz)** là tiêu chuẩn vàng hiện nay. Mọi tổ chức phát triển phần mềm quan trọng nên đầu tư fuzzing infrastructure.