Skip to content

Instantly share code, notes, and snippets.

@hugsy
Created April 30, 2017 00:43
Show Gist options
  • Save hugsy/701b1d5c67dc22c5f51639365dba9597 to your computer and use it in GitHub Desktop.
Save hugsy/701b1d5c67dc22c5f51639365dba9597 to your computer and use it in GitHub Desktop.
magic - defcon 2017
#!/usr/bin/python2
#
# magic - defcon 2017
#
# @_hugsy_
#
# The flag is: a color map of the sun sokemsUbif
#
import os, base64, telnetlib
from subprocess import *
def crack(f):
pre = ""
while True:
found = False
for i in range(256):
c = chr(i)
p = Popen(["magic_dist/%s" % f,],
stdout=PIPE,
stdin=PIPE,
close_fds=True
)
res = p.stdout.read(11)
p.stdin.write(pre+chr(i) + '\n')
p.wait()
if p.returncode == 0:
return pre+c
if p.returncode != len(pre)+1:
pre += c
found = True
break
if p.returncode==0xFA:
return pre + c
if not found:
raise Exception("bye")
return pre
t = telnetlib.Telnet("cm2k-magic_b46299df0752c152a8e0c5f0a9e5b8f0.quals.shallweplayaga.me", 12001)
t.read_until('send your solution as base64, followed by a newline\n')
while True:
h = t.read_until('\n').strip()
print "<<< ", h
res = crack(h)
t.write( base64.b64encode(res) + '\n')
print ">>> ", res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment