<s> import unittest <EOL> import ConfigParser <EOL> from struct import unpack <EOL> from impacket . dcerpc . v5 import transport <EOL> from impacket . dcerpc . v5 import scmr , epm <EOL> from impacket . dcerpc . v5 . ndr import NULL <EOL> from impacket . crypto import encryptSecret <EOL> from impacket . uuid import string_to_bin <EOL> from impacket import ntlm <EOL> class SCMRTests ( unittest . TestCase ) : <EOL> def changeServiceAndQuery ( self , dce , cbBufSize , hService , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) : <EOL> try : <EOL> resp = scmr . hRChangeServiceConfigW ( dce , hService , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> resp = scmr . hRQueryServiceConfigW ( dce , hService ) <EOL> resp . dump ( ) <EOL> if dwServiceType != scmr . SERVICE_NO_CHANGE : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == dwServiceType ) <EOL> if dwStartType != scmr . SERVICE_NO_CHANGE : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == dwStartType ) <EOL> if dwErrorControl != scmr . SERVICE_NO_CHANGE : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == dwErrorControl ) <EOL> if lpBinaryPathName != NULL : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == lpBinaryPathName ) <EOL> if lpBinaryPathName != NULL : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == lpBinaryPathName ) <EOL> if lpLoadOrderGroup != NULL : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == lpLoadOrderGroup ) <EOL> if lpServiceStartName != NULL : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == lpServiceStartName ) <EOL> if lpDisplayName != NULL : <EOL> self . assertTrue ( resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] == lpDisplayName ) <EOL> except : <EOL> resp = scmr . hRDeleteService ( dce , hService ) <EOL> raise <EOL> def changeServiceAndQuery2 ( self , dce , info , changeDone ) : <EOL> serviceHandle = info [ '<STR_LIT>' ] <EOL> dwInfoLevel = info [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> cbBuffSize = <NUM_LIT:0> <EOL> request = scmr . RQueryServiceConfig2W ( ) <EOL> request [ '<STR_LIT>' ] = serviceHandle <EOL> request [ '<STR_LIT>' ] = dwInfoLevel <EOL> request [ '<STR_LIT>' ] = cbBuffSize <EOL> try : <EOL> resp = dce . request ( request ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> else : <EOL> resp = e . get_packet ( ) <EOL> request [ '<STR_LIT>' ] = resp [ '<STR_LIT>' ] <EOL> resp = dce . request ( request ) <EOL> arrayData = '<STR_LIT>' . join ( resp [ '<STR_LIT>' ] ) <EOL> if dwInfoLevel == <NUM_LIT:1> : <EOL> self . assertTrue ( arrayData [ <NUM_LIT:4> : ] . decode ( '<STR_LIT>' ) == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:2> : <EOL> offset = unpack ( '<STR_LIT>' , arrayData [ <NUM_LIT:4> : ] [ : <NUM_LIT:4> ] ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( arrayData [ offset : ] [ : len ( changeDone ) * <NUM_LIT:2> ] . decode ( '<STR_LIT>' ) == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:3> : <EOL> self . assertTrue ( unpack ( '<STR_LIT>' , arrayData ) [ <NUM_LIT:0> ] == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:4> : <EOL> self . assertTrue ( unpack ( '<STR_LIT>' , arrayData ) [ <NUM_LIT:0> ] == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:5> : <EOL> self . assertTrue ( unpack ( '<STR_LIT>' , arrayData ) [ <NUM_LIT:0> ] == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:6> : <EOL> changeDone = '<STR_LIT>' . join ( changeDone ) . decode ( '<STR_LIT>' ) <EOL> self . assertTrue ( arrayData [ <NUM_LIT:4> : ] . decode ( '<STR_LIT>' ) == changeDone ) <EOL> elif dwInfoLevel == <NUM_LIT:7> : <EOL> self . assertTrue ( unpack ( '<STR_LIT>' , arrayData ) [ <NUM_LIT:0> ] == changeDone ) <EOL> def connect ( self ) : <EOL> rpctransport = transport . DCERPCTransportFactory ( self . stringBinding ) <EOL> if len ( self . hashes ) > <NUM_LIT:0> : <EOL> lmhash , nthash = self . hashes . split ( '<STR_LIT::>' ) <EOL> else : <EOL> lmhash = '<STR_LIT>' <EOL> nthash = '<STR_LIT>' <EOL> if hasattr ( rpctransport , '<STR_LIT>' ) : <EOL> rpctransport . set_credentials ( self . username , self . password , self . domain , lmhash , nthash ) <EOL> dce = rpctransport . get_dce_rpc ( ) <EOL> dce . connect ( ) <EOL> if self . __class__ . __name__ == '<STR_LIT>' : <EOL> dce . set_auth_level ( ntlm . NTLM_AUTH_PKT_PRIVACY ) <EOL> dce . bind ( scmr . MSRPC_UUID_SCMR ) <EOL> lpMachineName = '<STR_LIT>' <EOL> lpDatabaseName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS | scmr . SC_MANAGER_ENUMERATE_SERVICE <EOL> resp = scmr . hROpenSCManagerW ( dce , lpMachineName , lpDatabaseName , desiredAccess ) <EOL> scHandle = resp [ '<STR_LIT>' ] <EOL> return dce , rpctransport , scHandle <EOL> def test_RChangeServiceConfig2W ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> lpDisplayName = '<STR_LIT>' <EOL> dwDesiredAccess = scmr . SERVICE_ALL_ACCESS <EOL> dwServiceType = scmr . SERVICE_WIN32_OWN_PROCESS <EOL> dwStartType = scmr . SERVICE_DEMAND_START <EOL> dwErrorControl = scmr . SERVICE_ERROR_NORMAL <EOL> lpBinaryPathName = '<STR_LIT>' <EOL> lpLoadOrderGroup = NULL <EOL> lpdwTagId = NULL <EOL> lpDependencies = NULL <EOL> dwDependSize = <NUM_LIT:0> <EOL> lpServiceStartName = NULL <EOL> lpPassword = NULL <EOL> dwPwSize = <NUM_LIT:0> <EOL> resp = scmr . hRCreateServiceW ( dce , scHandle , lpServiceName , lpDisplayName , dwDesiredAccess , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize ) <EOL> resp . dump ( ) <EOL> newHandle = resp [ '<STR_LIT>' ] <EOL> error = False <EOL> try : <EOL> request = scmr . RChangeServiceConfig2W ( ) <EOL> request [ '<STR_LIT>' ] = newHandle <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:2> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:2> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> resp = dce . request ( request ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> resp = dce . request ( request ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> resp = dce . request ( request ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:6> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:6> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = list ( u'<STR_LIT>' . encode ( '<STR_LIT>' ) ) <EOL> resp = dce . request ( request ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:7> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:7> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> resp = dce . request ( request ) <EOL> self . changeServiceAndQuery2 ( dce , request , request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:8> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:8> <EOL> trigger = scmr . SERVICE_TRIGGER ( ) <EOL> trigger [ '<STR_LIT>' ] = scmr . SERVICE_TRIGGER_TYPE_DOMAIN_JOIN <EOL> trigger [ '<STR_LIT>' ] = scmr . SERVICE_TRIGGER_ACTION_SERVICE_START <EOL> trigger [ '<STR_LIT>' ] = string_to_bin ( scmr . DOMAIN_JOIN_GUID ) <EOL> item = scmr . SERVICE_TRIGGER_SPECIFIC_DATA_ITEM ( ) <EOL> item [ '<STR_LIT>' ] = scmr . SERVICE_TRIGGER_DATA_TYPE_STRING <EOL> item [ '<STR_LIT>' ] = list ( u'<STR_LIT>' . encode ( '<STR_LIT>' ) ) <EOL> trigger [ '<STR_LIT>' ] = NULL <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( trigger ) <EOL> resp = dce . request ( request ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:9> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:9> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:10> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:10> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:11> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:11> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> print e <EOL> error = True <EOL> pass <EOL> resp = scmr . hRDeleteService ( dce , newHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , newHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> if error : <EOL> self . assertTrue ( <NUM_LIT:1> == <NUM_LIT:0> ) <EOL> def test_REnumServicesStatusExW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> request = scmr . REnumServicesStatusExW ( ) <EOL> request [ '<STR_LIT>' ] = scHandle <EOL> request [ '<STR_LIT>' ] = scmr . SC_STATUS_PROCESS_INFO <EOL> request [ '<STR_LIT>' ] = scmr . SERVICE_WIN32_OWN_PROCESS <EOL> request [ '<STR_LIT>' ] = scmr . SERVICE_STATE_ALL <EOL> request [ '<STR_LIT>' ] = NULL <EOL> request [ '<STR_LIT>' ] = NULL <EOL> request [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> try : <EOL> resp = dce . request ( request ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> else : <EOL> resp = e . get_packet ( ) <EOL> resp . dump ( ) <EOL> request [ '<STR_LIT>' ] = resp [ '<STR_LIT>' ] <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> def test_RQueryServiceStatusEx ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> request = scmr . RQueryServiceStatusEx ( ) <EOL> request [ '<STR_LIT>' ] = serviceHandle <EOL> request [ '<STR_LIT>' ] = scmr . SC_STATUS_PROCESS_INFO <EOL> request [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> resp = dce . request ( request ) <EOL> array = '<STR_LIT>' . join ( resp [ '<STR_LIT>' ] ) <EOL> status = scmr . SERVICE_STATUS_PROCESS ( array ) <EOL> def te_REnumServiceGroupW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> dwServiceType = scmr . SERVICE_WIN32_OWN_PROCESS <EOL> dwServiceState = scmr . SERVICE_STATE_ALL <EOL> cbBufSize = <NUM_LIT:10> <EOL> lpResumeIndex = <NUM_LIT:0> <EOL> pszGroupName = '<STR_LIT>' <EOL> try : <EOL> resp = scmr . hREnumServiceGroupW ( dce , scHandle , dwServiceType , dwServiceState , cbBufSize , lpResumeIndex , pszGroupName ) <EOL> resp . dump ( ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_RQueryServiceConfigEx ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> request = scmr . RQueryServiceConfigEx ( ) <EOL> request [ '<STR_LIT>' ] = serviceHandle <EOL> request [ '<STR_LIT>' ] = <NUM_LIT> <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> def te_RControlServiceExW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> request = scmr . RControlServiceExW ( ) <EOL> request [ '<STR_LIT>' ] = serviceHandle <EOL> request [ '<STR_LIT>' ] = scmr . SERVICE_CONTROL_STOP <EOL> request [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> request [ '<STR_LIT>' ] = NULL <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> def te_RNotifyServiceStatusChange ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> request = scmr . RNotifyServiceStatusChange ( ) <EOL> request [ '<STR_LIT>' ] = serviceHandle <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = scmr . SERVICE_NOTIFY_RUNNING <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:0>' * <NUM_LIT:16> <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> request = scmr . RCloseNotifyHandle ( ) <EOL> request [ '<STR_LIT>' ] = resp [ '<STR_LIT>' ] <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> request = scmr . RGetNotifyResults ( ) <EOL> request [ '<STR_LIT>' ] = resp [ '<STR_LIT>' ] <EOL> resp = dce . request ( request ) <EOL> resp . dump ( ) <EOL> def test_RGetServiceDisplayNameW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> lpcchBuffer = len ( lpServiceName ) + <NUM_LIT:100> <EOL> resp = scmr . hRGetServiceDisplayNameW ( dce , scHandle , lpServiceName , lpcchBuffer ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_RGetServiceKeyNameW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpDisplayName = '<STR_LIT>' <EOL> lpcchBuffer = len ( lpDisplayName ) + <NUM_LIT:100> <EOL> resp = scmr . hRGetServiceKeyNameW ( dce , scHandle , lpDisplayName , lpcchBuffer ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_RStartServiceW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> try : <EOL> resp = scmr . hRStartServiceW ( dce , serviceHandle , <NUM_LIT:3> , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_RQueryServiceLockStatusW ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> pcbBytesNeeded = <NUM_LIT:1000> <EOL> resp = scmr . hRQueryServiceLockStatusW ( dce , scHandle , pcbBytesNeeded ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_enumservices ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> dwServiceType = scmr . SERVICE_KERNEL_DRIVER | scmr . SERVICE_FILE_SYSTEM_DRIVER | scmr . SERVICE_WIN32_OWN_PROCESS | scmr . SERVICE_WIN32_SHARE_PROCESS <EOL> dwServiceState = scmr . SERVICE_STATE_ALL <EOL> cbBufSize = <NUM_LIT:0> <EOL> resp = scmr . hREnumServicesStatusW ( dce , scHandle , dwServiceType , dwServiceState ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_create_change_delete ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> lpDisplayName = '<STR_LIT>' <EOL> dwDesiredAccess = scmr . SERVICE_ALL_ACCESS <EOL> dwServiceType = scmr . SERVICE_WIN32_OWN_PROCESS <EOL> dwStartType = scmr . SERVICE_DEMAND_START <EOL> dwErrorControl = scmr . SERVICE_ERROR_NORMAL <EOL> lpBinaryPathName = '<STR_LIT>' <EOL> lpLoadOrderGroup = NULL <EOL> lpdwTagId = NULL <EOL> lpDependencies = NULL <EOL> dwDependSize = <NUM_LIT:0> <EOL> lpServiceStartName = NULL <EOL> lpPassword = NULL <EOL> dwPwSize = <NUM_LIT:0> <EOL> resp = scmr . hRCreateServiceW ( dce , scHandle , lpServiceName , lpDisplayName , dwDesiredAccess , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize ) <EOL> resp . dump ( ) <EOL> newHandle = resp [ '<STR_LIT>' ] <EOL> cbBufSize = <NUM_LIT:0> <EOL> try : <EOL> resp = scmr . hRQueryServiceConfigW ( dce , newHandle ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> else : <EOL> resp = e . get_packet ( ) <EOL> resp . dump ( ) <EOL> cbBufSize = resp [ '<STR_LIT>' ] + <NUM_LIT:100> <EOL> dwServiceType = scmr . SERVICE_WIN32_SHARE_PROCESS <EOL> dwStartType = scmr . SERVICE_NO_CHANGE <EOL> dwErrorControl = scmr . SERVICE_NO_CHANGE <EOL> lpBinaryPathName = NULL <EOL> lpLoadOrderGroup = NULL <EOL> lpDependencies = NULL <EOL> dwDependSize = <NUM_LIT:0> <EOL> lpServiceStartName = NULL <EOL> lpPassword = NULL <EOL> dwPwSize = <NUM_LIT:0> <EOL> lpDisplayName = NULL <EOL> lpdwTagId = NULL <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> dwServiceType = scmr . SERVICE_NO_CHANGE <EOL> dwStartType = scmr . SERVICE_DISABLED <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> dwStartType = scmr . SERVICE_NO_CHANGE <EOL> dwErrorControl = scmr . SERVICE_ERROR_SEVERE <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> dwErrorControl = scmr . SERVICE_NO_CHANGE <EOL> lpBinaryPathName = '<STR_LIT>' <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpBinaryPathName = NULL <EOL> lpLoadOrderGroup = '<STR_LIT>' <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpLoadOrderGroup = NULL <EOL> lpDependencies = '<STR_LIT>' . encode ( '<STR_LIT>' ) <EOL> dwDependSize = len ( lpDependencies ) <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpDependencies = NULL <EOL> dwDependSize = <NUM_LIT:0> <EOL> lpServiceStartName = '<STR_LIT>' <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpServiceStartName = NULL <EOL> if self . __class__ . __name__ == '<STR_LIT>' : <EOL> lpPassword = '<STR_LIT>' . encode ( '<STR_LIT>' ) <EOL> s = rpctransport . get_smb_connection ( ) <EOL> key = s . getSessionKey ( ) <EOL> lpPassword = encryptSecret ( key , lpPassword ) <EOL> dwPwSize = len ( lpPassword ) <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpPassword = NULL <EOL> dwPwSize = <NUM_LIT:0> <EOL> lpDisplayName = '<STR_LIT>' <EOL> self . changeServiceAndQuery ( dce , cbBufSize , newHandle , dwServiceType , dwStartType , dwErrorControl , lpBinaryPathName , lpLoadOrderGroup , lpdwTagId , lpDependencies , dwDependSize , lpServiceStartName , lpPassword , dwPwSize , lpDisplayName ) <EOL> lpDisplayName = NULL <EOL> resp = scmr . hRDeleteService ( dce , newHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , newHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_query ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> resp = scmr . hRQueryServiceStatus ( dce , serviceHandle ) <EOL> cbBufSize = <NUM_LIT:0> <EOL> try : <EOL> resp = scmr . hREnumDependentServicesW ( dce , serviceHandle , scmr . SERVICE_STATE_ALL , cbBufSize ) <EOL> resp . dump ( ) <EOL> except scmr . DCERPCSessionError , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> else : <EOL> resp = e . get_packet ( ) <EOL> resp . dump ( ) <EOL> cbBufSize = resp [ '<STR_LIT>' ] <EOL> resp = scmr . hREnumDependentServicesW ( dce , serviceHandle , scmr . SERVICE_STATE_ALL , cbBufSize ) <EOL> resp . dump ( ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , serviceHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_lock_unlock ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> resp = scmr . hRLockServiceDatabase ( dce , scHandle ) <EOL> lockHandle = resp [ '<STR_LIT>' ] <EOL> resp = scmr . hRUnlockServiceDatabase ( dce , lockHandle ) <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_query_set_object_security ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> try : <EOL> resp = scmr . hRQueryServiceObjectSecurity ( dce , scHandle , scmr . DACL_SECURITY_INFORMATION , <NUM_LIT:0> ) <EOL> resp . dump ( ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_notify_config ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpMachineName = '<STR_LIT>' <EOL> try : <EOL> resp = scmr . hRNotifyBootConfigStatus ( dce , lpMachineName , <NUM_LIT> ) <EOL> resp . dump ( ) <EOL> except scmr . DCERPCSessionError , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) <= <NUM_LIT:0> : <EOL> raise <EOL> resp = scmr . hRCloseServiceHandle ( dce , scHandle ) <EOL> def test_RControlServiceCall ( self ) : <EOL> dce , rpctransport , scHandle = self . connect ( ) <EOL> lpServiceName = '<STR_LIT>' <EOL> desiredAccess = scmr . SERVICE_START | scmr . SERVICE_STOP | scmr . SERVICE_CHANGE_CONFIG | scmr . SERVICE_QUERY_CONFIG | scmr . SERVICE_QUERY_STATUS | scmr . SERVICE_ENUMERATE_DEPENDENTS <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> try : <EOL> req = scmr . RControlService ( ) <EOL> req [ '<STR_LIT>' ] = serviceHandle <EOL> req [ '<STR_LIT>' ] = scmr . SERVICE_CONTROL_STOP <EOL> resp = dce . request ( req ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> raise <EOL> pass <EOL> resp = scmr . hRCloseServiceHandle ( dce , serviceHandle ) <EOL> import time <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> resp = scmr . hROpenServiceW ( dce , scHandle , lpServiceName , desiredAccess ) <EOL> resp . dump ( ) <EOL> serviceHandle = resp [ '<STR_LIT>' ] <EOL> try : <EOL> resp = scmr . hRStartServiceW ( dce , serviceHandle , <NUM_LIT:0> , NULL ) <EOL> resp . dump ( ) <EOL> except Exception , e : <EOL> if str ( e ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> raise <EOL> return <EOL> class SMBTransport ( SCMRTests ) : <EOL> def setUp ( self ) : <EOL> SCMRTests . 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> class TCPTransport ( SCMRTests ) : <EOL> def setUp ( self ) : <EOL> SCMRTests . 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 = epm . hept_map ( self . machine , scmr . MSRPC_UUID_SCMR , protocol = '<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 ( SMBTransport ) <EOL> suite . addTests ( unittest . TestLoader ( ) . loadTestsFromTestCase ( TCPTransport ) ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:1> ) . run ( suite ) </s>
