MSSQL Database Pillaging
Once access is established through SQL authentication or via xp_cmdshell, the database itself is the primary loot target. Application databases contain credentials, API keys, PII, session tokens, and business-sensitive data. This page covers efficient enumeration of database structure and systematic extraction of high-value content.
Enumerate Databases
List all databases on the instance. System databases (master, tempdb, model, msdb) rarely contain application data — focus on anything else:
name database_id create_date master 1 2003-04-08 09:13:36 tempdb 2 2024-01-15 09:22:11 model 3 2003-04-08 09:13:36 msdb 4 2000-08-06 01:53:27 AppDB 5 2022-03-14 11:04:52 HRSystem 6 2021-09-01 08:33:17
AppDB and HRSystem are application databases worth enumerating.
Check which databases the current login can access:
Enumerate Tables
Switch to the target database and list all tables:
Look for tables with names suggesting credentials, tokens, or sensitive data:
Hunt Credential Columns
Search across all tables in the current database for columns likely to hold credentials:
TABLE_NAME COLUMN_NAME DATA_TYPE users password_hash varchar users api_token varchar settings smtp_password varchar integrations api_key varchar
Dump Sensitive Tables
Once interesting tables and columns are identified, read the data directly:
username email password_hash api_token admin [email protected] $2y$10$abc123... tok_live_abc123 jsmith [email protected] $2y$10$def456... NULL
Bcrypt hashes are slow to crack. Look for weaker hash formats first — MD5, SHA1, or unsalted SHA256 are common in older applications. Check the hash length and format before deciding whether cracking is worth attempting.
For configuration or settings tables that may store integration credentials:
Search All Databases
Run the column search across all non-system databases at once using dynamic SQL:
msdb — SQL Server Agent Job Loot
The msdb system database contains SQL Server Agent job definitions. Jobs often include inline T-SQL, PowerShell, or OS commands with embedded credentials:
Look for connection strings, passwords passed as arguments, or hardcoded credentials in the command column.
Stored Procedures and Views
Stored procedures and views sometimes contain embedded credentials or logic that reveals how the application stores and retrieves sensitive data:
Read a specific procedure:
Or search procedure definitions for credential patterns:
References
-
Microsoft — sys.databaseslearn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql (opens in new tab)
catalog view for database-level metadata
-
Microsoft — INFORMATION_SCHEMAlearn.microsoft.com/en-us/sql/relational-databases/system-information-schema-views/system-information-schema-views-transact-sql (opens in new tab)
portable views for table and column enumeration
-
Microsoft — msdb SQL Agentlearn.microsoft.com/en-us/sql/ssms/agent/sql-server-agent (opens in new tab)
agent job structure and sysjobsteps schema
Was this helpful?
Your feedback helps improve this page.