
동일한 nonce를 사용하는 암호문을 수집하여 AES-GCM nonce 재사용 공격을 시연하며, 취약한 애플리케이션에서 GHASH 키 유출, 메시지 위조 및 키 복구로 이어집니다.
# aes_gcm_nonce_reuse_sim.py - Simulated encryption oracle with fixed nonce
from Crypto.Cipher import AES
import os
key = os.urandom(16)
nonce = b'\x00' * 12 # ALWAYS SAME NONCE
def encrypt(plaintext):
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
ct, tag = cipher.encrypt_and_digest(plaintext)
return ct, tag
# Vulnerable: attacker can obtain many ciphertexts with same nonce
ct1, tag1 = encrypt(b"Secret message 1")
ct2, tag2 = encrypt(b"Secret message 2")
print("Ciphertexts collected. Nonce reuse allows key recovery and forgery.")
애플리케이션이 고정된 논스를 사용(또는 논스를 반복)하여 AES‑GCM 암호화를 수행합니다. 이로 인해 공격자가 동일한 논스로 생성된 여러 암호문을 관찰할 경우 인증 키를 복구하고, 임의의 메시지를 위조하며, 나아가 암호화 키까지 복구할 수 있습니다.
시뮬레이션을 실행하여 위험성을 확인하세요:
pip install pycryptodome
python aes_gcm_nonce_reuse_sim.py
이 프로그램은 동일한 논스로 생성된 암호문이 발생했음을 출력하여 취약점을 강조합니다.