Programming/node.js2019. 4. 8. 14:28

프록시 설정에서 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]

[링크 : https://www.npmjs.com/package/urldecode]

[링크 : https://opentutorials.org/module/938/7369]

Posted by 구차니