edoardottt/CVE-2025-67511

GitHub: edoardottt/CVE-2025-67511

该项目是针对 CAI 网络安全 AI 框架中 CVE-2025-67511 命令注入漏洞的分析文章与 PoC,揭示了 AI agent 工具函数因 shell 转义不完整而可被恶意目标反向利用的风险。

Stars: 4 | Forks: 0

# CVE-2025-67511:诱导安全 AI Agent 自我攻陷 Hacktive Security 关于 [CVE-2025-67511](https://github.com/aliasrobotics/cai/security/advisories/GHSA-4c65-9gqf-4w8h) 的博客文章 **博客文章链接**: ## TL;DR cai-framework <= 0.5.9 中提供给 AI agent 的函数工具 `run_ssh_command_with_credentials()` 存在命令注入漏洞,可实现远程命令执行。 本文描述了我在 CAI 框架中发现的一个漏洞。由于 AI agent 可访问的工具内部存在不完整的 shell 转义,导致恶意目标能够在分析师的机器上触发命令执行。 恶意目标可以将其自身的数据武器化,使得安全 agent 在不知情的情况下攻击了它本应保护的机器。 ## 什么是 CAI (Cybersecurity AI) 引用 CAI 的 README (): *"Cybersecurity AI (CAI) 是一个轻量级的开源框架,旨在赋能安全专业人员构建和部署由 AI 驱动的攻防自动化。CAI 是 AI 安全领域事实上的标准框架,已被数千名个人用户和数百家组织使用。无论您是安全研究员、道德黑客、IT 专业人员,还是希望提升安全状况的组织,CAI 都提供了基础构建块,用于创建能够协助缓解、漏洞发现、利用和安全评估的专用 AI agent。"* CAI 适用于自动化或半自动化的漏洞发现、渗透测试、漏洞赏金工作流以及安全评估。 AI agent 可以使用“工具”来扩展其纯文本推理之外的能力。它们允许 agent 在现实或数字世界中采取行动,而不仅仅是讨论这些行动。 它配备了用于典型安全任务(Web 搜索、命令行工具、文件管理、网络扫描等)的内置工具(用户也可以集成自定义工具)。 为了初步了解 CAI 的工作原理,以下是它使用 prompt `Solve this Lab instance URL: https://xxxyyyzzz.web-security-academy.net/` 解决 PortSwigger 实验的实际操作演示。 CAI Community Edition Demo 详情请参阅 。 ## 漏洞详情 这是工具 `run_ssh_command_with_credentials()` 的源代码 ([代码](https://github.com/aliasrobotics/cai/blob/0.5.9/src/cai/tools/command_and_control/sshpass.py)): ``` """ SSH Pass tool for executing remote commands via SSH using password authentication. [...] """ # noqa: E501 from cai.tools.common import run_command # pylint: disable=E0401 # noqa: E501 from cai.sdk.agents import function_tool @function_tool def run_ssh_command_with_credentials( host: str, username: str, password: str, command: str, port: int = 22) -> str: """ Execute a command on a remote host via SSH using password authentication. Args: host: Remote host address username: SSH username password: SSH password command: Command to execute on remote host port: SSH port (default: 22) Returns: str: Output from the remote command execution """ # Escape special characters in password and command to prevent shell injection escaped_password = password.replace("'", "'\\''") escaped_command = command.replace("'", "'\\''") ssh_command = ( f"sshpass -p '{escaped_password}' " f"ssh -o StrictHostKeyChecking=no " f"{username}@{host} -p {port} " f"'{escaped_command}'" ) return run_command(ssh_command) ``` 通常这里会逐行解释代码片段,但在本例中它本身就已经很清晰了。 正如描述注释所言:“通过 SSH 使用密码认证在远程主机上执行命令”。 问题在于,只有 *password* 和 *command* 的输入值被转义以防止 shell 注入;而 *username*、*host* 和 *port* 的值则被留作可注入状态。 ## 概念验证 创建一个包含以下内容的 `index.html` 文件: ``` target system nothing interesting here ``` 使用 Web 服务器提供该文件,例如: ``` sudo python3 -m http.server ``` 启动 cai framework: ``` # 启动 CAI cai # 选择 model /model 7 # 选择 agent type /parallel add blueteam_agent # 向 agent 分配任务 localhost is your target. grab secret information from http://localhost:8000/index.html and try to evaluate its security. try the attacks with proof of concepts ``` Agent 执行命令 `curl -s http://localhost:8000/index.html` 来获取 HTML 内容。 poc1 然后,它会使用在目标上发现的凭据,尝试通过存在漏洞的函数 `run_ssh_command_with_credentials()` 连接到默认端口 22 上的 SSH 服务,以执行命令 `id`。 poc2 结果,我们成功创建了文件 `/tmp/username`,但没有创建 `/tmp/password`(因为对该项应用了 shell 注入预防机制)。 poc3 攻击者可以暴露虚假的凭据,如上面的概念验证所示。 当 AI Agent 获取到虚假的 SSH 信息时,它会通过函数工具 `run_ssh_command_with_credentials()` 使用这些信息,从而导致部署 CAI 的主机发生命令注入。 ## 影响 通过暴露恶意构造的 SSH 凭据,攻击者可以促使 CAI agent: - 攻陷整个服务器主机 - 窃取凭据和机密信息 - 在组织内部进行横向移动 - 供应链和模型滥用风险 由于 CAI agent 被设计为自主检索信息、评估目标并采取行动,此问题将通常被动的“读取”操作(从公开内容中解析凭据)转变为自我触发的漏洞利用链。 在实际应用中,**恶意目标可以将其自身的数据武器化,使得安全 agent 在不知情的情况下攻击了它本应保护的机器**。 这使得该漏洞在以下使用 CAI 的场景中尤为严重: - 蓝队自动化(攻击者可以攻击防御者) - 漏洞赏金工作流(不受信任的目标可能会攻陷测试人员) - 红队模拟(意外地将权限提升至操作员的机器) - 外部资产的自动化扫描(agent 获取的任何内容都可能成为潜在的攻击向量) 该漏洞的影响评分为 9.7 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H)。 ## 修复方案 该补丁已在提交 [09ccb6e0baccf56c40e6cb429c698750843a999c](https://github.com/aliasrobotics/cai/commit/09ccb6e0baccf56c40e6cb429c698750843a999c) 中引入,并已合并至 main 分支。 截至撰稿时,PyPI 上尚未发布修复版本。 ## 参考资源 - -
标签:AI安全, Chat Copilot, PoC, 内存分配, 命令注入, 应用安全, 暴力破解, 渗透测试框架, 漏洞分析, 路径探测, 逆向工具, 防御, 防御加固