From 347067ceb0dc247a4157af28a9a299381c2dcbef Mon Sep 17 00:00:00 2001 From: Sunpy Date: Fri, 28 Sep 2018 21:58:12 +0200 Subject: [PATCH] Added logging --- proxy.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/proxy.py b/proxy.py index fc41763..a0afaed 100644 --- a/proxy.py +++ b/proxy.py @@ -34,21 +34,39 @@ class Proxy(Thread): if c: c_data, c_addr = client.recvfrom(self.BUFF_SIZE) - print("[C] data:{} addr:{}".format(c_data, c_addr)) + #print("[C] data:{} addr:{}".format(c_data, c_addr)) if c_data: + """ if c_data[:2] == b"\x08\x1e": print("Editing port check: {}".format(c_data.hex())) c_data = b"\x08\x1e\x77\xda" - print("[C] -> {}".format(c_data.hex())) + """ + print("[C] -> {}".format(c_data)) + with open("logs/client-raw.log", "ab") as f: + f.write(c_data + b"\r\n") + with open("logs/client-hex.log", "a") as f: + f.write(c_data.hex() + "\r\n") + with open("logs/all-raw.log", "ab") as f: + f.write(c_data + b"\r\n") + with open("logs/all-hex.log", "a") as f: + f.write(c_data.hex() + "\r\n") target.sendto(c_data, self.target) (s, _, _) = select.select([target],[],[],0) if s: s_data = target.recv(self.BUFF_SIZE) - print("[S] data:{}".format(s_data)) + #print("[S] data:{}".format(s_data)) if s_data: - print("[C] <- {}".format(s_data.hex())) + print("[C] <- {}".format(s_data)) + with open("logs/server-raw.log", "ab") as f: + f.write(s_data + b"\r\n") + with open("logs/server-hex.log", "a") as f: + f.write(s_data.hex() + "\r\n") + with open("logs/all-raw.log", "ab") as f: + f.write(s_data + b"\r\n") + with open("logs/all-hex.log", "a") as f: + f.write(s_data.hex() + "\r\n") client.sendto(s_data, c_addr) client.close() @@ -62,6 +80,15 @@ LISTEN = ("0.0.0.0", int(sys.argv[1])) TARGET = (sys.argv[2], int(sys.argv[3])) ##while True: + +# Delete old log files +open("logs/client-raw.log", "w").close() +open("logs/client-hex.log", "w").close() +open("logs/server-raw.log", "w").close() +open("logs/server-hex.log", "w").close() +open("logs/all-raw.log", "w").close() +open("logs/all-hex.log", "w").close() + proxy = Proxy(LISTEN, TARGET) proxy.start() proxy.join()