关于 security-scan
面向开发者的代码库安全扫描技能,可检查漏洞、泄露的密钥、依赖风险和不安全配置。它提供完整、快速及按类别聚焦的扫描,并按严重程度列出发现和修复建议。
主要功能
- 01检查 OWASP Top 10 类别
- 02检测密钥和凭据
- 03查找注入与加密问题
- 04审查依赖项和配置
- 05按严重程度报告并提供修复建议
适用场景
- 01部署前扫描代码库
- 02快速检查严重问题
- 03调查特定漏洞类别
- 04审查依赖项与配置风险
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ jwynia/ agent-skills --skill security-scan安装后在 Claude Code 中输入/security-scan确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/severity-matrix.mdreferences/owasp/a01-broken-access-control.mda02-cryptographic-failures.mda03-injection.mda04-a10-additional.mdreferences/patterns/javascript-typescript.mdpython.mdreferences/remediation/common-fixes.md详细介绍
安全扫描
全面检测代码库中的安全漏洞。
快速开始
/security-scan # Full scan of current directory
/security-scan --scope src/ # Scan specific directory
/security-scan --quick # Fast scan (critical issues only)
/security-scan --focus injection # Focus on specific category
此工具的功能
分析代码,检测多个类别的安全漏洞:
- OWASP Top 10 - 行业标准的 Web 漏洞类别
- 机密信息检测 - 硬编码的凭据、API 密钥和令牌
- 注入缺陷 - SQL、XSS 和命令注入模式
- 加密问题 - 弱算法和不安全的实现
- 配置问题 - 不安全的默认设置和错误配置
扫描模式
全面扫描(默认)
全面分析所有安全类别。
/security-scan
执行的检查:
- 所有 OWASP Top 10 类别
- 机密信息和凭据检测
- 依赖项漏洞(如果存在软件包文件)
- 配置文件审查
耗时: 视代码库大小而定,为 2-5 分钟
快速扫描
快速检查严重和高危问题。
/security-scan --quick
执行的检查:
- 严重注入模式
- 泄露的机密信息
- 已知的危险函数
耗时: 少于 1 分钟
定向扫描
针对特定漏洞类别进行扫描。
/security-scan --focus <category>
类别:
injection- SQL、XSS、命令注入secrets- 凭据、API 密钥、令牌crypto- 加密弱点auth- 身份验证/授权问题config- 配置安全
输出格式
严重性级别
| 级别 | 图标 | 含义 | 所需操作 |
|---|---|---|---|
| CRITICAL | [!] | 可利用的漏洞 | 立即修复 |
| HIGH | [H] | 严重的安全风险 | 部署前修复 |
| MEDIUM | [M] | 潜在漏洞 | 计划处理 |
| LOW | [L] | 轻微问题或安全加固项 | 考虑修复 |
| INFO | [i] | 信息性发现 | 仅供了解 |
发现项格式
[SEVERITY] CATEGORY: Brief description
File: path/to/file.ext:line
Pattern: What was detected
Risk: Why this is dangerous
Fix: How to remediate
汇总报告
SECURITY SCAN RESULTS
=====================
Scope: src/
Files scanned: 127
Duration: 45 seconds
FINDINGS BY SEVERITY
Critical: 2
High: 5
Medium: 12
Low: 8
TOP ISSUES
1. [!] SQL Injection in src/api/users.ts:45
2. [!] Hardcoded AWS key in src/config.ts:12
3. [H] XSS vulnerability in src/components/Comment.tsx:89
...
Run `/security-scan --details` for full report.
OWASP Top 10 覆盖范围
| # | 类别 | 检测方法 |
|---|---|---|
| A01 | 访问控制失效 | 授权模式分析 |
| A02 | 加密失效 | 弱加密检测 |
| A03 | 注入 | 模式匹配 + 数据流分析 |
| A04 | 不安全设计 | 安全控制缺口 |
| A05 | 安全配置错误 | 配置文件分析 |
| A06 | 易受攻击的组件 | 依赖项扫描 |
| A07 | 身份验证失效 | 身份验证模式审查 |
| A08 | 数据完整性失效 | 反序列化检查 |
| A09 | 日志记录失效 | 审计日志分析 |
| A10 | SSRF | 请求模式检测 |
有关各类别的详细检测规则,请参阅 references/owasp/。
检测模式
注入检测
SQL 注入:
- String concatenation in queries
- Unsanitized user input in database calls
- Dynamic query construction
跨站脚本(XSS):
- innerHTML assignments with user data
- document.write() with dynamic content
- Unescaped template interpolation
命令注入:
- exec(), system(), popen() with user input
- Shell command string construction
- Unsanitized subprocess arguments
有关特定语言的模式,请参阅 references/patterns/。
机密信息检测
高置信度模式:
AWS Access Key: AKIA[0-9A-Z]{16}
AWS Secret Key: [A-Za-z0-9/+=]{40}
GitHub Token: gh[pousr]_[A-Za-z0-9]{36,}
Stripe Key: sk_live_[A-Za-z0-9]{24,}
Private Key: -----BEGIN (RSA |EC )?PRIVATE KEY-----
中等置信度模式:
Generic API Key: api[_-]?key.*[=:]\s*['"][a-zA-Z0-9]{16,}
Password in Code: password\s*[=:]\s*['"][^'"]+['"]
Connection String: (mysql|postgres|mongodb)://[^:]+:[^@]+@
加密弱点
弱算法:
- MD5 for password hashing
- SHA1 for security purposes
- DES/3DES encryption
- RC4 stream cipher
实现问题:
- Hardcoded encryption keys
- Weak random number generation
- Missing salt in password hashing
- ECB mode encryption
与其他技能集成
与 /secrets-scan 集成
深入定向检测凭据:
/secrets-scan # Dedicated secrets analysis
/secrets-scan --entropy # High-entropy string detection
与 /dependency-scan 集成
软件包漏洞分析:
/dependency-scan # Check all dependencies
/dependency-scan --fix # Auto-fix where possible
与 /config-scan 集成
基础设施和配置审查:
/config-scan # All config files
/config-scan --docker # Container security
/config-scan --iac # Infrastructure as Code
扫描执行流程
阶段 1:发现
1. Identify project type (languages, frameworks)
2. Locate relevant files (source, config, dependencies)
3. Determine applicable security rules
阶段 2:静态分析
1. Pattern matching for known vulnerabilities
2. Data flow analysis for injection paths
3. Configuration review
阶段 3:机密信息扫描
1. High-confidence pattern matching
2. Entropy analysis for potential secrets
3. Git history check (optional)
阶段 4:依赖项分析
1. Parse package manifests
2. Check against vulnerability databases
3. Identify outdated packages
阶段 5:报告
1. Deduplicate findings
2. Assign severity scores
3. Generate actionable report
4. Provide remediation guidance
配置
项目级配置
在项目根目录中创建 .security-scan.yaml:
# Scan configuration
scan:
exclude:
- "node_modules/**"
- "vendor/**"
- "**/*.test.ts"
- "**/__mocks__/**"
# Severity thresholds
thresholds:
fail_on: critical # critical, high, medium, low
warn_on: medium
# Category toggles
categories:
injection: true
secrets: true
crypto: true
auth: true
config: true
dependencies: true
# Custom patterns
patterns:
secrets:
- name: "Internal API Key"
pattern: "INTERNAL_[A-Z]{3}_KEY_[a-zA-Z0-9]{32}"
severity: high
忽略模式
创建 .security-scan-ignore 以排除误报:
# Ignore specific files
src/test/fixtures/mock-credentials.ts
# Ignore specific lines (use inline comment)
# security-scan-ignore: test fixture
const mockApiKey = "sk_test_fake123";
命令参考
| 命令 | 描述 |
|---|---|
/security-scan | 全面安全扫描 |
/security-scan --quick | 仅检查严重问题 |
/security-scan --scope <path> | 扫描指定路径 |
/security-scan --focus <cat> | 仅扫描单个类别 |
/security-scan --details | 输出详细信息 |
/security-scan --json | 输出 JSON |
/security-scan --fix | 在可能的情况下自动修复 |
相关技能
/secrets-scan- 深入检测密钥/dependency-scan- 分析软件包漏洞/config-scan- 配置安全审查/review-code- 常规代码审查(包含安全审查)
参考资料
references/owasp/- OWASP Top 10 检测详情references/patterns/- 特定语言的漏洞模式references/remediation/- 按漏洞类型提供修复指南assets/severity-matrix.md- 严重程度评分标准
评论
支持 Markdown