From bff44a5ed2e98cc5d2c9b35152289c02d22cc6ae Mon Sep 17 00:00:00 2001 From: byt3bl33d3r Date: Sat, 14 Nov 2015 21:51:59 -0700 Subject: [PATCH] Fixed WMI query output formatting --- core/scripts/secretsdump.py | 6 +----- core/scripts/wmiquery.py | 21 +++++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/core/scripts/secretsdump.py b/core/scripts/secretsdump.py index 7085c7559..827466aa9 100755 --- a/core/scripts/secretsdump.py +++ b/core/scripts/secretsdump.py @@ -2058,11 +2058,7 @@ def dump_NTDS(self, method, history, pwdLastSet): def cleanup(self): logging.info('Cleaning up... ') if self.__remoteOps: - try: - self.__remoteOps.finish() - except DCERPCException: - sleep(2) - self.__remoteOps.finish() + self.__remoteOps.finish() if self.__SAMHashes: self.__SAMHashes.finish() if self.__LSASecrets: diff --git a/core/scripts/wmiquery.py b/core/scripts/wmiquery.py index 7d90b9155..cbb9ba489 100755 --- a/core/scripts/wmiquery.py +++ b/core/scripts/wmiquery.py @@ -27,6 +27,7 @@ from impacket.dcerpc.v5.dtypes import NULL from impacket.dcerpc.v5.dcom import wmi from impacket.dcerpc.v5.dcomrt import DCOMConnection +import core.settings as settings class WMIQUERY: @@ -52,15 +53,16 @@ def run(self, command, address, namespace): iWbemServices= iWbemLevel1Login.NTLMLogin(namespace, NULL, NULL) iWbemLevel1Login.RemRelease() - shell = WMIShell(iWbemServices) + shell = WMIShell(iWbemServices, address) shell.onecmd(command) iWbemServices.RemRelease() dcom.disconnect() class WMIShell(cmd.Cmd): - def __init__(self, iWbemServices): + def __init__(self, iWbemServices, address): cmd.Cmd.__init__(self) + self.address = address self.iWbemServices = iWbemServices def do_help(self, line): @@ -99,16 +101,10 @@ def printReply(self, iEnum): try: pEnum = iEnum.Next(0xffffffff,1)[0] record = pEnum.getProperties() - if printHeader is True: - print '|', - for col in record: - print '%s |' % col, - print - printHeader = False - print '|', - for key in record: - print '%s |' % record[key]['value'], - print + line = [] + for rec in record: + line.append('{}: {}'.format(rec, record[rec]['value'])) + print_att(' | '.join(line)) except Exception, e: #import traceback #print traceback.print_exc() @@ -124,6 +120,7 @@ def default(self, line): line = line[:-1] try: iEnumWbemClassObject = self.iWbemServices.ExecQuery(line.strip('\n')) + print_succ('{}:{} Executed specified WMI query:'.format(self.address, settings.args.port)) self.printReply(iEnumWbemClassObject) iEnumWbemClassObject.RemRelease() except Exception, e: