crypto

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cryptographic 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
../../shared/schemas/flags.md
for the full flag specification. This skill supports all cross-cutting flags. Key flags for this skill:
  • --scope
    determines which files to analyze (default:
    changed
    )
  • --depth standard
    checks imports, function calls, and configuration values
  • --depth deep
    traces key material origin and data flow for sensitive values
  • --severity
    filters output (crypto issues range from
    low
    to
    critical
    )
完整的参数规范请阅读
../../shared/schemas/flags.md
。本Skill支持所有跨域参数,其中关键参数包括:
  • --scope
    :确定要分析的文件范围(默认值:
    changed
  • --depth standard
    :检查导入项、函数调用和配置值
  • --depth deep
    :追踪敏感值的密钥材料来源和数据流
  • --severity
    :过滤输出结果(加密问题的严重程度范围从
    low
    critical

Framework Context

框架背景

Read
../../shared/frameworks/owasp-top10-2021.md
, section A02:2021 - Cryptographic Failures, for the full category description, common vulnerabilities, and prevention guidance.
Key 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
完整的类别描述、常见漏洞及预防指南,请阅读
../../shared/frameworks/owasp-top10-2021.md
中的A02:2021 - 加密失败章节。
涵盖的关键CWE包括:
  • CWE-261:密码的弱编码
  • CWE-327:使用已破解或有风险的加密算法
  • CWE-328:使用弱哈希算法
  • CWE-330:使用随机性不足的值
  • CWE-331:熵不足
  • CWE-338:使用加密不安全的PRNG
  • CWE-759:使用无盐的单向哈希
  • CWE-760:使用可预测盐值的单向哈希
  • CWE-798:使用硬编码凭据

Detection Patterns

检测模式

Read
references/detection-patterns.md
for the full catalog of code patterns, search heuristics, language-specific examples, and false positive guidance.
完整的代码模式、搜索启发式规则、特定语言示例及误报处理指南,请阅读
references/detection-patterns.md

Workflow

工作流程

1. Determine Scope

1. 确定分析范围

Parse flags and resolve the file list per
../../shared/schemas/flags.md
. Filter to files likely to contain cryptographic operations:
  • 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
:
  1. semgrep
    — primary scanner for crypto pattern detection
  2. bandit
    — Python-specific weak crypto detection
  3. gosec
    — Go-specific crypto issues
  4. gitleaks
    /
    trufflehog
    — hardcoded keys and secrets
Record which scanners are available and which are missing.
根据
../../shared/schemas/scanners.md
检测可用扫描器:
  1. semgrep
    —— 用于加密模式检测的主扫描器
  2. bandit
    —— 针对Python的弱加密检测工具
  3. gosec
    —— 针对Go的加密问题检测工具
  4. 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-banner

4. Claude Code Analysis

4. Claude代码分析

Regardless of scanner availability, perform manual code analysis:
  1. Hash algorithm audit: Grep for MD5, SHA1, SHA-256 (without key) used in security contexts (password hashing, token generation, signature verification).
  2. Key management: Find encryption keys, API secrets, and IVs — check if they are hardcoded, loaded from environment, or from a key management service.
  3. Password storage: Locate password hashing code and verify use of bcrypt, argon2, or scrypt with appropriate cost factors.
  4. Random number generation: Find random value generation and verify cryptographically secure sources are used for security-sensitive operations.
  5. TLS configuration: Check for TLS enforcement, certificate validation, and minimum protocol version.
  6. Encryption mode: Identify block cipher usage and verify ECB mode is not used for anything beyond single-block encryption.
When
--depth deep
, additionally trace:
  • 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
无论扫描器是否可用,都需执行手动代码分析:
  1. 哈希算法审计:搜索在安全场景(密码哈希、令牌生成、签名验证)中使用的MD5、SHA1、SHA-256(无密钥)。
  2. 密钥管理:查找加密密钥、API机密和初始化向量(IV)——检查它们是否硬编码、从环境变量加载或来自密钥管理服务。
  3. 密码存储:定位密码哈希代码,验证是否使用bcrypt、argon2或scrypt并配置了合适的成本因子。
  4. 随机数生成:查找随机值生成代码,验证安全敏感操作是否使用了加密安全的随机源。
  5. TLS配置:检查TLS强制实施、证书验证及最低协议版本。
  6. 加密模式:识别块密码的使用情况,验证ECB模式是否仅用于单块加密之外的场景。
当使用
--depth deep
参数时,额外追踪:
  • 加密密钥的来源及其在应用中的数据流
  • 敏感数据在存储和传输前是否已加密
  • 密钥轮换机制和生命周期

5. Report Findings

5. 报告发现结果

Format output per
../../shared/schemas/findings.md
using the
CRYPT
prefix (e.g.,
CRYPT-001
,
CRYPT-002
).
Include 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.md
的格式,使用
CRYPT
前缀格式化输出(例如:
CRYPT-001
,
CRYPT-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
.
  1. Weak hash algorithms for security — MD5 or SHA1 used for password hashing, token generation, integrity verification, or digital signatures.
  2. Hardcoded encryption keys and IVs — Symmetric keys, asymmetric private keys, or initialization vectors embedded directly in source code.
  3. Insecure random number generation
    Math.random()
    ,
    rand()
    , or
    random.random()
    used for tokens, session IDs, or cryptographic operations.
  4. 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.
  5. ECB mode usage — Block cipher encryption using ECB mode, which reveals patterns in the plaintext.
  6. Missing TLS enforcement — HTTP used where HTTPS is required, disabled certificate validation, or outdated TLS versions allowed.
  7. Insufficient key derivation — Using encryption keys directly from passwords without a proper key derivation function (PBKDF2, HKDF).
  8. Static or predictable IVs/nonces — Initialization vectors or nonces that are hardcoded, reused, or derived from predictable sources.
以下是与加密失败相关的高信号模式,每个模式都对应
references/detection-patterns.md
中的检测模式。
  1. 安全场景下使用弱哈希算法——MD5或SHA1用于密码哈希、令牌生成、完整性验证或数字签名。
  2. 硬编码加密密钥和IV——对称密钥、非对称私钥或初始化向量直接嵌入源代码中。
  3. 不安全的随机数生成——
    Math.random()
    rand()
    random.random()
    用于令牌、会话ID或加密操作。
  4. 未正确哈希的密码存储——密码以明文存储、使用可逆加密,或使用快速哈希算法(MD5、SHA系列)而非专门的密码哈希函数。
  5. ECB模式的使用——块密码加密使用ECB模式,这会泄露明文的模式信息。
  6. 未强制实施TLS——在需要HTTPS的场景下使用HTTP、禁用证书验证,或允许使用过时的TLS版本。
  7. 密钥推导不足——直接从密码生成加密密钥,未使用适当的密钥推导函数(PBKDF2、HKDF)。
  8. 静态或可预测的IV/Nonce——初始化向量或Nonce是硬编码、重复使用或来自可预测源的。

Scanner Integration

扫描器集成

ScannerCoverageCommand
semgrepWeak crypto, hardcoded keys, insecure random
semgrep scan --config auto --json --quiet <target>
banditPython crypto issues (MD5, DES, hardcoded passwords)
bandit -r <target> -f json -q
gosecGo crypto (weak TLS, hardcoded creds)
gosec -fmt json ./...
gitleaksHardcoded keys and secrets
gitleaks detect --source <target> --report-format json --report-path /dev/stdout --no-banner
Fallback (no scanner): Use Grep with patterns from
references/detection-patterns.md
to find hash function calls, encryption operations, key assignments, and random number generation. Report findings with
confidence: medium
.
Relevant 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弱加密、硬编码密钥、不安全随机数
semgrep scan --config auto --json --quiet <target>
banditPython加密问题(MD5、DES、硬编码密码)
bandit -r <target> -f json -q
gosecGo加密问题(弱TLS、硬编码凭据)
gosec -fmt json ./...
gitleaks硬编码密钥和机密信息
gitleaks detect --source <target> --report-format json --report-path /dev/stdout --no-banner
Fallback(无扫描器时):使用Grep结合
references/detection-patterns.md
中的模式,查找哈希函数调用、加密操作、密钥赋值和随机数生成。报告结果时标记
confidence: 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:
    CRYPT
    (e.g.,
    CRYPT-001
    )
  • metadata.tool:
    crypto
  • metadata.framework:
    owasp
  • metadata.category:
    A02
  • references.owasp:
    A02:2021
  • references.stride:
    I
    (Information Disclosure) or
    T
    (Tampering)
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,
    Math.random()
    for tokens
  • 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进行密码哈希(未被破解但并非理想选择)、非安全场景使用弱哈希算法