added default.nix and various ctf examples

This commit is contained in:
Emile Clark-Boman 2025-06-27 03:08:31 +10:00
parent b9c5a5bf3e
commit 89973b803c
6 changed files with 197 additions and 1 deletions

View file

@ -0,0 +1,46 @@
import requests
from imp.constants import PRINTABLE
from imp.attacks import paddingoracle
from Crypto.Util.Padding import pad
import string
NIBBLESET = [n.to_bytes() for n in range(256)]
HOST = 'https://aes.cryptohack.org'
ENDPOINT = '/ecb_oracle/encrypt/{0}/'
URI = HOST + ENDPOINT
CHARSET = [c.encode() for c in string.printable]
# CHARSET = NIBBLESET # OVERRIDE
FLAG_LEN = 26 # flag length, calculated by hand
SPACER = b'\x0f' # arbitrary spacing character
BLOCK_BYTES = 16
BLOCK_NIBBLES = 32 # measured in nibbles
def mkreq(hextext: str) -> dict[str, str]:
resp = requests.get(URI.format(hextext))
if resp.status_code != 200:
raise Exception(f'[!] resp failed! {resp} : {resp.text}')
return resp.json()
def encrypt(b: bytes) -> bytes:
resp = mkreq(b.hex())
return bytes.fromhex(resp['ciphertext'])
def main() -> None:
paddingoracle.crack(encrypt, pad, CHARSET, 16, batch_size=20, debug=True)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, EOFError):
print('\n[!] Interrupt')

View file

@ -0,0 +1,28 @@
import string
from imp.attacks import paddingoracle
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
CHARSET = [c.encode() for c in string.printable]
KEY = b'you wont get me!'
FLAG = b'imbaud{omg_you_catched_me}'
CIPHER = AES.new(KEY, AES.MODE_ECB)
def encrypt(b: bytes, debug=False) -> bytes:
padded = pad(b + FLAG, 16)
if debug:
print(padded)
# print(padded)
return CIPHER.encrypt(padded)
def main() -> None:
paddingoracle.crack(encrypt, pad, CHARSET, 16, batch_size=50, debug=True)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, EOFError):
print('\n[!] Interrupt')