Time-Based Blind NoSQL Injection

 
http://packetstorm.wowhacker.com/papers/general/timebased-nosql.txt
Time-Based Blind NoSQL Injection - Detecting server-side JavaScript 
injection vulnerabilities

In July 2011, Bryan Sullivan, a senior security researcher at Adobe 
Systems, demonstrated server-side JavaScript injection vulnerabilities 
in web applications using MongoDB and other NoSQL database engines. He 
demonstrated how they could be used to perform Denial of Service, File 
System, Remote Command Execution, and many other attacks, including the 
easy extraction of the entire contents of the NoSQL database -- a blind 
NoSQL injection attack (paper here at 
https://media.blackhat.com/bh-us-11/Sullivan/BH_US_11_Sullivan_Server_Side_WP.pdf). 


We not only confirmed the published data about the NoSQL injection 
vulnerabilities, but also discovered that the MongoDB shell supports a 
sleep() function which makes time-based detection possible of vulnerable 
web applications.

It is also possible to inject a custom sleep code, a technique that may 
be used to spot injection vulnerabilities in web applications using 
server-side JavaScript execution. This is not restricted to MongoDB.

Below you can find two examples of NoSQL injection vulnerabilities in 
PHP that could be spotted using these techniques.

Example 1: NoSQL Injection Vulnerability in PHP

The following requests would make these (or similar) vulnerable web 
application sleep for 10 seconds:

vulnerable.php?msg=1';sleep(10000);var%20foo='bar

The MongoDB sleep() function works with milliseconds.

Alternative technique using a custom sleep code:

vulnerable.php?msg=1';var%20d%20=%20new%20Date();%20var%20cd%20=%20null;%20do%20{%20cd%20=%20new%20Date();%20}%20while(cd-d%20<%2010000);var%20foo='bar 


<?
$mongo = new Mongo();
$db = $mongo->demo;
$id = $_GET['id'];
$js = "function() {
var id = '$id';
SOME CODE...
}";
$response = $db->execute($js);
...
?>

Example 2: NoSQL Injection Vulnerability in PHP

<?
$mongo = new Mongo();
$db = $mongo->demo;
$year = $_GET['year'];
$collection = $db->demo;
$query = 'function() {var search_year = \'' .
$year . '\';' .
'return this.publicationYear == search_year || ' .
' this.filmingYear == search_year || ' .
' this.recordingYear == search_year;}';
$cursor = $collection->find(array('$where' => $query));
...
?>


Example 3: Sleep in JavaScript

var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < 10000); // delay time (ms)

Solution

Always validate user input used in server-side JavaScript commands.

Article by Felipe Aragon. Originally published at 
http://www.syhunt.com/?n=Articles.NoSQLInjection

---

Copyright � 2010 Syhunt Security

Disclaimer:
The information in this article is provided "as is" without
warranty of any kind. Details provided are strictly for
educational and defensive purposes.

Syhunt is not liable for any damages caused by direct or
indirect use of the information provided by this article.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值