PHP Magic Quotes Bring security issues analysis _php Tips

Source: Internet
Author: User
Tags sql injection

The "\" character generated by the extraction of magic quotes from PHP can pose some security problems, such as the following snippet:

Foo.php?xigr= ' Ryat
function daddslashes ($string, $force = 0) {
!defined (' MAGIC_QUOTES_GPC ') && Define (' MAGIC_QUOTES_GPC ', GET_MAGIC_QUOTES_GPC ());
if (! MAGIC_QUOTES_GPC | | $force) {
if (Is_array ($string)) {
foreach ($string as $key => $val) {
$string [$key] = Daddslashes ($val, $ Force);
}
else {
$string = addslashes ($string);
}
}
return $string;
}
...
foreach (Array (' _cookie ', ' _post ', ' _get ') as $_request) {
foreach ($$_request as $_key =>) {
$_value }!= ' _ ' && $$_key = daddslashes ($_value);
}
echo $xigr [' Hi '];
echo \

The above code originally expected to get an array variable $xigr[' Hi ' after daddslashes (), but there was no strict type regulation of the variable $XIGR, when we submitted a string variable $xigr= ' Ryat, which changed from the above processing to \ ' Ryat , to the end $xigr[' Hi '] will output \, if this variable is introduced into the SQL statement, then it will cause serious security problems, then look at the following code fragment:

...
if ($XIGR) {
foreach ($xigr as $k => $v) {
$uids [] = $v [' uid '];
}
$query = $db->query ("Select UID from users WHERE uid". Implode ("', '", $uids). ");

Using the above mentioned ideas, through the submission of foo.php?xigr[]= ' &xigr[][uid]=evilcode such a structural form can easily break the GPC or similar security processing, the formation of SQL injection holes! Should give enough attention to this!

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.