gustavo-grieco/quimera

GitHub: gustavo-grieco/quimera

基于大语言模型与 Foundry 的数据驱动以太坊智能合约漏洞生成与验证工具。

Stars: 92 | Forks: 17

# Quimera Support quimera on drips.network 这是一个利用大型语言模型(LLM)逐步发现 Foundry 中智能合约漏洞的漏洞生成器,遵循以下步骤: 1. 获取智能合约的源代码并编写描述漏洞目标的提示(例如,闪电贷后余额应增加)。 2. 要求 LLM 创建或改进一个 Foundry 测试用例,尝试利用该合约。 3. 运行测试,检查交易跟踪,并查看是否获利。 4. 如果获利则停止;否则返回步骤 2,并将失败尝试的跟踪信息提供给 LLM 以帮助其改进。 **当前状态**:这是一个实验性原型。我们仍在研究最佳设置(如合适的温度)、如何编写更好的提示以及该工具的实际能力。以下是迄今为止使用 [Gemini Pro 2.5 06-05](https://blog.google/products/gemini/gemini-2-5-pro-latest-preview/) 重新发现已知漏洞的结果: | Exploit | Complexity | Comments | |-----------|------------|----------| |[APEMAGA](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/dc2cf9e53e9ccaf2eaf9806bad7cd914edefb41b/src/test/2024-06/APEMAGA_exp.sol#L23) | Low | Only one step needed.| |[VISOR](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/34cce572d25175ca915445f2ce7f7fbbb7cb593b/src/test/2021-12/Visor_exp.sol#L10) | Low | A few steps needed to build the WETH conversion calls, but overall the root cause is identified quickly. | | [FIRE](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/b3738a7fdffa4b0fc5b34237e70eec2890e54878/src/test/2024-10/FireToken_exp.sol) | Medium | It will first build the sequence of calls to exploit it, and then slowly adjust the amounts until profit is found. | | [XAI] | Low | A small number of steps needed, as you can see in the demo | | [Thunder-Loan](https://github.com/Cyfrin/2023-11-Thunder-Loan) | Low | This one is part of a CTF? | # 演示 ![Demo](https://i.imgur.com/3Xw7vb8.gif) # 需求 * 你需要一个 RPC 提供商(例如 Alchemy)和一个 Etherscan API 密钥。两者都有免费选项。 * 一个 LLM 服务,可以是本地(例如 ollama)或远程 LLM 服务(例如 gemini)。**你不需要支付 API 访问费用,特别是如果你使用“手动模式”** * [Foundry](https://book.getfoundry.sh/) # 安装 要安装,只需运行: ``` pip3 install git+https://github.com/gustavo-grieco/quimera ``` 如果你想使用[不同的 LLM 提供商](https://llm.datasette.io/en/stable/plugins/directory.html#plugin-directory),你需要安装它们作为插件。例如,要安装对 Gemini 和 Ollama 的支持: ``` llm install llm-gemini llm install llm-ollama ``` 请注意,在“手动模式”下,无需安装任何插件,因为用户可以直接复制和粘贴提示与响应。 **重要**:在使用 LLM 测试已知漏洞时,请确保禁用网络搜索,否则它们可能会访问原始漏洞代码。 # 入门 1. 修改 `keys.sh` 文件以添加 RPC 和 Etherscan 密钥。 2. 选择一个区块编号 `B`,然后执行 `source keys.sh B` 3. 调用 Quimera: ``` quimera TARGET --model gpt-4o --iterations 5 ``` 你可以使用 `llm models` 来显示可用的模型。 # 运行模式 Quimera 可以使用已部署的合约(通过 Etherscan 获取源代码)或本地模式(基于 Foundry 代码库)工作。要了解如何在本地使用,请查看 [tests/erc4626](tests/erc4626) 目录。它导入了 OpenZepelin ERC4626 金库,并在测试中使用 WETH 实例化。为了使用 Quimera,你必须在 [`test/quimera/QuimeraBase.t.sol`](tests/erc4626/test/quimera/QuimeraBase.t.sol) 中定义一个类似示例的 QuimeraBase 合约。 # 相关工作 [AI Agent Smart Contract Exploit Generation](https://arxiv.org/abs/2507.05558):一种与 Quimera 非常接近的方法,甚至共享在此处重新发现的某些漏洞。 [PoCo: Agentic Proof-of-Concept Exploit Generation for Smart Contracts](https://arxiv.org/abs/2511.02780):类似于离线的 Quimera,它基于审计员的注释在 Foundry 中生成 PoC。 [AI agents find $4.6M in blockchain smart contract exploits](https://red.anthropic.com/2025/smart-contracts/):与 Quimera 类似。它使用 Foundry 测试目标合约,并基于分叉的区块链节点。评估在代理停止调用工具或会话达到 60 分钟超时时结束。
标签:APEMAGA, C2, DeFi, DLL 劫持, Drips, FIRE, Flashloan, Foundry, Gemini, LLM, Unmanaged PE, VISOR, 交易追踪, 以太坊, 区块链安全, 大语言模型, 实验原型, 数据驱动, 智能合约, 温度参数, 生成式AI, 索引, 逆向工具, 重测试