MSSQL
MSSQL (Microsoft SQL)
SQLCMD allows SQL queries to be run through the windows command prompt or even remotely from another machine.
Way to connect to MSSQL:
impacket-mssqlclient Administrator:[email protected] -windows-authbreakdown:
Administrator:[email protected]
{username} :{passwd}@{IP_addr}check the version:
SELECT @@version;list of schema in database:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA;list all available database:
master, tempdb, model, and msdb are default databases
To get a list of tables
To get table column names:
To get all the values from the table:
breakdown
Below is an expanded set of notes and useful queries for MSSQL enumeration and usage, including commonly used views, functions, and procedures. This should help fill in the gaps and provide a more comprehensive reference.
Connecting and Running Commands
Using sqlcmd Locally:
sqlcmd Locally:-Sspecifies the server name or IP (e.g.,localhostor192.168.50.18)-Uspecifies the username-Pspecifies the passwordWithin
sqlcmd, end statements with a semicolon and useGOon a new line to execute. Example:
Using impacket-mssqlclient (Remote):
impacket-mssqlclient (Remote):No need to use
GOwhen running queries this way, asGOis asqlcmdbatch terminator and not part of the TDS protocol.
Basic Information and System Details
Check the Server Version:
Check Current User / Login:
Check the Current Database:
List All Available Databases:
Default system databases are usually: master, tempdb, model, and msdb.
Switch to a Specific Database:
Enumerating Schemas, Tables, and Columns
List All Schemas in the Current Database:
List All Tables in the Current Database:
List All Tables in Another Database:
List All Columns for a Specific Table:
If you need to qualify with a specific database and schema:
Select All Data From a Table:
Advanced Features
(Might Require Elevated Privileges)
Enable xp_cmdshell (if you have the right permissions):
xp_cmdshell (if you have the right permissions):Use xp_cmdshell to Run OS Commands (If Enabled):
xp_cmdshell to Run OS Commands (If Enabled):Directory Enumeration Using xp_dirtree:
Other Useful System Views
sys.syslogins(deprecated, but sometimes still accessible) can show logins.sys.sql_loginscan show SQL logins with hashed passwords (in certain conditions).sys.server_principalsandsys.database_principalsfor detailed user and login info.
Notes on Authentication and Connections
Integrated Authentication / Windows Auth: If you have a valid domain user that can connect with Windows auth:
The
-Eflag indicates trusted connection using current Windows credentials.Port Changes: By default, SQL Server uses port
1433. If the instance is listening on a different port, specify it as-S <server>,<port>(e.g.,sqlcmd -S 192.168.50.18,1433).
Last updated