Created
April 22, 2020 06:23
-
-
Save rarecoil/afcbcbf830fedc654043060d22424de6 to your computer and use it in GitHub Desktop.
CryptoHack: Passwords as Keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from Crypto.Cipher import AES | |
import requests | |
import hashlib | |
import sys | |
import binascii | |
result = requests.get('https://aes.cryptohack.org/passwords_as_keys/encrypt_flag') | |
ciphertext_hex = result.json()["ciphertext"] | |
with open('words', 'r') as f: | |
for word in f: | |
word = word.strip() | |
attempted_key = hashlib.md5(word.encode()).hexdigest() | |
ciphertext = bytes.fromhex(ciphertext_hex) | |
key = bytes.fromhex(attempted_key) | |
cipher = AES.new(key, AES.MODE_ECB) | |
try: | |
decrypted = cipher.decrypt(ciphertext) | |
result = binascii.unhexlify(decrypted.hex()) | |
if result.startswith('crypto{'.encode()): | |
print("key is %s" % word) | |
print(result.decode('utf-8')) | |
sys.exit(0) | |
except ValueError as e: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment