SuperAPI AI Directory

ctf-crypto

Security & auditing

View repository

Updated 10-16 09:35

About this skill

CTF Cryptography Attacks

In-Depth Reference

The following reference materialsload on demand, select the corresponding file according to the specific direction identified:


Classification Decision Tree

题目涉及加密?
├─ 古典密码(Caesar/Vigenere/XOR/替换) → [references/classic-ciphers.md](references/classic-ciphers.md)
├─ 对称加密(AES/DES/RC4/分组密码)
│  ├─ ECB → 块重排 / 逐字节oracle
│  ├─ CBC → 比特翻转 / Padding Oracle
│  └─ 流密码 → LFSR / Berlekamp-Massey
├─ RSA
│  ├─ 小e → 开根号         ├─ 小d → Wiener
│  ├─ p≈q → Fermat          ├─ 公共模数 → ExtGCD
│  └─ 部分已知因子 → Coppersmith (SageMath)
├─ ECC
│  ├─ 阶有小因子 → Pohlig-Hellman
│  ├─ 奇异曲线 → 映射到加法群
│  └─ ECDSA nonce重用 → 恢复私钥
├─ 格/LWE → Babai CVP / LLL 短向量
├─ PRNG → MT19937 untemper / LCG / V8 xs128p
├─ ZKP → 碰撞/预测盐 / Z3求解
└─ 哈希 → 长度扩展(hashpump) / 生日攻击

Quick Reference Tools

Scenario Tool/Command
RSA automatic attack RsaCtfTool.py -n N -e E --uncipher C
Substitution cipher quipqiup.com
SageMath sage -python script.py(Coppersmith/ECC/lattice)
Z3 constraint solving pip install z3-solver → BitVec / Int
PRNG MT19937 pip install not_random(floating-point state recovery)
V8 Math.random d0nutptr/v8_rand_buster
Padding Oracle PadBuster / padding-oracle library
XOR operation from pwn import xor

Commonly Used Python Libraries

pip install pycryptodome z3-solver sympy gmpy2

RSA Basics Quick Reference

from Crypto.Util.number import inverse, long_to_bytes
phi = (p-1)*(q-1)
d = inverse(e, phi)
m = pow(c, d, n)
print(long_to_bytes(m))

Common Patterns

  • RSA multiplicative homomorphism: unpadded RSA S(a)*S(b) mod n = S(a*b), can combine signature forgery
  • CBC Padding Oracle: ~4096 queries to decrypt a 16-byte block
  • Bleichenbacher (ROBOT): RSA PKCS#1 v1.5 padding oracle → ~10K queries to recover plaintext
  • CRC32 linearity: appending 4 bytes can forge any CRC32 signature
  • Hash length extension: Merkle-Damgard structure hash(SECRET||data) can append data

RSA Small Exponent Attack

  • When e=3, if m^3 < n (no modulo taken, no modular operation), the plaintext can be recovered directly by taking the cube root

Padding Oracle Details

  • At most 256 attempts per byte, brute-force trying all possible values