def recv(self): finished = False forceRecv = 0 retAnswer = '' while not finished: # At least give me the MSRPCRespHeader, especially important for TCP/UDP Transports self.response_data = self.__clientSock.recv( dcerpc.MSRPCRespHeader._SIZE) self.response_header = dcerpc.MSRPCRespHeader(self.response_data) # Ok, there might be situation, especially with large packets, that the transport layer didn't send us the full packet's contents # So we gotta check we received it all while (len(self.response_data) < self.response_header['frag_len']): self.response_data += self.__clientSock.recv( self.response_header['frag_len'] - len(self.response_data)) self.response_header = dcerpc.MSRPCRespHeader(self.response_data) if self.response_header['flags'] & dcerpc.MSRPC_LASTFRAG: # No need to reassembly DCERPC finished = True else: # Forcing Read Recv, we need more packets! forceRecv = 1 answer = self.response_header['pduData'] auth_len = self.response_header['auth_len'] if auth_len: auth_len += 8 auth_data = answer[-auth_len:] ntlmssp = ntlm.DCERPC_NTLMAuthHeader(data=auth_data) answer = answer[:-auth_len] if ntlmssp['auth_pad_len']: answer = answer[:-ntlmssp['auth_pad_len']] retAnswer += answer return self.response_data
def processRequest(self, data): packet = dcerpc.MSRPCHeader(data) if packet['type'] == dcerpc.MSRPC_BIND: bind = dcerpc.MSRPCBind(packet['pduData']) packet = self.bind(packet, bind) elif packet['type'] == dcerpc.MSRPC_REQUEST: request = dcerpc.MSRPCRequestHeader(data) response = dcerpc.MSRPCRespHeader(data) response['type'] = dcerpc.MSRPC_RESPONSE # Serve the opnum requested, if not, fails if self.__callbacks[self.__boundUUID].has_key(request['op_num']): # Call the function returnData = self.__callbacks[self.__boundUUID][ request['op_num']](request['pduData']) response['pduData'] = returnData else: response['type'] = dcerpc.MSRPC_FAULT response['pduData'] = struct.pack('<L', 0x000006E4L) response['frag_len'] = len(response) return response else: # Defaults to a fault packet = dcerpc.MSRPCRespHeader(data) packet['type'] = dcerpc.MSRPC_FAULT return packet