Home  >  Article  >  Backend Development  >  php mongodb injection_PHP tutorial

php mongodb injection_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:09:42833browse


The following will introduce the methods and principles of php+mongodb injection

One of the posts said: login.php?username=admin&passwd[$ne]=1 may be injected. When I first read it, I felt quite puzzled. How could this have an injection vulnerability? Finally, from this The reason was found in this post http://hi.baidu.com/hi_heige/item/ce93ce926dede4f428164747. Because PHP can directly submit arrays, which means that the arrays containing the "$ne" index are submitted, 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" }


In this case


[php]
$collection->find(array(
"username" => "admin",
"passwd" => array("$ne" => 1)
));

$collection->find(array(
"username" => "admin",
"passwd" => array("$ne" => 1)
));
It becomes:


[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 user information will be obtained

The way to solve this bug is to force the parameters into string type after obtaining the parameters:

[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, both of which are injected with


[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 to test it, and it really works.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477615.htmlTechArticleThe following will introduce the method and principle of php+mongodb injection. One of the posts said: login.php?username= It is possible to inject adminpasswd[$ne]=1. When I first saw it, I felt quite puzzled. This...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn