MSSQL AD Abuse

MSSQL Enumeration / Discovery

Python

The MSSQLPwner tool is based on impacket, and allows also authenticate using kerberos tickets, and attack through link chains

Enumerating from the network without domain session


Powershell

The powershell module PowerUpSQL is very useful in this case.

Enumerating from the network without domain session

Enumerating from inside the domain

MSSQL Basic Abuse

Access DB

MSSQL RCE

It might be also possible to execute commands inside the MSSQL host

Check in the page mentioned in the following section how to do this manually.

MSSQL Basic Hacking Tricks

1433 - Pentesting MSSQL - Microsoft SQL Server

If a MSSQL instance is trusted (database link) by a different MSSQL instance. If the user has privileges over the trusted database, he is going to be able to use the trust relationship to execute queries also in the other instance. This trusts can be chained and at some point the user might be able to find some misconfigured database where he can execute commands.

The links between databases work even across forest trusts.

Powershell Abuse

Metasploit

You can easily check for trusted links using metasploit.

Notice that metasploit will try to abuse only the openquery() function in MSSQL (so, if you can't execute command with openquery() you will need to try the EXECUTE method manually to execute commands, see more below.)

Manual - Openquery()

From Linux you could obtain a MSSQL console shell with sqsh and mssqlclient.py.

From Windows you could also find the links and execute commands manually using a MSSQL client like HeidiSQL

Login using Windows authentication:

Execute queries through the link (example: find more links in the new accessible instance):

You can continue these trusted links chain forever manually.

If you cannot perform actions like exec xp_cmdshell from openquery() try with the EXECUTE method.

Manual - EXECUTE

You can also abuse trusted links using EXECUTE:

Local Privilege Escalation

The MSSQL local user usually has a special type of privilege called SeImpersonatePrivilege. This allows the account to "impersonate a client after authentication".

A strategy that many authors have come up with is to force a SYSTEM service to authenticate to a rogue or man-in-the-middle service that the attacker creates. This rogue service is then able to impersonate the SYSTEM service whilst it's trying to authenticate.

SweetPotato has a collection of these various techniques which can be executed via Beacon's execute-assembly command.

Last updated