PowerUpSQL
PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server
Link: https://github.com/NetSPI/PowerUpSQL
Example:
Or load into memory
Commands:
Find information on local server
PS C:>Get-SQLInstanceLocal | Get-SQLServerInfo
Test Connection to a server
Get-SQLInstanceDomain –Verbose | Get-SQLConnectionTestThreaded –Verbose –Threads 1
0
Search data in SQL instance:
Cheatsheet
SQL Server Discovery Cheats
Description | Command |
Discover Local SQL Server Instances |
|
Discover Remote SQL Server Instances | UDP Broadcast Ping
|
Discover Active Directory Domain SQL Server Instances |
|
Discover Active Directory Domain SQL Server Instances using alternative domain credentials |
|
List SQL Servers using a specific domain account |
|
List shared domain user SQL Server service accounts |
|
SQL Server Authentication Cheats
All PowerUpSQL functions support authenticating directly to a known SQL Server instance without having to perform discovery first. You can authenticate using the current domain user credentials or provide an SQL Server login. All PowerUpSQL functions will attempt to authenticate to the provided instance as the current domain user if the username/password parameters are not provided. This also applies if you're running PowerShell through runas /netonly.
Below are some basic examples using the "Get-SQLQuery" function.
Description | Command Examples |
Authenticating to a known SQL Server instance as the current domain user. | Current Domain User
|
Authenticating to a known SQL Server instance using a SQL Server login. | Server and Instance Name
|
SQL Server Login Test Cheats
Description | Command |
Get a list of domain SQL servers that can be logged into with a provided SQL Server login |
|
Get a list of domain SQL servers that can be logged into with the current domain account |
|
Get a list of domain SQL servers that can be logged into using an alternative domain account |
|
Get a list of domain SQL servers that can be logged into using an alternative domain account from a non domain system. |
|
Discover domain SQL Servers and determine if they are configured with default passwords used by common applications based on the instance name |
|
SQL Server Authenticated Information Gathering Cheats
Description | Command |
Get general server information such as SQL/OS versions, service accounts, sysdmin access etc. | Get information from a single server
|
Get an inventory of common objects from the remote server including permissions, databases, tables, views etc, and dump them out into CSV files. |
|
SQL Server Privilege Escalation Cheats
Description | Command |
Domain User to SQL Service Account. While running as a domain user this function will automatically do 4 things. 1. Identify SQL Servers on the domain via a LDAP query to a DC for SPNs. 2. Attempt to log into each. 3. Perform UNC path injection using various methods. 4. Attempt to capture the password hashes for the associated SQL Server service account. |
|
OS admin to sysadmin via service account impersonation, then all PowerUpSQL commands can be run as a sysadmin. |
|
Audit for Issues |
|
Escalate to sysadmin |
|
Execute OS commands: xp_cmdshell |
|
Execute OS commands: Custom xp |
|
Execute OS commands: CLR |
|
Execute OS commands: Ole Automation Procedures |
|
Execute OS commands: External Scripting - R |
|
Execute OS commands: External Scripting - Python |
|
Execute OS commands: Agent Job - CmdExec |
|
Execute OS commands: Agent Job - PowerShell |
|
Execute OS commands: Agent Job - VBScript |
|
Execute OS commands: Agent Job - JScript |
|
Crawl database links |
|
Crawl database links and execute query |
|
Crawl database links and execute OS command |
|
Dump contents of Agent jobs. Often contain passwords. Verbose output includes job summary data. |
|
Enumerate all SQL Logins as least privilege user and test username as password. | Run against single server
|
SQL Server Data Targeting Cheats
Description | Command |
Dump an inventory of common objects to csv in the current directory. |
|
Execute arbitrary query |
|
Grab basic server information |
|
Grab list of non-default databases |
|
Dump common information from server to files |
|
Find sensitive data based on column name |
|
Find sensitive data based on column name, but only target databases with transparent encryption |
|
Miscellaneous Post Exploitation Cheats
Description | Command |
Export all custom CLR assemblies to DLLs. They can be decompiled offline, and often contain passwords. Also, they can be backdoored without too much effort. |
|
Create a SQL command that can be used to import an existing (or backdoored) CLR assembly. |
|
Create a DLL and SQL command that can be used to import a CLR assembly to execute OS commands. |
|
Get a list of Shared SQL Server service accounts |
|
Last updated