使用libFuzzer fuzz Chrome V8入门指南

本文讲的是 使用libFuzzer fuzz Chrome V8入门指南

什么是V8? 

V8(也称为Chrome V8)是由Chromium Project开发的用于Google Chrome浏览器的开源JavaScript引擎。使用V8的其他项目包括Couchbase,MongoDB和Node.js.等。在本文的帮助下,可能您会对其有更为深入的了解。

众所周知Google做事情总是会有点不一样,所以它不会像./configure && make那么简单。但是一旦您找出正确的过程,这其实真的并不难。因此再次感谢Google给我指出正确的方向。

克隆depot_tools资料库:

m.googlesource.com/chromium/tools/depot_tools.git

添加depot_tools到您的PATH结尾(您可能想把它放在您的~/.bashrc或~/.zshrc)。假设您克隆depot_tools到/path/to/depot_tools:

$ export PATH="$PATH:/path/to/depot_tools"

现在我们得到了我们将要fuzzing的代码,然后创建chromium用于结帐的目录并更改它:

$ mkdir ~/chromium && cd ~/chromium

从depot_tools 上运行工具fetch以查看代码及其依赖关系。

$ fetch --nohooks --no-history chromium

该–no-history选项将加快速度,因为它不会拉下整个git历史,事实上我们并不是真正需要fuzzing。

其余的说明假设您已切换到src目录:

$ cd src

举个例子,我使用的是Ubuntu 16.04 x64,而如果您正在使用Debian,那么这些说明也应该适用于您。否则,您可能需要调整构建依赖关系。

安装附加的构建依赖项。

$ build/install-build-deps.sh

运行钩子

$ gclient runhooks

现在,您已经有了开始构建fuzzing器所需的代码库和工具。对于这个例子,我使用的是libFuzzer而不是AFL。

构建fuzzer

首先,我们将运行这个命令来设置我们的目标:

$ gn gen out/libfuzzer '--args=use_libfuzzer=true is_asan=true is_ubsan_security=true is_debug=false enable_nacl=false' --check

这将使构建得这个系统去使用libFuzzer,ASan和UBSan。当它成功运行时,您将受到类似Done. Made 6168 targets from 1323 files in 9620ms的消息的欢迎。接下来运行gn ls out/libfuzzer | grep fuzzer,您会收到一个包含约519个条目的列表,其中大部分我们不会关心。在这个例子中,我要选一个json解析器,所以让我们来gn ls out/libfuzzer | grep json一下看看弹出的内容:

//components/json_schema:json_schema
//components/json_schema:unit_tests
//components/json_schema:unit_tests_bundle_data
//components/ntp_tiles:json_unsafe_parser
//components/safe_json:safe_json
//components/safe_json:test_support
//components/safe_json:unit_tests
//components/safe_json/public/interfaces:interfaces
//components/safe_json/public/interfaces:interfaces__check_deps_are_all_mojom
//components/safe_json/public/interfaces:interfaces__generator
//components/safe_json/public/interfaces:interfaces__is_mojom
//components/safe_json/public/interfaces:interfaces__type_mappings
//components/safe_json/public/interfaces:interfaces_blink
//components/safe_json/public/interfaces:interfaces_blink__generator
//components/safe_json/public/interfaces:interfaces_blink__type_mappings
//components/safe_json/public/interfaces:interfaces_js
//components/safe_json/public/interfaces:interfaces_js__generator
//components/safe_json/public/interfaces:interfaces_js_data_deps
//components/safe_json/public/interfaces:interfaces_shared
//components/safe_json/public/interfaces:interfaces_shared__generator
//components/safe_json/public/interfaces:interfaces_shared_cpp_sources
//components/safe_json/utility:utility
//content/browser/devtools:compressed_protocol_json
//extensions/shell/common/api:shell_api_features_json_features
//extensions/shell/common/api:shell_behavior_features_json_features
//extensions/shell/common/api:shell_manifest_features_json_features
//extensions/shell/common/api:shell_permission_features_json_features
//extensions/test:test_api_features_json_features
//extensions/test:test_behavior_features_json_features
//extensions/test:test_manifest_features_json_features
//extensions/test:test_permission_features_json_features
//gpu/config:process_json
//testing/libfuzzer/fuzzers:base_json_reader_fuzzer
//testing/libfuzzer/fuzzers:v8_json_parser_fuzzer
//testing/libfuzzer/fuzzers:v8_json_parser_fuzzer.options
//testing/libfuzzer/fuzzers:v8_json_parser_fuzzer_dict_copy
//third_party/WebKit/Source/platform:blink_json_parser_fuzzer
//third_party/WebKit/Source/platform:blink_json_parser_fuzzer.options
//third_party/WebKit/Source/platform:blink_json_parser_fuzzer_dict_copy
//third_party/angle/src/vulkan_support:vulkan_gen_json_files
//third_party/dom_distiller_js:json_values_converter_test_proto
//third_party/dom_distiller_js:json_values_converter_test_proto_gen
//third_party/dom_distiller_js:json_values_converter_tests
//third_party/jsoncpp:jsoncpp
//third_party/webrtc/base:rtc_json
//third_party/webrtc/rtc_base:rtc_json
//tools/json_schema_compiler:generated_api_util
//tools/json_schema_compiler/test:api
//tools/json_schema_compiler/test:api_schema_generator
//tools/json_schema_compiler/test:features_compiler_test
//tools/json_schema_compiler/test:features_compiler_test_json_features
//tools/json_schema_compiler/test:unit_tests
//v8:json_fuzzer
//v8:v8_simple_json_fuzzer

我觉得v8_json_parser_fuzzer看起来是一个不错的选择。所以为了构建这个特定的fuzzer,我们需要运行这个命令:

$ ninja -C out/libfuzzer v8_json_parser_fuzzer

您会看到[55/1074] CXX obj/third_party/libFuzzer/libfuzzer/FuzzerExtraCounters.o正在构建的文字。这一步可能需要一段时间,所以请耐心等待一杯咖啡的时间。一旦完成,cd out/libfuzzer以及您将要发现的v8_json_parser_fuzzerfuzzer就会连同v8_json_parser_fuzzer.dict的字典文件以及一个v8_json_parser_fuzzer.optionslibFuzzer选项文件一起来让您可以使用它定义各种东西。但我们现在不会对此进行深入。各位可以随意探索。

接下来为您的起始语料库创建一个目录,并根据所需将其命名为:

$ mkdir json_parser_corpus

使用您的json文件填写json_parser_corpus。这里我没有使用附带的V8fuzzing语料库,因为每个人以及他们的fuzzing都被填满了。如果您不想自己找一个示例,那么您可以使用下面这个:

{
    "colorsArray":[{
        "colorName":"red",
        "hexValue":"#f00"
    },
    {
        "colorName":"green",
        "hexValue":"#0f0"
    },
    {
        "colorName":"blue",
        "hexValue":"#00f"
    },
    {
        "colorName":"cyan",
        "hexValue":"#0ff"
    },
    {
        "colorName":"magenta",
        "hexValue":"#f0f"
    },
    {
        "colorName":"yellow",
        "hexValue":"#ff0"
    },
    {
        "colorName":"black",
        "hexValue":"#000"
    }
    ]
}

如果您只有一个核心,那么您的命令行将是:

$ ./v8_json_parser_fuzzer json_parser_corpus/ -dict=v8_json_parser_fuzzer.dict

而如果您有多个核心:

$ ./v8_json_parser_fuzzer json_parser_corpus/ -dict=v8_json_parser_fuzzer.dict -jobs=X -workers=X

注意: -jobs=X X是您希望fuzzer在找到触发特定job中止或崩溃的事件之后重新启动-workers=X的次数,X是要使libFuzzer利用的CPU内核数。

最后,恭喜您现在正在对V8进行fuzzing,我非常希望您能因此而找到一两个漏洞。




原文发布时间为:2017年7月26日
本文作者:鲁班七号
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值