-
-
Notifications
You must be signed in to change notification settings - Fork 544
Open
Description
1、项目:Python APIFlask项目
2、模型:deepseek-coder
3、问题描述:只发现了一个问题,然后进入了验证阶段。在验证阶段验证成功后输出json漏洞报告然后就陷入死循环:输出json漏洞报告,然后agent决策提示"[Verification] 决策: 继续验证 (LLM 需要更多验证)",接着继续输出同样的json漏洞报告...

4、补充说明:
(1)https://github.com/lintsinghua/DeepAudit/issues/78,这个ISSUE也有类似的情况,可能是类似的原因?我也是测试失败,但是实际又能跑(LLM配置测试成功,嵌入模型配置测试失败)

(2)目前只用了Deepseek进行测试,不确定该问题是否与具体模型有关系
循环输出的内容如下:
Final Answer:
{
"findings": [
{
"type": "information_disclosure",
"severity": "medium",
"file": "eAuth/config/user/api.py (行 34)",
"code": "User.username.like(f\"%{query.get('username')}%\")",
"description": "在多个 API 端点中,使用 f-string 格式化构建 SQL LIKE 查询模式,如 `like(f\"%{user_input}%\")`。虽然 SQLAlchemy 会对参数进行转义,防止传统的 SQL 注入,但用户输入中的特殊字符(如 `%` 和 `_`)在 LIKE 模式中有特殊含义。攻击者可以输入 `%` 字符来匹配任意字符串,可能导致意外的查询结果和信息泄露。例如,在用户搜索功能中,输入 `%` 可以匹配所有用户记录。",
"verdict": "confirmed",
"confidence": 1.0,
"is_verified": true,
"verification_method": "动态 Fuzzing Harness 测试与代码分析",
"verification_details": "1. 使用 read_file 读取了 eAuth/config/user/api.py,确认了第34行存在漏洞代码模式。\n2. 使用 search_code 发现相同模式也存在于 eAuth/config/role/api.py 中。\n3. 编写并执行了 Python Fuzzing Harness,模拟 SQL LIKE 查询逻辑。测试证明:当用户输入为 '%' 时,生成的模式 '%%%' 会匹配模拟数据库中的所有记录(7个用户),证实了信息泄露的可能性。输入 '_' 和 '%_%' 也会导致比预期更广泛的匹配。",
"poc": {
"description": "通过向受影响的 API 端点(如 /api/users)发送包含 '%' 字符的查询参数,可以获取所有记录。",
"steps": [
"1. 定位到使用模糊搜索的 API 端点(例如 GET /api/users)。",
"2. 在查询参数中添加 username=% (或其他对应字段)。",
"3. 观察响应,如果返回了所有用户数据而非空结果或错误,则漏洞存在。"
],
"payload": "username=%",
"harness_code": "import re\n\ndef simulate_sql_like(pattern, test_string):\n regex_pattern = re.escape(pattern)\n regex_pattern = regex_pattern.replace(r'\\%', '.*').replace(r'\\_', '.')\n regex_pattern = '^' + regex_pattern + '$'\n return bool(re.match(regex_pattern, test_string, re.DOTALL))\n\ndef build_like_filter(user_input):\n return f\"%{user_input}%\"\n\nmock_usernames = [\"admin\", \"alice\", \"bob\", \"charlie\", \"david_secure\", \"test%user\", \"normal_user\"]\nvulnerable_input = '%'\nsql_pattern = build_like_filter(vulnerable_input)\nmatches = [u for u in mock_usernames if simulate_sql_like(sql_pattern, u)]\nprint(f\"Input '%' matched {len(matches)} users: {matches}\") # 输出: 匹配所有7个用户"
},
"impact": "攻击者能够枚举系统中的所有用户、角色等实体名称。这些信息泄露有助于进行社会工程、账户枚举攻击和后续的密码爆破,并可能暴露隐藏的管理账户。",
"recommendation": "在将用户输入拼接到 LIKE 模式前,对通配符 '%' 和 '_' 进行转义(例如:`user_input.replace('%', '\\\\%').replace('_', '\\\\_')`)。考虑使用专门的工具函数或 ORM 扩展来安全处理 LIKE 查询。在 API 层实施分页和最大返回行数限制。"
}
],
"summary": {
"total": 1,
"confirmed": 1,
"likely": 0,
"false_positive": 0
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels