[1433] MSSQL

dbeaver GUI

To install dbeaver using a Debian package we can download the release .deb package from https://github.com/dbeaver/dbeaver/releases and execute the following command:

Intrusionz3r0X@htb[/htb]$ sudo dpkg -i dbeaver-<version>.deb]
Intrusionz3r0X@htb[/htb]$ dbeaver &

MSSQL default system schemas/databases:

  • master - keeps the information for an instance of SQL Server.

  • msdb - used by SQL Server Agent.

  • model - a template database copied for each new database.

  • resource - a read-only database that keeps system objects visible in every database on the server in sys schema.

  • tempdb - keeps temporary objects for SQL queries.

Basic Enumeration

MSSQLPWNER tool

Advance Enumeration and techniques

Enable XP_CMDSHELL

Write Files

Read Local Files

Capture NTLMv2 Hash

Impersonate Users

It's recommended to run EXECUTE AS LOGIN within the master DB

Linked Servers exploitation on MSSQL

Note: If we need to use quotes in our query to the linked server, we need to use single double quotes to escape the single quote. To run multiples commands at once we can divide them up with a semi colon (;).

Check the attributes LocalLogin and RemoteLogin to determine if your user can authenticate as Sysadmin on the linked server

Exploitation on Windows

Exploitation on Linux

Trustworthy Databases

If our user hasn't been granted remote login permissions as a sysadmin (sa), but instead has been provided public privileges as a local SQL User.we can pursue a strategy to enumerate trusted databases on the targeted linked server. Our objective would be to determine if the user holds the db_owner role for any trusted database. If such a database is identified, we can create a stored procedure to enable xp_cmdshell, ensuring it executes under the context of the OWNER, which typically would be the sa user.

Requirements

  1. Identified a trustworthy database

  2. Confirmed that our current user login name

  3. Confirm our current user has db_owner privileges roles on database

  4. Verify owner database is SA

Enumerate Trustworthy Databases

Exploitation on Windows

Exploitation on Linux

Last updated