@profullstack/threatcrush 0.15.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/av-worker.js +318 -1
- package/dist/av-worker.js.map +1 -1
- package/dist/daemon.js +907 -136
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +1343 -360
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -7972,11 +7972,11 @@ function drawSelect(surface, options) {
|
|
|
7972
7972
|
});
|
|
7973
7973
|
surface.text(width - 2, 0, options.open ? " \u25B4" : " \u25BE", { fg: color, bg: elevate(theme, 0.05) });
|
|
7974
7974
|
if (options.open && options.options?.length) {
|
|
7975
|
-
const
|
|
7976
|
-
const height = Math.min(
|
|
7975
|
+
const list3 = options.options;
|
|
7976
|
+
const height = Math.min(list3.length, surface.height - 1);
|
|
7977
7977
|
for (let i = 0; i < height; i++) {
|
|
7978
7978
|
const selected = i === (options.selectedIndex ?? 0);
|
|
7979
|
-
surface.text(0, i + 1, fit(` ${truncate(
|
|
7979
|
+
surface.text(0, i + 1, fit(` ${truncate(list3[i], width - 2)}`, width), {
|
|
7980
7980
|
fg: selected ? theme.selectionText : theme.foreground,
|
|
7981
7981
|
bg: selected ? theme.selection : elevate(theme, 0.08)
|
|
7982
7982
|
});
|
|
@@ -18276,7 +18276,7 @@ function isPublicAddress(ip) {
|
|
|
18276
18276
|
if (v === 6) return !/^(::1?$|f[cd]|fe[89ab]|ff)/i.test(ip);
|
|
18277
18277
|
return false;
|
|
18278
18278
|
}
|
|
18279
|
-
function localMapData(state, geo,
|
|
18279
|
+
function localMapData(state, geo, hostname8, now = Date.now()) {
|
|
18280
18280
|
const by = /* @__PURE__ */ new Map();
|
|
18281
18281
|
for (const e of state.events) {
|
|
18282
18282
|
const ip = e.source_ip;
|
|
@@ -18300,7 +18300,7 @@ function localMapData(state, geo, hostname7, now = Date.now()) {
|
|
|
18300
18300
|
const o = by.get(t.ip);
|
|
18301
18301
|
if (o) o.count = Math.max(o.count, t.count);
|
|
18302
18302
|
}
|
|
18303
|
-
const servers = geo.self ? [{ id: "self", name:
|
|
18303
|
+
const servers = geo.self ? [{ id: "self", name: hostname8, ...geo.self, online: state.connection === "live" }] : [];
|
|
18304
18304
|
return { servers, origins: [...by.values()], windowMinutes: 0, generatedAt: new Date(now).toISOString() };
|
|
18305
18305
|
}
|
|
18306
18306
|
function sourceAddresses(state) {
|
|
@@ -25807,15 +25807,15 @@ var require_parser2 = __commonJS({
|
|
|
25807
25807
|
var node_process = require("process");
|
|
25808
25808
|
var cst = require_cst();
|
|
25809
25809
|
var lexer = require_lexer();
|
|
25810
|
-
function includesToken(
|
|
25811
|
-
for (let i = 0; i <
|
|
25812
|
-
if (
|
|
25810
|
+
function includesToken(list3, type) {
|
|
25811
|
+
for (let i = 0; i < list3.length; ++i)
|
|
25812
|
+
if (list3[i].type === type)
|
|
25813
25813
|
return true;
|
|
25814
25814
|
return false;
|
|
25815
25815
|
}
|
|
25816
|
-
function findNonEmptyIndex(
|
|
25817
|
-
for (let i = 0; i <
|
|
25818
|
-
switch (
|
|
25816
|
+
function findNonEmptyIndex(list3) {
|
|
25817
|
+
for (let i = 0; i < list3.length; ++i) {
|
|
25818
|
+
switch (list3[i].type) {
|
|
25819
25819
|
case "space":
|
|
25820
25820
|
case "comment":
|
|
25821
25821
|
case "newline":
|
|
@@ -27066,9 +27066,9 @@ async function startActionCenter() {
|
|
|
27066
27066
|
row.text(error2 || warning2 || "Fleet detections, server health, and queued actions", { fg: error2 ? severityColors.high : theme.muted, size: "fill" });
|
|
27067
27067
|
});
|
|
27068
27068
|
});
|
|
27069
|
-
const
|
|
27070
|
-
selected = Math.min(selected, Math.max(0,
|
|
27071
|
-
const selectedDetection =
|
|
27069
|
+
const list3 = filtered();
|
|
27070
|
+
selected = Math.min(selected, Math.max(0, list3.length - 1));
|
|
27071
|
+
const selectedDetection = list3[selected];
|
|
27072
27072
|
const serverMap = serverById();
|
|
27073
27073
|
const online = data.servers.filter((server) => server.connection === "online").length;
|
|
27074
27074
|
const pending = data.actions.length;
|
|
@@ -27076,7 +27076,7 @@ async function startActionCenter() {
|
|
|
27076
27076
|
summary(row, theme, "SERVERS ONLINE", `${online}/${data.servers.length}`, theme.success);
|
|
27077
27077
|
summary(row, theme, "DETECTIONS", String(data.detections.length), severityColors.high);
|
|
27078
27078
|
summary(row, theme, "QUEUED ACTIONS", String(pending), theme.warning);
|
|
27079
|
-
summary(row, theme, "FILTERED EVENTS", String(
|
|
27079
|
+
summary(row, theme, "FILTERED EVENTS", String(list3.length), theme.accent);
|
|
27080
27080
|
});
|
|
27081
27081
|
ui.row({ size: 1 }, (row) => {
|
|
27082
27082
|
const selectedHost = serverMap.get(serverId);
|
|
@@ -27090,12 +27090,12 @@ async function startActionCenter() {
|
|
|
27090
27090
|
panel.label("Loading detections\u2026", { fg: theme.muted });
|
|
27091
27091
|
return;
|
|
27092
27092
|
}
|
|
27093
|
-
if (
|
|
27093
|
+
if (list3.length === 0) {
|
|
27094
27094
|
panel.label(error2 ? "Sign in and refresh to load fleet activity." : "No detections match these filters.", { fg: theme.muted });
|
|
27095
27095
|
return;
|
|
27096
27096
|
}
|
|
27097
27097
|
panel.table({
|
|
27098
|
-
rows:
|
|
27098
|
+
rows: list3,
|
|
27099
27099
|
header: true,
|
|
27100
27100
|
selected,
|
|
27101
27101
|
followSelection: true,
|
|
@@ -31116,10 +31116,10 @@ var source_default = chalk;
|
|
|
31116
31116
|
|
|
31117
31117
|
// src/index.ts
|
|
31118
31118
|
var import_readline = __toESM(require("readline"));
|
|
31119
|
-
var
|
|
31120
|
-
var
|
|
31121
|
-
var
|
|
31122
|
-
var
|
|
31119
|
+
var import_node_child_process37 = require("child_process");
|
|
31120
|
+
var import_node_fs87 = require("fs");
|
|
31121
|
+
var import_node_path62 = require("path");
|
|
31122
|
+
var import_node_os27 = require("os");
|
|
31123
31123
|
|
|
31124
31124
|
// src/commands/monitor.ts
|
|
31125
31125
|
var import_node_fs11 = require("fs");
|
|
@@ -37829,9 +37829,9 @@ var CrsEngine = class {
|
|
|
37829
37829
|
continue;
|
|
37830
37830
|
}
|
|
37831
37831
|
for (const target of compiled.rule.targets) {
|
|
37832
|
-
const
|
|
37833
|
-
|
|
37834
|
-
this.byTarget.set(target,
|
|
37832
|
+
const list3 = this.byTarget.get(target) ?? [];
|
|
37833
|
+
list3.push(compiled);
|
|
37834
|
+
this.byTarget.set(target, list3);
|
|
37835
37835
|
}
|
|
37836
37836
|
}
|
|
37837
37837
|
}
|
|
@@ -38179,6 +38179,7 @@ function parseConfigText(raw) {
|
|
|
38179
38179
|
docker_logs: parsed.docker_logs,
|
|
38180
38180
|
postgres_shell: parsed.postgres_shell,
|
|
38181
38181
|
login_watch: parsed.login_watch,
|
|
38182
|
+
ssh_context: parsed.ssh_context,
|
|
38182
38183
|
storage: parsed.storage,
|
|
38183
38184
|
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
38184
38185
|
// the JS-friendly name the rest of the daemon reads.
|
|
@@ -39756,15 +39757,15 @@ var Emitter = class {
|
|
|
39756
39757
|
this.listeners[ev].push(fn);
|
|
39757
39758
|
}
|
|
39758
39759
|
removeListener(ev, fn) {
|
|
39759
|
-
const
|
|
39760
|
-
const i =
|
|
39760
|
+
const list3 = this.listeners[ev];
|
|
39761
|
+
const i = list3.indexOf(fn);
|
|
39761
39762
|
if (i === -1) {
|
|
39762
39763
|
return;
|
|
39763
39764
|
}
|
|
39764
|
-
if (i === 0 &&
|
|
39765
|
-
|
|
39765
|
+
if (i === 0 && list3.length === 1) {
|
|
39766
|
+
list3.length = 0;
|
|
39766
39767
|
} else {
|
|
39767
|
-
|
|
39768
|
+
list3.splice(i, 1);
|
|
39768
39769
|
}
|
|
39769
39770
|
}
|
|
39770
39771
|
emit(ev, code, signal) {
|
|
@@ -45464,7 +45465,7 @@ function parseAuthorizedKeyLines(text) {
|
|
|
45464
45465
|
text.split("\n").forEach((raw, idx) => {
|
|
45465
45466
|
const line2 = raw.replace(/\r$/, "").trim();
|
|
45466
45467
|
if (!line2 || line2.startsWith("#")) return;
|
|
45467
|
-
let
|
|
45468
|
+
let optionText2 = "";
|
|
45468
45469
|
let rest = line2;
|
|
45469
45470
|
if (!KEY_TYPE.test(line2.split(/\s+/, 1)[0] ?? "")) {
|
|
45470
45471
|
let inQuote = false;
|
|
@@ -45482,13 +45483,13 @@ function parseAuthorizedKeyLines(text) {
|
|
|
45482
45483
|
}
|
|
45483
45484
|
}
|
|
45484
45485
|
if (cut === -1) return;
|
|
45485
|
-
|
|
45486
|
+
optionText2 = line2.slice(0, cut);
|
|
45486
45487
|
rest = line2.slice(cut).trimStart();
|
|
45487
45488
|
}
|
|
45488
45489
|
const parts = rest.split(/\s+/);
|
|
45489
45490
|
if (!KEY_TYPE.test(parts[0] ?? "") || !parts[1]) return;
|
|
45490
45491
|
const options = /* @__PURE__ */ new Map();
|
|
45491
|
-
for (const m of
|
|
45492
|
+
for (const m of optionText2.matchAll(/([A-Za-z-]+)(?:="((?:[^"\\]|\\.)*)")?/g)) {
|
|
45492
45493
|
options.set(m[1].toLowerCase(), m[2] ?? null);
|
|
45493
45494
|
}
|
|
45494
45495
|
out.push({ line: idx + 1, type: parts[0], comment: parts.slice(2).join(" "), options });
|
|
@@ -48199,19 +48200,19 @@ function parseAuthorizedKeys(text, file = "authorized_keys") {
|
|
|
48199
48200
|
text.split("\n").forEach((raw, idx) => {
|
|
48200
48201
|
const line2 = raw.replace(/\r$/, "").trim();
|
|
48201
48202
|
if (!line2 || line2.startsWith("#")) return;
|
|
48202
|
-
let
|
|
48203
|
+
let optionText2 = "";
|
|
48203
48204
|
let rest = line2;
|
|
48204
48205
|
const first = line2.split(/\s+/, 1)[0];
|
|
48205
48206
|
if (!KEY_TYPE2.test(first)) {
|
|
48206
48207
|
const split = splitOptionsPrefix(line2);
|
|
48207
|
-
|
|
48208
|
+
optionText2 = split.options;
|
|
48208
48209
|
rest = split.rest;
|
|
48209
48210
|
}
|
|
48210
48211
|
const parts = rest.split(/\s+/);
|
|
48211
48212
|
const type = parts[0] ?? "";
|
|
48212
48213
|
const blob = parts[1] ?? "";
|
|
48213
48214
|
if (!KEY_TYPE2.test(type) || !blob) return;
|
|
48214
|
-
const options =
|
|
48215
|
+
const options = optionText2 ? parseOptionList(optionText2) : [];
|
|
48215
48216
|
const get2 = (n) => options.find((o) => o.name === n)?.value ?? null;
|
|
48216
48217
|
keys.push({
|
|
48217
48218
|
file,
|
|
@@ -48303,9 +48304,9 @@ function parseSshdT(text) {
|
|
|
48303
48304
|
const m = /^(\S+)\s+(.*)$/.exec(line2);
|
|
48304
48305
|
if (!m) continue;
|
|
48305
48306
|
const key = m[1].toLowerCase();
|
|
48306
|
-
const
|
|
48307
|
-
|
|
48308
|
-
out.set(key,
|
|
48307
|
+
const list3 = out.get(key) ?? [];
|
|
48308
|
+
list3.push(m[2]);
|
|
48309
|
+
out.set(key, list3);
|
|
48309
48310
|
}
|
|
48310
48311
|
return out;
|
|
48311
48312
|
}
|
|
@@ -48355,15 +48356,15 @@ function parseProcModules(text) {
|
|
|
48355
48356
|
}
|
|
48356
48357
|
var RISKY_SOURCES = /* @__PURE__ */ new Set(["/", "/var/run/docker.sock", "/run/docker.sock"]);
|
|
48357
48358
|
function judgeDockerInspect(json2) {
|
|
48358
|
-
let
|
|
48359
|
+
let list3;
|
|
48359
48360
|
try {
|
|
48360
|
-
|
|
48361
|
+
list3 = JSON.parse(json2);
|
|
48361
48362
|
} catch {
|
|
48362
48363
|
return [];
|
|
48363
48364
|
}
|
|
48364
|
-
if (!Array.isArray(
|
|
48365
|
+
if (!Array.isArray(list3)) return [];
|
|
48365
48366
|
const out = [];
|
|
48366
|
-
for (const c of
|
|
48367
|
+
for (const c of list3) {
|
|
48367
48368
|
const reasons = [];
|
|
48368
48369
|
const hc = c.HostConfig ?? {};
|
|
48369
48370
|
if (hc.Privileged === true) reasons.push("--privileged");
|
|
@@ -48527,14 +48528,14 @@ function hexToV6(h) {
|
|
|
48527
48528
|
}
|
|
48528
48529
|
return full;
|
|
48529
48530
|
}
|
|
48530
|
-
function parseProcNetTcp(text,
|
|
48531
|
+
function parseProcNetTcp(text, family2) {
|
|
48531
48532
|
const out = [];
|
|
48532
48533
|
for (const line2 of text.split("\n").slice(1)) {
|
|
48533
48534
|
const f = line2.trim().split(/\s+/);
|
|
48534
48535
|
if (f.length < 10 || f[3] !== "0A") continue;
|
|
48535
48536
|
const [hexAddr, hexPort] = f[1].split(":");
|
|
48536
|
-
const addr =
|
|
48537
|
-
out.push({ addr, port: parseInt(hexPort, 16), family, inode: f[9] });
|
|
48537
|
+
const addr = family2 === 4 ? hexToV4(hexAddr) : hexToV6(hexAddr);
|
|
48538
|
+
out.push({ addr, port: parseInt(hexPort, 16), family: family2, inode: f[9] });
|
|
48538
48539
|
}
|
|
48539
48540
|
return out;
|
|
48540
48541
|
}
|
|
@@ -48562,7 +48563,7 @@ function classifyExposures(listeners, mappings, opts) {
|
|
|
48562
48563
|
const sensitive = [];
|
|
48563
48564
|
const seen = /* @__PURE__ */ new Set();
|
|
48564
48565
|
let publicCount = 0;
|
|
48565
|
-
const reachable = (addr,
|
|
48566
|
+
const reachable = (addr, family2) => !isLoopback(addr) && !isPrivate(addr) && (family2 === 4 || opts.hasGlobalV6);
|
|
48566
48567
|
const add = (e) => {
|
|
48567
48568
|
const key = `${e.kind}|${e.family}|${e.hostPort}`;
|
|
48568
48569
|
if (seen.has(key)) return;
|
|
@@ -48580,17 +48581,17 @@ function classifyExposures(listeners, mappings, opts) {
|
|
|
48580
48581
|
add({ kind: "docker", addr: m.hostIp, family: m.family, hostPort: m.hostPort, containerPort: m.containerPort, container: m.container, service });
|
|
48581
48582
|
}
|
|
48582
48583
|
for (const l of listeners) {
|
|
48583
|
-
for (const
|
|
48584
|
-
if (!reachable(l.addr,
|
|
48584
|
+
for (const family2 of l.family === 46 ? [4, 6] : [l.family]) {
|
|
48585
|
+
if (!reachable(l.addr, family2)) continue;
|
|
48585
48586
|
if (l.process === "docker-proxy" && opts.dockerKnown) continue;
|
|
48586
|
-
if (dockerHostPorts.has(`${
|
|
48587
|
+
if (dockerHostPorts.has(`${family2}|${l.port}`)) continue;
|
|
48587
48588
|
publicCount++;
|
|
48588
48589
|
const service = sensitiveService(l.port);
|
|
48589
48590
|
if (!service) continue;
|
|
48590
48591
|
if (l.process === "docker-proxy") {
|
|
48591
|
-
add({ kind: "docker", addr: l.addr, family, hostPort: l.port, process: l.process, pid: l.pid, service });
|
|
48592
|
+
add({ kind: "docker", addr: l.addr, family: family2, hostPort: l.port, process: l.process, pid: l.pid, service });
|
|
48592
48593
|
} else {
|
|
48593
|
-
add({ kind: "host", addr: l.addr, family, hostPort: l.port, process: l.process, pid: l.pid, service });
|
|
48594
|
+
add({ kind: "host", addr: l.addr, family: family2, hostPort: l.port, process: l.process, pid: l.pid, service });
|
|
48594
48595
|
}
|
|
48595
48596
|
}
|
|
48596
48597
|
}
|
|
@@ -48743,11 +48744,11 @@ function ufwToMatches(to, port) {
|
|
|
48743
48744
|
if (m[2] === "udp") return false;
|
|
48744
48745
|
return inRange(port, parsePorts(m[1]));
|
|
48745
48746
|
}
|
|
48746
|
-
function evaluateUfw(status, port,
|
|
48747
|
+
function evaluateUfw(status, port, family2) {
|
|
48747
48748
|
if (!status.active) return { verdict: "unknown", by: "ufw inactive" };
|
|
48748
48749
|
const allowlisted = [];
|
|
48749
48750
|
for (const r of status.rules) {
|
|
48750
|
-
if (r.v6 !== (
|
|
48751
|
+
if (r.v6 !== (family2 === 6)) continue;
|
|
48751
48752
|
if (/\bFWD\b|\bOUT\b/.test(r.action)) continue;
|
|
48752
48753
|
if (!ufwToMatches(r.to, port)) continue;
|
|
48753
48754
|
const anywhere = /^Anywhere/i.test(r.from);
|
|
@@ -48763,20 +48764,20 @@ function evaluateUfw(status, port, family) {
|
|
|
48763
48764
|
}
|
|
48764
48765
|
function parseNftInputChains(text) {
|
|
48765
48766
|
const out = [];
|
|
48766
|
-
let
|
|
48767
|
+
let family2 = "";
|
|
48767
48768
|
let table2 = "";
|
|
48768
48769
|
let cur = null;
|
|
48769
48770
|
for (const raw of text.split("\n")) {
|
|
48770
48771
|
const line2 = raw.trim();
|
|
48771
48772
|
const t = /^table\s+(\S+)\s+(\S+)\s*\{/.exec(line2);
|
|
48772
48773
|
if (t) {
|
|
48773
|
-
|
|
48774
|
+
family2 = t[1];
|
|
48774
48775
|
table2 = t[2];
|
|
48775
48776
|
continue;
|
|
48776
48777
|
}
|
|
48777
48778
|
const c = /^chain\s+(\S+)\s*\{/.exec(line2);
|
|
48778
48779
|
if (c) {
|
|
48779
|
-
cur = { family, table: table2, name: c[1], hook: "", policy: "accept", rules: [] };
|
|
48780
|
+
cur = { family: family2, table: table2, name: c[1], hook: "", policy: "accept", rules: [] };
|
|
48780
48781
|
continue;
|
|
48781
48782
|
}
|
|
48782
48783
|
if (!cur) continue;
|
|
@@ -48801,8 +48802,8 @@ function nftPortSet(spec) {
|
|
|
48801
48802
|
return [Number(a), Number(b ?? a)];
|
|
48802
48803
|
}).filter(([a, b]) => Number.isFinite(a) && Number.isFinite(b));
|
|
48803
48804
|
}
|
|
48804
|
-
function evaluateNftChain(chain, port,
|
|
48805
|
-
if (chain.family === "ip" &&
|
|
48805
|
+
function evaluateNftChain(chain, port, family2) {
|
|
48806
|
+
if (chain.family === "ip" && family2 === 6 || chain.family === "ip6" && family2 === 4) return { verdict: "unknown", by: "other family" };
|
|
48806
48807
|
const label = `nft ${chain.family} ${chain.table} ${chain.name}`;
|
|
48807
48808
|
for (const rule of chain.rules) {
|
|
48808
48809
|
const verdict = /\b(accept|drop|reject)\b\s*(?:with .*)?$/.exec(rule)?.[1];
|
|
@@ -49019,12 +49020,12 @@ function checkNetworkExposure(ctx) {
|
|
|
49019
49020
|
if (r.code === 0) nft = parseNftInputChains(r.stdout);
|
|
49020
49021
|
}
|
|
49021
49022
|
}
|
|
49022
|
-
const hostVerdict = (port,
|
|
49023
|
+
const hostVerdict = (port, family2) => {
|
|
49023
49024
|
const layers = [];
|
|
49024
|
-
if (ufw?.active) layers.push(evaluateUfw(ufw, port,
|
|
49025
|
-
else if (input[
|
|
49025
|
+
if (ufw?.active) layers.push(evaluateUfw(ufw, port, family2));
|
|
49026
|
+
else if (input[family2]) layers.push(evaluateIptChain(input[family2], { dport: port, origDport: port }));
|
|
49026
49027
|
for (const ch of nft) {
|
|
49027
|
-
const v = evaluateNftChain(ch, port,
|
|
49028
|
+
const v = evaluateNftChain(ch, port, family2);
|
|
49028
49029
|
if (v.verdict !== "unknown") layers.push(v);
|
|
49029
49030
|
}
|
|
49030
49031
|
const blocked = layers.find((l) => l.verdict === "blocked");
|
|
@@ -50366,8 +50367,8 @@ function ipMatches(ip, entry) {
|
|
|
50366
50367
|
const mask = 255 << 8 - remainder & 255;
|
|
50367
50368
|
return (target[wholeBytes] & mask) === (base[wholeBytes] & mask);
|
|
50368
50369
|
}
|
|
50369
|
-
function isProtected(ip,
|
|
50370
|
-
return
|
|
50370
|
+
function isProtected(ip, list3) {
|
|
50371
|
+
return list3.some((entry) => ipMatches(ip, entry));
|
|
50371
50372
|
}
|
|
50372
50373
|
function currentSshClient(env3 = process.env) {
|
|
50373
50374
|
const source = env3.SSH_CLIENT || env3.SSH_CONNECTION;
|
|
@@ -50452,7 +50453,7 @@ function defaultGateways() {
|
|
|
50452
50453
|
// src/core/respond/ip.ts
|
|
50453
50454
|
function refuseIp(ip, ctx) {
|
|
50454
50455
|
if ((0, import_node_net6.isIP)(ip) === 0) return `not an IP address: ${ip}`;
|
|
50455
|
-
const hit = (
|
|
50456
|
+
const hit = (list3) => list3.find((entry) => ipMatches(ip, entry));
|
|
50456
50457
|
let m = hit(DEFAULT_PROTECTED);
|
|
50457
50458
|
if (m) return `${ip} is in a private/loopback range (${m}); refusing`;
|
|
50458
50459
|
m = hit(SHARED_INFRASTRUCTURE);
|
|
@@ -53623,6 +53624,34 @@ var RULES = [
|
|
|
53623
53624
|
return /(?:navigator\.clipboard\.writeText|document\.execCommand\(\s*["']copy)/.test(t) && /(?:powershell|mshta|cmd(?:\.exe)?\s*\/c|curl\s[^\n]{0,200}\|\s*(?:ba|z)?sh|osascript)/i.test(t) && /(?:Win(?:dows)?\s*(?:key\s*)?\+\s*R|Windows\s+key|Ctrl\s*\+\s*V|Cmd\s*\+\s*Space|verify\s+you\s+are\s+(?:a\s+)?human|I(?:'|')?m\s+not\s+a\s+robot)/i.test(t);
|
|
53624
53625
|
}
|
|
53625
53626
|
},
|
|
53627
|
+
{
|
|
53628
|
+
id: "CrushAV.Web.PhishKitExfil",
|
|
53629
|
+
name: "Phishing page that sends passwords to a chat bot",
|
|
53630
|
+
severity: "critical",
|
|
53631
|
+
impact: "malicious",
|
|
53632
|
+
description: "A login page that sends whatever you type, including your password, to a Telegram bot or a Discord webhook. Real sites never do this: it is how phishing kits deliver stolen credentials. Do not enter anything on this page.",
|
|
53633
|
+
test: (c) => {
|
|
53634
|
+
if (!(WEB_EXTS.has(c.ext) || c.ext === "js" || c.ext === "mjs" || c.ext === "php")) return false;
|
|
53635
|
+
const t = c.text;
|
|
53636
|
+
const exfil = /api\.telegram\.org\/bot[\w$`'"+{}.:-]{0,80}\/send(?:Message|Document)/i.test(t) || /discord(?:app)?\.com\/api\/webhooks\/\d{5,}\//i.test(t);
|
|
53637
|
+
if (!exfil) return false;
|
|
53638
|
+
return /<input\b[^>]*\btype\s*=\s*["']?password\b/i.test(t) || /(?:getElementById|querySelector|getElementsByName)\s*\(\s*["'`][#.]?[\w-]*(?:pass(?:word|wd|code)?|pwd|otp|pin)[\w-]*["'`]/i.test(t) || /\$_(?:POST|REQUEST)\s*\[\s*["'][\w-]*(?:pass(?:word|wd)?|pwd)[\w-]*["']\s*\]/i.test(t);
|
|
53639
|
+
}
|
|
53640
|
+
},
|
|
53641
|
+
{
|
|
53642
|
+
id: "CrushAV.Web.BrowserMiner",
|
|
53643
|
+
name: "Web page that mines cryptocurrency in your browser",
|
|
53644
|
+
severity: "high",
|
|
53645
|
+
impact: "malicious",
|
|
53646
|
+
description: "This page loads a cryptocurrency miner that runs in the visitor's browser and uses their CPU for someone else's profit, usually without asking. Close it.",
|
|
53647
|
+
test: (c) => {
|
|
53648
|
+
if (!(WEB_EXTS.has(c.ext) || c.ext === "js" || c.ext === "mjs")) return false;
|
|
53649
|
+
const t = c.text;
|
|
53650
|
+
const started = /\b(?:CoinHive|CoinImp|Client|CRLT|WMP|deepMiner|Minero)\.(?:Anonymous|User|Init)\s*\(\s*["'`][\w$]{8,}["'`][\s\S]{0,400}?\.start\s*\(/.test(t);
|
|
53651
|
+
const poolScript = /<script\b[^>]*\bsrc\s*=\s*["']?(?:https?:)?\/\/(?:[\w-]+\.)*(?:coinhive\.com|coin-hive\.com|authedmine\.com|crypto-loot\.(?:com|org)|cryptoloot\.pro|webminepool\.com|coinimp\.com|www\.hostingcloud\.racing|minero\.cc|jsecoin\.com|monerominer\.rocks|webmine\.cz)\//i.test(t);
|
|
53652
|
+
return started || poolScript;
|
|
53653
|
+
}
|
|
53654
|
+
},
|
|
53626
53655
|
{
|
|
53627
53656
|
id: "CrushAV.Web.HtmlSmuggling",
|
|
53628
53657
|
name: "Web page that builds a hidden download",
|
|
@@ -53642,8 +53671,62 @@ var RULES = [
|
|
|
53642
53671
|
impact: "suspicious",
|
|
53643
53672
|
description: 'This SVG "image" contains a script that redirects you or decodes hidden content. Phishing emails use SVG attachments like this to send you to fake login pages.',
|
|
53644
53673
|
test: (c) => c.ext === "svg" && /<script\b/i.test(c.text) && /(?:location(?:\.href)?\s*=|location\.replace\(|window\.open\(|atob\s*\()/.test(c.text)
|
|
53674
|
+
},
|
|
53675
|
+
{
|
|
53676
|
+
// Seen 2026-11-22: "futures-trader", a Go Gate.io futures CLI (UPX, saved
|
|
53677
|
+
// as .txt). `save-key` stores your API key locally AND, in a goroutine,
|
|
53678
|
+
// runs `INSERT INTO api_keys (key_val, secret_val, exchange_name)` on the
|
|
53679
|
+
// author's free public MySQL (mysql5.sqlpub.com) with the DSN in plain text.
|
|
53680
|
+
id: "CrushAV.Stealer.SecretsToHardcodedDatabase",
|
|
53681
|
+
name: "Sends your secrets to someone else's database",
|
|
53682
|
+
severity: "critical",
|
|
53683
|
+
impact: "malicious",
|
|
53684
|
+
description: `This program carries the login for a remote database baked into it and writes API keys, passwords, tokens or wallet seeds into it. That is how fake trading bots and "tools" steal keys: whatever you give it ends up in the author's database. Delete it, and revoke any key or password you entered into it.`,
|
|
53685
|
+
test: (c) => isStealerHost(c) && findRemoteDsn(allText(c)) !== null && SECRET_INSERT.test(allText(c))
|
|
53686
|
+
},
|
|
53687
|
+
{
|
|
53688
|
+
id: "CrushAV.Stealer.ExchangeKeyHarvester",
|
|
53689
|
+
name: "Crypto exchange tool that leaks your API key",
|
|
53690
|
+
severity: "critical",
|
|
53691
|
+
impact: "malicious",
|
|
53692
|
+
description: "A crypto-exchange trading tool that also contains the password for someone's remote database. A real trading tool only talks to the exchange; one that also logs in to a private database is copying your exchange API key and secret there. Delete it, revoke the key on the exchange now and check for withdrawals.",
|
|
53693
|
+
test: (c) => isStealerHost(c) && EXCHANGE_API.test(allText(c)) && findRemoteDsn(allText(c)) !== null
|
|
53694
|
+
},
|
|
53695
|
+
{
|
|
53696
|
+
id: "CrushAV.Suspicious.FreePublicDatabase",
|
|
53697
|
+
name: "Logs in to a free public database",
|
|
53698
|
+
severity: "medium",
|
|
53699
|
+
impact: "suspicious",
|
|
53700
|
+
description: "This program has the password for a database on a free, anonymous hosting service built in. Real software almost never does this; data thieves use these services as a drop box. If you did not write it, do not give it any keys or passwords.",
|
|
53701
|
+
test: (c) => {
|
|
53702
|
+
if (!isStealerHost(c)) return false;
|
|
53703
|
+
const dsn = findRemoteDsn(allText(c));
|
|
53704
|
+
return dsn !== null && FREE_DB_HOSTS.test(dsn.host);
|
|
53705
|
+
}
|
|
53645
53706
|
}
|
|
53646
53707
|
];
|
|
53708
|
+
var isStealerHost = (c) => EXECUTABLE_KINDS.has(c.kind) || isScript(c) && !NON_RUNNABLE_SOURCE_EXTS.has(c.ext);
|
|
53709
|
+
var EXCHANGE_API = /\b(?:api\.gateio\.ws|api\.gate\.io|(?:f|d)?api\.binance\.(?:com|us)|api\.bybit\.com|www\.okx\.com\/api|api\.mexc\.com|contract\.mexc\.com|api\.bitget\.com|api(?:-futures)?\.kucoin\.com|api\.kraken\.com|futures\.kraken\.com|api\.huobi\.pro|api\.htx\.com|api\.coinbase\.com|api\.exchange\.coinbase\.com|api\.bitfinex\.com|api\.hyperliquid\.xyz|api\.bingx\.com|open-api\.bingx\.com|api\.phemex\.com|api\.lbkex\.com|api\.bitmart\.com)\b/i;
|
|
53710
|
+
var SECRET_INSERT = /\b(?:INSERT|REPLACE)\s+INTO\s+[`"[]?(?:\w+[`"\]]?\.)?[`"[]?\w*(?:api_?keys?|secrets?|passw\w*|credentials?|wallets?|seeds?|mnemonics?|tokens?|cookies?|private_?keys?)\w*[`"\]]?\s*\(|\b(?:INSERT|REPLACE)\s+INTO\s+[`"[]?\w+[`"\]]?\s*\([^)]{0,200}\b\w*(?:secret|passw|private_?key|seed|mnemonic|api_?key|access_?token|cookie)\w*\b[^)]{0,200}\)/i;
|
|
53711
|
+
var FREE_DB_HOSTS = /(?:^|\.)(?:sqlpub\.com|db4free\.net|freesqldatabase\.com|freemysqlhosting\.net|remotemysql\.com|freedb\.tech|filess\.io)$/i;
|
|
53712
|
+
var PLACEHOLDER_SECRET = /^(?:pass(?:word|wd)?|pwd|secret|changeme|example|xxx+|\*+|<[^>]*>|\{[^}]*\}|\$\{?\w+\}?|%[sv]|your_?\w*|user(?:name)?|root|test)$/i;
|
|
53713
|
+
var LOCAL_HOST = /^(?:localhost|127\.\d+\.\d+\.\d+|0\.0\.0\.0|::1|host|hostname|db|database|mysql|postgres|redis|mongo|example\.(?:com|org|net)|[\w.-]*\.example\.(?:com|org|net)|[\w-]*\.local|[\w-]*\.internal|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+)$/i;
|
|
53714
|
+
function findRemoteDsn(t) {
|
|
53715
|
+
const res = [
|
|
53716
|
+
/([\w.-]{1,64}):([^\s@:/'"`()]{4,128})@tcp\(([a-z0-9.-]+)(?::\d{2,5})?\)\/[\w-]{0,64}/gi,
|
|
53717
|
+
/(?:mysql|mariadb|postgres(?:ql)?|mongodb(?:\+srv)?|rediss?|mssql|sqlserver):\/\/([\w.%-]{1,64}):([^\s@/'"`]{4,128})@([a-z0-9.-]+)(?::\d{2,5})?(?:\/|\b)/gi,
|
|
53718
|
+
/([\w.-]{1,64}):([^\s@:/'"`()]{4,128})@([a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,24}):(?:3306|3307|3308|3309|3310|3311|5432|5433|6379|27017|1433)\/[\w-]{1,64}/gi
|
|
53719
|
+
];
|
|
53720
|
+
for (const re of res) {
|
|
53721
|
+
for (const m of t.matchAll(re)) {
|
|
53722
|
+
const [, user, pass, host] = m;
|
|
53723
|
+
if (PLACEHOLDER_SECRET.test(pass)) continue;
|
|
53724
|
+
if (LOCAL_HOST.test(host) || !/\.[a-z]{2,24}$|^\d+\.\d+\.\d+\.\d+$/i.test(host)) continue;
|
|
53725
|
+
return { user, host: host.toLowerCase() };
|
|
53726
|
+
}
|
|
53727
|
+
}
|
|
53728
|
+
return null;
|
|
53729
|
+
}
|
|
53647
53730
|
function buildContext(name, bytes, kind, size) {
|
|
53648
53731
|
let text = "";
|
|
53649
53732
|
const NodeBuffer = globalThis.Buffer;
|
|
@@ -53687,6 +53770,219 @@ function runRules(ctx, rules = RULES) {
|
|
|
53687
53770
|
return out;
|
|
53688
53771
|
}
|
|
53689
53772
|
|
|
53773
|
+
// ../../packages/av/src/upx.ts
|
|
53774
|
+
var UPX_MAX_OUTPUT = 64 * 1024 * 1024;
|
|
53775
|
+
var MAGIC = [85, 80, 88, 33];
|
|
53776
|
+
function methodName(id) {
|
|
53777
|
+
if (id === 2 || id === 3 || id === 4) return "nrv2b";
|
|
53778
|
+
if (id === 5 || id === 6 || id === 7) return "nrv2d";
|
|
53779
|
+
if (id === 8 || id === 9 || id === 10) return "nrv2e";
|
|
53780
|
+
if (id === 14) return "lzma";
|
|
53781
|
+
return "unknown";
|
|
53782
|
+
}
|
|
53783
|
+
var le32 = (b, o) => (b[o] | b[o + 1] << 8 | b[o + 2] << 16 | b[o + 3] << 24) >>> 0;
|
|
53784
|
+
function findUpxHeader(b) {
|
|
53785
|
+
const windows = [
|
|
53786
|
+
[0, Math.min(b.length, 8192)],
|
|
53787
|
+
[Math.max(0, b.length - 8192), b.length]
|
|
53788
|
+
];
|
|
53789
|
+
for (const [from, to] of windows) {
|
|
53790
|
+
for (let i = from; i + 32 <= to; i++) {
|
|
53791
|
+
if (b[i] !== MAGIC[0] || b[i + 1] !== MAGIC[1] || b[i + 2] !== MAGIC[2] || b[i + 3] !== MAGIC[3]) continue;
|
|
53792
|
+
const version = b[i + 4];
|
|
53793
|
+
const format2 = b[i + 5];
|
|
53794
|
+
const methodId = b[i + 6];
|
|
53795
|
+
const level = b[i + 7];
|
|
53796
|
+
if (version < 10 || version > 20 || level > 10 || format2 === 0) continue;
|
|
53797
|
+
const uLen = le32(b, i + 16);
|
|
53798
|
+
const cLen = le32(b, i + 20);
|
|
53799
|
+
if (cLen === 0 || uLen === 0 || cLen >= uLen || uLen > 2147483647) continue;
|
|
53800
|
+
return { headerOffset: i, version, format: format2, method: methodName(methodId), methodId, level, uLen, cLen };
|
|
53801
|
+
}
|
|
53802
|
+
}
|
|
53803
|
+
return null;
|
|
53804
|
+
}
|
|
53805
|
+
var Bits = class {
|
|
53806
|
+
constructor(src, pos) {
|
|
53807
|
+
this.src = src;
|
|
53808
|
+
this.pos = pos;
|
|
53809
|
+
}
|
|
53810
|
+
src;
|
|
53811
|
+
pos;
|
|
53812
|
+
bb = 0;
|
|
53813
|
+
bc = 0;
|
|
53814
|
+
bit() {
|
|
53815
|
+
if (this.bc > 0) return this.bb >>> --this.bc & 1;
|
|
53816
|
+
if (this.pos + 4 > this.src.length) throw new RangeError("upx: input overrun");
|
|
53817
|
+
this.bb = le32(this.src, this.pos);
|
|
53818
|
+
this.pos += 4;
|
|
53819
|
+
this.bc = 31;
|
|
53820
|
+
return this.bb >>> 31 & 1;
|
|
53821
|
+
}
|
|
53822
|
+
byte() {
|
|
53823
|
+
if (this.pos >= this.src.length) throw new RangeError("upx: input overrun");
|
|
53824
|
+
return this.src[this.pos++];
|
|
53825
|
+
}
|
|
53826
|
+
};
|
|
53827
|
+
function nrvDecompress(method, src, start, maxOut) {
|
|
53828
|
+
const out = new Uint8Array(Math.min(maxOut, UPX_MAX_OUTPUT));
|
|
53829
|
+
const r = new Bits(src, start);
|
|
53830
|
+
let o = 0;
|
|
53831
|
+
let lastOff = 1;
|
|
53832
|
+
for (; ; ) {
|
|
53833
|
+
while (r.bit()) {
|
|
53834
|
+
if (o >= out.length) return out;
|
|
53835
|
+
out[o++] = r.byte();
|
|
53836
|
+
}
|
|
53837
|
+
let off = 1;
|
|
53838
|
+
let len;
|
|
53839
|
+
if (method === "nrv2b") {
|
|
53840
|
+
do {
|
|
53841
|
+
off = off * 2 + r.bit();
|
|
53842
|
+
if (off > 16777218) throw new RangeError("upx: bad offset");
|
|
53843
|
+
} while (!r.bit());
|
|
53844
|
+
if (off === 2) off = lastOff;
|
|
53845
|
+
else {
|
|
53846
|
+
off = (off - 3) * 256 + r.byte() >>> 0;
|
|
53847
|
+
if (off === 4294967295) break;
|
|
53848
|
+
lastOff = ++off;
|
|
53849
|
+
}
|
|
53850
|
+
len = r.bit();
|
|
53851
|
+
len = len * 2 + r.bit();
|
|
53852
|
+
if (len === 0) {
|
|
53853
|
+
len = 1;
|
|
53854
|
+
do {
|
|
53855
|
+
len = len * 2 + r.bit();
|
|
53856
|
+
if (len > out.length) throw new RangeError("upx: bad length");
|
|
53857
|
+
} while (!r.bit());
|
|
53858
|
+
len += 2;
|
|
53859
|
+
}
|
|
53860
|
+
len += off > 3328 ? 1 : 0;
|
|
53861
|
+
} else {
|
|
53862
|
+
for (; ; ) {
|
|
53863
|
+
off = off * 2 + r.bit();
|
|
53864
|
+
if (r.bit()) break;
|
|
53865
|
+
off = (off - 1) * 2 + r.bit();
|
|
53866
|
+
if (off > 16777218) throw new RangeError("upx: bad offset");
|
|
53867
|
+
}
|
|
53868
|
+
if (off === 2) {
|
|
53869
|
+
off = lastOff;
|
|
53870
|
+
len = r.bit();
|
|
53871
|
+
} else {
|
|
53872
|
+
off = (off - 3) * 256 + r.byte() >>> 0;
|
|
53873
|
+
if (off === 4294967295) break;
|
|
53874
|
+
len = (off ^ 4294967295) & 1;
|
|
53875
|
+
off >>>= 1;
|
|
53876
|
+
lastOff = ++off;
|
|
53877
|
+
}
|
|
53878
|
+
if (method === "nrv2d") {
|
|
53879
|
+
len = len * 2 + r.bit();
|
|
53880
|
+
if (len === 0) {
|
|
53881
|
+
len = 1;
|
|
53882
|
+
do {
|
|
53883
|
+
len = len * 2 + r.bit();
|
|
53884
|
+
if (len > out.length) throw new RangeError("upx: bad length");
|
|
53885
|
+
} while (!r.bit());
|
|
53886
|
+
len += 2;
|
|
53887
|
+
}
|
|
53888
|
+
} else if (len) {
|
|
53889
|
+
len = 1 + r.bit();
|
|
53890
|
+
} else if (r.bit()) {
|
|
53891
|
+
len = 3 + r.bit();
|
|
53892
|
+
} else {
|
|
53893
|
+
len = 1;
|
|
53894
|
+
do {
|
|
53895
|
+
len = len * 2 + r.bit();
|
|
53896
|
+
if (len > out.length) throw new RangeError("upx: bad length");
|
|
53897
|
+
} while (!r.bit());
|
|
53898
|
+
len += 3;
|
|
53899
|
+
}
|
|
53900
|
+
len += off > 1280 ? 1 : 0;
|
|
53901
|
+
}
|
|
53902
|
+
if (off > o) throw new RangeError("upx: back-reference before start");
|
|
53903
|
+
const n = len + 1;
|
|
53904
|
+
for (let k = 0; k < n; k++) {
|
|
53905
|
+
if (o >= out.length) return out;
|
|
53906
|
+
out[o] = out[o - off];
|
|
53907
|
+
o++;
|
|
53908
|
+
}
|
|
53909
|
+
}
|
|
53910
|
+
return out.subarray(0, o);
|
|
53911
|
+
}
|
|
53912
|
+
function candidateStarts(b, info2) {
|
|
53913
|
+
const starts2 = [info2.headerOffset + 32];
|
|
53914
|
+
if (b[0] === 77 && b[1] === 90 && b.length > 64) {
|
|
53915
|
+
const pe = le32(b, 60);
|
|
53916
|
+
if (pe + 24 < b.length && le32(b, pe) === 17744) {
|
|
53917
|
+
const nSec = b[pe + 6] | b[pe + 7] << 8;
|
|
53918
|
+
const optSize = b[pe + 20] | b[pe + 21] << 8;
|
|
53919
|
+
const sec = pe + 24 + optSize;
|
|
53920
|
+
for (let s = 0; s < nSec && s < 16; s++) {
|
|
53921
|
+
const e = sec + s * 40;
|
|
53922
|
+
if (e + 40 > b.length) break;
|
|
53923
|
+
const rawSize = le32(b, e + 16);
|
|
53924
|
+
const rawPtr = le32(b, e + 20);
|
|
53925
|
+
if (rawSize >= info2.cLen && rawPtr < b.length) starts2.push(rawPtr);
|
|
53926
|
+
}
|
|
53927
|
+
}
|
|
53928
|
+
}
|
|
53929
|
+
for (let i = 0; i + 12 <= b.length; i += 4) {
|
|
53930
|
+
if (le32(b, i) === info2.uLen && le32(b, i + 4) === info2.cLen && b[i + 8] === info2.methodId) starts2.push(i + 12);
|
|
53931
|
+
}
|
|
53932
|
+
return starts2;
|
|
53933
|
+
}
|
|
53934
|
+
function upxUnpack(b) {
|
|
53935
|
+
const info2 = findUpxHeader(b);
|
|
53936
|
+
if (!info2) return null;
|
|
53937
|
+
if (info2.method !== "nrv2b" && info2.method !== "nrv2d" && info2.method !== "nrv2e") return { info: info2, bytes: null };
|
|
53938
|
+
if (info2.uLen > UPX_MAX_OUTPUT) return { info: info2, bytes: null };
|
|
53939
|
+
for (const start of candidateStarts(b, info2)) {
|
|
53940
|
+
try {
|
|
53941
|
+
const out = nrvDecompress(info2.method, b, start, info2.uLen);
|
|
53942
|
+
if (out.length === info2.uLen) return { info: info2, bytes: out };
|
|
53943
|
+
} catch {
|
|
53944
|
+
}
|
|
53945
|
+
}
|
|
53946
|
+
const blocks = decodeBlockChain(b, info2);
|
|
53947
|
+
return { info: info2, bytes: blocks };
|
|
53948
|
+
}
|
|
53949
|
+
function decodeBlockChain(b, info2) {
|
|
53950
|
+
const method = info2.method;
|
|
53951
|
+
const parts = [];
|
|
53952
|
+
let total = 0;
|
|
53953
|
+
for (let i = 0; i + 12 <= b.length; ) {
|
|
53954
|
+
const unc = le32(b, i);
|
|
53955
|
+
const cpr = le32(b, i + 4);
|
|
53956
|
+
if (parts.length && cpr === unc && unc > 0 && unc <= info2.uLen && i + 12 + cpr <= b.length && total + unc <= UPX_MAX_OUTPUT) {
|
|
53957
|
+
parts.push(b.subarray(i + 12, i + 12 + cpr));
|
|
53958
|
+
total += unc;
|
|
53959
|
+
i += 12 + cpr;
|
|
53960
|
+
continue;
|
|
53961
|
+
}
|
|
53962
|
+
if (b[i + 8] === info2.methodId && b[i + 11] === 0 && cpr > 0 && cpr < unc && unc <= info2.uLen && i + 12 + cpr <= b.length && total + unc <= UPX_MAX_OUTPUT) {
|
|
53963
|
+
try {
|
|
53964
|
+
const out = nrvDecompress(method, b, i + 12, unc);
|
|
53965
|
+
if (out.length === unc) {
|
|
53966
|
+
parts.push(out);
|
|
53967
|
+
total += unc;
|
|
53968
|
+
i += 12 + cpr;
|
|
53969
|
+
continue;
|
|
53970
|
+
}
|
|
53971
|
+
} catch {
|
|
53972
|
+
}
|
|
53973
|
+
}
|
|
53974
|
+
i++;
|
|
53975
|
+
}
|
|
53976
|
+
if (!total) return null;
|
|
53977
|
+
const all = new Uint8Array(total);
|
|
53978
|
+
let o = 0;
|
|
53979
|
+
for (const p of parts) {
|
|
53980
|
+
all.set(p, o);
|
|
53981
|
+
o += p.length;
|
|
53982
|
+
}
|
|
53983
|
+
return all;
|
|
53984
|
+
}
|
|
53985
|
+
|
|
53690
53986
|
// ../../packages/av/src/engine.ts
|
|
53691
53987
|
var DEFAULT_HEURISTIC_BYTES = 16 * 1024 * 1024;
|
|
53692
53988
|
var SignatureSet = class {
|
|
@@ -53750,11 +54046,33 @@ async function scanBytes(input, opts = {}) {
|
|
|
53750
54046
|
description: known.startsWith("EICAR") ? "The harmless standard antivirus test file. Seeing this means the scanner works." : `This exact file is known malware (${known}). Quarantine or delete it.`
|
|
53751
54047
|
});
|
|
53752
54048
|
}
|
|
54049
|
+
const rules = opts.rules ?? RULES;
|
|
53753
54050
|
const ctx = buildContext(input.name, input.bytes, kind, size);
|
|
53754
|
-
for (const d of runRules(ctx,
|
|
54051
|
+
for (const d of runRules(ctx, rules)) {
|
|
53755
54052
|
if (known && d.id === "CrushAV.Test.EICAR") continue;
|
|
53756
54053
|
detections.push(d);
|
|
53757
54054
|
}
|
|
54055
|
+
if (EXECUTABLE_KINDS.has(kind)) {
|
|
54056
|
+
const upx = upxUnpack(input.bytes);
|
|
54057
|
+
if (upx) {
|
|
54058
|
+
detections.push({
|
|
54059
|
+
engine: "heuristic",
|
|
54060
|
+
id: "CrushAV.Packer.UPX",
|
|
54061
|
+
name: "Compressed with UPX",
|
|
54062
|
+
severity: "info",
|
|
54063
|
+
impact: "info",
|
|
54064
|
+
description: upx.bytes ? `This program is compressed with UPX (${upx.info.method}). Some legitimate tools are; malware uses it to hide its contents. CrushAV unpacked it and scanned the inside too.` : `This program is compressed with UPX (${upx.info.method}) and CrushAV could not unpack it, so its contents were not inspected. Treat it with care if you do not know where it came from.`
|
|
54065
|
+
});
|
|
54066
|
+
if (upx.bytes) {
|
|
54067
|
+
const seen = new Set(detections.map((d) => d.id));
|
|
54068
|
+
const inner = buildContext(input.name, upx.bytes, kind, upx.bytes.length);
|
|
54069
|
+
for (const d of runRules(inner, rules)) {
|
|
54070
|
+
if (seen.has(d.id)) continue;
|
|
54071
|
+
detections.push({ ...d, description: `${d.description} (Found inside the UPX-packed program.)` });
|
|
54072
|
+
}
|
|
54073
|
+
}
|
|
54074
|
+
}
|
|
54075
|
+
}
|
|
53758
54076
|
return {
|
|
53759
54077
|
path: input.name,
|
|
53760
54078
|
size,
|
|
@@ -54067,9 +54385,9 @@ function parseClamOutput(stdout) {
|
|
|
54067
54385
|
for (const line2 of stdout.split(/\r?\n/)) {
|
|
54068
54386
|
const m = /^(.*): (\S+) FOUND$/.exec(line2.trim());
|
|
54069
54387
|
if (!m) continue;
|
|
54070
|
-
const
|
|
54071
|
-
|
|
54072
|
-
out.set(m[1],
|
|
54388
|
+
const list3 = out.get(m[1]) ?? [];
|
|
54389
|
+
list3.push(m[2]);
|
|
54390
|
+
out.set(m[1], list3);
|
|
54073
54391
|
}
|
|
54074
54392
|
return out;
|
|
54075
54393
|
}
|
|
@@ -54089,11 +54407,11 @@ async function clamScanFiles(info2, files, opts = {}) {
|
|
|
54089
54407
|
const detections = /* @__PURE__ */ new Map();
|
|
54090
54408
|
if (!info2.available || !info2.binary || files.length === 0) return { detections, error: null };
|
|
54091
54409
|
const dir = await (0, import_promises2.mkdtemp)((0, import_node_path21.join)((0, import_node_os11.tmpdir)(), "crushav-"));
|
|
54092
|
-
const
|
|
54410
|
+
const list3 = (0, import_node_path21.join)(dir, "files.txt");
|
|
54093
54411
|
try {
|
|
54094
|
-
await (0, import_promises2.writeFile)(
|
|
54412
|
+
await (0, import_promises2.writeFile)(list3, `${files.join("\n")}
|
|
54095
54413
|
`);
|
|
54096
|
-
const args = ["--no-summary", "--infected", "--stdout", `--file-list=${
|
|
54414
|
+
const args = ["--no-summary", "--infected", "--stdout", `--file-list=${list3}`];
|
|
54097
54415
|
if (info2.mode === "clamdscan") args.push("--fdpass", "--multiscan");
|
|
54098
54416
|
const r = await run2(info2.binary, args, opts.timeoutMs ?? 60 * 60 * 1e3, opts.signal);
|
|
54099
54417
|
for (const [path2, sigs] of parseClamOutput(r.stdout)) detections.set(path2, sigs.map(clamDetection));
|
|
@@ -55725,23 +56043,23 @@ function sshArgv(options) {
|
|
|
55725
56043
|
return args;
|
|
55726
56044
|
}
|
|
55727
56045
|
async function sshConnect(options) {
|
|
55728
|
-
const { hostname:
|
|
55729
|
-
if (!
|
|
56046
|
+
const { hostname: hostname8, port, username, identity } = options;
|
|
56047
|
+
if (!hostname8) {
|
|
55730
56048
|
console.log(source_default.red(" No hostname available for this server.\n"));
|
|
55731
56049
|
return;
|
|
55732
56050
|
}
|
|
55733
56051
|
const user = username || "root";
|
|
55734
|
-
const problem = sshTargetError({ hostname:
|
|
56052
|
+
const problem = sshTargetError({ hostname: hostname8, username: user, port });
|
|
55735
56053
|
if (problem) {
|
|
55736
56054
|
console.log(source_default.red(` ${problem}
|
|
55737
56055
|
`));
|
|
55738
56056
|
process.exitCode = 1;
|
|
55739
56057
|
return;
|
|
55740
56058
|
}
|
|
55741
|
-
console.log(source_default.green(` Connecting to ${user}@${
|
|
56059
|
+
console.log(source_default.green(` Connecting to ${user}@${hostname8}:${port}...
|
|
55742
56060
|
`));
|
|
55743
56061
|
console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
|
|
55744
|
-
const sshArgs = sshArgv({ hostname:
|
|
56062
|
+
const sshArgs = sshArgv({ hostname: hostname8, username: user, port, identity });
|
|
55745
56063
|
const ssh = (0, import_node_child_process11.spawn)("ssh", sshArgs, { stdio: "inherit" });
|
|
55746
56064
|
ssh.on("error", (err) => {
|
|
55747
56065
|
console.log(source_default.red(`
|
|
@@ -55760,16 +56078,16 @@ async function sshConnect(options) {
|
|
|
55760
56078
|
}
|
|
55761
56079
|
|
|
55762
56080
|
// src/commands/daemon.ts
|
|
55763
|
-
var
|
|
55764
|
-
var
|
|
55765
|
-
var
|
|
55766
|
-
var
|
|
56081
|
+
var import_node_child_process29 = require("child_process");
|
|
56082
|
+
var import_node_fs71 = require("fs");
|
|
56083
|
+
var import_node_path50 = require("path");
|
|
56084
|
+
var import_node_fs72 = require("fs");
|
|
55767
56085
|
|
|
55768
56086
|
// src/daemon/index.ts
|
|
55769
|
-
var
|
|
55770
|
-
var
|
|
55771
|
-
var
|
|
55772
|
-
var
|
|
56087
|
+
var import_node_fs70 = require("fs");
|
|
56088
|
+
var import_node_child_process28 = require("child_process");
|
|
56089
|
+
var import_node_os22 = require("os");
|
|
56090
|
+
var import_node_path49 = require("path");
|
|
55773
56091
|
var import_node_util4 = require("util");
|
|
55774
56092
|
init_paths();
|
|
55775
56093
|
|
|
@@ -58455,6 +58773,10 @@ var CloudSpool = class {
|
|
|
58455
58773
|
|
|
58456
58774
|
// src/daemon/workers/cloud-sync.ts
|
|
58457
58775
|
var MAX_BATCH_BYTES = 900 * 1024;
|
|
58776
|
+
function uploadSeverity(event) {
|
|
58777
|
+
const rule = event.details?.rule_severity;
|
|
58778
|
+
return typeof rule === "string" && rule in SEVERITY_RANK7 ? rule : event.severity;
|
|
58779
|
+
}
|
|
58458
58780
|
var CloudSync = class {
|
|
58459
58781
|
constructor(opts) {
|
|
58460
58782
|
this.opts = opts;
|
|
@@ -58539,7 +58861,7 @@ var CloudSync = class {
|
|
|
58539
58861
|
let out = null;
|
|
58540
58862
|
if (event.module === "firewall-rules") {
|
|
58541
58863
|
out = remediationEvent(link.serverId, event);
|
|
58542
|
-
} else if ((event.module === "rule-engine" || !this.opts.ruleModules.has(event.module)) && event.details?.heartbeat !== true && SEVERITY_RANK7[event
|
|
58864
|
+
} else if ((event.module === "rule-engine" || !this.opts.ruleModules.has(event.module)) && event.details?.heartbeat !== true && SEVERITY_RANK7[uploadSeverity(event)] >= SEVERITY_RANK7[this.opts.minSeverity]) {
|
|
58543
58865
|
out = detectionEvent(link.serverId, event);
|
|
58544
58866
|
}
|
|
58545
58867
|
if (!out) return;
|
|
@@ -59091,11 +59413,11 @@ var import_node_net14 = require("net");
|
|
|
59091
59413
|
init_cli_config();
|
|
59092
59414
|
function isAddressOrCidr(value) {
|
|
59093
59415
|
const [network, prefix, extra] = value.split("/");
|
|
59094
|
-
const
|
|
59095
|
-
if (
|
|
59416
|
+
const family2 = (0, import_node_net14.isIP)(network);
|
|
59417
|
+
if (family2 === 0 || extra !== void 0) return false;
|
|
59096
59418
|
if (prefix === void 0) return true;
|
|
59097
59419
|
if (!/^\d{1,3}$/.test(prefix)) return false;
|
|
59098
|
-
return Number(prefix) <= (
|
|
59420
|
+
return Number(prefix) <= (family2 === 4 ? 32 : 128);
|
|
59099
59421
|
}
|
|
59100
59422
|
var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
|
|
59101
59423
|
function isCloudAllowEntry(value) {
|
|
@@ -63116,9 +63438,9 @@ var PostgresShellWatch = class {
|
|
|
63116
63438
|
if (!root) return [];
|
|
63117
63439
|
const children = /* @__PURE__ */ new Map();
|
|
63118
63440
|
for (const e of entries2.values()) {
|
|
63119
|
-
const
|
|
63120
|
-
|
|
63121
|
-
children.set(e.ppid,
|
|
63441
|
+
const list3 = children.get(e.ppid) ?? [];
|
|
63442
|
+
list3.push(e.pid);
|
|
63443
|
+
children.set(e.ppid, list3);
|
|
63122
63444
|
}
|
|
63123
63445
|
const order2 = [];
|
|
63124
63446
|
const visit = (pid, depth) => {
|
|
@@ -63367,9 +63689,9 @@ var DockerLogsWatch = class {
|
|
|
63367
63689
|
if (this.stopped) return;
|
|
63368
63690
|
const now = Date.now();
|
|
63369
63691
|
const previous = this.lastPoll;
|
|
63370
|
-
let
|
|
63692
|
+
let list3;
|
|
63371
63693
|
try {
|
|
63372
|
-
|
|
63694
|
+
list3 = await this.deps.getJson("/containers/json");
|
|
63373
63695
|
this.warned = false;
|
|
63374
63696
|
} catch (err) {
|
|
63375
63697
|
if (!this.warned) this.opts.log(`[docker-logs] cannot list containers: ${err.message}`);
|
|
@@ -63378,7 +63700,7 @@ var DockerLogsWatch = class {
|
|
|
63378
63700
|
}
|
|
63379
63701
|
this.lastPoll = now;
|
|
63380
63702
|
const running = /* @__PURE__ */ new Set();
|
|
63381
|
-
for (const c of Array.isArray(
|
|
63703
|
+
for (const c of Array.isArray(list3) ? list3 : []) {
|
|
63382
63704
|
if (!c?.Id || !this.matches(c)) continue;
|
|
63383
63705
|
running.add(c.Id);
|
|
63384
63706
|
if (this.follows.has(c.Id)) continue;
|
|
@@ -64106,6 +64428,8 @@ function evidenceOf(event) {
|
|
|
64106
64428
|
const v = details[k];
|
|
64107
64429
|
if (typeof v === "string" || typeof v === "number") out[k] = String(v).slice(0, EVIDENCE_FIELD_CHARS);
|
|
64108
64430
|
}
|
|
64431
|
+
const ctx = details.ssh_context;
|
|
64432
|
+
if (ctx && typeof ctx === "object" && !Array.isArray(ctx) && ctx.v === 1) out.ssh_context = ctx;
|
|
64109
64433
|
return out;
|
|
64110
64434
|
}
|
|
64111
64435
|
var RuleEngine = class {
|
|
@@ -64257,10 +64581,655 @@ var RuleEngine = class {
|
|
|
64257
64581
|
}
|
|
64258
64582
|
};
|
|
64259
64583
|
|
|
64260
|
-
// src/daemon/
|
|
64261
|
-
var
|
|
64584
|
+
// src/daemon/ssh-context/index.ts
|
|
64585
|
+
var import_node_os21 = require("os");
|
|
64262
64586
|
var import_node_path45 = require("path");
|
|
64263
64587
|
|
|
64588
|
+
// ../../packages/event-detail/src/verdict.ts
|
|
64589
|
+
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
64590
|
+
function maxSeverity2(a, b) {
|
|
64591
|
+
return RANK[a] >= RANK[b] ? a : b;
|
|
64592
|
+
}
|
|
64593
|
+
function severityRank2(s) {
|
|
64594
|
+
return RANK[s ?? "info"] ?? 0;
|
|
64595
|
+
}
|
|
64596
|
+
function describeFailures(f, ip) {
|
|
64597
|
+
if (!f) return null;
|
|
64598
|
+
const mins = Math.max(1, Math.round(f.window_s / 60));
|
|
64599
|
+
if (f.total === 0) {
|
|
64600
|
+
return `No failed SSH attempts in the ${mins} min before this login (the rule fires on every accepted login).`;
|
|
64601
|
+
}
|
|
64602
|
+
const top = (f.ips ?? []).filter((x) => x.ip !== ip).slice(0, 3).map((x) => `${x.ip} x${x.count}`).join(", ");
|
|
64603
|
+
const users = (f.users ?? []).slice(0, 4).map((u) => u.user).join(", ");
|
|
64604
|
+
const span2 = f.first && f.last ? ` between ${hhmmss(f.first)} and ${hhmmss(f.last)} UTC` : "";
|
|
64605
|
+
if (f.same_ip > 0 && f.other_ips === 0) {
|
|
64606
|
+
return `${f.same_ip} failed attempt${f.same_ip === 1 ? "" : "s"} from this same address${span2}${users ? ` (users: ${users})` : ""}, then this login succeeded: a guessed or brute-forced credential is possible.`;
|
|
64607
|
+
}
|
|
64608
|
+
if (f.same_ip === 0) {
|
|
64609
|
+
return `${f.total} failed attempt${f.total === 1 ? "" : "s"} in the ${mins} min before, all from OTHER addresses${top ? ` (${top})` : ""}${users ? `, users: ${users}` : ""}. None came from this address, so this is not a brute force that succeeded.`;
|
|
64610
|
+
}
|
|
64611
|
+
return `${f.total} failed attempt${f.total === 1 ? "" : "s"} in the ${mins} min before: ${f.same_ip} from this address and ${f.other_ips} from others${top ? ` (${top})` : ""}${users ? `, users: ${users}` : ""}.`;
|
|
64612
|
+
}
|
|
64613
|
+
function hhmmss(iso) {
|
|
64614
|
+
const d = new Date(iso);
|
|
64615
|
+
return Number.isNaN(d.getTime()) ? iso : d.toISOString().slice(11, 19);
|
|
64616
|
+
}
|
|
64617
|
+
function computeVerdict(ctx) {
|
|
64618
|
+
const reasons = [];
|
|
64619
|
+
const key = ctx.key;
|
|
64620
|
+
const src = ctx.source;
|
|
64621
|
+
const ci = ctx.session?.ci_deploy;
|
|
64622
|
+
const forced = !!key?.command;
|
|
64623
|
+
const restricted = forced || !!key?.from;
|
|
64624
|
+
const publicSrc = !src || src.kind === "public" || src.kind === "github-actions";
|
|
64625
|
+
const ghActions = src?.kind === "github-actions";
|
|
64626
|
+
let severity = "info";
|
|
64627
|
+
let level = "review";
|
|
64628
|
+
const raise = (s, why) => {
|
|
64629
|
+
severity = maxSeverity2(severity, s);
|
|
64630
|
+
reasons.push(why);
|
|
64631
|
+
};
|
|
64632
|
+
if (key?.in_root_and_user) raise("critical", "the same key authorizes root and another account");
|
|
64633
|
+
if (key?.suspicious_comment) raise(restricted ? "high" : "critical", `key comment "${key.comment}" looks like a dated temporary CI/diagnostic key`);
|
|
64634
|
+
if (ctx.failures && ctx.failures.same_ip > 0) raise("critical", `${ctx.failures.same_ip} failed attempt(s) from this same address before it succeeded`);
|
|
64635
|
+
if (ci && /^deny/i.test(ci.decision)) raise("high", `ci-deploy DENIED${ci.repo ? ` ${ci.repo}` : ""}`);
|
|
64636
|
+
if (publicSrc && ctx.auth_method === "password") raise("critical", "password login from a public address");
|
|
64637
|
+
if (publicSrc && !ghActions && key?.found && !restricted && !key.restrict) raise("critical", "unrestricted key (no command=, from= or restrict) from a non-CI address");
|
|
64638
|
+
if (publicSrc && key && !key.found && ctx.auth_method === "publickey") raise("high", "key not found in any readable authorized_keys (another account, or AuthorizedKeysCommand)");
|
|
64639
|
+
if (forced && publicSrc && !ghActions) raise("medium", "forced-command key used from an address outside GitHub Actions");
|
|
64640
|
+
const red3 = severityRank2(severity) >= RANK.high;
|
|
64641
|
+
if (key?.expected && !red3) {
|
|
64642
|
+
level = "expected";
|
|
64643
|
+
severity = "info";
|
|
64644
|
+
reasons.unshift(`key marked as expected CI${key.comment ? ` (${key.comment})` : ""}`);
|
|
64645
|
+
} else if (ghActions && forced && !red3) {
|
|
64646
|
+
level = "likely-ci";
|
|
64647
|
+
severity = "low";
|
|
64648
|
+
reasons.unshift("GitHub Actions IP", "forced-command deploy key");
|
|
64649
|
+
if (ci && /^allow/i.test(ci.decision)) reasons.push(`ci-deploy ALLOW ${ci.action || ci.repo || ""}`.trim());
|
|
64650
|
+
} else if (src && ["loopback", "self", "tailscale", "private"].includes(src.kind) && !red3) {
|
|
64651
|
+
level = "internal";
|
|
64652
|
+
severity = maxSeverity2("low", severity);
|
|
64653
|
+
reasons.unshift(src.kind === "tailscale" ? "Tailscale address" : src.kind === "self" ? "one of this host's own addresses" : src.kind === "loopback" ? "loopback" : "private address");
|
|
64654
|
+
} else if (red3) {
|
|
64655
|
+
level = "suspicious";
|
|
64656
|
+
} else {
|
|
64657
|
+
severity = maxSeverity2("high", severity);
|
|
64658
|
+
if (!reasons.length) reasons.push(ghActions ? "GitHub Actions address but not a forced-command key" : "login from a public address");
|
|
64659
|
+
}
|
|
64660
|
+
return { level, severity, summary: verdictSummary(level, reasons, ctx), reasons };
|
|
64661
|
+
}
|
|
64662
|
+
function verdictSummary(level, reasons, ctx) {
|
|
64663
|
+
const head2 = {
|
|
64664
|
+
expected: "Expected CI key",
|
|
64665
|
+
"likely-ci": "Likely CI deploy",
|
|
64666
|
+
internal: "Internal login",
|
|
64667
|
+
review: "Review",
|
|
64668
|
+
suspicious: "Suspicious login"
|
|
64669
|
+
};
|
|
64670
|
+
if (level === "review" && reasons.length === 1 && /public address$/.test(reasons[0])) {
|
|
64671
|
+
const restricted = ctx.key?.command || ctx.key?.from;
|
|
64672
|
+
return `${head2.review}: ${restricted ? "restricted" : "unrestricted"} ${ctx.auth_method ?? "login"} from ${ctx.source?.ip ?? "a public address"}`;
|
|
64673
|
+
}
|
|
64674
|
+
return `${head2[level]}: ${reasons.join(", ")}`;
|
|
64675
|
+
}
|
|
64676
|
+
|
|
64677
|
+
// src/daemon/ssh-context/auth-history.ts
|
|
64678
|
+
var MAX_ENTRIES2 = 2e4;
|
|
64679
|
+
var KEEP_MS = 60 * 60 * 1e3;
|
|
64680
|
+
var SAME_ATTEMPT_MS = 1e4;
|
|
64681
|
+
function classifySshdMessage(message) {
|
|
64682
|
+
let m = /^Failed (?:password|publickey|none|keyboard-interactive\/pam|keyboard-interactive|hostbased) for (?:invalid user )?(\S+) from \S+ port (\d+)/.exec(message);
|
|
64683
|
+
if (m) return { kind: "failed", user: m[1], port: Number(m[2]) };
|
|
64684
|
+
m = /^Invalid user (\S*) from \S+(?: port (\d+))?/.exec(message);
|
|
64685
|
+
if (m) return { kind: "invalid", user: m[1] || "(empty)", port: m[2] ? Number(m[2]) : void 0 };
|
|
64686
|
+
m = /^(?:Connection closed by|Disconnected from) (?:authenticating|invalid) user (\S+) \S+ port (\d+)/.exec(message);
|
|
64687
|
+
if (m) return { kind: "preauth-close", user: m[1], port: Number(m[2]) };
|
|
64688
|
+
m = /^Disconnected from user (\S+) \S+ port (\d+)/.exec(message);
|
|
64689
|
+
if (m) return { kind: "close", user: m[1], port: Number(m[2]) };
|
|
64690
|
+
m = /^Received disconnect from \S+ port (\d+):\d+: .*disconnected by user/i.exec(message);
|
|
64691
|
+
if (m && !/\[preauth\]/.test(message)) return { kind: "close", port: Number(m[1]) };
|
|
64692
|
+
return null;
|
|
64693
|
+
}
|
|
64694
|
+
var SshAuthHistory = class {
|
|
64695
|
+
constructor(now = Date.now) {
|
|
64696
|
+
this.now = now;
|
|
64697
|
+
}
|
|
64698
|
+
now;
|
|
64699
|
+
failures = [];
|
|
64700
|
+
closes = [];
|
|
64701
|
+
seen = /* @__PURE__ */ new Map();
|
|
64702
|
+
record(line2) {
|
|
64703
|
+
const at = line2.timestamp instanceof Date ? line2.timestamp.getTime() : Date.now();
|
|
64704
|
+
if (Number.isNaN(at)) return;
|
|
64705
|
+
const key = `${at}|${line2.message}`;
|
|
64706
|
+
if (this.seen.has(key)) return;
|
|
64707
|
+
this.seen.set(key, at);
|
|
64708
|
+
const c = classifySshdMessage(line2.message);
|
|
64709
|
+
if (!c) return;
|
|
64710
|
+
if (c.kind === "close") {
|
|
64711
|
+
if (c.port) this.closes.push({ at, ip: line2.ip, port: c.port, user: c.user });
|
|
64712
|
+
} else {
|
|
64713
|
+
const user = c.user ?? "unknown";
|
|
64714
|
+
const same = [];
|
|
64715
|
+
if (c.port !== void 0) {
|
|
64716
|
+
for (let i = this.failures.length - 1; i >= 0; i--) {
|
|
64717
|
+
const f = this.failures[i];
|
|
64718
|
+
if (f.at < at - SAME_ATTEMPT_MS) break;
|
|
64719
|
+
if (f.ip === line2.ip && f.port === c.port) same.push(f);
|
|
64720
|
+
}
|
|
64721
|
+
}
|
|
64722
|
+
if (c.kind === "failed") {
|
|
64723
|
+
const placeholder = same.find((f) => f.kind !== "failed");
|
|
64724
|
+
if (placeholder) {
|
|
64725
|
+
placeholder.kind = "failed";
|
|
64726
|
+
placeholder.user = user;
|
|
64727
|
+
} else this.failures.push({ at, ip: line2.ip, user, kind: c.kind, port: c.port });
|
|
64728
|
+
} else if (same.length === 0) {
|
|
64729
|
+
this.failures.push({ at, ip: line2.ip, user, kind: c.kind, port: c.port });
|
|
64730
|
+
}
|
|
64731
|
+
}
|
|
64732
|
+
this.prune();
|
|
64733
|
+
}
|
|
64734
|
+
prune() {
|
|
64735
|
+
const cutoff = this.now() - KEEP_MS;
|
|
64736
|
+
if (this.failures.length > MAX_ENTRIES2) this.failures.splice(0, this.failures.length - MAX_ENTRIES2);
|
|
64737
|
+
if (this.closes.length > MAX_ENTRIES2) this.closes.splice(0, this.closes.length - MAX_ENTRIES2);
|
|
64738
|
+
while (this.failures.length && this.failures[0].at < cutoff) this.failures.shift();
|
|
64739
|
+
while (this.closes.length && this.closes[0].at < cutoff) this.closes.shift();
|
|
64740
|
+
if (this.seen.size > MAX_ENTRIES2) {
|
|
64741
|
+
let drop = this.seen.size - MAX_ENTRIES2 / 2;
|
|
64742
|
+
for (const k of this.seen.keys()) {
|
|
64743
|
+
if (drop-- <= 0) break;
|
|
64744
|
+
this.seen.delete(k);
|
|
64745
|
+
}
|
|
64746
|
+
}
|
|
64747
|
+
}
|
|
64748
|
+
/** Failures in the `windowS` seconds up to `atMs`, grouped, relative to the address that logged in. */
|
|
64749
|
+
failuresBefore(atMs, ip, windowS = 600) {
|
|
64750
|
+
const from = atMs - windowS * 1e3;
|
|
64751
|
+
const hits = this.failures.filter((f) => f.at >= from && f.at <= atMs + 1e3);
|
|
64752
|
+
const byIp = /* @__PURE__ */ new Map();
|
|
64753
|
+
const byUser = /* @__PURE__ */ new Map();
|
|
64754
|
+
for (const f of hits) {
|
|
64755
|
+
byIp.set(f.ip, (byIp.get(f.ip) ?? 0) + 1);
|
|
64756
|
+
byUser.set(f.user, (byUser.get(f.user) ?? 0) + 1);
|
|
64757
|
+
}
|
|
64758
|
+
const sameIp = byIp.get(ip) ?? 0;
|
|
64759
|
+
const top = (m, k) => [...m.entries()].sort((a, b) => b[1] - a[1]).slice(0, 10).map(([v, count]) => ({ [k]: v, count }));
|
|
64760
|
+
return {
|
|
64761
|
+
window_s: windowS,
|
|
64762
|
+
total: hits.length,
|
|
64763
|
+
same_ip: sameIp,
|
|
64764
|
+
other_ips: hits.length - sameIp,
|
|
64765
|
+
...hits.length ? {
|
|
64766
|
+
ips: top(byIp, "ip"),
|
|
64767
|
+
users: top(byUser, "user"),
|
|
64768
|
+
first: new Date(Math.min(...hits.map((h) => h.at))).toISOString(),
|
|
64769
|
+
last: new Date(Math.max(...hits.map((h) => h.at))).toISOString()
|
|
64770
|
+
} : {}
|
|
64771
|
+
};
|
|
64772
|
+
}
|
|
64773
|
+
/** When the session from `ip`:`port` closed, if it has. */
|
|
64774
|
+
closeOf(ip, port, afterMs) {
|
|
64775
|
+
if (!port) return null;
|
|
64776
|
+
const c = this.closes.find((x) => x.ip === ip && x.port === port && x.at >= afterMs - 1e3);
|
|
64777
|
+
return c ? c.at : null;
|
|
64778
|
+
}
|
|
64779
|
+
};
|
|
64780
|
+
|
|
64781
|
+
// src/daemon/ssh-context/authorized-keys.ts
|
|
64782
|
+
var import_node_fs64 = require("fs");
|
|
64783
|
+
var realKeyFilesIO = {
|
|
64784
|
+
passwd: () => {
|
|
64785
|
+
try {
|
|
64786
|
+
return (0, import_node_fs64.readFileSync)("/etc/passwd", "utf-8");
|
|
64787
|
+
} catch {
|
|
64788
|
+
return "";
|
|
64789
|
+
}
|
|
64790
|
+
},
|
|
64791
|
+
mtime: (p) => {
|
|
64792
|
+
try {
|
|
64793
|
+
return (0, import_node_fs64.statSync)(p).mtimeMs;
|
|
64794
|
+
} catch {
|
|
64795
|
+
return null;
|
|
64796
|
+
}
|
|
64797
|
+
},
|
|
64798
|
+
read: (p) => {
|
|
64799
|
+
try {
|
|
64800
|
+
return (0, import_node_fs64.readFileSync)(p, "utf-8");
|
|
64801
|
+
} catch {
|
|
64802
|
+
return null;
|
|
64803
|
+
}
|
|
64804
|
+
}
|
|
64805
|
+
};
|
|
64806
|
+
var NOLOGIN = /(?:nologin|false|sync|halt|shutdown)$/;
|
|
64807
|
+
function maskBlob(blob) {
|
|
64808
|
+
return `${blob.slice(0, 8)}\u2026[masked]`;
|
|
64809
|
+
}
|
|
64810
|
+
function optionText(o) {
|
|
64811
|
+
return o.value === null ? o.name : `${o.name}="${o.value.replace(/"/g, '\\"')}"`;
|
|
64812
|
+
}
|
|
64813
|
+
var MAX_OPTION_CHARS = 300;
|
|
64814
|
+
function maskedLine(k) {
|
|
64815
|
+
const opts = k.options.map((o) => optionText(o).slice(0, MAX_OPTION_CHARS)).join(",");
|
|
64816
|
+
return [opts, k.type, maskBlob(k.blob), k.comment].filter(Boolean).join(" ");
|
|
64817
|
+
}
|
|
64818
|
+
var AuthorizedKeysIndex = class {
|
|
64819
|
+
constructor(io = realKeyFilesIO) {
|
|
64820
|
+
this.io = io;
|
|
64821
|
+
}
|
|
64822
|
+
io;
|
|
64823
|
+
files = /* @__PURE__ */ new Map();
|
|
64824
|
+
accounts() {
|
|
64825
|
+
return parsePasswd(this.io.passwd()).filter((p) => p.uid === 0 || p.home && p.home !== "/" && !NOLOGIN.test(p.shell)).map((p) => ({ name: p.name, home: p.home.replace(/\/$/, "") }));
|
|
64826
|
+
}
|
|
64827
|
+
keysIn(path2, user) {
|
|
64828
|
+
const mtime = this.io.mtime(path2);
|
|
64829
|
+
if (mtime === null) {
|
|
64830
|
+
this.files.delete(path2);
|
|
64831
|
+
return [];
|
|
64832
|
+
}
|
|
64833
|
+
const cached = this.files.get(path2);
|
|
64834
|
+
if (cached && cached.mtime === mtime) return cached.keys;
|
|
64835
|
+
const keys = parseAuthorizedKeys(this.io.read(path2) ?? "", path2).map((k) => ({ ...k, user }));
|
|
64836
|
+
this.files.set(path2, { mtime, keys });
|
|
64837
|
+
return keys;
|
|
64838
|
+
}
|
|
64839
|
+
/** Every authorized_keys line carrying `fingerprint`, as login context. */
|
|
64840
|
+
lookup(fingerprint, expected = /* @__PURE__ */ new Set()) {
|
|
64841
|
+
const matches2 = [];
|
|
64842
|
+
for (const { name, home } of this.accounts()) {
|
|
64843
|
+
for (const f of ["authorized_keys", "authorized_keys2"]) {
|
|
64844
|
+
for (const k2 of this.keysIn(`${home}/.ssh/${f}`, name)) if (k2.fingerprint === fingerprint) matches2.push(k2);
|
|
64845
|
+
}
|
|
64846
|
+
}
|
|
64847
|
+
if (!matches2.length) return { found: false, fingerprint, ...expected.has(fingerprint) ? { expected: true } : {} };
|
|
64848
|
+
const k = matches2.find((m) => !m.command && !m.from && !m.restrict) ?? matches2[0];
|
|
64849
|
+
const accounts = [...new Set(matches2.map((m) => m.user))];
|
|
64850
|
+
const inRoot = matches2.some((m) => m.user === "root" || m.file.startsWith("/root/"));
|
|
64851
|
+
const inOther = matches2.some((m) => m.user !== "root" && !m.file.startsWith("/root/"));
|
|
64852
|
+
return {
|
|
64853
|
+
found: true,
|
|
64854
|
+
type: k.type,
|
|
64855
|
+
fingerprint,
|
|
64856
|
+
comment: k.comment.slice(0, 200) || void 0,
|
|
64857
|
+
options: k.options.map((o) => optionText(o).slice(0, MAX_OPTION_CHARS)),
|
|
64858
|
+
command: k.command ? k.command.slice(0, 500) : null,
|
|
64859
|
+
from: k.from ? k.from.slice(0, 300) : null,
|
|
64860
|
+
restrict: k.restrict,
|
|
64861
|
+
files: matches2.map((m) => `${m.file}:${m.line}`).slice(0, 10),
|
|
64862
|
+
accounts,
|
|
64863
|
+
line_masked: maskedLine(k).slice(0, 800),
|
|
64864
|
+
in_root_and_user: inRoot && inOther,
|
|
64865
|
+
suspicious_comment: suspiciousKeyComment(k.comment),
|
|
64866
|
+
...expected.has(fingerprint) ? { expected: true } : {}
|
|
64867
|
+
};
|
|
64868
|
+
}
|
|
64869
|
+
};
|
|
64870
|
+
|
|
64871
|
+
// src/daemon/ssh-context/ip-intel.ts
|
|
64872
|
+
var import_node_net22 = require("net");
|
|
64873
|
+
var import_node_os20 = require("os");
|
|
64874
|
+
var import_node_dns2 = require("dns");
|
|
64875
|
+
var import_node_fs65 = require("fs");
|
|
64876
|
+
function list2(entries2) {
|
|
64877
|
+
const b = new import_node_net22.BlockList();
|
|
64878
|
+
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
64879
|
+
return b;
|
|
64880
|
+
}
|
|
64881
|
+
var LOOPBACK = list2([["127.0.0.0", 8, "ipv4"], ["::1", 128, "ipv6"]]);
|
|
64882
|
+
var TAILSCALE = list2([["100.64.0.0", 10, "ipv4"], ["fd7a:115c:a1e0::", 48, "ipv6"]]);
|
|
64883
|
+
var PRIVATE = list2([
|
|
64884
|
+
["10.0.0.0", 8, "ipv4"],
|
|
64885
|
+
["172.16.0.0", 12, "ipv4"],
|
|
64886
|
+
["192.168.0.0", 16, "ipv4"],
|
|
64887
|
+
["169.254.0.0", 16, "ipv4"],
|
|
64888
|
+
["fc00::", 7, "ipv6"],
|
|
64889
|
+
["fe80::", 10, "ipv6"]
|
|
64890
|
+
]);
|
|
64891
|
+
function family(ip) {
|
|
64892
|
+
const f = (0, import_node_net22.isIP)(ip);
|
|
64893
|
+
return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
|
|
64894
|
+
}
|
|
64895
|
+
function normalizeIp2(ip) {
|
|
64896
|
+
const m = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(ip);
|
|
64897
|
+
return m ? m[1] : ip;
|
|
64898
|
+
}
|
|
64899
|
+
function ownAddresses() {
|
|
64900
|
+
const out = /* @__PURE__ */ new Set();
|
|
64901
|
+
try {
|
|
64902
|
+
for (const list3 of Object.values((0, import_node_os20.networkInterfaces)())) for (const a of list3 ?? []) out.add(a.address.split("%")[0]);
|
|
64903
|
+
} catch {
|
|
64904
|
+
}
|
|
64905
|
+
return out;
|
|
64906
|
+
}
|
|
64907
|
+
function classifyAddress(raw, c) {
|
|
64908
|
+
const ip = normalizeIp2(raw);
|
|
64909
|
+
const f = family(ip);
|
|
64910
|
+
if (!f) return "public";
|
|
64911
|
+
if (LOOPBACK.check(ip, f)) return "loopback";
|
|
64912
|
+
if (c.own().has(ip)) return "self";
|
|
64913
|
+
if (TAILSCALE.check(ip, f)) return "tailscale";
|
|
64914
|
+
if (PRIVATE.check(ip, f)) return "private";
|
|
64915
|
+
if (c.isGitHubActions(ip)) return "github-actions";
|
|
64916
|
+
return "public";
|
|
64917
|
+
}
|
|
64918
|
+
var META_URL = "https://api.github.com/meta";
|
|
64919
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
64920
|
+
var RETRY_MS = 30 * 60 * 1e3;
|
|
64921
|
+
function rangesDeps(cacheFile) {
|
|
64922
|
+
return {
|
|
64923
|
+
fetchJson: async (url) => {
|
|
64924
|
+
const res = await fetch(url, {
|
|
64925
|
+
headers: { accept: "application/vnd.github+json", "user-agent": "threatcrush-agent" },
|
|
64926
|
+
signal: AbortSignal.timeout(15e3)
|
|
64927
|
+
});
|
|
64928
|
+
if (!res.ok) throw new Error(`GitHub meta ${res.status}`);
|
|
64929
|
+
return res.json();
|
|
64930
|
+
},
|
|
64931
|
+
load: () => {
|
|
64932
|
+
try {
|
|
64933
|
+
const v = JSON.parse((0, import_node_fs65.readFileSync)(cacheFile, "utf-8"));
|
|
64934
|
+
return typeof v.at === "number" && Array.isArray(v.cidrs) ? { at: v.at, cidrs: v.cidrs.map(String) } : null;
|
|
64935
|
+
} catch {
|
|
64936
|
+
return null;
|
|
64937
|
+
}
|
|
64938
|
+
},
|
|
64939
|
+
save: (v) => {
|
|
64940
|
+
try {
|
|
64941
|
+
(0, import_node_fs65.writeFileSync)(cacheFile, JSON.stringify(v), { mode: 420 });
|
|
64942
|
+
} catch {
|
|
64943
|
+
}
|
|
64944
|
+
},
|
|
64945
|
+
now: Date.now
|
|
64946
|
+
};
|
|
64947
|
+
}
|
|
64948
|
+
var GitHubActionsRanges = class {
|
|
64949
|
+
constructor(deps, enabled = true) {
|
|
64950
|
+
this.deps = deps;
|
|
64951
|
+
this.enabled = enabled;
|
|
64952
|
+
const saved = enabled ? deps.load() : null;
|
|
64953
|
+
if (saved?.cidrs.length) this.set(saved.cidrs, saved.at);
|
|
64954
|
+
}
|
|
64955
|
+
deps;
|
|
64956
|
+
enabled;
|
|
64957
|
+
list = null;
|
|
64958
|
+
count = 0;
|
|
64959
|
+
at = 0;
|
|
64960
|
+
lastTry = 0;
|
|
64961
|
+
inflight = null;
|
|
64962
|
+
set(cidrs, at) {
|
|
64963
|
+
const b = new import_node_net22.BlockList();
|
|
64964
|
+
let n = 0;
|
|
64965
|
+
for (const c of cidrs) {
|
|
64966
|
+
const [addr, bits2] = c.split("/");
|
|
64967
|
+
const f = family(addr);
|
|
64968
|
+
const p = Number(bits2);
|
|
64969
|
+
if (!f || !Number.isInteger(p)) continue;
|
|
64970
|
+
try {
|
|
64971
|
+
b.addSubnet(addr, p, f);
|
|
64972
|
+
n++;
|
|
64973
|
+
} catch {
|
|
64974
|
+
}
|
|
64975
|
+
}
|
|
64976
|
+
if (n) {
|
|
64977
|
+
this.list = b;
|
|
64978
|
+
this.count = n;
|
|
64979
|
+
this.at = at;
|
|
64980
|
+
}
|
|
64981
|
+
}
|
|
64982
|
+
size() {
|
|
64983
|
+
return this.count;
|
|
64984
|
+
}
|
|
64985
|
+
/** Refresh when stale; never throws, never blocks a lookup for long. */
|
|
64986
|
+
async refresh() {
|
|
64987
|
+
if (!this.enabled) return;
|
|
64988
|
+
const now = this.deps.now();
|
|
64989
|
+
if (this.list && now - this.at < DAY_MS) return;
|
|
64990
|
+
if (now - this.lastTry < RETRY_MS) return;
|
|
64991
|
+
this.inflight ??= (async () => {
|
|
64992
|
+
this.lastTry = now;
|
|
64993
|
+
try {
|
|
64994
|
+
const body = await this.deps.fetchJson(META_URL);
|
|
64995
|
+
const cidrs = Array.isArray(body?.actions) ? body.actions.filter((c) => typeof c === "string") : [];
|
|
64996
|
+
if (cidrs.length) {
|
|
64997
|
+
this.set(cidrs, now);
|
|
64998
|
+
this.deps.save({ at: now, cidrs });
|
|
64999
|
+
}
|
|
65000
|
+
} catch {
|
|
65001
|
+
}
|
|
65002
|
+
})().finally(() => {
|
|
65003
|
+
this.inflight = null;
|
|
65004
|
+
});
|
|
65005
|
+
return this.inflight;
|
|
65006
|
+
}
|
|
65007
|
+
has(raw) {
|
|
65008
|
+
const ip = normalizeIp2(raw);
|
|
65009
|
+
const f = family(ip);
|
|
65010
|
+
return !!(this.list && f && this.list.check(ip, f));
|
|
65011
|
+
}
|
|
65012
|
+
};
|
|
65013
|
+
var realNetLookup = {
|
|
65014
|
+
reverse: (ip) => import_node_dns2.promises.reverse(ip),
|
|
65015
|
+
txt: (name) => import_node_dns2.promises.resolveTxt(name)
|
|
65016
|
+
};
|
|
65017
|
+
function withTimeout2(p, ms) {
|
|
65018
|
+
return Promise.race([p.catch(() => null), new Promise((r) => setTimeout(() => r(null), ms).unref?.())]);
|
|
65019
|
+
}
|
|
65020
|
+
function cymruOriginName2(raw) {
|
|
65021
|
+
const ip = normalizeIp2(raw);
|
|
65022
|
+
const f = (0, import_node_net22.isIP)(ip);
|
|
65023
|
+
if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
|
|
65024
|
+
if (f !== 6) return null;
|
|
65025
|
+
const parts = ip.split("::");
|
|
65026
|
+
const head2 = parts[0] ? parts[0].split(":") : [];
|
|
65027
|
+
const tail = parts.length > 1 && parts[1] ? parts[1].split(":") : [];
|
|
65028
|
+
const groups = [...head2, ...Array(8 - head2.length - tail.length).fill("0"), ...tail].map((g) => g.padStart(4, "0"));
|
|
65029
|
+
return `${groups.join("").split("").reverse().join(".")}.origin6.asn.cymru.com`;
|
|
65030
|
+
}
|
|
65031
|
+
function parseCymruOrigin2(txt) {
|
|
65032
|
+
const f = txt.split("|").map((s) => s.trim());
|
|
65033
|
+
const asn = Number((f[0] ?? "").split(/\s+/)[0]);
|
|
65034
|
+
if (!Number.isInteger(asn) || asn <= 0) return null;
|
|
65035
|
+
return { asn, country: f[2] && /^[A-Z]{2}$/.test(f[2]) ? f[2] : null };
|
|
65036
|
+
}
|
|
65037
|
+
function parseCymruAsName(txt) {
|
|
65038
|
+
const f = txt.split("|").map((s) => s.trim());
|
|
65039
|
+
const name = f[4]?.replace(/,\s*[A-Z]{2}$/, "").trim();
|
|
65040
|
+
return name ? name.slice(0, 120) : null;
|
|
65041
|
+
}
|
|
65042
|
+
var NetLookup = class {
|
|
65043
|
+
constructor(deps = realNetLookup, timeoutMs = 2500, now = Date.now) {
|
|
65044
|
+
this.deps = deps;
|
|
65045
|
+
this.timeoutMs = timeoutMs;
|
|
65046
|
+
this.now = now;
|
|
65047
|
+
}
|
|
65048
|
+
deps;
|
|
65049
|
+
timeoutMs;
|
|
65050
|
+
now;
|
|
65051
|
+
cache = /* @__PURE__ */ new Map();
|
|
65052
|
+
async lookup(ip) {
|
|
65053
|
+
const hit = this.cache.get(ip);
|
|
65054
|
+
if (hit && this.now() - hit.at < 6 * 60 * 60 * 1e3) return hit.v;
|
|
65055
|
+
const originName = cymruOriginName2(ip);
|
|
65056
|
+
const [names, origin] = await Promise.all([
|
|
65057
|
+
withTimeout2(this.deps.reverse(normalizeIp2(ip)), this.timeoutMs),
|
|
65058
|
+
originName ? withTimeout2(this.deps.txt(originName), this.timeoutMs) : Promise.resolve(null)
|
|
65059
|
+
]);
|
|
65060
|
+
const o = origin?.[0] ? parseCymruOrigin2(origin[0].join("")) : null;
|
|
65061
|
+
let asOrg = null;
|
|
65062
|
+
if (o) {
|
|
65063
|
+
const named = await withTimeout2(this.deps.txt(`AS${o.asn}.asn.cymru.com`), this.timeoutMs);
|
|
65064
|
+
asOrg = named?.[0] ? parseCymruAsName(named[0].join("")) : null;
|
|
65065
|
+
}
|
|
65066
|
+
const v = { rdns: names?.[0]?.slice(0, 253) ?? null, asn: o?.asn ?? null, as_org: asOrg, country: o?.country ?? null };
|
|
65067
|
+
if (this.cache.size > 2e3) this.cache.clear();
|
|
65068
|
+
this.cache.set(ip, { at: this.now(), v });
|
|
65069
|
+
return v;
|
|
65070
|
+
}
|
|
65071
|
+
};
|
|
65072
|
+
|
|
65073
|
+
// src/daemon/ssh-context/ci-deploy.ts
|
|
65074
|
+
var import_node_child_process24 = require("child_process");
|
|
65075
|
+
var SECRETISH = /\b([A-Za-z_]*(?:token|secret|password|passwd|apikey|api_key|key|auth)[A-Za-z_]*)=("[^"]*"|'[^']*'|\S+)/gi;
|
|
65076
|
+
function redactCommand(cmd) {
|
|
65077
|
+
return cmd.replace(SECRETISH, "$1=[redacted]").slice(0, 300);
|
|
65078
|
+
}
|
|
65079
|
+
function parseCiDeployMessage(message) {
|
|
65080
|
+
const m = /^\s*(ALLOW|DENY|DENIED|REJECT(?:ED)?)\b\s*(?:\(([^)]*)\))?(.*)$/i.exec(message);
|
|
65081
|
+
if (!m) return null;
|
|
65082
|
+
const rest = m[3] ?? "";
|
|
65083
|
+
const repo = /\brepo=(\S+)/.exec(rest)?.[1];
|
|
65084
|
+
const from = /\bfrom=(\S+)/.exec(rest)?.[1];
|
|
65085
|
+
const cmd = /\bcmd=(.*)$/.exec(rest)?.[1]?.trim();
|
|
65086
|
+
return {
|
|
65087
|
+
decision: m[1].toUpperCase().startsWith("ALLOW") ? "ALLOW" : "DENY",
|
|
65088
|
+
...m[2] ? { action: m[2].trim().slice(0, 200) } : {},
|
|
65089
|
+
...repo ? { repo: repo.slice(0, 200) } : {},
|
|
65090
|
+
...from ? { from } : {},
|
|
65091
|
+
...cmd ? { command: redactCommand(cmd) } : {}
|
|
65092
|
+
};
|
|
65093
|
+
}
|
|
65094
|
+
function parseCiDeployJournal(text, tag = "ci-deploy") {
|
|
65095
|
+
const out = [];
|
|
65096
|
+
const esc = tag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
65097
|
+
const re = new RegExp(`^(\\d+(?:\\.\\d+)?)\\s+\\S+\\s+${esc}(?:\\[\\d+\\])?:\\s(.*)$`);
|
|
65098
|
+
for (const line2 of text.split("\n")) {
|
|
65099
|
+
const m = re.exec(line2);
|
|
65100
|
+
if (!m) continue;
|
|
65101
|
+
const parsed = parseCiDeployMessage(m[2]);
|
|
65102
|
+
if (!parsed) continue;
|
|
65103
|
+
const atMs = Math.round(Number(m[1]) * 1e3);
|
|
65104
|
+
out.push({ ...parsed, atMs, at: new Date(atMs).toISOString() });
|
|
65105
|
+
}
|
|
65106
|
+
return out;
|
|
65107
|
+
}
|
|
65108
|
+
function pickCiDeploy(lines, ip, atMs) {
|
|
65109
|
+
const near = lines.filter((l) => l.from === ip && l.atMs !== void 0 && l.atMs >= atMs - 5e3 && l.atMs <= atMs + 6e4).sort((a, b) => Math.abs(a.atMs - atMs) - Math.abs(b.atMs - atMs));
|
|
65110
|
+
if (!near.length) return null;
|
|
65111
|
+
const { from: _from, atMs: _at, ...ctx } = near[0];
|
|
65112
|
+
return ctx;
|
|
65113
|
+
}
|
|
65114
|
+
var realJournal = (args) => new Promise((resolve9) => {
|
|
65115
|
+
(0, import_node_child_process24.execFile)("journalctl", args, { timeout: 4e3, maxBuffer: 1024 * 1024, encoding: "utf-8" }, (err, stdout) => resolve9(err ? null : stdout));
|
|
65116
|
+
});
|
|
65117
|
+
async function findCiDeploy(ip, atMs, tag = "ci-deploy", run3 = realJournal) {
|
|
65118
|
+
const s = Math.floor(atMs / 1e3);
|
|
65119
|
+
const out = await run3(["-t", tag, `--since=@${s - 5}`, `--until=@${s + 60}`, "-o", "short-unix", "--no-pager", "-q"]);
|
|
65120
|
+
return out ? pickCiDeploy(parseCiDeployJournal(out, tag), ip, atMs) : null;
|
|
65121
|
+
}
|
|
65122
|
+
|
|
65123
|
+
// src/daemon/ssh-context/index.ts
|
|
65124
|
+
function sshContextSettings(s) {
|
|
65125
|
+
const settle2 = Number(s?.settle_ms);
|
|
65126
|
+
const win = Number(s?.failure_window_seconds);
|
|
65127
|
+
return {
|
|
65128
|
+
enabled: s?.enabled !== false,
|
|
65129
|
+
networkLookups: s?.network_lookups !== false,
|
|
65130
|
+
githubRanges: s?.github_actions_ranges !== false,
|
|
65131
|
+
expectedKeys: new Set((Array.isArray(s?.expected_keys) ? s.expected_keys : []).map(String).filter((k) => k.startsWith("SHA256:"))),
|
|
65132
|
+
ciDeployTag: typeof s?.ci_deploy_tag === "string" && /^[\w.-]{1,64}$/.test(s.ci_deploy_tag) ? s.ci_deploy_tag : "ci-deploy",
|
|
65133
|
+
failureWindowS: Number.isFinite(win) && win >= 60 && win <= 86400 ? win : 600,
|
|
65134
|
+
settleMs: Number.isFinite(settle2) && settle2 >= 0 ? Math.min(settle2, 2e4) : 5e3
|
|
65135
|
+
};
|
|
65136
|
+
}
|
|
65137
|
+
function isAcceptedLogin(event) {
|
|
65138
|
+
return event.module === "ssh-guard" && /SSH login accepted/.test(event.message) && !!event.source_ip;
|
|
65139
|
+
}
|
|
65140
|
+
var SshLoginEnricher = class {
|
|
65141
|
+
constructor(settings, deps = {}) {
|
|
65142
|
+
this.settings = settings;
|
|
65143
|
+
this.deps = deps;
|
|
65144
|
+
const now = deps.now ?? Date.now;
|
|
65145
|
+
this.history = deps.history ?? new SshAuthHistory(now);
|
|
65146
|
+
this.keys = deps.keys ?? new AuthorizedKeysIndex();
|
|
65147
|
+
this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0, import_node_path45.join)(deps.stateDir ?? ".", "github-actions-ranges.json")), settings.githubRanges);
|
|
65148
|
+
this.net = deps.net ?? new NetLookup();
|
|
65149
|
+
this.sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
65150
|
+
this.host = deps.host ?? (0, import_node_os21.hostname)();
|
|
65151
|
+
const own = deps.own ?? (() => {
|
|
65152
|
+
if (now() - this.ownCache.at > 6e4) this.ownCache = { at: now(), v: ownAddresses() };
|
|
65153
|
+
return this.ownCache.v;
|
|
65154
|
+
});
|
|
65155
|
+
this.classifier = { own, isGitHubActions: (ip) => this.ranges.has(ip) };
|
|
65156
|
+
}
|
|
65157
|
+
settings;
|
|
65158
|
+
deps;
|
|
65159
|
+
history;
|
|
65160
|
+
keys;
|
|
65161
|
+
ranges;
|
|
65162
|
+
net;
|
|
65163
|
+
classifier;
|
|
65164
|
+
sleep;
|
|
65165
|
+
host;
|
|
65166
|
+
ownCache = { at: -Infinity, v: /* @__PURE__ */ new Set() };
|
|
65167
|
+
/** Warm the GitHub ranges at start-up; safe to call any time. */
|
|
65168
|
+
start() {
|
|
65169
|
+
if (this.settings.enabled) void this.ranges.refresh();
|
|
65170
|
+
}
|
|
65171
|
+
recordSshd(line2) {
|
|
65172
|
+
if (this.settings.enabled) this.history.record(line2);
|
|
65173
|
+
}
|
|
65174
|
+
wants(event) {
|
|
65175
|
+
return this.settings.enabled && isAcceptedLogin(event) && !("ssh_context" in (event.details ?? {}));
|
|
65176
|
+
}
|
|
65177
|
+
/** Adds `details.ssh_context` to the event in place and returns it. Never throws. */
|
|
65178
|
+
async enrich(event) {
|
|
65179
|
+
try {
|
|
65180
|
+
const d = event.details ??= {};
|
|
65181
|
+
const ip = normalizeIp2(event.source_ip ?? "");
|
|
65182
|
+
const atMs = event.timestamp instanceof Date ? event.timestamp.getTime() : Date.now();
|
|
65183
|
+
const user = typeof d.ssh_user === "string" ? d.ssh_user : /SSH login accepted for (\S+)/.exec(event.message)?.[1];
|
|
65184
|
+
const method = typeof d.auth_method === "string" ? d.auth_method : void 0;
|
|
65185
|
+
const fp = typeof d.fingerprint === "string" && d.fingerprint.startsWith("SHA256:") ? d.fingerprint : void 0;
|
|
65186
|
+
const port = typeof d.port === "number" ? d.port : Number(d.port) || void 0;
|
|
65187
|
+
await this.ranges.refresh();
|
|
65188
|
+
const kind = classifyAddress(ip, this.classifier);
|
|
65189
|
+
const key = fp ? this.keys.lookup(fp, this.settings.expectedKeys) : void 0;
|
|
65190
|
+
if (key && !key.type && typeof d.key_type === "string") key.type = d.key_type;
|
|
65191
|
+
const failures = this.history.failuresBefore(atMs, ip, this.settings.failureWindowS);
|
|
65192
|
+
const netP = this.settings.networkLookups && (kind === "public" || kind === "github-actions") ? this.net.lookup(ip).catch(() => null) : Promise.resolve(null);
|
|
65193
|
+
const settle2 = this.sleep(this.settings.settleMs);
|
|
65194
|
+
const [net] = await Promise.all([netP, settle2]);
|
|
65195
|
+
const ci = key?.command ? await findCiDeploy(ip, atMs, this.settings.ciDeployTag, this.deps.journal).catch(() => null) : null;
|
|
65196
|
+
const closed = this.history.closeOf(ip, port, atMs);
|
|
65197
|
+
let tz;
|
|
65198
|
+
try {
|
|
65199
|
+
tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
65200
|
+
} catch {
|
|
65201
|
+
tz = void 0;
|
|
65202
|
+
}
|
|
65203
|
+
const base = {
|
|
65204
|
+
v: 1,
|
|
65205
|
+
at: new Date(atMs).toISOString(),
|
|
65206
|
+
host: this.host,
|
|
65207
|
+
tz_offset_min: -new Date(atMs).getTimezoneOffset(),
|
|
65208
|
+
...tz ? { tz } : {},
|
|
65209
|
+
...user ? { user } : {},
|
|
65210
|
+
...method ? { auth_method: method } : {},
|
|
65211
|
+
...port ? { port } : {},
|
|
65212
|
+
...key ? { key } : {},
|
|
65213
|
+
source: { ip, kind, ...net ?? {} },
|
|
65214
|
+
failures,
|
|
65215
|
+
session: {
|
|
65216
|
+
...ci ? { ci_deploy: ci } : {},
|
|
65217
|
+
...closed !== null ? { closed_at: new Date(closed).toISOString(), duration_s: Math.max(0, Math.round((closed - atMs) / 1e3)) } : { open: true }
|
|
65218
|
+
}
|
|
65219
|
+
};
|
|
65220
|
+
const ctx = { ...base, verdict: computeVerdict(base) };
|
|
65221
|
+
d.ssh_context = ctx;
|
|
65222
|
+
return ctx;
|
|
65223
|
+
} catch {
|
|
65224
|
+
return null;
|
|
65225
|
+
}
|
|
65226
|
+
}
|
|
65227
|
+
};
|
|
65228
|
+
|
|
65229
|
+
// src/daemon/rules/loader.ts
|
|
65230
|
+
var import_node_fs66 = require("fs");
|
|
65231
|
+
var import_node_path46 = require("path");
|
|
65232
|
+
|
|
64264
65233
|
// src/daemon/rules/default-rules.ts
|
|
64265
65234
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
64266
65235
|
var SSHD_IDENT = String.raw`\[sshd(?:-session|-auth)?\]`;
|
|
@@ -64293,12 +65262,16 @@ var DEFAULT_RULES = [
|
|
|
64293
65262
|
{
|
|
64294
65263
|
id: "ssh-success-after-failures",
|
|
64295
65264
|
title: "SSH Login Accepted",
|
|
64296
|
-
//
|
|
64297
|
-
//
|
|
64298
|
-
//
|
|
64299
|
-
//
|
|
65265
|
+
// Matches every accepted login, not only one after failures (the id is
|
|
65266
|
+
// kept for dashboards and incidents keyed on it). What came before it is
|
|
65267
|
+
// in the login's ssh_context: the failures in the window and whether they
|
|
65268
|
+
// came from the same address. With [ssh_context] on (the default) the
|
|
65269
|
+
// detection's severity is the context's verdict: a GitHub Actions deploy
|
|
65270
|
+
// with a forced-command key is low, an operator-expected CI key is info,
|
|
65271
|
+
// an unrestricted key from the internet stays critical. It declares no
|
|
65272
|
+
// remediation: banning the person who just logged in is never the answer.
|
|
64300
65273
|
description: "Successful SSH login (alert only \u2014 never grounds for a ban)",
|
|
64301
|
-
version: "1.
|
|
65274
|
+
version: "1.1.0",
|
|
64302
65275
|
category: "auth",
|
|
64303
65276
|
severity: "critical",
|
|
64304
65277
|
source_types: ["ssh-guard", "auth"],
|
|
@@ -64310,7 +65283,7 @@ var DEFAULT_RULES = [
|
|
|
64310
65283
|
threshold: 1,
|
|
64311
65284
|
window_seconds: 60,
|
|
64312
65285
|
cooldown_seconds: 300,
|
|
64313
|
-
tags: ["ssh", "compromise-indicator"],
|
|
65286
|
+
tags: ["ssh", "compromise-indicator", "ssh-login-verdict"],
|
|
64314
65287
|
enabled: true
|
|
64315
65288
|
},
|
|
64316
65289
|
{
|
|
@@ -64931,16 +65904,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
64931
65904
|
function loadAllRules(customDir) {
|
|
64932
65905
|
const rules = [...DEFAULT_RULES];
|
|
64933
65906
|
const dir = customDir || RULES_DIR;
|
|
64934
|
-
if ((0,
|
|
65907
|
+
if ((0, import_node_fs66.existsSync)(dir)) {
|
|
64935
65908
|
let files = [];
|
|
64936
65909
|
try {
|
|
64937
|
-
files = (0,
|
|
65910
|
+
files = (0, import_node_fs66.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
64938
65911
|
} catch (err) {
|
|
64939
65912
|
console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
|
|
64940
65913
|
}
|
|
64941
65914
|
for (const file of files) {
|
|
64942
65915
|
try {
|
|
64943
|
-
const raw = (0,
|
|
65916
|
+
const raw = (0, import_node_fs66.readFileSync)((0, import_node_path46.join)(dir, file), "utf-8");
|
|
64944
65917
|
const parsed = JSON.parse(raw);
|
|
64945
65918
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
64946
65919
|
for (const rule of customRules) {
|
|
@@ -64971,24 +65944,24 @@ function loadAllRules(customDir) {
|
|
|
64971
65944
|
}
|
|
64972
65945
|
|
|
64973
65946
|
// src/daemon/firewall/adapters.ts
|
|
64974
|
-
var
|
|
64975
|
-
var
|
|
64976
|
-
var
|
|
64977
|
-
var
|
|
65947
|
+
var import_node_child_process25 = require("child_process");
|
|
65948
|
+
var import_node_fs67 = require("fs");
|
|
65949
|
+
var import_node_path47 = require("path");
|
|
65950
|
+
var import_node_net23 = require("net");
|
|
64978
65951
|
function assertValidFirewallIp(ip) {
|
|
64979
|
-
if ((0,
|
|
65952
|
+
if ((0, import_node_net23.isIP)(ip) !== 4) {
|
|
64980
65953
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
64981
65954
|
}
|
|
64982
65955
|
}
|
|
64983
65956
|
function assertBannableIp(ip) {
|
|
64984
|
-
if ((0,
|
|
65957
|
+
if ((0, import_node_net23.isIP)(ip) === 0) {
|
|
64985
65958
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
64986
65959
|
}
|
|
64987
65960
|
}
|
|
64988
65961
|
function writeIfAbsent(path2, contents) {
|
|
64989
|
-
(0,
|
|
65962
|
+
(0, import_node_fs67.mkdirSync)((0, import_node_path47.dirname)(path2), { recursive: true });
|
|
64990
65963
|
try {
|
|
64991
|
-
(0,
|
|
65964
|
+
(0, import_node_fs67.writeFileSync)(path2, contents, { flag: "wx" });
|
|
64992
65965
|
} catch (err) {
|
|
64993
65966
|
if (err.code !== "EEXIST") throw err;
|
|
64994
65967
|
}
|
|
@@ -65007,11 +65980,11 @@ var Fail2banAdapter = class {
|
|
|
65007
65980
|
enforces = true;
|
|
65008
65981
|
jailReady = false;
|
|
65009
65982
|
isAvailable() {
|
|
65010
|
-
const result = (0,
|
|
65983
|
+
const result = (0, import_node_child_process25.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
65011
65984
|
return result.status === 0;
|
|
65012
65985
|
}
|
|
65013
65986
|
client(args) {
|
|
65014
|
-
return (0,
|
|
65987
|
+
return (0, import_node_child_process25.execFileSync)("fail2ban-client", args, {
|
|
65015
65988
|
encoding: "utf-8",
|
|
65016
65989
|
stdio: ["ignore", "pipe", "pipe"]
|
|
65017
65990
|
});
|
|
@@ -65087,7 +66060,7 @@ var Fail2banAdapter = class {
|
|
|
65087
66060
|
const status = this.client(["status", this.jail]);
|
|
65088
66061
|
const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
65089
66062
|
if (!line2) return [];
|
|
65090
|
-
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
66063
|
+
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
|
|
65091
66064
|
} catch {
|
|
65092
66065
|
return [];
|
|
65093
66066
|
}
|
|
@@ -65097,45 +66070,45 @@ var Fail2banAdapter = class {
|
|
|
65097
66070
|
function parseBannedList(output) {
|
|
65098
66071
|
const found = [];
|
|
65099
66072
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
65100
|
-
if ((0,
|
|
66073
|
+
if ((0, import_node_net23.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
65101
66074
|
}
|
|
65102
66075
|
if (found.length > 0) return found;
|
|
65103
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
66076
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
|
|
65104
66077
|
}
|
|
65105
66078
|
var NftablesAdapter = class {
|
|
65106
66079
|
name = "nftables";
|
|
65107
66080
|
table = "threatcrush";
|
|
65108
66081
|
set = "blocklist";
|
|
65109
66082
|
isAvailable() {
|
|
65110
|
-
const result = (0,
|
|
66083
|
+
const result = (0, import_node_child_process25.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
65111
66084
|
return result.status === 0;
|
|
65112
66085
|
}
|
|
65113
66086
|
ensureSetup() {
|
|
65114
66087
|
try {
|
|
65115
|
-
(0,
|
|
66088
|
+
(0, import_node_child_process25.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
65116
66089
|
} catch {
|
|
65117
|
-
(0,
|
|
65118
|
-
(0,
|
|
65119
|
-
(0,
|
|
65120
|
-
(0,
|
|
66090
|
+
(0, import_node_child_process25.execSync)(`nft add table inet ${this.table}`);
|
|
66091
|
+
(0, import_node_child_process25.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
66092
|
+
(0, import_node_child_process25.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
66093
|
+
(0, import_node_child_process25.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
65121
66094
|
}
|
|
65122
66095
|
}
|
|
65123
66096
|
async block(ip) {
|
|
65124
66097
|
assertValidFirewallIp(ip);
|
|
65125
66098
|
this.ensureSetup();
|
|
65126
|
-
(0,
|
|
66099
|
+
(0, import_node_child_process25.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
65127
66100
|
}
|
|
65128
66101
|
async unblock(ip) {
|
|
65129
66102
|
assertValidFirewallIp(ip);
|
|
65130
66103
|
try {
|
|
65131
|
-
(0,
|
|
66104
|
+
(0, import_node_child_process25.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
65132
66105
|
} catch {
|
|
65133
66106
|
}
|
|
65134
66107
|
}
|
|
65135
66108
|
async isBlocked(ip) {
|
|
65136
66109
|
assertValidFirewallIp(ip);
|
|
65137
66110
|
try {
|
|
65138
|
-
const output = (0,
|
|
66111
|
+
const output = (0, import_node_child_process25.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
65139
66112
|
return output.includes(ip);
|
|
65140
66113
|
} catch {
|
|
65141
66114
|
return false;
|
|
@@ -65143,7 +66116,7 @@ var NftablesAdapter = class {
|
|
|
65143
66116
|
}
|
|
65144
66117
|
async listBlocked() {
|
|
65145
66118
|
try {
|
|
65146
|
-
const output = (0,
|
|
66119
|
+
const output = (0, import_node_child_process25.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
65147
66120
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
65148
66121
|
if (!match) return [];
|
|
65149
66122
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -65156,34 +66129,34 @@ var IptablesAdapter = class {
|
|
|
65156
66129
|
name = "iptables";
|
|
65157
66130
|
chain = "THREATCRUSH";
|
|
65158
66131
|
isAvailable() {
|
|
65159
|
-
const result = (0,
|
|
66132
|
+
const result = (0, import_node_child_process25.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
65160
66133
|
return result.status === 0;
|
|
65161
66134
|
}
|
|
65162
66135
|
ensureChain() {
|
|
65163
66136
|
try {
|
|
65164
|
-
(0,
|
|
66137
|
+
(0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
65165
66138
|
} catch {
|
|
65166
|
-
(0,
|
|
65167
|
-
(0,
|
|
66139
|
+
(0, import_node_child_process25.execSync)(`iptables -N ${this.chain}`);
|
|
66140
|
+
(0, import_node_child_process25.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
65168
66141
|
}
|
|
65169
66142
|
}
|
|
65170
66143
|
async block(ip) {
|
|
65171
66144
|
assertValidFirewallIp(ip);
|
|
65172
66145
|
this.ensureChain();
|
|
65173
66146
|
if (await this.isBlocked(ip)) return;
|
|
65174
|
-
(0,
|
|
66147
|
+
(0, import_node_child_process25.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
65175
66148
|
}
|
|
65176
66149
|
async unblock(ip) {
|
|
65177
66150
|
assertValidFirewallIp(ip);
|
|
65178
66151
|
try {
|
|
65179
|
-
(0,
|
|
66152
|
+
(0, import_node_child_process25.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
65180
66153
|
} catch {
|
|
65181
66154
|
}
|
|
65182
66155
|
}
|
|
65183
66156
|
async isBlocked(ip) {
|
|
65184
66157
|
assertValidFirewallIp(ip);
|
|
65185
66158
|
try {
|
|
65186
|
-
const output = (0,
|
|
66159
|
+
const output = (0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
65187
66160
|
return output.includes(ip);
|
|
65188
66161
|
} catch {
|
|
65189
66162
|
return false;
|
|
@@ -65191,7 +66164,7 @@ var IptablesAdapter = class {
|
|
|
65191
66164
|
}
|
|
65192
66165
|
async listBlocked() {
|
|
65193
66166
|
try {
|
|
65194
|
-
const output = (0,
|
|
66167
|
+
const output = (0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
65195
66168
|
const ips = [];
|
|
65196
66169
|
for (const line2 of output.split("\n")) {
|
|
65197
66170
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -65247,22 +66220,22 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
65247
66220
|
}
|
|
65248
66221
|
|
|
65249
66222
|
// src/daemon/firewall/remediation.ts
|
|
65250
|
-
var
|
|
65251
|
-
var
|
|
65252
|
-
var
|
|
66223
|
+
var import_node_fs68 = require("fs");
|
|
66224
|
+
var import_node_child_process26 = require("child_process");
|
|
66225
|
+
var import_node_net24 = require("net");
|
|
65253
66226
|
init_paths();
|
|
65254
66227
|
init_backoff();
|
|
65255
66228
|
|
|
65256
66229
|
// src/daemon/firewall/crawlers.ts
|
|
65257
|
-
var
|
|
66230
|
+
var import_node_dns3 = require("dns");
|
|
65258
66231
|
var CRAWLER_DOMAINS = ["googlebot.com", "google.com", "search.msn.com", "applebot.apple.com"];
|
|
65259
66232
|
var systemResolver = {
|
|
65260
|
-
reverse: (ip) =>
|
|
65261
|
-
lookup: async (host) => (await
|
|
66233
|
+
reverse: (ip) => import_node_dns3.promises.reverse(ip),
|
|
66234
|
+
lookup: async (host) => (await import_node_dns3.promises.lookup(host, { all: true })).map((a) => a.address)
|
|
65262
66235
|
};
|
|
65263
66236
|
var TIMEOUT_MS2 = 2e3;
|
|
65264
66237
|
var CACHE_MS = 6 * 36e5;
|
|
65265
|
-
function
|
|
66238
|
+
function withTimeout3(p) {
|
|
65266
66239
|
return Promise.race([
|
|
65267
66240
|
p,
|
|
65268
66241
|
new Promise((_, reject) => setTimeout(() => reject(new Error("dns timeout")), TIMEOUT_MS2).unref())
|
|
@@ -65279,9 +66252,9 @@ function crawlerVerifier(resolver = systemResolver) {
|
|
|
65279
66252
|
if (hit && hit.until > Date.now()) return hit.host;
|
|
65280
66253
|
let host = null;
|
|
65281
66254
|
try {
|
|
65282
|
-
const names = await
|
|
66255
|
+
const names = await withTimeout3(resolver.reverse(ip));
|
|
65283
66256
|
for (const name of names.filter(inCrawlerDomain)) {
|
|
65284
|
-
const addrs = await
|
|
66257
|
+
const addrs = await withTimeout3(resolver.lookup(name));
|
|
65285
66258
|
if (addrs.includes(ip)) {
|
|
65286
66259
|
host = name.replace(/\.$/, "");
|
|
65287
66260
|
break;
|
|
@@ -65319,19 +66292,19 @@ var defaultDiscovery = {
|
|
|
65319
66292
|
const snapshot = takeSnapshot({
|
|
65320
66293
|
readFile: (p) => {
|
|
65321
66294
|
try {
|
|
65322
|
-
return (0,
|
|
66295
|
+
return (0, import_node_fs68.readFileSync)(p, "utf-8");
|
|
65323
66296
|
} catch {
|
|
65324
66297
|
return null;
|
|
65325
66298
|
}
|
|
65326
66299
|
},
|
|
65327
66300
|
readDir: (p) => {
|
|
65328
66301
|
try {
|
|
65329
|
-
return (0,
|
|
66302
|
+
return (0, import_node_fs68.readdirSync)(p);
|
|
65330
66303
|
} catch {
|
|
65331
66304
|
return null;
|
|
65332
66305
|
}
|
|
65333
66306
|
},
|
|
65334
|
-
exists: (p) => (0,
|
|
66307
|
+
exists: (p) => (0, import_node_fs68.existsSync)(p)
|
|
65335
66308
|
});
|
|
65336
66309
|
const out = /* @__PURE__ */ new Set();
|
|
65337
66310
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -65340,7 +66313,7 @@ var defaultDiscovery = {
|
|
|
65340
66313
|
return out;
|
|
65341
66314
|
},
|
|
65342
66315
|
keyLoginJournal: (sinceSeconds) => new Promise((resolve9) => {
|
|
65343
|
-
(0,
|
|
66316
|
+
(0, import_node_child_process26.execFile)(
|
|
65344
66317
|
"journalctl",
|
|
65345
66318
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
65346
66319
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
@@ -65420,7 +66393,7 @@ var RemediationManager = class {
|
|
|
65420
66393
|
setTorExitCheck(check2) {
|
|
65421
66394
|
this.isTorExit = check2;
|
|
65422
66395
|
let dropped = 0;
|
|
65423
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
66396
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net24.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
65424
66397
|
for (const ip of Object.keys(this.operators)) {
|
|
65425
66398
|
if (!check2(ip)) continue;
|
|
65426
66399
|
delete this.operators[ip];
|
|
@@ -65513,7 +66486,7 @@ var RemediationManager = class {
|
|
|
65513
66486
|
if (remediation?.action !== "block") return;
|
|
65514
66487
|
}
|
|
65515
66488
|
const ip = event.source_ip;
|
|
65516
|
-
if (!ip || (0,
|
|
66489
|
+
if (!ip || (0, import_node_net24.isIP)(ip) === 0) return;
|
|
65517
66490
|
const strict = remediation?.override_operator_protection === true;
|
|
65518
66491
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
65519
66492
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -65542,7 +66515,7 @@ var RemediationManager = class {
|
|
|
65542
66515
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
65543
66516
|
*/
|
|
65544
66517
|
async ban(ip, reason, opts = {}) {
|
|
65545
|
-
if ((0,
|
|
66518
|
+
if ((0, import_node_net24.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
65546
66519
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
65547
66520
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
65548
66521
|
}
|
|
@@ -65819,7 +66792,7 @@ var RemediationManager = class {
|
|
|
65819
66792
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
65820
66793
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
65821
66794
|
for (const [ip, at] of Object.entries(saved)) {
|
|
65822
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
66795
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net24.isIP)(ip)) continue;
|
|
65823
66796
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
65824
66797
|
this.operators[ip] = at;
|
|
65825
66798
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -65844,7 +66817,7 @@ var RemediationManager = class {
|
|
|
65844
66817
|
}
|
|
65845
66818
|
logLine(line2) {
|
|
65846
66819
|
try {
|
|
65847
|
-
(0,
|
|
66820
|
+
(0, import_node_fs68.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
65848
66821
|
`);
|
|
65849
66822
|
} catch {
|
|
65850
66823
|
}
|
|
@@ -65888,19 +66861,19 @@ function remediationSettings(section) {
|
|
|
65888
66861
|
init_backoff();
|
|
65889
66862
|
|
|
65890
66863
|
// src/daemon/watchdog-service.ts
|
|
65891
|
-
var
|
|
65892
|
-
var
|
|
66864
|
+
var import_node_fs69 = require("fs");
|
|
66865
|
+
var import_node_path48 = require("path");
|
|
65893
66866
|
function defaultShareGid() {
|
|
65894
66867
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
65895
66868
|
if (!isRoot4) return void 0;
|
|
65896
66869
|
try {
|
|
65897
|
-
return (0,
|
|
66870
|
+
return (0, import_node_fs69.statSync)("/var/log/auth.log").gid;
|
|
65898
66871
|
} catch {
|
|
65899
66872
|
return void 0;
|
|
65900
66873
|
}
|
|
65901
66874
|
}
|
|
65902
66875
|
function startWatchdog(opts) {
|
|
65903
|
-
const dir = opts.config?.dir ?? (0,
|
|
66876
|
+
const dir = opts.config?.dir ?? (0, import_node_path48.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
65904
66877
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
65905
66878
|
if (opts.config?.enabled === false) {
|
|
65906
66879
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -65994,7 +66967,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
65994
66967
|
}
|
|
65995
66968
|
|
|
65996
66969
|
// src/core/node-runtime.ts
|
|
65997
|
-
var
|
|
66970
|
+
var import_node_child_process27 = require("child_process");
|
|
65998
66971
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
65999
66972
|
function nodeMajor(version) {
|
|
66000
66973
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -66008,23 +66981,23 @@ function daemonNodeProblem(version) {
|
|
|
66008
66981
|
}
|
|
66009
66982
|
function versionOfNode(path2) {
|
|
66010
66983
|
if (path2 === process.execPath) return process.versions.node;
|
|
66011
|
-
const res = (0,
|
|
66984
|
+
const res = (0, import_node_child_process27.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
66012
66985
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
66013
66986
|
}
|
|
66014
66987
|
|
|
66015
66988
|
// src/daemon/index.ts
|
|
66016
66989
|
function readVersion2() {
|
|
66017
66990
|
try {
|
|
66018
|
-
const pkg = JSON.parse((0,
|
|
66991
|
+
const pkg = JSON.parse((0, import_node_fs70.readFileSync)((0, import_node_path49.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
66019
66992
|
return pkg.version || "0.0.0";
|
|
66020
66993
|
} catch {
|
|
66021
66994
|
return "0.0.0";
|
|
66022
66995
|
}
|
|
66023
66996
|
}
|
|
66024
66997
|
async function runHardeningChecks() {
|
|
66025
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
66998
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process28.execFile)(
|
|
66026
66999
|
process.execPath,
|
|
66027
|
-
[(0,
|
|
67000
|
+
[(0, import_node_path49.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
66028
67001
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
66029
67002
|
);
|
|
66030
67003
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -66036,9 +67009,9 @@ async function runHardeningChecks() {
|
|
|
66036
67009
|
return patches ? [...findings2, patches] : findings2;
|
|
66037
67010
|
}
|
|
66038
67011
|
async function runPatchCheck() {
|
|
66039
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
67012
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process28.execFile)(
|
|
66040
67013
|
process.execPath,
|
|
66041
|
-
[(0,
|
|
67014
|
+
[(0, import_node_path49.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
66042
67015
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
66043
67016
|
);
|
|
66044
67017
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -66046,7 +67019,7 @@ async function runPatchCheck() {
|
|
|
66046
67019
|
}
|
|
66047
67020
|
function logLine(line2) {
|
|
66048
67021
|
try {
|
|
66049
|
-
(0,
|
|
67022
|
+
(0, import_node_fs70.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
66050
67023
|
`);
|
|
66051
67024
|
} catch {
|
|
66052
67025
|
}
|
|
@@ -66071,9 +67044,9 @@ async function runDaemon() {
|
|
|
66071
67044
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
66072
67045
|
const restartDaemon = () => {
|
|
66073
67046
|
if (PATHS.mode === "system") {
|
|
66074
|
-
(0,
|
|
67047
|
+
(0, import_node_child_process28.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
66075
67048
|
} else {
|
|
66076
|
-
(0,
|
|
67049
|
+
(0, import_node_child_process28.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
66077
67050
|
setTimeout(() => process.exit(0), 500).unref();
|
|
66078
67051
|
}
|
|
66079
67052
|
};
|
|
@@ -66088,7 +67061,7 @@ async function runDaemon() {
|
|
|
66088
67061
|
} catch (err) {
|
|
66089
67062
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
66090
67063
|
}
|
|
66091
|
-
const loaded = loadDaemonConfig(PATHS.configFile, (0,
|
|
67064
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path49.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
66092
67065
|
const config = loaded.config;
|
|
66093
67066
|
if (loaded.error) {
|
|
66094
67067
|
logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
|
|
@@ -66112,27 +67085,37 @@ async function runDaemon() {
|
|
|
66112
67085
|
const moduleHost = new ModuleHost(bus);
|
|
66113
67086
|
await moduleHost.start();
|
|
66114
67087
|
const ruleEngine = new RuleEngine((detection) => {
|
|
67088
|
+
const ctx = detection.raw_metadata?.evidence?.ssh_context;
|
|
67089
|
+
const useVerdict = !!ctx?.verdict && Array.isArray(detection.raw_metadata?.tags) && detection.raw_metadata.tags.includes("ssh-login-verdict");
|
|
66115
67090
|
const event = {
|
|
66116
67091
|
timestamp: /* @__PURE__ */ new Date(),
|
|
66117
67092
|
module: "rule-engine",
|
|
66118
67093
|
category: detection.raw_metadata?.category || "system",
|
|
66119
|
-
severity: detection.severity,
|
|
67094
|
+
severity: useVerdict ? ctx.verdict.severity : detection.severity,
|
|
66120
67095
|
message: `[DETECTION] ${detection.title}`,
|
|
66121
67096
|
source_ip: detection.source_ip,
|
|
66122
67097
|
details: {
|
|
66123
67098
|
rule_id: detection.rule_id,
|
|
66124
|
-
description: detection.description,
|
|
67099
|
+
description: useVerdict ? [ctx.verdict.summary, describeFailures(ctx.failures, ctx.source?.ip)].filter(Boolean).join(". ") : detection.description,
|
|
66125
67100
|
username: detection.username,
|
|
66126
|
-
...detection.raw_metadata
|
|
67101
|
+
...detection.raw_metadata,
|
|
67102
|
+
...useVerdict && ctx.verdict.severity !== detection.severity ? { rule_severity: detection.severity } : {}
|
|
66127
67103
|
}
|
|
66128
67104
|
};
|
|
66129
67105
|
bus.publish(event);
|
|
66130
67106
|
});
|
|
66131
67107
|
ruleEngine.loadRules(loadAllRules());
|
|
66132
67108
|
const keyDirectory = new KeyDirectory();
|
|
67109
|
+
const sshContext = new SshLoginEnricher(sshContextSettings(config.ssh_context), { stateDir: PATHS.stateDir });
|
|
67110
|
+
sshContext.start();
|
|
67111
|
+
bus.on("sshd", (line2) => sshContext.recordSshd(line2));
|
|
66133
67112
|
bus.on("event", (event) => {
|
|
66134
67113
|
if (event.module === "rule-engine") return;
|
|
66135
67114
|
enrichLoginEvent(event, keyDirectory);
|
|
67115
|
+
if (sshContext.wants(event)) {
|
|
67116
|
+
void sshContext.enrich(event).finally(() => ruleEngine.evaluate(event));
|
|
67117
|
+
return;
|
|
67118
|
+
}
|
|
66136
67119
|
ruleEngine.evaluate(event);
|
|
66137
67120
|
});
|
|
66138
67121
|
logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
|
|
@@ -66159,7 +67142,7 @@ async function runDaemon() {
|
|
|
66159
67142
|
const threatFeeds = new ThreatFeeds({
|
|
66160
67143
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
66161
67144
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
66162
|
-
cachePath: (0,
|
|
67145
|
+
cachePath: (0, import_node_path49.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
66163
67146
|
bus,
|
|
66164
67147
|
log: logLine
|
|
66165
67148
|
});
|
|
@@ -66167,9 +67150,9 @@ async function runDaemon() {
|
|
|
66167
67150
|
const privilegeWatch = new PrivilegeWatch({
|
|
66168
67151
|
settings: privilegeSettings(config.privileged),
|
|
66169
67152
|
bus,
|
|
66170
|
-
snapshotPath: (0,
|
|
66171
|
-
loginsPath: (0,
|
|
66172
|
-
cursorPath: (0,
|
|
67153
|
+
snapshotPath: (0, import_node_path49.join)(PATHS.stateDir, "privileges.json"),
|
|
67154
|
+
loginsPath: (0, import_node_path49.join)(PATHS.stateDir, "login-countries.json"),
|
|
67155
|
+
cursorPath: (0, import_node_path49.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
66173
67156
|
log: logLine
|
|
66174
67157
|
});
|
|
66175
67158
|
privilegeWatch.start();
|
|
@@ -66183,8 +67166,8 @@ async function runDaemon() {
|
|
|
66183
67166
|
const fileIntegrity = new FileIntegrityWatch({
|
|
66184
67167
|
bus,
|
|
66185
67168
|
settings: fileIntegritySettings(config.file_integrity),
|
|
66186
|
-
baselinePath: (0,
|
|
66187
|
-
observedPath: (0,
|
|
67169
|
+
baselinePath: (0, import_node_path49.join)(PATHS.stateDir, "file-integrity-baseline.json"),
|
|
67170
|
+
observedPath: (0, import_node_path49.join)(PATHS.stateDir, "file-integrity-observed.json"),
|
|
66188
67171
|
// `[remediation] dry_run` also covers the opt-in contain_writer response.
|
|
66189
67172
|
dryRun: () => remediation.status().dry_run,
|
|
66190
67173
|
log: logLine
|
|
@@ -66193,13 +67176,13 @@ async function runDaemon() {
|
|
|
66193
67176
|
const edr = new EdrWatch({
|
|
66194
67177
|
bus,
|
|
66195
67178
|
settings: edrSettings(config.edr),
|
|
66196
|
-
networkBaselinePath: (0,
|
|
66197
|
-
sourceStatusPath: (0,
|
|
67179
|
+
networkBaselinePath: (0, import_node_path49.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
67180
|
+
sourceStatusPath: (0, import_node_path49.join)(PATHS.stateDir, "edr-source.json"),
|
|
66198
67181
|
log: logLine
|
|
66199
67182
|
});
|
|
66200
67183
|
edr.start();
|
|
66201
67184
|
const torExits = new TorExitList({
|
|
66202
|
-
cachePath: (0,
|
|
67185
|
+
cachePath: (0, import_node_path49.join)(PATHS.stateDir, "tor-exits.txt"),
|
|
66203
67186
|
url: config.remediation?.tor_exit_list_url,
|
|
66204
67187
|
log: logLine
|
|
66205
67188
|
});
|
|
@@ -66207,7 +67190,7 @@ async function runDaemon() {
|
|
|
66207
67190
|
bus,
|
|
66208
67191
|
manager: remediation,
|
|
66209
67192
|
tor: torExits,
|
|
66210
|
-
historyPath: (0,
|
|
67193
|
+
historyPath: (0, import_node_path49.join)(PATHS.stateDir, "key-logins.json"),
|
|
66211
67194
|
keyLoginWatch: config.privileged?.key_login_watch !== false,
|
|
66212
67195
|
log: logLine
|
|
66213
67196
|
});
|
|
@@ -66280,9 +67263,9 @@ async function runDaemon() {
|
|
|
66280
67263
|
cloudSync = new CloudSync({
|
|
66281
67264
|
bus,
|
|
66282
67265
|
version,
|
|
66283
|
-
hostname: (0,
|
|
67266
|
+
hostname: (0, import_node_os22.hostname)(),
|
|
66284
67267
|
minSeverity,
|
|
66285
|
-
spoolPath: (0,
|
|
67268
|
+
spoolPath: (0, import_node_path49.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
66286
67269
|
log: logLine,
|
|
66287
67270
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
66288
67271
|
runHardening: runHardeningChecks
|
|
@@ -66316,8 +67299,8 @@ async function runDaemon() {
|
|
|
66316
67299
|
const autoUpdate = autoUpdateRef = new AutoUpdate({
|
|
66317
67300
|
version,
|
|
66318
67301
|
settings: updateSettings(config.update),
|
|
66319
|
-
pkgRoot: (0,
|
|
66320
|
-
statePath: (0,
|
|
67302
|
+
pkgRoot: (0, import_node_path49.join)(__dirname, ".."),
|
|
67303
|
+
statePath: (0, import_node_path49.join)(PATHS.stateDir, "auto-update.json"),
|
|
66321
67304
|
bus,
|
|
66322
67305
|
log: logLine,
|
|
66323
67306
|
restartDaemon
|
|
@@ -66439,7 +67422,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
66439
67422
|
function isRoot2() {
|
|
66440
67423
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
66441
67424
|
}
|
|
66442
|
-
var DAEMON_ENTRY = (0,
|
|
67425
|
+
var DAEMON_ENTRY = (0, import_node_path50.join)(__dirname, "daemon.js");
|
|
66443
67426
|
async function daemonForeground() {
|
|
66444
67427
|
await runDaemon();
|
|
66445
67428
|
}
|
|
@@ -66460,7 +67443,7 @@ async function daemonStart() {
|
|
|
66460
67443
|
return;
|
|
66461
67444
|
}
|
|
66462
67445
|
ensureRuntimeDirs();
|
|
66463
|
-
if (!(0,
|
|
67446
|
+
if (!(0, import_node_fs71.existsSync)(DAEMON_ENTRY)) {
|
|
66464
67447
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
66465
67448
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
66466
67449
|
return;
|
|
@@ -66468,8 +67451,8 @@ async function daemonStart() {
|
|
|
66468
67451
|
let out;
|
|
66469
67452
|
let err;
|
|
66470
67453
|
try {
|
|
66471
|
-
out = (0,
|
|
66472
|
-
err = (0,
|
|
67454
|
+
out = (0, import_node_fs72.openSync)(PATHS.logFile, "a");
|
|
67455
|
+
err = (0, import_node_fs72.openSync)(PATHS.logFile, "a");
|
|
66473
67456
|
} catch (e) {
|
|
66474
67457
|
const code = e.code;
|
|
66475
67458
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -66482,7 +67465,7 @@ async function daemonStart() {
|
|
|
66482
67465
|
}
|
|
66483
67466
|
return;
|
|
66484
67467
|
}
|
|
66485
|
-
const child = (0,
|
|
67468
|
+
const child = (0, import_node_child_process29.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
66486
67469
|
detached: true,
|
|
66487
67470
|
stdio: ["ignore", out, err],
|
|
66488
67471
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -66557,41 +67540,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
66557
67540
|
}
|
|
66558
67541
|
async function releaseStaleSocket() {
|
|
66559
67542
|
const deadline = Date.now() + 2e3;
|
|
66560
|
-
while ((0,
|
|
67543
|
+
while ((0, import_node_fs71.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
66561
67544
|
await new Promise((r) => setTimeout(r, 50));
|
|
66562
67545
|
}
|
|
66563
|
-
if ((0,
|
|
67546
|
+
if ((0, import_node_fs71.existsSync)(PATHS.socket)) {
|
|
66564
67547
|
try {
|
|
66565
|
-
(0,
|
|
67548
|
+
(0, import_node_fs71.unlinkSync)(PATHS.socket);
|
|
66566
67549
|
} catch {
|
|
66567
67550
|
}
|
|
66568
67551
|
}
|
|
66569
67552
|
}
|
|
66570
67553
|
|
|
66571
67554
|
// src/commands/service.ts
|
|
66572
|
-
var
|
|
66573
|
-
var
|
|
66574
|
-
var
|
|
66575
|
-
var
|
|
67555
|
+
var import_node_child_process30 = require("child_process");
|
|
67556
|
+
var import_node_fs73 = require("fs");
|
|
67557
|
+
var import_node_path51 = require("path");
|
|
67558
|
+
var import_node_os23 = require("os");
|
|
66576
67559
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
66577
67560
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
66578
67561
|
function resolveTemplate() {
|
|
66579
|
-
const templatePath = (0,
|
|
66580
|
-
if (!(0,
|
|
67562
|
+
const templatePath = (0, import_node_path51.join)(__dirname, "systemd", "threatcrushd.service");
|
|
67563
|
+
if (!(0, import_node_fs73.existsSync)(templatePath)) {
|
|
66581
67564
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
66582
67565
|
}
|
|
66583
|
-
return (0,
|
|
67566
|
+
return (0, import_node_fs73.readFileSync)(templatePath, "utf-8");
|
|
66584
67567
|
}
|
|
66585
67568
|
function stableBinPath(binPath) {
|
|
66586
67569
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
66587
67570
|
if (stable === binPath) return binPath;
|
|
66588
|
-
return (0,
|
|
67571
|
+
return (0, import_node_fs73.existsSync)(stable) ? stable : binPath;
|
|
66589
67572
|
}
|
|
66590
67573
|
function resolveBinPath() {
|
|
66591
67574
|
const arg = process.argv[1];
|
|
66592
|
-
if (arg && (0,
|
|
67575
|
+
if (arg && (0, import_node_fs73.existsSync)(arg)) return stableBinPath(arg);
|
|
66593
67576
|
try {
|
|
66594
|
-
return (0,
|
|
67577
|
+
return (0, import_node_child_process30.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
66595
67578
|
} catch {
|
|
66596
67579
|
return "threatcrush";
|
|
66597
67580
|
}
|
|
@@ -66599,11 +67582,11 @@ function resolveBinPath() {
|
|
|
66599
67582
|
function stableNodePath(execPath) {
|
|
66600
67583
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
66601
67584
|
if (stable === execPath) return execPath;
|
|
66602
|
-
return (0,
|
|
67585
|
+
return (0, import_node_fs73.existsSync)(stable) ? stable : execPath;
|
|
66603
67586
|
}
|
|
66604
67587
|
function looksLikeNodeScript(path2) {
|
|
66605
67588
|
try {
|
|
66606
|
-
const head2 = (0,
|
|
67589
|
+
const head2 = (0, import_node_fs73.readFileSync)(path2, "utf-8").slice(0, 120);
|
|
66607
67590
|
return /^#!.*\bnode\b/.test(head2);
|
|
66608
67591
|
} catch {
|
|
66609
67592
|
return false;
|
|
@@ -66631,20 +67614,20 @@ function isRoot3() {
|
|
|
66631
67614
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
66632
67615
|
}
|
|
66633
67616
|
function reexecWithSudo(args) {
|
|
66634
|
-
if ((0,
|
|
67617
|
+
if ((0, import_node_child_process30.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
66635
67618
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
66636
67619
|
const bin = resolveBinPath();
|
|
66637
67620
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
66638
|
-
const result = (0,
|
|
67621
|
+
const result = (0, import_node_child_process30.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
66639
67622
|
return result.status === 0;
|
|
66640
67623
|
}
|
|
66641
67624
|
function callerHome() {
|
|
66642
67625
|
const user = process.env.SUDO_USER;
|
|
66643
67626
|
if (!user) return null;
|
|
66644
67627
|
try {
|
|
66645
|
-
const line2 = (0,
|
|
67628
|
+
const line2 = (0, import_node_child_process30.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
66646
67629
|
const home = line2.split(":")[5];
|
|
66647
|
-
return home && (0,
|
|
67630
|
+
return home && (0, import_node_fs73.existsSync)(home) ? home : null;
|
|
66648
67631
|
} catch {
|
|
66649
67632
|
return null;
|
|
66650
67633
|
}
|
|
@@ -66652,13 +67635,13 @@ function callerHome() {
|
|
|
66652
67635
|
function stopUserModeDaemon() {
|
|
66653
67636
|
const home = callerHome();
|
|
66654
67637
|
if (!home) return;
|
|
66655
|
-
const runDir = (0,
|
|
66656
|
-
const pidFile = (0,
|
|
66657
|
-
const socket = (0,
|
|
66658
|
-
if (!(0,
|
|
67638
|
+
const runDir = (0, import_node_path51.join)(home, ".threatcrush", "run");
|
|
67639
|
+
const pidFile = (0, import_node_path51.join)(runDir, "threatcrushd.pid");
|
|
67640
|
+
const socket = (0, import_node_path51.join)(runDir, "threatcrushd.sock");
|
|
67641
|
+
if (!(0, import_node_fs73.existsSync)(pidFile) && !(0, import_node_fs73.existsSync)(socket)) return;
|
|
66659
67642
|
let pid = null;
|
|
66660
67643
|
try {
|
|
66661
|
-
pid = Number.parseInt((0,
|
|
67644
|
+
pid = Number.parseInt((0, import_node_fs73.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
66662
67645
|
} catch {
|
|
66663
67646
|
pid = null;
|
|
66664
67647
|
}
|
|
@@ -66671,13 +67654,13 @@ function stopUserModeDaemon() {
|
|
|
66671
67654
|
}
|
|
66672
67655
|
for (const path2 of [socket, pidFile]) {
|
|
66673
67656
|
try {
|
|
66674
|
-
if ((0,
|
|
67657
|
+
if ((0, import_node_fs73.existsSync)(path2)) (0, import_node_fs73.rmSync)(path2);
|
|
66675
67658
|
} catch {
|
|
66676
67659
|
}
|
|
66677
67660
|
}
|
|
66678
67661
|
}
|
|
66679
67662
|
function unitIsActive() {
|
|
66680
|
-
const result = (0,
|
|
67663
|
+
const result = (0, import_node_child_process30.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
66681
67664
|
return result.status === 0;
|
|
66682
67665
|
}
|
|
66683
67666
|
async function installServiceCommand() {
|
|
@@ -66688,8 +67671,8 @@ async function installServiceCommand() {
|
|
|
66688
67671
|
return;
|
|
66689
67672
|
}
|
|
66690
67673
|
const noSystemd = systemdUnavailableReason({
|
|
66691
|
-
hasSystemctl: (0,
|
|
66692
|
-
booted: (0,
|
|
67674
|
+
hasSystemctl: (0, import_node_child_process30.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
67675
|
+
booted: (0, import_node_fs73.existsSync)("/run/systemd/system")
|
|
66693
67676
|
});
|
|
66694
67677
|
if (noSystemd) {
|
|
66695
67678
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -66711,7 +67694,7 @@ async function installServiceCommand() {
|
|
|
66711
67694
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
66712
67695
|
let nodePath = stableNodePath(process.execPath);
|
|
66713
67696
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
66714
|
-
binPath = (0,
|
|
67697
|
+
binPath = (0, import_node_fs73.realpathSync)(binPath);
|
|
66715
67698
|
nodePath = process.execPath;
|
|
66716
67699
|
}
|
|
66717
67700
|
if (isNodeScript) {
|
|
@@ -66724,13 +67707,13 @@ async function installServiceCommand() {
|
|
|
66724
67707
|
}
|
|
66725
67708
|
}
|
|
66726
67709
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
66727
|
-
const configDir = (0,
|
|
67710
|
+
const configDir = (0, import_node_path51.join)((0, import_node_os23.homedir)(), ".threatcrush");
|
|
66728
67711
|
const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
|
|
66729
67712
|
const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
|
|
66730
67713
|
const containWriter = containWriterSettings(loadConfig().file_integrity).mode !== "off";
|
|
66731
67714
|
const extraCapabilities = containWriter ? ["CAP_SYS_PTRACE"] : [];
|
|
66732
67715
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths, extraCapabilities });
|
|
66733
|
-
(0,
|
|
67716
|
+
(0, import_node_fs73.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
66734
67717
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
66735
67718
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
66736
67719
|
if (containWriter) console.log(source_default.dim(" CAP_SYS_PTRACE granted for [file_integrity] contain_writer (reads /proc/<pid>/fd)"));
|
|
@@ -66746,8 +67729,8 @@ async function installServiceCommand() {
|
|
|
66746
67729
|
installLogrotate();
|
|
66747
67730
|
stopUserModeDaemon();
|
|
66748
67731
|
try {
|
|
66749
|
-
(0,
|
|
66750
|
-
(0,
|
|
67732
|
+
(0, import_node_child_process30.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
67733
|
+
(0, import_node_child_process30.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
66751
67734
|
} catch (err) {
|
|
66752
67735
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
66753
67736
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -66784,9 +67767,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
66784
67767
|
].join("\n");
|
|
66785
67768
|
}
|
|
66786
67769
|
function installLogrotate() {
|
|
66787
|
-
if (!(0,
|
|
67770
|
+
if (!(0, import_node_fs73.existsSync)((0, import_node_path51.dirname)(LOGROTATE_PATH))) return;
|
|
66788
67771
|
try {
|
|
66789
|
-
(0,
|
|
67772
|
+
(0, import_node_fs73.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
66790
67773
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
66791
67774
|
} catch (err) {
|
|
66792
67775
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -66808,20 +67791,20 @@ function ensureSystemDirs(configDir) {
|
|
|
66808
67791
|
];
|
|
66809
67792
|
let admGid2 = null;
|
|
66810
67793
|
try {
|
|
66811
|
-
admGid2 = (0,
|
|
67794
|
+
admGid2 = (0, import_node_fs73.statSync)("/var/log/auth.log").gid;
|
|
66812
67795
|
} catch {
|
|
66813
67796
|
}
|
|
66814
67797
|
for (const { path: path2, groupWritable, sticky } of dirs) {
|
|
66815
67798
|
try {
|
|
66816
|
-
(0,
|
|
67799
|
+
(0, import_node_fs73.mkdirSync)(path2, { recursive: true });
|
|
66817
67800
|
} catch {
|
|
66818
67801
|
}
|
|
66819
67802
|
try {
|
|
66820
67803
|
if (groupWritable && admGid2 !== null) {
|
|
66821
|
-
(0,
|
|
66822
|
-
(0,
|
|
67804
|
+
(0, import_node_fs73.chmodSync)(path2, sticky ? 1533 : 509);
|
|
67805
|
+
(0, import_node_child_process30.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
|
|
66823
67806
|
} else {
|
|
66824
|
-
(0,
|
|
67807
|
+
(0, import_node_fs73.chmodSync)(path2, 493);
|
|
66825
67808
|
}
|
|
66826
67809
|
} catch {
|
|
66827
67810
|
}
|
|
@@ -66841,29 +67824,29 @@ async function uninstallServiceCommand() {
|
|
|
66841
67824
|
return;
|
|
66842
67825
|
}
|
|
66843
67826
|
try {
|
|
66844
|
-
(0,
|
|
67827
|
+
(0, import_node_child_process30.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
66845
67828
|
} catch {
|
|
66846
67829
|
}
|
|
66847
67830
|
try {
|
|
66848
|
-
(0,
|
|
67831
|
+
(0, import_node_child_process30.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
66849
67832
|
} catch {
|
|
66850
67833
|
}
|
|
66851
67834
|
try {
|
|
66852
|
-
if ((0,
|
|
66853
|
-
(0,
|
|
67835
|
+
if ((0, import_node_fs73.existsSync)(UNIT_PATH)) {
|
|
67836
|
+
(0, import_node_child_process30.execSync)(`rm -f ${UNIT_PATH}`);
|
|
66854
67837
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
66855
67838
|
}
|
|
66856
67839
|
} catch {
|
|
66857
67840
|
}
|
|
66858
67841
|
try {
|
|
66859
|
-
(0,
|
|
67842
|
+
(0, import_node_child_process30.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
66860
67843
|
} catch {
|
|
66861
67844
|
}
|
|
66862
67845
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
66863
67846
|
}
|
|
66864
67847
|
|
|
66865
67848
|
// src/commands/save.ts
|
|
66866
|
-
var
|
|
67849
|
+
var import_node_fs74 = require("fs");
|
|
66867
67850
|
var import_toml6 = __toESM(require_toml());
|
|
66868
67851
|
init_cli_config();
|
|
66869
67852
|
init_paths();
|
|
@@ -66902,9 +67885,9 @@ async function saveCommand(opts = {}) {
|
|
|
66902
67885
|
}
|
|
66903
67886
|
const path2 = opts.config ?? PATHS.configFile;
|
|
66904
67887
|
let config = {};
|
|
66905
|
-
if ((0,
|
|
67888
|
+
if ((0, import_node_fs74.existsSync)(path2)) {
|
|
66906
67889
|
try {
|
|
66907
|
-
config = import_toml6.default.parse((0,
|
|
67890
|
+
config = import_toml6.default.parse((0, import_node_fs74.readFileSync)(path2, "utf-8"));
|
|
66908
67891
|
} catch (err) {
|
|
66909
67892
|
console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
|
|
66910
67893
|
`));
|
|
@@ -67017,8 +68000,8 @@ function welcomeCommand() {
|
|
|
67017
68000
|
}
|
|
67018
68001
|
|
|
67019
68002
|
// src/commands/properties.ts
|
|
67020
|
-
var
|
|
67021
|
-
var
|
|
68003
|
+
var import_node_fs75 = require("fs");
|
|
68004
|
+
var import_node_path52 = require("path");
|
|
67022
68005
|
var import_node_readline4 = __toESM(require("readline"));
|
|
67023
68006
|
init_cli_config();
|
|
67024
68007
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -67348,8 +68331,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
67348
68331
|
}
|
|
67349
68332
|
}
|
|
67350
68333
|
function parseImportFile(path2) {
|
|
67351
|
-
const ext = (0,
|
|
67352
|
-
const raw = (0,
|
|
68334
|
+
const ext = (0, import_node_path52.extname)(path2).toLowerCase();
|
|
68335
|
+
const raw = (0, import_node_fs75.readFileSync)(path2, "utf-8");
|
|
67353
68336
|
if (ext === ".json") {
|
|
67354
68337
|
const parsed = JSON.parse(raw);
|
|
67355
68338
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -67591,13 +68574,13 @@ async function rulesCommand(opts) {
|
|
|
67591
68574
|
}
|
|
67592
68575
|
|
|
67593
68576
|
// src/commands/harden.ts
|
|
67594
|
-
var
|
|
67595
|
-
var
|
|
68577
|
+
var import_node_fs77 = require("fs");
|
|
68578
|
+
var import_node_child_process31 = require("child_process");
|
|
67596
68579
|
init_cli_config();
|
|
67597
68580
|
|
|
67598
68581
|
// src/commands/cis-report.ts
|
|
67599
|
-
var
|
|
67600
|
-
var
|
|
68582
|
+
var import_node_os24 = require("os");
|
|
68583
|
+
var import_node_fs76 = require("fs");
|
|
67601
68584
|
|
|
67602
68585
|
// ../../packages/scan/src/cis/crosswalk.ts
|
|
67603
68586
|
var CAC_TAG = "v0.1.82";
|
|
@@ -67917,7 +68900,7 @@ ${xref}
|
|
|
67917
68900
|
function osRelease() {
|
|
67918
68901
|
let raw = "";
|
|
67919
68902
|
try {
|
|
67920
|
-
raw = (0,
|
|
68903
|
+
raw = (0, import_node_fs76.readFileSync)("/etc/os-release", "utf8");
|
|
67921
68904
|
} catch {
|
|
67922
68905
|
return {};
|
|
67923
68906
|
}
|
|
@@ -67980,7 +68963,7 @@ function buildCisEvidenceReport(findings2, score, now = /* @__PURE__ */ new Date
|
|
|
67980
68963
|
generated_at: now.toISOString(),
|
|
67981
68964
|
disclaimer: CIS_DISCLAIMER,
|
|
67982
68965
|
benchmark_catalog_checked_at: CIS_CATALOG_CHECKED_AT,
|
|
67983
|
-
host: { hostname: (0,
|
|
68966
|
+
host: { hostname: (0, import_node_os24.hostname)(), os_id: id, os_version: version, pretty_name: os5.PRETTY_NAME ?? null },
|
|
67984
68967
|
benchmark: edition ? { ...edition } : null,
|
|
67985
68968
|
mapping_profile: profile2 ? {
|
|
67986
68969
|
name: profile2.benchmarkName,
|
|
@@ -68051,20 +69034,20 @@ function writeCisReport(path2, format2, report) {
|
|
|
68051
69034
|
const markdown = renderCisMarkdown(report);
|
|
68052
69035
|
const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
|
|
68053
69036
|
` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
|
|
68054
|
-
(0,
|
|
69037
|
+
(0, import_node_fs76.writeFileSync)(path2, content);
|
|
68055
69038
|
}
|
|
68056
69039
|
|
|
68057
69040
|
// src/commands/harden.ts
|
|
68058
69041
|
function tryExec(cmd) {
|
|
68059
69042
|
try {
|
|
68060
|
-
return (0,
|
|
69043
|
+
return (0, import_node_child_process31.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
68061
69044
|
} catch {
|
|
68062
69045
|
return null;
|
|
68063
69046
|
}
|
|
68064
69047
|
}
|
|
68065
69048
|
function tryRead(path2) {
|
|
68066
69049
|
try {
|
|
68067
|
-
return (0,
|
|
69050
|
+
return (0, import_node_fs77.readFileSync)(path2, "utf-8");
|
|
68068
69051
|
} catch {
|
|
68069
69052
|
return null;
|
|
68070
69053
|
}
|
|
@@ -68178,8 +69161,8 @@ function checkSshWeakConfig() {
|
|
|
68178
69161
|
};
|
|
68179
69162
|
}
|
|
68180
69163
|
function checkAutoUpdates() {
|
|
68181
|
-
const unattended = (0,
|
|
68182
|
-
const dnfAuto = (0,
|
|
69164
|
+
const unattended = (0, import_node_fs77.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs77.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
69165
|
+
const dnfAuto = (0, import_node_fs77.existsSync)("/etc/dnf/automatic.conf");
|
|
68183
69166
|
if (unattended || dnfAuto) {
|
|
68184
69167
|
return {
|
|
68185
69168
|
key: "auto-updates",
|
|
@@ -68305,7 +69288,7 @@ function checkFail2ban() {
|
|
|
68305
69288
|
explanation: "fail2ban is installed and running."
|
|
68306
69289
|
};
|
|
68307
69290
|
}
|
|
68308
|
-
if ((0,
|
|
69291
|
+
if ((0, import_node_fs77.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
68309
69292
|
return {
|
|
68310
69293
|
key: checkKey,
|
|
68311
69294
|
status: "warn",
|
|
@@ -68530,9 +69513,9 @@ async function hardenCommand(opts) {
|
|
|
68530
69513
|
}
|
|
68531
69514
|
|
|
68532
69515
|
// src/core/patches/index.ts
|
|
68533
|
-
var
|
|
68534
|
-
var
|
|
68535
|
-
var
|
|
69516
|
+
var import_node_fs78 = require("fs");
|
|
69517
|
+
var import_node_path53 = require("path");
|
|
69518
|
+
var import_node_child_process32 = require("child_process");
|
|
68536
69519
|
var import_node_util5 = require("util");
|
|
68537
69520
|
|
|
68538
69521
|
// src/core/patches/dpkg-version.ts
|
|
@@ -68590,9 +69573,9 @@ function compareDebianVersions(a, b) {
|
|
|
68590
69573
|
var OSV_QUERY = "https://api.osv.dev/v1/query";
|
|
68591
69574
|
var STALE_AFTER_MS = 2 * 864e5;
|
|
68592
69575
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
68593
|
-
var
|
|
69576
|
+
var RANK2 = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
68594
69577
|
var defaultExec = async (file, args) => {
|
|
68595
|
-
const { stdout } = await (0, import_node_util5.promisify)(
|
|
69578
|
+
const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process32.execFile)(file, args, {
|
|
68596
69579
|
timeout: 12e4,
|
|
68597
69580
|
maxBuffer: 32 * 1024 * 1024,
|
|
68598
69581
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -68691,9 +69674,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
68691
69674
|
function newestReleaseMtime(dir) {
|
|
68692
69675
|
try {
|
|
68693
69676
|
let newest = 0;
|
|
68694
|
-
for (const name of (0,
|
|
69677
|
+
for (const name of (0, import_node_fs78.readdirSync)(dir)) {
|
|
68695
69678
|
if (!/Release$/.test(name)) continue;
|
|
68696
|
-
newest = Math.max(newest, (0,
|
|
69679
|
+
newest = Math.max(newest, (0, import_node_fs78.statSync)((0, import_node_path53.join)(dir, name)).mtimeMs);
|
|
68697
69680
|
}
|
|
68698
69681
|
return newest > 0 ? new Date(newest) : null;
|
|
68699
69682
|
} catch {
|
|
@@ -68710,7 +69693,7 @@ async function checkPatches(opts = {}) {
|
|
|
68710
69693
|
let osText = opts.osRelease;
|
|
68711
69694
|
if (osText === void 0) {
|
|
68712
69695
|
try {
|
|
68713
|
-
osText = (0,
|
|
69696
|
+
osText = (0, import_node_fs78.readFileSync)("/etc/os-release", "utf-8");
|
|
68714
69697
|
} catch {
|
|
68715
69698
|
osText = "";
|
|
68716
69699
|
}
|
|
@@ -68791,12 +69774,12 @@ async function checkPatches(opts = {}) {
|
|
|
68791
69774
|
} catch (err) {
|
|
68792
69775
|
report.osv_error ??= err.message;
|
|
68793
69776
|
}
|
|
68794
|
-
pkg.cves.sort((a, b) =>
|
|
69777
|
+
pkg.cves.sort((a, b) => RANK2[b.severity] - RANK2[a.severity] || a.id.localeCompare(b.id));
|
|
68795
69778
|
if (pkg.cves.length > 0) pkg.severity = pkg.cves[0].severity;
|
|
68796
69779
|
pkg.binaries.sort();
|
|
68797
69780
|
}
|
|
68798
69781
|
report.packages = [...bySource.values()].sort(
|
|
68799
|
-
(a, b) =>
|
|
69782
|
+
(a, b) => RANK2[b.severity] - RANK2[a.severity] || b.cves.length - a.cves.length || a.source.localeCompare(b.source)
|
|
68800
69783
|
);
|
|
68801
69784
|
const counts = emptyCounts2();
|
|
68802
69785
|
counts.packages = report.packages.length;
|
|
@@ -68809,7 +69792,7 @@ async function checkPatches(opts = {}) {
|
|
|
68809
69792
|
}
|
|
68810
69793
|
function worstSeverity(report) {
|
|
68811
69794
|
if (report.packages.length === 0) return null;
|
|
68812
|
-
return report.packages.reduce((w, p) =>
|
|
69795
|
+
return report.packages.reduce((w, p) => RANK2[p.severity] > RANK2[w] ? p.severity : w, "info");
|
|
68813
69796
|
}
|
|
68814
69797
|
var MAX_DETAIL_PACKAGES = 30;
|
|
68815
69798
|
function patchFinding(report) {
|
|
@@ -68936,27 +69919,27 @@ async function patchesCommand(opts) {
|
|
|
68936
69919
|
}
|
|
68937
69920
|
|
|
68938
69921
|
// src/commands/feeds.ts
|
|
68939
|
-
var
|
|
68940
|
-
var
|
|
69922
|
+
var import_node_net25 = require("net");
|
|
69923
|
+
var import_node_path55 = require("path");
|
|
68941
69924
|
init_paths();
|
|
68942
69925
|
|
|
68943
69926
|
// src/commands/feeds-resolver.ts
|
|
68944
|
-
var
|
|
68945
|
-
var
|
|
68946
|
-
var
|
|
69927
|
+
var import_node_child_process33 = require("child_process");
|
|
69928
|
+
var import_node_fs79 = require("fs");
|
|
69929
|
+
var import_node_path54 = require("path");
|
|
68947
69930
|
var realIO = {
|
|
68948
|
-
exists: (p) => (0,
|
|
69931
|
+
exists: (p) => (0, import_node_fs79.existsSync)(p),
|
|
68949
69932
|
read: (p) => {
|
|
68950
69933
|
try {
|
|
68951
|
-
return (0,
|
|
69934
|
+
return (0, import_node_fs79.readFileSync)(p, "utf-8");
|
|
68952
69935
|
} catch {
|
|
68953
69936
|
return null;
|
|
68954
69937
|
}
|
|
68955
69938
|
},
|
|
68956
|
-
write: (p, c) => (0,
|
|
68957
|
-
remove: (p) => (0,
|
|
69939
|
+
write: (p, c) => (0, import_node_fs79.writeFileSync)(p, c),
|
|
69940
|
+
remove: (p) => (0, import_node_fs79.rmSync)(p, { force: true }),
|
|
68958
69941
|
run: (cmd, args) => {
|
|
68959
|
-
const r = (0,
|
|
69942
|
+
const r = (0, import_node_child_process33.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
68960
69943
|
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
68961
69944
|
}
|
|
68962
69945
|
};
|
|
@@ -68964,17 +69947,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
|
68964
69947
|
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
68965
69948
|
function hookContent(resolver, stateDir) {
|
|
68966
69949
|
const head2 = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
68967
|
-
return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0,
|
|
68968
|
-
` : `${head2}include: "${(0,
|
|
69950
|
+
return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
69951
|
+
` : `${head2}include: "${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
68969
69952
|
`;
|
|
68970
69953
|
}
|
|
68971
69954
|
function apparmorRule(stateDir) {
|
|
68972
|
-
return ` ${(0,
|
|
69955
|
+
return ` ${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
68973
69956
|
}
|
|
68974
69957
|
function detectResolvers(io = realIO) {
|
|
68975
69958
|
const found = [];
|
|
68976
|
-
if (io.exists((0,
|
|
68977
|
-
if (io.exists((0,
|
|
69959
|
+
if (io.exists((0, import_node_path54.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
69960
|
+
if (io.exists((0, import_node_path54.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
68978
69961
|
return found;
|
|
68979
69962
|
}
|
|
68980
69963
|
function check(resolver, io) {
|
|
@@ -68987,7 +69970,7 @@ function restartIfActive(resolver, io) {
|
|
|
68987
69970
|
}
|
|
68988
69971
|
function installHook(resolver, stateDir, io = realIO) {
|
|
68989
69972
|
const hook = RESOLVER_HOOKS[resolver];
|
|
68990
|
-
const file = (0,
|
|
69973
|
+
const file = (0, import_node_path54.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
68991
69974
|
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
68992
69975
|
io.write(hook, hookContent(resolver, stateDir));
|
|
68993
69976
|
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
@@ -69048,8 +70031,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
69048
70031
|
}
|
|
69049
70032
|
return failed ? 1 : 0;
|
|
69050
70033
|
}
|
|
69051
|
-
const hosts = io.read((0,
|
|
69052
|
-
const unbound = io.read((0,
|
|
70034
|
+
const hosts = io.read((0, import_node_path54.join)(stateDir, RESOLVER_FILES.hosts));
|
|
70035
|
+
const unbound = io.read((0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound));
|
|
69053
70036
|
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
69054
70037
|
for (const r of ["dnsmasq", "unbound"]) {
|
|
69055
70038
|
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
@@ -69061,11 +70044,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
69061
70044
|
// src/commands/feeds.ts
|
|
69062
70045
|
async function loadSet() {
|
|
69063
70046
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
69064
|
-
const path2 = (0,
|
|
70047
|
+
const path2 = (0, import_node_path55.join)(dir, "threat-feeds.json");
|
|
69065
70048
|
const set = readFeedCache(path2);
|
|
69066
70049
|
if (set) return { set, from: path2 };
|
|
69067
70050
|
}
|
|
69068
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
70051
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path55.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
69069
70052
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
69070
70053
|
}
|
|
69071
70054
|
async function feedsCommand(action, value, opts) {
|
|
@@ -69080,8 +70063,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
69080
70063
|
process.exitCode = 2;
|
|
69081
70064
|
return;
|
|
69082
70065
|
}
|
|
69083
|
-
const ipHit = (0,
|
|
69084
|
-
const domainHit = (0,
|
|
70066
|
+
const ipHit = (0, import_node_net25.isIP)(value) ? matchIp(value, set) : null;
|
|
70067
|
+
const domainHit = (0, import_node_net25.isIP)(value) ? null : matchDomain(value, set);
|
|
69085
70068
|
const listed = ipHit ?? domainHit?.indicator ?? null;
|
|
69086
70069
|
if (opts.json) {
|
|
69087
70070
|
console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
|
|
@@ -69119,21 +70102,21 @@ async function feedsCommand(action, value, opts) {
|
|
|
69119
70102
|
}
|
|
69120
70103
|
|
|
69121
70104
|
// src/commands/tor.ts
|
|
69122
|
-
var
|
|
69123
|
-
var
|
|
69124
|
-
var
|
|
70105
|
+
var import_node_fs80 = require("fs");
|
|
70106
|
+
var import_node_net26 = require("net");
|
|
70107
|
+
var import_node_path56 = require("path");
|
|
69125
70108
|
init_paths();
|
|
69126
70109
|
async function torCommand(action, value, opts) {
|
|
69127
70110
|
let exits = /* @__PURE__ */ new Set();
|
|
69128
70111
|
let from = "";
|
|
69129
70112
|
let updated = null;
|
|
69130
70113
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
69131
|
-
const path2 = (0,
|
|
70114
|
+
const path2 = (0, import_node_path56.join)(dir, "tor-exits.txt");
|
|
69132
70115
|
try {
|
|
69133
|
-
if (!(0,
|
|
69134
|
-
exits = parseTorExitList((0,
|
|
70116
|
+
if (!(0, import_node_fs80.existsSync)(path2)) continue;
|
|
70117
|
+
exits = parseTorExitList((0, import_node_fs80.readFileSync)(path2, "utf-8"));
|
|
69135
70118
|
from = path2;
|
|
69136
|
-
updated = (0,
|
|
70119
|
+
updated = (0, import_node_fs80.statSync)(path2).mtime;
|
|
69137
70120
|
break;
|
|
69138
70121
|
} catch {
|
|
69139
70122
|
}
|
|
@@ -69149,10 +70132,10 @@ async function torCommand(action, value, opts) {
|
|
|
69149
70132
|
} catch {
|
|
69150
70133
|
}
|
|
69151
70134
|
}
|
|
69152
|
-
const remediation = loadConfig((0,
|
|
70135
|
+
const remediation = loadConfig((0, import_node_path56.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
69153
70136
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
69154
70137
|
if (action === "check") {
|
|
69155
|
-
if (!value || !(0,
|
|
70138
|
+
if (!value || !(0, import_node_net26.isIP)(value)) {
|
|
69156
70139
|
console.error("Usage: threatcrush tor check <ip>");
|
|
69157
70140
|
process.exitCode = 2;
|
|
69158
70141
|
return;
|
|
@@ -69180,14 +70163,14 @@ async function torCommand(action, value, opts) {
|
|
|
69180
70163
|
}
|
|
69181
70164
|
|
|
69182
70165
|
// src/commands/reputation.ts
|
|
69183
|
-
var
|
|
69184
|
-
var
|
|
69185
|
-
var
|
|
70166
|
+
var import_node_os25 = require("os");
|
|
70167
|
+
var import_node_fs81 = require("fs");
|
|
70168
|
+
var import_node_path57 = require("path");
|
|
69186
70169
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
69187
|
-
var CONFIG_PATH4 = (0,
|
|
70170
|
+
var CONFIG_PATH4 = (0, import_node_path57.join)((0, import_node_os25.homedir)(), ".threatcrush", "config.json");
|
|
69188
70171
|
function readConfig3() {
|
|
69189
70172
|
try {
|
|
69190
|
-
return JSON.parse((0,
|
|
70173
|
+
return JSON.parse((0, import_node_fs81.readFileSync)(CONFIG_PATH4, "utf-8"));
|
|
69191
70174
|
} catch {
|
|
69192
70175
|
return {};
|
|
69193
70176
|
}
|
|
@@ -69375,7 +70358,7 @@ async function reputationSubscribeCommand(opts) {
|
|
|
69375
70358
|
}
|
|
69376
70359
|
|
|
69377
70360
|
// src/commands/privileged.ts
|
|
69378
|
-
var
|
|
70361
|
+
var import_node_fs82 = require("fs");
|
|
69379
70362
|
init_paths();
|
|
69380
70363
|
var SEV2 = {
|
|
69381
70364
|
critical: source_default.red.bold,
|
|
@@ -69388,19 +70371,19 @@ async function privilegedCommand(opts) {
|
|
|
69388
70371
|
const snapshot = takeSnapshot({
|
|
69389
70372
|
readFile: (p) => {
|
|
69390
70373
|
try {
|
|
69391
|
-
return (0,
|
|
70374
|
+
return (0, import_node_fs82.readFileSync)(p, "utf-8");
|
|
69392
70375
|
} catch {
|
|
69393
70376
|
return null;
|
|
69394
70377
|
}
|
|
69395
70378
|
},
|
|
69396
70379
|
readDir: (p) => {
|
|
69397
70380
|
try {
|
|
69398
|
-
return (0,
|
|
70381
|
+
return (0, import_node_fs82.readdirSync)(p);
|
|
69399
70382
|
} catch {
|
|
69400
70383
|
return null;
|
|
69401
70384
|
}
|
|
69402
70385
|
},
|
|
69403
|
-
exists: (p) => (0,
|
|
70386
|
+
exists: (p) => (0, import_node_fs82.existsSync)(p)
|
|
69404
70387
|
});
|
|
69405
70388
|
let events = [];
|
|
69406
70389
|
let ledgerNote = "";
|
|
@@ -69442,12 +70425,12 @@ async function privilegedCommand(opts) {
|
|
|
69442
70425
|
}
|
|
69443
70426
|
|
|
69444
70427
|
// src/commands/integrity.ts
|
|
69445
|
-
var
|
|
69446
|
-
var
|
|
70428
|
+
var import_node_fs83 = require("fs");
|
|
70429
|
+
var import_node_path58 = require("path");
|
|
69447
70430
|
init_paths();
|
|
69448
70431
|
function readState2(path2) {
|
|
69449
70432
|
try {
|
|
69450
|
-
return JSON.parse((0,
|
|
70433
|
+
return JSON.parse((0, import_node_fs83.readFileSync)(path2, "utf8"));
|
|
69451
70434
|
} catch {
|
|
69452
70435
|
return null;
|
|
69453
70436
|
}
|
|
@@ -69467,11 +70450,11 @@ function changedCount(baseline, observed) {
|
|
|
69467
70450
|
async function integrityCommand(action = "status", opts = {}) {
|
|
69468
70451
|
const config = loadConfig();
|
|
69469
70452
|
const settings = fileIntegritySettings(config.file_integrity);
|
|
69470
|
-
const systemBaseline = (0,
|
|
69471
|
-
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0,
|
|
70453
|
+
const systemBaseline = (0, import_node_path58.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
|
|
70454
|
+
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs83.existsSync)(systemBaseline);
|
|
69472
70455
|
const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
|
|
69473
|
-
const baselinePath = (0,
|
|
69474
|
-
const observedPath = (0,
|
|
70456
|
+
const baselinePath = (0, import_node_path58.join)(stateDir, "file-integrity-baseline.json");
|
|
70457
|
+
const observedPath = (0, import_node_path58.join)(stateDir, "file-integrity-observed.json");
|
|
69475
70458
|
if (action === "rebaseline") {
|
|
69476
70459
|
const watch4 = new FileIntegrityWatch({
|
|
69477
70460
|
bus: { publish: () => void 0 },
|
|
@@ -69539,13 +70522,13 @@ async function integrityCommand(action = "status", opts = {}) {
|
|
|
69539
70522
|
}
|
|
69540
70523
|
|
|
69541
70524
|
// src/commands/edr.ts
|
|
69542
|
-
var
|
|
70525
|
+
var import_node_fs85 = require("fs");
|
|
69543
70526
|
init_paths();
|
|
69544
70527
|
|
|
69545
70528
|
// src/daemon/auditd/rules.ts
|
|
69546
|
-
var
|
|
69547
|
-
var
|
|
69548
|
-
var
|
|
70529
|
+
var import_node_fs84 = require("fs");
|
|
70530
|
+
var import_node_child_process34 = require("child_process");
|
|
70531
|
+
var import_node_path59 = require("path");
|
|
69549
70532
|
var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
|
|
69550
70533
|
var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
|
|
69551
70534
|
var CONNECT_KEY2 = "threatcrush_edr_connect";
|
|
@@ -69553,10 +70536,10 @@ var LISTEN_KEY2 = "threatcrush_edr_listen";
|
|
|
69553
70536
|
function passwdByName() {
|
|
69554
70537
|
let raw = "";
|
|
69555
70538
|
try {
|
|
69556
|
-
raw = (0,
|
|
70539
|
+
raw = (0, import_node_child_process34.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
69557
70540
|
} catch {
|
|
69558
70541
|
try {
|
|
69559
|
-
raw = (0,
|
|
70542
|
+
raw = (0, import_node_fs84.readFileSync)("/etc/passwd", "utf8");
|
|
69560
70543
|
} catch {
|
|
69561
70544
|
return /* @__PURE__ */ new Map();
|
|
69562
70545
|
}
|
|
@@ -69575,8 +70558,8 @@ function existingExecutables(names) {
|
|
|
69575
70558
|
for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
|
|
69576
70559
|
const candidate = `${prefix}/${name}`;
|
|
69577
70560
|
try {
|
|
69578
|
-
if (!(0,
|
|
69579
|
-
paths.add((0,
|
|
70561
|
+
if (!(0, import_node_fs84.existsSync)(candidate) || !(0, import_node_fs84.statSync)(candidate).isFile()) continue;
|
|
70562
|
+
paths.add((0, import_node_fs84.realpathSync)(candidate));
|
|
69580
70563
|
} catch {
|
|
69581
70564
|
}
|
|
69582
70565
|
}
|
|
@@ -69585,9 +70568,9 @@ function existingExecutables(names) {
|
|
|
69585
70568
|
}
|
|
69586
70569
|
function existingDirectories(paths) {
|
|
69587
70570
|
return [...new Set(paths)].filter((path2) => {
|
|
69588
|
-
if (!(0,
|
|
70571
|
+
if (!(0, import_node_path59.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
|
|
69589
70572
|
try {
|
|
69590
|
-
return (0,
|
|
70573
|
+
return (0, import_node_fs84.statSync)(path2).isDirectory();
|
|
69591
70574
|
} catch {
|
|
69592
70575
|
return false;
|
|
69593
70576
|
}
|
|
@@ -69630,7 +70613,7 @@ function generateAuditRules(settings) {
|
|
|
69630
70613
|
}
|
|
69631
70614
|
|
|
69632
70615
|
// src/commands/edr.ts
|
|
69633
|
-
var
|
|
70616
|
+
var import_node_path60 = require("path");
|
|
69634
70617
|
async function edrCommand(action = "status", opts = {}) {
|
|
69635
70618
|
const settings = edrSettings(loadConfig().edr);
|
|
69636
70619
|
if (action === "rules") {
|
|
@@ -69655,8 +70638,8 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
69655
70638
|
}
|
|
69656
70639
|
let readable = false;
|
|
69657
70640
|
try {
|
|
69658
|
-
if ((0,
|
|
69659
|
-
readable = (0,
|
|
70641
|
+
if ((0, import_node_fs85.existsSync)(settings.auditLogPath)) (0, import_node_fs85.accessSync)(settings.auditLogPath, import_node_fs85.constants.R_OK);
|
|
70642
|
+
readable = (0, import_node_fs85.existsSync)(settings.auditLogPath);
|
|
69660
70643
|
} catch {
|
|
69661
70644
|
}
|
|
69662
70645
|
let events = [];
|
|
@@ -69668,7 +70651,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
69668
70651
|
stateNote = `the daemon state database (${PATHS.stateDb}) is not readable here`;
|
|
69669
70652
|
}
|
|
69670
70653
|
const selection = selectEdrSource(settings.source === "auditd" ? { configured: "auditd", bpftracePath: null, btfPresent: false, isRoot: false } : probeHost(settings.source));
|
|
69671
|
-
const daemonSource = readEdrSourceStatus((0,
|
|
70654
|
+
const daemonSource = readEdrSourceStatus((0, import_node_path60.join)(PATHS.stateDir, "edr-source.json"));
|
|
69672
70655
|
const report = {
|
|
69673
70656
|
enabled: settings.enabled,
|
|
69674
70657
|
source: settings.source,
|
|
@@ -69854,7 +70837,7 @@ async function allowlistCommand(opts) {
|
|
|
69854
70837
|
}
|
|
69855
70838
|
|
|
69856
70839
|
// src/commands/abuse.ts
|
|
69857
|
-
var
|
|
70840
|
+
var import_node_fs86 = require("fs");
|
|
69858
70841
|
init_paths();
|
|
69859
70842
|
function rows(records) {
|
|
69860
70843
|
if (records.length === 0) {
|
|
@@ -69914,7 +70897,7 @@ function abuseRetractCommand(id, opts = {}) {
|
|
|
69914
70897
|
);
|
|
69915
70898
|
}
|
|
69916
70899
|
function abuseStatusCommand(opts = {}) {
|
|
69917
|
-
const config = loadConfig((0,
|
|
70900
|
+
const config = loadConfig((0, import_node_fs86.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
69918
70901
|
const cfg = resolveConfig(config.abuse_reporter);
|
|
69919
70902
|
const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
|
|
69920
70903
|
const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
|
|
@@ -69937,11 +70920,11 @@ function abuseStatusCommand(opts = {}) {
|
|
|
69937
70920
|
init_paths();
|
|
69938
70921
|
|
|
69939
70922
|
// src/upgrade.ts
|
|
69940
|
-
var
|
|
70923
|
+
var import_node_child_process35 = require("child_process");
|
|
69941
70924
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
69942
70925
|
var defaultRunner = (cmd) => {
|
|
69943
70926
|
try {
|
|
69944
|
-
return (0,
|
|
70927
|
+
return (0, import_node_child_process35.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
69945
70928
|
} catch {
|
|
69946
70929
|
return null;
|
|
69947
70930
|
}
|
|
@@ -70082,9 +71065,9 @@ function installUserAgent(target = globalThis) {
|
|
|
70082
71065
|
}
|
|
70083
71066
|
|
|
70084
71067
|
// src/core/cloud-upload.ts
|
|
70085
|
-
var
|
|
70086
|
-
var
|
|
70087
|
-
var
|
|
71068
|
+
var import_node_child_process36 = require("child_process");
|
|
71069
|
+
var import_node_os26 = require("os");
|
|
71070
|
+
var import_node_path61 = require("path");
|
|
70088
71071
|
init_cli_config();
|
|
70089
71072
|
function uploadDisabled(upload, env3 = process.env) {
|
|
70090
71073
|
if (upload === false) return true;
|
|
@@ -70103,8 +71086,8 @@ function cleanUrl(raw) {
|
|
|
70103
71086
|
return raw.split(/[?#]/)[0];
|
|
70104
71087
|
}
|
|
70105
71088
|
}
|
|
70106
|
-
function repoTarget(path2, run3 = (args) => (0,
|
|
70107
|
-
const abs = (0,
|
|
71089
|
+
function repoTarget(path2, run3 = (args) => (0, import_node_child_process36.execFileSync)("git", args, { cwd: (0, import_node_path61.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
|
|
71090
|
+
const abs = (0, import_node_path61.resolve)(path2);
|
|
70108
71091
|
try {
|
|
70109
71092
|
const root = run3(["rev-parse", "--show-toplevel"]);
|
|
70110
71093
|
const sub = abs === root ? "." : abs.slice(root.length + 1);
|
|
@@ -70117,9 +71100,9 @@ function repoTarget(path2, run3 = (args) => (0, import_node_child_process35.exec
|
|
|
70117
71100
|
const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
|
|
70118
71101
|
if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
|
|
70119
71102
|
}
|
|
70120
|
-
return { target: `${(0,
|
|
71103
|
+
return { target: `${(0, import_node_os26.hostname)()}:${root}`, root, sub };
|
|
70121
71104
|
} catch {
|
|
70122
|
-
return { target: `${(0,
|
|
71105
|
+
return { target: `${(0, import_node_os26.hostname)()}:${abs}`, root: abs, sub: "." };
|
|
70123
71106
|
}
|
|
70124
71107
|
}
|
|
70125
71108
|
async function uploadResult(result, opts) {
|
|
@@ -70476,25 +71459,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
70476
71459
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
70477
71460
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
70478
71461
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
70479
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
71462
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush", "install.json");
|
|
70480
71463
|
function detectPackageManager2() {
|
|
70481
71464
|
try {
|
|
70482
|
-
const npmGlobal = (0,
|
|
71465
|
+
const npmGlobal = (0, import_node_child_process37.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
70483
71466
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
70484
71467
|
} catch {
|
|
70485
71468
|
}
|
|
70486
71469
|
try {
|
|
70487
|
-
(0,
|
|
71470
|
+
(0, import_node_child_process37.execSync)("pnpm --version", { stdio: "pipe" });
|
|
70488
71471
|
return "pnpm";
|
|
70489
71472
|
} catch {
|
|
70490
71473
|
}
|
|
70491
71474
|
try {
|
|
70492
|
-
(0,
|
|
71475
|
+
(0, import_node_child_process37.execSync)("yarn --version", { stdio: "pipe" });
|
|
70493
71476
|
return "yarn";
|
|
70494
71477
|
} catch {
|
|
70495
71478
|
}
|
|
70496
71479
|
try {
|
|
70497
|
-
(0,
|
|
71480
|
+
(0, import_node_child_process37.execSync)("bun --version", { stdio: "pipe" });
|
|
70498
71481
|
return "bun";
|
|
70499
71482
|
} catch {
|
|
70500
71483
|
}
|
|
@@ -70502,14 +71485,14 @@ function detectPackageManager2() {
|
|
|
70502
71485
|
}
|
|
70503
71486
|
function readInstallConfig() {
|
|
70504
71487
|
try {
|
|
70505
|
-
return JSON.parse((0,
|
|
71488
|
+
return JSON.parse((0, import_node_fs87.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
70506
71489
|
} catch {
|
|
70507
71490
|
return {};
|
|
70508
71491
|
}
|
|
70509
71492
|
}
|
|
70510
71493
|
function packageLooksInstalled(pm, pkgName) {
|
|
70511
71494
|
try {
|
|
70512
|
-
const output = (0,
|
|
71495
|
+
const output = (0, import_node_child_process37.execSync)(globalListCommand(pm, pkgName), {
|
|
70513
71496
|
encoding: "utf-8",
|
|
70514
71497
|
stdio: ["pipe", "pipe", "pipe"]
|
|
70515
71498
|
});
|
|
@@ -70612,14 +71595,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
70612
71595
|
function restartSystemdDaemon() {
|
|
70613
71596
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
70614
71597
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
70615
|
-
if (!asRoot && (0,
|
|
71598
|
+
if (!asRoot && (0, import_node_child_process37.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
70616
71599
|
const [cmd, ...args] = argv;
|
|
70617
|
-
if ((0,
|
|
70618
|
-
return (0,
|
|
71600
|
+
if ((0, import_node_child_process37.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
71601
|
+
return (0, import_node_child_process37.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
70619
71602
|
}
|
|
70620
71603
|
function execQuiet(cmd) {
|
|
70621
71604
|
try {
|
|
70622
|
-
return (0,
|
|
71605
|
+
return (0, import_node_child_process37.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
70623
71606
|
} catch {
|
|
70624
71607
|
return null;
|
|
70625
71608
|
}
|
|
@@ -70951,7 +71934,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
70951
71934
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
70952
71935
|
console.log(LOGO2);
|
|
70953
71936
|
const logPath2 = PATHS.logFile;
|
|
70954
|
-
if (!(0,
|
|
71937
|
+
if (!(0, import_node_fs87.existsSync)(logPath2)) {
|
|
70955
71938
|
console.log(source_default.yellow(` No log file found at ${logPath2}`));
|
|
70956
71939
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
70957
71940
|
return;
|
|
@@ -70959,7 +71942,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
70959
71942
|
console.log(source_default.green(` Tailing ${logPath2}...
|
|
70960
71943
|
`));
|
|
70961
71944
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
70962
|
-
(0,
|
|
71945
|
+
(0, import_node_child_process37.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
|
|
70963
71946
|
});
|
|
70964
71947
|
program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
|
|
70965
71948
|
console.log(LOGO2);
|
|
@@ -70971,7 +71954,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
70971
71954
|
for (const cmd of commands2) {
|
|
70972
71955
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
70973
71956
|
`));
|
|
70974
|
-
(0,
|
|
71957
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
70975
71958
|
}
|
|
70976
71959
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
70977
71960
|
await reportIfStillStale();
|
|
@@ -70996,7 +71979,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
70996
71979
|
for (const cmd of commands) {
|
|
70997
71980
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
70998
71981
|
`));
|
|
70999
|
-
(0,
|
|
71982
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
71000
71983
|
}
|
|
71001
71984
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
71002
71985
|
if (installMode === "desktop") {
|
|
@@ -71047,7 +72030,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
71047
72030
|
for (const cmd of commands) {
|
|
71048
72031
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
71049
72032
|
`));
|
|
71050
|
-
(0,
|
|
72033
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
71051
72034
|
}
|
|
71052
72035
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
71053
72036
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -71124,10 +72107,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
71124
72107
|
});
|
|
71125
72108
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
71126
72109
|
console.log(LOGO2);
|
|
71127
|
-
const configPath = (0,
|
|
72110
|
+
const configPath = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush", "config.json");
|
|
71128
72111
|
let email = "";
|
|
71129
72112
|
try {
|
|
71130
|
-
const config = JSON.parse((0,
|
|
72113
|
+
const config = JSON.parse((0, import_node_fs87.readFileSync)(configPath, "utf-8"));
|
|
71131
72114
|
email = config.email || "";
|
|
71132
72115
|
} catch {
|
|
71133
72116
|
}
|
|
@@ -71144,9 +72127,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
71144
72127
|
return;
|
|
71145
72128
|
}
|
|
71146
72129
|
try {
|
|
71147
|
-
const dir = (0,
|
|
71148
|
-
if (!(0,
|
|
71149
|
-
(0,
|
|
72130
|
+
const dir = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush");
|
|
72131
|
+
if (!(0, import_node_fs87.existsSync)(dir)) (0, import_node_fs87.mkdirSync)(dir, { recursive: true });
|
|
72132
|
+
(0, import_node_fs87.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
71150
72133
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
71151
72134
|
} catch {
|
|
71152
72135
|
}
|