Fuzzing (Fuzz Testing) คืออะไร?
Fuzzing หรือ Fuzz Testing เป็นเทคนิคการทดสอบซอฟต์แวร์แบบ Black Box ที่ส่งข้อมูลนำเข้า (Input) ที่ สุ่ม (Random), ผิดปกติ (Malformed), ไม่คาดคิด (Unexpected), ขนาดใหญ่เกินไป, หรือมีโครงสร้างผิด เข้าไปในโปรแกรมเป้าหมาย เพื่อให้เกิด Crash, Hang, Memory Leak, Buffer Overflow, Assertion Failure, หรือ Undefined Behavior ซึ่งบ่งชี้ถึง Bug หรือช่องโหว่ด้านความปลอดภัย
หลักการทำงานของ Fuzzer
- Target Identification: ระบุ Target (Binary, Library, API, Protocol, File Format, Kernel Syscall)
- Input Generation: สร้าง Test Cases (Mutational / Generational)
- Execution: รัน Target ด้วย Input ที่สร้าง (มักใน Sandbox/VM/Container)
- Monitoring: ตรวจสอบ Crash, Sanitizer Alert (ASAN, MSAN, TSAN, UBSAN), Timeout, Exit Code
- Crash Triage: Deduplicate, Minimize (Delta Debugging), Root Cause Analysis
- Reporting: Bug Report พร้อม PoC, Stack Trace, Impact Assessment
ประเภทของ Fuzzing
| ประเภท | คำอธิบาย | ตัวอย่าง Tools |
|---|---|---|
| Black-box Fuzzing | ไม่รู้ Source Code / Internal Structure ส่ง Input ผ่าน Interface (Network, File, API) | AFL (no source), Peach, Boofuzz, Sulley |
| White-box Fuzzing | รู้ Source Code ใช้ Static Analysis / Symbolic Execution นำทาง (Directed/Concolic) | KLEE, SAGE, Driller, SymCC, Fuzzolic |
| Grey-box Fuzzing | มี Instrumentation (Coverage Feedback) แต่ไม่จำเป็นต้องมี Source (Compile-time Instrumentation) | AFL++, libFuzzer, Honggfuzz, WinAFL |
| Structure-aware / Grammar-based | Input ต้องมีโครงสร้าง (JSON, XML, Protobuf, HTTP, TLS) ใช้ Grammar/Spec | NAUTILUS, Superion, Protobuf Fuzzer, Domato |
| Protocol/Network Fuzzing | Fuzzing Network Protocols (TCP, UDP, HTTP, DNS, TLS, DHCP, SIP, RDP, SMB) | Boofuzz, Peach, AFLNet, AFLNWE, NYX, Snipuzz |
| Kernel Fuzzing | Fuzzing OS Kernel (Syscalls, IOCTL, File Systems, Drivers) | Syzkaller, Trinity, KAFL, Moonshine |
| Hardware/Firmware Fuzzing | Fuzzing Firmware, Baseband, Bluetooth, USB, PCIe | FirmAFL, ICE, μAFL, HALucinator |
Coverage-guided Fuzzing (Modern Standard)
ใช้ Code Coverage Feedback (Edge Coverage) นำทางการ Mutate Input → หา Path ใหม่เร็วขึ้น → หา Bug ลึกได้มากขึ้น
- AFL++ (American Fuzzy Lop++): King of Fuzzers, GCC/Clang Instrumentation, QEMU Mode (Binary-only), Persistent Mode, Structure-aware (libprotobuf-mutator)
- libFuzzer: In-process, Clang-based, Integrated with LLVM, เร็วมากสำหรับ Library/API
- Honggfuzz: Linux/BSD, Hardware Feedback (Intel PT), Persistent Mode, .NET/Java Support
Sanitizers (Bug Detectors ร่วมกับ Fuzzing)
| Sanitizer | Detects | Compiler Flag |
|---|---|---|
| ASAN (AddressSanitizer) | Buffer Overflow, Use-after-free, Double-free, Stack-use-after-return | -fsanitize=address |
| MSAN (MemorySanitizer) | Uninitialized Memory Reads | -fsanitize=memory |
| TSAN (ThreadSanitizer) | Data Races, Deadlocks | -fsanitize=thread |
| UBSAN (UndefinedBehaviorSanitizer) | Undefined Behavior (Integer Overflow, Null Ptr, Shift, Alignment) | -fsanitize=undefined |
Network Protocol Fuzzing (เฉพาะ Network Security)
- Boofuzz: Python-based, Successor of Sulley, Stateful Protocol Fuzzing, รองรับ TCP/UDP/SSL/Serial
- Peach Fuzzer / Pitfall: Data Model + State Model, XML Definition, Commercial/Community
- AFLNet / AFLNWE: AFL++ Adapted สำหรับ Network Protocols (Stateful, Response-guided)
- Snipuzz: Black-box Network Fuzzing ใช้ Side-channel (Timing, Error Pages)
- WiFuzzit: IEEE 802.11 Wi-Fi Fuzzing (AP & Station)
ข้อดีของ Fuzzing
- หา Bug ที่ Unit Test / Static Analysis หาไม่เจอ (Deep State, Complex Input)
- Automation สูง รันได้ 24/7
- ไม่ต้องรู้ Source Code (Black/Grey-box)
- หา Zero-day / 1-day Vulnerabilities ได้จริง (Heartbleed, Shellshock, ImageMagick, Chrome/Edge RCE)
- Regression Testing: กัน Bug กลับมา
ข้อจำกัดและความท้าทาย
- False Positives: Crash ที่ไม่ใช่ Security Impact (ต้อง Triage)
- Path Explosion: State Space ใหญ่เกินไป (ต้อง Grammar/Seeds/Guided)
- Seed Quality: Seed Corpus ดี = ผลลัพธ์ดี (Collect Seeds จาก Real Traffic, Specs, Repos)
- Performance: ต้องการ CPU/RAM มาก (Parallelize, Persistent Mode, Cloud)
- Complex Protocols: TLS, Stateful Protocols ยาก (ต้อง State Model)
Fuzzing Workflow เริ่มต้น (Getting Started)
# 1. Install AFL++
git clone https://github.com/AFLplusplus/AFLplusplus
cd AFLplusplus && make && sudo make install
# 2. Compile Target with Instrumentation
CC=afl-clang-fast CXX=afl-clang-fast++ ./configure --disable-shared
make clean all
# 3. Prepare Seeds
mkdir seeds
echo "test" > seeds/test.txt
# หรือดึงจาก real samples
# 4. Run Fuzzing
afl-fuzz -i seeds -o output -- ./target_binary @@
# 5. Monitor & Triage Crashes
ls output/default/crashes/
# ใช้ afl-tmin เพื่อ minimize test case
# ใช้ gdb/lldb เพื่อ debug
Fuzzing ใน SDLC (Shift Left)
- Developer: libFuzzer Unit Tests (OSS-Fuzz Style)
- CI/CD: Nightly Fuzzing Jobs (ClusterFuzz, OSS-Fuzz, GitHub Actions + AFL++)
- Release: Pre-release Fuzzing Campaign
- Post-release: Continuous Fuzzing, Regression
สรุป
Fuzzing เป็นเทคนิค Automated Vulnerability Discovery ที่ทรงพลังที่สุดในปัจจุบัน สำหรับ Network Security เน้นที่ Protocol Fuzzing (Boofuzz, AFLNet) และ File Format Parsing (AFL++ + libprotobuf-mutator) การรวม Coverage-guided Fuzzing + Sanitizers + Good Seeds + CI/CD Integration คือสูตรสำเร็จ