From 82b1a7702855b9188774bd72baa91c7c5fa1309e Mon Sep 17 00:00:00 2001 From: NtAlexio2 Date: Fri, 13 Sep 2024 19:26:11 -0400 Subject: [PATCH 1/2] drop python2 support in wmiexec.py --- examples/wmiexec.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/examples/wmiexec.py b/examples/wmiexec.py index 52411b55da..2b9fcaaf6f 100755 --- a/examples/wmiexec.py +++ b/examples/wmiexec.py @@ -43,7 +43,6 @@ from impacket.dcerpc.v5.dcom import wmi from impacket.dcerpc.v5.dtypes import NULL from impacket.krb5.keytab import Keytab -from six import PY2 OUTPUT_FILENAME = '__' + str(time.time()) CODEC = sys.stdout.encoding @@ -226,10 +225,7 @@ def do_cd(self, s): print(self.__outputBuffer) self.__outputBuffer = '' else: - if PY2: - self.__pwd = ntpath.normpath(ntpath.join(self.__pwd, s.decode(sys.stdin.encoding))) - else: - self.__pwd = ntpath.normpath(ntpath.join(self.__pwd, s)) + self.__pwd = ntpath.normpath(ntpath.join(self.__pwd, s)) self.execute_remote('cd ') self.__pwd = self.__outputBuffer.strip('\r\n') self.prompt = (self.__pwd + '>') @@ -296,10 +292,7 @@ def execute_remote(self, data, shell_type='cmd'): if self.__noOutput is False: command += ' 1> ' + '\\\\127.0.0.1\\%s' % self.__share + self.__output + ' 2>&1' - if PY2: - self.__win32Process.Create(command.decode(sys.stdin.encoding), self.__pwd, None) - else: - self.__win32Process.Create(command, self.__pwd, None) + self.__win32Process.Create(command, self.__pwd, None) self.get_output() def send_data(self, data): From 616751230caa4cfcbaa1f87165006d591ba7121a Mon Sep 17 00:00:00 2001 From: NtAlexio2 Date: Fri, 13 Sep 2024 19:26:41 -0400 Subject: [PATCH 2/2] display ProcessId to user --- examples/wmiexec.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/wmiexec.py b/examples/wmiexec.py index 2b9fcaaf6f..0fb30137cf 100755 --- a/examples/wmiexec.py +++ b/examples/wmiexec.py @@ -292,8 +292,11 @@ def execute_remote(self, data, shell_type='cmd'): if self.__noOutput is False: command += ' 1> ' + '\\\\127.0.0.1\\%s' % self.__share + self.__output + ' 2>&1' - self.__win32Process.Create(command, self.__pwd, None) - self.get_output() + response = self.__win32Process.Create(command, self.__pwd, None) + if self.__noOutput is False: + self.get_output() + else: + response.printInformation() # print ProcessId and ReturnValue def send_data(self, data): self.execute_remote(data, self.__shell_type)