Author: Demon
Link: http: // demo n.tw/programming/php-urldecode-sql-injection.html
The Discuz X1.5 forum of Ihipop school was hacked and had a quarrel for an afternoon. Google "Discuz! X1-1.5 notify_credit.php Blind SQL injection exploit ", you'll know.
Discuz is a popular forum system in China. There should be many Hacked websites. However, I am not interested in intruding other people's websites. I also despise the so-called "hackers" whose code will not write attacks that only use tools released by others ".
After a rough look at the code, this SQL injection vulnerability is caused by the urldecode function. In the PHP manual, the urldecode function has a warning:
The superglobals $ _ GET and $ _ REQUEST are already decoded. Using urldecode () on an element in $ _ GET or $ _ REQUEST cocould have unexpected and dangerous results.
The Discuz developer (probably a newbie) adds a urldecode:
Foreach ($ _ POST as $ k =>$ v) {$ value = urldecode ($ v); $ this-> setParameter ($ k, $ value );} the single quotation mark is urlencode twice and then % 2527. Then, POST. When PHP generates the global variable $ _ POST, urldecode first and get % 27, PHP then checks the settings of Magic Quotes, but % 27 will not be set by addslashes whether or not Magic Quotes is enabled, because there is no single quotation mark at all. However, if you add urldecode to the PHP code, % 27 will become a single quotation mark, and then ...... You know.
Www.2cto.com
When I was a beginner in PHP, I read a bad book from the school library, and I didn't write any PHP code in it. when processing the form, it will automatically urldecode, so I used the urldecode function to decode it myself (I vaguely remember it was written in the book as well. It was a mistake ).
To sum up, it is: 1. It is very important to choose a good book; 2. Use the urldecode function with caution. 3. Pay attention to the warning in the PHP manual.