hexdump(remote_buffersend to our response handler remote_buffer response_handler(remote_buffersend the response to the local socket client_socket send(remote_bufferprint "[<==sent to localhost if no more data on either sideclose the connections if not len(local_bufferor not len(remote_buffer)client_socket close(remote_socket close(print "[*no more data closing connections break this function contains the bulk of the logic for our proxy to start offwe check to make sure we don' need to first initiate connection to the remote side and request data before going into our main loop some server daemons will expect you to do this first (ftp servers typically send banner firstfor examplewe then use our receive_from function which we reuse for both sides of the communicationit simply takes in connected socket object and performs receive we then dump the contents of the packet so that we can inspect it for anything interesting next we hand the output to our response_handler function inside this functionyou can modify the packet contentsperform fuzzing taskstest for authentication issuesor whatever else your heart desires there is complimentary request_handler function that does the same for modifying outbound traffic as well the final step is to send the received buffer to our local client the rest of the proxy code is straightforwardwe continually read from localprocesssend to remoteread from remoteprocessand send to local until there is no more data detected let' put together the rest of our functions to complete our proxy this is pretty hex dumping function directly taken from the comments heredef hexdump(srclength= )result [digits if isinstance(srcunicodeelse for in xrange( len(src)length) src[ : +lengthhexa bjoin(["% * (digitsord( )for in ]text 'join([ if <ord( else bfor in ]result appendb"% %-* % (ilength*(digits )hexatextprint '\njoin(resultdef receive_from(connection)buffer "we set second timeoutdepending on your targetthis may need to be adjusted connection settimeout( trykeep reading into the buffer until there' no more data or we time out while true