opencode-api-security-testing 1.0.0 → 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.
Files changed (4) hide show
  1. package/README.md +10 -39
  2. package/package.json +1 -1
  3. package/src/index.ts +162 -21
  4. package/index.ts +0 -9
package/README.md CHANGED
@@ -1,46 +1,27 @@
1
1
  # API Security Testing Plugin
2
2
 
3
- OpenCode 插件,用于自动化 API 安全测试。
3
+ API 安全测试插件,为 OpenCode 提供自动化漏洞扫描和渗透测试能力。
4
4
 
5
- ## 问题排查
6
-
7
- 如果您遇到 OpenCode 无法连接的问题,请先确保已从 `opencode.json` 中移除插件配置,然后按以下步骤安装。
8
-
9
- ## 安装步骤
10
-
11
- ### 步骤 1:复制 Agents
5
+ ## 安装
12
6
 
13
7
  ```bash
14
- # 创建全局 agents 目录(如果不存在)
15
- mkdir -p ~/.config/opencode/agents
16
-
17
- # 复制 agents 到全局配置目录
18
- cp -r agents/* ~/.config/opencode/agents/
8
+ npm install opencode-api-security-testing
19
9
  ```
20
10
 
21
- ### 步骤 2:复制 Commands(可选)
11
+ ## 配置
22
12
 
23
- ```bash
24
- # 创建全局 commands 目录(如果不存在)
25
- mkdir -p ~/.config/opencode/commands
13
+ 在 `opencode.json` 中添加:
26
14
 
27
- # 复制 commands
28
- cp -r commands/* ~/.config/opencode/commands/
29
- ```
30
-
31
- ### 步骤 3:复制 References(供参考)
32
-
33
- ```bash
34
- # 复制漏洞测试参考文档
35
- cp -r references ~/.config/opencode/
15
+ ```json
16
+ {
17
+ "plugin": ["opencode-api-security-testing"]
18
+ }
36
19
  ```
37
20
 
38
21
  ## 使用方法
39
22
 
40
23
  ### 使用 Agents
41
24
 
42
- 在 OpenCode 中使用 `@` 提及 agents:
43
-
44
25
  ```
45
26
  @cyber-supervisor 对 https://example.com 进行 API 安全测试
46
27
  ```
@@ -53,16 +34,6 @@ cp -r references ~/.config/opencode/
53
34
  @resource-specialist 发现所有 API 端点
54
35
  ```
55
36
 
56
- ### 使用 Commands
57
-
58
- ```
59
- /api-security-testing-scan https://example.com/api
60
- ```
61
-
62
- ```
63
- /api-security-testing-test https://example.com/api/login sqli
64
- ```
65
-
66
37
  ## Agents
67
38
 
68
39
  ### cyber-supervisor
@@ -76,7 +47,7 @@ cp -r references ~/.config/opencode/
76
47
 
77
48
  ## 漏洞测试参考
78
49
 
79
- 参考文档位于 `references/vulnerabilities/` 目录:
50
+ 详细测试指南位于 `references/vulnerabilities/` 目录:
80
51
 
81
52
  | 文件 | 漏洞类型 |
82
53
  |------|---------|
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-api-security-testing",
3
- "version": "1.0.0",
3
+ "version": "1.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
@@ -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. **动态采集** - 使用无头浏览器或代理拦截采集 API 端点
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
 
package/index.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { Plugin } from "@opencode-ai/plugin";
2
-
3
- const ApiSecurityTestingPlugin: Plugin = async () => {
4
- return {
5
- tool: {},
6
- };
7
- };
8
-
9
- export default ApiSecurityTestingPlugin;