jarvis-sec 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. jarvis_sec-0.1.0/PKG-INFO +79 -0
  2. jarvis_sec-0.1.0/README.md +59 -0
  3. jarvis_sec-0.1.0/pyproject.toml +55 -0
  4. jarvis_sec-0.1.0/setup.cfg +4 -0
  5. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/__init__.py +228 -0
  6. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/agents.py +141 -0
  7. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/analysis.py +368 -0
  8. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/cli.py +1233 -0
  9. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/clustering.py +1769 -0
  10. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/data_collector.py +2111 -0
  11. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/data_flow_analyzer.py +814 -0
  12. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/file_manager.py +561 -0
  13. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/joern_analyzer.py +440 -0
  14. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/parsers.py +80 -0
  15. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/project_database.py +1524 -0
  16. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/prompts.py +265 -0
  17. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/report.py +364 -0
  18. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/review.py +578 -0
  19. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/status.py +281 -0
  20. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/taint_analyzer.py +854 -0
  21. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/types.py +24 -0
  22. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/utils.py +670 -0
  23. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/verification.py +1243 -0
  24. jarvis_sec-0.1.0/src/jarvis/jarvis_sec/workflow.py +816 -0
  25. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/PKG-INFO +79 -0
  26. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/SOURCES.txt +31 -0
  27. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/dependency_links.txt +1 -0
  28. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/entry_points.txt +3 -0
  29. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/requires.txt +9 -0
  30. jarvis_sec-0.1.0/src/jarvis_sec.egg-info/top_level.txt +1 -0
  31. jarvis_sec-0.1.0/tests/test_checkers.py +358 -0
  32. jarvis_sec-0.1.0/tests/test_rust_checker_datasets.py +327 -0
  33. jarvis_sec-0.1.0/tests/test_taint_analyzer.py +281 -0
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: jarvis-sec
3
+ Version: 0.1.0
4
+ Summary: Jarvis Security Scanner: C/C++/Rust security audit tool with heuristic scan and taint analysis
5
+ Author: skyfireitdiy
6
+ License-Expression: MIT
7
+ Keywords: security,scan,c,cpp,rust,audit,jarvis
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Topic :: Security
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: jarvis-ai-assistant>=7.0.1
14
+ Requires-Dist: typer
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Requires-Dist: pytest-cov; extra == "dev"
18
+ Requires-Dist: ruff; extra == "dev"
19
+ Provides-Extra: joern
20
+
21
+ # jarvis-sec
22
+
23
+ Jarvis 安全扫描工具:面向 C/C++/Rust 代码仓的安全审计 CLI。
24
+
25
+ `jarvis-sec`(别名 `jsec`)是 [Jarvis](https://github.com/skyfireitdiy/Jarvis) 生态中的独立安全扫描工具,从主仓库拆分而来。它直接以 `jarvis-ai-assistant` 作为运行时依赖,复用其 `PrettyOutput` / `Agent` / `ToolRegistry` 等基础设施。
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ pip install jarvis-sec
31
+ ```
32
+
33
+ > 依赖 `jarvis-ai-assistant>=7.0.1`,安装时会自动带上。
34
+
35
+ ## 使用
36
+
37
+ ```bash
38
+ # 查看帮助
39
+ jarvis-sec --help
40
+ jsec --help
41
+
42
+ # 配置安全扫描
43
+ jarvis-sec config
44
+
45
+ # 执行安全扫描(启发式 + 单Agent验证)
46
+ jarvis-sec scan --path ./target_project
47
+
48
+ # 从 JSON 分析安全问题
49
+ jarvis-sec analyze --input issues.json
50
+
51
+ # 仅启发式直扫
52
+ jarvis-sec heuristic --path ./target_project
53
+ ```
54
+
55
+ 配置文件路径为相对当前工作目录的 `.jarvis/sec/config.json`。
56
+
57
+ ## 能力
58
+
59
+ - **启发式扫描**:基于正则与规则模板快速定位候选问题(C/C++/Rust)
60
+ - **污点传播分析**:追踪数据从 source 到 sink 的传播路径
61
+ - **调用图分析**:跨函数/跨文件分析
62
+ - **单 Agent 验证**:对候选问题逐条交由 Agent 验证,降低误报
63
+ - **Joern(可选)**:若系统安装了 [Joern](https://joern.io/),自动启用更精确的代码属性图分析;未安装时自动降级为内置分析器
64
+
65
+ ## 开发
66
+
67
+ ```bash
68
+ pip install -e ".[dev]"
69
+ pytest tests/ -m "not slow"
70
+ ruff check src/
71
+ ```
72
+
73
+ ## 编排
74
+
75
+ `orchestration/jsec_adversarial.yaml` 是对抗式自进化编排配置:`jsec_adversary` 主动搜索漏洞并驱动 `jsec_rule_developer` 改进检测规则。
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,59 @@
1
+ # jarvis-sec
2
+
3
+ Jarvis 安全扫描工具:面向 C/C++/Rust 代码仓的安全审计 CLI。
4
+
5
+ `jarvis-sec`(别名 `jsec`)是 [Jarvis](https://github.com/skyfireitdiy/Jarvis) 生态中的独立安全扫描工具,从主仓库拆分而来。它直接以 `jarvis-ai-assistant` 作为运行时依赖,复用其 `PrettyOutput` / `Agent` / `ToolRegistry` 等基础设施。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install jarvis-sec
11
+ ```
12
+
13
+ > 依赖 `jarvis-ai-assistant>=7.0.1`,安装时会自动带上。
14
+
15
+ ## 使用
16
+
17
+ ```bash
18
+ # 查看帮助
19
+ jarvis-sec --help
20
+ jsec --help
21
+
22
+ # 配置安全扫描
23
+ jarvis-sec config
24
+
25
+ # 执行安全扫描(启发式 + 单Agent验证)
26
+ jarvis-sec scan --path ./target_project
27
+
28
+ # 从 JSON 分析安全问题
29
+ jarvis-sec analyze --input issues.json
30
+
31
+ # 仅启发式直扫
32
+ jarvis-sec heuristic --path ./target_project
33
+ ```
34
+
35
+ 配置文件路径为相对当前工作目录的 `.jarvis/sec/config.json`。
36
+
37
+ ## 能力
38
+
39
+ - **启发式扫描**:基于正则与规则模板快速定位候选问题(C/C++/Rust)
40
+ - **污点传播分析**:追踪数据从 source 到 sink 的传播路径
41
+ - **调用图分析**:跨函数/跨文件分析
42
+ - **单 Agent 验证**:对候选问题逐条交由 Agent 验证,降低误报
43
+ - **Joern(可选)**:若系统安装了 [Joern](https://joern.io/),自动启用更精确的代码属性图分析;未安装时自动降级为内置分析器
44
+
45
+ ## 开发
46
+
47
+ ```bash
48
+ pip install -e ".[dev]"
49
+ pytest tests/ -m "not slow"
50
+ ruff check src/
51
+ ```
52
+
53
+ ## 编排
54
+
55
+ `orchestration/jsec_adversarial.yaml` 是对抗式自进化编排配置:`jsec_adversary` 主动搜索漏洞并驱动 `jsec_rule_developer` 改进检测规则。
56
+
57
+ ## License
58
+
59
+ MIT
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "jarvis-sec"
7
+ version = "0.1.0"
8
+ description = "Jarvis Security Scanner: C/C++/Rust security audit tool with heuristic scan and taint analysis"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "skyfireitdiy" },
14
+ ]
15
+ keywords = ["security", "scan", "c", "cpp", "rust", "audit", "jarvis"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Topic :: Security",
20
+ ]
21
+ dependencies = [
22
+ "jarvis-ai-assistant>=7.0.1",
23
+ "typer",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ "pytest",
29
+ "pytest-cov",
30
+ "ruff",
31
+ ]
32
+ joern = []
33
+
34
+ [project.scripts]
35
+ jarvis-sec = "jarvis.jarvis_sec.cli:main"
36
+ jsec = "jarvis.jarvis_sec.cli:main"
37
+
38
+ [tool.setuptools]
39
+ packages = ["jarvis.jarvis_sec"]
40
+ package-dir = { "" = "src" }
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ markers = [
45
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
46
+ ]
47
+
48
+ [tool.ruff]
49
+ line-length = 100
50
+ target-version = "py310"
51
+
52
+ [tool.ruff.lint]
53
+ # 锁定规则集为经典默认(E4/E7/E9/F),避免新版本 ruff 引入的 UP/BLE 等
54
+ # 规则导致 CI 与本地检查结果不一致(与主仓库 jarvis-ai-assistant 保持一致)。
55
+ select = ["E4", "E7", "E9", "F"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,228 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Jarvis 安全分析套件
4
+
5
+ 当前版本概述:
6
+ - 关键路径:直扫(direct_scan)→ 单Agent逐条验证(只读工具:read_code/execute_script)→ 聚合输出(JSON + Markdown)
7
+ - 目标范围:内存管理、缓冲区操作、错误处理等基础安全问题识别
8
+ - 约束:不修改核心框架文件,保持最小侵入;严格只读分析
9
+
10
+ 集成方式:
11
+ - 复用 jarvis.jarvis_agent.Agent 与工具注册系统(jarvis.jarvis_tools.registry.ToolRegistry)
12
+ - 提供入口:
13
+ - run_security_analysis(entry_path, ...):直扫 + 单Agent逐条验证 + 聚合
14
+
15
+ - workflow.direct_scan(entry_path, ...):仅启发式直扫
16
+
17
+ 说明:
18
+ - 已移除 MultiAgent 编排与相关提示词;不存在"阶段一"等表述
19
+ - 模块化重构:将功能拆分为多个模块(prompts, parsers, utils, agents, clustering, analysis, verification, review)
20
+ """
21
+
22
+ from jarvis.jarvis_utils.exception_utils import save_exception
23
+ from typing import Any, Dict, List, Optional
24
+
25
+ from jarvis.jarvis_utils.output import PrettyOutput
26
+
27
+ from jarvis.jarvis_agent import Agent # noqa: F401
28
+ from jarvis.jarvis_sec.utils import (
29
+ initialize_analysis_context as _initialize_analysis_context,
30
+ )
31
+ from jarvis.jarvis_sec.utils import (
32
+ load_or_run_heuristic_scan as _load_or_run_heuristic_scan,
33
+ )
34
+ from jarvis.jarvis_sec.utils import prepare_candidates as _prepare_candidates
35
+ from jarvis.jarvis_sec.utils import (
36
+ group_candidates_by_file as _group_candidates_by_file,
37
+ )
38
+ from jarvis.jarvis_sec.utils import create_report_writer as _create_report_writer
39
+ from jarvis.jarvis_sec.clustering import ( # type: ignore[attr-defined]
40
+ process_clustering_phase as _process_clustering_phase,
41
+ )
42
+ from jarvis.jarvis_sec.verification import (
43
+ process_verification_phase as _process_verification_phase,
44
+ )
45
+
46
+ from jarvis.jarvis_sec.workflow import direct_scan
47
+ from jarvis.jarvis_sec.workflow import run_with_agent
48
+
49
+ # 注:当前版本不使用 MultiAgent 编排,已移除默认多智能体配置与创建函数。
50
+ # 请使用 run_security_analysis(单Agent逐条验证)或 workflow.direct_scan + format_markdown_report(直扫基线)。
51
+ # 注意:部分函数已迁移到模块化文件中(prompts.py, parsers.py, utils.py, agents.py, clustering.py, analysis.py, verification.py, review.py),
52
+ # 本文件中保留了这些函数的别名导入,以便向后兼容。
53
+
54
+
55
+ def run_security_analysis(
56
+ entry_path: str,
57
+ languages: Optional[List[str]] = None,
58
+ report_file: Optional[str] = None,
59
+ cluster_limit: int = 50,
60
+ exclude_dirs: Optional[List[str]] = None,
61
+ enable_verification: bool = True,
62
+ force_save_memory: bool = False,
63
+ output_file: Optional[str] = None,
64
+ ) -> str:
65
+ """
66
+ 运行安全分析工作流(混合模式)。
67
+
68
+ 改进:
69
+ - 即使在 agent 模式下,也先进行本地正则/启发式直扫,生成候选问题;
70
+ 然后将候选问题拆分为子任务,交由多Agent进行深入分析与聚合。
71
+
72
+ 注意:此函数会在发生异常时更新状态文件为 error 状态。
73
+
74
+ 参数:
75
+ - entry_path: 待分析的根目录路径
76
+ - languages: 限定扫描的语言扩展(例如 ["c", "cpp", "h", "hpp", "rs"]),为空则使用默认
77
+
78
+ 返回:
79
+ - 最终报告(字符串),由 Aggregator 生成(JSON + Markdown)
80
+
81
+ 其他:
82
+ - report_file: 增量报告文件路径(JSONL)。当每个子任务检测到 issues 时,立即将一条记录追加到该文件;
83
+ 若未指定,则默认写入 entry_path/.jarvis/sec/agent_issues.jsonl
84
+ - cluster_limit: 聚类时每批次最多处理的告警数(默认 50),当单个文件告警过多时按批次进行聚类
85
+ - exclude_dirs: 要排除的目录列表(可选),默认已包含测试目录(test, tests, __tests__, spec, testsuite, testdata)
86
+ - enable_verification: 是否启用二次验证(默认 True),关闭后分析Agent确认的问题将直接写入报告
87
+ - 断点续扫: 默认开启。会基于 .jarvis/sec/candidates.jsonl、clusters.jsonl 和 analysis.jsonl 文件进行状态恢复。
88
+ """
89
+
90
+ langs = languages or ["c", "cpp", "h", "hpp", "rs"]
91
+
92
+ # 状态管理器(不再使用 status.json,使用空对象)
93
+ class DummyStatusManager:
94
+ def update_pre_scan(self, **kwargs: Any) -> None:
95
+ pass
96
+
97
+ def update_clustering(self, **kwargs: Any) -> None:
98
+ pass
99
+
100
+ def update_review(self, **kwargs: Any) -> None:
101
+ pass
102
+
103
+ def update_verification(self, **kwargs: Any) -> None:
104
+ pass
105
+
106
+ def mark_completed(self, **kwargs: Any) -> None:
107
+ pass
108
+
109
+ def mark_error(self, **kwargs: Any) -> None:
110
+ pass
111
+
112
+ status_mgr = DummyStatusManager()
113
+
114
+ # 初始化分析上下文
115
+ sec_dir, progress_path, _progress_append = _initialize_analysis_context(
116
+ entry_path, status_mgr
117
+ )
118
+
119
+ # 1) 启发式扫描(支持断点续扫)
120
+ candidates, summary = _load_or_run_heuristic_scan(
121
+ entry_path, langs, exclude_dirs, sec_dir, status_mgr, _progress_append
122
+ )
123
+
124
+ # 2) 将候选问题精简为子任务清单,控制上下文长度
125
+ compact_candidates = _prepare_candidates(candidates)
126
+
127
+ # 3) 保存候选到新的 candidates.jsonl 文件(包含gid)
128
+ from jarvis.jarvis_sec.file_manager import get_candidates_file
129
+ from jarvis.jarvis_sec.file_manager import save_candidates
130
+
131
+ try:
132
+ save_candidates(sec_dir, compact_candidates)
133
+ _progress_append(
134
+ {
135
+ "event": "candidates_saved",
136
+ "path": str(get_candidates_file(sec_dir)),
137
+ "issues_count": len(compact_candidates),
138
+ }
139
+ )
140
+ except Exception as e:
141
+ save_exception(e, module="jarvis.jarvis_sec.__init__", function="mark_error")
142
+ pass
143
+
144
+ # 记录批次选择信息(可选,用于日志)
145
+ try:
146
+ groups = _group_candidates_by_file(compact_candidates)
147
+ if groups:
148
+ selected_file, items = max(groups.items(), key=lambda kv: len(kv[1]))
149
+ try:
150
+ PrettyOutput.auto_print(
151
+ f"[jarvis-sec] 批次选择: 文件={selected_file} 数量={len(items)}"
152
+ )
153
+ except Exception as e:
154
+ save_exception(e, module="jarvis.jarvis_sec.__init__", function="mark_error")
155
+ pass
156
+ _progress_append(
157
+ {
158
+ "event": "batch_selection",
159
+ "selected_file": selected_file,
160
+ "selected_count": len(items),
161
+ "total_in_file": len(items),
162
+ }
163
+ )
164
+ except Exception as e:
165
+ save_exception(e, module="jarvis.jarvis_sec.__init__", function="mark_error")
166
+ pass
167
+
168
+ # 创建报告写入函数
169
+ _append_report = _create_report_writer(sec_dir, report_file)
170
+
171
+ # 3) 处理聚类阶段
172
+ cluster_batches, invalid_clusters_for_review = _process_clustering_phase(
173
+ compact_candidates,
174
+ entry_path,
175
+ langs,
176
+ cluster_limit,
177
+ sec_dir,
178
+ status_mgr,
179
+ _progress_append,
180
+ force_save_memory=force_save_memory,
181
+ )
182
+
183
+ # 4) 处理验证阶段
184
+ meta_records: List[Dict[str, Any]] = []
185
+ all_issues = _process_verification_phase(
186
+ cluster_batches,
187
+ entry_path,
188
+ langs,
189
+ sec_dir,
190
+ status_mgr,
191
+ _progress_append,
192
+ _append_report,
193
+ enable_verification=enable_verification,
194
+ force_save_memory=force_save_memory,
195
+ )
196
+
197
+ # 5) 使用统一聚合器生成最终报告(JSON + Markdown)
198
+ try:
199
+ from jarvis.jarvis_sec.report import build_json_and_markdown
200
+
201
+ result = build_json_and_markdown(
202
+ all_issues, # type: ignore
203
+ scanned_root=summary.get("scanned_root"),
204
+ scanned_files=summary.get("scanned_files"),
205
+ meta=meta_records or None,
206
+ output_file=output_file,
207
+ )
208
+ # 标记分析完成
209
+ status_mgr.mark_completed(
210
+ total_issues=len(all_issues),
211
+ message=f"安全分析完成,共发现 {len(all_issues)} 个问题",
212
+ )
213
+ return result
214
+ except Exception as e:
215
+ # 发生错误时更新状态
216
+ error_msg = str(e)
217
+ status_mgr.mark_error(error_message=error_msg, error_type=type(e).__name__)
218
+ raise
219
+ finally:
220
+ # 清理资源
221
+ pass
222
+
223
+
224
+ __all__ = [
225
+ "run_security_analysis",
226
+ "direct_scan",
227
+ "run_with_agent",
228
+ ]
@@ -0,0 +1,141 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Agent创建和订阅模块"""
3
+
4
+ from jarvis.jarvis_utils.exception_utils import save_exception
5
+ from typing import Any, Dict
6
+
7
+ from jarvis.jarvis_agent import Agent
8
+ from jarvis.jarvis_sec.prompts import build_summary_prompt
9
+ from jarvis.jarvis_sec.prompts import get_cluster_summary_prompt
10
+ from jarvis.jarvis_sec.prompts import get_cluster_system_prompt
11
+ from jarvis.jarvis_sec.prompts import get_review_summary_prompt
12
+ from jarvis.jarvis_sec.prompts import get_review_system_prompt
13
+ from jarvis.jarvis_tools.registry import ToolRegistry
14
+ from jarvis.jarvis_utils.tag import ot
15
+
16
+
17
+ def subscribe_summary_event(agent: Agent) -> Dict[str, str]:
18
+ """订阅Agent摘要事件"""
19
+ summary_container: Dict[str, str] = {"text": ""}
20
+ try:
21
+ from jarvis.jarvis_agent.events import AFTER_SUMMARY as _AFTER_SUMMARY
22
+ except Exception:
23
+ _AFTER_SUMMARY = None # type: ignore
24
+
25
+ if _AFTER_SUMMARY:
26
+
27
+ def _on_after_summary(**kwargs: Any) -> None:
28
+ try:
29
+ summary_container["text"] = str(kwargs.get("summary", "") or "")
30
+ except Exception:
31
+ summary_container["text"] = ""
32
+
33
+ try:
34
+ agent.event_bus.subscribe(_AFTER_SUMMARY, _on_after_summary)
35
+ except Exception as e:
36
+ save_exception(e, module="jarvis.jarvis_sec.agents", function="_on_after_summary")
37
+ pass
38
+ return summary_container
39
+
40
+
41
+ def create_analysis_agent(task_id: str, force_save_memory: bool = False) -> Agent:
42
+ """创建分析Agent"""
43
+ system_prompt = f"""
44
+ # 单Agent安全分析约束
45
+ - 你的核心任务是评估代码的安全问题,目标:针对本候选问题进行证据核实、风险评估与修复建议补充,查找漏洞触发路径,确认在某些条件下会触发;以此来判断是否是漏洞。
46
+ - **必须进行调用路径推导**:
47
+ - 对于每个候选问题,必须明确推导从可控输入到缺陷代码的完整调用路径。
48
+ - 调用路径推导必须包括:
49
+ 1. 识别可控输入的来源(例如:用户输入、网络数据、文件读取、命令行参数等)
50
+ 2. 追踪数据流:从输入源开始,逐步追踪数据如何传递到缺陷代码位置
51
+ 3. 识别调用链:明确列出从入口函数到缺陷代码的所有函数调用序列(例如:main() -> parse_input() -> process_data() -> vulnerable_function())
52
+ 4. 分析每个调用点的数据校验情况:检查每个函数是否对输入进行了校验、边界检查或安全检查
53
+ 5. 确认触发条件:明确说明在什么条件下,未校验或恶意输入能够到达缺陷代码位置
54
+ - 如果无法推导出完整的调用路径,或者所有调用路径都有充分的保护措施,则应该判定为误报。
55
+ - 调用路径推导必须在分析过程中明确展示,不能省略或假设。
56
+ - 工具优先:使用 read_code 读取目标文件附近源码(行号前后各 ~50 行),必要时用 execute_script 辅助检索。
57
+ - **调用路径追溯要求**:
58
+ - 必须向上追溯所有可能的调用者,查看完整的调用路径,以确认风险是否真实存在。
59
+ - 使用 read_code 和 execute_script 工具查找函数的调用者(例如:使用 grep 搜索函数名,查找所有调用该函数的位置)。
60
+ - 对于每个调用者,必须检查其是否对输入进行了校验。
61
+ - 如果发现任何调用路径未做校验,必须明确记录该路径。
62
+ - 例如:一个函数存在空指针解引用风险,必须检查所有调用者。如果所有调用者均能确保传入的指针非空,则该风险在当前代码库中可能不会实际触发;但如果存在任何调用者未做校验,则风险真实存在。
63
+ - 若多条告警位于同一文件且行号相距不远,可一次性读取共享上下文,对这些相邻告警进行联合分析与判断;但仍需避免无关扩展与大范围遍历。
64
+ - 禁止修改任何文件或执行写操作命令(rm/mv/cp/echo >、sed -i、git、patch、chmod、chown 等);仅进行只读分析与读取。
65
+ - 每次仅执行一个操作;等待工具结果后再进行下一步。
66
+ - **记忆使用**:
67
+ - 分析过程中,善用 memory 工具(action=retrieve)检索已有的记忆,特别是与当前分析函数相关的记忆。
68
+ - 若有需要,用 memory 工具(action=save)保存每个函数的分析要点,以函数名为 tag(例如:函数名、文件名等)。
69
+ - 记忆内容示例:某函数的指针已判空、某函数已有输入校验、某函数的调用路径分析结果等。
70
+ - 这样可以避免重复分析,提高效率,并保持分析的一致性。
71
+ - 完成对本批次候选问题的判断后,主输出仅打印结束符 {ot("!!!COMPLETE!!!")},不要输出其他任何内容。任务总结将在后续交互中给出。
72
+ """.strip()
73
+
74
+ agent_kwargs: Dict[str, Any] = dict(
75
+ system_prompt=system_prompt,
76
+ name=task_id,
77
+ auto_complete=True,
78
+ need_summary=True,
79
+ summary_prompt=build_summary_prompt(),
80
+ non_interactive=True,
81
+ in_multi_agent=False,
82
+ use_methodology=False,
83
+ use_analysis=False,
84
+ output_handler=[ToolRegistry()],
85
+ force_save_memory=force_save_memory,
86
+ use_tools=["read_code", "execute_script", "memory"],
87
+ quick_mode=True,
88
+ )
89
+ return Agent(**agent_kwargs)
90
+
91
+
92
+ def create_review_agent(
93
+ current_review_num: int,
94
+ ) -> Agent:
95
+ """创建复核Agent"""
96
+ review_system_prompt = get_review_system_prompt()
97
+ review_summary_prompt = get_review_summary_prompt()
98
+
99
+ review_task_id = f"JARVIS-SEC-Review-Batch-{current_review_num}"
100
+ review_agent_kwargs: Dict[str, Any] = dict(
101
+ system_prompt=review_system_prompt,
102
+ name=review_task_id,
103
+ auto_complete=True,
104
+ need_summary=True,
105
+ summary_prompt=review_summary_prompt,
106
+ non_interactive=True,
107
+ in_multi_agent=False,
108
+ use_methodology=False,
109
+ use_analysis=False,
110
+ output_handler=[ToolRegistry()],
111
+ use_tools=["read_code", "execute_script", "memory"],
112
+ quick_mode=True,
113
+ )
114
+ return Agent(**review_agent_kwargs)
115
+
116
+
117
+ def create_cluster_agent(
118
+ file: str,
119
+ chunk_idx: int,
120
+ force_save_memory: bool = False,
121
+ ) -> Agent:
122
+ """创建聚类Agent"""
123
+ cluster_system_prompt = get_cluster_system_prompt()
124
+ cluster_summary_prompt = get_cluster_summary_prompt()
125
+
126
+ agent_kwargs_cluster: Dict[str, Any] = dict(
127
+ system_prompt=cluster_system_prompt,
128
+ name=f"JARVIS-SEC-Cluster::{file}::batch{chunk_idx}",
129
+ auto_complete=True,
130
+ need_summary=True,
131
+ summary_prompt=cluster_summary_prompt,
132
+ non_interactive=True,
133
+ in_multi_agent=False,
134
+ use_methodology=False,
135
+ use_analysis=False,
136
+ output_handler=[ToolRegistry()],
137
+ force_save_memory=force_save_memory,
138
+ use_tools=["read_code", "execute_script", "memory"],
139
+ quick_mode=True,
140
+ )
141
+ return Agent(**agent_kwargs_cluster)