Skip to content
leg3ndProjects & tools
01Home02Projects03Tools04Notes
GMT+8
O/ OSCP exploitation reference
Workspace controls Memory only · 0 steps
Visualize path ↗
Command values 0 filled

Temporary connection values clear on reload. Passwords, hashes and tickets remain placeholders. Check address-family syntax in the selected command.

Reference index ↗ Search all procedures & variants ↗
01Discovery02Enumeration03Initial access04Usable access05Local privilege06Active Directory07Internal access08Evidence & reporting

QUICK REFERENCE

Discovery›Services›Web mapping›Web exploitation›Credentials›Public exploits›Sessions & transfers›Linux escalation›Windows escalation›AD enumeration›AD identity attacks›Lateral movement›Pivoting & tunnels›Execution troubleshooting›Integration & evidence›
174 methods · 15 topicsFull reference on GitHub ↗Commands · scripts · next steps
Tools/OSCP/Enumeration/Services
← All services tasks

Use SQL Server rights, impersonation and command facilities

CommandsIf → thenExplanation & examples

Needs: Correct SQL versus Windows authentication; database role and configuration must permit the requested operation

Shell commands

# Baseline
impacket-mssqlclient 'USER@TARGET'
impacket-mssqlclient 'DOMAIN/USER@TARGET' -windows-auth

At the SQL prompt

-- At the SQL prompt
SELECT @@VERSION;
SELECT SYSTEM_USER;
SELECT IS_SRVROLEMEMBER('sysadmin');
SELECT name FROM sys.databases;
USE DATABASE;
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
SELECT TOP 20 * FROM SCHEMA.TABLE;

-- MSSQL variant — command-execution boundary
EXEC xp_cmdshell 'whoami';

-- MSSQL linked-server and login-context mapping
SELECT SYSTEM_USER AS current_login,
       ORIGINAL_LOGIN() AS original_login,
       SUSER_SNAME() AS effective_login,
       IS_SRVROLEMEMBER('sysadmin') AS is_sysadmin;

SELECT name, product, provider, data_source, is_linked
FROM sys.servers
WHERE is_linked = 1;

EXEC master.dbo.sp_helplinkedsrvlogin;

-- MSSQL linked-server and login-context mapping
EXEC ('SELECT SYSTEM_USER AS remote_login,
              ORIGINAL_LOGIN() AS remote_original_login,
              IS_SRVROLEMEMBER(''sysadmin'') AS remote_is_sysadmin')
AT [LINKED_SERVER];

xp_cmdshell is disabled by default on new installations. Enabling it generally requires high privilege and changes server configuration; do not enable it merely to enumerate. When available, a sysadmin's child process normally runs as the SQL Server service account; an authorized non-sysadmin may use a configured proxy. Verify returned identity before choosing the next action.

MSSQL linked-server and login-context mapping

If RPC execution is disabled but data access is allowed, use a read-only pass-through query instead:

-- MSSQL linked-server and login-context mapping
SELECT *
FROM OPENQUERY([LINKED_SERVER],
  'SELECT SYSTEM_USER AS remote_login,
          ORIGINAL_LOGIN() AS remote_original_login');

MSSQL linked-server and login-context mapping

Decide: a returned remote identity enables only the operations granted to that mapped login. RPC OUT is disabled, login-mapping failures and data-access failures rule out different mechanisms; they do not prove the server is unreachable. If enum_impersonate identifies a specific permitted login, test only that login and always return to the original context:

-- MSSQL linked-server and login-context mapping
EXECUTE AS LOGIN = 'LOGIN';
SELECT SYSTEM_USER, ORIGINAL_LOGIN(), SUSER_SNAME(), IS_SRVROLEMEMBER('sysadmin');
REVERT;

Do not enable RPC, create mappings or change server configuration merely to enumerate. A remote SQL query is not OS execution; independently validate any file or command facility and the operating-system identity behind it.

Verify → Verify SQL identity and any OS effect with hostname/whoami; record service/proxy execution identity.

If it fails → Login success with denied configuration changes is a rights boundary. Do not repeatedly enable an unavailable facility. More detail ↓

If → then

  • Confirmed SQL control plus database file, execution or impersonation privileges → Convert database rights into a file or operating-system effect

    Needs: DBMS-specific privilege and enabled facility; OS service identity, writable/readable destination and a compatible consumer

  • A secret-like value, key file, stored hash, challenge response or ticket → Classify the artifact and its identity context

    Needs: Artifact provenance and format; possible local/domain/application identity and compatible protocol

  • A PoC, injected command or remote client reports execution → Verify command execution, host and represented identity

    Needs: A functioning execution primitive and an observable output or controlled side effect

No useful finding → another task in this topic. Failed check → resolve the failure before ruling out the path.

Explanation & examples

Use SQL Server rights, impersonation and command facilities

USE WHEN
SQL Server credentials or a Windows identity accepted by the database
STARTING ACCESS
A confirmed reachable application; anonymous context or one identified credential
RESULT
Database data, a more useful SQL security context or verified server command execution

Recognize the clue

Once SQL Server authentication works, inspect actual login/server role and supported impersonation context.

SELECT SYSTEM_USER, ORIGINAL_LOGIN(), @@VERSION;
SELECT IS_SRVROLEMEMBER('sysadmin');
SYNTHETIC EXAMPLE OUTPUT
SYSTEM_USER: DOMAIN\USER
ORIGINAL_LOGIN: DOMAIN\USER
IS_SRVROLEMEMBER: 0

Means: A valid login with sysadmin=0 is data/rights evidence, not permission to enable xp_cmdshell.

Confirm: Enumerate actual database/server grants and useful impersonation; independently verify any OS facility and its identity.

After validation
Required role/configuration and OS effect are verified: use the supported database-to-command method.
Ruled out in this context
No facility/impersonation right rules out that proposed OS chain while readable data may remain.
Still inconclusive
A failed role query or unknown proxy context needs a narrower rights check.

Troubleshooting: Login success with denied configuration changes is a rights boundary. Do not repeatedly enable an unavailable facility.

Let the tool prompt for the password. At the SQL prompt:

Interpret: IS_SRVROLEMEMBER('sysadmin') returns 1, 0 or NULL; NULL is not success. Impacket also exposes helpers such as enum_impersonate and xp_cmdshell depending on version and rights.

MSSQL variant — command-execution boundary

xp_cmdshell is disabled by default on new installations. Enabling it generally requires high privilege and changes server configuration; do not enable it merely to enumerate. When available, a sysadmin's child process normally runs as the SQL Server service account; an authorized non-sysadmin may use a configured proxy. Verify returned identity before choosing the next action.

MSSQL linked-server and login-context mapping

Treat a linked server as another authentication and authorization boundary. The local SQL login, its mapped remote login, remote SQL role and RPC/data-access settings can all differ.

Interpret: sys.servers proves configuration, not remote access. sp_helplinkedsrvlogin shows local-to-remote mappings; a NULL local login can represent a mapping that applies to all local logins. Preserve the local and remote identities separately.

After selecting one named link, test the smallest remote query supported by its configuration:

If RPC execution is disabled but data access is allowed, use a read-only pass-through query instead:

Decide: a returned remote identity enables only the operations granted to that mapped login. RPC OUT is disabled, login-mapping failures and data-access failures rule out different mechanisms; they do not prove the server is unreachable. If enum_impersonate identifies a specific permitted login, test only that login and always return to the original context:

Do not enable RPC, create mappings or change server configuration merely to enumerate. A remote SQL query is not OS execution; independently validate any file or command facility and the operating-system identity behind it.

Sources: Microsoft sys.servers, sp_helplinkedsrvlogin, EXECUTE AS, and OPENQUERY.

Why it works

SQL login, sysadmin/impersonation rights and xp_cmdshell configuration are separate conditions. OS commands run under the SQL service or configured proxy context, not automatically as domain administrator.

Worked example · hypothetical

Observation: Windows authentication succeeds to SQL Server. Test: inspect role and allowed impersonation. Illustrative output: only a low-privilege database user. Interpretation: enumerate permitted data and relationships before proposing xp_cmdshell.

New identity, privilege, host or route? Re-enumerate → All topic tasks →

Study guide ↗Full procedure ↗Cheatsheet ↗
HomeProjectsToolsNotes
Interactive toolsOSCP notes ↗Extended OSCP workspace ↗Attack-path visualizer ↗

© 2026 Armaan. Built with curiosity.

GitHub ↗GMT+8