From 8b54345bc142568e7d4c08b8177891b68d548759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Sat, 30 Mar 2024 00:56:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=B0=8F=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proxy/mitmproxy/createConnectHandler.js | 8 ++++---- .../proxy/mitmproxy/createRequestHandler.js | 2 +- packages/mitmproxy/src/utils/util.match.js | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js index 4c0158d..3849c1d 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js @@ -4,7 +4,7 @@ const log = require('../../../utils/util.log') const DnsUtil = require('../../dns/index') const localIP = '127.0.0.1' const defaultDns = require('dns') -const matchUtil = require('../../../utils/util.match') +// const matchUtil = require('../../../utils/util.match') const speedTest = require('../../speed/index.js') function isSslConnect (sslConnectInterceptors, req, cltSocket, head) { for (const intercept of sslConnectInterceptors) { @@ -31,7 +31,7 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar } console.log('sni config', sniConfig) - const sniRegexpMap = matchUtil.domainMapRegexply(sniConfig) + // const sniRegexpMap = matchUtil.domainMapRegexply(sniConfig) return function connectHandler (req, cltSocket, head) { // eslint-disable-next-line node/no-deprecated-api const srvUrl = url.parse(`https://${req.url}`) @@ -45,12 +45,12 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar }) } else { log.info('不拦截请求:', hostname) - connect(req, cltSocket, head, hostname, srvUrl.port, dnsConfig, sniRegexpMap) + connect(req, cltSocket, head, hostname, srvUrl.port, dnsConfig/*, sniRegexpMap */) } } } -function connect (req, cltSocket, head, hostname, port, dnsConfig, sniRegexpMap) { +function connect (req, cltSocket, head, hostname, port, dnsConfig/*, sniRegexpMap */) { // tunneling https // log.info('connect:', hostname, port) const start = new Date().getTime() diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js index 9559ec2..f03ff60 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js @@ -110,7 +110,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e function onFree () { const url = `${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}` const start = new Date().getTime() - log.info('代理请求:', url, rOptions.method) + log.info('代理请求:', url, rOptions.method, rOptions.servername ? ', sni: ' + rOptions.servername : '') let isDnsIntercept if (dnsConfig) { const dns = DnsUtil.hasDnsLookup(dnsConfig, rOptions.hostname) diff --git a/packages/mitmproxy/src/utils/util.match.js b/packages/mitmproxy/src/utils/util.match.js index b77e80c..8dd733d 100644 --- a/packages/mitmproxy/src/utils/util.match.js +++ b/packages/mitmproxy/src/utils/util.match.js @@ -106,14 +106,14 @@ function deleteNullItems (target) { } function matchHostnameAll (hostMap, hostname, action) { - // log.debug('matchHostnameAll:', action, hostMap) + // log.debug('matchHostname-all:', action, hostMap) if (hostMap == null) { - log.warn(`matchHostnameAll: ${action}: '${hostname}', hostMap is null`) + log.warn(`matchHostname-all: ${action}: '${hostname}', hostMap is null`) return null } if (hostMap.origin == null) { - log.warn(`matchHostnameAll: ${action}: '${hostname}', hostMap.origin is null`) + log.warn(`matchHostname-all: ${action}: '${hostname}', hostMap.origin is null`) return null } @@ -139,7 +139,7 @@ function matchHostnameAll (hostMap, hostname, action) { // 正则表达式匹配 if (hostname.match(regexp)) { value = hostMap[target] - log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) + log.info(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) values = merge(values, value) } } @@ -148,28 +148,28 @@ function matchHostnameAll (hostMap, hostname, action) { // 优先级:2 value = hostMap.origin['*' + hostname] if (value) { - log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) + log.info(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) } // 优先级:3 value = hostMap.origin['*.' + hostname] if (value) { - log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) + log.info(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) } // 优先级:4,最高(注:优先级高的配置,可以覆盖优先级低的配置,甚至有空配置时,可以移除已有配置) value = hostMap.origin[hostname] if (value) { - log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) + log.info(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) } if (!lodash.isEmpty(values)) { deleteNullItems(values) - log.info(`matchHostnameAll: ${action}: '${hostname}':`, JSON.stringify(values)) + log.info(`matchHostname-all: ${action}: '${hostname}':`, JSON.stringify(values)) return values } else { - log.debug(`matchHostnameAll: ${action}: '${hostname}' Not-Matched`) + log.debug(`matchHostname-all: ${action}: '${hostname}' Not-Matched`) } }