
Demonstrates a padding oracle attack against AES-CBC encryption using a vulnerable Flask decrypt endpoint and a Python exploit script to decrypt arbitrary ciphertext without the key.
# padding_oracle_server.py - Server that returns padding error
from flask import Flask, request
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import os
key = os.urandom(16)
app = Flask(__name__)
@app.route('/decrypt', methods=['POST'])
def decrypt():
ct = bytes.fromhex(request.form['ciphertext'])
cipher = AES.new(key, AES.MODE_CBC, iv=ct[:16])
try:
pt = unpad(cipher.decrypt(ct[16:]), 16)
return "OK"
except ValueError:
return "Padding error", 400
if __name__ == '__main__':
app.run(port=5000)
A web application decrypts data using AES‑CBC and leaks whether the padding is valid. An attacker can submit modified ciphertexts and, based on the server’s error responses, iteratively decrypt or encrypt arbitrary data without knowing the key.
pip install flask pycryptodome
python padding_oracle_server.py
python exploit_padding_oracle.py
The oracle detection confirms the vulnerability; full exploitation uses tools like padbuster.