async def DRSGetNCChanges(self, guid, req_attributes={}): try: if self.handle is None: await rr(self.open()) logger.debug('Calling DRSGetNCChanges for %s ' % guid) request = drsuapi.DRSGetNCChanges() request['hDrs'] = self.handle request['dwInVersion'] = 8 request['pmsgIn']['tag'] = 8 request['pmsgIn']['V8'][ 'uuidDsaObjDest'] = self.__NtdsDsaObjectGuid request['pmsgIn']['V8'][ 'uuidInvocIdSrc'] = self.__NtdsDsaObjectGuid dsName = drsuapi.DSNAME() dsName['SidLen'] = 0 dsName['Guid'] = string_to_bin(guid) #guid.to_bytes() dsName['Sid'] = '' dsName['NameLen'] = 0 dsName['StringName'] = ('\x00') dsName['structLen'] = len(dsName.getData()) request['pmsgIn']['V8']['pNC'] = dsName request['pmsgIn']['V8']['usnvecFrom']['usnHighObjUpdate'] = 0 request['pmsgIn']['V8']['usnvecFrom']['usnHighPropUpdate'] = 0 request['pmsgIn']['V8']['pUpToDateVecDest'] = NULL request['pmsgIn']['V8'][ 'ulFlags'] = drsuapi.DRS_INIT_SYNC | drsuapi.DRS_WRIT_REP request['pmsgIn']['V8']['cMaxObjects'] = 1 request['pmsgIn']['V8']['cMaxBytes'] = 0 request['pmsgIn']['V8']['ulExtendedOp'] = drsuapi.EXOP_REPL_OBJ if self.__ppartialAttrSet is None: self.__prefixTable = [] self.__ppartialAttrSet = drsuapi.PARTIAL_ATTR_VECTOR_V1_EXT() self.__ppartialAttrSet['dwVersion'] = 1 self.__ppartialAttrSet['cAttrs'] = len(req_attributes) for attId in list(req_attributes.values()): self.__ppartialAttrSet['rgPartialAttr'].append( drsuapi.MakeAttid(self.__prefixTable, attId)) request['pmsgIn']['V8']['pPartialAttrSet'] = self.__ppartialAttrSet request['pmsgIn']['V8']['PrefixTableDest']['PrefixCount'] = len( self.__prefixTable) request['pmsgIn']['V8']['PrefixTableDest'][ 'pPrefixEntry'] = self.__prefixTable request['pmsgIn']['V8']['pPartialAttrSetEx1'] = NULL data, err = await self.dce.request(request) return data, err except Exception as e: print('err!') return None, e
DRS_GET_ALL_GROUP_MEMBERSHIP = 0x80000000 # 5.113 LDAP_CONN_PROPERTIES BND = 0x00000001 SSL = 0x00000002 UDP = 0x00000004 GC = 0x00000008 GSS = 0x00000010 NGO = 0x00000020 SPL = 0x00000040 MD5 = 0x00000080 SGN = 0x00000100 SL = 0x00000200 # 5.137 NTSAPI_CLIENT_GUID NTDSAPI_CLIENT_GUID = string_to_bin('e24d201a-4fd6-11d1-a3da-0000f875ae0d') # 5.139 NULLGUID NULLGUID = string_to_bin('00000000-0000-0000-0000-000000000000') # 5.205 USN USN = LONGLONG # 4.1.4.1.2 DRS_MSG_CRACKREQ_V1 DS_NAME_FLAG_GCVERIFY = 0x00000004 DS_NAME_FLAG_TRUST_REFERRAL = 0x00000008 DS_NAME_FLAG_PRIVATE_RESOLVE_FPOS = 0x80000000 DS_LIST_SITES = 0xFFFFFFFF DS_LIST_SERVERS_IN_SITE = 0xFFFFFFFE DS_LIST_DOMAINS_IN_SITE = 0xFFFFFFFD
DCERPCException.__init__(self, error_string, error_code, packet) def __str__( self ): key = self.error_code if key in system_errors.ERROR_MESSAGES: error_msg_short = system_errors.ERROR_MESSAGES[key][0] error_msg_verbose = system_errors.ERROR_MESSAGES[key][1] return 'BKRP SessionError: code: 0x%x - %s - %s' % (self.error_code, error_msg_short, error_msg_verbose) else: return 'BKRP SessionError: unknown error code: 0x%x' % self.error_code ################################################################################ # CONSTANTS ################################################################################ BACKUPKEY_BACKUP_GUID = string_to_bin("7F752B10-178E-11D1-AB8F-00805F14DB40") BACKUPKEY_RESTORE_GUID_WIN2K = string_to_bin("7FE94D50-178E-11D1-AB8F-00805F14DB40") BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID = string_to_bin("018FF48A-EABA-40C6-8F6D-72370240E967") BACKUPKEY_RESTORE_GUID = string_to_bin("47270C64-2FC7-499B-AC5B-0E37CDCE899A") ################################################################################ # STRUCTURES ################################################################################ class BYTE_ARRAY(NDRUniConformantArray): item = 'c' class PBYTE_ARRAY(NDRPOINTER): referent = ( ('Data', BYTE_ARRAY), )
# Some calls have helper functions, which makes it even easier to use. # They are located at the end of this file. # Helper functions start with "h"<name of the call>. # There are test cases for them too. # from aiosmb.dcerpc.v5 import system_errors from aiosmb.dcerpc.v5.dtypes import ULONGLONG, UINT, USHORT, LPWSTR, DWORD, ULONG, NULL from aiosmb.dcerpc.v5.ndr import NDRCALL, NDRSTRUCT, NDRUNION, NDRPOINTER, NDRUniConformantArray from aiosmb.dcerpc.v5.rpcrt import DCERPCException from aiosmb.dcerpc.v5.uuid import uuidtup_to_bin, string_to_bin from aiosmb.dcerpc.v5.rprn import DRIVER_INFO_2_ARRAY MSRPC_UUID_PAR = uuidtup_to_bin( ('76F03F96-CDFD-44FC-A22C-64950A001209', '1.0')) MSRPC_UUID_WINSPOOL = string_to_bin('9940CA8E-512F-4C58-88A9-61098D6896BD') class DCERPCSessionError(DCERPCException): def __init__(self, error_string=None, error_code=None, packet=None): DCERPCException.__init__(self, error_string, error_code, packet) def __str__(self): key = self.error_code if key in system_errors.ERROR_MESSAGES: error_msg_short = system_errors.ERROR_MESSAGES[key][0] error_msg_verbose = system_errors.ERROR_MESSAGES[key][1] return 'RPRN SessionError: code: 0x%x - %s - %s' % ( self.error_code, error_msg_short, error_msg_verbose) else: return 'RPRN SessionError: unknown error code: 0x%x' % self.error_code