Skip to content

Instantly share code, notes, and snippets.

@dkales

dkales/attack.py Secret

Created February 23, 2016 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkales/d396c0318d12e93d89fa to your computer and use it in GitHub Desktop.
Save dkales/d396c0318d12e93d89fa to your computer and use it in GitHub Desktop.
Hashdesigner Internetwache CTF challenge crypto70
#!/usr/bin/python2
from pwn import *
import random
def proof_of_work(prefix, rlen=15, hashfunc=hashlib.sha1):
i = 0
maxiter = 2 ** 28
while i < maxiter:
i += 1
s = prefix
for _ in range(rlen-len(s)):
s += random.choice(string.lowercase+string.digits)
h = hashfunc()
h.update(s)
digest = h.digest()
binary = ''.join('{0:08b}'.format(ord(x)) for x in digest)
if binary.endswith("0"*16):
log.info("found proof of work after {} iterations"
.format(i))
return s
log.critical("couldn't find matching proof of work after {} iterations"
.format(i))
return None
p = remote("188.166.133.53", 10009)
line = p.recvline()
prefix = line[line.find("It has ")+7:line.find(" as the prefix.")]
proof = proof_of_work(prefix)
p.recv(len("Enter work:"))
p.sendline(proof)
succ = p.recvline()
assert("Thank you" in succ)
p.sendline("DhvxGXEdJkRiv4QEDS") # brute-forced offline
p.interactive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment