Created
September 22, 2011 16:37
-
-
Save zoranzaric/1235279 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
#!/usr/bin/env python | |
from telnetlib import Telnet | |
import sys | |
def submit(flag): | |
t = Telnet("localhost", 8888) | |
t.read_very_eager() | |
t.write(flag) | |
result = t.read_very_eager() | |
if result == "nope...\n\n": | |
print "no" | |
elif result == "KTHXBYE!\n\n": | |
print "yes" | |
elif result == "U MAD?!\n\n": | |
print "..." | |
t.close() | |
if __name__ == '__main__': | |
if sys.stdin.isatty(): | |
flags = sys.argv[1:] | |
else: | |
flags = [line[0:-1] for line in sys.stdin] | |
for flag in flags: | |
submit(flag) |
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/env python | |
import socket | |
GREETING = """Welcome to teh awesome TUD submit server! | |
Please paste your flags! | |
""" | |
ADDRESS = ("127.0.0.1", 8888) | |
class SubmitServer(): | |
def __init__(self): | |
self.FLAGLEN = 5 | |
self.flags = set() | |
def _is_palindrome(self, flag): | |
return flag == flag[::-1] | |
def listen(self): | |
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
self.socket.bind(ADDRESS) | |
self.socket.listen(23) | |
print "Listening on %s:%d..." % ADDRESS | |
while True: | |
connection, address = self.socket.accept() | |
connection.send(GREETING) | |
msg = '' | |
while len(msg) < self.FLAGLEN: | |
chunk = connection.recv(self.FLAGLEN-len(msg)) | |
if chunk == '': | |
raise RuntimeError("socket connection broken") | |
msg = msg + chunk | |
print msg | |
if self._is_palindrome(msg): | |
if msg in self.flags: | |
connection.send("U MAD?!\n\n") | |
else: | |
self.flags.add(msg) | |
connection.send("KTHXBYE!\n\n") | |
else: | |
connection.send("nope...\n\n") | |
connection.close() | |
ss = SubmitServer() | |
ss.listen() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment