Skip to main content

Overview

impacket-mssqlclient is an interactive MSSQL client that supports SQL auth, Windows/NTLM auth, pass-the-hash, and Kerberos. Once connected, escalate from database access to OS command execution, file reads, and lateral movement.

Authentication

SQL Authentication

Windows Authentication

Pass-the-Hash

Kerberos Authentication

Custom Port


Basic Connection

Once connected, you get an interactive SQL prompt:

Enable xp_cmdshell

xp_cmdshell executes OS commands. Disabled by default — requires sysadmin to enable.

Via sp_configure

Using the Built-in Command

The mssqlclient shell has a shortcut:

Execute OS Commands via xp_cmdshell


File Read

OPENROWSET

BULK INSERT


Capture NTLM Hash via xp_dirtree

Force the MSSQL service account to authenticate to your SMB server, capturing its NetNTLMv2 hash.
The MSSQL service account hash appears on your SMB server. Crack it or relay it.

Linked Servers

Linked servers allow querying remote MSSQL instances through the current one. They often run with elevated privileges.

Enumerate Linked Servers


Ole Automation Procedures

sp_OACreate provides an alternative to xp_cmdshell for command execution and file operations.

Enable Ole Automation

Write a File

Execute a Command via Ole Automation


Enable xp_cmdshell via Ole Automation

When sp_configure is blocked (trigger/policy), use Ole Automation to modify the registry directly and enable xp_cmdshell.
After modifying the registry, restart the SQL service or try RECONFIGURE to apply changes.

EXECUTE AS LOGIN (Impersonation)

If your user has impersonation privileges, escalate by executing as a more privileged login.

Enumerate Impersonation Privileges

Impersonate and Escalate

Database-Level Impersonation


Quick Reference