Topic: Hack this code: possible mysql injection (Read 2494 times)
Community Supporter?
Hunky Junky Monky Man!
Gender:
Posts: 68
436 credits Members referred : 0
Schwa?
« on: Jan 15, 2008, 03:45:31 am »
Ok - as always - edited to protect my employer - or my job
So, I've been auditing some code for my employer, and I found some unfiltered code a mysql query.
The url from /news is /newsitem/12 where 12 is the ID of the article.
Then, here is the code:
$newsID = basename($_SERVER['REQUEST_URI']); $sql = "select * from Tnews where newsID={$newsID}";
So, I've already fixed this - so no worries, but I'm having a hard time actually proving the SQL injection issue here. Every time I put something in there, it gets urlencoded (obviously) by the browser. I've been able to successfully break the sql, but never get extra info. I've also tried telnet connections to the apache server - but any non-url encoded urls generate 400 errors for bad request.
Anyone have any ideas?
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Jan 15, 2008, 06:24:58 am »
$newsID = basename($_SERVER['REQUEST_URI']); $sql = "select * from Tnews where newsID=".(int)$newsID;
lol
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #2 on: Jan 15, 2008, 06:44:53 am »
The (int) is always good to use for numeric queries.
Now if you are looking for something fast that will work on anything (but may cause other kind of problems) you can try something like this:
Community Supporter?
Hunky Junky Monky Man!
Gender:
Posts: 68
436 credits Members referred : 0
Schwa?
« Reply #6 on: Jan 22, 2008, 03:11:07 pm »
Nope - it gets URL encoded in the URL.
Try this:
make a php file named test.php
inside of it put: echo basename($_SERVER['REQUEST_URI']);
Start experimenting with adding additional items onto the end of it... so... test.php/123 test.php/; select *
see how the results look to get a better idea of what I'm talking about
Community Supporter?
Hunky Junky Monky Man!
Gender:
Posts: 68
436 credits Members referred : 0
Schwa?
« Reply #7 on: Feb 10, 2008, 10:57:18 pm »
This is depressing. I've posted this query among several boards - and everyone keeps replying with generic solutions - as if it was a $_GET result and not from the $_SERVER['REQUEST_URI'];
I guess I'm just going to assume that even though I 'fixed' the errors, it never could have been exploited...
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7523