Communitygithub.com

AFL++

AFL++は、より優れたファジングパフォーマンスと高度な機能を備えたAFLのフォークです。C/C++プロジェクトのマルチコアファジングに使用します。

AFL++ とは?

AFL++は、オリジナルのAFLファザーをフォークしたもので、安定性を維持しながら優れたファジング性能と高度な機能を提供します。libFuzzerと比較した主要な利点は、マルチコアでのファジングキャンペーンを安定してサポートしていることであり、大規模なファジングに最適です。C/C++プロジェクト向けに設計されており、ClangまたはGCCでコンパイル可能なプロジェクトであれば利用できます。Docker、Ubuntu/Debianリポジトリ、ソースからのインストールなど複数の方法をサポートし、LTOモード(afl-clang-lto)のようなコンパイルモードを選択することで、最良のパフォーマンスと計装を実現します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/SamuelChien/mega-skills-collection/tree/HEAD/aflpp

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

AFL++ は何をしますか?

AFL++は、オリジナルのAFLファザーをフォークしたもので、安定性を維持しながら優れたファジング性能と高度な機能を提供します。libFuzzerに対する大きな利点は、マルチコアでのファジングキャンペーンを安定してサポートしていることであり、大規模なファジングに最適です。

使用すべき状況

ファザー最適な用途複雑さ
AFL++マルチコアファジング、多様なミューテーション、成熟したプロジェクト中
libFuzzer迅速なセットアップ、シングルスレッド、シンプルなハーネス低
LibAFLカスタムファザー、研究、高度なユースケース高

次の場合にAFL++を選択してください:

  • スループットを最大化するためにマルチコアファジングが必要な場合
  • プロジェクトがClangまたはGCCでコンパイルできる場合
  • 多様なミューテーション戦略と成熟したツールが必要な場合
  • libFuzzerが頭打ちになり、より多くのカバレッジが必要な場合
  • 並列実行がメリットとなる本番コードベースをファジングする場合

クイックスタート

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    // ファザーから提供されたデータでコードを呼び出す
    check_buf((char*)data, size);
    return 0;
}

コンパイルして実行:

# 最初にAFL++ラッパースクリプトをセットアップ(インストールを参照)
./afl++ docker afl-clang-fast++ -DNO_MAIN=1 -O2 -fsanitize=fuzzer harness.cc main.cc -o fuzz
mkdir seeds && echo "aaaa" > seeds/minimal_seed
./afl++ docker afl-fuzz -i seeds -o out -- ./fuzz

インストール

AFL++には、LLVM、Python、Rustを含む多くの依存関係があります。AFL++でのファジングには、最新のDebianまたはUbuntuディストリビューションを使用することをお勧めします。

方法使用すべき状況サポートされるコンパイラ
Ubuntu/Debianリポジトリ最近のUbuntu、基本的な機能のみUbuntu 23.10: Clang 14 & GCC 13Debian 12: Clang 14 & GCC 12
Docker(Docker Hubから)特定のAFL++バージョン、Apple Siliconサポート4.35c時点: Clang 19 & GCC 11
Docker(ソースから)未リリースの機能をテスト、パッチを適用Dockerfileで設定可能
ソースからDockerを避ける、特定のパッチが必要LLVM_CONFIG環境変数で調整可能

Ubuntu/Debian

afl++をインストールする前に、apt-cache show afl++でパッケージのclangバージョン依存関係を確認し、一致するlldバージョン(例:lld-17)をインストールしてください。

apt install afl++ lld-17

Docker(Docker Hubから)

docker pull aflplusplus/aflplusplus:stable

Docker(ソースから)

git clone --depth 1 --branch stable https://github.com/AFLplusplus/AFLplusplus
cd AFLplusplus
docker build -t aflplusplus .

ソースから

Ubuntuのバージョン要件と依存関係については、Dockerfileを参照してください。LLVM_CONFIGを設定してClangバージョン(例:llvm-config-18)を指定します。

ラッパースクリプトのセットアップ

ホストまたはDocker上でAFL++を実行するためのラッパースクリプトを作成します:

cat <<'EOF' > ./afl++
#!/bin/sh
AFL_VERSION="${AFL_VERSION:-"stable"}"
case "$1" in
   host)
        shift
        bash -c "$*"
        ;;
    docker)
        shift
        /usr/bin/env docker run -ti \
            --privileged \
            -v ./:/src \
            --rm \
            --name afl_fuzzing \
            "aflplusplus/aflplusplus:$AFL_VERSION" \
            bash -c "cd /src && bash -c \"$*\""
        ;;
    *)
        echo "使用方法: $0 {host|docker}"
        exit 1
        ;;
esac
EOF
chmod +x ./afl++

セキュリティ警告: afl-system-configおよびafl-persistent-configスクリプトはroot権限を必要とし、OSのセキュリティ機能を無効にします。本番システムや開発環境ではファジングしないでください。代わりに専用のVMを使用してください。

システム設定

毎回の再起動後に実行すると、1秒あたりの実行数が最大15%向上します:

./afl++ <host/docker> afl-system-config

最大のパフォーマンスを得るには、カーネルセキュリティ緩和策を無効にします(grubブートローダが必要、Dockerではサポートされていません):

./afl++ host afl-persistent-config
update-grub
reboot
./afl++ <host/docker> afl-system-config

cat /proc/cmdlineで確認 - 出力にmitigations=offが含まれている必要があります。

ハーネスの作成

ハーネスの構造

AFL++はlibFuzzerスタイルのハーネスをサポートしています:

#include <stdint.h>
#include <stddef.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    // 1. 必要に応じて入力サイズを検証
    if (size < MIN_SIZE || size > MAX_SIZE) return 0;

    // 2. ファズデータでターゲット関数を呼び出す
    target_function(data, size);

    // 3. 0を返す(0以外は将来の使用のために予約)
    return 0;
}

ハーネスのルール

すべきことしてはいけないこと
実行間でグローバル状態をリセットする以前の実行からの状態に依存する
エッジケースを適切に処理する無効な入力で終了する
ハーネスを決定論的に保つ乱数生成器を使用する
割り当てられたメモリを解放するメモリリークを作成する
入力サイズを検証する無制限の入力を処理する

関連項目: 詳細なハーネス作成テクニック、複雑な入力を処理するためのパターン、および高度な戦略については、fuzz-harness-writing テクニックスキルを参照してください。

コンパイル

AFL++は、トレードオフの異なる複数のコンパイルモードを提供します。

コンパイルモードの決定木

コンパイルモードを選択してください:

  • LTOモード (afl-clang-lto): 最高のパフォーマンスと計装。これを最初に試してください。
  • LLVMモード (afl-clang-fast): LTOがコンパイルに失敗した場合のフォールバック。
  • GCCプラグイン (afl-gcc-fast): GCCを必要とするプロジェクト向け。

基本的なコンパイル(LLVMモード)

./afl++ <host/docker> afl-clang-fast++ -DNO_MAIN=1 -O2 -fsanitize=fuzzer harness.cc main.cc -o fuzz

GCCコンパイル

./afl++ <host/docker> afl-g++-fast -DNO_MAIN=1 -O2 -fsanitize=fuzzer harness.cc main.cc -o fuzz

重要: GCCバージョンは、AFL++ GCCプラグインのコンパイルに使用されたバージョンと一致している必要があります。

サニタイザーを使用する場合

./afl++ <host/docker> AFL_USE_ASAN=1 afl-clang-fast++ -DNO_MAIN=1 -O2 -fsanitize=fuzzer harness.cc main.cc -o fuzz

関連項目: 詳細なサニタイザー設定、一般的な問題、および高度なフラグについては、address-sanitizer および undefined-behavior-sanitizer テクニックスキルを参照してください。

ビルドフラグ

-gは必要ありません。AFL++コンパイラによってデフォルトで追加されます。

フラグ目的
-DNO_MAIN=1libFuzzerハーネス使用時にmain関数をスキップ
-O2本番最適化レベル(ファジングに推奨)
-fsanitize=fuzzerlibFuzzer互換モードを有効にし、実行可能ファイルのリンク時にファザーランタイムを追加
-fsanitize=fuzzer-no-linkファザーランタイムをリンクせずに計装(静的ライブラリおよびオブジェクトファイル用)

コーパス管理

初期コーパスの作成

AFL++には少なくとも1つの空でないシードファイルが必要です:

mkdir seeds
echo "aaaa" > seeds/minimal_seed

実際のプロジェクトでは、代表的な入力を収集してください:

  • ファジングするフォーマットのサンプルファイルをダウンロード
  • プロジェクトのテストスイートからテストケースを抽出
  • ファイルフォーマットに最小限の有効な入力を使用

コーパスの最小化

キャンペーン後、コーパスを最小化してユニークなカバレッジのみを保持します:

./afl++ <host/docker> afl-cmin -i out/default/queue -o minimized_corpus -- ./fuzz

関連項目: コーパス作成戦略、辞書、およびシード選択については、fuzzing-corpus テクニックスキルを参照してください。

キャンペーンの実行

基本的な実行

./afl++ <host/docker> afl-fuzz -i seeds -o out -- ./fuzz

環境変数の設定

./afl++ <host/docker> AFL_FAST_CAL=1 afl-fuzz -i seeds -o out -- ./fuzz

出力の解釈

AFL++ UIはリアルタイムのファジング統計情報を表示します:

出力意味
execs/sec実行速度 - 高いほど良い
cycles done完了したキューパスの数
corpus countキュー内のユニークなテストケースの数
saved crashes見つかったユニークなクラッシュの数
stability安定したエッジの割合(100%に近い必要があります)

出力ディレクトリ構造

out/default/
├── cmdline          # SUTはどのように呼び出されたか?
├── crashes/         # SUTをクラッシュさせる入力
│   └── id:000000,sig:06,src:000002,time:286,execs:13105,op:havoc,rep:4
├── hangs/           # SUTをハングさせる入力
├── queue/           # 最終的なファザー状態を再現するテストケース
│   ├── id:000000,time:0,execs:0,orig:minimal_seed
│   └── id:000001,src:000000,time:0,execs:8,op:havoc,rep:6,+cov
├── fuzzer_stats     # キャンペーン統計
└── plot_data        # プロット用データ

結果の分析

ライブキャンペーン統計を表示:

./afl++ <host/docker> afl-whatsup out

カバレッジプロットを作成:

apt install gnuplot
./afl++ <host/docker> afl-plot out/default out_graph/

テストケースの再実行

./afl++ <host/docker> ./fuzz out/default/crashes/<test_case>

ファザーオプション

オプション目的
-G 4000最大テスト入力長(デフォルト:1048576バイト)
-t 1000各テストケースのタイムアウト(ミリ秒)(デフォルト:1000ms)
-m 1000メモリ制限(メガバイト)(デフォルト:0 = 無制限)
-x ./dict.dictミューテーションをガイドする辞書ファイルを使用

マルチコアファジング

AFL++はマルチコアファジングに優れており、2つの大きな利点があります:

  1. 1秒あたりの実行数が多い(物理コアに比例して拡大)
  2. 非対称ファジング(例:1つのASanジョブ、残りはサニタイザーなし)

キャンペーンの開始

プライマリファザーを開始(バックグラウンド):

./afl++ <host/docker> afl-fuzz -M primary -i seeds -o state -- ./fuzz 1>primary.log 2>primary.error &

セカンダリファザーを開始(コアと同じ数だけ):

./afl++ <host/docker> afl-fuzz -S secondary01 -i seeds -o state -- ./fuzz 1>secondary01.log 2>secondary01.error &
./afl++ <host/docker> afl-fuzz -S secondary02 -i seeds -o state -- ./fuzz 1>secondary02.log 2>secondary02.error &

マルチコアキャンペーンの監視

実行中のすべてのジョブを一覧表示:

jobs

ライブ統計を表示(毎秒更新):

./afl++ <host/docker> watch -n1 --color afl-whatsup state/

すべてのファザーの停止

kill $(jobs -p)

カバレッジ分析

AFL++はエッジ計装を通じて自動的にカバレッジを追跡します。カバレッジ情報はfuzzer_statsとplot_dataに保存されます。

カバレッジの測定

afl-plotを使用して経時的なカバレッジを可視化:

./afl++ <host/docker> afl-plot out/default out_graph/

カバレッジの改善

  • フォーマットを認識したファジングのために辞書を使用
  • より長いキャンペーンを実行(cycles_wo_findsはプラトーを示す)
  • マルチコアファジングで異なるミューテーション戦略を試す
  • カバレッジのギャップを分析し、ターゲットを絞ったシード入力を追加

関連項目: 詳細なカバレッジ分析テクニック、カバレッジギャップの特定、および体系的なカバレッジ改善については、coverage-analysis テクニックスキルを参照してください。

CMPLOG

CMPLOG/RedQueenは、あらゆるファザーで利用可能な最良のパス制約解決メカニズムです。 これを有効にするには、ファズターゲットをそれ用に計装する必要があります。 ファジングターゲットをビルドする前に、環境変数を設定します:

./afl++ <host/docker> AFL_LLVM_CMPLOG=1 make

ハーネスのコンパイルとリンクには特別なアクションは必要ありません。

CMPLOGで計装されたファジングターゲットでファザーインスタンスを実行するには、コマンドライン引数に-c0を追加します:

./afl++ <host/docker> afl-fuzz -c0 -S cmplog -i seeds -o state -- ./fuzz 1>secondary02.log 2>secondary02.error &

サニタイザー統合

サニタイザーは、即座にクラッシュを引き起こさないメモリ破壊バグを見つけるために不可欠です。

AddressSanitizer(ASan)

./afl++ <host/docker> AFL_USE_ASAN=1 afl-clang-fast++ -DNO_MAIN=1 -O2 -fsanitize=fuzzer harness.cc main.cc -o fuzz

注意: 20TBの仮想メモリ予約のため、ASanではメモリ制限(-m)はサポートされていません。

UndefinedBehaviorSanitizer(UBSan)

./afl++ <host/docker> AFL_USE_UBSAN=1 afl-clang-fast++ -DNO_MAIN=1 -O2 -fsanitize=fuzzer,undefined harness.cc main.cc -o fuzz

一般的なサニタイザーの問題

問題解決策
ASanがファジングを遅くするマルチコア設定で1つのASanジョブのみを使用
スタックの枯渇ASAN_OPTIONS=stack_size=...でスタックを増やす
GCCバージョンの不一致システムGCCがAFL++プラグインバージョンと一致することを確認

関連項目: 包括的なサニタイザー設定とトラブルシューティングについては、address-sanitizer テクニックスキルを参照してください。

高度な使用法

ヒントとコツ

ヒントなぜ役立つか
可能な場合はLLVMFuzzerTestOneInputハーネスを使用ファジングキャンペーンの安定性が少なくとも85%あれば、これが最も効率的なファジングスタイルです。そうでない場合は、標準入力またはファイル入力ファジングを試してください
辞書を使用ファザーがフォーマット固有のキーワードとマジックバイトを発見するのに役立ちます
現実的なタイムアウトを設定システム負荷による誤検出を防ぎます
入力サイズを制限大きな入力が必ずしもより多くのスペースを探索するとは限りません
安定性を監視低い安定性は非決定論的な動作を示します

標準入力ファジング

AFL++は、libFuzzerハーネスなしでstdinから読み取るプログラムをファジングできます:

./afl++ <host/docker> afl-clang-fast++ -O2 main_stdin.c -o fuzz_stdin
./afl++ <host/docker> afl-fuzz -i seeds -o out -- ./fuzz_stdin

これは永続モードより低速ですが、ハーネスコードは必要ありません。

ファイル入力ファジング

ファイルを読み取るプログラムの場合は、@@プレースホルダーを使用します:

./afl++ <host/docker> afl-clang-fast++ -O2 main_file.c -o fuzz_file
./afl++ <host/docker> afl-fuzz -i seeds -o out -- ./fuzz_file @@

パフォーマンスを向上させるには、fmemopenを使用してメモリからファイル記述子を作成します。

引数ファジング

argv-fuzz-inl.hを使用してコマンドライン引数をファジングします:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __AFL_COMPILER
#include "argv-fuzz-inl.h"
#endif

void check_buf(char *buf, size_t buf_len) {
    if(buf_len > 0 && buf[0] == 'a') {
        if(buf_len > 1 && buf[1] == 'b') {
            if(buf_len > 2 && buf[2] == 'c') {
                abort();
            }


…

[翻訳のために切り詰められました]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

SamuelChien/mega-skills-collection

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

SamuelChien/mega-skills-collection

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

SamuelChien/mega-skills-collection

Ingeniero de Sistemas de Andru.ia. Diseña, redacta y despliega nuevas habilidades (skills) dentro del repositorio siguiendo el Estándar de Diamante.

SamuelChien/mega-skills-collection

Estratega de Inteligencia de Dominio de Andru.ia. Analiza el nicho específico de un proyecto para inyectar conocimientos, regulaciones y estándares únicos del sector. Actívalo tras definir el nicho.

SamuelChien/mega-skills-collection

2D game development principles. Sprites, tilemaps, physics, camera.

SamuelChien/mega-skills-collection

3D game development principles. Rendering, shaders, physics, cameras.

SamuelChien/mega-skills-collection

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

SamuelChien/mega-skills-collection

Accessibility audit skill for scanning, fixing, and verifying WCAG 2.2 Level A and AA compliance across React, Next.js, Vue, Angular, Svelte, and plain HTML codebases. Use when auditing accessibility, fixing a11y violations, checking color contrast, generating compliance reports, or integrating accessibility checks into CI/CD pipelines.

SamuelChien/mega-skills-collection

Ab Test Analyzer - Auto-activating skill for Data Analytics. Triggers on: ab test analyzer, ab test analyzer Part of the Data Analytics skill category.

SamuelChien/mega-skills-collection

A B Test Config Creator - Auto-activating skill for ML Deployment. Triggers on: a b test config creator, a b test config creator Part of the ML Deployment skill category.

SamuelChien/mega-skills-collection

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "conversion experiment," "statistical significance," or "test this." For tracking implementation, see analytics-tracking.

SamuelChien/mega-skills-collection

Acceptance Criteria Creator - Auto-activating skill for Enterprise Workflows. Triggers on: acceptance criteria creator, acceptance criteria creator Part of the Enterprise Workflows skill category.

SamuelChien/mega-skills-collection

Use when a coding task should be driven end-to-end from issue intake through implementation, review, deployment, and acceptance verification with minimal human re-intervention.

SamuelChien/mega-skills-collection

Accessibility Audit Runner - Auto-activating skill for Frontend Development. Triggers on: accessibility audit runner, accessibility audit runner Part of the Frontend Development skill category.

SamuelChien/mega-skills-collection

You are an accessibility expert specializing in WCAG compliance, inclusive design, and assistive technology compatibility. Conduct audits, identify barriers, and provide remediation guidance.

SamuelChien/mega-skills-collection

Web accessibility patterns for WCAG 2.2 compliance including ARIA, keyboard navigation, screen readers, and testing

SamuelChien/mega-skills-collection

Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Discord channel.

SamuelChien/mega-skills-collection

Create unified specification packages across Business, Development, and Design teams. Staged elaboration (L0 Vision → L1 Requirements → L2 Team Detail → L3 Acceptance Criteria) to build shared understanding. Does not write code.

SamuelChien/mega-skills-collection

Research a company or person and get actionable sales intel. Works standalone with web search, supercharged when you connect enrichment tools or your CRM. Trigger with "research [company]", "look up [person]", "intel on [prospect]", "who is [name] at [company]", or "tell me about [company]".

SamuelChien/mega-skills-collection

Validate messaging consistency across website, GitHub repos, and local documentation generating read-only discrepancy reports. Use when checking content alignment or finding mixed messaging. Trigger with phrases like "check consistency", "validate documentation", or "audit messaging".

関連スキル