Skip to content

Instantly share code, notes, and snippets.

@c3c
Last active October 9, 2016 13:59
Show Gist options
  • Save c3c/f5b4dc1988c334b5c01b67870d7fc35e to your computer and use it in GitHub Desktop.
Save c3c/f5b4dc1988c334b5c01b67870d7fc35e to your computer and use it in GitHub Desktop.
Hackover CTF rollthedice solution
from pwn import *
from Crypto.Cipher import AES
r = remote("challenges.hackover.h4q.it", 1415)
def decr(key, roll):
return u16(AES.new(key).decrypt(roll)[:2], endian="big")
for i in range(32):
r.recvuntil("My dice roll: ")
roll = b64d(r.recvline())
r.recvuntil("Your dice roll: ")
r.sendline(b64e(roll))
r.recvuntil("My key: ")
key = b64d(r.recvline())
dice = decr(key, roll)
log.info("Got dice roll: %d" % dice)
# only the first 2 bytes of the AES block are relevant
# we can bruteforce a key which decrypts to the bytes we need
i = 0
while True:
trykey = p64(0)+p64(i)
if decr(trykey, roll) == 7-dice:
break
i+=1
r.recvuntil("Your key: ")
r.sendline(b64e(trykey))
r.interactive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment