Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问clear审计通过

fuzzing-obstacles模糊障碍

Agent Skill

fuzzing-obstacles 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

47,520

周安装

1,952

GitHub Stars

4,874

下载量

16,640
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:fuzzing-obstacles(模糊障碍)
来源仓库:https://github.com/trailofbits/skills
仓库路径:skills/fuzzing-obstacles
安装命令:
npx skills add https://github.com/trailofbits/skills --skill fuzzing-obstacles
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/trailofbits/skills --skill fuzzing-obstacles

简介

修补代码以绕过校验和、全局状态以及阻碍模糊器进展的验证障碍。

  • 使用条件编译(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  • 在 C/C++ 中,cfg!(模糊测试)
  • 在 Rust 中)在模糊测试构建过程中跳过障碍,同时保留生产行为
  • 常见的障碍包括校验和验证、非确定性 PRNG、基于时间的种子以及阻止模糊器探索更深层次代码路径的复杂验证
  • 通过覆盖率分析识别无法访问的代码,一次修补一个障碍,并测量覆盖率的改进,从而逐步应用
  • 通过检查下游代码是否依赖于跳过验证所做的假设来评估误报风险;必要时使用防御性默认设置

SKILL.md

Overcoming Fuzzing Obstacles

Codebases often contain anti-fuzzing patterns that prevent effective coverage. Checksums, global state (like time-seeded PRNGs), and validation checks can block the fuzzer from exploring deeper code paths. This technique shows how to patch your System Under Test (SUT) to bypass these obstacles during fuzzing while preserving production behavior.

Overview

Many real-world programs were not designed with fuzzing in mind. They may:

  • Verify checksums or cryptographic hashes before processing input
  • Rely on global state (e.g., system time, environment variables)
  • Use non-deterministic random number generators
  • Perform complex validation that makes it difficult for the fuzzer to generate valid inputs

These patterns make fuzzing difficult because:

  1. Checksums: The fuzzer must guess correct hash values (astronomically unlikely)
  2. Global state: Same input produces different behavior across runs (breaks determinism)
  3. Complex validation: The fuzzer spends effort hitting validation failures instead of exploring deeper code

The solution is conditional compilation: modify code behavior during fuzzing builds while keeping production code unchanged.

Key Concepts

ConceptDescription
SUT PatchingModifying System Under Test to be fuzzing-friendly
Conditional CompilationCode that behaves differently based on compile-time flags
Fuzzing Build ModeSpecial build configuration that enables fuzzing-specific patches
False PositivesCrashes found during fuzzing that cannot occur in production
DeterminismSame input always produces same behavior (critical for fuzzing)

When to Apply

Apply this technique when:

  • The fuzzer gets stuck at checksum or hash verification
  • Coverage reports show large blocks of unreachable code behind validation
  • Code uses time-based seeds or other non-deterministic global state
  • Complex validation makes it nearly impossible to generate valid inputs
  • You see the fuzzer repeatedly hitting the same validation failures

Skip this technique when:

  • The obstacle can be overcome with a good seed corpus or dictionary
  • The validation is simple enough for the fuzzer to learn (e.g., magic bytes)
  • You're doing grammar-based or structure-aware fuzzing that handles validation
  • Skipping the check would introduce too many false positives
  • The code is already fuzzing-friendly

Quick Reference

TaskC/C++Rust
Check if fuzzing build#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTIONcfg!(fuzzing)
Skip check during fuzzing#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION return -1; #endifif!cfg!(fuzzing) {return Err(...)}
Common obstaclesChecksums, PRNGs, time-based logicChecksums, PRNGs, time-based logic
Supported fuzzerslibFuzzer, AFL++, LibAFL, honggfuzzcargo-fuzz, libFuzzer

Step-by-Step

Step 1: Identify the Obstacle

Run the fuzzer and analyze coverage to find code that's unreachable. Common patterns:

  1. Look for checksum/hash verification before deeper processing
  2. Check for calls to rand(), time(), or srand() with system seeds
  3. Find validation functions that reject most inputs
  4. Identify global state initialization that differs across runs

Tools to help:

  • Coverage reports (see coverage-analysis technique)
  • Profiling with -fprofile-instr-generate
  • Manual code inspection of entry points

Step 2: Add Conditional Compilation

Modify the obstacle to bypass it during fuzzing builds.

C/C++ Example:

// Before: Hard obstacle
if (checksum != expected_hash) {
    return -1;  // Fuzzer never gets past here
}

// After: Conditional bypass
if (checksum != expected_hash) {
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    return -1;  // Only enforced in production
#endif
}
// Fuzzer can now explore code beyond this check

Rust Example:

// Before: Hard obstacle
if checksum != expected_hash {
    return Err(MyError::Hash);  // Fuzzer never gets past here
}

// After: Conditional bypass
if checksum != expected_hash {
    if !cfg!(fuzzing) {
        return Err(MyError::Hash);  // Only enforced in production
    }
}
// Fuzzer can now explore code beyond this check

Step 3: Verify Coverage Improvement

After patching:

  1. Rebuild with fuzzing instrumentation
  2. Run the fuzzer for a short time
  3. Compare coverage to the unpatched version
  4. Confirm new code paths are being explored

Step 4: Assess False Positive Risk

Consider whether skipping the check introduces impossible program states:

  • Does code after the check assume validated properties?
  • Could skipping validation cause crashes that cannot occur in production?
  • Is there implicit state dependency?

If false positives are likely, consider a more targeted patch (see Common Patterns below).

Common Patterns

Pattern: Bypass Checksum Validation

Use Case: Hash/checksum blocks all fuzzer progress

Before:

uint32_t computed = hash_function(data, size);
if (computed != expected_checksum) {
    return ERROR_INVALID_HASH;
}
process_data(data, size);

After:

uint32_t computed = hash_function(data, size);
if (computed != expected_checksum) {
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    return ERROR_INVALID_HASH;
#endif
}
process_data(data, size);

False positive risk: LOW - If data processing doesn't depend on checksum correctness

Pattern: Deterministic PRNG Seeding

Use Case: Non-deterministic random state prevents reproducibility

Before:

void initialize() {
    srand(time(NULL));  // Different seed each run
}

After:

void initialize() {
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    srand(12345);  // Fixed seed for fuzzing
#else
    srand(time(NULL));
#endif
}

False positive risk: LOW - Fuzzer can explore all code paths with fixed seed

Pattern: Careful Validation Skip

Use Case: Validation must be skipped but downstream code has assumptions

Before (Dangerous):

#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (!validate_config(&config)) {
    return -1;  // Ensures config.x != 0
}
#endif

int32_t result = 100 / config.x;  // CRASH: Division by zero in fuzzing!

After (Safe):

#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (!validate_config(&config)) {
    return -1;
}
#else
// During fuzzing, use safe defaults for failed validation
if (!validate_config(&config)) {
    config.x = 1;  // Prevent division by zero
    config.y = 1;
}
#endif

int32_t result = 100 / config.x;  // Safe in both builds

False positive risk: MITIGATED - Provides safe defaults instead of skipping

Pattern: Bypass Complex Format Validation

Use Case: Multi-step validation makes valid input generation nearly impossible

Rust Example:

// Before: Multiple validation stages
pub fn parse_message(data: &[u8]) -> Result<Message, Error> {
    validate_magic_bytes(data)?;
    validate_structure(data)?;
    validate_checksums(data)?;
    validate_crypto_signature(data)?;

    deserialize_message(data)
}

// After: Skip expensive validation during fuzzing
pub fn parse_message(data: &[u8]) -> Result<Message, Error> {
    validate_magic_bytes(data)?;  // Keep cheap checks

    if !cfg!(fuzzing) {
        validate_structure(data)?;
        validate_checksums(data)?;
        validate_crypto_signature(data)?;
    }

    deserialize_message(data)
}

False positive risk: MEDIUM - Deserialization must handle malformed data gracefully

Advanced Usage

Tips and Tricks

TipWhy It Helps
Keep cheap validationMagic bytes and size checks guide fuzzer without much cost
Use fixed seeds for PRNGsMakes behavior deterministic while exploring all code paths
Patch incrementallySkip one obstacle at a time and measure coverage impact
Add defensive defaultsWhen skipping validation, provide safe fallback values
Document all patchesFuture maintainers need to understand fuzzing vs. production differences

Real-World Examples

OpenSSL: Uses FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to modify cryptographic algorithm behavior. For example, in crypto/cmp/cmp_vfy.c, certain signature checks are relaxed during fuzzing to allow deeper exploration of certificate validation logic.

ogg crate (Rust): Uses cfg!(fuzzing) to skip checksum verification during fuzzing. This allows the fuzzer to explore audio processing code without spending effort guessing correct checksums.

Measuring Patch Effectiveness

After applying patches, quantify the improvement:

  1. Line coverage: Use llvm-cov or cargo-cov to see new reachable lines
  2. Basic block coverage: More fine-grained than line coverage
  3. Function coverage: How many more functions are now reachable?
  4. Corpus size: Does the fuzzer generate more diverse inputs?

Effective patches typically increase coverage by 10-50% or more.

Combining with Other Techniques

Obstacle patching works well with:

  • Corpus seeding: Provide valid inputs that get past initial parsing
  • Dictionaries: Help fuzzer learn magic bytes and common values
  • Structure-aware fuzzing: Use protobuf or grammar definitions for complex formats
  • Harness improvements: Better harness can sometimes avoid obstacles entirely

Anti-Patterns

Anti-PatternProblemCorrect Approach
Skip all validation wholesaleCreates false positives and unstable fuzzingSkip only specific obstacles that block coverage
No risk assessmentFalse positives waste time and hide real bugsAnalyze downstream code for assumptions
Forget to document patchesFuture maintainers don't understand the differencesAdd comments explaining why patch is safe
Patch without measuringDon't know if it helpedCompare coverage before and after
Over-patchingMakes fuzzing build diverge too much from productionMinimize differences between builds

Tool-Specific Guidance

libFuzzer

libFuzzer automatically defines FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION during compilation.

# C++ compilation
clang++ -g -fsanitize=fuzzer,address -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
    harness.cc target.cc -o fuzzer

# The macro is usually defined automatically by -fsanitize=fuzzer
clang++ -g -fsanitize=fuzzer,address harness.cc target.cc -o fuzzer

Integration tips:

  • The macro is defined automatically; manual definition is usually unnecessary
  • Use #ifdef to check for the macro
  • Combine with sanitizers to detect bugs in newly reachable code

AFL++

AFL++ also defines FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION when using its compiler wrappers.

# Compilation with AFL++ wrappers
afl-clang-fast++ -g -fsanitize=address target.cc harness.cc -o fuzzer

# The macro is defined automatically by afl-clang-fast

Integration tips:

  • Use afl-clang-fast or afl-clang-lto for automatic macro definition
  • Persistent mode harnesses benefit most from obstacle patching
  • Consider using AFL_LLVM_LAF_ALL for additional input-to-state transformations

honggfuzz

honggfuzz also supports the macro when building targets.

# Compilation
hfuzz-clang++ -g -fsanitize=address target.cc harness.cc -o fuzzer

Integration tips:

  • Use hfuzz-clang or hfuzz-clang++ wrappers
  • The macro is available for conditional compilation
  • Combine with honggfuzz's feedback-driven fuzzing

cargo-fuzz (Rust)

cargo-fuzz automatically sets the fuzzing cfg option during builds.

# Build fuzz target (cfg!(fuzzing) is automatically set)
cargo fuzz build fuzz_target_name

# Run fuzz target
cargo fuzz run fuzz_target_name

Integration tips:

  • Use cfg!(fuzzing) for runtime checks in production builds
  • Use #[cfg(fuzzing)] for compile-time conditional compilation
  • The fuzzing cfg is only set during cargo fuzz builds, not regular cargo build
  • Can be manually enabled with RUSTFLAGS="--cfg fuzzing" for testing

LibAFL

LibAFL supports the C/C++ macro for targets written in C/C++.

# Compilation
clang++ -g -fsanitize=address -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
    target.cc -c -o target.o

Integration tips:

  • Define the macro manually or use compiler flags
  • Works the same as with libFuzzer
  • Useful when building custom LibAFL-based fuzzers

Troubleshooting

IssueCauseSolution
Coverage doesn't improve after patchingWrong obstacle identifiedProfile execution to find actual bottleneck
Many false positive crashesDownstream code has assumptionsAdd defensive defaults or partial validation
Code compiles differentlyMacro not defined in all build configsVerify macro in all source files and dependencies
Fuzzer finds bugs in patched codePatch introduced invalid statesReview patch for state invariants; consider safer approach
Can't reproduce production bugsBuild differences too largeMinimize patches; keep validation for state-critical checks

Related Skills

Tools That Use This Technique

SkillHow It Applies
libfuzzerDefines FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION automatically
aflppSupports the macro via compiler wrappers
honggfuzzUses the macro for conditional compilation
cargo-fuzzSets cfg!(fuzzing) for Rust conditional compilation

Related Techniques

SkillRelationship
fuzz-harness-writingBetter harnesses may avoid obstacles; patching enables deeper exploration
coverage-analysisUse coverage to identify obstacles and measure patch effectiveness
corpus-seedingSeed corpus can help overcome obstacles without patching
dictionary-generationDictionaries help with magic bytes but not checksums or complex validation

Resources

Key External Resources

OpenSSL Fuzzing Documentation OpenSSL's fuzzing infrastructure demonstrates large-scale use of FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. The project uses this macro to modify cryptographic validation, certificate parsing, and other security-critical code paths to enable deeper fuzzing while maintaining production correctness.

LibFuzzer Documentation on Flags Official LLVM documentation for libFuzzer, including how the fuzzer defines compiler macros and how to use them effectively. Covers integration with sanitizers and coverage instrumentation.

Rust cfg Attribute Reference Complete reference for Rust conditional compilation, including cfg!(fuzzing) and cfg!(test). Explains compile-time vs. runtime conditional compilation and best practices.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

30.59%
按下载量换算5,090

Codex

22.91%
按下载量换算3,812

OpenCode

17.24%
按下载量换算2,869

Gemini CLI

12.37%
按下载量换算2,058

Antigravity

6.68%
按下载量换算1,112

Cursor

3.34%
按下载量换算556

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills