PORT STATE SERVICE REASON VERSION 135/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC 139/tcp open netbios-ssn syn-ack ttl 127 Microsoft Windows netbios-ssn 445/tcp open microsoft-ds? syn-ack ttl 127 1433/tcp open ms-sql-s syn-ack ttl 127 Microsoft SQL Server 14.00.1000.00 | ms-sql-ntlm-info: | Target_Name: HTB | NetBIOS_Domain_Name: HTB | NetBIOS_Computer_Name: QUERIER | DNS_Domain_Name: HTB.LOCAL | DNS_Computer_Name: QUERIER.HTB.LOCAL | DNS_Tree_Name: HTB.LOCAL |_ Product_Version: 10.0.17763 | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback | Issuer: commonName=SSL_Self_Signed_Fallback | Public Key type: rsa | Public Key bits: 2048 | Signature Algorithm: sha256WithRSAEncryption | Not valid before: 2019-06-19T20:54:35 | Not valid after: 2049-06-19T20:54:35 | MD5: 3d0e 78a8 d3f9 045f e210 83b0 63c2 678d | SHA-1: 2f70 d6a2 fb84 c349 ac3d b5ca 96ae 8b0a 3a0e 275c | -----BEGIN CERTIFICATE----- | MIIC/jCCAeagAwIBAgIQOynOEG/RjYlM4VpPmIkO4DANBgkqhkiG9w0BAQsFADA7 | MTkwNwYDVQQDHjAAUwBTAEwAXwBTAGUAbABmAF8AUwBpAGcAbgBlAGQAXwBGAGEA | bABsAGIAYQBjAGswHhcNMTkwNjE5MjA1NDM1WhcNNDkwNjE5MjA1NDM1WjA7MTkw | NwYDVQQDHjAAUwBTAEwAXwBTAGUAbABmAF8AUwBpAGcAbgBlAGQAXwBGAGEAbABs | AGIAYQBjAGswggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYiSfYhQ1q | o0GWGyw/3Z7wObjDPeTQPgFZ1l6oIr+ujBBbFQA4tbM5HYAg1qADwgXt64R2TGLn | /Brjort64fXYGXk2lzMrgevvckeeC6u9GcT6YWLA76JOeGeZftyrHoF4t5Bodf0A | K/rn3BGsWvh+sBBngi6SS5dBg2cb3lPPgbd3n23BwIRKBvwqmYtjFveqqUpXoHQX | ldOcEbnJ6Rp6gq/mE+s0A6cXqsqL4j14RDKsS+7rkU6aP8yXFvFaj/MCk8yXmX8K | NNJZ5hF4xB8exkcBwjN550bnXqnqR7fK0yt+YqoioGOwQHS2HpJ/plVuD4XRGdXQ | XA0eg/pqXSytAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAEzemJ04ugnttlGahv1Y | b4/+rnaGsp4orcPQDxcDuLzXPBJQ2NJ0Um16uZ559neDtC+1cMgmt8Y2n29pSuX1 | bPj4Dc3n+YofSsYHYPgCxBQHaq0bJxX1UoHsk2o1i28CywQ2bgojFu+iKFmwEMgQ | ni5jFBkUBM/JJ5MUYR8PNJ66hkXRiL4pl63oElNMRwT0vlgaIU4qGmWrE72iCLui | h0DajwCJjND8f8ILVC3arvVWMZXitQOUT7hRH5NGjQhBfBsHXaB5QB/l90BQK3NR | Hwdcc4kgjG6o6HK5aEw300xBuFq7YMxNWqg6ScYvURm83J80TqFjMnfhfRMTyypK | LE8= |_-----END CERTIFICATE----- |_ssl-date: 2019-06-19T21:21:54+00:00; +1s from scanner time. Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Host script results: |_clock-skew: mean: 0s, deviation: 0s, median: 0s | ms-sql-info: | 10.10.10.125:1433: | Version: | name: Microsoft SQL Server | number: 14.00.1000.00 | Product: Microsoft SQL Server |_ TCP port: 1433 | p2p-conficker: | Checking for Conficker.C or higher... | Check 1 (port 10624/tcp): CLEAN (Couldn't connect) | Check 2 (port 43566/tcp): CLEAN (Couldn't connect) | Check 3 (port 64306/udp): CLEAN (Timeout) | Check 4 (port 40571/udp): CLEAN (Failed to receive data) |_ 0/4 checks are positive: Host is CLEAN or ports are blocked | smb2-security-mode: | 2.02: |_ Message signing enabled but not required | smb2-time: | date: 2019-06-19 23:21:57 |_ start_date: N/A
Pwn
The machine has SMB accessible with null sessions. Using smbclient it’s possible to get the list of shares (somehow smbclient.py from Impacket and nullinux didn’t work).
1 2 3 4 5 6 7 8 9 10
smbclient -L '\\10.10.10.125\' Unable to initialize messaging context Enter MYGROUP\dodo's password:
Sharename Type Comment --------- ---- ------- ADMIN$ Disk Remote Admin C$ Disk Default share IPC$ IPC Remote IPC Reports Disk
The only shares that it is accessible without authentication is Reports.
The Excel file contains a VBA macro that is executed when the file is opened:
Once the connection is established we found out that the user reporting can’t enable xp_cmdshell (this function is used to execute commands on the server using stored procedures). Recalling from the Giddy‘s box, another stored procedure can be abused to trigger a SMB coonection from the SQL Server: xp_dirtree.
Using smbserver.py (yeah…from Impacket!) we can spin up a SMB server used to capture the NetNTLMv2 hash from the SQL Server.
Using this pair of credentials it’s possible to execute commands from the MSSQL client:
And the first flag can be read:
xp_cmdshell type C:\Users\mssql-svc\Desktop\user.txt
To move on the privilege escaltion phase we used PowerUP.ps1 from PowerShellMafia. This script will check for loot credentials, vulnerable DDLs and unquoted path that can be exploited in Windows machines.
Using the same SMB server it’s possible to upload the script on the machine.
The script is located in the %TEMP% folder and use xp_cmdshell we can trigger the import and the execution:
With the Administrator user login we can read the last flag.
N.B.: in this case the user mssql-svc has the privilege SeImpersonatePrivilege enabled but the system (Windows Server 2019) is patched against Rotten Potato family exploits.