Post quantum migration attack

From brucesongs/kali-claw · View interactive version

Post quantum migration attack is an AI agent skill from the GitHub repository brucesongs/kali-claw. Attacks against cryptographic systems during the PQC migration period. Covers Harvest-Now-Decrypt-Later (SNDL/HNDL), hybrid PQC downgrade abuse, KEM combiner flaws, mixed-protocol failures, NIST PQC standard implementations (ML-KEM/Kyber, ML-DSA/Dilithium, SLH-DSA/SPHINCS+), and QKD infrastructure a

How to use this skill

Skill file

Post-Quantum Migration Attack

Summary

Attackers target cryptographic systems during the multi-year window before quantum computers break RSA/ECC but after adversaries begin capturing long-lived ciphertext ("Harvest Now, Decrypt Later"). The migration to Post-Quantum Cryptography (PQC) introduces new attack surfaces: hybrid PQC downgrade abuse, KEM combiner flaws, signature stripping in mixed protocols, side-channels in lattice implementation (MatrixVector multiplication timing), and Classical/Post-Quantum (CPQ) certificate chain inconsistencies. This domain covers red-teaming PQC deployments, auditing migration agility, and exploiting transition-period weaknesses in TLS 1.3 + Kyber, SSH + NTRU-Prime, X.509 + Dilithium, IPsec + McEliece, Signal + PQXDH, and QKD infrastructure (BB84/E91 protocols, trusted nodes, key relay).

Use Cases

Core Tools

| Tool | Purpose |

|------|---------|

| oqs-provider | OpenSSL 3.x provider enabling ML-KEM/ML-DSA in TLS |

| liboqs | Reference C library for PQC algorithms |

| oqs-openssl111 | OpenSSL 1.1.1 fork with PQC (legacy) |

| testssl.sh | TLS scanner with PQC cipher detection |

| ssh-audit | SSH server scanner with PQC kex detection |

| Wireshark | Packet analysis with PQC TLS dissectors |

| PQCmule | Hybrid PQC test server |

| pqcrystals | Reference Kyber/Dilithium/SPHINCS+ implementations |

| SageMath | Lattice reduction (BKZ, LLL) for cryptanalysis |

| fpylll | Python LLL library for lattice cryptanalysis |

| ThunderKitten | FPGA-based side-channel PQC test bench |

| qkd-simulator | BB84/E91 QKD protocol test simulator |

| curl-oqs | curl build with PQC TLS support |

| nginx-oqs | nginx build with PQC TLS |

| mitmproxy | MITM with custom PQC TLS handlers |

| tcpdump | Passive capture for HNDL analysis |

| cryptoadvance/specter | Bitcoin/script PQC migration testing |

Methodology

Phase 1 — Discovery & Inventory

Identify classical, hybrid, and PQ-only deployments. Map protocol → algorithm posture:

# TLS PQC cipher detection
testssl --wide --color 0 https://target.example.com | grep -iE "kyber|dilithium|pqc|x25519kyber|secp256r1kyber"

# SSH PQC kex detection
ssh-audit target.example.com | grep -iE "sntrup|pq|post-quantum"

# IPsec proposal audit (StrongSwan)
ipsec statusall | grep -iE "ike=|esp="

Phase 2 — HNDL Threat Modeling

Identify data with long-lived confidentiality. Model SNDL capture points:

# Capture TLS handshakes (long-lived ciphertext source)
tcpdump -i eth0 -w hndl.pcap 'tcp port 443' &

# Identify encryption curves (Kyber hybrid vs classical)
tshark -r hndl.pcap -Y "tls.handshake.type == 2" \
  -T fields -e tls.handshake.extensions.supported_groups

Phase 3 — Downgrade & Stripping Attacks

Test whether MITM can force classical-only:

# MITM with mitmproxy removing Kyber from supported_groups
mitmproxy --mode transparent \
  --set tls_versions="TLS1.3" \
  --script strip-kyber.py

# Or via Wireshark filter
tshark -r capture.pcap -Y "tls.handshake.extensions.supported_groups !contains 0x07e4"

Phase 4 — KEM Combininer Flaw Analysis

Audit hybrid KEM combiner. XOR combiner is unsafe if any component is broken:

# Verify combiner uses KDF (HKDF), not XOR
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes

# Safe: HKDF(ct1 || ct2 || ss1 || ss2)
combined = HKDF(
    algorithm=hashes.SHA3_256(),
    length=32,
    salt=None,
    info=b"x25519-kyber768-combiner-v1"
).derive(x25519_ss + kyber768_ss)

Phase 5 — PQC Implementation Cryptanalysis

Test lattice-based implementations for side-channels:

# Build liboqs with timing instrumentation
git clone https://github.com/open-quantum-safe/liboqs.git
cd liboqs && mkdir build && cd build
cmake -DOQS_ENABLE_KEM_CLASSICAL_MCELIECE=ON ..
make -j$(nproc)

# Run Kyber decaps with controlled inputs (cache timing)
python3 -c "
import time, oqs
kem = oqs.KeyEncapsulation('Kyber768')
pk = kem.generate_keypair()
ct_list = []
for _ in range(1000):
    ct, _ = kem.encap_secret(pk)
    ct_list.append(ct)
for ct in ct_list[:10]:
    t0 = time.perf_counter_ns()
    kem.decap_secret(ct)
    t1 = time.perf_counter_ns()
    print(t1 - t0)
"

Phase 6 — Certificate Chain Inconsistency

Test X.509 chains mixing classical and PQ:

# Generate ML-DSA (Dilithium) root CA
openssl req -x509 -provider oqsprovider -provider default \
  -newkey dilithium3 -keyout root.key -out root.crt \
  -subj "/CN=PQ Root CA" -days 3650

# Issue leaf cert with classical RSA but chain to PQ root
openssl req -newkey rsa:2048 -keyout leaf.key -out leaf.csr \
  -subj "/CN=hybrid-leaf"
openssl x509 -req -in leaf.csr -CA root.crt -CAkey root.key \
  -CAcreateserial -out leaf.crt -days 365 \
  -CAcreateserial

Phase 7 — Signal PQXDH Audit

Signal's PQXDH uses X3DH + Kyber. Audit the PQ layer:

# Signal PQXDH: X25519 + Kyber-1024
# Verify Kyber ciphertext is checked for identity binding
# Failure mode: server returns Kyber-1024 ciphertext without identity key
# Server MUST sign PQ identity in prekey bundle

# Test: prekey bundle without PQ signature
import requests
bundle = requests.get('https://signal.example.com/v2/keys/100').json()
assert 'pqPreKeySignature' in bundle, "PQ signature missing"

Phase 8 — QKD Infrastructure Attack

Test BB84/E91 QKD links:

# Detector blinding attack
# Many commercial QKD systems accept bright-light detector blinding
# Test: shine >1mW laser into fiber detector
# Vulnerable: detector enters linear mode → attacker controls all "quantum" bits

# Photon number splitting (PNS)
# Test: adversary with beam splitter captures multi-photon pulses
# Mitigation: decoy states

# Trusted node compromise
# Many commercial QKD networks use trusted relay (China: Beijing-Shanghai line)
# Test: compromise trusted node → recover all keys

Phase 9 — Digital Signature Stripping

Test whether PQ signatures are stripped in transit:

# SSH: force RSA-only by removing sntrup761 from kex
ssh -o KexAlgorithms=curve25519-sha256@libssh.org \
    -o PubkeyAcceptedAlgorithms=ssh-rsa \
    user@target.example.com

# Test if server accepts (vulnerable to downgrade)

Phase 10 — Reporting

Produce report covering:

Practical Steps

Step 1 — Inventory classical cryptography

# All RSA/ECC usage in target environment
grep -rnE "RSA_|ECC_|ecdh_|ecdsa_" /etc/ /opt/ /var/ 2>/dev/null | head

# TLS cert algorithm
echo | openssl s_client -connect target:443 2>/dev/null \
  | openssl x509 -noout -text | grep -E "Public Key Algorithm|Signature Algorithm"

Step 2 — Test hybrid PQC negotiation

# Using oqs-provider-enabled openssl
openssl s_client -connect target:443 \
  -groups "x25519kyber768draft00:x25519:secp256r1" \
  -tls1_3 2>&1 | grep -E "Server Temp Key|Peer signature type|KEM"

# Verify negotiated group
echo | openssl s_client -connect target:443 \
  -groups "x25519kyber768draft00" -tls1_3 2>&1 \
  | grep "Server Temp Key"

Step 3 — Attempt downgrade

# Try classical-only
echo | openssl s_client -connect target:443 \
  -groups "x25519" -tls1_3 2>&1 | grep "Server Temp Key"

# If server accepts both, test MITM downgrade feasibility
mitmproxy --mode regular -p 8080 \
  --set confdir=~/.mitmproxy \
  --script downgrade-to-classical.py

Step 4 — Audit KEM combiner

# Read TLS stack source
# Check combiner for XOR (unsafe) vs HKDF (safe)
# OpenSSL 3.x with oqs-provider uses NIST-compliant combiner

# Test combiner by observing key derivation via debugger
import subprocess
out = subprocess.check_output([
    'openssl', 's_client', '-connect', 'target:443',
    '-groups', 'x25519kyber768draft00',
    '-keylogfile', '/tmp/keylog'
])
# Verify keylog contains derived secret tied to both X25519 and Kyber

Step 5 — Test certificate chain

# Generate test PQ root
openssl genpkey -provider oqsprovider -algorithm dilithium3 -out root.key
openssl req -x509 -provider oqsprovider -provider default \
  -key root.key -out root.crt -subj "/CN=PQ Root CA" -days 3650

# Test server rejects chain mixing PQ root + classical leaf
openssl verify -CAfile root.crt classical_leaf.crt
# Expected: error (signature algorithm mismatch)
# Vulnerable: OK (chain algorithm cross-talk bug)

Step 6 — Audit JWT/COSE with PQ algorithms

# Test JWT library with ML-DSA
import jwt
# Generate ML-DSA keypair
# Sign JWT
# Verify library rejects alg confusion (e.g., "ML-DSA-65" → "HS256")

Step 7 — Capture for HNDL analysis

# Long-term capture of TLS handshakes (for retrospective decryption in ~10-15 years)
# Use Wireshark with keylog to identify which sessions are NOT forward-secret

tshark -i eth0 -f "tcp port 443" -w hndl-target.pcap \
  -T fields -e tls.handshake.type \
  -e tls.handshake.extensions.supported_groups \
  -e tls.handshake.certificate

Defense Perspective

Defenders must assume:

  1. Adversary has 10-year-old ciphertext — anything RSA/ECC-protected is at risk when CRQC arrives
  2. Crypto agility is mandatory — protocols must hot-swap algorithms without breaking clients
  3. Hybrid is required for transition — pure PQC algorithms have less battle-testing
  4. Side-channels in lattice implementations are real (multiple academic papers, e.g., Cyril Bouyssou's 2024 RowHammer attack on Kyber)
  5. KEM combiners matter — XOR combiners fail catastrophically; HKDF is safe
  6. PQ certificates are huge (SPHINCS+ public keys are 2KB+, signatures 8KB+) — protocol MTU issues
  7. QKD is not a silver bullet — has trusted-node vulnerabilities and limited distance
  8. Migration takes 5-15 years — start now, even for "low-sensitivity" data

Key defensive controls:

Key Terms

| Term | Definition |

|------|------------|

| CRQC | Cryptographically Relevant Quantum Computer — breaks RSA-2048, ECC-256 |

| HNDL / SNDL | Harvest Now, Decrypt Later — passive capture of ciphertext for future decryption |

| PQC | Post-Quantum Cryptography — algorithms resistant to quantum attacks |

| ML-KEM | Module Lattice KEM (NIST FIPS 203, formerly Kyber) |

| ML-DSA | Module Lattice Digital Signature Algorithm (NIST FIPS 204, formerly Dilithium) |

| SLH-DSA | Stateless Hash-based DSA (NIST FIPS 205, formerly SPHINCS+) |

| Hybrid PQC | Classical + PQ algorithm in single primitive (e.g., X25519Kyber768) |

| KEM combiner | Function to derive final secret from multiple KEM components |

| PQXDH | Post-Quantum Extended Diffie-Hellman (Signal's PQ protocol) |

| QKD | Quantum Key Distribution — physical-layer key exchange via quantum states |

| CNSA 2.0 | Commercial National Security Algorithm Suite (NSA, 2022) |

| Crypto agility | Ability to swap algorithms without protocol changes |

Compliance & Regulatory Context

Attack Surface Summary

| Surface | Attack | Reference |

|---------|--------|-----------|

| TLS 1.3 hybrid PQC | Downgrade (Kyber stripping) | payloads.md §3 |

| SSH PQ kex | Downgrade (curve25519 force) | payloads.md §3.3 |

| IPsec PQ ke | Classical DH force | payloads.md §3.4 |

| KEM combiner | XOR (unsafe) detection | payloads.md §4 |

| liboqs implementation | Timing / RowHammer / EM | payloads.md §5 |

| X.509 cert chain | PQ/classical cross-talk | payloads.md §6 |

| Signal PQXDH | PQ prekey stripping | payloads.md §7 |

| QKD infrastructure | Detector blind / PNS / trusted node | payloads.md §8 |

| JWT/COSE | PQ alg confusion | payloads.md §9 |

| Migration agility | Hot-swap race condition | payloads.md §10 |

Engagement Workflow

  1. Scoping: confirm protocols, libraries, QKD inclusion
  2. Discovery: inventory classical / hybrid / PQ posture
  3. HNDL capture: long-term passive collection
  4. Downgrade test: MITM strip PQ
  5. KEM combiner audit: source review
  6. Side-channel: timing / EM / RowHammer (if in scope)
  7. Cert chain: PQ/classical cross-talk
  8. PQXDH/QKD: protocol-specific audits
  9. Reporting: per-data-class migration roadmap

Algorithm Choice Matrix

| Use case | Recommended | Backup | Avoid |

|----------|-------------|--------|-------|

| General KEM | ML-KEM-768 | X25519+Kyber-768 | Pure RSA |

| Long-term KEM | ML-KEM-1024 | X25519+Kyber-1024 | ECC-only |

| General sig | ML-DSA-65 | RSA-3072+Dilithium-3 | ECDSA-only |

| Long-term sig | SLH-DSA-192s | ML-DSA-87 | Ed25519-only |

| Code signing | SLH-DSA-256f | ML-DSA-87 + RSA | RSA-only |

| HSM-bound KEM | ML-KEM-1024 (Thales 7.13+) | RSA-4096 (transition) | ECC-only |

Quantum Threat Timeline

Migration Priorities by Data Class

| Data class | Migration target | Rationale |

|-----------|------------------|-----------|

| State secrets | 2028 | 30-year confidentiality, state-level HNDL |

| Biometric | 2028 | Lifetime of subject |

| Genome | IMMEDIATE | Lifetime of descendants |

| Long-term keys | 2028 | 5-yr rotation insufficient |

| PII / PHI | 2030 | 10-year regulatory retention |

| Financial | 2032 | Compliance + fraud window |

| Ephemeral | 2035 | Short-lived data |

Detection Methods

PQC Migration Audit

SIEM Detection Rules

Defense Evasion Techniques

HNDL/SNDL (Harvest Now, Decrypt Later) Stealth

Hybrid PQC Downgrade

QKD (Quantum Key Distribution) Attack

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.