MSSQL Enumeration
Overview
Microsoft SQL (MSSQL) is Microsoft's SQL-based relational database management system. Unlike MySQL, which is open-source, MSSQL is closed source and was initially written to run on Windows operating systems. It is popular among database administrators and developers when building applications that run on Microsoft's .NET framework due to its strong native support for .NET.
Key Characteristics:
Port 1433: Default MSSQL port
Authentication: Windows Authentication or SQL Server Authentication
Default Instance: MSSQLSERVER
Protocol: Tabular Data Stream (TDS)
Platform: Primarily Windows (Linux/MacOS versions available)
MSSQL Clients
SQL Server Management Studio (SSMS)
SQL Server Management Studio (SSMS) comes as a feature that can be installed with the MSSQL install package or downloaded separately. Key points:
Commonly installed on the server for initial configuration
Can be installed on any system for remote database management
May contain saved credentials on vulnerable systems
Provides full database management capabilities
Alternative MSSQL Clients
mssql-cli
Command-line interface for MSSQL
SQL Server PowerShell
PowerShell module for MSSQL
HeidiSQL
Lightweight GUI client
SQLPro
Professional database client
Impacket's mssqlclient.py
Python-based client (preferred for pentesting)
Locating Impacket MSSQL Client
Default System Databases
MSSQL has default system databases that help understand the structure of all databases hosted on a target server:
master
Tracks all system information for an SQL server instance
model
Template database that acts as a structure for every new database created
msdb
Used by SQL Server Agent to schedule jobs & alerts
tempdb
Stores temporary objects
resource
Read-only database containing system objects included with SQL server
Default Configuration
Initial Setup
When an admin initially installs and configures MSSQL to be network accessible:
Service Account: SQL service runs as
NT SERVICE\MSSQLSERVERAuthentication: Windows Authentication by default
Encryption: Not enforced by default
Access Control: Uses Windows OS for authentication processing
Authentication Methods
Windows Authentication:
Uses local SAM database or domain controller
Integrates with Active Directory
Can lead to privilege escalation if compromised
SQL Server Authentication:
Uses database-specific user accounts
Independent of Windows authentication
Dangerous Settings
Common misconfigurations that can lead to security issues:
No encryption
High
MSSQL clients not using encryption to connect
Self-signed certificates
Medium
Can be spoofed during attacks
Named pipes enabled
Medium
Additional attack surface
Default SA credentials
Critical
Weak or unchanged SA account passwords
SA account enabled
High
Admins may forget to disable default SA account
Footprinting the Service
Comprehensive Nmap Scan
Example Nmap Output Analysis
Key Information Extracted:
Hostname: SQL-01
Instance: MSSQLSERVER
Version: Microsoft SQL Server 2019 RTM (15.00.2000.00)
Named Pipes: Enabled (\target\pipe\sql\query)
Clustering: Not clustered
Metasploit MSSQL Ping Scanner
Connecting with mssqlclient.py
Windows Authentication
Basic Database Enumeration
SQL Server Authentication
Advanced Enumeration
Database Information Gathering
System Information
HTB Academy Lab Questions
Question 1: Hostname Detection
Task: Enumerate the target and list the hostname of MSSQL server
Solution:
Question 2: Non-Default Database Discovery
Task: Connect using account (backdoor:Password1) and list non-default database
Solution:
Enumeration Techniques
1. Service Detection
2. Authentication Testing
3. Database Analysis
Security Assessment
Common Vulnerabilities
Default Credentials: SA account with weak passwords
Windows Authentication: Compromised domain accounts
Missing Encryption: Plaintext communication
Excessive Permissions: Over-privileged database users
Outdated Software: Unpatched MSSQL instances
Enumeration Checklist
Attack Vectors
1. Credential-based Access
2. Command Execution
3. Data Extraction
Tools and Techniques
Essential Tools
Defensive Measures
Security Best Practices
Disable SA account: Use Windows Authentication only
Enable encryption: Force SSL/TLS connections
Least privilege: Restrict database permissions
Regular updates: Apply security patches
Monitor access: Enable audit logging
Network security: Firewall restrictions
Last updated