opencode-api-security-testing 1.0.1 → 1.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.
- package/package.json +1 -1
- package/src/index.ts +162 -21
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
3
|
import type { AgentConfig } from "@opencode-ai/sdk";
|
|
4
|
+
import { join } from "path";
|
|
3
5
|
|
|
4
6
|
const CYBER_SUPERVISOR_PROMPT = `你是 API 安全测试的**赛博监工**,代号"渗透测试员P9"。
|
|
5
7
|
|
|
@@ -10,22 +12,22 @@ const CYBER_SUPERVISOR_PROMPT = `你是 API 安全测试的**赛博监工**,
|
|
|
10
12
|
3. **压力升级** - 遇到失败自动换方法
|
|
11
13
|
4. **智能委派** - 使用 delegate_task 委派给 probing-miner 和 resource-specialist
|
|
12
14
|
|
|
15
|
+
## 可用工具(通过 Skill)
|
|
16
|
+
|
|
17
|
+
- api_scan: 对目标进行完整 API 安全扫描
|
|
18
|
+
- api_fuzz: 对特定端点进行模糊测试
|
|
19
|
+
- browser_collect: 使用浏览器采集动态内容
|
|
20
|
+
- vuln_verify: 验证漏洞是否存在
|
|
21
|
+
- cloud_storage_test: 测试云存储安全
|
|
22
|
+
- graphql_test: GraphQL 安全测试
|
|
23
|
+
|
|
13
24
|
## 工作流程
|
|
14
25
|
|
|
15
|
-
发现线索 →
|
|
26
|
+
发现线索 → 调用工具 → 收集结果 → 继续追查
|
|
16
27
|
↓
|
|
17
28
|
进度追踪 → 压力升级(L1-L4) → 永不停止
|
|
18
29
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
| 失败次数 | 等级 | 行动 |
|
|
22
|
-
|---------|------|------|
|
|
23
|
-
| 2次 | L1 | 换方法继续 |
|
|
24
|
-
| 3次 | L2 | 委派 resource-specialist 重新采集 |
|
|
25
|
-
| 5次 | L3 | 委派 probing-miner 针对性挖掘 |
|
|
26
|
-
| 7次+ | L4 | 同时委派两个 agent |
|
|
27
|
-
|
|
28
|
-
## 漏洞类型参考
|
|
30
|
+
## 漏洞类型
|
|
29
31
|
|
|
30
32
|
- SQL 注入: references/vulnerabilities/01-sqli-tests.md
|
|
31
33
|
- IDOR: references/vulnerabilities/04-idor-tests.md
|
|
@@ -41,7 +43,15 @@ const PROBING_MINER_PROMPT = `你是**探测挖掘专家**,专注于对 API
|
|
|
41
43
|
|
|
42
44
|
1. **针对性测试** - 根据端点类型选择合适的测试方法
|
|
43
45
|
2. **漏洞验证** - 对发现的漏洞进行验证并生成 PoC
|
|
44
|
-
3.
|
|
46
|
+
3. **调用工具** - 使用 api_scan, api_fuzz, vuln_verify 等工具
|
|
47
|
+
|
|
48
|
+
## 可用工具
|
|
49
|
+
|
|
50
|
+
- api_scan: 完整 API 安全扫描
|
|
51
|
+
- api_fuzz: 端点模糊测试
|
|
52
|
+
- vuln_verify: 漏洞验证
|
|
53
|
+
- cloud_storage_test: 云存储测试
|
|
54
|
+
- graphql_test: GraphQL 测试
|
|
45
55
|
|
|
46
56
|
## 漏洞测试指南
|
|
47
57
|
|
|
@@ -49,24 +59,25 @@ const PROBING_MINER_PROMPT = `你是**探测挖掘专家**,专注于对 API
|
|
|
49
59
|
- 用户枚举: references/vulnerabilities/02-user-enum-tests.md
|
|
50
60
|
- JWT 安全: references/vulnerabilities/03-jwt-tests.md
|
|
51
61
|
- IDOR: references/vulnerabilities/04-idor-tests.md
|
|
52
|
-
- 敏感数据: references/vulnerabilities/05-sensitive-data-tests.md
|
|
53
|
-
- 业务逻辑: references/vulnerabilities/06-biz-logic-tests.md
|
|
54
|
-
- 安全配置: references/vulnerabilities/07-security-config-tests.md
|
|
55
|
-
- 暴力破解: references/vulnerabilities/08-brute-force-tests.md
|
|
56
|
-
- GraphQL: references/vulnerabilities/11-graphql-tests.md
|
|
57
|
-
- SSRF: references/vulnerabilities/12-ssrf-tests.md`;
|
|
62
|
+
- 敏感数据: references/vulnerabilities/05-sensitive-data-tests.md`;
|
|
58
63
|
|
|
59
64
|
const RESOURCE_SPECIALIST_PROMPT = `你是**资源探测专家**,专注于采集和发现 API 端点。
|
|
60
65
|
|
|
61
66
|
## 职责
|
|
62
67
|
|
|
63
|
-
1. **动态采集** -
|
|
68
|
+
1. **动态采集** - 使用浏览器采集 API 端点
|
|
64
69
|
2. **静态分析** - 从 JS 文件和源码中提取端点
|
|
65
70
|
3. **模式识别** - 识别 API 的 URL 模式和参数结构
|
|
66
71
|
|
|
72
|
+
## 可用工具
|
|
73
|
+
|
|
74
|
+
- browser_collect: 使用 Playwright 采集动态内容
|
|
75
|
+
- js_parse: 解析 JavaScript 文件提取端点
|
|
76
|
+
- url_discover: 发现隐藏 URL
|
|
77
|
+
|
|
67
78
|
## 采集技术
|
|
68
79
|
|
|
69
|
-
### 方法1: Playwright
|
|
80
|
+
### 方法1: Playwright 浏览器采集
|
|
70
81
|
使用 Playwright 打开页面,拦截所有 XHR/Fetch 请求
|
|
71
82
|
|
|
72
83
|
### 方法2: JavaScript 文件分析
|
|
@@ -75,8 +86,138 @@ const RESOURCE_SPECIALIST_PROMPT = `你是**资源探测专家**,专注于采
|
|
|
75
86
|
### 方法3: 目录和文件探测
|
|
76
87
|
常见路径:/api/v1/*, /graphql, /swagger, /.well-known/*`;
|
|
77
88
|
|
|
78
|
-
const ApiSecurityTestingPlugin: Plugin = async () => {
|
|
89
|
+
const ApiSecurityTestingPlugin: Plugin = async (ctx) => {
|
|
79
90
|
return {
|
|
91
|
+
tool: {
|
|
92
|
+
api_security_scan: tool({
|
|
93
|
+
description: "对目标进行完整的 API 安全扫描。参数:target(目标URL), scan_type(full/quick/targeted), vulnerabilities(要检测的漏洞类型数组)",
|
|
94
|
+
args: {
|
|
95
|
+
target: tool.schema.string(),
|
|
96
|
+
scan_type: tool.schema.enum(["full", "quick", "targeted"]).optional(),
|
|
97
|
+
vulnerabilities: tool.schema.array(tool.schema.string()).optional(),
|
|
98
|
+
},
|
|
99
|
+
async execute(args, context) {
|
|
100
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
101
|
+
const cmd = `cd ${skillPath} && pip install -q -r requirements.txt 2>/dev/null; python3 -c "
|
|
102
|
+
import sys
|
|
103
|
+
sys.path.insert(0, 'core')
|
|
104
|
+
from deep_api_tester_v55 import DeepAPITesterV55
|
|
105
|
+
tester = DeepAPITesterV55(target='${args.target}', headless=True)
|
|
106
|
+
results = tester.run_test()
|
|
107
|
+
print(results)
|
|
108
|
+
"`;
|
|
109
|
+
const result = await ctx.$`${cmd}`;
|
|
110
|
+
return result.toString();
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
|
|
114
|
+
api_fuzz_test: tool({
|
|
115
|
+
description: "对特定 API 端点进行模糊测试。参数:endpoint(端点URL), method(HTTP方法)",
|
|
116
|
+
args: {
|
|
117
|
+
endpoint: tool.schema.string(),
|
|
118
|
+
method: tool.schema.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional(),
|
|
119
|
+
},
|
|
120
|
+
async execute(args, context) {
|
|
121
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
122
|
+
const cmd = `cd ${skillPath} && python3 -c "
|
|
123
|
+
import sys
|
|
124
|
+
sys.path.insert(0, 'core')
|
|
125
|
+
from api_fuzzer import APIFuzzer
|
|
126
|
+
fuzzer = APIFuzzer('${args.endpoint}')
|
|
127
|
+
results = fuzzer.fuzz(method='${args.method || 'GET'}')
|
|
128
|
+
print(results)
|
|
129
|
+
"`;
|
|
130
|
+
const result = await ctx.$`${cmd}`;
|
|
131
|
+
return result.toString();
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
|
|
135
|
+
vuln_verify: tool({
|
|
136
|
+
description: "验证漏洞是否存在。参数:vuln_type(漏洞类型), endpoint(端点), evidence(可选证据)",
|
|
137
|
+
args: {
|
|
138
|
+
vuln_type: tool.schema.string(),
|
|
139
|
+
endpoint: tool.schema.string(),
|
|
140
|
+
evidence: tool.schema.string().optional(),
|
|
141
|
+
},
|
|
142
|
+
async execute(args, context) {
|
|
143
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
144
|
+
const cmd = `cd ${skillPath} && python3 -c "
|
|
145
|
+
import sys
|
|
146
|
+
sys.path.insert(0, 'core')
|
|
147
|
+
from verifiers.vuln_verifier import VulnVerifier
|
|
148
|
+
verifier = VulnVerifier()
|
|
149
|
+
result = verifier.verify('${args.vuln_type}', '${args.endpoint}')
|
|
150
|
+
print(result)
|
|
151
|
+
"`;
|
|
152
|
+
const result = await ctx.$`${cmd}`;
|
|
153
|
+
return result.toString();
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
|
|
157
|
+
browser_collect: tool({
|
|
158
|
+
description: "使用 Playwright 浏览器采集动态内容。参数:url(目标URL), wait_for(等待元素)",
|
|
159
|
+
args: {
|
|
160
|
+
url: tool.schema.string(),
|
|
161
|
+
wait_for: tool.schema.string().optional(),
|
|
162
|
+
},
|
|
163
|
+
async execute(args, context) {
|
|
164
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
165
|
+
const cmd = `cd ${skillPath} && python3 -c "
|
|
166
|
+
import sys
|
|
167
|
+
sys.path.insert(0, 'core')
|
|
168
|
+
from collectors.browser_collect import BrowserCollector
|
|
169
|
+
collector = BrowserCollector(headless=True)
|
|
170
|
+
endpoints = collector.collect('${args.url}')
|
|
171
|
+
print(f'发现 {len(endpoints)} 个端点:')
|
|
172
|
+
for ep in endpoints:
|
|
173
|
+
print(ep)
|
|
174
|
+
"`;
|
|
175
|
+
const result = await ctx.$`${cmd}`;
|
|
176
|
+
return result.toString();
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
|
|
180
|
+
cloud_storage_test: tool({
|
|
181
|
+
description: "测试云存储安全。参数:bucket_url(存储桶URL)",
|
|
182
|
+
args: {
|
|
183
|
+
bucket_url: tool.schema.string(),
|
|
184
|
+
},
|
|
185
|
+
async execute(args, context) {
|
|
186
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
187
|
+
const cmd = `cd ${skillPath} && python3 -c "
|
|
188
|
+
import sys
|
|
189
|
+
sys.path.insert(0, 'core')
|
|
190
|
+
from cloud_storage_tester import CloudStorageTester
|
|
191
|
+
tester = CloudStorageTester()
|
|
192
|
+
result = tester.full_test('${args.bucket_url}')
|
|
193
|
+
print(result)
|
|
194
|
+
"`;
|
|
195
|
+
const result = await ctx.$`${cmd}`;
|
|
196
|
+
return result.toString();
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
|
|
200
|
+
graphql_security_test: tool({
|
|
201
|
+
description: "测试 GraphQL 安全。参数:endpoint(GraphQL端点)",
|
|
202
|
+
args: {
|
|
203
|
+
endpoint: tool.schema.string(),
|
|
204
|
+
},
|
|
205
|
+
async execute(args, context) {
|
|
206
|
+
const skillPath = join(context.directory, "skills/api-security-testing");
|
|
207
|
+
const cmd = `cd ${skillPath} && python3 -c "
|
|
208
|
+
import sys
|
|
209
|
+
sys.path.insert(0, 'core')
|
|
210
|
+
from smart_analyzer import SmartAnalyzer
|
|
211
|
+
analyzer = SmartAnalyzer()
|
|
212
|
+
result = analyzer.graphql_test('${args.endpoint}')
|
|
213
|
+
print(result)
|
|
214
|
+
"`;
|
|
215
|
+
const result = await ctx.$`${cmd}`;
|
|
216
|
+
return result.toString();
|
|
217
|
+
},
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
|
|
80
221
|
config: async (config) => {
|
|
81
222
|
const agentConfig = config.agent as Record<string, AgentConfig> | undefined;
|
|
82
223
|
|