Nautilusはカバレッジガイド型の文法ベースのファザーです。テストカバレッジを向上させ、より多くのバグを見つけるために使用できます。半有効な入力の文法を指定することで、Nautilusは複雑な突然変異を実行し、より興味深いテストケースを発見することができます。このファザーの背後にある多くのアイデアは、NDSS 2019で発表された論文に文書化されています。
バージョン2.0では、この初期プロトタイプに多くの改良が加えられ、AFL++と100%互換性を持つようになりました。一般的な使いやすさの改善に加えて、バージョン2.0には多数の輝く新機能が含まれています:
EXPR -> EXPR + EXPR や EXPR -> NUM、NUM -> 1 のようなルールを使って文法を指定します。これらのルールから、ファザーはツリーを構築します。この内部表現により、生のバイトよりもはるかに複雑な突然変異を適用できます。このツリーはその後、ターゲットアプリケーションの実際の入力に変換されます。通常の文脈自由文法では、このプロセスは簡単です: すべての葉が連結されます。以下の例の左のツリーは入力 a=1+2 に解析され、右のツリーは a=1+1+1+2 になります。文法の表現力を高めるために、Nautilusを使用すると、アンパースプロセスにPython関数を提供して、より複雑な指定を可能にすることができます。
# checkout the git
git clone '[email protected]:nautilus-fuzz/nautilus.git'
cd nautilus
/path/to/AFLplusplus/afl-clang-fast test.c -o test #afl-clang-fast as provided by AFL
# all arguments can also be set using the config.ron file
cargo run --release -- -g grammars/grammar_py_example.py -o /tmp/workdir -- ./test @@
# or if you want to use QEMU mode:
cargo run /path/to/AFLplusplus/afl-qemu-trace -- ./test_bin @@
ここでは、有効なXMLライクな入力のための文法を生成するためにPythonを使用します。開始タグと終了タグが一致することを保証するためにスクリプトルールを使用していることに注意してください。
#ctx.rule(NONTERM: string, RHS: string|bytes) adds a rule NONTERM->RHS. We can use {NONTERM} in the RHS to request a recursion.
ctx.rule("START","<document>{XML_CONTENT}</document>")
ctx.rule("XML_CONTENT","{XML}{XML_CONTENT}")
ctx.rule("XML_CONTENT","")
#ctx.script(NONTERM:string, RHS: [string]], func) adds a rule NONTERM->func(*RHS).
# In contrast to normal `rule`, RHS is an array of nonterminals.
# It's up to the function to combine the values returned for the NONTERMINALS with any fixed content used.
ctx.script("XML",["TAG","ATTR","XML_CONTENT"], lambda tag,attr,body: b"<%s %s>%s</%s>"%(tag,attr,body,tag) )
ctx.rule("ATTR","foo=bar")
ctx.rule("TAG","some_tag")
ctx.rule("TAG","other_tag")
#sometimes we don't want to explore the set of possible inputs in more detail. For example, if we fuzz a script
#interpreter, we don't want to spend time on fuzzing all different variable names. In such cases we can use Regex
#terminals. Regex terminals are only mutated during generation, but not during normal mutation stages, saving a lot of time.
#The fuzzer still explores different values for the regex, but it won't be able to learn interesting values incrementally.
#Use this when incremantal exploration would most likely waste time.
ctx.regex("TAG","[a-z]+")
文法をテストするには、ジェネレータを使用できます:
$ cargo run --bin generator -- -g grammars/grammar_py_exmaple.py -t 100
<document><some_tag foo=bar><other_tag foo=bar><other_tag foo=bar><some_tag foo=bar></some_tag></other_tag><some_tag foo=bar><other_tag foo=bar></other_tag></some_tag><other_tag foo=bar></other_tag><some_tag foo=bar></some_tag></other_tag><other_tag foo=bar></other_tag><some_tag foo=bar></some_tag></some_tag></document>
NautilusをAFLと組み合わせて使用することもできます。AFLの-oを同じ作業ディレクトリに指定するだけで、AFLはNautilusと同期します。これは一方向であることに注意してください。AFLはNautilusの入力をインポートしますが、その逆はありません。
#Terminal/Screen 1
./afl-fuzz -Safl -i /tmp/seeds -o /tmp/workdir/ ./test @@
#Terminal/Screen 2
cargo run --release -- -o /tmp/workdir -- ./test @@