使用libFuzzer fuzz Chrome V8入门指南

简介: 本文讲的是使用libFuzzer fuzz Chrome V8入门指南,V8(也称为Chrome V8)是由Chromium Project开发的用于Google Chrome浏览器的开源JavaScript引擎。
本文讲的是 使用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日
本文作者:鲁班七号
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。
目录
相关文章
|
12天前
|
Web App开发 搜索推荐 前端开发
【热门话题】Chrome 插件研发详解:从入门到实践
本文详细介绍了Chrome插件的开发,从基础概念到实战技巧。首先,解释了插件的结构,包括manifest.json、背景脚本、内容脚本和UI界面。接着,阐述了生命周期、通信机制以及开发步骤,包括创建项目结构、编写manifest.json、开发脚本和UI,以及测试与调试。通过一个显示当前页面URL的插件实例,展示了具体实现过程。最后,讲解了如何在Chrome Web Store发布和分发插件。Chrome插件开发为开发者提供了创造个性化体验的平台,本文旨在引导读者入门并深入实践。
32 2
|
Web App开发 SQL 存储
Chrome操作指南——入门篇(一)
Chrome操作指南——入门篇(一)
Chrome操作指南——入门篇(一)
|
Web App开发 存储 前端开发
Chrome操作指南——入门篇(二)
Chrome操作指南——入门篇(二)
Chrome操作指南——入门篇(二)
|
Web App开发 开发者
Chrome操作指南——入门篇(三)
Chrome操作指南——入门篇(三)
Chrome操作指南——入门篇(三)
|
Web App开发 前端开发 开发者
Chrome操作指南——入门篇(四) command
Chrome操作指南——入门篇(四) command
Chrome操作指南——入门篇(四) command
|
Web App开发 存储 JavaScript
Chrome操作指南——入门篇(五)Snippets
Chrome操作指南——入门篇(五)Snippets
Chrome操作指南——入门篇(五)Snippets
|
Web App开发 前端开发 CDN
Chrome操作指南——入门篇(六)console.injector
Chrome操作指南——入门篇(六)console.injector
Chrome操作指南——入门篇(六)console.injector
|
Web App开发 前端开发 API
Chrome操作指南——入门篇(七)console中的await和log
Chrome操作指南——入门篇(七)console中的await和log
Chrome操作指南——入门篇(七)console中的await和log
|
Web App开发 前端开发
Chrome操作指南——入门篇(八)breakpoint
Chrome操作指南——入门篇(八)breakpoint
Chrome操作指南——入门篇(八)breakpoint
|
Web App开发 前端开发
Chrome操作指南——入门篇(九)调试小技巧
Chrome操作指南——入门篇(九)调试小技巧
Chrome操作指南——入门篇(九)调试小技巧

热门文章

最新文章