there are number of reasons to have tcp proxy in your tool beltboth for forwarding traffic to bounce from host to hostbut also when assessing network-based software when performing penetration tests in enterprise environmentsyou'll commonly be faced with the fact that you can' run wiresharkthat you can' load drivers to sniff the loopback on windowsor that network segmentation prevents you from running your tools directly against your target host have employed simple python proxy in number of cases to help understand unknown protocolsmodify traffic being sent to an applicationand create test cases for fuzzers let' get to it import sys import socket import threading def server_loop(local_host,local_port,remote_host,remote_port,receive_first)server socket socket(socket af_inetsocket sock_streamtryserver bind((local_host,local_port)exceptprint "[!!failed to listen on % :% (local_host,local_ portprint "[!!check for other listening sockets or correct permissions sys exit( print "[*listening on % :% (local_host,local_portserver listen( while trueclient_socketaddr server accept(print out the local connection information print "[==>received incoming connection from % :% (addr[ ],addr[ ]start thread to talk to the remote host proxy_thread threading thread(target=proxy_handlerargs=(client_socket,remote_host,remote_port,receive_first)proxy_thread start(def main()no fancy command-line parsing here if len(sys argv[ :]! print "usage/proxy py [localhost[localport[remotehost[remoteport[receive_first]print "example/proxy py truesys exit( setup local listening parameters local_host sys argv[ local_port int(sys argv[ ]setup remote target remote_host sys argv[ remote_port int(sys argv[ ]this tells our proxy to connect and receive data before sending to the remote host receive_first sys argv[