Created
August 25, 2015 05:05
-
-
Save icheernoom/325a82161a8f40d9e90f to your computer and use it in GitHub Desktop.
Python script to solve "Statistics" challenge in IceCTF 2015
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, time | |
def get_num(recv): | |
m = re.match("(.+)\nGimme", recv) | |
num = m.group(1).split(' ') | |
num = map(int, num) | |
return num | |
def calc(recv): | |
if "maximum" in recv: | |
print "[+] Maximum" | |
return max(get_num(recv)) | |
elif "minimum" in recv: | |
print "[+] Minimum" | |
return min(get_num(recv)) | |
elif "sum" in recv: | |
print "[+] Sum" | |
num = get_num(recv) | |
num = "+".join(map(str, num)) | |
sum = eval(num) | |
return sum | |
elif "average" in recv: | |
print "[+] Average" | |
num = get_num(recv) | |
count = len(num) | |
num = "+".join(map(str, num)) | |
sum = eval(num) | |
var = str(float(sum)/float(count)) | |
return var | |
else: | |
print recv | |
exit() | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('vuln2015.icec.tf', 9000)) | |
while True: | |
time.sleep(4) | |
recv = s.recv(81920000) | |
data = calc(recv) | |
print "[*] Sending:",data | |
s.send(bytes(data)+"\r\n") | |
s.close | |
''' | |
root@ubuntu:~# python prog50.py | |
[+] Maximum | |
[*] Sending: 6915 | |
[+] Minimum | |
[*] Sending: 27 | |
[+] Maximum | |
[*] Sending: 9802 | |
[+] Minimum | |
[*] Sending: 1873 | |
[+] Minimum | |
[*] Sending: 336 | |
[+] Sum | |
[*] Sending: 291411 | |
...[snip]... | |
[+] Minimum | |
[*] Sending: 6 | |
[+] Average | |
[*] Sending: 4903.53196622 | |
[+] Average | |
[*] Sending: 4962.05309735 | |
[+] Maximum | |
[*] Sending: 9999 | |
[+] Average | |
[*] Sending: 4914.8852459 | |
[+] Minimum | |
[*] Sending: 4 | |
Welcome Daniel! | |
The flag is: why_is_there_code_in_my_statistics | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment