PHP is_numeric function bypasses generating SQL injection

Source: Internet
Author: User



Honest mysql_real_escape_string () to prevent death ... is_numeric's SQL utilization condition is a bit harsh, but still less good = =



There are also actual cases in a CTF, please poke http://drops.wooyun.org/tips/870



First. Introduction of Is_numberic function
Domestic part of the CMS program has been useful to the Is_numberic function, we first look at the structure of this function
BOOL Is_numeric (mixed $var)
Returns TRUE if Var is a numeric and numeric string, otherwise FALSE is returned.




Second, the function is safe



Let's look at an example to see if this function is safe.


The code is as follows: $s = is_numeric ($_get[' s ')? $_get[' s ']:0;
$sql = "INSERT into test (type) values ($s);"; VALUES ($s) are not values (' $s ')
mysql_query ($sql);


The above fragment program is to determine whether the parameter S is a number, is to return a number, not to return 0, and then brought into the database query. (This will not construct the SQL statement)
We convert ' 1 or 1 ' to the value of the ' s ' parameter for the 16 binary 0x31206f722031
After the program runs, we query the database to see, such as:

If you re-query the field of this table out, do not filter into another SQL statement, will cause 2 injections.




Third. Summary
Try not to use this function, if you want to use this function, it is recommended to use the canonical SQL statement, conditional add single quotation marks, so that the 16 binary 0x31206f722031 will be displayed in the database. No 1 or 1 will appear.



Original link



PHP is_numeric function bypasses generating SQL injection


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.