MSSQL (1433)

TCP - 1433

UDP - 1434

TCP - 2433 if hidden mode

Footprinting using nmap

sudo nmap --script ms-sql-info,ms-sql-empty-password,ms-sql-xp-cmdshell,ms-sql-config,ms-sql-ntlm-info,ms-sql-tables,ms-sql-hasdbaccess,ms-sql-dac,ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=sa,mssql.password=,mssql.instance-name=MSSQLSERVER -sV -p 1433 10.129.201.248

MSSQL ping in metasploit

use scanner/mssql/mssql_ping

Connecting with MSSQL client

python3 mssqlclient.py Administrator@10.129.201.248 -windows-auth

Show databases command

select name from sys.databases

MSSQL tools:

  • mssql-cli

  • SQL Server Powershell

  • HediSQL

  • SQLPro

  • Impacket's mssqlclient.py

Protocol Specific Attacks

Code Execution

If xp_cmdshell is disabled, we can enable it

Note:

There are other methods to get command execution, such as adding extended stored proceduresarrow-up-right, CLR Assembliesarrow-up-right, SQL Server Agent Jobsarrow-up-right, and external scriptsarrow-up-right

xp_regwrite can also be used for priv esc

Write Local Files

  1. Enable Ole automation procedures (must be admin)

  1. Create a File

Read Local Files

Capture MSSQL Service Hash

  1. XP_DIRTREE Hash Stealing

    XP_SUBDIRS Hash Stealing

  2. We will receive the hash if success

  3. You can pth or crack the hash

    Cracking NTLMv2 hash john -w=rockyou.txt --format=netntlmv2 hashes.txt

Impersonating Existing Users

  1. Identify users we can impersonate

  1. Verify our current user and role

  1. Impersonate the SA user

Note: Use master if there is an error before running the execute as login. Use revert to change back to ht previous user.

Communicate with other databases

  1. Identify linked servers

  1. if isremote=0 that is lined server, if not, that is a remote server

Last updated