您的位置:首页 > 科技 > 能源 > GDBFuzz:基于硬件断点的嵌入式系统模糊测试工具

GDBFuzz:基于硬件断点的嵌入式系统模糊测试工具

2024/12/27 5:53:12 来源:https://blog.csdn.net/FreeBuf_/article/details/140267136  浏览:    关键词:GDBFuzz:基于硬件断点的嵌入式系统模糊测试工具

关于GDBFuzz

GDBFuzz是一款功能强大的模糊测试工具,在该工具的帮助下,广大研究人员可以使用硬件断点对嵌入式系统进行模糊测试。

GDBFuzz的理念是利用微控制器的硬件断点作为覆盖引导模糊测试的反馈。因此,GDB被用作通用接口以实现广泛的适用性。对于固件的二进制分析,GDBFuzz使用了Ghidra实现。

工具要求

Java

Python 3

工具安装

注意,GDBFuzz已在 Ubuntu 20.04 LTS 和 Raspberry Pie OS 32 位上进行了测试。

首先,我们需要在本地设备上安装并配置好最新版本的Java和Python 3环境,然后创建一个新的虚拟环境并安装所有的依赖组件:

virtualenv .venvsource .venv/bin/activatemakechmod a+x ./src/GDBFuzz/main.py

工具使用

本地运行样例

GDBFuzz会使用以下键来从配置文件中读取设置:

[SUT]# Path to the binary file of the SUT.# This can, for example, be an .elf file or a .bin file.binary_file_path = <path># Address of the root node of the CFG.# Breakpoints are placed at nodes of this CFG.# e.g. 'LLVMFuzzerTestOneInput' or 'main'entrypoint = <entrypoint># Number of inputs that must be executed without a breakpoint hit until# breakpoints are rotated.until_rotate_breakpoints = <number># Maximum number of breakpoints that can be placed at any given time.max_breakpoints = <number># Blacklist functions that shall be ignored.# ignore_functions is a space separated list of function names e.g. 'malloc free'.ignore_functions = <space separated list># One of {Hardware, QEMU, SUTRunsOnHost}# Hardware: An external component starts a gdb server and GDBFuzz can connect to this gdb server.# QEMU: GDBFuzz starts QEMU. QEMU emulates binary_file_path and starts gdbserver.# SUTRunsOnHost: GDBFuzz start the target program within GDB.target_mode = <mode># Set this to False if you want to start ghidra, analyze the SUT,# and start the ghidra bridge server manually.start_ghidra = True# Space separated list of addresses where software breakpoints (for error# handling code) are set. Execution of those is considered a crash.# Example: software_breakpoint_addresses = 0x123 0x432software_breakpoint_addresses =# Whether all triggered software breakpoints are considered as crashconsider_sw_breakpoint_as_error = False[SUTConnection]# The class 'SUT_connection_class' in file 'SUT_connection_path' implements# how inputs are sent to the SUT.# Inputs can, for example, be sent over Wi-Fi, Serial, Bluetooth, ...# This class must inherit from ./connections/SUTConnection.py.# See ./connections/SUTConnection.py for more information.SUT_connection_file = FIFOConnection.py[GDB]path_to_gdb = gdb-multiarch#Written in address:portgdb_server_address = localhost:4242[Fuzzer]# In Bytesmaximum_input_length = 100000# In secondssingle_run_timeout = 20# In secondstotal_runtime = 3600# Optional# Path to a directory where each file contains one seed. If you don't want to# use seeds, leave the value empty.seeds_directory =[BreakpointStrategy]# Strategies to choose basic blocks are located in# 'src/GDBFuzz/breakpoint_strategies/'# For the paper we use the following strategies# 'RandomBasicBlockStrategy.py' - Randomly choosing unreached basic blocks# 'RandomBasicBlockNoDomStrategy.py' - Like previous, but doesn't use dominance relations to derive transitively reached nodes.# 'RandomBasicBlockNoCorpusStrategy.py' - Like first, but prevents growing the input corpus and therefore behaves like blackbox fuzzing with coverage measurement.# 'BlackboxStrategy.py', - Doesn't set any breakpointsbreakpoint_strategy_file = RandomBasicBlockStrategy.py[Dependencies]path_to_qemu = dependencies/qemu/build/x86_64-linux-user/qemu-x86_64path_to_ghidra = dependencies/ghidra[LogsAndVisualizations]# One of {DEBUG, INFO, WARNING, ERROR, CRITICAL}loglevel = INFO# Path to a directory where output files (e.g. graphs, logfiles) are stored.output_directory = ./output# If set to True, an MQTT client sends UI elements (e.g. graphs)enable_UI = False

项目的./example_programs/目录中提供了一个配置文件样例,benchmark/benchSUTs/GDBFuzz_wrapper/common/路径下也有一个可以进行模糊测试的样例程序。

下列命令可以直接对目标程序执行模糊测试:

chmod a+x ./example_programs/json-2017-02-12./src/GDBFuzz/main.py --config ./example_programs/fuzz_json.cfg

在 Docker 容器中安装并运行

make dockerimage

如需在Docker中执行上述测试,需要先将example_programs和output文件夹映射为卷,然后按如下方式启动GDBFuzz:

chmod a+x ./example_programs/json-2017-02-12docker run -it --env CONFIG_FILE=/example_programs/fuzz_json_docker_qemu.cfg -v $(pwd)/example_programs:/example_programs -v $(pwd)/output:/output gdbfuzz:1.0

模糊测试输出

根据配置文件中指定的output_directory内容,工具将会生成一个包含下列结构的“trial-0”文件夹:

.├── corpus            ├── crashes           ├── cfg               ├── fuzzer_stats      ├── plot_data         ├── reverse_cfg       

可视化实现

GDBFuzz 有一个可选功能,可以绘制覆盖节点的控制流图。默认情况下,此功能处于禁用状态。我们可以在用户配置中将“enable_UI”设置为“True”来启用它。

执行下列命令安装graphviz:

sudo apt-get install graphviz

然后安装最新版本的Node.js:

$ node --versionv16.9.1$ npm --version7.21.1

安装 Web UI 依赖项:

cd ./src/webuinpm install

安装并更新mosquitto MQTT代理,并使用以下内容替换/etc/mosquitto/conf.d/mosquitto.conf文件中的内容:

listener 1883allow_anonymous truelistener 9001protocol websockets

重新启动 mosquitto 代理:

sudo service mosquitto restart

检查 mosquitto 代理是否正在运行:

sudo service mosquitto status

启动网页用户界面:

cd ./src/webuinpm start

打开Web浏览器并访问“http://localhost:3000/”即可。

许可证协议

本项目的开发与发布遵循AGPL-3.0开源许可协议。

项目地址

GDBFuzz:【GitHub传送门】

参考资料

Fuzzing Embedded Systems Using Debug Interfaces - CISPA

Installieren von Node.js unter Ubuntu 20.04 | DigitalOcean

How to Install The Mosquitto MQTT Broker on Linux

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com