Php mongodb Injection

Source: Internet
Author: User
Tags mongodb injection php mongodb

 


The following describes the php + mongodb injection methods and principles.

One of the posts said: login. php? Username = admin & passwd [$ ne] = 1 may be injected. At first glance, I was wondering how the injection vulnerability exists, finally refer from this post. Because PHP can directly submit an array, that is to say, it submits an array containing the "$ ne" index. I made a demo:


[Php]
$ Passwd = $ _ GET ["passwd"];
Var_dump ($ passwd );

$ Passwd = $ _ GET ["passwd"];
Var_dump ($ passwd );
Test results:

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

 


In this case


[Php]
$ Collection-> find (array (
"Username" => "admin ",
"Passwd" => array ("$ ne" => 1)
));

$ Collection-> find (array (
"Username" => "admin ",
"Passwd" => array ("$ ne" => 1)
));
To:


[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 type (username = [$ ne] = 1 & passwd [$ ne] = 1), all user information will be obtained.

The solution to this bug is to forcibly convert the parameters to the string type after obtaining them:

[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.


[Php]

Mysql_query ("SELECT * FROM collection
WHERE username = "admin ",
AND passwd! = 1

Mysql_query ("SELECT * FROM collection
WHERE username = "admin ",
AND passwd! = 1
I made a demo and tested it.

 

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.