From cfdc5d5556b72c76925a7db83b90417cabd9e1d5 Mon Sep 17 00:00:00 2001 From: xorrior Date: Fri, 27 Oct 2017 03:47:06 -0400 Subject: [PATCH] Patch b64decode padding error --- data/agent/agent.py | 3 +++ lib/common/agents.py | 8 ++++---- lib/common/packets.py | 9 +-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/data/agent/agent.py b/data/agent/agent.py index c35cf4f..e84692f 100644 --- a/data/agent/agent.py +++ b/data/agent/agent.py @@ -134,6 +134,9 @@ def build_response_packet(taskingID, packetData, resultID=0): if packetData: packetData = base64.b64encode(packetData.decode('utf-8').encode('utf-8',errors='ignore')) + if len(packetData) % 4: + packetData += '=' * (4 - len(packetData) % 4) + length = struct.pack('=L',len(packetData)) return packetType + totalPacket + packetNum + resultID + length + packetData else: diff --git a/lib/common/agents.py b/lib/common/agents.py index f318015..d4f7557 100644 --- a/lib/common/agents.py +++ b/lib/common/agents.py @@ -1481,10 +1481,10 @@ class Agents: conn = self.get_db_connection() cur = conn.cursor() data = cur.execute("SELECT data FROM taskings WHERE agent=? AND id=?", [sessionID,taskID]).fetchone()[0] - cur.close() - theSender="Agents" - if data.startswith("function Get-Keystrokes"): - theSender += "PsKeyLogger" + cur.close() + theSender="Agents" + if data.startswith("function Get-Keystrokes"): + theSender += "PsKeyLogger" if results: # signal that this agent returned results dispatcher.send("[*] Agent %s returned results." % (sessionID), sender=theSender) diff --git a/lib/common/packets.py b/lib/common/packets.py index b73ad36..89373e7 100644 --- a/lib/common/packets.py +++ b/lib/common/packets.py @@ -199,14 +199,7 @@ def parse_result_packet(packet, offset=0): taskID = struct.unpack('=H', packet[6+offset:8+offset])[0] length = struct.unpack('=L', packet[8+offset:12+offset])[0] if length != '0': - if length % 4: - #padding fix - datapart = packet[12+offset:12+offset+length] - datapart += '=' * (4 - length % 4) - data = base64.b64decode(datapart) - else: - data = base64.b64decode(packet[12+offset:12+offset+length]) - #data = base64.b64decode(packet[12+offset:12+offset+length]) + data = base64.b64decode(packet[12+offset:12+offset+length]) else: data = None remainingData = packet[12+offset+length:]