zoukankan      html  css  js  c++  java
  • Mongodb注入

    0x01 Brief Description

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

    0x02 Produce the vulnerability

    漏洞环境搭建:

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

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

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

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

    mongdb的配置见下图

     上图中可以看到mongodb默认是绑定到127.0.0.1,也就是说只允许本地访问,如果想要允许其它ip连接,只需要注释掉改行(不推荐,这样会导致未授权访问安全问题)。

    关于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

  • 相关阅读:
    韩式英语
    Daily dictation 听课笔记
    words with same pronunciation
    you will need to restart eclipse for the changes to take effect. would you like to restart now?
    glottal stop(britain fountain mountain)
    education 的发音
    第一次用Matlab 的lamada语句
    SVN的switch命令
    String的split
    SVN模型仓库中的资源从一个地方移动到另一个地方的办法(很久才解决)
  • 原文地址:https://www.cnblogs.com/mrchang/p/6255226.html
Copyright © 2011-2022 走看看