if len(buffer)client send(bufferwhile truenow wait for data back recv_len response "while recv_lendata client recv( recv_len len(dataresponse+data if recv_len break print responsewait for more input buffer raw_input(""buffer +"\nsend it off client send(bufferexceptprint "[*exceptionexiting tear down the connection client close(most of this code should look familiar to you by now we start by setting up our tcp socket object and then test to see if we have received any input from stdin if all is wellwe ship the data off to the remote target and receive back data until there is no more data to receive we then wait for further input from the user and continue sending and receiving data until the user kills the script the extra line break is attached specifically to our user input so that our client will be compatible with our command shell now we'll move on and create our primary server loop and stub function that will handle both our command execution and our full command shell def server_loop()global target if no target is definedwe listen on all interfaces if not len(target)target server socket socket(socket af_inetsocket sock_streamserver bind((target,port)server listen( while trueclient_socketaddr server accept(spin off thread to handle our new client client_thread threading thread(target=client_handlerargs=(client_socket,)client_thread start(def run_command(command)trim the newline command command rstrip(