githubEdit

MSSQL Attacks


Setup

Load the SQL-BOF Aggressor script:

  1. Go to Cobalt Strike > Script Manager

  2. Click Load

  3. Select C:\Tools\SQL-BOF\SQL\SQL.cna


Enumeration

Find MSSQL Servers via LDAP

ldapsearch (&(samAccountType=805306368)(servicePrincipalName=MSSQLSvc*)) --attributes name,samAccountName,servicePrincipalName

# Example output:
name: MSSQL Service
sAMAccountName: mssql_svc
servicePrincipalName: MSSQLSvc/ilf-db-1.inlanefreight.local:1433, MSSQLSvc/ilf-db-1.inlanefreight.local
retrieved 1 results total

Server Information

Impersonate User with Access


xp_cmdshell

Direct command execution with output.

Check if Enabled

Enable

Execute Commands

Disable (Cleanup)


OLE Automation Procedures

Command execution without output - use for reverse shells.

Check if Enabled

Enable

Execute Reverse Shell

Generate encoded PowerShell command:

Execute:

Disable (Cleanup)


SQL CLR (Common Language Runtime)

Execute .NET assemblies within SQL Server.

Check if Enabled

Create CLR Assembly

  1. Create new Class Library (.NET Framework) in Visual Studio

    • Project name: MyProcedure

  2. Add smb_x64.xthread.bin as embedded resource

  3. Use the following code:

Execute CLR DLL

Disable (Cleanup)


Linked Servers

Pivot through SQL Server links.

Check Identity on Linked Server

Enable RPC for Linked Server

Execute CLR via Linked Server


SQL Server Privilege Escalation

Escalate from SQL service account to SYSTEM using potato attacks.

Check Token Privileges

Find Writable Directory

Upload Payload

Execute SweetPotato


Quick Reference

Method
Output
Use Case

xp_cmdshell

✅ Yes

Quick command execution

OLE Automation

❌ No

Reverse shell payload

CLR

❌ No

Beacon injection

Linked Servers

Varies

Pivot to other SQL servers

SQL-BOF Command
Description

sql-info

Server information

sql-whoami

Current user context

sql-query

Execute raw SQL

sql-enablexp / sql-disablexp

Toggle xp_cmdshell

sql-xpcmd

Execute via xp_cmdshell

sql-enableole / sql-disableole

Toggle OLE Automation

sql-olecmd

Execute via OLE

sql-clr

Execute CLR assembly

sql-disableclr

Disable CLR

sql-links

Enumerate linked servers

sql-checkrpc / sql-enablerpc

Toggle RPC

Last updated