code-abyss 1.5.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -0
  3. package/bin/install.js +193 -0
  4. package/bin/uninstall.js +42 -0
  5. package/config/AGENTS.md +247 -0
  6. package/config/CLAUDE.md +207 -0
  7. package/config/settings.example.json +27 -0
  8. package/output-styles/abyss-cultivator.md +399 -0
  9. package/package.json +41 -0
  10. package/skills/SKILL.md +115 -0
  11. package/skills/ai/SKILL.md +29 -0
  12. package/skills/ai/agent-dev.md +242 -0
  13. package/skills/ai/llm-security.md +288 -0
  14. package/skills/architecture/SKILL.md +41 -0
  15. package/skills/architecture/api-design.md +225 -0
  16. package/skills/architecture/caching.md +299 -0
  17. package/skills/architecture/cloud-native.md +285 -0
  18. package/skills/architecture/compliance.md +299 -0
  19. package/skills/architecture/data-security.md +184 -0
  20. package/skills/architecture/message-queue.md +329 -0
  21. package/skills/architecture/security-arch.md +210 -0
  22. package/skills/development/SKILL.md +43 -0
  23. package/skills/development/cpp.md +246 -0
  24. package/skills/development/go.md +323 -0
  25. package/skills/development/java.md +277 -0
  26. package/skills/development/python.md +288 -0
  27. package/skills/development/rust.md +313 -0
  28. package/skills/development/shell.md +313 -0
  29. package/skills/development/typescript.md +277 -0
  30. package/skills/devops/SKILL.md +36 -0
  31. package/skills/devops/cost-optimization.md +272 -0
  32. package/skills/devops/database.md +217 -0
  33. package/skills/devops/devsecops.md +198 -0
  34. package/skills/devops/git-workflow.md +181 -0
  35. package/skills/devops/observability.md +280 -0
  36. package/skills/devops/performance.md +273 -0
  37. package/skills/devops/testing.md +186 -0
  38. package/skills/gen-docs/SKILL.md +114 -0
  39. package/skills/gen-docs/scripts/doc_generator.py +491 -0
  40. package/skills/multi-agent/SKILL.md +268 -0
  41. package/skills/run_skill.py +88 -0
  42. package/skills/security/SKILL.md +51 -0
  43. package/skills/security/blue-team.md +379 -0
  44. package/skills/security/code-audit.md +265 -0
  45. package/skills/security/pentest.md +226 -0
  46. package/skills/security/red-team.md +321 -0
  47. package/skills/security/threat-intel.md +322 -0
  48. package/skills/security/vuln-research.md +369 -0
  49. package/skills/tests/README.md +225 -0
  50. package/skills/tests/SUMMARY.md +362 -0
  51. package/skills/tests/__init__.py +3 -0
  52. package/skills/tests/test_change_analyzer.py +558 -0
  53. package/skills/tests/test_doc_generator.py +538 -0
  54. package/skills/tests/test_module_scanner.py +376 -0
  55. package/skills/tests/test_quality_checker.py +516 -0
  56. package/skills/tests/test_security_scanner.py +426 -0
  57. package/skills/verify-change/SKILL.md +138 -0
  58. package/skills/verify-change/scripts/change_analyzer.py +529 -0
  59. package/skills/verify-module/SKILL.md +125 -0
  60. package/skills/verify-module/scripts/module_scanner.py +321 -0
  61. package/skills/verify-quality/SKILL.md +158 -0
  62. package/skills/verify-quality/scripts/quality_checker.py +481 -0
  63. package/skills/verify-security/SKILL.md +141 -0
  64. package/skills/verify-security/scripts/security_scanner.py +368 -0
@@ -0,0 +1,379 @@
1
+ ---
2
+ name: blue-team
3
+ description: 蓝队防御技术。检测工程、SOC运营、应急响应、数字取证。当用户提到蓝队、检测规则、Sigma、YARA、SIEM、告警、应急响应、取证、SOC时使用。
4
+ ---
5
+
6
+ # ❄ 玄冰秘典 · 蓝队防御 (Blue Team)
7
+
8
+
9
+ ## 防御链
10
+
11
+ ```
12
+ 预防 → 检测 → 响应 → 恢复
13
+ │ │ │ │
14
+ └─ 加固 ─┴─ SIEM ─┴─ IR ─┴─ 取证
15
+ ```
16
+
17
+ ## 检测工程
18
+
19
+ ### Sigma 规则
20
+
21
+ ```yaml
22
+ # Mimikatz 检测
23
+ title: Mimikatz Credential Dumping
24
+ id: 0d65953c-7f75-4f4b-9a16-8b8f9f2b6d5e
25
+ status: stable
26
+ description: Detects Mimikatz credential dumping via LSASS access
27
+ references:
28
+ - https://attack.mitre.org/techniques/T1003/001/
29
+ tags:
30
+ - attack.credential_access
31
+ - attack.t1003.001
32
+ logsource:
33
+ category: process_access
34
+ product: windows
35
+ detection:
36
+ selection:
37
+ TargetImage|endswith: '\lsass.exe'
38
+ GrantedAccess:
39
+ - '0x1010'
40
+ - '0x1038'
41
+ - '0x1410'
42
+ filter_system:
43
+ SourceImage|startswith:
44
+ - 'C:\Windows\System32\'
45
+ condition: selection and not filter_system
46
+ level: high
47
+ ---
48
+ # 可疑 PowerShell
49
+ title: Suspicious PowerShell Download
50
+ logsource:
51
+ category: process_creation
52
+ product: windows
53
+ detection:
54
+ selection:
55
+ CommandLine|contains:
56
+ - 'IEX'
57
+ - 'Invoke-Expression'
58
+ - 'DownloadString'
59
+ - 'Net.WebClient'
60
+ - '-enc'
61
+ - 'FromBase64String'
62
+ condition: selection
63
+ level: high
64
+ ---
65
+ # DCSync 检测
66
+ title: DCSync Attack
67
+ logsource:
68
+ product: windows
69
+ service: security
70
+ detection:
71
+ selection:
72
+ EventID: 4662
73
+ Properties|contains:
74
+ - '1131f6ad-9c07-11d1-f79f-00c04fc2dcd2'
75
+ - '1131f6aa-9c07-11d1-f79f-00c04fc2dcd2'
76
+ filter_dc:
77
+ SubjectUserName|endswith: '$'
78
+ condition: selection and not filter_dc
79
+ level: critical
80
+ ```
81
+
82
+ ### Sigma 转换
83
+ ```bash
84
+ # 安装
85
+ pip install sigma-cli
86
+
87
+ # 转换为各平台格式
88
+ sigma convert -t splunk -p sysmon rules/
89
+ sigma convert -t elasticsearch rules/
90
+ sigma convert -t azure-monitor rules/
91
+ ```
92
+
93
+ ### YARA 规则
94
+
95
+ ```yara
96
+ rule Mimikatz_Memory {
97
+ meta:
98
+ description = "Detects Mimikatz in memory"
99
+ severity = "critical"
100
+ strings:
101
+ $s1 = "mimikatz" ascii wide nocase
102
+ $s2 = "sekurlsa::logonpasswords" ascii wide
103
+ $s3 = "lsadump::dcsync" ascii wide
104
+ $func = "kuhl_m_" ascii
105
+ condition:
106
+ 2 of ($s*) or $func
107
+ }
108
+
109
+ rule Cobalt_Strike_Beacon {
110
+ meta:
111
+ description = "Detects Cobalt Strike Beacon"
112
+ strings:
113
+ $config = { 69 68 69 68 69 6B 69 68 }
114
+ $sleep = "sleeptime" ascii
115
+ $jitter = "jitter" ascii
116
+ condition:
117
+ $config or all of ($sleep, $jitter)
118
+ }
119
+
120
+ rule Webshell_Generic {
121
+ meta:
122
+ description = "Generic webshell detection"
123
+ strings:
124
+ $php = "<?php" nocase
125
+ $eval = /eval\s*\(\s*\$_(GET|POST|REQUEST)/ nocase
126
+ $system = /system\s*\(\s*\$_(GET|POST)/ nocase
127
+ condition:
128
+ $php and any of ($eval, $system)
129
+ }
130
+ ```
131
+
132
+ ## 关键日志源
133
+
134
+ ### Windows 安全日志
135
+ ```python
136
+ CRITICAL_EVENTS = {
137
+ # 登录事件
138
+ '4624': 'Successful Logon',
139
+ '4625': 'Failed Logon',
140
+ '4648': 'Explicit Credential Logon',
141
+
142
+ # 进程事件
143
+ '4688': 'Process Creation',
144
+ '4689': 'Process Termination',
145
+
146
+ # 账户事件
147
+ '4720': 'User Account Created',
148
+ '4728': 'Member Added to Security Group',
149
+ '4732': 'Member Added to Local Group',
150
+
151
+ # Kerberos
152
+ '4768': 'TGT Request',
153
+ '4769': 'Service Ticket Request',
154
+ '4771': 'Pre-Auth Failed',
155
+
156
+ # 目录服务
157
+ '4662': 'Directory Service Access',
158
+ }
159
+ ```
160
+
161
+ ### Sysmon 事件
162
+ ```python
163
+ SYSMON_EVENTS = {
164
+ '1': 'Process Create',
165
+ '3': 'Network Connection',
166
+ '7': 'Image Loaded',
167
+ '8': 'CreateRemoteThread',
168
+ '10': 'ProcessAccess',
169
+ '11': 'FileCreate',
170
+ '12': 'Registry Key Create/Delete',
171
+ '13': 'Registry Value Set',
172
+ '17': 'Pipe Created',
173
+ '22': 'DNS Query',
174
+ '23': 'FileDelete',
175
+ }
176
+ ```
177
+
178
+ ## SOC 运营
179
+
180
+ ### 告警分级
181
+ ```yaml
182
+ P1 - Critical (15分钟响应):
183
+ - 确认的入侵活动
184
+ - 勒索软件执行
185
+ - 数据外泄
186
+ - 特权账户被控
187
+
188
+ P2 - High (1小时响应):
189
+ - 可疑横向移动
190
+ - 凭证窃取尝试
191
+ - C2 通信检测
192
+ - 异常特权操作
193
+
194
+ P3 - Medium (4小时响应):
195
+ - 可疑进程执行
196
+ - 异常网络连接
197
+ - 策略违规
198
+
199
+ P4 - Low (24小时响应):
200
+ - 信息性告警
201
+ - 合规检查
202
+ ```
203
+
204
+ ### 告警质量指标
205
+ ```python
206
+ class AlertMetrics:
207
+ def calculate(self, alerts):
208
+ total = len(alerts)
209
+ tp = sum(1 for a in alerts if a['verified'] == 'true_positive')
210
+ fp = sum(1 for a in alerts if a['verified'] == 'false_positive')
211
+
212
+ return {
213
+ 'true_positive_rate': tp / total * 100,
214
+ 'false_positive_rate': fp / total * 100,
215
+ 'mean_time_to_detect': self._mttd(alerts),
216
+ 'mean_time_to_respond': self._mttr(alerts),
217
+ }
218
+ ```
219
+
220
+ ## 应急响应
221
+
222
+ ### IR 流程
223
+ ```
224
+ ┌─────────────────────────────────────────────────────────────┐
225
+ │ 应急响应流程 │
226
+ ├─────────────────────────────────────────────────────────────┤
227
+ │ 1. 准备 (Preparation) │
228
+ │ └─ 工具准备、流程文档、联系人清单 │
229
+ │ ↓ │
230
+ │ 2. 识别 (Identification) │
231
+ │ └─ 确认事件、评估范围、初步分类 │
232
+ │ ↓ │
233
+ │ 3. 遏制 (Containment) │
234
+ │ └─ 隔离系统、阻断通信、保护证据 │
235
+ │ ↓ │
236
+ │ 4. 根除 (Eradication) │
237
+ │ └─ 清除恶意软件、修复漏洞、重置凭证 │
238
+ │ ↓ │
239
+ │ 5. 恢复 (Recovery) │
240
+ │ └─ 系统恢复、监控加强、业务恢复 │
241
+ │ ↓ │
242
+ │ 6. 总结 (Lessons Learned) │
243
+ │ └─ 事件报告、改进措施、知识沉淀 │
244
+ └─────────────────────────────────────────────────────────────┘
245
+ ```
246
+
247
+ ### 快速遏制
248
+ ```bash
249
+ # Windows - 隔离主机
250
+ netsh advfirewall set allprofiles state on
251
+ netsh advfirewall firewall add rule name="Block All" dir=out action=block
252
+
253
+ # Linux - 隔离主机
254
+ iptables -P INPUT DROP
255
+ iptables -P OUTPUT DROP
256
+ iptables -A INPUT -s TRUSTED_IP -j ACCEPT
257
+
258
+ # 禁用账户
259
+ net user compromised_user /active:no
260
+ passwd -l compromised_user
261
+
262
+ # 终止恶意进程
263
+ taskkill /F /PID <pid>
264
+ kill -9 <pid>
265
+ ```
266
+
267
+ ### 证据收集
268
+ ```bash
269
+ # Windows
270
+ wmic process list full > processes.txt
271
+ netstat -ano > netstat.txt
272
+ reg export HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run run.reg
273
+ wevtutil epl Security security.evtx
274
+
275
+ # Linux
276
+ ps auxf > processes.txt
277
+ netstat -tulpn > netstat.txt
278
+ cat /etc/passwd > passwd.txt
279
+ last > logins.txt
280
+ cp /var/log/auth.log .
281
+ ```
282
+
283
+ ## 数字取证
284
+
285
+ ### 内存取证
286
+ ```bash
287
+ # 内存获取
288
+ # Windows - WinPMEM
289
+ winpmem_mini_x64.exe memory.raw
290
+
291
+ # Linux - LiME
292
+ insmod lime.ko "path=/tmp/memory.lime format=lime"
293
+
294
+ # 分析 - Volatility
295
+ vol.py -f memory.raw imageinfo
296
+ vol.py -f memory.raw --profile=Win10x64 pslist
297
+ vol.py -f memory.raw --profile=Win10x64 netscan
298
+ vol.py -f memory.raw --profile=Win10x64 malfind
299
+ vol.py -f memory.raw --profile=Win10x64 dlllist
300
+ ```
301
+
302
+ ### 磁盘取证
303
+ ```bash
304
+ # 镜像获取
305
+ dd if=/dev/sda of=disk.img bs=4M status=progress
306
+
307
+ # 挂载分析
308
+ mount -o ro,loop disk.img /mnt/evidence
309
+
310
+ # 时间线分析
311
+ log2timeline.py timeline.plaso disk.img
312
+ psort.py -o l2tcsv timeline.plaso -w timeline.csv
313
+
314
+ # 文件恢复
315
+ foremost -i disk.img -o recovered/
316
+ photorec disk.img
317
+ ```
318
+
319
+ ### 日志分析
320
+ ```bash
321
+ # Windows 事件日志
322
+ # 使用 EvtxECmd 解析
323
+ EvtxECmd.exe -f Security.evtx --csv output/
324
+
325
+ # Linux 日志
326
+ grep "Failed password" /var/log/auth.log
327
+ grep "Accepted" /var/log/auth.log | awk '{print $1,$2,$3,$9,$11}'
328
+ zcat /var/log/auth.log.*.gz | grep "sudo"
329
+ ```
330
+
331
+ ## 威胁狩猎
332
+
333
+ ### 狩猎假设
334
+ ```yaml
335
+ # 基于 ATT&CK 的狩猎假设
336
+ hypothesis: "攻击者可能使用 PowerShell 下载并执行恶意代码"
337
+ technique: T1059.001
338
+ data_sources:
339
+ - Windows PowerShell 日志
340
+ - Sysmon 进程创建
341
+ query: |
342
+ EventID=4104 AND ScriptBlockText CONTAINS ("IEX" OR "DownloadString")
343
+ ```
344
+
345
+ ### 狩猎查询示例
346
+ ```sql
347
+ -- 异常父子进程关系
348
+ SELECT parent_name, process_name, command_line
349
+ FROM processes
350
+ WHERE parent_name = 'winword.exe'
351
+ AND process_name IN ('cmd.exe', 'powershell.exe', 'wscript.exe')
352
+
353
+ -- 异常网络连接
354
+ SELECT process_name, remote_address, remote_port
355
+ FROM network_connections
356
+ WHERE remote_port NOT IN (80, 443, 53)
357
+ AND process_name NOT IN ('chrome.exe', 'firefox.exe')
358
+
359
+ -- 可疑计划任务
360
+ SELECT name, command, trigger
361
+ FROM scheduled_tasks
362
+ WHERE command LIKE '%powershell%' OR command LIKE '%cmd%'
363
+ ```
364
+
365
+ ## 工具清单
366
+
367
+ | 工具 | 用途 |
368
+ |------|------|
369
+ | Sigma | 通用检测规则 |
370
+ | YARA | 恶意软件检测 |
371
+ | Splunk/Elastic | SIEM 平台 |
372
+ | Volatility | 内存取证 |
373
+ | Autopsy | 磁盘取证 |
374
+ | Velociraptor | 端点响应 |
375
+ | TheHive | 事件管理 |
376
+ | MISP | 威胁情报 |
377
+
378
+ ---
379
+
@@ -0,0 +1,265 @@
1
+ ---
2
+ name: code-audit
3
+ description: 代码安全审计。危险函数识别、污点分析、漏洞挖掘、安全审计。当用户提到代码审计、安全审计、漏洞挖掘、危险函数、sink点、source点、污点分析时使用。
4
+ ---
5
+
6
+ # 🔥 赤焰秘典 · 代码安全审计 (Code Audit)
7
+
8
+
9
+ ## 审计流程
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────────────┐
13
+ │ 代码审计流程 │
14
+ ├─────────────────────────────────────────────────────────────┤
15
+ │ 1. 信息收集 │
16
+ │ ├─ 识别语言、框架、依赖 │
17
+ │ ├─ 定位入口点(路由、API、用户输入) │
18
+ │ └─ 梳理数据流向 │
19
+ │ ↓ │
20
+ │ 2. 危险函数扫描 │
21
+ │ ├─ 命令执行 Sink │
22
+ │ ├─ SQL 注入 Sink │
23
+ │ ├─ 文件操作 Sink │
24
+ │ └─ 反序列化 Sink │
25
+ │ ↓ │
26
+ │ 3. 污点分析 │
27
+ │ └─ Source (用户输入) → 传播路径 → Sink (危险函数) │
28
+ │ ↓ │
29
+ │ 4. 漏洞验证 & 报告 │
30
+ │ └─ PoC 编写 → 影响评估 → 修复建议 │
31
+ └─────────────────────────────────────────────────────────────┘
32
+ ```
33
+
34
+ ## 危险函数速查
35
+
36
+ ### Python
37
+ ```python
38
+ # 🔴 命令执行
39
+ os.system(cmd)
40
+ os.popen(cmd)
41
+ subprocess.call(cmd, shell=True)
42
+ subprocess.Popen(cmd, shell=True)
43
+ eval(user_input)
44
+ exec(user_input)
45
+
46
+ # 🔴 SQL 注入
47
+ cursor.execute(f"SELECT * FROM users WHERE id = {user_id}")
48
+ cursor.execute("SELECT * FROM users WHERE id = " + user_id)
49
+
50
+ # 🔴 反序列化
51
+ pickle.loads(user_data)
52
+ yaml.load(user_data) # 不安全
53
+ marshal.loads(user_data)
54
+
55
+ # 🔴 文件操作
56
+ open(user_path, 'r') # 路径穿越
57
+ shutil.copy(user_src, user_dst)
58
+
59
+ # 🔴 SSRF
60
+ requests.get(user_url)
61
+ urllib.request.urlopen(user_url)
62
+
63
+ # ✅ 安全替代
64
+ subprocess.run([cmd, arg1, arg2], shell=False)
65
+ cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
66
+ yaml.safe_load(user_data)
67
+ ```
68
+
69
+ ### Java
70
+ ```java
71
+ // 🔴 命令执行
72
+ Runtime.getRuntime().exec(userInput);
73
+ new ProcessBuilder(userInput).start();
74
+
75
+ // 🔴 SQL 注入
76
+ Statement stmt = conn.createStatement();
77
+ stmt.execute("SELECT * FROM users WHERE id = " + userId);
78
+
79
+ // 🔴 反序列化
80
+ ObjectInputStream ois = new ObjectInputStream(userInputStream);
81
+ ois.readObject();
82
+
83
+ // 🔴 SSRF
84
+ new URL(userUrl).openConnection();
85
+ HttpClient.newHttpClient().send(request);
86
+
87
+ // 🔴 XXE
88
+ DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(userXml);
89
+
90
+ // ✅ 安全替代
91
+ PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
92
+ pstmt.setInt(1, userId);
93
+ ```
94
+
95
+ ### JavaScript/Node.js
96
+ ```javascript
97
+ // 🔴 命令执行
98
+ child_process.exec(userInput);
99
+ eval(userInput);
100
+ new Function(userInput)();
101
+
102
+ // 🔴 原型污染
103
+ Object.assign(target, userInput);
104
+ _.merge(target, userInput);
105
+ JSON.parse(userInput); // 配合 __proto__
106
+
107
+ // 🔴 SQL 注入
108
+ db.query(`SELECT * FROM users WHERE id = ${userId}`);
109
+
110
+ // 🔴 XSS
111
+ element.innerHTML = userInput;
112
+ document.write(userInput);
113
+
114
+ // ✅ 安全替代
115
+ child_process.execFile(cmd, [arg1, arg2]);
116
+ db.query("SELECT * FROM users WHERE id = ?", [userId]);
117
+ element.textContent = userInput;
118
+ ```
119
+
120
+ ### Go
121
+ ```go
122
+ // 🔴 命令执行
123
+ exec.Command("sh", "-c", userInput).Run()
124
+
125
+ // 🔴 SQL 注入
126
+ db.Query("SELECT * FROM users WHERE id = " + userId)
127
+
128
+ // 🔴 路径穿越
129
+ filepath.Join(baseDir, userPath) // 未校验 ..
130
+
131
+ // 🔴 SSTI
132
+ template.HTML(userInput)
133
+
134
+ // ✅ 安全替代
135
+ exec.Command(cmd, arg1, arg2).Run()
136
+ db.Query("SELECT * FROM users WHERE id = ?", userId)
137
+ ```
138
+
139
+ ## 污点分析
140
+
141
+ ### 概念
142
+ ```
143
+ Source (污点源) → 传播路径 → Sink (汇聚点)
144
+ 用户可控输入 数据流转 危险函数调用
145
+ ```
146
+
147
+ ### Source 识别
148
+ ```python
149
+ # HTTP 请求参数
150
+ request.args.get('param')
151
+ request.form.get('param')
152
+ request.json.get('param')
153
+ request.headers.get('header')
154
+ request.cookies.get('cookie')
155
+
156
+ # 文件输入
157
+ open(file).read()
158
+ sys.stdin.read()
159
+
160
+ # 环境变量
161
+ os.environ.get('VAR')
162
+
163
+ # 数据库查询结果(二次注入)
164
+ cursor.fetchone()
165
+ ```
166
+
167
+ ### 传播追踪
168
+ ```python
169
+ # 示例:追踪污点传播
170
+ user_input = request.args.get('id') # Source
171
+ processed = user_input.strip() # 传播
172
+ query = f"SELECT * FROM users WHERE id = {processed}" # 传播
173
+ cursor.execute(query) # Sink!
174
+ ```
175
+
176
+ ## 快速扫描命令
177
+
178
+ ```bash
179
+ # Python 危险函数
180
+ grep -rn "eval\|exec\|os.system\|subprocess\|pickle.loads" --include="*.py" .
181
+
182
+ # Java 危险函数
183
+ grep -rn "Runtime.exec\|ProcessBuilder\|ObjectInputStream\|Statement.execute" --include="*.java" .
184
+
185
+ # JavaScript 危险函数
186
+ grep -rn "eval\|child_process\|innerHTML\|document.write" --include="*.js" .
187
+
188
+ # Go 危险函数
189
+ grep -rn "exec.Command\|template.HTML" --include="*.go" .
190
+
191
+ # SQL 注入模式
192
+ grep -rn "execute.*+\|execute.*f\"\|Query.*+" --include="*.py" --include="*.java" .
193
+ ```
194
+
195
+ ## 漏洞报告格式
196
+
197
+ ```markdown
198
+ ## [漏洞类型] - [严重程度: Critical/High/Medium/Low]
199
+
200
+ **文件:** `path/to/file.py:行号`
201
+
202
+ **漏洞代码:**
203
+ ```python
204
+ # 有问题的代码片段
205
+ user_id = request.args.get('id')
206
+ cursor.execute(f"SELECT * FROM users WHERE id = {user_id}")
207
+ ```
208
+
209
+ **漏洞原理:**
210
+ 用户输入直接拼接到 SQL 语句中,未经过滤或参数化,导致 SQL 注入。
211
+
212
+ **污点追踪:**
213
+ ```
214
+ request.args.get('id') [Source]
215
+
216
+ f"SELECT ... {user_id}" [传播]
217
+
218
+ cursor.execute(query) [Sink]
219
+ ```
220
+
221
+ **PoC:**
222
+ ```
223
+ GET /api/users?id=1' OR '1'='1
224
+ ```
225
+
226
+ **修复建议:**
227
+ ```python
228
+ cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
229
+ ```
230
+ ```
231
+
232
+ ## 审计检查清单
233
+
234
+ ### 输入验证
235
+ - [ ] 所有用户输入是否经过验证
236
+ - [ ] 是否使用白名单验证
237
+ - [ ] 是否有长度限制
238
+
239
+ ### SQL 注入
240
+ - [ ] 是否使用参数化查询
241
+ - [ ] 是否有 ORM 保护
242
+ - [ ] 动态表名/列名是否白名单
243
+
244
+ ### 命令注入
245
+ - [ ] 是否避免 shell=True
246
+ - [ ] 参数是否正确转义
247
+ - [ ] 是否使用白名单命令
248
+
249
+ ### 文件操作
250
+ - [ ] 路径是否规范化
251
+ - [ ] 是否检查路径穿越
252
+ - [ ] 文件类型是否验证
253
+
254
+ ### 认证授权
255
+ - [ ] 敏感操作是否验证身份
256
+ - [ ] 是否有越权检查
257
+ - [ ] 会话管理是否安全
258
+
259
+ ### 加密
260
+ - [ ] 是否使用安全算法
261
+ - [ ] 密钥管理是否安全
262
+ - [ ] 是否有硬编码密钥
263
+
264
+ ---
265
+