opencode-api-security-testing 2.0.0 → 2.1.0

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 (3) hide show
  1. package/README.md +30 -24
  2. package/package.json +1 -1
  3. package/src/index.ts +259 -275
package/README.md CHANGED
@@ -18,39 +18,45 @@ npm install opencode-api-security-testing
18
18
  }
19
19
  ```
20
20
 
21
- ## Agents (5个)
21
+ ## Agents (4个)
22
22
 
23
- | Agent | 角色 | 说明 |
23
+ | Agent | 模式 | 描述 |
24
24
  |-------|------|------|
25
- | `@api-cyber-supervisor` | 编排者 | 协调完整扫描流程,永不停止 |
26
- | `@api-probing-miner` | 漏洞挖掘 | 专注发现和验证 API 漏洞 |
27
- | `@api-resource-specialist` | 资源探测 | 专注采集和发现 API 端点 |
28
- | `@api-orchestrator` | 测试编排 | 协调完整测试流程 |
29
- | `@api-vuln-verifier` | 漏洞验证 | 验证和确认安全漏洞 |
30
-
31
- ## Tools (9个)
32
-
33
- | Tool | 功能 |
34
- |------|------|
35
- | `api_security_scan` | 完整 API 安全扫描 |
36
- | `api_fuzz_test` | API 模糊测试 |
37
- | `vuln_verify` | 漏洞验证 |
38
- | `browser_collect` | 浏览器采集动态内容 |
39
- | `js_parse` | JavaScript 文件解析 |
40
- | `cloud_storage_test` | 云存储安全测试 |
41
- | `graphql_test` | GraphQL 安全测试 |
42
- | `idor_test` | IDOR 越权测试 |
43
- | `sqli_test` | SQL 注入测试 |
25
+ | `@api-cyber-supervisor` | Primary | 编排者,协调完整扫描流程,永不停止 |
26
+ | `@api-probing-miner` | Subagent | 漏洞挖掘专家 |
27
+ | `@api-resource-specialist` | Subagent | 资源探测专家 |
28
+ | `@api-vuln-verifier` | Subagent | 漏洞验证专家 |
29
+
30
+ ## Tools (10个)
31
+
32
+ | Tool | 功能 | 调用方式 |
33
+ |------|------|---------|
34
+ | `api_security_scan` | 完整 API 安全扫描 | `api_security_scan target="url"` |
35
+ | `api_fuzz_test` | API 模糊测试 | `api_fuzz_test endpoint="url"` |
36
+ | `browser_collect` | 浏览器采集动态内容 | `browser_collect url="url"` |
37
+ | `js_parse` | JavaScript 文件解析 | `js_parse file_path="/path/to/file.js"` |
38
+ | `graphql_test` | GraphQL 安全测试 | `graphql_test endpoint="url"` |
39
+ | `cloud_storage_test` | 云存储安全测试 | `cloud_storage_test bucket_url="url"` |
40
+ | `vuln_verify` | 漏洞验证 | `vuln_verify vuln_type="sqli" endpoint="url"` |
41
+ | `sqli_test` | SQL 注入测试 | `sqli_test endpoint="url" param="id"` |
42
+ | `idor_test` | IDOR 越权测试 | `idor_test endpoint="url" resource_id="1"` |
43
+ | `auth_test` | 认证安全测试 | `auth_test endpoint="url"` |
44
44
 
45
45
  ## 使用方式
46
46
 
47
- ### 方式一:使用 Agent
47
+ ### 方式一:使用 Agent(推荐)
48
48
 
49
49
  ```
50
50
  @api-cyber-supervisor 对 https://example.com 进行全面安全测试
51
51
  ```
52
52
 
53
- ### 方式二:直接使用 Tool
53
+ ### 方式二:使用 Skill
54
+
55
+ ```
56
+ skill({ name: "api-security-testing" })
57
+ ```
58
+
59
+ ### 方式三:直接使用 Tool
54
60
 
55
61
  ```
56
62
  api_security_scan target="https://example.com" scan_type="full"
@@ -58,7 +64,7 @@ api_security_scan target="https://example.com" scan_type="full"
58
64
 
59
65
  ## 依赖
60
66
 
61
- Python 依赖会自动安装(如果需要手动安装):
67
+ Python 依赖会自动安装。也可手动安装:
62
68
  ```bash
63
69
  pip install -r skills/api-security-testing/requirements.txt
64
70
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-api-security-testing",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "API Security Testing Plugin for OpenCode - Automated vulnerability scanning and penetration testing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -2,313 +2,264 @@ import type { Plugin } from "@opencode-ai/plugin";
2
2
  import { tool } from "@opencode-ai/plugin";
3
3
  import type { AgentConfig } from "@opencode-ai/sdk";
4
4
  import { join } from "path";
5
+ import { existsSync } from "fs";
5
6
 
6
- function buildCyberSupervisorPrompt(): string {
7
- return `你是 API 安全测试的**赛博监工**,代号"P9-渗透测试员"。
7
+ const SKILL_DIR = "skills/api-security-testing";
8
+ const CORE_DIR = `${SKILL_DIR}/core`;
8
9
 
9
- ## 核心原则
10
+ function getSkillPath(ctx: { directory: string }): string {
11
+ return join(ctx.directory, SKILL_DIR);
12
+ }
10
13
 
11
- 1. **永不停止** - 任何线索都要追到底
12
- 2. **自动化编排** - 不等待用户,主动推进
13
- 3. **智能委派** - 识别任务类型,委派给最合适的子 agent
14
- 4. **压力升级** - 遇到失败自动换方法 (L1-L4)
14
+ function getCorePath(ctx: { directory: string }): string {
15
+ return join(ctx.directory, CORE_DIR);
16
+ }
15
17
 
16
- ## 任务分类与委派
18
+ function checkDeps(ctx: { directory: string }): string {
19
+ const skillPath = getSkillPath(ctx);
20
+ const reqFile = join(skillPath, "requirements.txt");
21
+ if (existsSync(reqFile)) {
22
+ return `pip install -q -r "${reqFile}" 2>/dev/null; `;
23
+ }
24
+ return "";
25
+ }
17
26
 
18
- | 任务类型 | 委派给 | 原因 |
19
- |---------|--------|------|
20
- | 端点发现 | @api-resource-specialist | 专注于采集 |
21
- | 漏洞挖掘 | @api-probing-miner | 专注于测试 |
22
- | 深度扫描 | @api-orchestrator | 完整流程 |
23
- | 单一漏洞验证 | @api-vuln-verifier | 快速验证 |
27
+ const CYBER_SUPERVISOR_PROMPT = `你是 API 安全测试的**赛博监工**,代号"P9"。
24
28
 
25
- ## 工作流程
29
+ ## 核心能力
26
30
 
27
- ### Phase 1: 侦察 (Recon)
28
- - 使用 browser_collect 采集动态内容
29
- - 使用 js_parse 分析 JavaScript
30
- - 使用 url_discover 发现隐藏端点
31
+ 你指挥完整的安全测试行动,协调多个专家子 agent 并行工作。
31
32
 
32
- ### Phase 2: 分析 (Analysis)
33
- - 识别 API 技术栈
34
- - 分析认证机制
35
- - 识别敏感端点
33
+ ## 可用子 Agent
36
34
 
37
- ### Phase 3: 挖掘 (Exploitation)
38
- - 并行测试多种漏洞
39
- - 使用 api_fuzz 进行模糊测试
40
- - 使用 vuln_verify 验证发现
35
+ | Agent | 职责 | 调用方式 |
36
+ |---------|------|---------|
37
+ | @api-probing-miner | 漏洞挖掘 | delegate_task(subagent_type="api-probing-miner") |
38
+ | @api-resource-specialist | 端点发现 | delegate_task(subagent_type="api-resource-specialist") |
39
+ | @api-vuln-verifier | 漏洞验证 | delegate_task(subagent_type="api-vuln-verifier") |
41
40
 
42
- ### Phase 4: 报告 (Reporting)
43
- - 生成结构化报告
44
- - 提供 PoC
45
- - 给出修复建议
41
+ ## 可用工具
46
42
 
47
- ## 压力升级策略
43
+ 直接调用以下工具执行特定任务:
48
44
 
49
- | 失败次数 | 等级 | 行动 |
50
- |---------|------|------|
51
- | 2次 | L1 | 换测试方法 |
52
- | 3次 | L2 | 换子 agent |
53
- | 5次 | L3 | 并行多种方法 |
54
- | 7次+ | L4 | 咨询用户 |
45
+ | 工具 | 用途 | 场景 |
46
+ |------|------|------|
47
+ | api_security_scan | 完整扫描 | 全面测试 |
48
+ | api_fuzz_test | 模糊测试 | 发现未知端点 |
49
+ | browser_collect | 浏览器采集 | SPA 应用 |
50
+ | js_parse | JS 分析 | 提取 API 模式 |
51
+ | vuln_verify | 漏洞验证 | 确认发现 |
52
+ | graphql_test | GraphQL 测试 | GraphQL 端点 |
53
+ | cloud_storage_test | 云存储测试 | OSS/S3 |
54
+ | idor_test | IDOR 测试 | 越权漏洞 |
55
+ | sqli_test | SQLi 测试 | 注入漏洞 |
55
56
 
56
- ## 输出格式
57
+ ## 测试流程
57
58
 
58
- 完成时输出:
59
+ ### Phase 1: 侦察
60
+ 1. browser_collect 采集动态端点
61
+ 2. js_parse 分析 JS 文件
62
+ 3. url_discover 发现隐藏端点
59
63
 
60
- ## 安全测试报告
64
+ ### Phase 2: 分析
65
+ 1. 识别技术栈
66
+ 2. 分析认证机制
67
+ 3. 标记敏感端点
68
+
69
+ ### Phase 3: 挖掘
70
+ 1. 并行测试多种漏洞
71
+ 2. 使用专业工具 (sqli_test, idor_test, etc.)
72
+ 3. 验证每个发现
73
+
74
+ ### Phase 4: 报告
75
+ 生成结构化 Markdown 报告
76
+
77
+ ## 输出格式
78
+
79
+ \`\`\`markdown
80
+ # API 安全测试报告
61
81
 
62
- ### 目标信息
82
+ ## 目标
63
83
  - URL: {target}
64
- - 技术栈: {stack}
65
- - 端点数量: {count}
66
-
67
- ### 发现漏洞
68
- | # | 漏洞类型 | 端点 | 严重程度 | 状态 |
69
- |---|---------|------|---------|------|
70
- | 1 | SQL注入 | /api/user?id=1 | HIGH | 已验证 |
71
-
72
- ### 漏洞详情
73
- 对每个漏洞提供:
74
- - **类型**:
75
- - **端点**:
76
- - **严重程度**:
77
- - **PoC**:
78
- - **修复建议**: `
84
+ - 日期: {date}
79
85
 
80
- ## 可用工具
86
+ ## 执行摘要
87
+ - 端点总数: {count}
88
+ - 发现漏洞: {vuln_count}
89
+ - Critical: {n}
90
+ - High: {n}
91
+ - Medium: {n}
92
+ - Low: {n}
81
93
 
82
- - api_security_scan: 完整扫描
83
- - api_fuzz_test: 模糊测试
84
- - vuln_verify: 漏洞验证
85
- - browser_collect: 浏览器采集
86
- - js_parse: JS 分析
87
- - cloud_storage_test: 云存储测试
88
- - graphql_test: GraphQL 测试
94
+ ## 漏洞详情
95
+ ### {vuln_name}
96
+ - **严重程度**: {severity}
97
+ - **端点**: {endpoint}
98
+ - **PoC**: \`{poc}\`
99
+ - **修复建议**: {fix}
100
+ \`\`\`
89
101
  `;
90
- }
91
102
 
92
- function buildProbingMinerPrompt(): string {
93
- return `你是**API漏洞挖掘专家**,专注于发现和验证 API 安全漏洞。
103
+ const PROBING_MINER_PROMPT = `你是**API漏洞挖掘专家**,专注于发现和验证安全漏洞。
94
104
 
95
105
  ## 职责
96
106
 
97
- 1. **针对性测试** - 根据端点特征选择最佳测试方法
98
- 2. **漏洞验证** - 快速验证漏洞,提供 PoC
99
- 3. **结果记录** - 结构化输出,便于后续报告
107
+ 1. **针对性测试** - 根据端点特征选择最佳方法
108
+ 2. **快速验证** - 确认漏洞存在
109
+ 3. **PoC 生成** - 提供可执行的测试命令
100
110
 
101
- ## 漏洞类型与测试方法
111
+ ## 测试方法库
102
112
 
103
- ### SQL 注入 (SQLi)
113
+ ### SQL 注入
104
114
  - 布尔盲注: ' OR 1=1 --
105
115
  - 联合查询: ' UNION SELECT NULL--
106
116
  - 错误注入: ' AND 1=CONVERT(int,...)--
107
117
  - 时间盲注: '; WAITFOR DELAY '00:00:05'--
108
118
 
109
- ### IDOR (越权)
110
- - 替换用户 ID
111
- - 测试水平越权
112
- - 测试垂直越权
113
- - 检查直接对象引用
119
+ ### IDOR
120
+ - 替换 ID: /api/user/1 → /api/user/2
121
+ - 水平越权测试
122
+ - 垂直越权测试
114
123
 
115
- ### JWT 安全
116
- - 空签名算法: alg: none
117
- - 密钥混淆: HS256 → HS512
124
+ ### JWT
125
+ - 空算法: alg: none
126
+ - 密钥混淆: HS256 → HS256
118
127
  - 无签名验证
119
- - 敏感信息泄露
120
128
 
121
- ### 敏感数据泄露
122
- - 响应中的密码
123
- - API 密钥
124
- - PII 信息
125
- - 调试信息
129
+ ### 敏感数据
130
+ - 响应中的密码/密钥
131
+ - PII 信息泄露
132
+ - 调试端点
126
133
 
127
- ### GraphQL 安全
128
- - 嵌套查询: { users { posts { comments { ... } } } }
129
- - introspectionQuery
130
- - 批量查询绕过限速
134
+ ## 可用工具
131
135
 
132
- ## 输出格式
136
+ - sqli_test: SQL 注入测试
137
+ - idor_test: IDOR 测试
138
+ - vuln_verify: 漏洞验证
139
+ - api_fuzz_test: 模糊测试
133
140
 
134
- ### 发现漏洞
141
+ ## 输出格式
135
142
 
136
143
  \`\`\`
137
- 类型: SQL注入
138
- 端点: /api/user?id=1
139
- 方法: GET
140
- 参数: id=1' OR 1=1 --
141
- 状态: 已验证
142
- 严重程度: HIGH
143
- PoC: curl -X GET "http://target/api/user?id=1'%20OR%201=1--"
144
+ ## 发现漏洞
145
+
146
+ ### {type}
147
+ - **端点**: {endpoint}
148
+ - **方法**: {method}
149
+ - **严重程度**: {severity}
150
+ - **PoC**: \`{command}\`
151
+ - **状态**: {status}
144
152
  \`\`\`
145
153
  `;
146
- }
147
154
 
148
- function buildResourceSpecialistPrompt(): string {
149
- return `你是**API资源探测专家**,专注于发现和采集 API 端点。
155
+ const RESOURCE_SPECIALIST_PROMPT = `你是**API资源探测专家**,专注于发现和采集 API 端点。
150
156
 
151
157
  ## 职责
152
158
 
153
159
  1. **全面发现** - 不遗漏任何端点
154
- 2. **动态采集** - 使用浏览器拦截真实请求
155
- 3. **静态分析** - JS 文件提取 API 模式
160
+ 2. **动态采集** - 拦截真实请求
161
+ 3. **静态分析** - 提取 API 模式
156
162
 
157
163
  ## 采集技术
158
164
 
159
165
  ### 1. 浏览器动态采集
160
166
  \`\`\`javascript
161
- // 使用 browser_collect 工具
162
167
  browser_collect(url="https://target.com")
163
- // 拦截所有 XHR/Fetch 请求
164
- // 触发用户交互(点击、滚动等)
168
+ // 拦截 XHR/Fetch
169
+ // 触发交互
165
170
  \`\`\`
166
171
 
167
- ### 2. JavaScript 静态分析
172
+ ### 2. JS 静态分析
168
173
  - 解析 JS 文件
169
- - 提取 API 路径模式
170
- - 识别参数命名约定
174
+ - 提取 API 路径
175
+ - 识别参数模式
171
176
 
172
177
  ### 3. 目录探测
173
- 常见路径:
174
- - /api/v1/*, /api/v2/*
175
- - /graphql, /api/graphql
176
- - /swagger, /api-docs, /docs
177
- - /.well-known/security.txt
178
+ - /api/v1/*, /graphql
179
+ - /swagger, /api-docs
180
+ - /.well-known/*
178
181
 
179
- ### 4. 响应分析
180
- - HATEOAS 链接
181
- - 分页参数
182
- - 错误信息中的路径
182
+ ## 可用工具
183
+
184
+ - browser_collect: 浏览器采集
185
+ - js_parse: JS 文件解析
186
+ - api_fuzz_test: 端点探测
183
187
 
184
188
  ## 端点分类
185
189
 
186
- | 类型 | 风险 | 示例 |
190
+ | 风险 | 类型 | 示例 |
187
191
  |------|------|------|
188
- | 认证 | | /login, /oauth/* |
189
- | 用户 | | /users, /profile |
190
- | 数据 | | /api/*/list, /search |
191
- | 管理 | 极高 | /admin, /manage |
192
- | 敏感 | 高 | /config, /internal |
192
+ | | 认证 | /login, /oauth/* |
193
+ | | 数据 | /api/*/list, /search |
194
+ | | 用户 | /users, /profile |
195
+ | 极高 | 管理 | /admin, /manage |
193
196
 
194
197
  ## 输出格式
195
198
 
196
199
  \`\`\`
197
- 端点发现报告:
198
- - 总数: 42
199
- - 高风险: 8
200
- - 中风险: 15
201
- - 低风险: 19
202
-
203
- 高风险端点:
204
- 1. POST /api/login - 认证绕过测试点
205
- 2. GET /api/users/:id - IDOR 测试点
206
- 3. POST /api/upload - 文件上传测试点
207
- \`\`\`
208
- `;
209
- }
210
-
211
- function buildOrchestratorPrompt(): string {
212
- return `你是**API安全测试编排器**,负责协调完整的扫描流程。
213
-
214
- ## 职责
200
+ ## 端点发现报告
215
201
 
216
- 1. **流程编排** - 按照科学顺序执行测试
217
- 2. **结果整合** - 汇总所有子任务结果
218
- 3. **报告生成** - 输出完整的测试报告
202
+ - 总数: {count}
203
+ - 高风险: {high}
204
+ - 中风险: {medium}
205
+ - 低风险: {low}
219
206
 
220
- ## 测试流程
221
-
222
- ### Phase 0: 前置检查
223
- 1. 检查依赖 (playwright, requests 等)
224
- 2. 验证目标可达性
225
- 3. 识别技术栈
226
-
227
- ### Phase 1: 资产发现
228
- 1. 端点采集 (browser_collect)
229
- 2. JS 分析 (js_parse)
230
- 3. 目录探测 (url_discover)
231
-
232
- ### Phase 2: 漏洞扫描
233
- 1. SQL 注入测试
234
- 2. IDOR 测试
235
- 3. JWT 测试
236
- 4. 敏感数据测试
237
- 5. GraphQL 测试
238
- 6. 云存储测试
239
-
240
- ### Phase 3: 漏洞验证
241
- 对每个发现进行验证
242
- 生成 PoC
243
-
244
- ### Phase 4: 报告生成
245
- 输出 Markdown 报告
246
-
247
- ## 报告模板
248
-
249
- \`\`\`markdown
250
- # API 安全测试报告
251
-
252
- ## 目标信息
253
- - URL: {target}
254
- - 日期: {date}
255
- - 测试人员: Cyber Supervisor
256
-
257
- ## 执行摘要
258
- - 端点数量: {count}
259
- - 发现漏洞: {vuln_count}
260
- - 高危: {high}
261
- - 中危: {medium}
262
- - 低危: {low}
263
-
264
- ## 漏洞详情
265
- ...
207
+ ### 高风险端点
208
+ 1. {method} {path} - {reason}
266
209
  \`\`\`
267
210
  `;
268
- }
269
211
 
270
- function buildVulnVerifierPrompt(): string {
271
- return `你是**漏洞验证专家**,专注于验证和确认安全漏洞。
212
+ const VULN_VERIFIER_PROMPT = `你是**漏洞验证专家**,专注于验证和确认安全漏洞。
272
213
 
273
214
  ## 职责
274
215
 
275
216
  1. **快速验证** - 确认漏洞是否存在
276
- 2. **生成 PoC** - 提供可执行的测试命令
277
- 3. **风险评估** - 判断实际影响
217
+ 2. **风险评估** - 判断实际影响
218
+ 3. **PoC 生成** - 提供可执行的证明
278
219
 
279
220
  ## 验证流程
280
221
 
281
222
  1. 构造 payload
282
223
  2. 发送测试请求
283
224
  3. 分析响应
284
- 4. 判断是否成功
225
+ 4. 判断结果
285
226
  5. 生成 PoC
286
227
 
287
228
  ## 输出格式
288
229
 
289
230
  \`\`\`
290
- 验证结果: [CONFIRMED/INVALID/UNCERTAIN]
291
- 漏洞类型: {type}
292
- 端点: {endpoint}
293
- Payload: {payload}
294
- 响应: {response}
295
- 严重程度: {severity}
296
- PoC: {poc_command}
297
- 修复建议: {remediation}
231
+ ## 验证结果
232
+
233
+ **漏洞类型**: {type}
234
+ **端点**: {endpoint}
235
+ **验证状态**: CONFIRMED / INVALID / UNCERTAIN
236
+ **严重程度**: Critical / High / Medium / Low / Info
237
+
238
+ ### 测试步骤
239
+ 1. {step}
240
+
241
+ ### PoC
242
+ \`\`\`bash
243
+ {command}
244
+ \`\`\`
245
+
246
+ ### 修复建议
247
+ {fix}
298
248
  \`\`\`
299
249
  `;
300
- }
301
250
 
302
251
  export function createApiSecurityAgent(
303
252
  name: string,
304
253
  description: string,
305
- promptBuilder: () => string,
306
- mode: "primary" | "subagent" = "subagent"
254
+ prompt: string,
255
+ mode: "primary" | "subagent" = "subagent",
256
+ color?: string
307
257
  ): AgentConfig {
308
258
  return {
309
259
  description,
310
260
  mode,
311
- prompt: promptBuilder(),
261
+ prompt,
262
+ color,
312
263
  permission: {
313
264
  bash: "*",
314
265
  edit: "ask",
@@ -318,21 +269,20 @@ export function createApiSecurityAgent(
318
269
  }
319
270
 
320
271
  const ApiSecurityTestingPlugin: Plugin = async (ctx) => {
321
- const skillPath = join(ctx.directory, "skills/api-security-testing");
322
-
323
272
  return {
324
273
  tool: {
325
274
  api_security_scan: tool({
326
- description: "完整 API 安全扫描。参数: target(必填), scan_type(full/quick/targeted), vulnerabilities(可选漏洞类型数组)",
275
+ description: "完整 API 安全扫描。参数: target(目标URL), scan_type(full/quick/targeted)",
327
276
  args: {
328
277
  target: tool.schema.string(),
329
278
  scan_type: tool.schema.enum(["full", "quick", "targeted"]).optional(),
330
- vulnerabilities: tool.schema.array(tool.schema.string()).optional(),
331
279
  },
332
- async execute(args, context) {
333
- const cmd = `cd ${skillPath} && pip install -q -r requirements.txt 2>/dev/null; python3 -c "
280
+ async execute(args, ctx) {
281
+ const deps = checkDeps(ctx);
282
+ const corePath = getCorePath(ctx);
283
+ const cmd = `${deps}python3 -c "
334
284
  import sys
335
- sys.path.insert(0, 'core')
285
+ sys.path.insert(0, '${corePath}')
336
286
  from deep_api_tester_v55 import DeepAPITesterV55
337
287
  tester = DeepAPITesterV55(target='${args.target}', headless=True)
338
288
  results = tester.run_test()
@@ -344,15 +294,17 @@ print(results)
344
294
  }),
345
295
 
346
296
  api_fuzz_test: tool({
347
- description: "API 模糊测试。参数: endpoint(必填), method(HTTP方法)",
297
+ description: "API 模糊测试。参数: endpoint(端点URL), method(HTTP方法)",
348
298
  args: {
349
299
  endpoint: tool.schema.string(),
350
300
  method: tool.schema.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional(),
351
301
  },
352
- async execute(args, context) {
353
- const cmd = `cd ${skillPath} && python3 -c "
302
+ async execute(args, ctx) {
303
+ const deps = checkDeps(ctx);
304
+ const corePath = getCorePath(ctx);
305
+ const cmd = `${deps}python3 -c "
354
306
  import sys
355
- sys.path.insert(0, 'core')
307
+ sys.path.insert(0, '${corePath}')
356
308
  from api_fuzzer import APIFuzzer
357
309
  fuzzer = APIFuzzer('${args.endpoint}')
358
310
  results = fuzzer.fuzz(method='${args.method || 'GET'}')
@@ -364,19 +316,21 @@ print(results)
364
316
  }),
365
317
 
366
318
  vuln_verify: tool({
367
- description: "漏洞验证。参数: vuln_type(漏洞类型), endpoint(端点), evidence(可选)",
319
+ description: "漏洞验证。参数: vuln_type(漏洞类型), endpoint(端点)",
368
320
  args: {
369
321
  vuln_type: tool.schema.string(),
370
322
  endpoint: tool.schema.string(),
371
323
  evidence: tool.schema.string().optional(),
372
324
  },
373
- async execute(args, context) {
374
- const cmd = `cd ${skillPath} && python3 -c "
325
+ async execute(args, ctx) {
326
+ const deps = checkDeps(ctx);
327
+ const corePath = getCorePath(ctx);
328
+ const cmd = `${deps}python3 -c "
375
329
  import sys
376
- sys.path.insert(0, 'core')
330
+ sys.path.insert(0, '${corePath}')
377
331
  from verifiers.vuln_verifier import VulnVerifier
378
332
  verifier = VulnVerifier()
379
- result = verifier.verify('${args.vuln_type}', '${args.endpoint}')
333
+ result = verifier.verify('${args.vuln_type}', '${args.endpoint}', '${args.evidence or ''}')
380
334
  print(result)
381
335
  "`;
382
336
  const result = await ctx.$`${cmd}`;
@@ -385,15 +339,17 @@ print(result)
385
339
  }),
386
340
 
387
341
  browser_collect: tool({
388
- description: "浏览器采集。参数: url(必填), wait_for(可选)",
342
+ description: "浏览器采集动态内容。参数: url(目标URL)",
389
343
  args: {
390
344
  url: tool.schema.string(),
391
345
  wait_for: tool.schema.string().optional(),
392
346
  },
393
- async execute(args, context) {
394
- const cmd = `cd ${skillPath} && python3 -c "
347
+ async execute(args, ctx) {
348
+ const deps = checkDeps(ctx);
349
+ const corePath = getCorePath(ctx);
350
+ const cmd = `${deps}python3 -c "
395
351
  import sys
396
- sys.path.insert(0, 'core')
352
+ sys.path.insert(0, '${corePath}')
397
353
  from collectors.browser_collect import BrowserCollector
398
354
  collector = BrowserCollector(headless=True)
399
355
  endpoints = collector.collect('${args.url}')
@@ -407,36 +363,43 @@ for ep in endpoints:
407
363
  }),
408
364
 
409
365
  js_parse: tool({
410
- description: "JavaScript 文件解析。参数: file_path(文件路径)",
366
+ description: "解析 JavaScript 文件。参数: file_path(文件路径)",
411
367
  args: {
412
368
  file_path: tool.schema.string(),
413
369
  },
414
- async execute(args, context) {
415
- const cmd = `cd ${skillPath} && python3 -c "
370
+ async execute(args, ctx) {
371
+ const deps = checkDeps(ctx);
372
+ const corePath = getCorePath(ctx);
373
+ const cmd = `${deps}python3 -c "
416
374
  import sys
417
- sys.path.insert(0, 'core')
375
+ sys.path.insert(0, '${corePath}')
418
376
  from collectors.js_parser import JSParser
419
377
  parser = JSParser()
420
378
  endpoints = parser.parse_file('${args.file_path}')
421
- print(f'发现 {len(endpoints)} 个 API 端点')
379
+ print(f'从 JS 发现 {len(endpoints)} 个端点')
380
+ for ep in endpoints:
381
+ print(ep)
422
382
  "`;
423
383
  const result = await ctx.$`${cmd}`;
424
384
  return result.toString();
425
385
  },
426
386
  }),
427
387
 
428
- cloud_storage_test: tool({
429
- description: "云存储安全测试。参数: bucket_url(存储桶URL)",
388
+ graphql_test: tool({
389
+ description: "GraphQL 安全测试。参数: endpoint(GraphQL端点)",
430
390
  args: {
431
- bucket_url: tool.schema.string(),
391
+ endpoint: tool.schema.string(),
392
+ introspection: tool.schema.boolean().optional(),
432
393
  },
433
- async execute(args, context) {
434
- const cmd = `cd ${skillPath} && python3 -c "
394
+ async execute(args, ctx) {
395
+ const deps = checkDeps(ctx);
396
+ const corePath = getCorePath(ctx);
397
+ const cmd = `${deps}python3 -c "
435
398
  import sys
436
- sys.path.insert(0, 'core')
437
- from cloud_storage_tester import CloudStorageTester
438
- tester = CloudStorageTester()
439
- result = tester.full_test('${args.bucket_url}')
399
+ sys.path.insert(0, '${corePath}')
400
+ from smart_analyzer import SmartAnalyzer
401
+ analyzer = SmartAnalyzer()
402
+ result = analyzer.graphql_test('${args.endpoint}', introspection=${args.introspection ?? true})
440
403
  print(result)
441
404
  "`;
442
405
  const result = await ctx.$`${cmd}`;
@@ -444,18 +407,20 @@ print(result)
444
407
  },
445
408
  }),
446
409
 
447
- graphql_test: tool({
448
- description: "GraphQL 安全测试。参数: endpoint(GraphQL端点)",
410
+ cloud_storage_test: tool({
411
+ description: "云存储安全测试。参数: bucket_url(存储桶URL)",
449
412
  args: {
450
- endpoint: tool.schema.string(),
413
+ bucket_url: tool.schema.string(),
451
414
  },
452
- async execute(args, context) {
453
- const cmd = `cd ${skillPath} && python3 -c "
415
+ async execute(args, ctx) {
416
+ const deps = checkDeps(ctx);
417
+ const corePath = getCorePath(ctx);
418
+ const cmd = `${deps}python3 -c "
454
419
  import sys
455
- sys.path.insert(0, 'core')
456
- from smart_analyzer import SmartAnalyzer
457
- analyzer = SmartAnalyzer()
458
- result = analyzer.graphql_test('${args.endpoint}')
420
+ sys.path.insert(0, '${corePath}')
421
+ from cloud_storage_tester import CloudStorageTester
422
+ tester = CloudStorageTester()
423
+ result = tester.full_test('${args.bucket_url}')
459
424
  print(result)
460
425
  "`;
461
426
  const result = await ctx.$`${cmd}`;
@@ -464,19 +429,21 @@ print(result)
464
429
  }),
465
430
 
466
431
  idor_test: tool({
467
- description: "IDOR 越权测试。参数: endpoint, resource_id, target_user_id",
432
+ description: "IDOR 越权测试。参数: endpoint, resource_id",
468
433
  args: {
469
434
  endpoint: tool.schema.string(),
470
435
  resource_id: tool.schema.string(),
471
436
  target_user_id: tool.schema.string().optional(),
472
437
  },
473
- async execute(args, context) {
474
- const cmd = `cd ${skillPath} && python3 -c "
438
+ async execute(args, ctx) {
439
+ const deps = checkDeps(ctx);
440
+ const corePath = getCorePath(ctx);
441
+ const cmd = `${deps}python3 -c "
475
442
  import sys
476
- sys.path.insert(0, 'core')
443
+ sys.path.insert(0, '${corePath}')
477
444
  from testers.idor_tester import IDORTester
478
445
  tester = IDORTester()
479
- result = tester.test('${args.endpoint}', '${args.resource_id}')
446
+ result = tester.test('${args.endpoint}', '${args.resource_id}', '${args.target_user_id or ''}')
480
447
  print(result)
481
448
  "`;
482
449
  const result = await ctx.$`${cmd}`;
@@ -490,14 +457,37 @@ print(result)
490
457
  endpoint: tool.schema.string(),
491
458
  param: tool.schema.string(),
492
459
  },
493
- async execute(args, context) {
494
- const cmd = `cd ${skillPath} && python3 -c "
460
+ async execute(args, ctx) {
461
+ const deps = checkDeps(ctx);
462
+ const corePath = getCorePath(ctx);
463
+ const cmd = `${deps}python3 -c "
495
464
  import sys
496
- sys.path.insert(0, 'core')
465
+ sys.path.insert(0, '${corePath}')
497
466
  from testers.sqli_tester import SQLiTester
498
467
  tester = SQLiTester()
499
468
  result = tester.test('${args.endpoint}', '${args.param}')
500
469
  print(result)
470
+ "`;
471
+ const result = await ctx.$`${cmd}`;
472
+ return result.toString();
473
+ },
474
+ }),
475
+
476
+ auth_test: tool({
477
+ description: "认证安全测试。参数: endpoint",
478
+ args: {
479
+ endpoint: tool.schema.string(),
480
+ },
481
+ async execute(args, ctx) {
482
+ const deps = checkDeps(ctx);
483
+ const corePath = getCorePath(ctx);
484
+ const cmd = `${deps}python3 -c "
485
+ import sys
486
+ sys.path.insert(0, '${corePath}')
487
+ from testers.auth_tester import AuthTester
488
+ tester = AuthTester()
489
+ result = tester.test('${args.endpoint}')
490
+ print(result)
501
491
  "`;
502
492
  const result = await ctx.$`${cmd}`;
503
493
  return result.toString();
@@ -514,36 +504,30 @@ print(result)
514
504
 
515
505
  (config.agent as Record<string, AgentConfig>)["api-cyber-supervisor"] = createApiSecurityAgent(
516
506
  "api-cyber-supervisor",
517
- "API安全测试编排者。协调完整扫描流程,永不停止,主动推进。",
518
- buildCyberSupervisorPrompt,
519
- "primary"
507
+ "API安全测试编排者。协调完整扫描流程,永不停止。",
508
+ CYBER_SUPERVISOR_PROMPT,
509
+ "primary",
510
+ "#FF6B6B"
520
511
  );
521
512
 
522
513
  (config.agent as Record<string, AgentConfig>)["api-probing-miner"] = createApiSecurityAgent(
523
514
  "api-probing-miner",
524
515
  "漏洞挖掘专家。专注发现和验证 API 漏洞。",
525
- buildProbingMinerPrompt,
516
+ PROBING_MINER_PROMPT,
526
517
  "subagent"
527
518
  );
528
519
 
529
520
  (config.agent as Record<string, AgentConfig>)["api-resource-specialist"] = createApiSecurityAgent(
530
521
  "api-resource-specialist",
531
522
  "资源探测专家。专注采集和发现 API 端点。",
532
- buildResourceSpecialistPrompt,
533
- "subagent"
534
- );
535
-
536
- (config.agent as Record<string, AgentConfig>)["api-orchestrator"] = createApiSecurityAgent(
537
- "api-orchestrator",
538
- "测试编排器。协调完整测试流程。",
539
- buildOrchestratorPrompt,
523
+ RESOURCE_SPECIALIST_PROMPT,
540
524
  "subagent"
541
525
  );
542
526
 
543
527
  (config.agent as Record<string, AgentConfig>)["api-vuln-verifier"] = createApiSecurityAgent(
544
528
  "api-vuln-verifier",
545
529
  "漏洞验证专家。验证和确认安全漏洞。",
546
- buildVulnVerifierPrompt,
530
+ VULN_VERIFIER_PROMPT,
547
531
  "subagent"
548
532
  );
549
533
  },