2727from impacket .dcerpc .v5 .dtypes import NULL
2828from impacket .dcerpc .v5 .dcom import wmi
2929from impacket .dcerpc .v5 .dcomrt import DCOMConnection
30+ import core .settings as settings
3031
3132class WMIQUERY :
3233
@@ -52,15 +53,16 @@ def run(self, command, address, namespace):
5253 iWbemServices = iWbemLevel1Login .NTLMLogin (namespace , NULL , NULL )
5354 iWbemLevel1Login .RemRelease ()
5455
55- shell = WMIShell (iWbemServices )
56+ shell = WMIShell (iWbemServices , address )
5657 shell .onecmd (command )
5758
5859 iWbemServices .RemRelease ()
5960 dcom .disconnect ()
6061
6162class WMIShell (cmd .Cmd ):
62- def __init__ (self , iWbemServices ):
63+ def __init__ (self , iWbemServices , address ):
6364 cmd .Cmd .__init__ (self )
65+ self .address = address
6466 self .iWbemServices = iWbemServices
6567
6668 def do_help (self , line ):
@@ -99,16 +101,10 @@ def printReply(self, iEnum):
99101 try :
100102 pEnum = iEnum .Next (0xffffffff ,1 )[0 ]
101103 record = pEnum .getProperties ()
102- if printHeader is True :
103- print '|' ,
104- for col in record :
105- print '%s |' % col ,
106- print
107- printHeader = False
108- print '|' ,
109- for key in record :
110- print '%s |' % record [key ]['value' ],
111- print
104+ line = []
105+ for rec in record :
106+ line .append ('{}: {}' .format (rec , record [rec ]['value' ]))
107+ print_att (' | ' .join (line ))
112108 except Exception , e :
113109 #import traceback
114110 #print traceback.print_exc()
@@ -124,6 +120,7 @@ def default(self, line):
124120 line = line [:- 1 ]
125121 try :
126122 iEnumWbemClassObject = self .iWbemServices .ExecQuery (line .strip ('\n ' ))
123+ print_succ ('{}:{} Executed specified WMI query:' .format (self .address , settings .args .port ))
127124 self .printReply (iEnumWbemClassObject )
128125 iEnumWbemClassObject .RemRelease ()
129126 except Exception , e :
0 commit comments