Skip to content

Instantly share code, notes, and snippets.

@sonickun
Last active November 9, 2016 08:04
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 sonickun/0c56ae7090272a2be7517a5799023912 to your computer and use it in GitHub Desktop.
Save sonickun/0c56ae7090272a2be7517a5799023912 to your computer and use it in GitHub Desktop.
Hack The Vote 2016 | Boxes of Ballots (crypto 200pt)
import socket
import string
import time
flag_len = 23
remoteip = "boxesofballots.pwn.republican"
remoteport = 9001
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_{}"
def sock(remoteip, remoteport):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((remoteip, remoteport))
return s, s.makefile('rw', bufsize=0)
def read_until(f, delim='\n'):
data = ''
while not data.endswith(delim):
data += f.read(1)
return data
flag = ""
for i in range(flag_len):
s, f = sock(remoteip, remoteport)
send_data = '{"data": "%s", "op": "enc"}' % ('A'*(31-i))
s.send(send_data + "\n")
stream = read_until(f, "}")
cipher = stream.split('"')[-2]
first_block = cipher[:64]
print "[*] first_block:", first_block
s.close()
for c in charset:
s, f = sock(remoteip, remoteport)
send_data = '{"data": "%s%c", "op": "enc"}' % ('A'*(31-i)+flag, c)
print "send", send_data
s.send(send_data + "\n")
stream = read_until(f, "}")
cipher = stream.split('"')[-2]
if cipher[:64] == first_block:
flag = flag + c
print "[*] FLAG: %s" % flag
break
s.close()
print
# [*] FLAG: flag{Source_iz_4_noobs}
@sonickun
Copy link
Author

sonickun commented Nov 9, 2016

こちらが指定した平文にFlagを付加してAES-CBC暗号化した結果を返してくる。’A’×ブロック長の暗号文の先頭ブロックを保持しておき、’A’×(ブロック長-1)+xの暗号文の先頭ブロックと一致するようにxをブルートフォースするとFlagが1byte求まる(以下繰り返し)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment