Last active
November 9, 2016 08:04
-
-
Save sonickun/0c56ae7090272a2be7517a5799023912 to your computer and use it in GitHub Desktop.
Hack The Vote 2016 | Boxes of Ballots (crypto 200pt)
This file contains 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
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() | |
# [*] FLAG: flag{Source_iz_4_noobs} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こちらが指定した平文にFlagを付加してAES-CBC暗号化した結果を返してくる。’A’×ブロック長の暗号文の先頭ブロックを保持しておき、’A’×(ブロック長-1)+xの暗号文の先頭ブロックと一致するようにxをブルートフォースするとFlagが1byte求まる(以下繰り返し)