- Added Hermes tool to CLI tools and updated related components.

This commit is contained in:
decolua
2026-04-23 16:39:31 +07:00
parent ab7dd63b22
commit 368f4c3e7f
15 changed files with 821 additions and 38 deletions
+15 -5
View File
@@ -11,6 +11,7 @@ const { getCertForDomain } = require("./cert/generate");
const DB_FILE = path.join(DATA_DIR, "db.json");
const LOCAL_PORT = 443;
const IS_WIN = process.platform === "win32";
const ENABLE_FILE_LOG = false;
const LOG_DIR = path.join(DATA_DIR, "logs", "mitm");
const INTERNAL_REQUEST_HEADER = { name: "x-request-source", value: "local" };
@@ -222,16 +223,25 @@ const server = https.createServer(sslOptions, async (req, res) => {
// Kill only processes LISTENING on LOCAL_PORT (not outbound connections)
function killPort(port) {
try {
const pids = execSync(`lsof -nP -iTCP:${port} -sTCP:LISTEN -t`, { encoding: "utf-8", windowsHide: true }).trim();
if (!pids) return;
const pidList = pids.split("\n").filter(p => p && Number(p) !== process.pid);
let pidList = [];
if (IS_WIN) {
const psCmd = `powershell -NonInteractive -WindowStyle Hidden -Command ` +
`"Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess"`;
const out = execSync(psCmd, { encoding: "utf-8", windowsHide: true }).trim();
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();
if (!out) return;
pidList = out.split("\n").filter(p => p && Number(p) !== process.pid);
}
if (pidList.length === 0) return;
pidList.forEach(pid => {
try {
process.kill(Number(pid), "SIGKILL");
if (IS_WIN) execSync(`taskkill /F /PID ${pid}`, { windowsHide: true });
else process.kill(Number(pid), "SIGKILL");
} catch (e) {
err(`Failed to kill PID ${pid}: ${e.message}`);
throw e;
}
});
log(`Killed ${pidList.length} process(es) on port ${port}`);