PHP beware of the SQL injection vulnerability caused by urldecode

Source: Internet
Author: User
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, therefore, I used the urldecode function to decode the Discuz X1.5 Forum of Ihipop school. I had a quarrel there 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:
The code is as follows:
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.

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.
From http://demon.tw/programming/php-urldecode-sql-injection.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.