-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathoracle.py
More file actions
28 lines (23 loc) · 708 Bytes
/
oracle.py
File metadata and controls
28 lines (23 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
import sys,os
from Crypto.Cipher import AES
from settings import *
mode = AES.MODE_CBC
# AES CBC decryption
def decryption(encrypted):
decryptor = AES.new(key, mode, IV=IV)
return decryptor.decrypt(encrypted)
# Ckeck validity of PKCS7 padding
def pkcs7_padding(data):
pkcs7 = True
last_byte_padding = data[-1]
if(last_byte_padding < 1 or last_byte_padding > 16):
pkcs7 = False
else:
for i in range(0,last_byte_padding):
if(last_byte_padding != data[-1-i]):
pkcs7 = False
return pkcs7
# Determine if the message is encrypted with valid PKCS7 padding
def oracle(encrypted):
return pkcs7_padding(decryption(encrypted))