Syhunt: Google V8 - Server-Side JS Injection in vulnerable web apps

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介: http://seclists.org/fulldisclosure/2012/Feb/409Google V8 Server-Side JavaScript Injection joi...
http://seclists.org/fulldisclosure/2012/Feb/409
Google V8 Server-Side JavaScript Injection joins the set of web 
application security vulnerabilities

TIME-BASED PHP V8JS INJECTION & NOSQL/SSJS INJECTION

Detecting server-side JavaScript (SSJS) injection vulnerabilities using 
time-based techniques. Article by Felipe Aragon - February 25, 2012

This article, which is an update of an article that we originally 
published on December 18, 2011, intends to highlight the risk of 
unvalidated input used to execute server-side JavaScript.

As you read this, web developers are starting to learn how to use V8Js 
(Google's V8 JavaScript engine) in PHP:
http://www.php.net/manual/en/v8js.examples.php
http://stackoverflow.com/questions/9035567/why-is-a-function-re-definition-faster-than-calling-the-first-one

...or MongoDB, which is a scalable, high-performance, open source NoSQL 
database that also allows JavaScript to be used in queries:
http://www.mongodb.org/

Today, the most common source of PHP security flaws is unvalidated 
input. They give rise to SQL Injection, XSS, Remote Command Execution, 
Local and Remote File Inclusion, etc (known as the PHP Top 5 
https://www.owasp.org/index.php/PHP_Top_5). With the rising adoption of 
server-side JavaScript, we can expect server-side JS injection 
vulnerabilities caused by unvalidated user input to become prevalent, 
and the techniques for exploiting them, commonplace. At Syhunt, we 
already started our own collection of techniques for detecting 
server-side JS injection vulnerabilities. We want to proactively detect 
them before they are exploited.

The Time-Based JS Injection Technique
**********************************************

Injecting a custom sleep code is a technique that may be used to spot 
injection vulnerabilities in web applications using server-side 
JavaScript execution. This works with any web system that supports 
server-side JavaScript execution, such as JavaScript web application 
frameworks and servers like Jaxer (http://jaxer.org/), or PHP with V8Js, 
or NoSQL engines like MongoDB.

Below you can find examples of server-side JavaScript injection 
vulnerabilities in PHP that could be spotted using the sleep technique. 
In the past, we used this same sleep code in the client-side to 
demonstrate how vulnerabilities we found in the A-A-S (Application 
Access Server) could be exploited 
(http://www.syhunt.com/?n=Advisories.Aas-multiple).

Example 1: PHP V8JS Injection Vulnerabilities (PHP + V8Js)
*************

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

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


Vulnerable Code:

$msg = $_GET['msg'];
$v8 = new V8Js();
$v8->executeString("var msg = '$msg'; ..SOME CODE..");


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


Vulnerable Code:

$msg = $_GET['msg'];
$v8 = new V8Js();
$JS = <<< EOT
len = print($msg + "\\n");
..SOME CODE..
EOT;

$v8->executeString($JS, 'basic.js');

Example 2: NoSQL SSJS Injection Vulnerability (PHP + MongoDB)
*************

The MongoDB shell provides a sleep() function (see 
http://api.mongodb.org/js/current/symbols/src/shell_utils.js.html) which 
makes time-based detection much easier to perform.

The following requests would make these (or similar) vulnerable web 
applications 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';d=new%20Date();do{cd=new%20Date();}while(cd-d<10000);foo='bar 


Vulnerable Code:

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

Example 3: NoSQL SSJS Injection Vulnerability (PHP + MongoDB)
*************

Vulnerable Code:

<?
$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 4: SSJS Injection Vulnerability (PHP + Jaxer)
*************

Example of a vulnerable application built using the Jaxer Ajax server 
and PHP.

Vulnerable Code:

<?php
$myVar = $_GET['id'];

echo "<script runat=server>
     myPHPVar = '$myVar';
     onload = function(){
     ..SOME CODE..
     };
</script>";
?>


Example 5: Sleep in JavaScript
*************

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

Additional Information

The advent of Big Data and Cloud Computing is driving adoption of NoSQL 
in the enterprise. Because of this, NoSQL-related vulnerabilities are 
expected to become much more widespread 
(http://www.govtech.com/policy-management/9-Cybersecurity-Threat-Predictions-for-2012.html)

In July last year, 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 available at
https://media.blackhat.com/bh-us-11/Sullivan/BH_US_11_Sullivan_Server_Side_WP.pdf).

Solution

Always validate user input used in server-side JavaScript commands.
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
2月前
|
JavaScript 前端开发
Google Earth Engine(GEE)扩展——ee-polyfill JavaScript 方法 (ES6+)
Google Earth Engine(GEE)扩展——ee-polyfill JavaScript 方法 (ES6+)
16 1
|
3月前
|
前端开发 JavaScript 开发者
Web前端开发中的JavaScript闭包应用
JavaScript闭包是Web前端开发中常见的概念,它可以帮助开发者解决作用域问题,提高代码的可读性和可维护性。本文将介绍JavaScript闭包的基本概念和应用,以及如何在Web前端开发中使用闭包。
29 3
|
8天前
|
JavaScript 前端开发 API
Vue.js:构建高效且灵活的Web应用的利器
Vue.js:构建高效且灵活的Web应用的利器
|
1月前
|
运维 JavaScript 前端开发
发现了一款宝藏学习项目,包含了Web全栈的知识体系,JS、Vue、React知识就靠它了!
发现了一款宝藏学习项目,包含了Web全栈的知识体系,JS、Vue、React知识就靠它了!
|
1月前
|
JavaScript 前端开发 API
Vue.js:构建现代化Web应用的灵活选择
Vue.js:构建现代化Web应用的灵活选择
37 0
|
2月前
|
JavaScript 前端开发 Java
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 以及 Ext JS。
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 和 Ext JS 都是 JavaScript 框架,用于开发 Web 应用程序。它们分别提供了不同的功能和特性,以帮助开发者更高效地构建和维护 Web 应用程序。
17 2
|
2月前
|
Web App开发 JavaScript 前端开发
构建现代Web应用:Vue.js与Node.js的完美结合
在当今快速发展的Web技术领域,选择合适的技术栈对于开发高效、响应迅速的现代Web应用至关重要。本文深入探讨了Vue.js和Node.js结合使用的优势,以及如何利用这两种技术构建一个完整的前后端分离的Web应用。不同于传统的摘要,我们将通过一个实际的项目示例,展示从搭建项目架构到实现具体功能的整个过程,着重介绍了Vue.js在构建用户友好的界面方面的能力,以及Node.js在处理服务器端逻辑和数据库交互中的高效性。通过本文,读者不仅能够理解Vue.js与Node.js各自的特点,还能学习到如何将这两种技术融合应用,以提升Web应用的开发效率和用户体验。
|
3月前
|
前端开发 JavaScript 定位技术
web版拳皇,使用html,css,js来制作一款拳皇游戏
web版拳皇,使用html,css,js来制作一款拳皇游戏
35 0
|
3月前
|
开发框架 JavaScript 前端开发
React.js:改变Web开发方式的JavaScript库
React.js:改变Web开发方式的JavaScript库
36 1
|
4月前
|
JavaScript 前端开发 中间件
Node.js Web 模块的各种用法和常见场景
Node.js Web 模块的各种用法和常见场景
28 1