From 4cea08c3145d9b219788bc2f7adedbc481ad7ccb Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 30 Jun 2021 17:25:14 +0200 Subject: [PATCH] Add null-byte after size bytes --- clientBlaster.py | 5 ++++- serverBlaster.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clientBlaster.py b/clientBlaster.py index bb6528b..ccd0d50 100644 --- a/clientBlaster.py +++ b/clientBlaster.py @@ -62,12 +62,15 @@ def removeThread(): tprint(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "Thread closed. Threads: " +str(threadCount)+ " (Actual: " +str(threading.active_count())+ ")" + colorama.Style.RESET_ALL) def sendResponse(connection,data): - connection.sendall(len(data).to_bytes(4,"big") + data) + connection.sendall(len(data).to_bytes(4,"big") + b"\x00" + data) def getResponse(connection): data = b'' data = connection.recv(4) if not data: return False + nul = connection.recv(1) + if not nul: return False + if nul != b"\x00": return False requestLength = int.from_bytes(data,"big") if requestLength > maxRequestSize: raise Exception("security","request_too_large") return connection.recv(requestLength) diff --git a/serverBlaster.py b/serverBlaster.py index a893310..b2c31ed 100644 --- a/serverBlaster.py +++ b/serverBlaster.py @@ -32,7 +32,7 @@ class receiverThread(threading.Thread): print("server: " +response) def sendRequest(connection,data): - connection.sendall(len(data).to_bytes(4,"big") + data) + connection.sendall(len(data).to_bytes(4,"big") + b"\x00" + data) def getResponse(connection): data = b'' @@ -42,6 +42,15 @@ def getResponse(connection): connection.close() return + nul = connection.recv(1) + if not nul: + connection.close() + return + + if nul != b"\x00": + connection.close() + return + requestLength = int.from_bytes(data,"big") data = connection.recv(requestLength) return data