Mongodb注入

0x01 Brief Descriptionphp

做为nosql(not only sql)数据库的一种,mongodb很强大,不少企业也在用到。相对于sql数据库,nosql数据库有如下优势:简单便捷、方便拓展、更好的性能html

0x02 Produce the vulnerabilityvue

漏洞环境搭建:web

kali2.0搭建的环境apt-get install mongodb,注意最好用aliyun的源,以前用的中科大的源,没有找到下载。sql

安装完成以后开启服务,见下图:mongodb

环境的搭建原型来自这里:数据库

http://bobao.360.cn/learning/detail/2839.html安全

mongdb的配置见下图nosql

 上图中能够看到mongodb默认是绑定到127.0.0.1,也就是说只容许本地访问,若是想要容许其它ip链接,只须要注释掉改行(不推荐,这样会致使未受权访问安全问题)。ide

关于mongodb开启认证以及建立角色的相关内容能够参考慕课网上的视频Mongodb安全

服务的开启

service mongodb start

查看数据库

show  dbs

查看集合

show collections

查看集合中的元素

db.collectionname.find()

数据的CURD就不细述了,最终的数据以下图所示:

GUI链接推荐使用mongovue,显示比较友好。

web端代码(记得安装mongodb模块 apt-get install php5-mongo)

 1 <?php
 2 echo "param is id :)";
 3 if(!empty($_GET['id']))
 4 {
 5     $m = new MongoClient();
 6     $id = $_GET['id'];
 7     if ($id=="1")
 8     {
 9         echo "You Can't access Admin's Account";
10     }
11     else
12     {
13         $db = $m->securitytest;
14         $collection = $db->users;
15         $qry = array("id"=> $_GET['id']);
16         $cursor = $collection->find($qry);
17         foreach($cursor as $document)
18         {
19             echo "<br>";
20             echo "Username:".$document["username"]."<br>";
21             echo "Password:".$document["password"]."<br>";
22             echo "<br>";
23 
24         }
25         
26     }
27 
28 }

题解:

打开页面以下图所示,知道这里的参数是id

这个时候输入参数id=1,提示不容许访问

输入参数id=3 显示以下:

而后咱们知道mongodb有这样一个关键字 ne 就是not equal的意思

Syntax: {field: {$ne: value} }
$ne selects the documents where the value of the field is not equal (i.e. !=) to the specified value. This includes documents that do not contain the field.

 like this

 就是查询到了id不为1的数据

那在这里呢,咱们就能够这样构造进行注入:

http://192.168.247.132/inj.php?id[$ne]=2

Flag get!

固然还能够继续爆出collections和dbs,可参考这里:https://www.secpulse.com/archives/3278.html

此外还应该注意nosql数据库的未受权访问的问题,常见的nosql数据库及端口

 0x03 Reference

相关学习视频:

http://www.imooc.com/video/5933

mongodb的中文文档:

http://docs.mongoing.com/manual-zh/

black nosql injection 视频后半部分

https://www.youtube.com/watch?v=ZYiTLZGK4AQ