SQL

Learning Objectives

  • Understand SQL databases as high-value targets for data exfiltration, RCE, and lateral movement.

  • Differentiate between database types (e.g., MSSQL vs. MySQL) and their common deployments (e.g., web app backends).

Attack Surface Overview

# Common Vectors
- Misconfigurations (exposed ports, weak auth)
- SQL Injection (web β†’ DB)
- Auth bypass / brute-force
- Privilege escalation (stored procs, UDFs)
- RCE via xp_cmdshell / UDF
- NTLM relay & hash stealing
- Linked server pivoting

Enumeration (Stealth β†’ Aggressive)

# 1. Fast Port Discovery (Enhanced with Masscan for speed) 
masscan -p1433,1434,3306,5432 --rate=1000 --open-only 10.10.10.0/24 # Faster than nmap for large ranges 
# Or RustScan for even quicker results: rustscan -a 10.10.10.0/24 -- -sV -sC

# 2. Service Fingerprinting + Scripts (Add timing for stealth) 
nmap -Pn -sV -sC -p1433 --script=ms-sql* --max-rate 100 -T2 # -T2 for slower, stealthier scan 
nmap -Pn -sV -sC -p3306 --script=mysql* --max-rate 100 -T2 # PostgreSQL Enum 
nmap -Pn -sV -sC -p5432 --script=postgres* # Includes postgres-info, postgres-roles

# 3. Advanced MSSQL Enum (Add NTLM info for relay prep) 
nmap -p1433 --script=ms-sql-info,ms-sql-ntlm-info,ms-sql-empty-password,ms-sql-hasdbaccess,ms-sql-hashes-hashdump

# 4. MySQL Deep Scan 
nmap -p3306 --script=mysql-databases,mysql-users,mysql-variables,mysql-empty-password,mysql-info

# 5. PostgreSQL Deep Scan (New) 
nmap -p5432 --script=postgres-database,postgres-roles,postgres-user,postgres-lang-extensions

# 6. Metasploit Auxiliaries (Parallelize with resource scripts) 
use auxiliary/scanner/mssql/mssql_login set RHOSTS ; set USER_FILE users.txt; set PASS_FILE pass.txt; run 
# CrackMapExec for MSSQL (faster, multi-protocol) 
crackmapexec mssql -u users.txt -p pass.txt --shares # Also checks shares for pivots

Authentication & Misconfigurations

Common Weak Configs

Protocol-Specific Attacks

MySQL

MSSQL

PostgreSQL

Impersonation & PrivEsc

Linked Servers (Lateral Movement)

SQL Injection (SQLi) – Must-Know

Payload Cheat Sheet

Latest CVEs (2024–2025)

Post-Exploitation & Persistence

Key Commands Summary (Copy-Paste Ready)

Prep & Practice Plan

Last updated