def test_IWbemLevel1Login_EstablishPosition(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) resp = iWbemLevel1Login.EstablishPosition() print resp dcom.disconnect()
def test_IWbemLevel1Login_NTLMLogin(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) resp = iWbemLevel1Login.NTLMLogin('\\\\%s\\root\\cimv2' % self.machine, NULL, NULL) print resp dcom.disconnect()
def test_IWbemServices_GetObject(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) iWbemServices= iWbemLevel1Login.NTLMLogin('\\\\%s\\root\\cimv2' % self.machine, NULL, NULL) iWbemLevel1Login.RemRelease() classObject,_ = iWbemServices.GetObject('Win32_Process') dcom.disconnect()
def test_IWbemLevel1Login_WBEMLogin(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) try: resp = iWbemLevel1Login.WBEMLogin() print resp except Exception, e: if str(e).find('E_NOTIMPL') < 0: dcom.disconnect() raise
def tes_IWbemServices_OpenNamespace(self): # Not working dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) iWbemServices= iWbemLevel1Login.NTLMLogin('//./ROOT', NULL, NULL) try: resp = iWbemServices.OpenNamespace('__Namespace') print resp except Exception, e: dcom.disconnect() raise
def test_IWbemServices_ExecMethod(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) iWbemServices= iWbemLevel1Login.NTLMLogin('\\\\%s\\root\\cimv2' % self.machine, NULL, NULL) #classObject,_ = iWbemServices.GetObject('WinMgmts:Win32_LogicalDisk='C:'') classObject,_ = iWbemServices.GetObject('Win32_Process') obj = classObject.Create('notepad.exe', 'c:\\', None) handle = obj.getProperties()['ProcessId']['value'] iEnumWbemClassObject = iWbemServices.ExecQuery('SELECT * from Win32_Process where handle = %s' % handle) oooo = iEnumWbemClassObject.Next(0xffffffff,1)[0] #import time #time.sleep(5) owner = oooo.Terminate(1) #iEnumWbemClassObject = iWbemServices.ExecQuery('SELECT * from Win32_Group where name = "testGroup0"') #oooo = iEnumWbemClassObject.Next(0xffffffff,1)[0] #import time #owner = oooo.Rename('testGroup1') #iEnumWbemClassObject = iWbemServices.ExecQuery('SELECT * from Win32_Share where name = "Users"') #oooo = iEnumWbemClassObject.Next(0xffffffff,1)[0] #import time #owner = oooo.GetAccessMask() #print owner.getProperties() #iEnumWbemClassObject = iWbemServices.ExecQuery('SELECT * from Win32_Share where name = "Users"') #oooo = iEnumWbemClassObject.Next(0xffffffff,1)[0] #obj = oooo.SetShareInfo(0, 'HOLA BETO', None) #classObject,_ = iWbemServices.GetObject('Win32_ShadowCopy') #obj = classObject.Create('C:\\', 'ClientAccessible') #print obj.getProperties() # this one doesn't work #classObject,_ = iWbemServices.GetObject('Win32_Service') #obj = classObject.Create('BETOSERVICE', 'Beto Service', 'c:\\beto', 16, 0, 'Manual', 0, None, None, None, None, None) #print obj.getProperties() dcom.disconnect()
def test_IWbemServices_ExecQuery(self): dcom = DCOMConnection(self.machine, self.username, self.password, self.domain, self.lmhash, self.nthash) iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login) iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) iWbemServices= iWbemLevel1Login.NTLMLogin('\\\\%s\\root\\cimv2' % self.machine, NULL, NULL) classes = [ 'Win32_Account', 'Win32_UserAccount', 'Win32_Group', 'Win32_SystemAccount', 'Win32_Service'] for classn in classes: print "Reading %s " % classn try: iEnumWbemClassObject = iWbemServices.ExecQuery('SELECT * from %s' % classn) done = False while done is False: try: iEnumWbemClassObject.Next(0xffffffff,1) except Exception, e: if str(e).find('S_FALSE') < 0: print e else: done = True pass except Exception, e: if str(e).find('S_FALSE') < 0: print e