-
Notifications
You must be signed in to change notification settings - Fork 59
/
delegation.py
157 lines (116 loc) · 4.51 KB
/
delegation.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
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
from havoc import Demon, RegisterCommand, RegisterModule
import re
def get_delegation( demonID, *params ):
TaskID : str = None
demon : Demon = None
packer = Packer()
demon = Demon( demonID )
del_query = {
'constrained': '(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=16777216))',
'unconstrained': '(&(objectClass=computer)(primarygroupid=515)(userAccountControl:1.2.840.113556.1.4.803:=524288))',
'rbcd': '(&(msDS-AllowedToActOnBehalfOfOtherIdentity=*)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))'
}
del_attrs = {
'constrained': 'sAMAccountName,msDS-AllowedToDelegateTo',
'unconstrained': 'sAMAccountName',
'rbcd': 'sAMAccountName'
}
num_params = len(params)
query = ''
attributes = ''
result_limit = 0
hostname = ''
domain = ''
if num_params < 1:
demon.ConsoleWrite( demon.CONSOLE_ERROR, "Not enough parameters" )
return False
if num_params > 1:
demon.ConsoleWrite( demon.CONSOLE_ERROR, "Too many parameters" )
return False
if params[ 0 ].lower() not in del_query:
demon.ConsoleWrite( demon.CONSOLE_ERROR, "Wrong first parameter" )
return False
query = del_query[ params[ 0 ].lower() ]
attrs = del_attrs[ params[ 0 ].lower() ]
if num_params >= 2:
attributes = params[ 1 ]
# not used
if num_params >= 3:
result_limit = params[ 2 ]
if num_params >= 4:
hostname = params[ 3 ]
if num_params >= 5:
domain = params[ 4 ]
packer.addstr(query)
packer.addstr(attrs)
packer.adduint32(result_limit)
packer.addstr(hostname)
packer.addstr(domain)
TaskID = demon.ConsoleWrite( demon.CONSOLE_TASK, "Tasked demon to run ldap query" )
demon.InlineExecute( TaskID, "go", f"bin/ldapsearch.{demon.ProcessArch}.o", packer.getbuffer(), False )
return TaskID
def get_spns( demonID, *params ):
TaskID : str = None
demon : Demon = None
packer = Packer()
demon = Demon( demonID )
num_params = len(params)
query = '(&(samAccountType=805306368)(!samAccountName=krbtgt)(serviceprincipalname=*)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))'
attributes = 'sAMAccountName,servicePrincipalName'
result_limit = 0
hostname = ''
domain = ''
if num_params > 0:
demon.ConsoleWrite( demon.CONSOLE_ERROR, "Too many parameters" )
return False
# not used
if num_params >= 2:
attributes = params[ 1 ]
if num_params >= 3:
result_limit = params[ 2 ]
if num_params >= 4:
hostname = params[ 3 ]
if num_params >= 5:
domain = params[ 4 ]
packer.addstr(query)
packer.addstr(attributes)
packer.adduint32(result_limit)
packer.addstr(hostname)
packer.addstr(domain)
TaskID = demon.ConsoleWrite( demon.CONSOLE_TASK, "Tasked demon to run ldap query" )
demon.InlineExecute( TaskID, "go", f"bin/ldapsearch.{demon.ProcessArch}.o", packer.getbuffer(), False )
return TaskID
def get_asrep( demonID, *params ):
TaskID : str = None
demon : Demon = None
packer = Packer()
demon = Demon( demonID )
num_params = len(params)
query = '(&(userAccountControl:1.2.840.113556.1.4.803:=4194304)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))'
attributes = 'sAMAccountName'
result_limit = 0
hostname = ''
domain = ''
if num_params > 1:
demon.ConsoleWrite( demon.CONSOLE_ERROR, "Too many parameters" )
return False
# not used
if num_params >= 2:
attributes = params[ 1 ]
if num_params >= 3:
result_limit = params[ 2 ]
if num_params >= 4:
hostname = params[ 3 ]
if num_params >= 5:
domain = params[ 4 ]
packer.addstr(query)
packer.addstr(attributes)
packer.adduint32(result_limit)
packer.addstr(hostname)
packer.addstr(domain)
TaskID = demon.ConsoleWrite( demon.CONSOLE_TASK, "Tasked demon to run ldap query" )
demon.InlineExecute( TaskID, "go", f"bin/ldapsearch.{demon.ProcessArch}.o", packer.getbuffer(), False )
return TaskID
RegisterCommand( get_delegation, "", "get-delegation", "Enumerate a given domain for different types of abusable Kerberos Delegation settings.", 0, "[Constrained,Unconstrained,RBCD]", "constrained" )
RegisterCommand( get_spns, "", "get-spns", "Enumerate a given domain for user accounts with SPNs.", 0, "", "" )
RegisterCommand( get_asrep, "", "get-asrep", "Enumerate a given domain for user accounts with ASREP.", 0, "", "" )