Skip to main content

MSSQL

Microsoft SQL Server isn’t just a place data lives — it’s a foothold on a Windows box. Weak sa credentials get you in, and xp_cmdshell lets you run operating-system commands straight from a SQL prompt. A database login becomes code execution on the host.
Protocol: TCP · Port: 1433

What Is MSSQL?

Microsoft SQL Server (MSSQL) is Microsoft’s SQL-based relational database management system. Versions run on Linux and macOS, but you’ll most often meet MSSQL on Windows targets — which is what makes it so valuable: it ties directly into Windows authentication and can execute OS commands.

MSSQL Clients

SQL Server Management Studio (SSMS) ships with the MSSQL install package or can be downloaded separately. Because it’s a client application, it can be installed on any admin’s or developer’s workstation — not just the database server.
Since SSMS lives on client machines too, you may find a vulnerable workstation with SSMS holding saved credentials that connect straight to the database. The DB server isn’t the only place to look for a way in.

Default System Databases

MSSQL ships with system databases that reveal the structure of everything hosted on the server:

Default Configuration

When an admin installs MSSQL to be network-accessible, the service typically runs as NT SERVICE\MSSQLSERVER. Authentication set to Windows Authentication means the underlying Windows OS processes the login — checking the local SAM database or the domain controller (Active Directory) before granting access to the DBMS. That’s the link that makes MSSQL a stepping stone into the wider Windows environment.

Dangerous Settings

Worth investigating on any MSSQL instance:
The sa account is the prize. It’s the built-in sysadmin, and admins frequently forget to disable it or leave it with a weak password. sa access means full control of the server — including the ability to enable and run xp_cmdshell for OS command execution.

Footprinting the Service

MSSQL Clients for Pentesters

Beyond SSMS, many clients can connect to MSSQL:
  1. mssql-cli
  2. SQL Server PowerShell
  3. HeidiSQL
  4. SQLPro
  5. Impacket’s mssqlclient.py
mssqlclient.py is usually the most useful — Impacket ships on most pentest distros by default. Find it with:

Nmap

MSSQL listens on TCP 1433. The MSSQL NSE scripts pull a lot at once — hostname, instance name, version, and whether named pipes are enabled:

Metasploit mssql_ping

The mssql_ping auxiliary scanner adds more footprinting detail:

Connecting with mssqlclient.py

With guessed or recovered credentials, connect and interact using T-SQL (Transact-SQL). The windows-auth flag uses Windows authentication:
Get a lay of the land by listing databases (in MSSQL, tables are sysobjects):

Command Execution with xp_cmdshell

This is what sets MSSQL apart. With sa (or sufficient privileges), the xp_cmdshell stored procedure runs OS commands as the SQL service account. It’s disabled by default, but you can enable it from the SQL prompt:
xp_cmdshell turns a database login into a shell on the Windows host, running as the SQL service account. From whoami you can move to downloading and running a payload, and from there to privilege escalation — the SQL service account often has SeImpersonatePrivilege, opening the door to a Potato attack. This is the single most important reason to prioritize MSSQL on a Windows engagement.

Quick Reference

The footprinting flow: nmap ms-sql-* for instance/version → try sa with weak/default creds → connect with mssqlclient.py → enumerate databases → enable and abuse xp_cmdshell for command execution on the host.
Next: Oracle TNS — the Oracle listener, SID enumeration, and database privilege escalation.