프록시 설정에서 3128로 모두 처리하도록 하고(http, https 모두 3128 포트)
자동 생성된 인증서를 x509 타입으로 바꾸어서 윈도우에 믿을수 있는 root CA로 등록하면 해결 (HSTS 문제 우회)
$ cd ./.http-mitm-proxy/certs/ca.pem $ openssl x509 -outform der -in ca.pem -out der.pem |
아무튼 아래와 같이 하면.. 데이터는 어쩔수 없지만 HTML 등은 볼 수 있을 듯
var Proxy = require('http-mitm-proxy');
var proxy = Proxy();
var path = require('path');
proxy.use(Proxy.wildcard);
proxy.onError(function(ctx, err) {
console.error('proxy error:', err);
});
proxy.onRequest(function(ctx, callback) {
{
ctx.use(Proxy.gunzip);
console.log('');
console.log(ctx.clientToProxyRequest.headers.host);
console.log(ctx.clientToProxyRequest.url);
ctx.onResponseData(function(ctx, chunk, callback) {
// chunk = new Buffer(chunk.toString().replace(/<span.*?<\/span>/g, '<span>Pwned!</span>'));
return callback(null, chunk);
});
}
return callback();
});
proxy.onResponse(function(ctx, callback) {
return callback();
});
proxy.onResponseData(function(ctx, chunk, callback) {
console.log(chunk.length);
console.log(chunk.toString());
return callback(null, chunk);
});
proxy.onCertificateRequired = function(hostname, callback) {
return callback(null, {
keyFile: path.resolve('/ca/certs/', hostname + '.key'),
certFile: path.resolve('/ca/certs/', hostname + '.crt')
});
};
proxy.listen({port: 3128});
[링크 : https://www.npmjs.com/package/http-mitm-proxy]
+
var Proxy = require('http-mitm-proxy');
var proxy = Proxy();
var path = require('path');
var url = require('url');
var { URLSearchParams } = require('url');
var decode = require('urldecode')
proxy.use(Proxy.wildcard);
proxy.onError(function(ctx, err) {
console.error('proxy error:', err);
});
proxy.onRequest(function(ctx, callback) {
{
ctx.use(Proxy.gunzip);
console.log(ctx.clientToProxyRequest.headers.host);
var pback = ctx.clientToProxyRequest.url;
console.log(ctx.clientToProxyRequest.url);
var params = new URLSearchParams(url.parse(pback).query);
params.sort();
console.log(url.parse(pback).pathname + '?' + decode(params.toString()));
ctx.onResponseData(function(ctx, chunk, callback) {
// chunk = new Buffer(chunk.toString().replace(/<span.*?<\/span>/g, '<span>Pwned!</span>'));
return callback(null, chunk);
});
}
return callback();
});
proxy.onResponse(function(ctx, callback) {
return callback();
});
proxy.onResponseData(function(ctx, chunk, callback) {
return callback(null, chunk);
});
proxy.onCertificateRequired = function(hostname, callback) {
return callback(null, {
keyFile: path.resolve('/ca/certs/', hostname + '.key'),
certFile: path.resolve('/ca/certs/', hostname + '.crt')
});
};
proxy.listen({port: 3128});
[링크 : https://nodejs.org/docs/latest-v8.x/api/url.html]
'Programming > node.js' 카테고리의 다른 글
https cache proxy using node.js (0) | 2019.04.12 |
---|---|
node.js mkdir -p 옵션 사용하기 (0) | 2019.04.10 |
node.js 구버전 모듈에러 TypeError: path.existsSync is not a function (0) | 2019.04.05 |
node.js mitm proxy (for https) (0) | 2019.04.02 |
proxy http node.js (0) | 2019.04.01 |