-
Notifications
You must be signed in to change notification settings - Fork 92
/
Test-KerberosDoubleHop.ps1
287 lines (182 loc) · 11.3 KB
/
Test-KerberosDoubleHop.ps1
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
Function Test-KerberosDoubleHop {
<#
.SYNOPSIS
This cmdlet is for finding AD Objects that are vulnerable to Kerberos Double Hop Vulnerability
.DESCRIPTION
This only works if run on a Domain Controller. If you find any users that are susceptible you can protect the user account by going to their properties in AD, Account Tab - Check the box User Account is Sensitive and Cannot be Delegated; Admin Credentials will be found in an lsass dump file. Lsass dump file can be analyzed without us knowing when the vulnerability is on an admin account and a computer. #
.PARAMETER All
This switch parameter indicates you want to recieve Kerberos Double Hop info on all Computers, Users, and Admins in Active Directory
.PARAMETER UserResults
This switch parameter indicates you want to recieve Kerberos Double Hop info on all Users in Active Directory
.PARAMETER AdminResults
This switch parameter indicates you want to recieve Kerberos Double Hop info on all Admins in Active Directory
.PARAMETER ComputerResults
This switch parameter indicates you want to recieve Kerberos Double Hop info on all Computers in Active Directory
.PARAMETER Server
This parameter is used to define the Domain Controller to run this check from. This allows you to execute this on a remote domain controller
.PARAMETER UseSSL
This parameter indicates you want to use WinRM over HTTPS to execute this cmdlet on the remote Domain Controller
.EXAMPLE
Test-KerberosDoubleHop -All
# This example checks for and displays Computers, Users, and Admin AD Objects vulnerable to a Kerberos Double Hop on the domain controller you are logged into
.EXAMPLE
Test-KerberosDoubleHop -Server DC01.domain.com -UserResults
# This example uses WinRM to display User AD Objects vulnerable to a Kerberos Double Hop on the remote domain controller DC01.domain.com
.EXAMPLE
Test-KerberosDoubleHop -Server DC01.domain.com -UseSSL -AdminResults
# This example uses WinRM over HTTPS to display Admin AD Objects vulnerable to a Kerberos Double Hop on the remote domain controller DC01.domain.com
.EXAMPLE
Test-KerberosDoubleHop -ComputerResults -AdminResults
# This example checks for and displays Computer and Admin AD Objects vulnerable to a Kerberos Double Hop on the domain controller you are logged into
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: [email protected]
.INPUTS
None
.OUTPUTS
None
.LINK
https://osbornepro.com
https://writeups.osbornepro.com
https://encrypit.osbornepro.com
https://btpssecpack.osbornepro.com
https://github.com/tobor88
https://github.com/OsbornePro
https://gitlab.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.hackthebox.eu/profile/52286
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
#>
[CmdletBinding(DefaultParameterSetName='Local')]
param(
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$All,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$UserResults,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$AdminResults,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$ComputerResults,
[Parameter(
Position=0,
ParameterSetName='Remote',
Mandatory=$True,
ValueFromPipeline=$False,
HelpMessage="`n[H] Enter the hostname or FQDN of a domain controller in your environment. `n[E] EXAMPLE: DC01.domain.com")] # End Parameter
[String]$Server,
[Parameter(
ParameterSetName='Remote',
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$UseSSL
) # End param
$DomainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$Domain = $DomainObj.Name
$DCs = $DomainObj.DomainControllers.Name
Switch ($PSCmdlet.ParameterSetName) {
'Remote' {
$Regex = ‘(?<Address>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))’
If ($Server -match $Regex) {
Throw "[x] Please use the hostname or FQDN of the domain controller"
} # End If
If ($Server -notlike "*.$Domain") {
$ComputerName = "$Server.$Domain"
} Else {
$ComputerName = $Server
} # End If Else
If ($ComputerName -notin $DCs) {
Throw "[x] $ComputerName is not a known domain controller for $Domain"
} # End If
$Bool = $False
If ($UseSSL.IsPresent) {
$Bool = $True
} # End If
Invoke-Command -ArgumentList $All,$UserResults,$AdminResults,$ComputerResults -HideComputerName $ComputerName -UseSSL:$Bool -ScriptBlock {
$All = $Args[0]
$UserResults = $Args[1]
$AdminResults = $Args[2]
$ComputerResults = $Args[3]
If ($ComputerResults.IsPresent -or $All.IsPresent) {
Write-Verbose -Message "Getting information on computers in the domain that are vulnerable to a Kerberos Double Hop attack"
$ComputerResult = Get-ADComputer -Filter {(TrustedForDelegation -eq $True) -and (PrimaryGroupId -eq 515)} -Properties TrustedforDelegation,TrustedtoAuthForDelegation,servicePrincipalName,Description | Select-Object -Property DistinguishedName,TrustedForDelegation,TrustedtoAuthForDelegation
Write-Output -InputObject "[*] The above computers are vulnerable to Kerberos Hop Attack. This vulnerability allows an attacker to pivot to other machines using TGT stored on a trusted device. This can than be forwarded to a server for authentication."
} # End If
If ($UserResults.IsPresent -or $All.IsPresent) {
Write-Verbose -Message "Discovering accounts with the AD property 'Account is sensitive and cannot be delegated' selected. These accounts are protected against the Kerberos Double Hop vulnerability."
$UserResult = Get-ADGroupMember -Identity "Domain Users" | ForEach-Object {
Get-ADUser -Identity $_ -Properties AccountNotDelegated | Where-Object {$_.AccountNotDelegated -eq $False} | Select-Object -Property DistinguishedName,AccountNotDelegated
} # End ForEach-Object
Write-Output -InputObject "[*] The above accounts are vulnerable to a Kerberos Double Hop"
} # End If
If ($AdminResults.IsPresent -or $All.IsPresent) {
$AdminResult = @()
Write-Verbose -Message "Discovering any Admin Accounts vulnerable to Kerberos Hop Vulnerability"
$AdminResult += Get-ADGroupMember -Identity "Domain Admins" | ForEach-Object {
Get-ADUser -Identity $_ -Properties AccountNotDelegated | Where-Object {$_.AccountNotDelegated -eq $False} | Select-Object -Property DistinguishedName,AccountNotDelegated
} # End ForEach-Object
Write-Output -InputObject "[*] The above admin accounts are vulnerable to a Kerberos Double Hop"
} # End If
If ($ComputerResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObjet "COMPUTER RESULTS"
$ComputerResult
} # End If
If ($UserResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObject "`nUSER RESULTS"
$UserResult
} # End If
If ($AdminResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObject "`nADMIN RESULTS"
$AdminResult
} # End If
} # End Invoke-Command
} # End Switch Remote
'Local' {
$ComputerName = "$env:COMPUTERNAME.$Domain"
If ($ComputerName -notin $DCs) {
Throw "[x] $ComputerName is not a known domain controller for $Domain"
} # End If
If ($ComputerResults.IsPresent -or $All.IsPresent) {
Write-Verbose -Message "Getting information on computers in the domain that are vulnerable to a Kerberos Double Hop attack"
$ComputerResult = Get-ADComputer -Filter {(TrustedForDelegation -eq $True) -and (PrimaryGroupId -eq 515)} -Properties TrustedforDelegation,TrustedtoAuthForDelegation,servicePrincipalName,Description | Select-Object -Property DistinguishedName,TrustedForDelegation,TrustedtoAuthForDelegation
Write-Output -InputObject "[*] The above computers are vulnerable to Kerberos Hop Attack. This vulnerability allows an attacker to pivot to other machines using TGT stored on a trusted device. This can than be forwarded to a server for authentication."
} # End If
If ($UserResults.IsPresent -or $All.IsPresent) {
Write-Verbose -Message "Discovering accounts with the AD property 'Account is sensitive and cannot be delegated' selected. These accounts are protected against the Kerberos Double Hop vulnerability."
$UserResult = Get-ADGroupMember -Identity "Domain Users" | ForEach-Object {
Get-ADUser -Identity $_ -Properties AccountNotDelegated | Where-Object {$_.AccountNotDelegated -eq $False} | Select-Object -Property DistinguishedName,AccountNotDelegated
} # End ForEach-Object
Write-Output -InputObject "[*] The above accounts are vulnerable to a Kerberos Double Hop"
} # End If
If ($AdminResults.IsPresent -or $All.IsPresent) {
$AdminResult = @()
Write-Verbose -Message "Discovering any Admin Accounts vulnerable to Kerberos Hop Vulnerability"
$AdminResult += Get-ADGroupMember -Identity "Domain Admins" | ForEach-Object {
Get-ADUser -Identity $_ -Properties AccountNotDelegated | Where-Object {$_.AccountNotDelegated -eq $False} | Select-Object -Property DistinguishedName,AccountNotDelegated
} # End ForEach-Object
Write-Output -InputObjet "[*] The above admin accounts are vulnerable to a Kerberos Double Hop"
} # End If
If ($ComputerResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObject "COMPUTER RESULTS"
$ComputerResult
} # End If
If ($UserResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObject "`nUSER RESULTS"
$UserResult
} # End If
If ($AdminResults.IsPresent -or $All.IsPresent) {
Write-Output -InputObject "`nADMIN RESULTS"
$AdminResult
} # End If
} # End Switch Local
} # End Switch
} # End Function Test-KerberosDoubleHop