async def from_smbconnection(connection:SMBConnection, auth_level = None, open:bool = True, perform_dummy:bool = False): """ Creates the connection to the service using an established SMBConnection. This connection will use the given SMBConnection as transport layer. """ try: if auth_level is None: #for SMB connection no extra auth needed auth_level = RPC_C_AUTHN_LEVEL_PKT_PRIVACY epm = EPM.from_smbconnection(connection) _, err = await epm.connect() if err is not None: raise err constring, err = await epm.map(Even6RPC().service_uuid) if err is not None: raise err target = DCERPCTarget.from_connection_string(constring, smb_connection = connection) dcerpc_auth = DCERPCAuth.from_smb_gssapi(connection.gssapi) rpc_connection = DCERPC5Connection(dcerpc_auth, target) service, err = await Even6RPC.from_rpcconnection(rpc_connection, auth_level=auth_level, open=open, perform_dummy = perform_dummy) if err is not None: raise err return service, None except Exception as e: return None, e finally: if epm is not None: await epm.disconnect()
async def create_target(ip, remoteIf, proxy: SMBProxy = None, dc_ip: str = None, domain: str = None): epm = None try: epm = EPM.from_address(ip, proxy=proxy) _, err = await epm.connect() if err is not None: raise err res, err = await epm.map(remoteIf) if err is not None: raise err return DCERPCTarget.from_connection_string(res, proxy=proxy, dc_ip=dc_ip, domain=domain), None except Exception as e: return False, e finally: if epm is not None: await epm.disconnect()
def from_smbconnection(smb_connection, port: int = 135, protocol: str = 'ncacn_ip_tcp', data_representation=None): """ Sets up the EPM connection from an existing SMB connection """ dcerpc_target_str = r'%s:%s[%s]' % ( protocol, smb_connection.target.get_hostname_or_ip(), port) target = DCERPCTarget.from_connection_string( dcerpc_target_str, proxy=smb_connection.target.proxy) auth = DCERPCAuth.from_smb_gssapi(smb_connection.gssapi) connection = DCERPC5Connection(auth, target) connection.set_auth_type(RPC_C_AUTHN_LEVEL_NONE) return EPM(connection, data_representation)
def from_address(ip, port: int = 135, protocol: str = 'ncacn_ip_tcp', data_representation=None, proxy: SMBProxy = None): """ Sets up the EPM object from IP/hostname port protocol parameters """ dcerpc_target_str = r'%s:%s[%s]' % (protocol, ip, port) target = DCERPCTarget.from_connection_string(dcerpc_target_str, proxy=proxy) auth = None connection = DCERPC5Connection(auth, target) connection.set_auth_type(RPC_C_AUTHN_LEVEL_NONE) return EPM(connection, data_representation)
def get_connection_from_stringbinding(self, s): target = DCERPCTarget.from_connection_string( s, smb_connection=self.smb_connection) #target.proxy = self.smb_connection.target.proxy auth = DCERPCAuth.from_smb_gssapi(self.smb_connection.gssapi) return DCERPC5Connection(auth, target)