Security Scanning 是一个用于安全扫描的命令行技能集合,覆盖静态代码分析、依赖漏洞扫描、密钥检测和容器镜像扫描四类任务,主要面向开发者和安全工程人员在本地或 CI 流程中使用。
用途
该技能用于在开发过程中发现代码层漏洞、供应链依赖中的已知漏洞、意外泄露的凭据以及容器镜像中的安全问题,形成一个可快速执行的安全检查流程。
主要能力
静态分析(SAST)
使用 Semgrep 查找代码级漏洞。示例命令包括:
- 自动检测规则扫描当前目录:
semgrep scan --config auto . - 使用 OWASP Top 10 规则:
semgrep scan --config "p/owasp-top-ten" . - 按语言扫描:
semgrep scan --config "p/python" src/ - JSON 输出便于处理:
semgrep scan --config auto --json . | jq '.results[] | {path: .path, line: .start.line, rule: .check_id, message: .extra.message}' - 按严重级别过滤:
semgrep scan --config auto --severity ERROR .
依赖漏洞扫描(SCA)
使用 Trivy、Snyk 以及包管理器自带审计命令。
Trivy 扫描项目依赖:
trivy fs --severity HIGH,CRITICAL .trivy fs --format json --output trivy-report.json .trivy fs --scanners vuln package-lock.jsontrivy fs --exit-code 1 --severity CRITICAL .(适用于 CI,发现严重项时失败)
Snyk 依赖与代码扫描:
snyk testsnyk monitorsnyk test --file=requirements.txtsnyk code testsnyk test --print-deps
npm/pnpm/pip 自带审计(无需额外工具):
npm audit --json | jq '.vulnerabilities | to_entries[] | {name: .key, severity: .value.severity, via: .value.via[0]}'pnpm audit --jsonpip audit --format json
密钥检测
使用 TruffleHog 查找泄露的凭据:
- 扫描 git 历史:
trufflehog git file://. --json | jq '{detector: .DetectorName, file: .SourceMetadata.Data.Git.file, line: .SourceMetadata.Data.Git.line}' - 仅扫描文件系统(不含 git 历史):
trufflehog filesystem . --json - 扫描指定分支:
trufflehog git file://. --branch main - 从指定提交开始扫描:
trufflehog git file://. --since-commit abc123
容器镜像扫描
Trivy 扫描 Docker 镜像:
trivy image --severity HIGH,CRITICAL myapp:latesttrivy image --format json --output image-report.json myapp:latesttrivy image --severity CRITICAL nginx:latest
Grype 镜像漏洞扫描:
grype myapp:latestgrype myapp:latest --only-fixed --fail-on criticalgrype dir:.grype myapp:latest -o json | jq '.matches[] | {name: .vulnerability.id, severity: .vulnerability.severity, package: .artifact.name}'
使用方式
该技能以命令行工具组合的形式使用,按以下快速分类处理流程执行:
- 密钥优先:
trufflehog git file://. --json(泄露凭据属于最紧急风险) - 依赖检查:
trivy fs --severity HIGH,CRITICAL .(查找供应链中的已知 CVE) - 代码检查:
semgrep scan --config auto .(检查自身代码漏洞) - 镜像检查:
trivy image myapp:latest(如使用容器)
适用场景
适用于本地开发阶段的安全自检,以及 CI 流程中自动化安全检查。可在提交前或构建流程中按需调用相应命令。
限制与注意事项
- 处理扫描结果前应始终人工复核,SAST 中误报较为常见。
- 严重级别顺序为 CRITICAL > HIGH > MEDIUM > LOW > INFO,应优先处理 CRITICAL 和 HIGH。
- 在 CI 流程中,可使用 Trivy 的
--exit-code 1或 Semgrep 的--error使构建在发现问题时失败。 - 在大仓库中扫描 git 历史中的密钥可能较慢,可使用
--since-commit限制范围。 - 首次使用 Snyk CLI 前需运行
snyk auth。
关于具体工具的安装方式、支持的平台范围、收费与价格信息,资料中暂未提供。