mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
Fix MITM
This commit is contained in:
+12
-1
@@ -1,7 +1,18 @@
|
||||
// All intercepted domains + URL patterns per tool
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
const IS_DEV = process.env.NODE_ENV === "development";
|
||||
|
||||
// Resolve lsof absolute path — packaged apps / sudo secure_path may strip /usr/sbin from PATH
|
||||
const LSOF_BIN = (() => {
|
||||
if (process.platform === "win32") return null;
|
||||
for (const p of ["/usr/sbin/lsof", "/usr/bin/lsof", "/sbin/lsof"]) {
|
||||
try { fs.accessSync(p, fs.constants.X_OK); return p; } catch { /* try next */ }
|
||||
}
|
||||
return "lsof"; // last-resort fallback (depends on PATH)
|
||||
})();
|
||||
|
||||
const TARGET_HOSTS = [
|
||||
"daily-cloudcode-pa.googleapis.com",
|
||||
"cloudcode-pa.googleapis.com",
|
||||
@@ -53,4 +64,4 @@ function getToolForHost(host) {
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = { IS_DEV, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, LOG_BLACKLIST_URL_PARTS, getToolForHost };
|
||||
module.exports = { IS_DEV, LSOF_BIN, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, LOG_BLACKLIST_URL_PARTS, getToolForHost };
|
||||
|
||||
+3
-2
@@ -15,6 +15,7 @@ const { installCert, uninstallCert } = require("./cert/install");
|
||||
const { isCertExpired } = require("./cert/rootCA");
|
||||
const { DATA_DIR, MITM_DIR } = require("./paths");
|
||||
const { log, err } = require("./logger");
|
||||
const { LSOF_BIN } = require("./config");
|
||||
|
||||
const DEFAULT_MITM_ROUTER_BASE = "http://localhost:20128";
|
||||
|
||||
@@ -108,7 +109,7 @@ function getProcessUsingPort443() {
|
||||
if (processMatch) return processMatch[1].replace(".exe", "");
|
||||
}
|
||||
} else {
|
||||
const result = execSync("lsof -i :443", { encoding: "utf8", windowsHide: true });
|
||||
const result = execSync(`${LSOF_BIN} -i :443`, { encoding: "utf8", windowsHide: true });
|
||||
const lines = result.trim().split("\n");
|
||||
if (lines.length > 1) return lines[1].split(/\s+/)[0];
|
||||
}
|
||||
@@ -298,7 +299,7 @@ function getPort443Owner(sudoPassword) {
|
||||
});
|
||||
} else {
|
||||
// Only find process actually LISTENING on TCP port 443
|
||||
exec("lsof -nP -iTCP:443 -sTCP:LISTEN -t", { windowsHide: true }, (err, stdout) => {
|
||||
exec(`${LSOF_BIN} -nP -iTCP:443 -sTCP:LISTEN -t`, { windowsHide: true }, (err, stdout) => {
|
||||
if (err || !stdout?.trim()) return resolve(null);
|
||||
const pid = parseInt(stdout.trim().split("\n")[0], 10);
|
||||
if (!pid || isNaN(pid)) return resolve(null);
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ const dns = require("dns");
|
||||
const { promisify } = require("util");
|
||||
const { execSync } = require("child_process");
|
||||
const { log, err, dumpRequest, createResponseDumper, clearDumpDir } = require("./logger");
|
||||
const { IS_DEV, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, getToolForHost } = require("./config");
|
||||
const { IS_DEV, LSOF_BIN, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, getToolForHost } = require("./config");
|
||||
const { DATA_DIR, MITM_DIR } = require("./paths");
|
||||
const { getCertForDomain } = require("./cert/generate");
|
||||
const { getMitmAlias } = require("./dbReader");
|
||||
@@ -231,7 +231,7 @@ function killPort(port) {
|
||||
if (!out) return;
|
||||
pidList = out.split(/\r?\n/).map(s => s.trim()).filter(p => p && Number(p) !== process.pid && Number(p) > 4);
|
||||
} else {
|
||||
const out = execSync(`lsof -nP -iTCP:${port} -sTCP:LISTEN -t`, { encoding: "utf-8", windowsHide: true }).trim();
|
||||
const out = execSync(`${LSOF_BIN} -nP -iTCP:${port} -sTCP:LISTEN -t`, { encoding: "utf-8", windowsHide: true }).trim();
|
||||
if (!out) return;
|
||||
pidList = out.split("\n").filter(p => p && Number(p) !== process.pid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user