关于 Cryptographic Analysis & Assessment
面向安全从业者的 Claude 技能,用于评估密码配置与实现。它检查 TLS、密码套件、哈希、代码和密钥管理,并涵盖后量子迁移考量。
主要功能
- 01TLS 配置审计
- 02密码套件强度评估
- 03哈希识别与审查
- 04密码实现代码审查
- 05密钥管理与轮换建议
- 06后量子迁移评估
适用场景
- 01审计服务的 TLS 设置
- 02检查代码中的弱加密模式
- 03评估密码哈希方案
- 04规划向 PQC 迁移密码技术
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ masriyan/ claude-code-cybersecurity-skill --skill cryptographic-analysis-&-assessment安装后在 Claude Code 中输入/cryptographic-analysis-&-assessment确认已加载。
附带文件scripts/tls_auditor.pyexamples/example_usage.md
详细介绍
密码分析与评估
目的
帮助 Claude 进行密码安全评估,包括 SSL/TLS 配置审计、密码套件分析与建议、哈希算法识别、加密实现代码审查、密钥管理评估,以及检测密码学漏洞。Claude 会直接分析提供的配置和代码。
激活条件
用户提出以下问题时,此技能会激活:
- 审计服务器或服务的 SSL/TLS 配置
- 评估密码套件的安全强度
- 根据哈希值或代码识别哈希算法
- 审查代码中的密码学实现缺陷
- 评估密钥长度、密钥管理或轮换策略
- 检测硬编码密钥、弱 IV 或 ECB 模式的使用
- 生成 TLS 配置建议(Mozilla 配置)
- 分析证书(过期时间、证书链、透明度)
- 提供后量子密码学指导
- 审查密码哈希实现(bcrypt、Argon2、PBKDF2)
前提条件
pip install cryptography requests pyOpenSSL
推荐工具:
sslyze— Python TLS 扫描器testssl.sh— 全面的 TLS 测试openssl— 命令行 TLS 操作Wireshark— TLS 流量分析certbot— 证书管理
核心能力
1. SSL/TLS 配置审计
用户要求审计服务器 TLS 或粘贴 TLS 配置时:
命令行审计方法:
# Quick TLS check using openssl
openssl s_client -connect example.com:443 -tls1_2 2>/dev/null | grep -E "Protocol|Cipher"
openssl s_client -connect example.com:443 -tls1 2>/dev/null | grep -E "handshake|error"
# Check certificate details
openssl s_client -connect example.com:443 </dev/null 2>/dev/null | openssl x509 -noout -dates -subject -issuer
# Comprehensive scan with sslyze
sslyze --regular example.com --json_out result.json
# Or testssl.sh (most comprehensive)
./testssl.sh --severity HIGH --quiet example.com
# Use the skill's script
python scripts/tls_auditor.py --host example.com --port 443 --output report.json
python scripts/tls_auditor.py --host mail.example.com --port 993 --grade
TLS 版本支持评级:
| 协议 | 状态 | 操作 |
|---|---|---|
| SSLv2 | 严重缺陷 | 立即禁用 |
| SSLv3 | 存在缺陷(POODLE) | 立即禁用 |
| TLS 1.0 | 已弃用(违反 PCI-DSS) | 禁用 — BEAST、POODLE |
| TLS 1.1 | 已弃用 | 禁用 |
| TLS 1.2 | 可接受(使用强密码套件时) | 限制使用 |
| TLS 1.3 | 当前标准 | 启用并优先使用 |
TLS 漏洞检查清单:
[ ] Heartbleed (CVE-2014-0160): openssl s_client + heartbleed test
[ ] POODLE: SSLv3 enabled?
[ ] BEAST: TLS 1.0 + CBC cipher?
[ ] ROBOT: RSA key exchange supported?
[ ] DROWN: SSLv2 on any port of same server?
[ ] Logjam/FREAK: DHE < 2048-bit or EXPORT ciphers?
[ ] CRIME/BREACH: TLS compression enabled?
[ ] Sweet32: 3DES (64-bit block cipher) supported?
[ ] Weak certificate: RSA < 2048-bit, SHA-1 signed?
[ ] Certificate validity: Not expired, chain complete, not self-signed for prod?
[ ] HSTS: Strict-Transport-Security header present?
[ ] CT: Certificate in public transparency logs?
2. 密码套件强度评估
用户询问密码套件安全性时:
TLS 1.3 密码套件(均安全 — 请使用):
| 密码套件 | 密钥交换 | 身份验证 | 加密 | MAC | 评级 |
|---|---|---|---|---|---|
| TLS_AES_256_GCM_SHA384 | ECDHE | RSA/ECDSA | AES-256-GCM | SHA-384 | A+ |
| TLS_CHACHA20_POLY1305_SHA256 | ECDHE | RSA/ECDSA | ChaCha20 | Poly1305 | A+ |
| TLS_AES_128_GCM_SHA256 | ECDHE | RSA/ECDSA | AES-128-GCM | SHA-256 | A |
TLS 1.2 密码套件评级:
| 密码套件 | 评级 | 备注 |
|---|---|---|
| ECDHE-ECDSA-AES256-GCM-SHA384 | A+ | 极佳 — AEAD、PFS |
| ECDHE-RSA-AES256-GCM-SHA384 | A+ | 极佳 — AEAD、PFS |
| ECDHE-RSA-AES128-GCM-SHA256 | A | 良好 — AEAD、PFS |
| DHE-RSA-AES256-GCM-SHA384 | A | 良好 — DHE ≥ 2048 位时 |
| AES256-GCM-SHA384 | B | 无前向保密性 |
| ECDHE-RSA-AES256-SHA384 | B | CBC 模式(时序攻击) |
| RC4-SHA | F | RC4 存在缺陷 — 切勿使用 |
| DES-CBC3-SHA | F | 3DES 存在漏洞(Sweet32) |
| NULL-SHA | F | 未加密 |
| EXPORT-RC4-MD5 | F | 存在 FREAK 漏洞 |
推荐的 nginx TLS 配置(Mozilla 现代配置):
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off; # TLS 1.3 ignores this; client order for TLS 1.2
# For TLS 1.2 compatibility
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
# DH parameters for DHE cipher suites
ssl_dhparam /etc/nginx/dhparam.pem; # Generate: openssl dhparam -out dhparam.pem 4096
# Session management
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Disabling improves forward secrecy
# HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 8.8.8.8 valid=300s;
生成 DH 参数:
# 4096-bit DH parameters (do this once, takes a few minutes)
openssl dhparam -out /etc/nginx/dhparam.pem 4096
3. 哈希算法识别与评估
当用户提供哈希值或要求识别哈希算法时:
按格式识别哈希:
| 哈希格式 / 长度 | 算法 | 安全状态 |
|---|---|---|
| 32 个十六进制字符 | MD5 | 已失效 — 存在碰撞攻击 |
| 40 个十六进制字符 | SHA-1 | 已弃用 — 存在 SHAttered 碰撞 |
| 56 个十六进制字符 | SHA-224 | 可接受(用途有限) |
| 64 个十六进制字符 | SHA-256 | 当前标准 |
| 96 个十六进制字符 | SHA-384 | 安全性强 |
| 128 个十六进制字符 | SHA-512 | 安全性强 |
$apr1$... | MD5-APR(Apache) | 较弱 — 仅迭代 1000 次 |
$1$... | MD5-crypt | 已失效 |
$5$... | SHA-256-crypt | 可接受 |
$6$... | SHA-512-crypt | 良好 |
$2b$12$... | bcrypt(成本 12) | 适用于密码 |
$argon2id$... | Argon2id | 最适用于密码 |
sha256:... | Django SHA-256 | 良好 |
pbkdf2_sha256$... | PBKDF2-SHA256 | 迭代次数 ≥ 260,000 时效果良好 |
密码哈希安全性评估:
bcrypt:
$2b$10$... → cost factor 10 → ~100ms/hash → ACCEPTABLE
$2b$12$... → cost factor 12 → ~400ms/hash → GOOD
$2b$14$... → cost factor 14 → ~1.6s/hash → STRONG
Argon2id (OWASP recommended):
Minimum: m=19456 (19MB), t=2 iterations, p=1 parallelism
Strong: m=65536 (64MB), t=3 iterations, p=4 parallelism
PBKDF2:
SHA-1: 1,300,000 iterations minimum (NIST 2023)
SHA-256: 600,000 iterations minimum (NIST 2023)
SHA-512: 210,000 iterations minimum (NIST 2023)
Avoid:
Plain MD5/SHA-1 → instantly cracked
bcrypt cost < 10 → too fast for modern hardware
No salt → rainbow table attack
SHA-256 without KDF → GPU-crackable
4. 加密实现代码审查
当用户要求审查代码中的加密缺陷时:
Claude 会直接读取代码并标记以下模式:
Python 加密反模式:
# INSECURE: Hardcoded encryption key
key = b"mysecretkey12345" # ← NEVER hardcode keys
cipher = AES.new(key, AES.MODE_ECB) # ← ECB mode is insecure
# INSECURE: ECB mode (produces identical ciphertext for identical blocks)
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_ECB) # ← Pattern detection attacks possible
# INSECURE: Static/reused IV
iv = b"\x00" * 16 # ← Static IV allows pattern detection
cipher = AES.new(key, AES.MODE_CBC, iv) # ← Reusing IV with same key = CRITICAL
# INSECURE: Weak hash for passwords
import hashlib
password_hash = hashlib.md5(password.encode()).hexdigest() # ← GPU-crackable
# INSECURE: Trusting certificate errors
import ssl
ssl._create_default_https_context = ssl._create_unverified_context # ← MitM possible
requests.get(url, verify=False) # ← Never do this in production
安全的 Python 加密模式:
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
import os, secrets
# SECURE: Derive key from password using PBKDF2
def derive_key(password: bytes, salt: bytes = None) -> tuple[bytes, bytes]:
if salt is None:
salt = secrets.token_bytes(32) # 256-bit random salt
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32, # 256-bit key
salt=salt,
iterations=600_000 # NIST 2023 minimum for PBKDF2-SHA256
)
key = kdf.derive(password)
return key, salt
# SECURE: AES-GCM (authenticated encryption)
def encrypt(data: bytes, key: bytes) -> bytes:
aesgcm = AESGCM(key)
nonce = secrets.token_bytes(12) # 96-bit random nonce (NEVER reuse!)
ciphertext = aesgcm.encrypt(nonce, data, associated_data=None)
return nonce + ciphertext # Prepend nonce for decryption
def decrypt(ciphertext: bytes, key: bytes) -> bytes:
aesgcm = AESGCM(key)
nonce = ciphertext[:12]
return aesgcm.decrypt(nonce, ciphertext[12:], associated_data=None)
# SECURE: Argon2id for password hashing
from argon2 import PasswordHasher
ph = PasswordHasher(time_cost=3, memory_cost=65536, parallelism=4)
hashed = ph.hash(password) # Automatic random salt
ph.verify(hashed, password) # Verify with timing-safe comparison
代码审查清单:
Encryption:
[ ] No hardcoded keys (check for key = b"...", SECRET_KEY = "...", etc.)
[ ] No ECB mode (MODE_ECB, "AES/ECB/PKCS5Padding")
[ ] IV/Nonce is random and unique per encryption operation
[ ] Authenticated encryption used (AES-GCM, ChaCha20-Poly1305)
[ ] Key properly derived from password (PBKDF2, bcrypt, Argon2)
[ ] No custom/homebrew crypto algorithms
Certificate Handling:
[ ] Certificate validation is NOT disabled (verify=True)
[ ] Certificate pinning for mobile/critical apps
[ ] No ssl._create_unverified_context
Randomness:
[ ] Cryptographic operations use secrets module or os.urandom()
[ ] Not using random.random() or random.randint() for security
[ ] Tokens and OTPs have sufficient entropy (≥128 bits)
5. 密钥管理评估
当用户询问密钥管理时:
密钥长度建议(2025):
| 算法 | 最低要求 | 建议 | 备注 |
|---|---|---|---|
| RSA | 2048 位 | 3072 位 | NIST 建议 2030 年后使用 3072 位以上 |
| ECC(ECDSA) | P-256 | P-384 | P-256 可用至 2030 年 |
| AES | 128 位 | 256 位 | 128 位足够;高价值场景使用 256 位 |
| ECDH(密钥交换) | P-256 | P-384 | |
| DH(经典) | 2048 位 | 3072 位 | 应避免,优先使用 ECDH |
| SHA(哈希) | SHA-256 | SHA-256/384/512 | SHA-1 已弃用 |
后量子密码学迁移:
NIST 于 2024 年最终确定了 PQC 标准:
- ML-KEM(CRYSTALS-Kyber)— 密钥封装机制(在密钥交换中取代 RSA/ECDH)
- ML-DSA(CRYSTALS-Dilithium)— 数字签名(取代 RSA/ECDSA)
- SLH-DSA(SPHINCS+)— 无状态哈希签名(保守的备用方案)
对于预期在 2030 年后仍需保护数据的系统,应开始规划 PQC 迁移。
密钥轮换计划:
| 密钥类型 | 建议轮换周期 |
|---|---|
| TLS 证书 | 每年一次(或使用 90 天有效期的 Let's Encrypt 证书) |
| 签名密钥(JWT/API) | 90 天 |
| 加密密钥(静态数据) | 每年一次 |
| API 密钥 / 服务令牌 | 90 天或按服务设定 |
| 员工 SSH 密钥 | 每年一次 + 岗位变动时 |
| 密码哈希 | 密码变更时 |
脚本参考
tls_auditor.py
python scripts/tls_auditor.py --host example.com --port 443 --output report.json
python scripts/tls_auditor.py --host mail.example.com --port 993 --grade
技能集成
| 条件 | 相邻技能 |
|---|---|
| Web 应用 TLS 审计 | ← 技能 09(Web 安全) |
| 云服务加密评估 | ← 技能 10(云安全) |
| 发现弱加密 → 加固建议 | → 技能 15(蓝队防御) |
| 加密缺陷 → 漏洞报告 | → 技能 02(漏洞扫描器) |
参考资料
- Mozilla SSL 配置生成器
- NIST SP 800-52 Rev. 2 — TLS 指南
- SSL Labs 评级标准
- NIST 后量子密码学标准
- OWASP 加密失败
- OWASP 加密存储备忘单
- NIST 密码存储指南
v3.0 增强(2026 年更新)
后量子迁移现已投入实际应用:
- PQC 标准已定稿 — FIPS 203(ML-KEM,密钥封装)、FIPS 204(ML-DSA,签名)和 FIPS 205(SLH-DSA,基于哈希的签名)已发布。新设计建议采用这些标准;FIPS 206(FN-DSA/Falcon)即将发布。
- 混合密钥交换 — 对于 TLS,建议采用混合组(例如 X25519+ML-KEM-768 /
X25519MLKEM768),以便在迁移期间,即使遭受经典计算和量子攻击,机密性也能得到保障。 - 先收集、后解密 — 对长期机密以及需要多年保密的数据,优先采用 PQC;这是当前风险,而非未来风险。
- 密码敏捷性 — 标记硬编码的算法和密钥长度;建议采用抽象层,以便替换密码原语。将密码学资产(CBOM)列入清单,作为迁移的第一步。
- 严格弃用 — 优先采用 TLS 1.3 / 禁用 TLS 1.0-1.1;将 SHA-1 和 RSA/DH < 2048 标记为不合格;RSA-2048 目前仍可接受,但已进入 PQC 迁移倒计时。
精确性规则: 每项发现都要注明密码原语、密钥长度/曲线、协议版本,以及具体的升级方案(当前的经典方案和目标 PQC 方案)。