def tcp_message(flow): ''' This callback is hit every time mitmproxy receives a packet. It's the main entrypoint into this script. ''' global connection_count tcp_msg = flow.messages[-1] # Keep track of all the different connections, assign a unique id to each if not hasattr(flow, 'connection_id'): flow.connection_id = connection_count connection_count += 1 # this is not thread safe but I think that's fine tcp_msg.connection_id = flow.connection_id # The first packet the frontend sends shounld be parsed differently tcp_msg.is_initial = len(flow.messages) == 1 if tcp_msg.is_initial: # skip parsing initial messages for now, they're not important tcp_msg.parsed = None else: tcp_msg.parsed = structs.parse(tcp_msg.content, from_frontend=tcp_msg.from_client) # record the message, for debugging purposes captured_messages.put(tcp_msg) # okay, finally, give the packet to the command the user wants us to use handler._accept(flow, tcp_msg)
def check_response(port): def chat(): if port.debug: print "Success" try: response = parse(port.last_rx) except MappingError: print "Fault:" print "%s" % pretty(port.last_rx) raise if response.event_opcode == 'cmd_complete': if response.event_params.cmd_response.status == 'success': chat() return if response.event_opcode == 'vendor_specific': if response.event_params.vendor_event_opcode == 'cmd_status': if response.event_params.vendor_event_params.status == 'success': chat() return
def do_test_end(port): container = cmd_container('test_end') build_write_check(port,container) return parse(port.last_rx).event_params.cmd_response.pkt_count