Skip to content

Instantly share code, notes, and snippets.


vdeturckheim/injector_full.js Secret

Created Jan 21, 2021
What would you like to do?
'use strict';
const CDP = require('chrome-remote-interface');
const main = async function () {
const client = await CDP({
port: 9229
await client.Runtime.enable();
const ServerPrototypeResult = await client.Runtime.evaluate({expression:"require('http').Server.prototype", includeCommandLineAPI: true, returnByValue: false});
const ServerInstanceListResult = await client.Runtime.queryObjects({ prototypeObjectId: ServerPrototypeResult.result.objectId });
const ServerInstancesResult = await client.Runtime.getProperties({ objectId: ServerInstanceListResult.objects.objectId });
const serverInstance = ServerInstancesResult.result[0].value.objectId;
await client.Runtime.evaluate({expression:"process.patchListeners = require(`./toInject.js`).patchListeners", includeCommandLineAPI: true, returnByValue: false});
// in the injected function, the value for `this` will be the instance of the server
await client.Runtime.callFunctionOn({ objectId: serverInstance, functionDeclaration: 'function() { process.patchListeners(this) }', returnByValue: true });
await client.Runtime.evaluate({expression:"delete process.patchListeners", includeCommandLineAPI: true, returnByValue: false});
await client.Runtime.evaluate({"expression":"require('inspector').close()","includeCommandLineAPI":true});
await client.close();
main(); // on Node 15, an error will stop the process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment