Created
June 16, 2013 11:34
-
-
Save flankerhqd/5791791 to your computer and use it in GitHub Desktop.
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
| import os | |
| import socket | |
| import re | |
| import subprocess | |
| HOST = "bigbadbob.shallweplayaga.me" | |
| PORT = 2232 | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| BUFSIZE = 4096 | |
| ALGO = "/Users/hqdvista/Documents/algo/ctf/defcon/acm4" | |
| def connect(): | |
| s.connect((HOST,PORT)) | |
| def consume(): | |
| for i in range(0,4): | |
| rubbish = s.recv(4*BUFSIZE) | |
| print rubbish | |
| def getData(): | |
| data = s.recv(BUFSIZE) | |
| print data | |
| return data | |
| def sendRaw(data): | |
| s.send(data+"\n") | |
| if __name__ == '__main__': | |
| connect() | |
| consume() | |
| cnt = 1 | |
| data = getData() | |
| print data | |
| while True: | |
| p = subprocess.Popen([ALGO], | |
| stdout=subprocess.PIPE, | |
| stdin=subprocess.PIPE) | |
| p.stdin.write(data) | |
| p.stdin.close() | |
| resp = p.stdout.read() | |
| sendRaw(resp) | |
| data = getData() | |
| print data | |
| if data.find("Congratulations") != -1: | |
| print "iter %d done" % cnt | |
| cnt = cnt + 1 | |
| else: | |
| print "error" | |
| break | |
| p.terminate() | |
| print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment