opencode-api-security-testing 2.0.0 → 2.1.1
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.
- package/README.md +30 -24
- package/SKILL.md +1797 -0
- package/core/advanced_recon.py +788 -0
- package/core/agentic_analyzer.py +445 -0
- package/core/analyzers/api_parser.py +210 -0
- package/core/analyzers/response_analyzer.py +212 -0
- package/core/analyzers/sensitive_finder.py +184 -0
- package/core/api_fuzzer.py +422 -0
- package/core/api_interceptor.py +525 -0
- package/core/api_parser.py +955 -0
- package/core/browser_tester.py +479 -0
- package/core/cloud_storage_tester.py +1330 -0
- package/core/collectors/__init__.py +23 -0
- package/core/collectors/api_path_finder.py +300 -0
- package/core/collectors/browser_collect.py +645 -0
- package/core/collectors/browser_collector.py +411 -0
- package/core/collectors/http_client.py +111 -0
- package/core/collectors/js_collector.py +490 -0
- package/core/collectors/js_parser.py +780 -0
- package/core/collectors/url_collector.py +319 -0
- package/core/context_manager.py +682 -0
- package/core/deep_api_tester_v35.py +844 -0
- package/core/deep_api_tester_v55.py +366 -0
- package/core/dynamic_api_analyzer.py +532 -0
- package/core/http_client.py +179 -0
- package/core/models.py +296 -0
- package/core/orchestrator.py +890 -0
- package/core/prerequisite.py +227 -0
- package/core/reasoning_engine.py +1042 -0
- package/core/response_classifier.py +606 -0
- package/core/runner.py +938 -0
- package/core/scan_engine.py +599 -0
- package/core/skill_executor.py +435 -0
- package/core/skill_executor_v2.py +670 -0
- package/core/skill_executor_v3.py +704 -0
- package/core/smart_analyzer.py +687 -0
- package/core/strategy_pool.py +707 -0
- package/core/testers/auth_tester.py +264 -0
- package/core/testers/idor_tester.py +200 -0
- package/core/testers/sqli_tester.py +211 -0
- package/core/testing_loop.py +655 -0
- package/core/utils/base_path_dict.py +255 -0
- package/core/utils/payload_lib.py +167 -0
- package/core/utils/ssrf_detector.py +220 -0
- package/core/verifiers/vuln_verifier.py +536 -0
- package/package.json +17 -13
- package/references/asset-discovery.md +119 -612
- package/references/graphql-guidance.md +65 -641
- package/references/intake.md +84 -0
- package/references/report-template.md +131 -38
- package/references/rest-guidance.md +55 -526
- package/references/severity-model.md +52 -264
- package/references/test-matrix.md +65 -263
- package/references/validation.md +53 -400
- package/scripts/postinstall.js +46 -0
- package/src/index.ts +259 -275
- package/agents/cyber-supervisor.md +0 -55
- package/agents/probing-miner.md +0 -42
- package/agents/resource-specialist.md +0 -31
- package/commands/api-security-testing-scan.md +0 -59
- package/commands/api-security-testing-test.md +0 -49
- package/commands/api-security-testing.md +0 -72
- package/tsconfig.json +0 -17
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
28
|
-
- 使用 browser_collect 采集动态内容
|
|
29
|
-
- 使用 js_parse 分析 JavaScript
|
|
30
|
-
- 使用 url_discover 发现隐藏端点
|
|
31
|
+
你指挥完整的安全测试行动,协调多个专家子 agent 并行工作。
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
- 识别 API 技术栈
|
|
34
|
-
- 分析认证机制
|
|
35
|
-
- 识别敏感端点
|
|
33
|
+
## 可用子 Agent
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
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
|
-
|
|
43
|
-
- 生成结构化报告
|
|
44
|
-
- 提供 PoC
|
|
45
|
-
- 给出修复建议
|
|
41
|
+
## 可用工具
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
直接调用以下工具执行特定任务:
|
|
48
44
|
|
|
49
|
-
|
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
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
|
-
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
|
|
94
|
+
## 漏洞详情
|
|
95
|
+
### {vuln_name}
|
|
96
|
+
- **严重程度**: {severity}
|
|
97
|
+
- **端点**: {endpoint}
|
|
98
|
+
- **PoC**: \`{poc}\`
|
|
99
|
+
- **修复建议**: {fix}
|
|
100
|
+
\`\`\`
|
|
89
101
|
`;
|
|
90
|
-
}
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
return `你是**API漏洞挖掘专家**,专注于发现和验证 API 安全漏洞。
|
|
103
|
+
const PROBING_MINER_PROMPT = `你是**API漏洞挖掘专家**,专注于发现和验证安全漏洞。
|
|
94
104
|
|
|
95
105
|
## 职责
|
|
96
106
|
|
|
97
|
-
1. **针对性测试** -
|
|
98
|
-
2.
|
|
99
|
-
3.
|
|
107
|
+
1. **针对性测试** - 根据端点特征选择最佳方法
|
|
108
|
+
2. **快速验证** - 确认漏洞存在
|
|
109
|
+
3. **PoC 生成** - 提供可执行的测试命令
|
|
100
110
|
|
|
101
|
-
##
|
|
111
|
+
## 测试方法库
|
|
102
112
|
|
|
103
|
-
### SQL 注入
|
|
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
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
- 检查直接对象引用
|
|
119
|
+
### IDOR
|
|
120
|
+
- 替换 ID: /api/user/1 → /api/user/2
|
|
121
|
+
- 水平越权测试
|
|
122
|
+
- 垂直越权测试
|
|
114
123
|
|
|
115
|
-
### JWT
|
|
116
|
-
-
|
|
117
|
-
- 密钥混淆: HS256 →
|
|
124
|
+
### JWT
|
|
125
|
+
- 空算法: alg: none
|
|
126
|
+
- 密钥混淆: HS256 → HS256
|
|
118
127
|
- 无签名验证
|
|
119
|
-
- 敏感信息泄露
|
|
120
128
|
|
|
121
|
-
###
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
- 调试信息
|
|
129
|
+
### 敏感数据
|
|
130
|
+
- 响应中的密码/密钥
|
|
131
|
+
- PII 信息泄露
|
|
132
|
+
- 调试端点
|
|
126
133
|
|
|
127
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
## 发现漏洞
|
|
145
|
+
|
|
146
|
+
### {type}
|
|
147
|
+
- **端点**: {endpoint}
|
|
148
|
+
- **方法**: {method}
|
|
149
|
+
- **严重程度**: {severity}
|
|
150
|
+
- **PoC**: \`{command}\`
|
|
151
|
+
- **状态**: {status}
|
|
144
152
|
\`\`\`
|
|
145
153
|
`;
|
|
146
|
-
}
|
|
147
154
|
|
|
148
|
-
|
|
149
|
-
return `你是**API资源探测专家**,专注于发现和采集 API 端点。
|
|
155
|
+
const RESOURCE_SPECIALIST_PROMPT = `你是**API资源探测专家**,专注于发现和采集 API 端点。
|
|
150
156
|
|
|
151
157
|
## 职责
|
|
152
158
|
|
|
153
159
|
1. **全面发现** - 不遗漏任何端点
|
|
154
|
-
2. **动态采集** -
|
|
155
|
-
3. **静态分析** -
|
|
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
|
-
//
|
|
164
|
-
//
|
|
168
|
+
// 拦截 XHR/Fetch
|
|
169
|
+
// 触发交互
|
|
165
170
|
\`\`\`
|
|
166
171
|
|
|
167
|
-
### 2.
|
|
172
|
+
### 2. JS 静态分析
|
|
168
173
|
- 解析 JS 文件
|
|
169
|
-
- 提取 API
|
|
170
|
-
-
|
|
174
|
+
- 提取 API 路径
|
|
175
|
+
- 识别参数模式
|
|
171
176
|
|
|
172
177
|
### 3. 目录探测
|
|
173
|
-
|
|
174
|
-
- /
|
|
175
|
-
-
|
|
176
|
-
- /swagger, /api-docs, /docs
|
|
177
|
-
- /.well-known/security.txt
|
|
178
|
+
- /api/v1/*, /graphql
|
|
179
|
+
- /swagger, /api-docs
|
|
180
|
+
- /.well-known/*
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
|
189
|
-
|
|
|
190
|
-
|
|
|
191
|
-
|
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
271
|
-
return `你是**漏洞验证专家**,专注于验证和确认安全漏洞。
|
|
212
|
+
const VULN_VERIFIER_PROMPT = `你是**漏洞验证专家**,专注于验证和确认安全漏洞。
|
|
272
213
|
|
|
273
214
|
## 职责
|
|
274
215
|
|
|
275
216
|
1. **快速验证** - 确认漏洞是否存在
|
|
276
|
-
2.
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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,
|
|
333
|
-
const
|
|
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, '
|
|
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(
|
|
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,
|
|
353
|
-
const
|
|
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, '
|
|
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(端点)
|
|
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,
|
|
374
|
-
const
|
|
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, '
|
|
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: "
|
|
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,
|
|
394
|
-
const
|
|
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, '
|
|
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
|
|
366
|
+
description: "解析 JavaScript 文件。参数: file_path(文件路径)",
|
|
411
367
|
args: {
|
|
412
368
|
file_path: tool.schema.string(),
|
|
413
369
|
},
|
|
414
|
-
async execute(args,
|
|
415
|
-
const
|
|
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, '
|
|
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)}
|
|
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
|
-
|
|
429
|
-
description: "
|
|
388
|
+
graphql_test: tool({
|
|
389
|
+
description: "GraphQL 安全测试。参数: endpoint(GraphQL端点)",
|
|
430
390
|
args: {
|
|
431
|
-
|
|
391
|
+
endpoint: tool.schema.string(),
|
|
392
|
+
introspection: tool.schema.boolean().optional(),
|
|
432
393
|
},
|
|
433
|
-
async execute(args,
|
|
434
|
-
const
|
|
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, '
|
|
437
|
-
from
|
|
438
|
-
|
|
439
|
-
result =
|
|
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
|
-
|
|
448
|
-
description: "
|
|
410
|
+
cloud_storage_test: tool({
|
|
411
|
+
description: "云存储安全测试。参数: bucket_url(存储桶URL)",
|
|
449
412
|
args: {
|
|
450
|
-
|
|
413
|
+
bucket_url: tool.schema.string(),
|
|
451
414
|
},
|
|
452
|
-
async execute(args,
|
|
453
|
-
const
|
|
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, '
|
|
456
|
-
from
|
|
457
|
-
|
|
458
|
-
result =
|
|
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
|
|
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,
|
|
474
|
-
const
|
|
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, '
|
|
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,
|
|
494
|
-
const
|
|
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, '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
530
|
+
VULN_VERIFIER_PROMPT,
|
|
547
531
|
"subagent"
|
|
548
532
|
);
|
|
549
533
|
},
|