crypto
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCryptographic Failures (A02:2021)
加密失败(A02:2021)
Analyze source code for cryptographic weaknesses including use of broken or weak
algorithms, hardcoded encryption keys, improper password hashing, cleartext
transmission of sensitive data, missing encryption at rest, and insecure random
number generation.
分析源代码中的加密弱点,包括使用已破解或弱算法、硬编码加密密钥、不当的密码哈希、敏感数据明文传输、静态数据未加密以及不安全的随机数生成。
Supported Flags
支持的参数
Read for the full flag specification. This skill
supports all cross-cutting flags. Key flags for this skill:
../../shared/schemas/flags.md- determines which files to analyze (default:
--scope)changed - checks imports, function calls, and configuration values
--depth standard - traces key material origin and data flow for sensitive values
--depth deep - filters output (crypto issues range from
--severitytolow)critical
完整的参数规范请阅读。本Skill支持所有跨域参数,其中关键参数包括:
../../shared/schemas/flags.md- :确定要分析的文件范围(默认值:
--scope)changed - :检查导入项、函数调用和配置值
--depth standard - :追踪敏感值的密钥材料来源和数据流
--depth deep - :过滤输出结果(加密问题的严重程度范围从
--severity到low)critical
Framework Context
框架背景
Read , section A02:2021 -
Cryptographic Failures, for the full category description, common
vulnerabilities, and prevention guidance.
../../shared/frameworks/owasp-top10-2021.mdKey CWEs in scope:
- CWE-261: Weak Encoding for Password
- CWE-327: Use of a Broken or Risky Cryptographic Algorithm
- CWE-328: Use of Weak Hash
- CWE-330: Use of Insufficiently Random Values
- CWE-331: Insufficient Entropy
- CWE-338: Use of Cryptographically Weak PRNG
- CWE-759: Use of a One-Way Hash without a Salt
- CWE-760: Use of a One-Way Hash with a Predictable Salt
- CWE-798: Use of Hard-coded Credentials
完整的类别描述、常见漏洞及预防指南,请阅读中的A02:2021 - 加密失败章节。
../../shared/frameworks/owasp-top10-2021.md涵盖的关键CWE包括:
- CWE-261:密码的弱编码
- CWE-327:使用已破解或有风险的加密算法
- CWE-328:使用弱哈希算法
- CWE-330:使用随机性不足的值
- CWE-331:熵不足
- CWE-338:使用加密不安全的PRNG
- CWE-759:使用无盐的单向哈希
- CWE-760:使用可预测盐值的单向哈希
- CWE-798:使用硬编码凭据
Detection Patterns
检测模式
Read for the full catalog of code patterns,
search heuristics, language-specific examples, and false positive guidance.
references/detection-patterns.md完整的代码模式、搜索启发式规则、特定语言示例及误报处理指南,请阅读。
references/detection-patterns.mdWorkflow
工作流程
1. Determine Scope
1. 确定分析范围
Parse flags and resolve the file list per .
Filter to files likely to contain cryptographic operations:
../../shared/schemas/flags.md- Crypto/security utility modules (,
**/crypto/**,**/security/**)**/utils/encrypt* - Authentication modules (,
**/auth/**,**/login/**)**/password* - Configuration files (,
**/.env*,**/config/**)**/settings* - Database models with password fields ()
**/models/** - TLS/SSL configuration (,
**/ssl/**,**/tls/**)**/certs/**
解析参数并根据确定文件列表。筛选出可能包含加密操作的文件:
../../shared/schemas/flags.md- 加密/安全工具模块(,
**/crypto/**,**/security/**)**/utils/encrypt* - 认证模块(,
**/auth/**,**/login/**)**/password* - 配置文件(,
**/.env*,**/config/**)**/settings* - 包含密码字段的数据库模型()
**/models/** - TLS/SSL配置(,
**/ssl/**,**/tls/**)**/certs/**
2. Check for Available Scanners
2. 检查可用扫描器
Detect scanners per :
../../shared/schemas/scanners.md- — primary scanner for crypto pattern detection
semgrep - — Python-specific weak crypto detection
bandit - — Go-specific crypto issues
gosec - /
gitleaks— hardcoded keys and secretstrufflehog
Record which scanners are available and which are missing.
根据检测可用扫描器:
../../shared/schemas/scanners.md- —— 用于加密模式检测的主扫描器
semgrep - —— 针对Python的弱加密检测工具
bandit - —— 针对Go的加密问题检测工具
gosec - /
gitleaks—— 检测硬编码密钥和机密信息trufflehog
记录可用和缺失的扫描器。
3. Run Scanners (If Available)
3. 运行扫描器(若可用)
If semgrep is available:
semgrep scan --config auto --json --quiet <target>Filter results to rules matching cryptographic patterns, weak hashing, hardcoded
keys, and TLS configuration. Normalize output to the findings schema.
If gitleaks is available (for hardcoded key detection):
gitleaks detect --source <target> --report-format json --report-path /dev/stdout --no-banner若semgrep可用:
semgrep scan --config auto --json --quiet <target>筛选出匹配加密模式、弱哈希、硬编码密钥及TLS配置的规则结果。将输出标准化为发现结果的格式。
若gitleaks可用(用于检测硬编码密钥):
gitleaks detect --source <target> --report-format json --report-path /dev/stdout --no-banner4. Claude Code Analysis
4. Claude代码分析
Regardless of scanner availability, perform manual code analysis:
- Hash algorithm audit: Grep for MD5, SHA1, SHA-256 (without key) used in security contexts (password hashing, token generation, signature verification).
- Key management: Find encryption keys, API secrets, and IVs — check if they are hardcoded, loaded from environment, or from a key management service.
- Password storage: Locate password hashing code and verify use of bcrypt, argon2, or scrypt with appropriate cost factors.
- Random number generation: Find random value generation and verify cryptographically secure sources are used for security-sensitive operations.
- TLS configuration: Check for TLS enforcement, certificate validation, and minimum protocol version.
- Encryption mode: Identify block cipher usage and verify ECB mode is not used for anything beyond single-block encryption.
When , additionally trace:
--depth deep- Where encryption keys originate and how they flow through the application
- Whether sensitive data is encrypted before storage and in transit
- Key rotation mechanisms and lifecycle
无论扫描器是否可用,都需执行手动代码分析:
- 哈希算法审计:搜索在安全场景(密码哈希、令牌生成、签名验证)中使用的MD5、SHA1、SHA-256(无密钥)。
- 密钥管理:查找加密密钥、API机密和初始化向量(IV)——检查它们是否硬编码、从环境变量加载或来自密钥管理服务。
- 密码存储:定位密码哈希代码,验证是否使用bcrypt、argon2或scrypt并配置了合适的成本因子。
- 随机数生成:查找随机值生成代码,验证安全敏感操作是否使用了加密安全的随机源。
- TLS配置:检查TLS强制实施、证书验证及最低协议版本。
- 加密模式:识别块密码的使用情况,验证ECB模式是否仅用于单块加密之外的场景。
当使用参数时,额外追踪:
--depth deep- 加密密钥的来源及其在应用中的数据流
- 敏感数据在存储和传输前是否已加密
- 密钥轮换机制和生命周期
5. Report Findings
5. 报告发现结果
Format output per using the prefix
(e.g., , ).
../../shared/schemas/findings.mdCRYPTCRYPT-001CRYPT-002Include for each finding:
- Severity and confidence
- Exact file location with code snippet
- Impact description specific to the cryptographic weakness
- Concrete fix with diff showing the secure alternative
- CWE and OWASP references
根据的格式,使用前缀格式化输出(例如:, )。
../../shared/schemas/findings.mdCRYPTCRYPT-001CRYPT-002每个发现结果需包含:
- 严重程度和置信度
- 精确的文件位置及代码片段
- 针对该加密弱点的影响描述
- 显示安全替代方案的具体修复代码差异
- CWE和OWASP参考链接
What to Look For
检查要点
These are the high-signal patterns specific to cryptographic failures. Each
maps to a detection pattern in .
references/detection-patterns.md-
Weak hash algorithms for security — MD5 or SHA1 used for password hashing, token generation, integrity verification, or digital signatures.
-
Hardcoded encryption keys and IVs — Symmetric keys, asymmetric private keys, or initialization vectors embedded directly in source code.
-
Insecure random number generation —,
Math.random(), orrand()used for tokens, session IDs, or cryptographic operations.random.random() -
Password storage without proper hashing — Passwords stored in plaintext, with reversible encryption, or with fast hashes (MD5, SHA-family) instead of purpose-built password hashing functions.
-
ECB mode usage — Block cipher encryption using ECB mode, which reveals patterns in the plaintext.
-
Missing TLS enforcement — HTTP used where HTTPS is required, disabled certificate validation, or outdated TLS versions allowed.
-
Insufficient key derivation — Using encryption keys directly from passwords without a proper key derivation function (PBKDF2, HKDF).
-
Static or predictable IVs/nonces — Initialization vectors or nonces that are hardcoded, reused, or derived from predictable sources.
以下是与加密失败相关的高信号模式,每个模式都对应中的检测模式。
references/detection-patterns.md-
安全场景下使用弱哈希算法——MD5或SHA1用于密码哈希、令牌生成、完整性验证或数字签名。
-
硬编码加密密钥和IV——对称密钥、非对称私钥或初始化向量直接嵌入源代码中。
-
不安全的随机数生成——、
Math.random()或rand()用于令牌、会话ID或加密操作。random.random() -
未正确哈希的密码存储——密码以明文存储、使用可逆加密,或使用快速哈希算法(MD5、SHA系列)而非专门的密码哈希函数。
-
ECB模式的使用——块密码加密使用ECB模式,这会泄露明文的模式信息。
-
未强制实施TLS——在需要HTTPS的场景下使用HTTP、禁用证书验证,或允许使用过时的TLS版本。
-
密钥推导不足——直接从密码生成加密密钥,未使用适当的密钥推导函数(PBKDF2、HKDF)。
-
静态或可预测的IV/Nonce——初始化向量或Nonce是硬编码、重复使用或来自可预测源的。
Scanner Integration
扫描器集成
| Scanner | Coverage | Command |
|---|---|---|
| semgrep | Weak crypto, hardcoded keys, insecure random | |
| bandit | Python crypto issues (MD5, DES, hardcoded passwords) | |
| gosec | Go crypto (weak TLS, hardcoded creds) | |
| gitleaks | Hardcoded keys and secrets | |
Fallback (no scanner): Use Grep with patterns from
to find hash function calls, encryption operations, key assignments, and random
number generation. Report findings with .
references/detection-patterns.mdconfidence: mediumRelevant semgrep rule categories:
python.cryptography.security.insecure-hash-*python.cryptography.security.insecure-cipher-*javascript.crypto.security.weak-*java.crypto.security.weak-*generic.secrets.security.detected-*
| 扫描器 | 覆盖范围 | 命令 |
|---|---|---|
| semgrep | 弱加密、硬编码密钥、不安全随机数 | |
| bandit | Python加密问题(MD5、DES、硬编码密码) | |
| gosec | Go加密问题(弱TLS、硬编码凭据) | |
| gitleaks | 硬编码密钥和机密信息 | |
Fallback(无扫描器时):使用Grep结合中的模式,查找哈希函数调用、加密操作、密钥赋值和随机数生成。报告结果时标记。
references/detection-patterns.mdconfidence: medium相关的semgrep规则类别:
python.cryptography.security.insecure-hash-*python.cryptography.security.insecure-cipher-*javascript.crypto.security.weak-*java.crypto.security.weak-*generic.secrets.security.detected-*
Output Format
输出格式
Use the findings schema from .
../../shared/schemas/findings.md- ID prefix: (e.g.,
CRYPT)CRYPT-001 - metadata.tool:
crypto - metadata.framework:
owasp - metadata.category:
A02 - references.owasp:
A02:2021 - references.stride: (Information Disclosure) or
I(Tampering)T
Severity guidance for this category:
- critical: Plaintext password storage, hardcoded production encryption keys, disabled TLS verification
- high: MD5/SHA1 for password hashing, ECB mode on sensitive data, for tokens
Math.random() - medium: Weak key derivation, outdated TLS versions (TLS 1.0/1.1), missing encryption at rest
- low: SHA-256 for password hashing (not broken but not ideal), non-security use of weak hash
使用中的发现结果格式。
../../shared/schemas/findings.md- ID前缀:(例如:
CRYPT)CRYPT-001 - metadata.tool:
crypto - metadata.framework:
owasp - metadata.category:
A02 - references.owasp:
A02:2021 - references.stride:(信息泄露)或
I(篡改)T
本类别的严重程度指南:
- critical(严重):明文存储密码、硬编码生产环境加密密钥、禁用TLS验证
- high(高):MD5/SHA1用于密码哈希、敏感数据使用ECB模式、用于生成令牌
Math.random() - medium(中):弱密钥推导、过时TLS版本(TLS 1.0/1.1)、静态数据未加密
- low(低):使用SHA-256进行密码哈希(未被破解但并非理想选择)、非安全场景使用弱哈希算法