Python impacket.dcerpc.v5.rpcrt.DCERPCException() Examples
The following are 30
code examples of impacket.dcerpc.v5.rpcrt.DCERPCException().
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.rpcrt
, or try the search function
.
Example #1
Source File: reg.py From Slackor with GNU General Public License v3.0 | 6 votes |
def __print_all_subkeys_and_entries(self, rpc, keyName, keyHandler, index): index = 0 while True: try: subkey = rrp.hBaseRegEnumKey(rpc, keyHandler, index) index += 1 ans = rrp.hBaseRegOpenKey(rpc, keyHandler, subkey['lpNameOut'], samDesired=rrp.MAXIMUM_ALLOWED | rrp.KEY_ENUMERATE_SUB_KEYS) newKeyName = keyName + subkey['lpNameOut'][:-1] + '\\' print(newKeyName) self.__print_key_values(rpc, ans['phkResult']) self.__print_all_subkeys_and_entries(rpc, newKeyName, ans['phkResult'], 0) except rrp.DCERPCSessionError as e: if e.get_error_code() == ERROR_NO_MORE_ITEMS: break except rpcrt.DCERPCException as e: if str(e).find('access_denied') >= 0: logging.error('Cannot access subkey %s, bypassing it' % subkey['lpNameOut'][:-1]) continue elif str(e).find('rpc_x_bad_stub_data') >= 0: logging.error('Fault call, cannot retrieve value for %s, bypassing it' % subkey['lpNameOut'][:-1]) return raise
Example #2
Source File: smbrelayclient.py From Slackor with GNU General Public License v3.0 | 6 votes |
def isAdmin(self): rpctransport = SMBTransport(self.session.getRemoteHost(), 445, r'\svcctl', smb_connection=self.session) dce = rpctransport.get_dce_rpc() try: dce.connect() except: pass else: dce.bind(scmr.MSRPC_UUID_SCMR) try: # 0xF003F - SC_MANAGER_ALL_ACCESS # http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx ans = scmr.hROpenSCManagerW(dce,'{}\x00'.format(self.target.hostname),'ServicesActive\x00', 0xF003F) return "TRUE" except scmr.DCERPCException as e: pass return "FALSE"
Example #3
Source File: smbrelayclient.py From GhostPotato with MIT License | 6 votes |
def isAdmin(self): rpctransport = SMBTransport(self.session.getRemoteHost(), 445, r'\svcctl', smb_connection=self.session) dce = rpctransport.get_dce_rpc() try: dce.connect() except: pass else: dce.bind(scmr.MSRPC_UUID_SCMR) try: # 0xF003F - SC_MANAGER_ALL_ACCESS # http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx ans = scmr.hROpenSCManagerW(dce,'{}\x00'.format(self.target.hostname),'ServicesActive\x00', 0xF003F) return "TRUE" except scmr.DCERPCException as e: pass return "FALSE"
Example #4
Source File: reg.py From PiBunny with MIT License | 6 votes |
def __print_all_subkeys_and_entries(self, rpc, keyName, keyHandler, index): index = 0 while True: try: subkey = rrp.hBaseRegEnumKey(rpc, keyHandler, index) index += 1 ans = rrp.hBaseRegOpenKey(rpc, keyHandler, subkey['lpNameOut'], samDesired=rrp.MAXIMUM_ALLOWED | rrp.KEY_ENUMERATE_SUB_KEYS) newKeyName = keyName + subkey['lpNameOut'][:-1] + '\\' print newKeyName self.__print_key_values(rpc, ans['phkResult']) self.__print_all_subkeys_and_entries(rpc, newKeyName, ans['phkResult'], 0) except rrp.DCERPCSessionError, e: if e.get_error_code() == ERROR_NO_MORE_ITEMS: break except rpcrt.DCERPCException, e: if str(e).find('access_denied') >= 0: logging.error('Cannot access subkey %s, bypassing it' % subkey['lpNameOut'][:-1]) continue elif str(e).find('rpc_x_bad_stub_data') >= 0: logging.error('Fault call, cannot retrieve value for %s, bypassing it' % subkey['lpNameOut'][:-1]) return raise
Example #5
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 #6
Source File: smb.py From ActiveReign with GNU General Public License v3.0 | 6 votes |
def get_os_arch(self): # Credit: https://github.com/byt3bl33d3r/CrackMapExec/blob/master/cme/protocols/smb.py # Credit: https://github.com/SecureAuthCorp/impacket/blob/impacket_0_9_19/examples/getArch.py try: stringBinding = r'ncacn_ip_tcp:{}[135]'.format(self.host) 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: dce.disconnect() return 32 else: dce.disconnect() return 64 except: return 0
Example #7
Source File: rpc.py From ActiveReign with GNU General Public License v3.0 | 6 votes |
def get_netloggedon(self): self.loggedon = {} self.create_rpc_con(r'\wkssvc') try: resp = wkst.hNetrWkstaUserEnum(self.rpc_connection, 1) except DCERPCException as e: return list() results = list() for wksta_user in resp['UserInfo']['WkstaUserInfo']['Level1']['Buffer']: self.loggedon[wksta_user['wkui1_username'].strip('\x00')] = { 'domain' : wksta_user['wkui1_logon_domain'].strip('\x00'), 'logon_srv' : wksta_user['wkui1_logon_server'].strip('\x00'), 'user' : wksta_user['wkui1_username'].strip('\x00'), } self.rpc_connection.disconnect()
Example #8
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 #9
Source File: dump.py From CVE-2019-1040 with MIT License | 6 votes |
def getDomainUsers(self, enumerationContext=0): if self.__samr is None: self.connectSamr(self.getMachineNameAndDomain()[1]) try: resp = samr.hSamrEnumerateUsersInDomain(self.__samr, self.__domainHandle, userAccountControl=samr.USER_NORMAL_ACCOUNT | \ samr.USER_WORKSTATION_TRUST_ACCOUNT | \ samr.USER_SERVER_TRUST_ACCOUNT |\ samr.USER_INTERDOMAIN_TRUST_ACCOUNT, enumerationContext=enumerationContext) except DCERPCException as e: if str(e).find('STATUS_MORE_ENTRIES') < 0: raise resp = e.get_packet() return resp
Example #10
Source File: rpc.py From ActiveReign with GNU General Public License v3.0 | 5 votes |
def get_netsessions(self): self.sessions = {} self.create_rpc_con(r'\srvsvc') try: resp = srvs.hNetrSessionEnum(self.rpc_connection, '\x00', NULL, 10) except DCERPCException: return list() for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']: self.sessions[session['sesi10_username'].strip('\x00')] = {'user' : session['sesi10_username'].strip('\x00'), 'host' : session['sesi10_cname'].strip('\x00'), 'time' : session['sesi10_time'], 'idle' : session['sesi10_idle_time'] } self.rpc_connection.disconnect()
Example #11
Source File: getArch.py From Slackor with GNU General Public License v3.0 | 5 votes |
def run(self): if self.__options.targets is not None: for line in self.__options.targets.readlines(): self.__machinesList.append(line.strip(' \r\n')) else: self.__machinesList.append(self.__options.target) logging.info('Gathering OS architecture for %d machines' % len(self.__machinesList)) logging.info('Socket connect timeout set to %s secs' % self.__options.timeout) for machine in self.__machinesList: try: stringBinding = r'ncacn_ip_tcp:%s[135]' % machine transport = DCERPCTransportFactory(stringBinding) transport.set_connect_timeout(int(self.__options.timeout)) dce = transport.get_dce_rpc() dce.connect() try: dce.bind(MSRPC_UUID_PORTMAP, transfer_syntax=self.NDR64Syntax) except DCERPCException as e: if str(e).find('syntaxes_not_supported') >= 0: print('%s is 32-bit' % machine) else: logging.error(str(e)) pass else: print('%s is 64-bit' % machine) dce.disconnect() except Exception as e: #import traceback #traceback.print_exc() logging.error('%s: %s' % (machine, str(e))) # Process command-line arguments.
Example #12
Source File: transport.py From Slackor with GNU General Public License v3.0 | 5 votes |
def DCERPCTransportFactory(stringbinding): sb = DCERPCStringBinding(stringbinding) na = sb.get_network_address() ps = sb.get_protocol_sequence() if 'ncadg_ip_udp' == ps: port = sb.get_endpoint() if port: return UDPTransport(na, int(port)) else: return UDPTransport(na) elif 'ncacn_ip_tcp' == ps: port = sb.get_endpoint() if port: return TCPTransport(na, int(port)) else: return TCPTransport(na) elif 'ncacn_http' == ps: port = sb.get_endpoint() if port: return HTTPTransport(na, int(port)) else: return HTTPTransport(na) elif 'ncacn_np' == ps: named_pipe = sb.get_endpoint() if named_pipe: named_pipe = named_pipe[len(r'\pipe'):] return SMBTransport(na, filename = named_pipe) else: return SMBTransport(na) elif 'ncalocal' == ps: named_pipe = sb.get_endpoint() return LOCALTransport(filename = named_pipe) else: raise DCERPCException("Unknown protocol sequence.")
Example #13
Source File: transport.py From Slackor with GNU General Public License v3.0 | 5 votes |
def connect(self): try: af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_DGRAM)[0] self.__socket = socket.socket(af, socktype, proto) self.__socket.settimeout(self.get_connect_timeout()) except socket.error as msg: self.__socket = None raise DCERPCException("Could not connect: %s" % msg) return 1
Example #14
Source File: transport.py From Slackor with GNU General Public License v3.0 | 5 votes |
def connect(self): af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_STREAM)[0] self.__socket = socket.socket(af, socktype, proto) try: self.__socket.settimeout(self.get_connect_timeout()) self.__socket.connect(sa) except socket.error as msg: self.__socket.close() raise DCERPCException("Could not connect: %s" % msg) return 1
Example #15
Source File: transport.py From Slackor with GNU General Public License v3.0 | 5 votes |
def connect(self): TCPTransport.connect(self) self.get_socket().send('RPC_CONNECT ' + self.getRemoteHost() + ':593 HTTP/1.0\r\n\r\n') data = self.get_socket().recv(8192) if data[10:13] != '200': raise DCERPCException("Service not supported.")
Example #16
Source File: transport.py From PiBunny with MIT License | 5 votes |
def connect(self): TCPTransport.connect(self) self.get_socket().send('RPC_CONNECT ' + self.getRemoteHost() + ':593 HTTP/1.0\r\n\r\n') data = self.get_socket().recv(8192) if data[10:13] != '200': raise DCERPCException("Service not supported.")
Example #17
Source File: smb.py From ActiveReign with GNU General Public License v3.0 | 5 votes |
def isAdmin(self): try: rpctransport = SMBTransport(self.host, self.port, r'\svcctl', smb_connection=self.con) dce = rpctransport.get_dce_rpc() try: dce.connect() except: pass else: dce.bind(scmr.MSRPC_UUID_SCMR) try: # 0xF003F - SC_MANAGER_ALL_ACCESS # http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx ans = scmr.hROpenSCManagerW(dce, '{}\x00'.format(self.host), 'ServicesActive\x00', 0xF003F) self.admin = True return True except scmr.DCERPCException as e: pass except Exception as e: print(e) return False ################################ # Dump SAM / LSA # Methods were modified from: # https://github.com/byt3bl33d3r/CrackMapExec/blob/master/cme/protocols/smb.py # https://github.com/SecureAuthCorp/impacket/blob/master/examples/secretsdump.py ################################
Example #18
Source File: computer.py From BloodHound.py with MIT License | 5 votes |
def rpc_get_loggedon(self): """ Query logged on users via RPC. Requires admin privs """ binding = r'ncacn_np:%s[\PIPE\wkssvc]' % self.addr loggedonusers = set() dce = self.dce_rpc_connect(binding, wkst.MSRPC_UUID_WKST) if dce is None: logging.warning('Connection failed: %s', binding) return try: # 1 means more detail, including the domain resp = wkst.hNetrWkstaUserEnum(dce, 1) for record in resp['UserInfo']['WkstaUserInfo']['Level1']['Buffer']: # Skip computer accounts if record['wkui1_username'][-2] == '$': continue # Skip sessions for local accounts if record['wkui1_logon_domain'][:-1].upper() == self.samname.upper(): continue domain = record['wkui1_logon_domain'][:-1].upper() domain_entry = self.ad.get_domain_by_name(domain) if domain_entry is not None: domain = ADUtils.ldap2domain(domain_entry['attributes']['distinguishedName']) logging.debug('Found logged on user at %s: %s@%s' % (self.hostname, record['wkui1_username'][:-1], domain)) loggedonusers.add((record['wkui1_username'][:-1], domain)) except DCERPCException as e: if 'rpc_s_access_denied' in str(e): logging.debug('Access denied while enumerating LoggedOn on %s, probably no admin privs', self.hostname) else: logging.debug('Exception connecting to RPC: %s', e) except Exception as e: if 'connection reset' in str(e): logging.debug('Connection was reset: %s', e) else: raise e dce.disconnect() return list(loggedonusers)
Example #19
Source File: secretsdump.py From PiBunny with MIT License | 5 votes |
def getDomainUsers(self, enumerationContext=0): if self.__samr is None: self.connectSamr(self.getMachineNameAndDomain()[1]) try: resp = samr.hSamrEnumerateUsersInDomain(self.__samr, self.__domainHandle, userAccountControl=samr.USER_NORMAL_ACCOUNT | \ samr.USER_WORKSTATION_TRUST_ACCOUNT | \ samr.USER_SERVER_TRUST_ACCOUNT |\ samr.USER_INTERDOMAIN_TRUST_ACCOUNT, enumerationContext=enumerationContext) except DCERPCException, e: if str(e).find('STATUS_MORE_ENTRIES') < 0: raise resp = e.get_packet()
Example #20
Source File: transport.py From PiBunny with MIT License | 5 votes |
def connect(self): try: af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_DGRAM)[0] self.__socket = socket.socket(af, socktype, proto) self.__socket.settimeout(self.get_connect_timeout()) except socket.error, msg: self.__socket = None raise DCERPCException("Could not connect: %s" % msg)
Example #21
Source File: transport.py From PiBunny with MIT License | 5 votes |
def connect(self): af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_STREAM)[0] self.__socket = socket.socket(af, socktype, proto) try: self.__socket.settimeout(self.get_connect_timeout()) self.__socket.connect(sa) except socket.error, msg: self.__socket.close() raise DCERPCException("Could not connect: %s" % msg)
Example #22
Source File: secretsdump.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def getDomainUsers(self, enumerationContext=0): if self.__samr is None: self.connectSamr(self.getMachineNameAndDomain()[1]) try: resp = samr.hSamrEnumerateUsersInDomain(self.__samr, self.__domainHandle, userAccountControl=samr.USER_NORMAL_ACCOUNT | \ samr.USER_WORKSTATION_TRUST_ACCOUNT | \ samr.USER_SERVER_TRUST_ACCOUNT |\ samr.USER_INTERDOMAIN_TRUST_ACCOUNT, enumerationContext=enumerationContext) except DCERPCException, e: if str(e).find('STATUS_MORE_ENTRIES') < 0: raise resp = e.get_packet()
Example #23
Source File: requester.py From pywerview with GNU General Public License v3.0 | 5 votes |
def _create_wmi_connection(self, namespace='root\\cimv2'): try: self._dcom = DCOMConnection(self._target_computer, self._user, self._password, self._domain, self._lmhash, self._nthash) except DCERPCException: self._dcom = None else: i_interface = self._dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login, wmi.IID_IWbemLevel1Login) i_wbem_level1_login = wmi.IWbemLevel1Login(i_interface) self._wmi_connection = i_wbem_level1_login.NTLMLogin(ntpath.join('\\\\{}\\'.format(self._target_computer), namespace), NULL, NULL)
Example #24
Source File: transport.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def DCERPCTransportFactory(stringbinding): sb = DCERPCStringBinding(stringbinding) na = sb.get_network_address() ps = sb.get_protocol_sequence() if 'ncadg_ip_udp' == ps: port = sb.get_endpoint() if port: return UDPTransport(na, int(port)) else: return UDPTransport(na) elif 'ncacn_ip_tcp' == ps: port = sb.get_endpoint() if port: return TCPTransport(na, int(port)) else: return TCPTransport(na) elif 'ncacn_http' == ps: port = sb.get_endpoint() if port: return HTTPTransport(na, int(port)) else: return HTTPTransport(na) elif 'ncacn_np' == ps: named_pipe = sb.get_endpoint() if named_pipe: named_pipe = named_pipe[len(r'\pipe'):] return SMBTransport(na, filename = named_pipe) else: return SMBTransport(na) elif 'ncalocal' == ps: named_pipe = sb.get_endpoint() return LOCALTransport(filename = named_pipe) else: raise DCERPCException("Unknown protocol sequence.")
Example #25
Source File: transport.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def connect(self): try: af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_DGRAM)[0] self.__socket = socket.socket(af, socktype, proto) self.__socket.settimeout(self.get_connect_timeout()) except socket.error, msg: self.__socket = None raise DCERPCException("Could not connect: %s" % msg)
Example #26
Source File: transport.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def connect(self): af, socktype, proto, canonname, sa = socket.getaddrinfo(self.getRemoteHost(), self.get_dport(), 0, socket.SOCK_STREAM)[0] self.__socket = socket.socket(af, socktype, proto) try: self.__socket.settimeout(self.get_connect_timeout()) self.__socket.connect(sa) except socket.error, msg: self.__socket.close() raise DCERPCException("Could not connect: %s" % msg)
Example #27
Source File: transport.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def connect(self): TCPTransport.connect(self) self.get_socket().send('RPC_CONNECT ' + self.getRemoteHost() + ':593 HTTP/1.0\r\n\r\n') data = self.get_socket().recv(8192) if data[10:13] != '200': raise DCERPCException("Service not supported.")
Example #28
Source File: net.py From pywerview with GNU General Public License v3.0 | 5 votes |
def get_netsession(self): try: resp = srvs.hNetrSessionEnum(self._rpc_connection, '\x00', NULL, 10) except DCERPCException: return list() results = list() for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']: results.append(rpcobj.Session(session)) return results
Example #29
Source File: net.py From pywerview with GNU General Public License v3.0 | 5 votes |
def get_netloggedon(self): try: resp = wkst.hNetrWkstaUserEnum(self._rpc_connection, 1) except DCERPCException: return list() results = list() for wksta_user in resp['UserInfo']['WkstaUserInfo']['Level1']['Buffer']: results.append(rpcobj.WkstaUser(wksta_user)) return results # TODO: if self._target_computer == self._domain_controller, check that # self._domain_controller is indeed a domain controller
Example #30
Source File: misc.py From pywerview with GNU General Public License v3.0 | 5 votes |
def invoke_checklocaladminaccess(self): try: # 0xF003F - SC_MANAGER_ALL_ACCESS # http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx ans = scmr.hROpenSCManagerW(self._rpc_connection, '{}\x00'.format(self._target_computer), 'ServicesActive\x00', 0xF003F) except DCERPCException: return False return True