Supports http/https traffic monitoring.
npm install pms-proxy
- Javascript
const {PPServerProxy} = require('pms-proxy');
- Typescript
import PPServerProxy from "pms-proxy";
const server = new PPServerProxy()
server.listen(1234).then(() => {
console('created!');
})
const forwardDst = 'wss://socketsbay.com/wss/v2/2/demo/';
server.getWebsocket()
.addRule()
.host('abc.com')
.then(new PPPassThroughWsHandler(forwardDst))
server.getWebsocket()
.addRule()
.url(/wss:\/\/hello\.com/)
.then(new PPPassThroughWsHandler(forwardDst))
Note: https only capture when provide CA cert, and install CA cert in machine
server.addRule()
.any()
.then(async (request, response) => {
console.log(request.method, request.url);
const passThrough = new PPPassThroughHttpHandler();
passThrough.injectBuffer((request, buffer) => {
console.log('--> response buffer size', buffer.length);
return { data: buffer };
})
await passThrough.handle(request, response);
})
const pass = new PPPassThroughHttpHandler();
pass.injectBuffer((req, buffer) => {
return {
data: buffer.toString() + "<script>alert('hello world!')</script>"
};
})
server.addRule()
.host(/abc\.com/g)
// or .host("abc.com")
// or .host((host) => host === "abc.com")
.then(pass);
server.addRule()
.any()
.then((req, res) => {
res.status(200).write('Hello world!');
})
/// app as express
const app = createAppHttpHandler();
app.get('/', (req, res) => {
res.status(200).send('oke');
})
server.addRule().host('test-fake.com').then(app);
const ws = server.getWebsocket();
ws.addRule()
.host('abc.com')
.then((req, ws) => {
ws.send('oke ws');
})
const inject = new PPPassThroughWsHandler();
inject.injectSend(data => data.toString() + ' inject!');
inject.injectReceive(data => data.toString() + ' inject!');
const ws = server.getWebsocket();
ws.addRule().host('abc.com').then(inject)
const server = new PPServerProxy({
https: {
certPath: path.join(__dirname, '../certs/rootCA.pem'),
keyPath: path.join(__dirname, '../certs/rootCA.key')
}
});
- create CA cert:
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 -out rootCA.pem
openssl pkcs12 -export -out rootCA.p12 -inkey rootCA.key -in rootCA.pem
- create monitor https & SPKI
const https = await PPCa.generateCACertificate();
const spki = PPCa.generateSPKIFingerprint((<PPCaFileOptions>https).cert);
const userData = path.join('C:/test-chrome');
const server = new PPServerProxy({https});
await server.listen(1234);
// node module
child_process.exec(
`start chrome --proxy-server="http://127.0.0.1:1234" --ignore-certificate-errors-spki-list=\"${spki}\" --user-data-dir=\"${userData}\"`
);