
توضح استغلال إعادة استخدام 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 مع Nonce ثابت (أو يكرر Nonce). يتيح ذلك للمهاجم الذي يرصد نصوصًا مشفرة متعددة تحت نفس الـ Nonce استعادة مفتاح المصادقة، وتزوير رسائل عشوائية، وربما استعادة مفتاح التشفير.
شغّل المحاكاة لرؤية الخطر:
pip install pycryptodome
python aes_gcm_nonce_reuse_sim.py
يُظهر البرنامج إنشاء نصوص مشفرة بنفس الـ Nonce، مما يسلط الضوء على الثغرة.