Saturday February 11, 2012 @ 10:15:28 GMT+10    ( Weather:  n/a )
Home » Weblog Archives

Powered byD's Bloggie
Weblog » Archive » 2005 » September » Day 30 » PHP urldecode()
Browse by specific entry ...
 PHP Single Quote vs Doubel QuoteThe New Blogging System 

PHP urldecode() - 8:20 pm
Coding , PHP , Security  -  poster 

Don't use a urldecode on a $_GET variable !

Say you have a script:
script.php [ Hide ]
[ Highlight ] [ Text ]
<?php
// Don't do this !
$value = urldecode($_GET['something']);
?>


Exploit:
An attacker can make a query to that script script.php?something=%2527 [...]

The fact...

PHP "receives" this as %27, which your urldecode() will convert to ' (the singlequote). This may be CATASTROPHIC when injecting into SQL or some PHP functions relying on escaped quotes -- magic quotes rightly cannot detect this and will not protect you!

Eg. This exploit affects phpBB < 2.0.11


Solution:
Just an example of how you can make that more secure:
[ Hide ]
[ Highlight ] [ Text ]
<?php
$query = htmlspecialchars($_GET['query']);  
$query = str_replace('%2522', '', $query);  
$query = str_replace('%27', '', $query);  
$query = str_replace('%2527', '', $query);  
?>

[ Hide ]
[ Highlight ] [ Text ]
<?php
// good 
str_replace('&amp;', '&', htmlspecialchars($_GET['redirect']);
// bad
htmlspecialchars(urldecode($_GET['redirect']));
?>
 PHP Single Quote vs Doubel QuoteThe New Blogging System 

Reader comments ( Add your comments )

- No comments (yet) -

Leave a public comment

Info Note: Neither BBCode nor HTML tags are supported currently.
Why ? Just to make my life easier and keep things simple.
Others: Comments that are longer than 1000 characters will be truncated.

    ) Info

Info

Info


Before you submit... verification

Please enter verification codes as seen in the image above to post your comment.
If you can't read the word, click here
(Your comment will be manually approved by admin before it's displayed to public)

$ view_blog.php 2009.09.17 18:16:41 $
Lost? | XML/HTML sitemap | Contact
38.107.179.241 , 22 queries , 0.0784s
Gzip enabled , CSS compressed , JS compressed
Copyright © 2005-2011 Darren's Outpost