Last active
August 29, 2015 14:11
-
-
Save icheernoom/3d4fd19b75e3f9e2e76c to your computer and use it in GitHub Desktop.
Python script to solve "Choose the number" challenge in SECCON CTF 2014.
This file contains hidden or 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
#!/usr/bin/python | |
# Author: Kitwipat Towattana (@icheernoom) | |
import socket, re | |
def get_data(recv): | |
m = re.match("(.+)\nThe", recv) | |
return m | |
def get_num(m): | |
#num = re.split(", ",m.group(1)) | |
num = m.group(1).split(', ') | |
num = map(int, num) | |
return num | |
def min_max(recv): | |
print "===" | |
if "maximum" in recv: | |
print "maximum" | |
return max(get_num(get_data(recv))) | |
elif "minimum" in recv: | |
print "minimum" | |
return min(get_num(get_data(recv))) | |
else: | |
print recv | |
exit() | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('number.quals.seccon.jp', 31337)) | |
while(1): | |
recv = s.recv(2048) | |
data = min_max(recv) | |
print data | |
s.send(bytes(data)+"\r\n") | |
s.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment