Skip to content

Instantly share code, notes, and snippets.

@AndyNovo AndyNovo/encryption.py Secret
Last active Feb 17, 2019

Embed
What would you like to do?
Somewhat contrived CTF problem
import hashlib
import random
from Crypto.Cipher import AES
#Find These At https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-100000.txt
f=file('10-million-password-list-top-100000.txt','r')
pwds = [pwd.strip() for pwd in f]
f.close()
#format ninja{...}
f=file('theflag','r')
flag=f.read()
f.close()
thispassword = random.choice(pwds)
cipher=AES.new(hashlib.sha256(thispassword).digest(), AES.MODE_ECB)
ct = cipher.encrypt(flag).encode('hex')
assert(cipher.decrypt(ct.decode('hex')) == flag)
def stretch(password, salt, iterations):
final=''
for r in range(iterations):
final = hashlib.sha256(final + password+salt).digest()
return final.encode('hex')
print "Stored in our database:", stretch(thispassword, "saltysalty", 5)
print "Encrypted Flag:",ct
Stored in our database: 22f2474bd416be6face5483ba5f4df44c5e22c9e8776bd3cdf109b12d5c9a699
Encrypted Flag: e82f6c5702f4c9c549cbee3fc6fbfb9ab9c27364b4471d22cb0feb628284cb30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.