ligurio/luzer

GitHub: ligurio/luzer

基于 libFuzzer 的覆盖率引导 Lua 模糊测试引擎,用于发现 Lua 代码及其 C 扩展中的安全漏洞和程序缺陷。

Stars: 59 | Forks: 5

[![静态分析](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/052ba4b0dd000222.svg)](https://github.com/ligurio/luzer/actions/workflows/check.yaml) [![测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/3ef5c5146c000223.svg)](https://github.com/ligurio/luzer/actions/workflows/test.yaml) [![许可证:ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC) [![Luarocks](https://img.shields.io/luarocks/v/ligurio/luzer/scm-1)](https://luarocks.org/modules/ligurio/luzer) # luzer 一个基于覆盖率引导的原生 Lua fuzzer。 ## 概述 Fuzzing 是一种自动化测试类型,通过持续操作程序的输入来发现错误。`luzer` 使用覆盖率引导来智能地遍历被 fuzz 的代码,以发现并向用户报告故障。由于它可以触及人类经常忽略的边缘情况,因此 fuzz 测试对于发现安全漏洞和弱点具有特别重要的价值。 `luzer` 是一个基于覆盖率引导的 Lua fuzzing 引擎。它支持对 Lua 代码进行 fuzz,也支持对为 Lua 编写的 C 扩展进行 fuzz。Luzer 基于 [libFuzzer][libfuzzer-url] 开发。在对原生代码进行 fuzz 时,`luzer` 可以与 Address Sanitizer 或 Undefined Behavior Sanitizer 结合使用,以捕获更多的错误。 ## 快速开始 要在您自己的项目中使用 luzer,请遵循以下几个简单步骤: 1. 设置 `luzer` 模块: ``` $ luarocks --local install luzer $ eval $(luarocks path) ``` 2. 创建一个调用您代码的 fuzz target: ``` local luzer = require("luzer") local function TestOneInput(buf) local b = {} buf:gsub(".", function(c) table.insert(b, c) end) if b[1] == 'c' then if b[2] == 'r' then if b[3] == 'a' then if b[4] == 's' then if b[5] == 'h' then assert(nil) end end end end end end luzer.Fuzz(TestOneInput) ``` 3. 使用 fuzz target 启动 fuzzer ``` $ luajit examples/example_basic.lua INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 1557779137 INFO: Loaded 1 modules (151 inline 8-bit counters): 151 [0x7f0640e706e3, 0x7f0640e7077a), INFO: Loaded 1 PC tables (151 PCs): 151 [0x7f0640e70780,0x7f0640e710f0), INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes INFO: A corpus is not provided, starting from an empty corpus #2 INITED cov: 17 ft: 18 corp: 1/1b exec/s: 0 rss: 26Mb #32 NEW cov: 17 ft: 24 corp: 2/4b lim: 4 exec/s: 0 rss: 26Mb L: 3/3 MS: 5 ShuffleBytes-ShuffleBytes-CopyPart-ChangeByte-CMP- DE: "\x00\x00"- ... ``` 当 fuzzing 进行时,fuzzing 引擎会生成新的输入,并针对提供的 fuzz target 运行这些输入。默认情况下,它会持续运行,直到发现失败的输入,或者用户取消该过程(例如使用 `Ctrl^C`)。 第一行输出表明在 fuzzing 开始之前收集了“基准覆盖率”(baseline coverage)。 为了收集基准覆盖率,fuzzing 引擎会执行种子语料库(seed corpus)和生成的语料库,以确保没有发生错误,并了解现有语料库已经提供的代码覆盖率。 请参阅以下使用 luzer 库的测试: - Tarantool Lua API 测试,https://github.com/tarantool/tarantool/tree/master/test/fuzz/lua - Lua 标准库测试,https://github.com/ligurio/lua-c-api-tests/tree/master/tests/lapi - https://github.com/ligurio/snippets/tree/master/luzer-tests ## 文档 参见 [文档](docs/index.md)。 ## 许可证 版权所有 © 2022-2025 [Sergey Bronnikov][bronevichok-url]。 在 ISC 许可证下分发。
标签:API密钥检测, ASan, C扩展, Fuzzing, LibFuzzer, Lua, LuaRocks, rizin, UBSan, 原生Lua, 地址消毒器, 安全测试, 客户端加密, 客户端加密, 攻击性安全, 模糊测试引擎, 覆盖率引导, 输入验证