Created
October 20, 2017 03:07
-
-
Save tqkve/7bb5925b3f76f71f1f7851c4373af011 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 socket | |
| import random | |
| from base64 import b64decode as bd,b64encode as be | |
| HOST = "flatearth.fluxfingers.net" | |
| # HOST = "localhost" | |
| PORT = 1718 | |
| def ru(s, end): | |
| res = "" | |
| while not res.endswith(end): | |
| res += s.recv(1) | |
| return res | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.connect((HOST, PORT)) | |
| ru(s, "> ") | |
| print "Connected" | |
| g = "" | |
| while len(g) != 8: | |
| _g = g | |
| while 1: | |
| s.send("1") | |
| ru(s, "> ") | |
| guess = "".join(chr(random.randint(0, 255)) for _ in xrange(2)) | |
| # print "guess: {}".format([guess]) | |
| s.send(g + guess) | |
| r = ru(s, "\nRound") | |
| decoded = r[30: -6] | |
| db64 = be(decoded) | |
| ru(s, "> ") | |
| if len(g) == 0: | |
| if db64.endswith("=="): g += guess | |
| elif len(g) == 2: | |
| if len(db64) >= 4 and not db64.endswith("="): g += guess | |
| elif len(g) == 4: | |
| if len(db64) == 8 and db64.endswith("=="): g += guess | |
| elif len(g) == 6: | |
| if len(db64) == 8 and not db64.endswith("="): g += guess | |
| if len(g) - len(_g) == 2: | |
| break | |
| # Send secret and get flag | |
| random = "".join(chr(((ord(a) - 64) % 256) ^ ord(b)) for a,b in zip(db64, g)) | |
| s.send("2") | |
| ru(s, "> ") | |
| s.send(random.encode("hex")) | |
| print s.recv(1024) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment