From 9af92cc75ccc39c6b5295f4005d3b45d6d0d3b5d Mon Sep 17 00:00:00 2001 From: Sunpy Date: Fri, 28 Sep 2018 22:13:01 +0200 Subject: [PATCH] Proxy log different port --- .gitignore | 2 ++ proxy.py | 40 ++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 6a18ad4..5059a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,5 @@ ENV/ # Rope project settings .ropeproject +# Logs +logs/ diff --git a/proxy.py b/proxy.py index a0afaed..e23d057 100644 --- a/proxy.py +++ b/proxy.py @@ -1,4 +1,5 @@ import sys +import os import socket from threading import Thread import select @@ -42,14 +43,14 @@ class Proxy(Thread): c_data = b"\x08\x1e\x77\xda" """ print("[C] -> {}".format(c_data)) - with open("logs/client-raw.log", "ab") as f: + with open("logs/{}-client-raw.log".format(LISTEN[1]), "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: + with open("logs/{}-client-hex.log".format(LISTEN[1]), "a") as f: f.write(c_data.hex() + "\r\n") + with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: + f.write(b"[C] -> " + c_data + b"\r\n") + with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: + f.write("[C] -> " + c_data.hex() + "\r\n") target.sendto(c_data, self.target) (s, _, _) = select.select([target],[],[],0) @@ -59,14 +60,14 @@ class Proxy(Thread): #print("[S] data:{}".format(s_data)) if s_data: print("[C] <- {}".format(s_data)) - with open("logs/server-raw.log", "ab") as f: + with open("logs/{}-server-raw.log".format(LISTEN[1]), "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: + with open("logs/{}-server-hex.log".format(LISTEN[1]), "a") as f: f.write(s_data.hex() + "\r\n") + with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: + f.write(b"[C] <- " + s_data + b"\r\n") + with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: + f.write("[C] <- " + s_data.hex() + "\r\n") client.sendto(s_data, c_addr) client.close() @@ -81,13 +82,16 @@ TARGET = (sys.argv[2], int(sys.argv[3])) ##while True: +if not os.path.exists("logs"): + os.makedirs("logs") + # 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() +open("logs/{}-client-raw.log".format(LISTEN[1]), "w").close() +open("logs/{}-client-hex.log".format(LISTEN[1]), "w").close() +open("logs/{}-server-raw.log".format(LISTEN[1]), "w").close() +open("logs/{}-server-hex.log".format(LISTEN[1]), "w").close() +open("logs/{}-all-raw.log".format(LISTEN[1]), "w").close() +open("logs/{}-all-hex.log".format(LISTEN[1]), "w").close() proxy = Proxy(LISTEN, TARGET) proxy.start()