4 个版本 (2 个重大变更)

使用旧的 Rust 2015

0.3.1 2023年5月9日
0.3.0 2023年1月13日
0.2.0 2022年10月18日
0.1.0 2021年12月8日

#174 in 测试

Download history 551/week @ 2024-03-09 679/week @ 2024-03-16 389/week @ 2024-03-23 443/week @ 2024-03-30 828/week @ 2024-04-06 1139/week @ 2024-04-13 1264/week @ 2024-04-20 686/week @ 2024-04-27 477/week @ 2024-05-04 1124/week @ 2024-05-11 626/week @ 2024-05-18 502/week @ 2024-05-25 226/week @ 2024-06-01 3/week @ 2024-06-08 27/week @ 2024-06-15 7/week @ 2024-06-22

每月 289 次下载

AGPL-3.0

97KB
2K SLoC

Nautilus 2.0

Nautilus 是一个基于语法的覆盖率指导模糊器。你可以使用它来提高测试覆盖率并发现更多错误。通过指定半有效输入的语法,Nautilus 能够执行复杂的变异并揭示更多有趣的测试用例。许多这个模糊器背后的想法都在2019年NDSS上发表的论文中有详细记录。

版本 2.0 对这个早期原型进行了许多改进,并且现在与 AFL++ 完全兼容。除了通用可用性改进之外,版本 2.0 还包括许多新特性

  • AFL-Qemu 模式支持
  • 支持使用 Python 指定的语法
  • 支持使用 Python 脚本从结构生成输入的非上下文无关语法
  • 支持指定二进制协议/格式
  • 支持指定基于正则表达式的终端,这些终端不是定向变异的一部分
  • 更好地避免重复生成非常短的输入
  • 代码库的大规模清理
  • 对无效语法的有用错误输出
  • 修复了偶尔导致模糊器死锁的超时代码中的错误

Nautilus 如何工作?

您可以使用类似于 EXPR -> EXPR + EXPREXPR -> NUM 以及 NUM -> 1 这样的规则来指定语法。根据这些规则,fuzzer 构建一棵树。这种内部表示形式允许应用比原始字节更复杂的突变。然后将这棵树转换为实际应用的目标输入。在正常的上下文无关文法中,这个过程很简单:所有叶子节点都进行连接。下面示例中的左树将解析为输入 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

mkdir /tmp/workdir
# all arguments can also be set using the config.ron file
cargo run --release -- -g test_cases/grammar_regex_root.py -o /tmp/workdir -- ./test @@

# or if you want to use QEMU mode:
cargo run /path/to/AFLplusplus/afl-qemu-trace -- ./test_bin @@

示例

在这里,我们使用 Python 生成有效的 XML 类似输入的语法。注意使用了脚本规则以确保打开和关闭标签匹配。

#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_example.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 @@

奖杯

依赖关系

~6–13MB
~159K SLoC