<s> import sys <EOL> import unittest <EOL> import ConfigParser <EOL> from struct import pack , unpack <EOL> from impacket . dcerpc . v5 import transport <EOL> from impacket . dcerpc . v5 import epm , dcomrt <EOL> from impacket . dcerpc . v5 . dcom import wmi <EOL> from impacket . dcerpc . v5 . dtypes import NULL <EOL> from impacket . dcerpc . v5 . rpcrt import RPC_C_AUTHN_LEVEL_NONE <EOL> from impacket . dcerpc . v5 . dcomrt import DCOMConnection <EOL> from impacket . winregistry import hexdump <EOL> from impacket . uuid import string_to_bin , uuidtup_to_bin , generate <EOL> from impacket import system_errors , ntlm <EOL> class WMITests ( unittest . TestCase ) : <EOL> def tes_activation ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLoginClientID ) <EOL> dcom . disconnect ( ) <EOL> def test_IWbemLevel1Login_EstablishPosition ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> resp = iWbemLevel1Login . EstablishPosition ( ) <EOL> print resp <EOL> dcom . disconnect ( ) <EOL> def test_IWbemLevel1Login_RequestChallenge ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> try : <EOL> resp = iWbemLevel1Login . RequestChallenge ( ) <EOL> print resp <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> dcom . disconnect ( ) <EOL> raise <EOL> dcom . disconnect ( ) <EOL> def test_IWbemLevel1Login_WBEMLogin ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> try : <EOL> resp = iWbemLevel1Login . WBEMLogin ( ) <EOL> print resp <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> dcom . disconnect ( ) <EOL> raise <EOL> dcom . disconnect ( ) <EOL> def test_IWbemLevel1Login_NTLMLogin ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> resp = iWbemLevel1Login . NTLMLogin ( '<STR_LIT>' % self . machine , NULL , NULL ) <EOL> print resp <EOL> dcom . disconnect ( ) <EOL> def tes_IWbemServices_OpenNamespace ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> iWbemServices = iWbemLevel1Login . NTLMLogin ( '<STR_LIT>' , NULL , NULL ) <EOL> try : <EOL> resp = iWbemServices . OpenNamespace ( '<STR_LIT>' ) <EOL> print resp <EOL> except Exception , e : <EOL> dcom . disconnect ( ) <EOL> raise <EOL> dcom . disconnect ( ) <EOL> def test_IWbemServices_GetObject ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> iWbemServices = iWbemLevel1Login . NTLMLogin ( '<STR_LIT>' % self . machine , NULL , NULL ) <EOL> iWbemLevel1Login . RemRelease ( ) <EOL> classObject , _ = iWbemServices . GetObject ( '<STR_LIT>' ) <EOL> dcom . disconnect ( ) <EOL> def test_IWbemServices_ExecQuery ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> iWbemServices = iWbemLevel1Login . NTLMLogin ( '<STR_LIT>' % self . machine , NULL , NULL ) <EOL> classes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for classn in classes : <EOL> print "<STR_LIT>" % classn <EOL> try : <EOL> iEnumWbemClassObject = iWbemServices . ExecQuery ( '<STR_LIT>' % classn ) <EOL> done = False <EOL> while done is False : <EOL> try : <EOL> iEnumWbemClassObject . Next ( <NUM_LIT> , <NUM_LIT:1> ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> print e <EOL> else : <EOL> done = True <EOL> pass <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> print e <EOL> dcom . disconnect ( ) <EOL> def test_IWbemServices_ExecMethod ( self ) : <EOL> dcom = DCOMConnection ( self . machine , self . username , self . password , self . domain , self . lmhash , self . nthash ) <EOL> iInterface = dcom . CoCreateInstanceEx ( wmi . CLSID_WbemLevel1Login , wmi . IID_IWbemLevel1Login ) <EOL> iWbemLevel1Login = wmi . IWbemLevel1Login ( iInterface ) <EOL> iWbemServices = iWbemLevel1Login . NTLMLogin ( '<STR_LIT>' % self . machine , NULL , NULL ) <EOL> classObject , _ = iWbemServices . GetObject ( '<STR_LIT>' ) <EOL> obj = classObject . Create ( '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> handle = obj . getProperties ( ) [ '<STR_LIT>' ] [ '<STR_LIT:value>' ] <EOL> iEnumWbemClassObject = iWbemServices . ExecQuery ( '<STR_LIT>' % handle ) <EOL> oooo = iEnumWbemClassObject . Next ( <NUM_LIT> , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> owner = oooo . Terminate ( <NUM_LIT:1> ) <EOL> dcom . disconnect ( ) <EOL> class TCPTransport ( WMITests ) : <EOL> def setUp ( self ) : <EOL> WMITests . setUp ( self ) <EOL> configFile = ConfigParser . ConfigParser ( ) <EOL> configFile . read ( '<STR_LIT>' ) <EOL> self . username = configFile . get ( '<STR_LIT>' , '<STR_LIT:username>' ) <EOL> self . domain = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . serverName = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . password = configFile . get ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . machine = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hashes = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . stringBinding = r'<STR_LIT>' % self . machine <EOL> self . ts = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if len ( self . hashes ) > <NUM_LIT:0> : <EOL> self . lmhash , self . nthash = self . hashes . split ( '<STR_LIT::>' ) <EOL> else : <EOL> self . lmhash = '<STR_LIT>' <EOL> self . nthash = '<STR_LIT>' <EOL> class TCPTransport64 ( WMITests ) : <EOL> def setUp ( self ) : <EOL> WMITests . setUp ( self ) <EOL> configFile = ConfigParser . ConfigParser ( ) <EOL> configFile . read ( '<STR_LIT>' ) <EOL> self . username = configFile . get ( '<STR_LIT>' , '<STR_LIT:username>' ) <EOL> self . domain = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . serverName = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . password = configFile . get ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . machine = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hashes = configFile . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . stringBinding = r'<STR_LIT>' % self . machine <EOL> self . ts = ( '<STR_LIT>' , '<STR_LIT:1.0>' ) <EOL> if len ( self . hashes ) > <NUM_LIT:0> : <EOL> self . lmhash , self . nthash = self . hashes . split ( '<STR_LIT::>' ) <EOL> else : <EOL> self . lmhash = '<STR_LIT>' <EOL> self . nthash = '<STR_LIT>' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> testcase = sys . argv [ <NUM_LIT:1> ] <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( globals ( ) [ testcase ] ) <EOL> else : <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( TCPTransport ) <EOL> suite . addTests ( unittest . TestLoader ( ) . loadTestsFromTestCase ( TCPTransport64 ) ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:1> ) . run ( suite ) </s>
