PHP MongoDB Injection _php Tutorial

Source: Internet
Author: User
Tags mongodb injection php mongodb
The following is an introduction to the methods and principles of PHP+MONGODB injection

One of the posts said: login.php?username=admin&passwd[$ne]=1 may inject, just look at the time, I feel quite puzzled, this how there is an injection of loopholes, and finally from this post http:// The reason was found in the hi.baidu.com/hi_heige/item/ce93ce926dede4f428164747. Because PHP is able to submit an array directly, that is to say, it is a "$ne" index, I made a demo:


[PHP]
$passwd =$_get["passwd"];
Var_dump ($PASSWD);

$passwd =$_get["passwd"];
Var_dump ($PASSWD);
The test results are:

Array (1) {["$ne"]=> string (1) "1"}


That way.


[PHP]
$collection->find (Array (
"Username" = "admin",
"passwd" = Array ("$ne" = 1)
));

$collection->find (Array (
"Username" = "admin",
"passwd" = Array ("$ne" = 1)
));
It becomes the following:


[PHP]

$collection->find (Array ("username" + "admin", "passwd" = = Array ("$ne" + 1))); $collection->find (Array (
"Username" = "admin",
"passwd" = Array ("$ne" = 1)
));


If you change the link to this (username=[$ne]=1&passwd[$ne]=1), then all the user information will be retrieved.

The workaround for this bug is to cast the argument to the string type after getting the parameter:

[PHP]
$collection->find (Array (
"Username" = (string) $_get[' username '],
"Passwd" = (string) $_get[' passwd ']
));

$collection->find (Array (
"Username" = (string) $_get[' username '],
"Passwd" = (string) $_get[' passwd ']
); This is the same as executing the following MySQL statement, all injected


[PHP]

mysql_query ("SELECT * FROM Collection
WHERE username= "Admin",
and Passwd!=1

mysql_query ("SELECT * FROM Collection
WHERE username= "Admin",
and Passwd!=1
I did a demo test, and it worked.

http://www.bkjia.com/PHPjc/477615.html www.bkjia.com true http://www.bkjia.com/PHPjc/477615.html techarticle The following describes the next Php+mongodb injection method and principle of one of the post said: login.php?username=adminpasswd[$ne]=1 may inject, just look at the time, I feel very puzzled, 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.