@profullstack/threatcrush 0.15.2 → 0.16.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 +6 -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 +1031 -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);
|
|
@@ -53385,6 +53386,9 @@ var WIN_SCRIPT_EXTS = /* @__PURE__ */ new Set(["js", "jse", "vbs", "vbe", "wsf",
|
|
|
53385
53386
|
var WEB_EXTS = /* @__PURE__ */ new Set(["html", "htm", "shtml", "xhtml", "svg", "hta"]);
|
|
53386
53387
|
var SERVER_SCRIPT_EXTS = /* @__PURE__ */ new Set(["php", "phtml", "php3", "php4", "php5", "php7", "phar", "asp", "aspx", "ashx", "jsp", "jspx"]);
|
|
53387
53388
|
var isScript = (c) => c.kind === "script" || SCRIPT_EXTS.has(c.ext);
|
|
53389
|
+
var SHELL_EXTS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "command", "bat", "cmd"]);
|
|
53390
|
+
var isShellScript = (c) => SHELL_EXTS.has(c.ext) || !c.ext && /^#!\s*\S*\/(?:env\s+)?(?:ba|z|da|k)?sh\b/.test(c.text);
|
|
53391
|
+
var EXEC_SINK = /child_process|\bexecSync\b|\bspawn(?:Sync)?\s*\(|\bexecFile\b|subprocess\.|os\.(?:system|popen|exec\w*)\s*\(|\bPopen\s*\(|\bsystem\s*\(|(?<![.\w$])exec\s*\(|\bshell_exec\b|\bpassthru\b|\bproc_open\b|Invoke-Expression|\bIEX\b|Start-Process|WScript\.Shell|Runtime\.getRuntime/;
|
|
53388
53392
|
var POWERSHELL_HOST_EXTS = /* @__PURE__ */ new Set(["ps1", "psm1", "bat", "cmd", "vbs", "vbe", "wsf", "hta"]);
|
|
53389
53393
|
var isWindowsScriptContext = (c) => POWERSHELL_HOST_EXTS.has(c.ext) || c.kind === "lnk" || ["js", "jse"].includes(c.ext) && /ActiveXObject|WScript\.|GetObject\(\s*["']winmgmts/i.test(c.text);
|
|
53390
53394
|
var NON_RUNNABLE_SOURCE_EXTS = /* @__PURE__ */ new Set(["ts", "tsx", "mts", "cts", "md", "markdown", "rst", "go", "rs", "c", "h", "cc", "cpp", "hpp", "java", "kt", "cs", "swift", "scala"]);
|
|
@@ -53536,7 +53540,9 @@ var RULES = [
|
|
|
53536
53540
|
test: (c) => {
|
|
53537
53541
|
if (!isScript(c)) return false;
|
|
53538
53542
|
const t = c.text;
|
|
53539
|
-
|
|
53543
|
+
const oneLiner = /bash\s+-i\s*>&\s*\/dev\/tcp\//.test(t) || /\/dev\/tcp\/\d{1,3}(?:\.\d{1,3}){3}\/\d{2,5}\s*0>&1/.test(t) || /\bnc(?:at)?\s+(?:-\w+\s+)*-e\s+\/bin\/(?:ba)?sh\b/.test(t);
|
|
53544
|
+
if (oneLiner && (isShellScript(c) || EXEC_SINK.test(t))) return true;
|
|
53545
|
+
return /socket\.socket\([\s\S]{0,300}?(?:os\.dup2|pty\.spawn)\([\s\S]{0,300}?\/bin\/(?:ba)?sh/.test(t) || /New-Object\s+System\.Net\.Sockets\.TCPClient\([\s\S]{0,600}?(?:\bIEX\b|Invoke-Expression)/i.test(t);
|
|
53540
53546
|
}
|
|
53541
53547
|
},
|
|
53542
53548
|
{
|
|
@@ -54062,9 +54068,9 @@ function parseClamOutput(stdout) {
|
|
|
54062
54068
|
for (const line2 of stdout.split(/\r?\n/)) {
|
|
54063
54069
|
const m = /^(.*): (\S+) FOUND$/.exec(line2.trim());
|
|
54064
54070
|
if (!m) continue;
|
|
54065
|
-
const
|
|
54066
|
-
|
|
54067
|
-
out.set(m[1],
|
|
54071
|
+
const list3 = out.get(m[1]) ?? [];
|
|
54072
|
+
list3.push(m[2]);
|
|
54073
|
+
out.set(m[1], list3);
|
|
54068
54074
|
}
|
|
54069
54075
|
return out;
|
|
54070
54076
|
}
|
|
@@ -54084,11 +54090,11 @@ async function clamScanFiles(info2, files, opts = {}) {
|
|
|
54084
54090
|
const detections = /* @__PURE__ */ new Map();
|
|
54085
54091
|
if (!info2.available || !info2.binary || files.length === 0) return { detections, error: null };
|
|
54086
54092
|
const dir = await (0, import_promises2.mkdtemp)((0, import_node_path21.join)((0, import_node_os11.tmpdir)(), "crushav-"));
|
|
54087
|
-
const
|
|
54093
|
+
const list3 = (0, import_node_path21.join)(dir, "files.txt");
|
|
54088
54094
|
try {
|
|
54089
|
-
await (0, import_promises2.writeFile)(
|
|
54095
|
+
await (0, import_promises2.writeFile)(list3, `${files.join("\n")}
|
|
54090
54096
|
`);
|
|
54091
|
-
const args = ["--no-summary", "--infected", "--stdout", `--file-list=${
|
|
54097
|
+
const args = ["--no-summary", "--infected", "--stdout", `--file-list=${list3}`];
|
|
54092
54098
|
if (info2.mode === "clamdscan") args.push("--fdpass", "--multiscan");
|
|
54093
54099
|
const r = await run2(info2.binary, args, opts.timeoutMs ?? 60 * 60 * 1e3, opts.signal);
|
|
54094
54100
|
for (const [path2, sigs] of parseClamOutput(r.stdout)) detections.set(path2, sigs.map(clamDetection));
|
|
@@ -55720,23 +55726,23 @@ function sshArgv(options) {
|
|
|
55720
55726
|
return args;
|
|
55721
55727
|
}
|
|
55722
55728
|
async function sshConnect(options) {
|
|
55723
|
-
const { hostname:
|
|
55724
|
-
if (!
|
|
55729
|
+
const { hostname: hostname8, port, username, identity } = options;
|
|
55730
|
+
if (!hostname8) {
|
|
55725
55731
|
console.log(source_default.red(" No hostname available for this server.\n"));
|
|
55726
55732
|
return;
|
|
55727
55733
|
}
|
|
55728
55734
|
const user = username || "root";
|
|
55729
|
-
const problem = sshTargetError({ hostname:
|
|
55735
|
+
const problem = sshTargetError({ hostname: hostname8, username: user, port });
|
|
55730
55736
|
if (problem) {
|
|
55731
55737
|
console.log(source_default.red(` ${problem}
|
|
55732
55738
|
`));
|
|
55733
55739
|
process.exitCode = 1;
|
|
55734
55740
|
return;
|
|
55735
55741
|
}
|
|
55736
|
-
console.log(source_default.green(` Connecting to ${user}@${
|
|
55742
|
+
console.log(source_default.green(` Connecting to ${user}@${hostname8}:${port}...
|
|
55737
55743
|
`));
|
|
55738
55744
|
console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
|
|
55739
|
-
const sshArgs = sshArgv({ hostname:
|
|
55745
|
+
const sshArgs = sshArgv({ hostname: hostname8, username: user, port, identity });
|
|
55740
55746
|
const ssh = (0, import_node_child_process11.spawn)("ssh", sshArgs, { stdio: "inherit" });
|
|
55741
55747
|
ssh.on("error", (err) => {
|
|
55742
55748
|
console.log(source_default.red(`
|
|
@@ -55755,16 +55761,16 @@ async function sshConnect(options) {
|
|
|
55755
55761
|
}
|
|
55756
55762
|
|
|
55757
55763
|
// src/commands/daemon.ts
|
|
55758
|
-
var
|
|
55759
|
-
var
|
|
55760
|
-
var
|
|
55761
|
-
var
|
|
55764
|
+
var import_node_child_process29 = require("child_process");
|
|
55765
|
+
var import_node_fs71 = require("fs");
|
|
55766
|
+
var import_node_path50 = require("path");
|
|
55767
|
+
var import_node_fs72 = require("fs");
|
|
55762
55768
|
|
|
55763
55769
|
// src/daemon/index.ts
|
|
55764
|
-
var
|
|
55765
|
-
var
|
|
55766
|
-
var
|
|
55767
|
-
var
|
|
55770
|
+
var import_node_fs70 = require("fs");
|
|
55771
|
+
var import_node_child_process28 = require("child_process");
|
|
55772
|
+
var import_node_os22 = require("os");
|
|
55773
|
+
var import_node_path49 = require("path");
|
|
55768
55774
|
var import_node_util4 = require("util");
|
|
55769
55775
|
init_paths();
|
|
55770
55776
|
|
|
@@ -58450,6 +58456,10 @@ var CloudSpool = class {
|
|
|
58450
58456
|
|
|
58451
58457
|
// src/daemon/workers/cloud-sync.ts
|
|
58452
58458
|
var MAX_BATCH_BYTES = 900 * 1024;
|
|
58459
|
+
function uploadSeverity(event) {
|
|
58460
|
+
const rule = event.details?.rule_severity;
|
|
58461
|
+
return typeof rule === "string" && rule in SEVERITY_RANK7 ? rule : event.severity;
|
|
58462
|
+
}
|
|
58453
58463
|
var CloudSync = class {
|
|
58454
58464
|
constructor(opts) {
|
|
58455
58465
|
this.opts = opts;
|
|
@@ -58534,7 +58544,7 @@ var CloudSync = class {
|
|
|
58534
58544
|
let out = null;
|
|
58535
58545
|
if (event.module === "firewall-rules") {
|
|
58536
58546
|
out = remediationEvent(link.serverId, event);
|
|
58537
|
-
} else if ((event.module === "rule-engine" || !this.opts.ruleModules.has(event.module)) && event.details?.heartbeat !== true && SEVERITY_RANK7[event
|
|
58547
|
+
} 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]) {
|
|
58538
58548
|
out = detectionEvent(link.serverId, event);
|
|
58539
58549
|
}
|
|
58540
58550
|
if (!out) return;
|
|
@@ -59086,11 +59096,11 @@ var import_node_net14 = require("net");
|
|
|
59086
59096
|
init_cli_config();
|
|
59087
59097
|
function isAddressOrCidr(value) {
|
|
59088
59098
|
const [network, prefix, extra] = value.split("/");
|
|
59089
|
-
const
|
|
59090
|
-
if (
|
|
59099
|
+
const family2 = (0, import_node_net14.isIP)(network);
|
|
59100
|
+
if (family2 === 0 || extra !== void 0) return false;
|
|
59091
59101
|
if (prefix === void 0) return true;
|
|
59092
59102
|
if (!/^\d{1,3}$/.test(prefix)) return false;
|
|
59093
|
-
return Number(prefix) <= (
|
|
59103
|
+
return Number(prefix) <= (family2 === 4 ? 32 : 128);
|
|
59094
59104
|
}
|
|
59095
59105
|
var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
|
|
59096
59106
|
function isCloudAllowEntry(value) {
|
|
@@ -63111,9 +63121,9 @@ var PostgresShellWatch = class {
|
|
|
63111
63121
|
if (!root) return [];
|
|
63112
63122
|
const children = /* @__PURE__ */ new Map();
|
|
63113
63123
|
for (const e of entries2.values()) {
|
|
63114
|
-
const
|
|
63115
|
-
|
|
63116
|
-
children.set(e.ppid,
|
|
63124
|
+
const list3 = children.get(e.ppid) ?? [];
|
|
63125
|
+
list3.push(e.pid);
|
|
63126
|
+
children.set(e.ppid, list3);
|
|
63117
63127
|
}
|
|
63118
63128
|
const order2 = [];
|
|
63119
63129
|
const visit = (pid, depth) => {
|
|
@@ -63362,9 +63372,9 @@ var DockerLogsWatch = class {
|
|
|
63362
63372
|
if (this.stopped) return;
|
|
63363
63373
|
const now = Date.now();
|
|
63364
63374
|
const previous = this.lastPoll;
|
|
63365
|
-
let
|
|
63375
|
+
let list3;
|
|
63366
63376
|
try {
|
|
63367
|
-
|
|
63377
|
+
list3 = await this.deps.getJson("/containers/json");
|
|
63368
63378
|
this.warned = false;
|
|
63369
63379
|
} catch (err) {
|
|
63370
63380
|
if (!this.warned) this.opts.log(`[docker-logs] cannot list containers: ${err.message}`);
|
|
@@ -63373,7 +63383,7 @@ var DockerLogsWatch = class {
|
|
|
63373
63383
|
}
|
|
63374
63384
|
this.lastPoll = now;
|
|
63375
63385
|
const running = /* @__PURE__ */ new Set();
|
|
63376
|
-
for (const c of Array.isArray(
|
|
63386
|
+
for (const c of Array.isArray(list3) ? list3 : []) {
|
|
63377
63387
|
if (!c?.Id || !this.matches(c)) continue;
|
|
63378
63388
|
running.add(c.Id);
|
|
63379
63389
|
if (this.follows.has(c.Id)) continue;
|
|
@@ -64101,6 +64111,8 @@ function evidenceOf(event) {
|
|
|
64101
64111
|
const v = details[k];
|
|
64102
64112
|
if (typeof v === "string" || typeof v === "number") out[k] = String(v).slice(0, EVIDENCE_FIELD_CHARS);
|
|
64103
64113
|
}
|
|
64114
|
+
const ctx = details.ssh_context;
|
|
64115
|
+
if (ctx && typeof ctx === "object" && !Array.isArray(ctx) && ctx.v === 1) out.ssh_context = ctx;
|
|
64104
64116
|
return out;
|
|
64105
64117
|
}
|
|
64106
64118
|
var RuleEngine = class {
|
|
@@ -64252,10 +64264,655 @@ var RuleEngine = class {
|
|
|
64252
64264
|
}
|
|
64253
64265
|
};
|
|
64254
64266
|
|
|
64255
|
-
// src/daemon/
|
|
64256
|
-
var
|
|
64267
|
+
// src/daemon/ssh-context/index.ts
|
|
64268
|
+
var import_node_os21 = require("os");
|
|
64257
64269
|
var import_node_path45 = require("path");
|
|
64258
64270
|
|
|
64271
|
+
// ../../packages/event-detail/src/verdict.ts
|
|
64272
|
+
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
64273
|
+
function maxSeverity2(a, b) {
|
|
64274
|
+
return RANK[a] >= RANK[b] ? a : b;
|
|
64275
|
+
}
|
|
64276
|
+
function severityRank2(s) {
|
|
64277
|
+
return RANK[s ?? "info"] ?? 0;
|
|
64278
|
+
}
|
|
64279
|
+
function describeFailures(f, ip) {
|
|
64280
|
+
if (!f) return null;
|
|
64281
|
+
const mins = Math.max(1, Math.round(f.window_s / 60));
|
|
64282
|
+
if (f.total === 0) {
|
|
64283
|
+
return `No failed SSH attempts in the ${mins} min before this login (the rule fires on every accepted login).`;
|
|
64284
|
+
}
|
|
64285
|
+
const top = (f.ips ?? []).filter((x) => x.ip !== ip).slice(0, 3).map((x) => `${x.ip} x${x.count}`).join(", ");
|
|
64286
|
+
const users = (f.users ?? []).slice(0, 4).map((u) => u.user).join(", ");
|
|
64287
|
+
const span2 = f.first && f.last ? ` between ${hhmmss(f.first)} and ${hhmmss(f.last)} UTC` : "";
|
|
64288
|
+
if (f.same_ip > 0 && f.other_ips === 0) {
|
|
64289
|
+
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.`;
|
|
64290
|
+
}
|
|
64291
|
+
if (f.same_ip === 0) {
|
|
64292
|
+
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.`;
|
|
64293
|
+
}
|
|
64294
|
+
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}` : ""}.`;
|
|
64295
|
+
}
|
|
64296
|
+
function hhmmss(iso) {
|
|
64297
|
+
const d = new Date(iso);
|
|
64298
|
+
return Number.isNaN(d.getTime()) ? iso : d.toISOString().slice(11, 19);
|
|
64299
|
+
}
|
|
64300
|
+
function computeVerdict(ctx) {
|
|
64301
|
+
const reasons = [];
|
|
64302
|
+
const key = ctx.key;
|
|
64303
|
+
const src = ctx.source;
|
|
64304
|
+
const ci = ctx.session?.ci_deploy;
|
|
64305
|
+
const forced = !!key?.command;
|
|
64306
|
+
const restricted = forced || !!key?.from;
|
|
64307
|
+
const publicSrc = !src || src.kind === "public" || src.kind === "github-actions";
|
|
64308
|
+
const ghActions = src?.kind === "github-actions";
|
|
64309
|
+
let severity = "info";
|
|
64310
|
+
let level = "review";
|
|
64311
|
+
const raise = (s, why) => {
|
|
64312
|
+
severity = maxSeverity2(severity, s);
|
|
64313
|
+
reasons.push(why);
|
|
64314
|
+
};
|
|
64315
|
+
if (key?.in_root_and_user) raise("critical", "the same key authorizes root and another account");
|
|
64316
|
+
if (key?.suspicious_comment) raise(restricted ? "high" : "critical", `key comment "${key.comment}" looks like a dated temporary CI/diagnostic key`);
|
|
64317
|
+
if (ctx.failures && ctx.failures.same_ip > 0) raise("critical", `${ctx.failures.same_ip} failed attempt(s) from this same address before it succeeded`);
|
|
64318
|
+
if (ci && /^deny/i.test(ci.decision)) raise("high", `ci-deploy DENIED${ci.repo ? ` ${ci.repo}` : ""}`);
|
|
64319
|
+
if (publicSrc && ctx.auth_method === "password") raise("critical", "password login from a public address");
|
|
64320
|
+
if (publicSrc && !ghActions && key?.found && !restricted && !key.restrict) raise("critical", "unrestricted key (no command=, from= or restrict) from a non-CI address");
|
|
64321
|
+
if (publicSrc && key && !key.found && ctx.auth_method === "publickey") raise("high", "key not found in any readable authorized_keys (another account, or AuthorizedKeysCommand)");
|
|
64322
|
+
if (forced && publicSrc && !ghActions) raise("medium", "forced-command key used from an address outside GitHub Actions");
|
|
64323
|
+
const red3 = severityRank2(severity) >= RANK.high;
|
|
64324
|
+
if (key?.expected && !red3) {
|
|
64325
|
+
level = "expected";
|
|
64326
|
+
severity = "info";
|
|
64327
|
+
reasons.unshift(`key marked as expected CI${key.comment ? ` (${key.comment})` : ""}`);
|
|
64328
|
+
} else if (ghActions && forced && !red3) {
|
|
64329
|
+
level = "likely-ci";
|
|
64330
|
+
severity = "low";
|
|
64331
|
+
reasons.unshift("GitHub Actions IP", "forced-command deploy key");
|
|
64332
|
+
if (ci && /^allow/i.test(ci.decision)) reasons.push(`ci-deploy ALLOW ${ci.action || ci.repo || ""}`.trim());
|
|
64333
|
+
} else if (src && ["loopback", "self", "tailscale", "private"].includes(src.kind) && !red3) {
|
|
64334
|
+
level = "internal";
|
|
64335
|
+
severity = maxSeverity2("low", severity);
|
|
64336
|
+
reasons.unshift(src.kind === "tailscale" ? "Tailscale address" : src.kind === "self" ? "one of this host's own addresses" : src.kind === "loopback" ? "loopback" : "private address");
|
|
64337
|
+
} else if (red3) {
|
|
64338
|
+
level = "suspicious";
|
|
64339
|
+
} else {
|
|
64340
|
+
severity = maxSeverity2("high", severity);
|
|
64341
|
+
if (!reasons.length) reasons.push(ghActions ? "GitHub Actions address but not a forced-command key" : "login from a public address");
|
|
64342
|
+
}
|
|
64343
|
+
return { level, severity, summary: verdictSummary(level, reasons, ctx), reasons };
|
|
64344
|
+
}
|
|
64345
|
+
function verdictSummary(level, reasons, ctx) {
|
|
64346
|
+
const head2 = {
|
|
64347
|
+
expected: "Expected CI key",
|
|
64348
|
+
"likely-ci": "Likely CI deploy",
|
|
64349
|
+
internal: "Internal login",
|
|
64350
|
+
review: "Review",
|
|
64351
|
+
suspicious: "Suspicious login"
|
|
64352
|
+
};
|
|
64353
|
+
if (level === "review" && reasons.length === 1 && /public address$/.test(reasons[0])) {
|
|
64354
|
+
const restricted = ctx.key?.command || ctx.key?.from;
|
|
64355
|
+
return `${head2.review}: ${restricted ? "restricted" : "unrestricted"} ${ctx.auth_method ?? "login"} from ${ctx.source?.ip ?? "a public address"}`;
|
|
64356
|
+
}
|
|
64357
|
+
return `${head2[level]}: ${reasons.join(", ")}`;
|
|
64358
|
+
}
|
|
64359
|
+
|
|
64360
|
+
// src/daemon/ssh-context/auth-history.ts
|
|
64361
|
+
var MAX_ENTRIES2 = 2e4;
|
|
64362
|
+
var KEEP_MS = 60 * 60 * 1e3;
|
|
64363
|
+
var SAME_ATTEMPT_MS = 1e4;
|
|
64364
|
+
function classifySshdMessage(message) {
|
|
64365
|
+
let m = /^Failed (?:password|publickey|none|keyboard-interactive\/pam|keyboard-interactive|hostbased) for (?:invalid user )?(\S+) from \S+ port (\d+)/.exec(message);
|
|
64366
|
+
if (m) return { kind: "failed", user: m[1], port: Number(m[2]) };
|
|
64367
|
+
m = /^Invalid user (\S*) from \S+(?: port (\d+))?/.exec(message);
|
|
64368
|
+
if (m) return { kind: "invalid", user: m[1] || "(empty)", port: m[2] ? Number(m[2]) : void 0 };
|
|
64369
|
+
m = /^(?:Connection closed by|Disconnected from) (?:authenticating|invalid) user (\S+) \S+ port (\d+)/.exec(message);
|
|
64370
|
+
if (m) return { kind: "preauth-close", user: m[1], port: Number(m[2]) };
|
|
64371
|
+
m = /^Disconnected from user (\S+) \S+ port (\d+)/.exec(message);
|
|
64372
|
+
if (m) return { kind: "close", user: m[1], port: Number(m[2]) };
|
|
64373
|
+
m = /^Received disconnect from \S+ port (\d+):\d+: .*disconnected by user/i.exec(message);
|
|
64374
|
+
if (m && !/\[preauth\]/.test(message)) return { kind: "close", port: Number(m[1]) };
|
|
64375
|
+
return null;
|
|
64376
|
+
}
|
|
64377
|
+
var SshAuthHistory = class {
|
|
64378
|
+
constructor(now = Date.now) {
|
|
64379
|
+
this.now = now;
|
|
64380
|
+
}
|
|
64381
|
+
now;
|
|
64382
|
+
failures = [];
|
|
64383
|
+
closes = [];
|
|
64384
|
+
seen = /* @__PURE__ */ new Map();
|
|
64385
|
+
record(line2) {
|
|
64386
|
+
const at = line2.timestamp instanceof Date ? line2.timestamp.getTime() : Date.now();
|
|
64387
|
+
if (Number.isNaN(at)) return;
|
|
64388
|
+
const key = `${at}|${line2.message}`;
|
|
64389
|
+
if (this.seen.has(key)) return;
|
|
64390
|
+
this.seen.set(key, at);
|
|
64391
|
+
const c = classifySshdMessage(line2.message);
|
|
64392
|
+
if (!c) return;
|
|
64393
|
+
if (c.kind === "close") {
|
|
64394
|
+
if (c.port) this.closes.push({ at, ip: line2.ip, port: c.port, user: c.user });
|
|
64395
|
+
} else {
|
|
64396
|
+
const user = c.user ?? "unknown";
|
|
64397
|
+
const same = [];
|
|
64398
|
+
if (c.port !== void 0) {
|
|
64399
|
+
for (let i = this.failures.length - 1; i >= 0; i--) {
|
|
64400
|
+
const f = this.failures[i];
|
|
64401
|
+
if (f.at < at - SAME_ATTEMPT_MS) break;
|
|
64402
|
+
if (f.ip === line2.ip && f.port === c.port) same.push(f);
|
|
64403
|
+
}
|
|
64404
|
+
}
|
|
64405
|
+
if (c.kind === "failed") {
|
|
64406
|
+
const placeholder = same.find((f) => f.kind !== "failed");
|
|
64407
|
+
if (placeholder) {
|
|
64408
|
+
placeholder.kind = "failed";
|
|
64409
|
+
placeholder.user = user;
|
|
64410
|
+
} else this.failures.push({ at, ip: line2.ip, user, kind: c.kind, port: c.port });
|
|
64411
|
+
} else if (same.length === 0) {
|
|
64412
|
+
this.failures.push({ at, ip: line2.ip, user, kind: c.kind, port: c.port });
|
|
64413
|
+
}
|
|
64414
|
+
}
|
|
64415
|
+
this.prune();
|
|
64416
|
+
}
|
|
64417
|
+
prune() {
|
|
64418
|
+
const cutoff = this.now() - KEEP_MS;
|
|
64419
|
+
if (this.failures.length > MAX_ENTRIES2) this.failures.splice(0, this.failures.length - MAX_ENTRIES2);
|
|
64420
|
+
if (this.closes.length > MAX_ENTRIES2) this.closes.splice(0, this.closes.length - MAX_ENTRIES2);
|
|
64421
|
+
while (this.failures.length && this.failures[0].at < cutoff) this.failures.shift();
|
|
64422
|
+
while (this.closes.length && this.closes[0].at < cutoff) this.closes.shift();
|
|
64423
|
+
if (this.seen.size > MAX_ENTRIES2) {
|
|
64424
|
+
let drop = this.seen.size - MAX_ENTRIES2 / 2;
|
|
64425
|
+
for (const k of this.seen.keys()) {
|
|
64426
|
+
if (drop-- <= 0) break;
|
|
64427
|
+
this.seen.delete(k);
|
|
64428
|
+
}
|
|
64429
|
+
}
|
|
64430
|
+
}
|
|
64431
|
+
/** Failures in the `windowS` seconds up to `atMs`, grouped, relative to the address that logged in. */
|
|
64432
|
+
failuresBefore(atMs, ip, windowS = 600) {
|
|
64433
|
+
const from = atMs - windowS * 1e3;
|
|
64434
|
+
const hits = this.failures.filter((f) => f.at >= from && f.at <= atMs + 1e3);
|
|
64435
|
+
const byIp = /* @__PURE__ */ new Map();
|
|
64436
|
+
const byUser = /* @__PURE__ */ new Map();
|
|
64437
|
+
for (const f of hits) {
|
|
64438
|
+
byIp.set(f.ip, (byIp.get(f.ip) ?? 0) + 1);
|
|
64439
|
+
byUser.set(f.user, (byUser.get(f.user) ?? 0) + 1);
|
|
64440
|
+
}
|
|
64441
|
+
const sameIp = byIp.get(ip) ?? 0;
|
|
64442
|
+
const top = (m, k) => [...m.entries()].sort((a, b) => b[1] - a[1]).slice(0, 10).map(([v, count]) => ({ [k]: v, count }));
|
|
64443
|
+
return {
|
|
64444
|
+
window_s: windowS,
|
|
64445
|
+
total: hits.length,
|
|
64446
|
+
same_ip: sameIp,
|
|
64447
|
+
other_ips: hits.length - sameIp,
|
|
64448
|
+
...hits.length ? {
|
|
64449
|
+
ips: top(byIp, "ip"),
|
|
64450
|
+
users: top(byUser, "user"),
|
|
64451
|
+
first: new Date(Math.min(...hits.map((h) => h.at))).toISOString(),
|
|
64452
|
+
last: new Date(Math.max(...hits.map((h) => h.at))).toISOString()
|
|
64453
|
+
} : {}
|
|
64454
|
+
};
|
|
64455
|
+
}
|
|
64456
|
+
/** When the session from `ip`:`port` closed, if it has. */
|
|
64457
|
+
closeOf(ip, port, afterMs) {
|
|
64458
|
+
if (!port) return null;
|
|
64459
|
+
const c = this.closes.find((x) => x.ip === ip && x.port === port && x.at >= afterMs - 1e3);
|
|
64460
|
+
return c ? c.at : null;
|
|
64461
|
+
}
|
|
64462
|
+
};
|
|
64463
|
+
|
|
64464
|
+
// src/daemon/ssh-context/authorized-keys.ts
|
|
64465
|
+
var import_node_fs64 = require("fs");
|
|
64466
|
+
var realKeyFilesIO = {
|
|
64467
|
+
passwd: () => {
|
|
64468
|
+
try {
|
|
64469
|
+
return (0, import_node_fs64.readFileSync)("/etc/passwd", "utf-8");
|
|
64470
|
+
} catch {
|
|
64471
|
+
return "";
|
|
64472
|
+
}
|
|
64473
|
+
},
|
|
64474
|
+
mtime: (p) => {
|
|
64475
|
+
try {
|
|
64476
|
+
return (0, import_node_fs64.statSync)(p).mtimeMs;
|
|
64477
|
+
} catch {
|
|
64478
|
+
return null;
|
|
64479
|
+
}
|
|
64480
|
+
},
|
|
64481
|
+
read: (p) => {
|
|
64482
|
+
try {
|
|
64483
|
+
return (0, import_node_fs64.readFileSync)(p, "utf-8");
|
|
64484
|
+
} catch {
|
|
64485
|
+
return null;
|
|
64486
|
+
}
|
|
64487
|
+
}
|
|
64488
|
+
};
|
|
64489
|
+
var NOLOGIN = /(?:nologin|false|sync|halt|shutdown)$/;
|
|
64490
|
+
function maskBlob(blob) {
|
|
64491
|
+
return `${blob.slice(0, 8)}\u2026[masked]`;
|
|
64492
|
+
}
|
|
64493
|
+
function optionText(o) {
|
|
64494
|
+
return o.value === null ? o.name : `${o.name}="${o.value.replace(/"/g, '\\"')}"`;
|
|
64495
|
+
}
|
|
64496
|
+
var MAX_OPTION_CHARS = 300;
|
|
64497
|
+
function maskedLine(k) {
|
|
64498
|
+
const opts = k.options.map((o) => optionText(o).slice(0, MAX_OPTION_CHARS)).join(",");
|
|
64499
|
+
return [opts, k.type, maskBlob(k.blob), k.comment].filter(Boolean).join(" ");
|
|
64500
|
+
}
|
|
64501
|
+
var AuthorizedKeysIndex = class {
|
|
64502
|
+
constructor(io = realKeyFilesIO) {
|
|
64503
|
+
this.io = io;
|
|
64504
|
+
}
|
|
64505
|
+
io;
|
|
64506
|
+
files = /* @__PURE__ */ new Map();
|
|
64507
|
+
accounts() {
|
|
64508
|
+
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(/\/$/, "") }));
|
|
64509
|
+
}
|
|
64510
|
+
keysIn(path2, user) {
|
|
64511
|
+
const mtime = this.io.mtime(path2);
|
|
64512
|
+
if (mtime === null) {
|
|
64513
|
+
this.files.delete(path2);
|
|
64514
|
+
return [];
|
|
64515
|
+
}
|
|
64516
|
+
const cached = this.files.get(path2);
|
|
64517
|
+
if (cached && cached.mtime === mtime) return cached.keys;
|
|
64518
|
+
const keys = parseAuthorizedKeys(this.io.read(path2) ?? "", path2).map((k) => ({ ...k, user }));
|
|
64519
|
+
this.files.set(path2, { mtime, keys });
|
|
64520
|
+
return keys;
|
|
64521
|
+
}
|
|
64522
|
+
/** Every authorized_keys line carrying `fingerprint`, as login context. */
|
|
64523
|
+
lookup(fingerprint, expected = /* @__PURE__ */ new Set()) {
|
|
64524
|
+
const matches2 = [];
|
|
64525
|
+
for (const { name, home } of this.accounts()) {
|
|
64526
|
+
for (const f of ["authorized_keys", "authorized_keys2"]) {
|
|
64527
|
+
for (const k2 of this.keysIn(`${home}/.ssh/${f}`, name)) if (k2.fingerprint === fingerprint) matches2.push(k2);
|
|
64528
|
+
}
|
|
64529
|
+
}
|
|
64530
|
+
if (!matches2.length) return { found: false, fingerprint, ...expected.has(fingerprint) ? { expected: true } : {} };
|
|
64531
|
+
const k = matches2.find((m) => !m.command && !m.from && !m.restrict) ?? matches2[0];
|
|
64532
|
+
const accounts = [...new Set(matches2.map((m) => m.user))];
|
|
64533
|
+
const inRoot = matches2.some((m) => m.user === "root" || m.file.startsWith("/root/"));
|
|
64534
|
+
const inOther = matches2.some((m) => m.user !== "root" && !m.file.startsWith("/root/"));
|
|
64535
|
+
return {
|
|
64536
|
+
found: true,
|
|
64537
|
+
type: k.type,
|
|
64538
|
+
fingerprint,
|
|
64539
|
+
comment: k.comment.slice(0, 200) || void 0,
|
|
64540
|
+
options: k.options.map((o) => optionText(o).slice(0, MAX_OPTION_CHARS)),
|
|
64541
|
+
command: k.command ? k.command.slice(0, 500) : null,
|
|
64542
|
+
from: k.from ? k.from.slice(0, 300) : null,
|
|
64543
|
+
restrict: k.restrict,
|
|
64544
|
+
files: matches2.map((m) => `${m.file}:${m.line}`).slice(0, 10),
|
|
64545
|
+
accounts,
|
|
64546
|
+
line_masked: maskedLine(k).slice(0, 800),
|
|
64547
|
+
in_root_and_user: inRoot && inOther,
|
|
64548
|
+
suspicious_comment: suspiciousKeyComment(k.comment),
|
|
64549
|
+
...expected.has(fingerprint) ? { expected: true } : {}
|
|
64550
|
+
};
|
|
64551
|
+
}
|
|
64552
|
+
};
|
|
64553
|
+
|
|
64554
|
+
// src/daemon/ssh-context/ip-intel.ts
|
|
64555
|
+
var import_node_net22 = require("net");
|
|
64556
|
+
var import_node_os20 = require("os");
|
|
64557
|
+
var import_node_dns2 = require("dns");
|
|
64558
|
+
var import_node_fs65 = require("fs");
|
|
64559
|
+
function list2(entries2) {
|
|
64560
|
+
const b = new import_node_net22.BlockList();
|
|
64561
|
+
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
64562
|
+
return b;
|
|
64563
|
+
}
|
|
64564
|
+
var LOOPBACK = list2([["127.0.0.0", 8, "ipv4"], ["::1", 128, "ipv6"]]);
|
|
64565
|
+
var TAILSCALE = list2([["100.64.0.0", 10, "ipv4"], ["fd7a:115c:a1e0::", 48, "ipv6"]]);
|
|
64566
|
+
var PRIVATE = list2([
|
|
64567
|
+
["10.0.0.0", 8, "ipv4"],
|
|
64568
|
+
["172.16.0.0", 12, "ipv4"],
|
|
64569
|
+
["192.168.0.0", 16, "ipv4"],
|
|
64570
|
+
["169.254.0.0", 16, "ipv4"],
|
|
64571
|
+
["fc00::", 7, "ipv6"],
|
|
64572
|
+
["fe80::", 10, "ipv6"]
|
|
64573
|
+
]);
|
|
64574
|
+
function family(ip) {
|
|
64575
|
+
const f = (0, import_node_net22.isIP)(ip);
|
|
64576
|
+
return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
|
|
64577
|
+
}
|
|
64578
|
+
function normalizeIp2(ip) {
|
|
64579
|
+
const m = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(ip);
|
|
64580
|
+
return m ? m[1] : ip;
|
|
64581
|
+
}
|
|
64582
|
+
function ownAddresses() {
|
|
64583
|
+
const out = /* @__PURE__ */ new Set();
|
|
64584
|
+
try {
|
|
64585
|
+
for (const list3 of Object.values((0, import_node_os20.networkInterfaces)())) for (const a of list3 ?? []) out.add(a.address.split("%")[0]);
|
|
64586
|
+
} catch {
|
|
64587
|
+
}
|
|
64588
|
+
return out;
|
|
64589
|
+
}
|
|
64590
|
+
function classifyAddress(raw, c) {
|
|
64591
|
+
const ip = normalizeIp2(raw);
|
|
64592
|
+
const f = family(ip);
|
|
64593
|
+
if (!f) return "public";
|
|
64594
|
+
if (LOOPBACK.check(ip, f)) return "loopback";
|
|
64595
|
+
if (c.own().has(ip)) return "self";
|
|
64596
|
+
if (TAILSCALE.check(ip, f)) return "tailscale";
|
|
64597
|
+
if (PRIVATE.check(ip, f)) return "private";
|
|
64598
|
+
if (c.isGitHubActions(ip)) return "github-actions";
|
|
64599
|
+
return "public";
|
|
64600
|
+
}
|
|
64601
|
+
var META_URL = "https://api.github.com/meta";
|
|
64602
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
64603
|
+
var RETRY_MS = 30 * 60 * 1e3;
|
|
64604
|
+
function rangesDeps(cacheFile) {
|
|
64605
|
+
return {
|
|
64606
|
+
fetchJson: async (url) => {
|
|
64607
|
+
const res = await fetch(url, {
|
|
64608
|
+
headers: { accept: "application/vnd.github+json", "user-agent": "threatcrush-agent" },
|
|
64609
|
+
signal: AbortSignal.timeout(15e3)
|
|
64610
|
+
});
|
|
64611
|
+
if (!res.ok) throw new Error(`GitHub meta ${res.status}`);
|
|
64612
|
+
return res.json();
|
|
64613
|
+
},
|
|
64614
|
+
load: () => {
|
|
64615
|
+
try {
|
|
64616
|
+
const v = JSON.parse((0, import_node_fs65.readFileSync)(cacheFile, "utf-8"));
|
|
64617
|
+
return typeof v.at === "number" && Array.isArray(v.cidrs) ? { at: v.at, cidrs: v.cidrs.map(String) } : null;
|
|
64618
|
+
} catch {
|
|
64619
|
+
return null;
|
|
64620
|
+
}
|
|
64621
|
+
},
|
|
64622
|
+
save: (v) => {
|
|
64623
|
+
try {
|
|
64624
|
+
(0, import_node_fs65.writeFileSync)(cacheFile, JSON.stringify(v), { mode: 420 });
|
|
64625
|
+
} catch {
|
|
64626
|
+
}
|
|
64627
|
+
},
|
|
64628
|
+
now: Date.now
|
|
64629
|
+
};
|
|
64630
|
+
}
|
|
64631
|
+
var GitHubActionsRanges = class {
|
|
64632
|
+
constructor(deps, enabled = true) {
|
|
64633
|
+
this.deps = deps;
|
|
64634
|
+
this.enabled = enabled;
|
|
64635
|
+
const saved = enabled ? deps.load() : null;
|
|
64636
|
+
if (saved?.cidrs.length) this.set(saved.cidrs, saved.at);
|
|
64637
|
+
}
|
|
64638
|
+
deps;
|
|
64639
|
+
enabled;
|
|
64640
|
+
list = null;
|
|
64641
|
+
count = 0;
|
|
64642
|
+
at = 0;
|
|
64643
|
+
lastTry = 0;
|
|
64644
|
+
inflight = null;
|
|
64645
|
+
set(cidrs, at) {
|
|
64646
|
+
const b = new import_node_net22.BlockList();
|
|
64647
|
+
let n = 0;
|
|
64648
|
+
for (const c of cidrs) {
|
|
64649
|
+
const [addr, bits2] = c.split("/");
|
|
64650
|
+
const f = family(addr);
|
|
64651
|
+
const p = Number(bits2);
|
|
64652
|
+
if (!f || !Number.isInteger(p)) continue;
|
|
64653
|
+
try {
|
|
64654
|
+
b.addSubnet(addr, p, f);
|
|
64655
|
+
n++;
|
|
64656
|
+
} catch {
|
|
64657
|
+
}
|
|
64658
|
+
}
|
|
64659
|
+
if (n) {
|
|
64660
|
+
this.list = b;
|
|
64661
|
+
this.count = n;
|
|
64662
|
+
this.at = at;
|
|
64663
|
+
}
|
|
64664
|
+
}
|
|
64665
|
+
size() {
|
|
64666
|
+
return this.count;
|
|
64667
|
+
}
|
|
64668
|
+
/** Refresh when stale; never throws, never blocks a lookup for long. */
|
|
64669
|
+
async refresh() {
|
|
64670
|
+
if (!this.enabled) return;
|
|
64671
|
+
const now = this.deps.now();
|
|
64672
|
+
if (this.list && now - this.at < DAY_MS) return;
|
|
64673
|
+
if (now - this.lastTry < RETRY_MS) return;
|
|
64674
|
+
this.inflight ??= (async () => {
|
|
64675
|
+
this.lastTry = now;
|
|
64676
|
+
try {
|
|
64677
|
+
const body = await this.deps.fetchJson(META_URL);
|
|
64678
|
+
const cidrs = Array.isArray(body?.actions) ? body.actions.filter((c) => typeof c === "string") : [];
|
|
64679
|
+
if (cidrs.length) {
|
|
64680
|
+
this.set(cidrs, now);
|
|
64681
|
+
this.deps.save({ at: now, cidrs });
|
|
64682
|
+
}
|
|
64683
|
+
} catch {
|
|
64684
|
+
}
|
|
64685
|
+
})().finally(() => {
|
|
64686
|
+
this.inflight = null;
|
|
64687
|
+
});
|
|
64688
|
+
return this.inflight;
|
|
64689
|
+
}
|
|
64690
|
+
has(raw) {
|
|
64691
|
+
const ip = normalizeIp2(raw);
|
|
64692
|
+
const f = family(ip);
|
|
64693
|
+
return !!(this.list && f && this.list.check(ip, f));
|
|
64694
|
+
}
|
|
64695
|
+
};
|
|
64696
|
+
var realNetLookup = {
|
|
64697
|
+
reverse: (ip) => import_node_dns2.promises.reverse(ip),
|
|
64698
|
+
txt: (name) => import_node_dns2.promises.resolveTxt(name)
|
|
64699
|
+
};
|
|
64700
|
+
function withTimeout2(p, ms) {
|
|
64701
|
+
return Promise.race([p.catch(() => null), new Promise((r) => setTimeout(() => r(null), ms).unref?.())]);
|
|
64702
|
+
}
|
|
64703
|
+
function cymruOriginName2(raw) {
|
|
64704
|
+
const ip = normalizeIp2(raw);
|
|
64705
|
+
const f = (0, import_node_net22.isIP)(ip);
|
|
64706
|
+
if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
|
|
64707
|
+
if (f !== 6) return null;
|
|
64708
|
+
const parts = ip.split("::");
|
|
64709
|
+
const head2 = parts[0] ? parts[0].split(":") : [];
|
|
64710
|
+
const tail = parts.length > 1 && parts[1] ? parts[1].split(":") : [];
|
|
64711
|
+
const groups = [...head2, ...Array(8 - head2.length - tail.length).fill("0"), ...tail].map((g) => g.padStart(4, "0"));
|
|
64712
|
+
return `${groups.join("").split("").reverse().join(".")}.origin6.asn.cymru.com`;
|
|
64713
|
+
}
|
|
64714
|
+
function parseCymruOrigin2(txt) {
|
|
64715
|
+
const f = txt.split("|").map((s) => s.trim());
|
|
64716
|
+
const asn = Number((f[0] ?? "").split(/\s+/)[0]);
|
|
64717
|
+
if (!Number.isInteger(asn) || asn <= 0) return null;
|
|
64718
|
+
return { asn, country: f[2] && /^[A-Z]{2}$/.test(f[2]) ? f[2] : null };
|
|
64719
|
+
}
|
|
64720
|
+
function parseCymruAsName(txt) {
|
|
64721
|
+
const f = txt.split("|").map((s) => s.trim());
|
|
64722
|
+
const name = f[4]?.replace(/,\s*[A-Z]{2}$/, "").trim();
|
|
64723
|
+
return name ? name.slice(0, 120) : null;
|
|
64724
|
+
}
|
|
64725
|
+
var NetLookup = class {
|
|
64726
|
+
constructor(deps = realNetLookup, timeoutMs = 2500, now = Date.now) {
|
|
64727
|
+
this.deps = deps;
|
|
64728
|
+
this.timeoutMs = timeoutMs;
|
|
64729
|
+
this.now = now;
|
|
64730
|
+
}
|
|
64731
|
+
deps;
|
|
64732
|
+
timeoutMs;
|
|
64733
|
+
now;
|
|
64734
|
+
cache = /* @__PURE__ */ new Map();
|
|
64735
|
+
async lookup(ip) {
|
|
64736
|
+
const hit = this.cache.get(ip);
|
|
64737
|
+
if (hit && this.now() - hit.at < 6 * 60 * 60 * 1e3) return hit.v;
|
|
64738
|
+
const originName = cymruOriginName2(ip);
|
|
64739
|
+
const [names, origin] = await Promise.all([
|
|
64740
|
+
withTimeout2(this.deps.reverse(normalizeIp2(ip)), this.timeoutMs),
|
|
64741
|
+
originName ? withTimeout2(this.deps.txt(originName), this.timeoutMs) : Promise.resolve(null)
|
|
64742
|
+
]);
|
|
64743
|
+
const o = origin?.[0] ? parseCymruOrigin2(origin[0].join("")) : null;
|
|
64744
|
+
let asOrg = null;
|
|
64745
|
+
if (o) {
|
|
64746
|
+
const named = await withTimeout2(this.deps.txt(`AS${o.asn}.asn.cymru.com`), this.timeoutMs);
|
|
64747
|
+
asOrg = named?.[0] ? parseCymruAsName(named[0].join("")) : null;
|
|
64748
|
+
}
|
|
64749
|
+
const v = { rdns: names?.[0]?.slice(0, 253) ?? null, asn: o?.asn ?? null, as_org: asOrg, country: o?.country ?? null };
|
|
64750
|
+
if (this.cache.size > 2e3) this.cache.clear();
|
|
64751
|
+
this.cache.set(ip, { at: this.now(), v });
|
|
64752
|
+
return v;
|
|
64753
|
+
}
|
|
64754
|
+
};
|
|
64755
|
+
|
|
64756
|
+
// src/daemon/ssh-context/ci-deploy.ts
|
|
64757
|
+
var import_node_child_process24 = require("child_process");
|
|
64758
|
+
var SECRETISH = /\b([A-Za-z_]*(?:token|secret|password|passwd|apikey|api_key|key|auth)[A-Za-z_]*)=("[^"]*"|'[^']*'|\S+)/gi;
|
|
64759
|
+
function redactCommand(cmd) {
|
|
64760
|
+
return cmd.replace(SECRETISH, "$1=[redacted]").slice(0, 300);
|
|
64761
|
+
}
|
|
64762
|
+
function parseCiDeployMessage(message) {
|
|
64763
|
+
const m = /^\s*(ALLOW|DENY|DENIED|REJECT(?:ED)?)\b\s*(?:\(([^)]*)\))?(.*)$/i.exec(message);
|
|
64764
|
+
if (!m) return null;
|
|
64765
|
+
const rest = m[3] ?? "";
|
|
64766
|
+
const repo = /\brepo=(\S+)/.exec(rest)?.[1];
|
|
64767
|
+
const from = /\bfrom=(\S+)/.exec(rest)?.[1];
|
|
64768
|
+
const cmd = /\bcmd=(.*)$/.exec(rest)?.[1]?.trim();
|
|
64769
|
+
return {
|
|
64770
|
+
decision: m[1].toUpperCase().startsWith("ALLOW") ? "ALLOW" : "DENY",
|
|
64771
|
+
...m[2] ? { action: m[2].trim().slice(0, 200) } : {},
|
|
64772
|
+
...repo ? { repo: repo.slice(0, 200) } : {},
|
|
64773
|
+
...from ? { from } : {},
|
|
64774
|
+
...cmd ? { command: redactCommand(cmd) } : {}
|
|
64775
|
+
};
|
|
64776
|
+
}
|
|
64777
|
+
function parseCiDeployJournal(text, tag = "ci-deploy") {
|
|
64778
|
+
const out = [];
|
|
64779
|
+
const esc = tag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
64780
|
+
const re = new RegExp(`^(\\d+(?:\\.\\d+)?)\\s+\\S+\\s+${esc}(?:\\[\\d+\\])?:\\s(.*)$`);
|
|
64781
|
+
for (const line2 of text.split("\n")) {
|
|
64782
|
+
const m = re.exec(line2);
|
|
64783
|
+
if (!m) continue;
|
|
64784
|
+
const parsed = parseCiDeployMessage(m[2]);
|
|
64785
|
+
if (!parsed) continue;
|
|
64786
|
+
const atMs = Math.round(Number(m[1]) * 1e3);
|
|
64787
|
+
out.push({ ...parsed, atMs, at: new Date(atMs).toISOString() });
|
|
64788
|
+
}
|
|
64789
|
+
return out;
|
|
64790
|
+
}
|
|
64791
|
+
function pickCiDeploy(lines, ip, atMs) {
|
|
64792
|
+
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));
|
|
64793
|
+
if (!near.length) return null;
|
|
64794
|
+
const { from: _from, atMs: _at, ...ctx } = near[0];
|
|
64795
|
+
return ctx;
|
|
64796
|
+
}
|
|
64797
|
+
var realJournal = (args) => new Promise((resolve9) => {
|
|
64798
|
+
(0, import_node_child_process24.execFile)("journalctl", args, { timeout: 4e3, maxBuffer: 1024 * 1024, encoding: "utf-8" }, (err, stdout) => resolve9(err ? null : stdout));
|
|
64799
|
+
});
|
|
64800
|
+
async function findCiDeploy(ip, atMs, tag = "ci-deploy", run3 = realJournal) {
|
|
64801
|
+
const s = Math.floor(atMs / 1e3);
|
|
64802
|
+
const out = await run3(["-t", tag, `--since=@${s - 5}`, `--until=@${s + 60}`, "-o", "short-unix", "--no-pager", "-q"]);
|
|
64803
|
+
return out ? pickCiDeploy(parseCiDeployJournal(out, tag), ip, atMs) : null;
|
|
64804
|
+
}
|
|
64805
|
+
|
|
64806
|
+
// src/daemon/ssh-context/index.ts
|
|
64807
|
+
function sshContextSettings(s) {
|
|
64808
|
+
const settle2 = Number(s?.settle_ms);
|
|
64809
|
+
const win = Number(s?.failure_window_seconds);
|
|
64810
|
+
return {
|
|
64811
|
+
enabled: s?.enabled !== false,
|
|
64812
|
+
networkLookups: s?.network_lookups !== false,
|
|
64813
|
+
githubRanges: s?.github_actions_ranges !== false,
|
|
64814
|
+
expectedKeys: new Set((Array.isArray(s?.expected_keys) ? s.expected_keys : []).map(String).filter((k) => k.startsWith("SHA256:"))),
|
|
64815
|
+
ciDeployTag: typeof s?.ci_deploy_tag === "string" && /^[\w.-]{1,64}$/.test(s.ci_deploy_tag) ? s.ci_deploy_tag : "ci-deploy",
|
|
64816
|
+
failureWindowS: Number.isFinite(win) && win >= 60 && win <= 86400 ? win : 600,
|
|
64817
|
+
settleMs: Number.isFinite(settle2) && settle2 >= 0 ? Math.min(settle2, 2e4) : 5e3
|
|
64818
|
+
};
|
|
64819
|
+
}
|
|
64820
|
+
function isAcceptedLogin(event) {
|
|
64821
|
+
return event.module === "ssh-guard" && /SSH login accepted/.test(event.message) && !!event.source_ip;
|
|
64822
|
+
}
|
|
64823
|
+
var SshLoginEnricher = class {
|
|
64824
|
+
constructor(settings, deps = {}) {
|
|
64825
|
+
this.settings = settings;
|
|
64826
|
+
this.deps = deps;
|
|
64827
|
+
const now = deps.now ?? Date.now;
|
|
64828
|
+
this.history = deps.history ?? new SshAuthHistory(now);
|
|
64829
|
+
this.keys = deps.keys ?? new AuthorizedKeysIndex();
|
|
64830
|
+
this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0, import_node_path45.join)(deps.stateDir ?? ".", "github-actions-ranges.json")), settings.githubRanges);
|
|
64831
|
+
this.net = deps.net ?? new NetLookup();
|
|
64832
|
+
this.sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
64833
|
+
this.host = deps.host ?? (0, import_node_os21.hostname)();
|
|
64834
|
+
const own = deps.own ?? (() => {
|
|
64835
|
+
if (now() - this.ownCache.at > 6e4) this.ownCache = { at: now(), v: ownAddresses() };
|
|
64836
|
+
return this.ownCache.v;
|
|
64837
|
+
});
|
|
64838
|
+
this.classifier = { own, isGitHubActions: (ip) => this.ranges.has(ip) };
|
|
64839
|
+
}
|
|
64840
|
+
settings;
|
|
64841
|
+
deps;
|
|
64842
|
+
history;
|
|
64843
|
+
keys;
|
|
64844
|
+
ranges;
|
|
64845
|
+
net;
|
|
64846
|
+
classifier;
|
|
64847
|
+
sleep;
|
|
64848
|
+
host;
|
|
64849
|
+
ownCache = { at: -Infinity, v: /* @__PURE__ */ new Set() };
|
|
64850
|
+
/** Warm the GitHub ranges at start-up; safe to call any time. */
|
|
64851
|
+
start() {
|
|
64852
|
+
if (this.settings.enabled) void this.ranges.refresh();
|
|
64853
|
+
}
|
|
64854
|
+
recordSshd(line2) {
|
|
64855
|
+
if (this.settings.enabled) this.history.record(line2);
|
|
64856
|
+
}
|
|
64857
|
+
wants(event) {
|
|
64858
|
+
return this.settings.enabled && isAcceptedLogin(event) && !("ssh_context" in (event.details ?? {}));
|
|
64859
|
+
}
|
|
64860
|
+
/** Adds `details.ssh_context` to the event in place and returns it. Never throws. */
|
|
64861
|
+
async enrich(event) {
|
|
64862
|
+
try {
|
|
64863
|
+
const d = event.details ??= {};
|
|
64864
|
+
const ip = normalizeIp2(event.source_ip ?? "");
|
|
64865
|
+
const atMs = event.timestamp instanceof Date ? event.timestamp.getTime() : Date.now();
|
|
64866
|
+
const user = typeof d.ssh_user === "string" ? d.ssh_user : /SSH login accepted for (\S+)/.exec(event.message)?.[1];
|
|
64867
|
+
const method = typeof d.auth_method === "string" ? d.auth_method : void 0;
|
|
64868
|
+
const fp = typeof d.fingerprint === "string" && d.fingerprint.startsWith("SHA256:") ? d.fingerprint : void 0;
|
|
64869
|
+
const port = typeof d.port === "number" ? d.port : Number(d.port) || void 0;
|
|
64870
|
+
await this.ranges.refresh();
|
|
64871
|
+
const kind = classifyAddress(ip, this.classifier);
|
|
64872
|
+
const key = fp ? this.keys.lookup(fp, this.settings.expectedKeys) : void 0;
|
|
64873
|
+
if (key && !key.type && typeof d.key_type === "string") key.type = d.key_type;
|
|
64874
|
+
const failures = this.history.failuresBefore(atMs, ip, this.settings.failureWindowS);
|
|
64875
|
+
const netP = this.settings.networkLookups && (kind === "public" || kind === "github-actions") ? this.net.lookup(ip).catch(() => null) : Promise.resolve(null);
|
|
64876
|
+
const settle2 = this.sleep(this.settings.settleMs);
|
|
64877
|
+
const [net] = await Promise.all([netP, settle2]);
|
|
64878
|
+
const ci = key?.command ? await findCiDeploy(ip, atMs, this.settings.ciDeployTag, this.deps.journal).catch(() => null) : null;
|
|
64879
|
+
const closed = this.history.closeOf(ip, port, atMs);
|
|
64880
|
+
let tz;
|
|
64881
|
+
try {
|
|
64882
|
+
tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
64883
|
+
} catch {
|
|
64884
|
+
tz = void 0;
|
|
64885
|
+
}
|
|
64886
|
+
const base = {
|
|
64887
|
+
v: 1,
|
|
64888
|
+
at: new Date(atMs).toISOString(),
|
|
64889
|
+
host: this.host,
|
|
64890
|
+
tz_offset_min: -new Date(atMs).getTimezoneOffset(),
|
|
64891
|
+
...tz ? { tz } : {},
|
|
64892
|
+
...user ? { user } : {},
|
|
64893
|
+
...method ? { auth_method: method } : {},
|
|
64894
|
+
...port ? { port } : {},
|
|
64895
|
+
...key ? { key } : {},
|
|
64896
|
+
source: { ip, kind, ...net ?? {} },
|
|
64897
|
+
failures,
|
|
64898
|
+
session: {
|
|
64899
|
+
...ci ? { ci_deploy: ci } : {},
|
|
64900
|
+
...closed !== null ? { closed_at: new Date(closed).toISOString(), duration_s: Math.max(0, Math.round((closed - atMs) / 1e3)) } : { open: true }
|
|
64901
|
+
}
|
|
64902
|
+
};
|
|
64903
|
+
const ctx = { ...base, verdict: computeVerdict(base) };
|
|
64904
|
+
d.ssh_context = ctx;
|
|
64905
|
+
return ctx;
|
|
64906
|
+
} catch {
|
|
64907
|
+
return null;
|
|
64908
|
+
}
|
|
64909
|
+
}
|
|
64910
|
+
};
|
|
64911
|
+
|
|
64912
|
+
// src/daemon/rules/loader.ts
|
|
64913
|
+
var import_node_fs66 = require("fs");
|
|
64914
|
+
var import_node_path46 = require("path");
|
|
64915
|
+
|
|
64259
64916
|
// src/daemon/rules/default-rules.ts
|
|
64260
64917
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
64261
64918
|
var SSHD_IDENT = String.raw`\[sshd(?:-session|-auth)?\]`;
|
|
@@ -64288,12 +64945,16 @@ var DEFAULT_RULES = [
|
|
|
64288
64945
|
{
|
|
64289
64946
|
id: "ssh-success-after-failures",
|
|
64290
64947
|
title: "SSH Login Accepted",
|
|
64291
|
-
//
|
|
64292
|
-
//
|
|
64293
|
-
//
|
|
64294
|
-
//
|
|
64948
|
+
// Matches every accepted login, not only one after failures (the id is
|
|
64949
|
+
// kept for dashboards and incidents keyed on it). What came before it is
|
|
64950
|
+
// in the login's ssh_context: the failures in the window and whether they
|
|
64951
|
+
// came from the same address. With [ssh_context] on (the default) the
|
|
64952
|
+
// detection's severity is the context's verdict: a GitHub Actions deploy
|
|
64953
|
+
// with a forced-command key is low, an operator-expected CI key is info,
|
|
64954
|
+
// an unrestricted key from the internet stays critical. It declares no
|
|
64955
|
+
// remediation: banning the person who just logged in is never the answer.
|
|
64295
64956
|
description: "Successful SSH login (alert only \u2014 never grounds for a ban)",
|
|
64296
|
-
version: "1.
|
|
64957
|
+
version: "1.1.0",
|
|
64297
64958
|
category: "auth",
|
|
64298
64959
|
severity: "critical",
|
|
64299
64960
|
source_types: ["ssh-guard", "auth"],
|
|
@@ -64305,7 +64966,7 @@ var DEFAULT_RULES = [
|
|
|
64305
64966
|
threshold: 1,
|
|
64306
64967
|
window_seconds: 60,
|
|
64307
64968
|
cooldown_seconds: 300,
|
|
64308
|
-
tags: ["ssh", "compromise-indicator"],
|
|
64969
|
+
tags: ["ssh", "compromise-indicator", "ssh-login-verdict"],
|
|
64309
64970
|
enabled: true
|
|
64310
64971
|
},
|
|
64311
64972
|
{
|
|
@@ -64926,16 +65587,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
64926
65587
|
function loadAllRules(customDir) {
|
|
64927
65588
|
const rules = [...DEFAULT_RULES];
|
|
64928
65589
|
const dir = customDir || RULES_DIR;
|
|
64929
|
-
if ((0,
|
|
65590
|
+
if ((0, import_node_fs66.existsSync)(dir)) {
|
|
64930
65591
|
let files = [];
|
|
64931
65592
|
try {
|
|
64932
|
-
files = (0,
|
|
65593
|
+
files = (0, import_node_fs66.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
64933
65594
|
} catch (err) {
|
|
64934
65595
|
console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
|
|
64935
65596
|
}
|
|
64936
65597
|
for (const file of files) {
|
|
64937
65598
|
try {
|
|
64938
|
-
const raw = (0,
|
|
65599
|
+
const raw = (0, import_node_fs66.readFileSync)((0, import_node_path46.join)(dir, file), "utf-8");
|
|
64939
65600
|
const parsed = JSON.parse(raw);
|
|
64940
65601
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
64941
65602
|
for (const rule of customRules) {
|
|
@@ -64966,24 +65627,24 @@ function loadAllRules(customDir) {
|
|
|
64966
65627
|
}
|
|
64967
65628
|
|
|
64968
65629
|
// src/daemon/firewall/adapters.ts
|
|
64969
|
-
var
|
|
64970
|
-
var
|
|
64971
|
-
var
|
|
64972
|
-
var
|
|
65630
|
+
var import_node_child_process25 = require("child_process");
|
|
65631
|
+
var import_node_fs67 = require("fs");
|
|
65632
|
+
var import_node_path47 = require("path");
|
|
65633
|
+
var import_node_net23 = require("net");
|
|
64973
65634
|
function assertValidFirewallIp(ip) {
|
|
64974
|
-
if ((0,
|
|
65635
|
+
if ((0, import_node_net23.isIP)(ip) !== 4) {
|
|
64975
65636
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
64976
65637
|
}
|
|
64977
65638
|
}
|
|
64978
65639
|
function assertBannableIp(ip) {
|
|
64979
|
-
if ((0,
|
|
65640
|
+
if ((0, import_node_net23.isIP)(ip) === 0) {
|
|
64980
65641
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
64981
65642
|
}
|
|
64982
65643
|
}
|
|
64983
65644
|
function writeIfAbsent(path2, contents) {
|
|
64984
|
-
(0,
|
|
65645
|
+
(0, import_node_fs67.mkdirSync)((0, import_node_path47.dirname)(path2), { recursive: true });
|
|
64985
65646
|
try {
|
|
64986
|
-
(0,
|
|
65647
|
+
(0, import_node_fs67.writeFileSync)(path2, contents, { flag: "wx" });
|
|
64987
65648
|
} catch (err) {
|
|
64988
65649
|
if (err.code !== "EEXIST") throw err;
|
|
64989
65650
|
}
|
|
@@ -65002,11 +65663,11 @@ var Fail2banAdapter = class {
|
|
|
65002
65663
|
enforces = true;
|
|
65003
65664
|
jailReady = false;
|
|
65004
65665
|
isAvailable() {
|
|
65005
|
-
const result = (0,
|
|
65666
|
+
const result = (0, import_node_child_process25.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
65006
65667
|
return result.status === 0;
|
|
65007
65668
|
}
|
|
65008
65669
|
client(args) {
|
|
65009
|
-
return (0,
|
|
65670
|
+
return (0, import_node_child_process25.execFileSync)("fail2ban-client", args, {
|
|
65010
65671
|
encoding: "utf-8",
|
|
65011
65672
|
stdio: ["ignore", "pipe", "pipe"]
|
|
65012
65673
|
});
|
|
@@ -65082,7 +65743,7 @@ var Fail2banAdapter = class {
|
|
|
65082
65743
|
const status = this.client(["status", this.jail]);
|
|
65083
65744
|
const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
65084
65745
|
if (!line2) return [];
|
|
65085
|
-
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
65746
|
+
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
|
|
65086
65747
|
} catch {
|
|
65087
65748
|
return [];
|
|
65088
65749
|
}
|
|
@@ -65092,45 +65753,45 @@ var Fail2banAdapter = class {
|
|
|
65092
65753
|
function parseBannedList(output) {
|
|
65093
65754
|
const found = [];
|
|
65094
65755
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
65095
|
-
if ((0,
|
|
65756
|
+
if ((0, import_node_net23.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
65096
65757
|
}
|
|
65097
65758
|
if (found.length > 0) return found;
|
|
65098
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
65759
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
|
|
65099
65760
|
}
|
|
65100
65761
|
var NftablesAdapter = class {
|
|
65101
65762
|
name = "nftables";
|
|
65102
65763
|
table = "threatcrush";
|
|
65103
65764
|
set = "blocklist";
|
|
65104
65765
|
isAvailable() {
|
|
65105
|
-
const result = (0,
|
|
65766
|
+
const result = (0, import_node_child_process25.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
65106
65767
|
return result.status === 0;
|
|
65107
65768
|
}
|
|
65108
65769
|
ensureSetup() {
|
|
65109
65770
|
try {
|
|
65110
|
-
(0,
|
|
65771
|
+
(0, import_node_child_process25.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
65111
65772
|
} catch {
|
|
65112
|
-
(0,
|
|
65113
|
-
(0,
|
|
65114
|
-
(0,
|
|
65115
|
-
(0,
|
|
65773
|
+
(0, import_node_child_process25.execSync)(`nft add table inet ${this.table}`);
|
|
65774
|
+
(0, import_node_child_process25.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
65775
|
+
(0, import_node_child_process25.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
65776
|
+
(0, import_node_child_process25.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
65116
65777
|
}
|
|
65117
65778
|
}
|
|
65118
65779
|
async block(ip) {
|
|
65119
65780
|
assertValidFirewallIp(ip);
|
|
65120
65781
|
this.ensureSetup();
|
|
65121
|
-
(0,
|
|
65782
|
+
(0, import_node_child_process25.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
65122
65783
|
}
|
|
65123
65784
|
async unblock(ip) {
|
|
65124
65785
|
assertValidFirewallIp(ip);
|
|
65125
65786
|
try {
|
|
65126
|
-
(0,
|
|
65787
|
+
(0, import_node_child_process25.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
65127
65788
|
} catch {
|
|
65128
65789
|
}
|
|
65129
65790
|
}
|
|
65130
65791
|
async isBlocked(ip) {
|
|
65131
65792
|
assertValidFirewallIp(ip);
|
|
65132
65793
|
try {
|
|
65133
|
-
const output = (0,
|
|
65794
|
+
const output = (0, import_node_child_process25.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
65134
65795
|
return output.includes(ip);
|
|
65135
65796
|
} catch {
|
|
65136
65797
|
return false;
|
|
@@ -65138,7 +65799,7 @@ var NftablesAdapter = class {
|
|
|
65138
65799
|
}
|
|
65139
65800
|
async listBlocked() {
|
|
65140
65801
|
try {
|
|
65141
|
-
const output = (0,
|
|
65802
|
+
const output = (0, import_node_child_process25.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
65142
65803
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
65143
65804
|
if (!match) return [];
|
|
65144
65805
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -65151,34 +65812,34 @@ var IptablesAdapter = class {
|
|
|
65151
65812
|
name = "iptables";
|
|
65152
65813
|
chain = "THREATCRUSH";
|
|
65153
65814
|
isAvailable() {
|
|
65154
|
-
const result = (0,
|
|
65815
|
+
const result = (0, import_node_child_process25.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
65155
65816
|
return result.status === 0;
|
|
65156
65817
|
}
|
|
65157
65818
|
ensureChain() {
|
|
65158
65819
|
try {
|
|
65159
|
-
(0,
|
|
65820
|
+
(0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
65160
65821
|
} catch {
|
|
65161
|
-
(0,
|
|
65162
|
-
(0,
|
|
65822
|
+
(0, import_node_child_process25.execSync)(`iptables -N ${this.chain}`);
|
|
65823
|
+
(0, import_node_child_process25.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
65163
65824
|
}
|
|
65164
65825
|
}
|
|
65165
65826
|
async block(ip) {
|
|
65166
65827
|
assertValidFirewallIp(ip);
|
|
65167
65828
|
this.ensureChain();
|
|
65168
65829
|
if (await this.isBlocked(ip)) return;
|
|
65169
|
-
(0,
|
|
65830
|
+
(0, import_node_child_process25.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
65170
65831
|
}
|
|
65171
65832
|
async unblock(ip) {
|
|
65172
65833
|
assertValidFirewallIp(ip);
|
|
65173
65834
|
try {
|
|
65174
|
-
(0,
|
|
65835
|
+
(0, import_node_child_process25.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
65175
65836
|
} catch {
|
|
65176
65837
|
}
|
|
65177
65838
|
}
|
|
65178
65839
|
async isBlocked(ip) {
|
|
65179
65840
|
assertValidFirewallIp(ip);
|
|
65180
65841
|
try {
|
|
65181
|
-
const output = (0,
|
|
65842
|
+
const output = (0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
65182
65843
|
return output.includes(ip);
|
|
65183
65844
|
} catch {
|
|
65184
65845
|
return false;
|
|
@@ -65186,7 +65847,7 @@ var IptablesAdapter = class {
|
|
|
65186
65847
|
}
|
|
65187
65848
|
async listBlocked() {
|
|
65188
65849
|
try {
|
|
65189
|
-
const output = (0,
|
|
65850
|
+
const output = (0, import_node_child_process25.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
65190
65851
|
const ips = [];
|
|
65191
65852
|
for (const line2 of output.split("\n")) {
|
|
65192
65853
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -65242,22 +65903,22 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
65242
65903
|
}
|
|
65243
65904
|
|
|
65244
65905
|
// src/daemon/firewall/remediation.ts
|
|
65245
|
-
var
|
|
65246
|
-
var
|
|
65247
|
-
var
|
|
65906
|
+
var import_node_fs68 = require("fs");
|
|
65907
|
+
var import_node_child_process26 = require("child_process");
|
|
65908
|
+
var import_node_net24 = require("net");
|
|
65248
65909
|
init_paths();
|
|
65249
65910
|
init_backoff();
|
|
65250
65911
|
|
|
65251
65912
|
// src/daemon/firewall/crawlers.ts
|
|
65252
|
-
var
|
|
65913
|
+
var import_node_dns3 = require("dns");
|
|
65253
65914
|
var CRAWLER_DOMAINS = ["googlebot.com", "google.com", "search.msn.com", "applebot.apple.com"];
|
|
65254
65915
|
var systemResolver = {
|
|
65255
|
-
reverse: (ip) =>
|
|
65256
|
-
lookup: async (host) => (await
|
|
65916
|
+
reverse: (ip) => import_node_dns3.promises.reverse(ip),
|
|
65917
|
+
lookup: async (host) => (await import_node_dns3.promises.lookup(host, { all: true })).map((a) => a.address)
|
|
65257
65918
|
};
|
|
65258
65919
|
var TIMEOUT_MS2 = 2e3;
|
|
65259
65920
|
var CACHE_MS = 6 * 36e5;
|
|
65260
|
-
function
|
|
65921
|
+
function withTimeout3(p) {
|
|
65261
65922
|
return Promise.race([
|
|
65262
65923
|
p,
|
|
65263
65924
|
new Promise((_, reject) => setTimeout(() => reject(new Error("dns timeout")), TIMEOUT_MS2).unref())
|
|
@@ -65274,9 +65935,9 @@ function crawlerVerifier(resolver = systemResolver) {
|
|
|
65274
65935
|
if (hit && hit.until > Date.now()) return hit.host;
|
|
65275
65936
|
let host = null;
|
|
65276
65937
|
try {
|
|
65277
|
-
const names = await
|
|
65938
|
+
const names = await withTimeout3(resolver.reverse(ip));
|
|
65278
65939
|
for (const name of names.filter(inCrawlerDomain)) {
|
|
65279
|
-
const addrs = await
|
|
65940
|
+
const addrs = await withTimeout3(resolver.lookup(name));
|
|
65280
65941
|
if (addrs.includes(ip)) {
|
|
65281
65942
|
host = name.replace(/\.$/, "");
|
|
65282
65943
|
break;
|
|
@@ -65314,19 +65975,19 @@ var defaultDiscovery = {
|
|
|
65314
65975
|
const snapshot = takeSnapshot({
|
|
65315
65976
|
readFile: (p) => {
|
|
65316
65977
|
try {
|
|
65317
|
-
return (0,
|
|
65978
|
+
return (0, import_node_fs68.readFileSync)(p, "utf-8");
|
|
65318
65979
|
} catch {
|
|
65319
65980
|
return null;
|
|
65320
65981
|
}
|
|
65321
65982
|
},
|
|
65322
65983
|
readDir: (p) => {
|
|
65323
65984
|
try {
|
|
65324
|
-
return (0,
|
|
65985
|
+
return (0, import_node_fs68.readdirSync)(p);
|
|
65325
65986
|
} catch {
|
|
65326
65987
|
return null;
|
|
65327
65988
|
}
|
|
65328
65989
|
},
|
|
65329
|
-
exists: (p) => (0,
|
|
65990
|
+
exists: (p) => (0, import_node_fs68.existsSync)(p)
|
|
65330
65991
|
});
|
|
65331
65992
|
const out = /* @__PURE__ */ new Set();
|
|
65332
65993
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -65335,7 +65996,7 @@ var defaultDiscovery = {
|
|
|
65335
65996
|
return out;
|
|
65336
65997
|
},
|
|
65337
65998
|
keyLoginJournal: (sinceSeconds) => new Promise((resolve9) => {
|
|
65338
|
-
(0,
|
|
65999
|
+
(0, import_node_child_process26.execFile)(
|
|
65339
66000
|
"journalctl",
|
|
65340
66001
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
65341
66002
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
@@ -65415,7 +66076,7 @@ var RemediationManager = class {
|
|
|
65415
66076
|
setTorExitCheck(check2) {
|
|
65416
66077
|
this.isTorExit = check2;
|
|
65417
66078
|
let dropped = 0;
|
|
65418
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
66079
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net24.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
65419
66080
|
for (const ip of Object.keys(this.operators)) {
|
|
65420
66081
|
if (!check2(ip)) continue;
|
|
65421
66082
|
delete this.operators[ip];
|
|
@@ -65508,7 +66169,7 @@ var RemediationManager = class {
|
|
|
65508
66169
|
if (remediation?.action !== "block") return;
|
|
65509
66170
|
}
|
|
65510
66171
|
const ip = event.source_ip;
|
|
65511
|
-
if (!ip || (0,
|
|
66172
|
+
if (!ip || (0, import_node_net24.isIP)(ip) === 0) return;
|
|
65512
66173
|
const strict = remediation?.override_operator_protection === true;
|
|
65513
66174
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
65514
66175
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -65537,7 +66198,7 @@ var RemediationManager = class {
|
|
|
65537
66198
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
65538
66199
|
*/
|
|
65539
66200
|
async ban(ip, reason, opts = {}) {
|
|
65540
|
-
if ((0,
|
|
66201
|
+
if ((0, import_node_net24.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
65541
66202
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
65542
66203
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
65543
66204
|
}
|
|
@@ -65814,7 +66475,7 @@ var RemediationManager = class {
|
|
|
65814
66475
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
65815
66476
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
65816
66477
|
for (const [ip, at] of Object.entries(saved)) {
|
|
65817
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
66478
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net24.isIP)(ip)) continue;
|
|
65818
66479
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
65819
66480
|
this.operators[ip] = at;
|
|
65820
66481
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -65839,7 +66500,7 @@ var RemediationManager = class {
|
|
|
65839
66500
|
}
|
|
65840
66501
|
logLine(line2) {
|
|
65841
66502
|
try {
|
|
65842
|
-
(0,
|
|
66503
|
+
(0, import_node_fs68.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
65843
66504
|
`);
|
|
65844
66505
|
} catch {
|
|
65845
66506
|
}
|
|
@@ -65883,19 +66544,19 @@ function remediationSettings(section) {
|
|
|
65883
66544
|
init_backoff();
|
|
65884
66545
|
|
|
65885
66546
|
// src/daemon/watchdog-service.ts
|
|
65886
|
-
var
|
|
65887
|
-
var
|
|
66547
|
+
var import_node_fs69 = require("fs");
|
|
66548
|
+
var import_node_path48 = require("path");
|
|
65888
66549
|
function defaultShareGid() {
|
|
65889
66550
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
65890
66551
|
if (!isRoot4) return void 0;
|
|
65891
66552
|
try {
|
|
65892
|
-
return (0,
|
|
66553
|
+
return (0, import_node_fs69.statSync)("/var/log/auth.log").gid;
|
|
65893
66554
|
} catch {
|
|
65894
66555
|
return void 0;
|
|
65895
66556
|
}
|
|
65896
66557
|
}
|
|
65897
66558
|
function startWatchdog(opts) {
|
|
65898
|
-
const dir = opts.config?.dir ?? (0,
|
|
66559
|
+
const dir = opts.config?.dir ?? (0, import_node_path48.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
65899
66560
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
65900
66561
|
if (opts.config?.enabled === false) {
|
|
65901
66562
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -65989,7 +66650,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
65989
66650
|
}
|
|
65990
66651
|
|
|
65991
66652
|
// src/core/node-runtime.ts
|
|
65992
|
-
var
|
|
66653
|
+
var import_node_child_process27 = require("child_process");
|
|
65993
66654
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
65994
66655
|
function nodeMajor(version) {
|
|
65995
66656
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -66003,23 +66664,23 @@ function daemonNodeProblem(version) {
|
|
|
66003
66664
|
}
|
|
66004
66665
|
function versionOfNode(path2) {
|
|
66005
66666
|
if (path2 === process.execPath) return process.versions.node;
|
|
66006
|
-
const res = (0,
|
|
66667
|
+
const res = (0, import_node_child_process27.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
66007
66668
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
66008
66669
|
}
|
|
66009
66670
|
|
|
66010
66671
|
// src/daemon/index.ts
|
|
66011
66672
|
function readVersion2() {
|
|
66012
66673
|
try {
|
|
66013
|
-
const pkg = JSON.parse((0,
|
|
66674
|
+
const pkg = JSON.parse((0, import_node_fs70.readFileSync)((0, import_node_path49.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
66014
66675
|
return pkg.version || "0.0.0";
|
|
66015
66676
|
} catch {
|
|
66016
66677
|
return "0.0.0";
|
|
66017
66678
|
}
|
|
66018
66679
|
}
|
|
66019
66680
|
async function runHardeningChecks() {
|
|
66020
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
66681
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process28.execFile)(
|
|
66021
66682
|
process.execPath,
|
|
66022
|
-
[(0,
|
|
66683
|
+
[(0, import_node_path49.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
66023
66684
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
66024
66685
|
);
|
|
66025
66686
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -66031,9 +66692,9 @@ async function runHardeningChecks() {
|
|
|
66031
66692
|
return patches ? [...findings2, patches] : findings2;
|
|
66032
66693
|
}
|
|
66033
66694
|
async function runPatchCheck() {
|
|
66034
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
66695
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process28.execFile)(
|
|
66035
66696
|
process.execPath,
|
|
66036
|
-
[(0,
|
|
66697
|
+
[(0, import_node_path49.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
66037
66698
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
66038
66699
|
);
|
|
66039
66700
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -66041,7 +66702,7 @@ async function runPatchCheck() {
|
|
|
66041
66702
|
}
|
|
66042
66703
|
function logLine(line2) {
|
|
66043
66704
|
try {
|
|
66044
|
-
(0,
|
|
66705
|
+
(0, import_node_fs70.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
66045
66706
|
`);
|
|
66046
66707
|
} catch {
|
|
66047
66708
|
}
|
|
@@ -66066,9 +66727,9 @@ async function runDaemon() {
|
|
|
66066
66727
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
66067
66728
|
const restartDaemon = () => {
|
|
66068
66729
|
if (PATHS.mode === "system") {
|
|
66069
|
-
(0,
|
|
66730
|
+
(0, import_node_child_process28.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
66070
66731
|
} else {
|
|
66071
|
-
(0,
|
|
66732
|
+
(0, import_node_child_process28.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
66072
66733
|
setTimeout(() => process.exit(0), 500).unref();
|
|
66073
66734
|
}
|
|
66074
66735
|
};
|
|
@@ -66083,7 +66744,7 @@ async function runDaemon() {
|
|
|
66083
66744
|
} catch (err) {
|
|
66084
66745
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
66085
66746
|
}
|
|
66086
|
-
const loaded = loadDaemonConfig(PATHS.configFile, (0,
|
|
66747
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path49.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
66087
66748
|
const config = loaded.config;
|
|
66088
66749
|
if (loaded.error) {
|
|
66089
66750
|
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)"}`);
|
|
@@ -66107,27 +66768,37 @@ async function runDaemon() {
|
|
|
66107
66768
|
const moduleHost = new ModuleHost(bus);
|
|
66108
66769
|
await moduleHost.start();
|
|
66109
66770
|
const ruleEngine = new RuleEngine((detection) => {
|
|
66771
|
+
const ctx = detection.raw_metadata?.evidence?.ssh_context;
|
|
66772
|
+
const useVerdict = !!ctx?.verdict && Array.isArray(detection.raw_metadata?.tags) && detection.raw_metadata.tags.includes("ssh-login-verdict");
|
|
66110
66773
|
const event = {
|
|
66111
66774
|
timestamp: /* @__PURE__ */ new Date(),
|
|
66112
66775
|
module: "rule-engine",
|
|
66113
66776
|
category: detection.raw_metadata?.category || "system",
|
|
66114
|
-
severity: detection.severity,
|
|
66777
|
+
severity: useVerdict ? ctx.verdict.severity : detection.severity,
|
|
66115
66778
|
message: `[DETECTION] ${detection.title}`,
|
|
66116
66779
|
source_ip: detection.source_ip,
|
|
66117
66780
|
details: {
|
|
66118
66781
|
rule_id: detection.rule_id,
|
|
66119
|
-
description: detection.description,
|
|
66782
|
+
description: useVerdict ? [ctx.verdict.summary, describeFailures(ctx.failures, ctx.source?.ip)].filter(Boolean).join(". ") : detection.description,
|
|
66120
66783
|
username: detection.username,
|
|
66121
|
-
...detection.raw_metadata
|
|
66784
|
+
...detection.raw_metadata,
|
|
66785
|
+
...useVerdict && ctx.verdict.severity !== detection.severity ? { rule_severity: detection.severity } : {}
|
|
66122
66786
|
}
|
|
66123
66787
|
};
|
|
66124
66788
|
bus.publish(event);
|
|
66125
66789
|
});
|
|
66126
66790
|
ruleEngine.loadRules(loadAllRules());
|
|
66127
66791
|
const keyDirectory = new KeyDirectory();
|
|
66792
|
+
const sshContext = new SshLoginEnricher(sshContextSettings(config.ssh_context), { stateDir: PATHS.stateDir });
|
|
66793
|
+
sshContext.start();
|
|
66794
|
+
bus.on("sshd", (line2) => sshContext.recordSshd(line2));
|
|
66128
66795
|
bus.on("event", (event) => {
|
|
66129
66796
|
if (event.module === "rule-engine") return;
|
|
66130
66797
|
enrichLoginEvent(event, keyDirectory);
|
|
66798
|
+
if (sshContext.wants(event)) {
|
|
66799
|
+
void sshContext.enrich(event).finally(() => ruleEngine.evaluate(event));
|
|
66800
|
+
return;
|
|
66801
|
+
}
|
|
66131
66802
|
ruleEngine.evaluate(event);
|
|
66132
66803
|
});
|
|
66133
66804
|
logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
|
|
@@ -66154,7 +66825,7 @@ async function runDaemon() {
|
|
|
66154
66825
|
const threatFeeds = new ThreatFeeds({
|
|
66155
66826
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
66156
66827
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
66157
|
-
cachePath: (0,
|
|
66828
|
+
cachePath: (0, import_node_path49.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
66158
66829
|
bus,
|
|
66159
66830
|
log: logLine
|
|
66160
66831
|
});
|
|
@@ -66162,9 +66833,9 @@ async function runDaemon() {
|
|
|
66162
66833
|
const privilegeWatch = new PrivilegeWatch({
|
|
66163
66834
|
settings: privilegeSettings(config.privileged),
|
|
66164
66835
|
bus,
|
|
66165
|
-
snapshotPath: (0,
|
|
66166
|
-
loginsPath: (0,
|
|
66167
|
-
cursorPath: (0,
|
|
66836
|
+
snapshotPath: (0, import_node_path49.join)(PATHS.stateDir, "privileges.json"),
|
|
66837
|
+
loginsPath: (0, import_node_path49.join)(PATHS.stateDir, "login-countries.json"),
|
|
66838
|
+
cursorPath: (0, import_node_path49.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
66168
66839
|
log: logLine
|
|
66169
66840
|
});
|
|
66170
66841
|
privilegeWatch.start();
|
|
@@ -66178,8 +66849,8 @@ async function runDaemon() {
|
|
|
66178
66849
|
const fileIntegrity = new FileIntegrityWatch({
|
|
66179
66850
|
bus,
|
|
66180
66851
|
settings: fileIntegritySettings(config.file_integrity),
|
|
66181
|
-
baselinePath: (0,
|
|
66182
|
-
observedPath: (0,
|
|
66852
|
+
baselinePath: (0, import_node_path49.join)(PATHS.stateDir, "file-integrity-baseline.json"),
|
|
66853
|
+
observedPath: (0, import_node_path49.join)(PATHS.stateDir, "file-integrity-observed.json"),
|
|
66183
66854
|
// `[remediation] dry_run` also covers the opt-in contain_writer response.
|
|
66184
66855
|
dryRun: () => remediation.status().dry_run,
|
|
66185
66856
|
log: logLine
|
|
@@ -66188,13 +66859,13 @@ async function runDaemon() {
|
|
|
66188
66859
|
const edr = new EdrWatch({
|
|
66189
66860
|
bus,
|
|
66190
66861
|
settings: edrSettings(config.edr),
|
|
66191
|
-
networkBaselinePath: (0,
|
|
66192
|
-
sourceStatusPath: (0,
|
|
66862
|
+
networkBaselinePath: (0, import_node_path49.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
66863
|
+
sourceStatusPath: (0, import_node_path49.join)(PATHS.stateDir, "edr-source.json"),
|
|
66193
66864
|
log: logLine
|
|
66194
66865
|
});
|
|
66195
66866
|
edr.start();
|
|
66196
66867
|
const torExits = new TorExitList({
|
|
66197
|
-
cachePath: (0,
|
|
66868
|
+
cachePath: (0, import_node_path49.join)(PATHS.stateDir, "tor-exits.txt"),
|
|
66198
66869
|
url: config.remediation?.tor_exit_list_url,
|
|
66199
66870
|
log: logLine
|
|
66200
66871
|
});
|
|
@@ -66202,7 +66873,7 @@ async function runDaemon() {
|
|
|
66202
66873
|
bus,
|
|
66203
66874
|
manager: remediation,
|
|
66204
66875
|
tor: torExits,
|
|
66205
|
-
historyPath: (0,
|
|
66876
|
+
historyPath: (0, import_node_path49.join)(PATHS.stateDir, "key-logins.json"),
|
|
66206
66877
|
keyLoginWatch: config.privileged?.key_login_watch !== false,
|
|
66207
66878
|
log: logLine
|
|
66208
66879
|
});
|
|
@@ -66275,9 +66946,9 @@ async function runDaemon() {
|
|
|
66275
66946
|
cloudSync = new CloudSync({
|
|
66276
66947
|
bus,
|
|
66277
66948
|
version,
|
|
66278
|
-
hostname: (0,
|
|
66949
|
+
hostname: (0, import_node_os22.hostname)(),
|
|
66279
66950
|
minSeverity,
|
|
66280
|
-
spoolPath: (0,
|
|
66951
|
+
spoolPath: (0, import_node_path49.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
66281
66952
|
log: logLine,
|
|
66282
66953
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
66283
66954
|
runHardening: runHardeningChecks
|
|
@@ -66311,8 +66982,8 @@ async function runDaemon() {
|
|
|
66311
66982
|
const autoUpdate = autoUpdateRef = new AutoUpdate({
|
|
66312
66983
|
version,
|
|
66313
66984
|
settings: updateSettings(config.update),
|
|
66314
|
-
pkgRoot: (0,
|
|
66315
|
-
statePath: (0,
|
|
66985
|
+
pkgRoot: (0, import_node_path49.join)(__dirname, ".."),
|
|
66986
|
+
statePath: (0, import_node_path49.join)(PATHS.stateDir, "auto-update.json"),
|
|
66316
66987
|
bus,
|
|
66317
66988
|
log: logLine,
|
|
66318
66989
|
restartDaemon
|
|
@@ -66434,7 +67105,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
66434
67105
|
function isRoot2() {
|
|
66435
67106
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
66436
67107
|
}
|
|
66437
|
-
var DAEMON_ENTRY = (0,
|
|
67108
|
+
var DAEMON_ENTRY = (0, import_node_path50.join)(__dirname, "daemon.js");
|
|
66438
67109
|
async function daemonForeground() {
|
|
66439
67110
|
await runDaemon();
|
|
66440
67111
|
}
|
|
@@ -66455,7 +67126,7 @@ async function daemonStart() {
|
|
|
66455
67126
|
return;
|
|
66456
67127
|
}
|
|
66457
67128
|
ensureRuntimeDirs();
|
|
66458
|
-
if (!(0,
|
|
67129
|
+
if (!(0, import_node_fs71.existsSync)(DAEMON_ENTRY)) {
|
|
66459
67130
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
66460
67131
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
66461
67132
|
return;
|
|
@@ -66463,8 +67134,8 @@ async function daemonStart() {
|
|
|
66463
67134
|
let out;
|
|
66464
67135
|
let err;
|
|
66465
67136
|
try {
|
|
66466
|
-
out = (0,
|
|
66467
|
-
err = (0,
|
|
67137
|
+
out = (0, import_node_fs72.openSync)(PATHS.logFile, "a");
|
|
67138
|
+
err = (0, import_node_fs72.openSync)(PATHS.logFile, "a");
|
|
66468
67139
|
} catch (e) {
|
|
66469
67140
|
const code = e.code;
|
|
66470
67141
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -66477,7 +67148,7 @@ async function daemonStart() {
|
|
|
66477
67148
|
}
|
|
66478
67149
|
return;
|
|
66479
67150
|
}
|
|
66480
|
-
const child = (0,
|
|
67151
|
+
const child = (0, import_node_child_process29.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
66481
67152
|
detached: true,
|
|
66482
67153
|
stdio: ["ignore", out, err],
|
|
66483
67154
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -66552,41 +67223,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
66552
67223
|
}
|
|
66553
67224
|
async function releaseStaleSocket() {
|
|
66554
67225
|
const deadline = Date.now() + 2e3;
|
|
66555
|
-
while ((0,
|
|
67226
|
+
while ((0, import_node_fs71.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
66556
67227
|
await new Promise((r) => setTimeout(r, 50));
|
|
66557
67228
|
}
|
|
66558
|
-
if ((0,
|
|
67229
|
+
if ((0, import_node_fs71.existsSync)(PATHS.socket)) {
|
|
66559
67230
|
try {
|
|
66560
|
-
(0,
|
|
67231
|
+
(0, import_node_fs71.unlinkSync)(PATHS.socket);
|
|
66561
67232
|
} catch {
|
|
66562
67233
|
}
|
|
66563
67234
|
}
|
|
66564
67235
|
}
|
|
66565
67236
|
|
|
66566
67237
|
// src/commands/service.ts
|
|
66567
|
-
var
|
|
66568
|
-
var
|
|
66569
|
-
var
|
|
66570
|
-
var
|
|
67238
|
+
var import_node_child_process30 = require("child_process");
|
|
67239
|
+
var import_node_fs73 = require("fs");
|
|
67240
|
+
var import_node_path51 = require("path");
|
|
67241
|
+
var import_node_os23 = require("os");
|
|
66571
67242
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
66572
67243
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
66573
67244
|
function resolveTemplate() {
|
|
66574
|
-
const templatePath = (0,
|
|
66575
|
-
if (!(0,
|
|
67245
|
+
const templatePath = (0, import_node_path51.join)(__dirname, "systemd", "threatcrushd.service");
|
|
67246
|
+
if (!(0, import_node_fs73.existsSync)(templatePath)) {
|
|
66576
67247
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
66577
67248
|
}
|
|
66578
|
-
return (0,
|
|
67249
|
+
return (0, import_node_fs73.readFileSync)(templatePath, "utf-8");
|
|
66579
67250
|
}
|
|
66580
67251
|
function stableBinPath(binPath) {
|
|
66581
67252
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
66582
67253
|
if (stable === binPath) return binPath;
|
|
66583
|
-
return (0,
|
|
67254
|
+
return (0, import_node_fs73.existsSync)(stable) ? stable : binPath;
|
|
66584
67255
|
}
|
|
66585
67256
|
function resolveBinPath() {
|
|
66586
67257
|
const arg = process.argv[1];
|
|
66587
|
-
if (arg && (0,
|
|
67258
|
+
if (arg && (0, import_node_fs73.existsSync)(arg)) return stableBinPath(arg);
|
|
66588
67259
|
try {
|
|
66589
|
-
return (0,
|
|
67260
|
+
return (0, import_node_child_process30.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
66590
67261
|
} catch {
|
|
66591
67262
|
return "threatcrush";
|
|
66592
67263
|
}
|
|
@@ -66594,11 +67265,11 @@ function resolveBinPath() {
|
|
|
66594
67265
|
function stableNodePath(execPath) {
|
|
66595
67266
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
66596
67267
|
if (stable === execPath) return execPath;
|
|
66597
|
-
return (0,
|
|
67268
|
+
return (0, import_node_fs73.existsSync)(stable) ? stable : execPath;
|
|
66598
67269
|
}
|
|
66599
67270
|
function looksLikeNodeScript(path2) {
|
|
66600
67271
|
try {
|
|
66601
|
-
const head2 = (0,
|
|
67272
|
+
const head2 = (0, import_node_fs73.readFileSync)(path2, "utf-8").slice(0, 120);
|
|
66602
67273
|
return /^#!.*\bnode\b/.test(head2);
|
|
66603
67274
|
} catch {
|
|
66604
67275
|
return false;
|
|
@@ -66626,20 +67297,20 @@ function isRoot3() {
|
|
|
66626
67297
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
66627
67298
|
}
|
|
66628
67299
|
function reexecWithSudo(args) {
|
|
66629
|
-
if ((0,
|
|
67300
|
+
if ((0, import_node_child_process30.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
66630
67301
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
66631
67302
|
const bin = resolveBinPath();
|
|
66632
67303
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
66633
|
-
const result = (0,
|
|
67304
|
+
const result = (0, import_node_child_process30.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
66634
67305
|
return result.status === 0;
|
|
66635
67306
|
}
|
|
66636
67307
|
function callerHome() {
|
|
66637
67308
|
const user = process.env.SUDO_USER;
|
|
66638
67309
|
if (!user) return null;
|
|
66639
67310
|
try {
|
|
66640
|
-
const line2 = (0,
|
|
67311
|
+
const line2 = (0, import_node_child_process30.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
66641
67312
|
const home = line2.split(":")[5];
|
|
66642
|
-
return home && (0,
|
|
67313
|
+
return home && (0, import_node_fs73.existsSync)(home) ? home : null;
|
|
66643
67314
|
} catch {
|
|
66644
67315
|
return null;
|
|
66645
67316
|
}
|
|
@@ -66647,13 +67318,13 @@ function callerHome() {
|
|
|
66647
67318
|
function stopUserModeDaemon() {
|
|
66648
67319
|
const home = callerHome();
|
|
66649
67320
|
if (!home) return;
|
|
66650
|
-
const runDir = (0,
|
|
66651
|
-
const pidFile = (0,
|
|
66652
|
-
const socket = (0,
|
|
66653
|
-
if (!(0,
|
|
67321
|
+
const runDir = (0, import_node_path51.join)(home, ".threatcrush", "run");
|
|
67322
|
+
const pidFile = (0, import_node_path51.join)(runDir, "threatcrushd.pid");
|
|
67323
|
+
const socket = (0, import_node_path51.join)(runDir, "threatcrushd.sock");
|
|
67324
|
+
if (!(0, import_node_fs73.existsSync)(pidFile) && !(0, import_node_fs73.existsSync)(socket)) return;
|
|
66654
67325
|
let pid = null;
|
|
66655
67326
|
try {
|
|
66656
|
-
pid = Number.parseInt((0,
|
|
67327
|
+
pid = Number.parseInt((0, import_node_fs73.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
66657
67328
|
} catch {
|
|
66658
67329
|
pid = null;
|
|
66659
67330
|
}
|
|
@@ -66666,13 +67337,13 @@ function stopUserModeDaemon() {
|
|
|
66666
67337
|
}
|
|
66667
67338
|
for (const path2 of [socket, pidFile]) {
|
|
66668
67339
|
try {
|
|
66669
|
-
if ((0,
|
|
67340
|
+
if ((0, import_node_fs73.existsSync)(path2)) (0, import_node_fs73.rmSync)(path2);
|
|
66670
67341
|
} catch {
|
|
66671
67342
|
}
|
|
66672
67343
|
}
|
|
66673
67344
|
}
|
|
66674
67345
|
function unitIsActive() {
|
|
66675
|
-
const result = (0,
|
|
67346
|
+
const result = (0, import_node_child_process30.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
66676
67347
|
return result.status === 0;
|
|
66677
67348
|
}
|
|
66678
67349
|
async function installServiceCommand() {
|
|
@@ -66683,8 +67354,8 @@ async function installServiceCommand() {
|
|
|
66683
67354
|
return;
|
|
66684
67355
|
}
|
|
66685
67356
|
const noSystemd = systemdUnavailableReason({
|
|
66686
|
-
hasSystemctl: (0,
|
|
66687
|
-
booted: (0,
|
|
67357
|
+
hasSystemctl: (0, import_node_child_process30.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
67358
|
+
booted: (0, import_node_fs73.existsSync)("/run/systemd/system")
|
|
66688
67359
|
});
|
|
66689
67360
|
if (noSystemd) {
|
|
66690
67361
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -66706,7 +67377,7 @@ async function installServiceCommand() {
|
|
|
66706
67377
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
66707
67378
|
let nodePath = stableNodePath(process.execPath);
|
|
66708
67379
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
66709
|
-
binPath = (0,
|
|
67380
|
+
binPath = (0, import_node_fs73.realpathSync)(binPath);
|
|
66710
67381
|
nodePath = process.execPath;
|
|
66711
67382
|
}
|
|
66712
67383
|
if (isNodeScript) {
|
|
@@ -66719,13 +67390,13 @@ async function installServiceCommand() {
|
|
|
66719
67390
|
}
|
|
66720
67391
|
}
|
|
66721
67392
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
66722
|
-
const configDir = (0,
|
|
67393
|
+
const configDir = (0, import_node_path51.join)((0, import_node_os23.homedir)(), ".threatcrush");
|
|
66723
67394
|
const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
|
|
66724
67395
|
const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
|
|
66725
67396
|
const containWriter = containWriterSettings(loadConfig().file_integrity).mode !== "off";
|
|
66726
67397
|
const extraCapabilities = containWriter ? ["CAP_SYS_PTRACE"] : [];
|
|
66727
67398
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths, extraCapabilities });
|
|
66728
|
-
(0,
|
|
67399
|
+
(0, import_node_fs73.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
66729
67400
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
66730
67401
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
66731
67402
|
if (containWriter) console.log(source_default.dim(" CAP_SYS_PTRACE granted for [file_integrity] contain_writer (reads /proc/<pid>/fd)"));
|
|
@@ -66741,8 +67412,8 @@ async function installServiceCommand() {
|
|
|
66741
67412
|
installLogrotate();
|
|
66742
67413
|
stopUserModeDaemon();
|
|
66743
67414
|
try {
|
|
66744
|
-
(0,
|
|
66745
|
-
(0,
|
|
67415
|
+
(0, import_node_child_process30.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
67416
|
+
(0, import_node_child_process30.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
66746
67417
|
} catch (err) {
|
|
66747
67418
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
66748
67419
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -66779,9 +67450,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
66779
67450
|
].join("\n");
|
|
66780
67451
|
}
|
|
66781
67452
|
function installLogrotate() {
|
|
66782
|
-
if (!(0,
|
|
67453
|
+
if (!(0, import_node_fs73.existsSync)((0, import_node_path51.dirname)(LOGROTATE_PATH))) return;
|
|
66783
67454
|
try {
|
|
66784
|
-
(0,
|
|
67455
|
+
(0, import_node_fs73.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
66785
67456
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
66786
67457
|
} catch (err) {
|
|
66787
67458
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -66803,20 +67474,20 @@ function ensureSystemDirs(configDir) {
|
|
|
66803
67474
|
];
|
|
66804
67475
|
let admGid2 = null;
|
|
66805
67476
|
try {
|
|
66806
|
-
admGid2 = (0,
|
|
67477
|
+
admGid2 = (0, import_node_fs73.statSync)("/var/log/auth.log").gid;
|
|
66807
67478
|
} catch {
|
|
66808
67479
|
}
|
|
66809
67480
|
for (const { path: path2, groupWritable, sticky } of dirs) {
|
|
66810
67481
|
try {
|
|
66811
|
-
(0,
|
|
67482
|
+
(0, import_node_fs73.mkdirSync)(path2, { recursive: true });
|
|
66812
67483
|
} catch {
|
|
66813
67484
|
}
|
|
66814
67485
|
try {
|
|
66815
67486
|
if (groupWritable && admGid2 !== null) {
|
|
66816
|
-
(0,
|
|
66817
|
-
(0,
|
|
67487
|
+
(0, import_node_fs73.chmodSync)(path2, sticky ? 1533 : 509);
|
|
67488
|
+
(0, import_node_child_process30.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
|
|
66818
67489
|
} else {
|
|
66819
|
-
(0,
|
|
67490
|
+
(0, import_node_fs73.chmodSync)(path2, 493);
|
|
66820
67491
|
}
|
|
66821
67492
|
} catch {
|
|
66822
67493
|
}
|
|
@@ -66836,29 +67507,29 @@ async function uninstallServiceCommand() {
|
|
|
66836
67507
|
return;
|
|
66837
67508
|
}
|
|
66838
67509
|
try {
|
|
66839
|
-
(0,
|
|
67510
|
+
(0, import_node_child_process30.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
66840
67511
|
} catch {
|
|
66841
67512
|
}
|
|
66842
67513
|
try {
|
|
66843
|
-
(0,
|
|
67514
|
+
(0, import_node_child_process30.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
66844
67515
|
} catch {
|
|
66845
67516
|
}
|
|
66846
67517
|
try {
|
|
66847
|
-
if ((0,
|
|
66848
|
-
(0,
|
|
67518
|
+
if ((0, import_node_fs73.existsSync)(UNIT_PATH)) {
|
|
67519
|
+
(0, import_node_child_process30.execSync)(`rm -f ${UNIT_PATH}`);
|
|
66849
67520
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
66850
67521
|
}
|
|
66851
67522
|
} catch {
|
|
66852
67523
|
}
|
|
66853
67524
|
try {
|
|
66854
|
-
(0,
|
|
67525
|
+
(0, import_node_child_process30.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
66855
67526
|
} catch {
|
|
66856
67527
|
}
|
|
66857
67528
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
66858
67529
|
}
|
|
66859
67530
|
|
|
66860
67531
|
// src/commands/save.ts
|
|
66861
|
-
var
|
|
67532
|
+
var import_node_fs74 = require("fs");
|
|
66862
67533
|
var import_toml6 = __toESM(require_toml());
|
|
66863
67534
|
init_cli_config();
|
|
66864
67535
|
init_paths();
|
|
@@ -66897,9 +67568,9 @@ async function saveCommand(opts = {}) {
|
|
|
66897
67568
|
}
|
|
66898
67569
|
const path2 = opts.config ?? PATHS.configFile;
|
|
66899
67570
|
let config = {};
|
|
66900
|
-
if ((0,
|
|
67571
|
+
if ((0, import_node_fs74.existsSync)(path2)) {
|
|
66901
67572
|
try {
|
|
66902
|
-
config = import_toml6.default.parse((0,
|
|
67573
|
+
config = import_toml6.default.parse((0, import_node_fs74.readFileSync)(path2, "utf-8"));
|
|
66903
67574
|
} catch (err) {
|
|
66904
67575
|
console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
|
|
66905
67576
|
`));
|
|
@@ -67012,8 +67683,8 @@ function welcomeCommand() {
|
|
|
67012
67683
|
}
|
|
67013
67684
|
|
|
67014
67685
|
// src/commands/properties.ts
|
|
67015
|
-
var
|
|
67016
|
-
var
|
|
67686
|
+
var import_node_fs75 = require("fs");
|
|
67687
|
+
var import_node_path52 = require("path");
|
|
67017
67688
|
var import_node_readline4 = __toESM(require("readline"));
|
|
67018
67689
|
init_cli_config();
|
|
67019
67690
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -67343,8 +68014,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
67343
68014
|
}
|
|
67344
68015
|
}
|
|
67345
68016
|
function parseImportFile(path2) {
|
|
67346
|
-
const ext = (0,
|
|
67347
|
-
const raw = (0,
|
|
68017
|
+
const ext = (0, import_node_path52.extname)(path2).toLowerCase();
|
|
68018
|
+
const raw = (0, import_node_fs75.readFileSync)(path2, "utf-8");
|
|
67348
68019
|
if (ext === ".json") {
|
|
67349
68020
|
const parsed = JSON.parse(raw);
|
|
67350
68021
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -67586,13 +68257,13 @@ async function rulesCommand(opts) {
|
|
|
67586
68257
|
}
|
|
67587
68258
|
|
|
67588
68259
|
// src/commands/harden.ts
|
|
67589
|
-
var
|
|
67590
|
-
var
|
|
68260
|
+
var import_node_fs77 = require("fs");
|
|
68261
|
+
var import_node_child_process31 = require("child_process");
|
|
67591
68262
|
init_cli_config();
|
|
67592
68263
|
|
|
67593
68264
|
// src/commands/cis-report.ts
|
|
67594
|
-
var
|
|
67595
|
-
var
|
|
68265
|
+
var import_node_os24 = require("os");
|
|
68266
|
+
var import_node_fs76 = require("fs");
|
|
67596
68267
|
|
|
67597
68268
|
// ../../packages/scan/src/cis/crosswalk.ts
|
|
67598
68269
|
var CAC_TAG = "v0.1.82";
|
|
@@ -67912,7 +68583,7 @@ ${xref}
|
|
|
67912
68583
|
function osRelease() {
|
|
67913
68584
|
let raw = "";
|
|
67914
68585
|
try {
|
|
67915
|
-
raw = (0,
|
|
68586
|
+
raw = (0, import_node_fs76.readFileSync)("/etc/os-release", "utf8");
|
|
67916
68587
|
} catch {
|
|
67917
68588
|
return {};
|
|
67918
68589
|
}
|
|
@@ -67975,7 +68646,7 @@ function buildCisEvidenceReport(findings2, score, now = /* @__PURE__ */ new Date
|
|
|
67975
68646
|
generated_at: now.toISOString(),
|
|
67976
68647
|
disclaimer: CIS_DISCLAIMER,
|
|
67977
68648
|
benchmark_catalog_checked_at: CIS_CATALOG_CHECKED_AT,
|
|
67978
|
-
host: { hostname: (0,
|
|
68649
|
+
host: { hostname: (0, import_node_os24.hostname)(), os_id: id, os_version: version, pretty_name: os5.PRETTY_NAME ?? null },
|
|
67979
68650
|
benchmark: edition ? { ...edition } : null,
|
|
67980
68651
|
mapping_profile: profile2 ? {
|
|
67981
68652
|
name: profile2.benchmarkName,
|
|
@@ -68046,20 +68717,20 @@ function writeCisReport(path2, format2, report) {
|
|
|
68046
68717
|
const markdown = renderCisMarkdown(report);
|
|
68047
68718
|
const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
|
|
68048
68719
|
` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
|
|
68049
|
-
(0,
|
|
68720
|
+
(0, import_node_fs76.writeFileSync)(path2, content);
|
|
68050
68721
|
}
|
|
68051
68722
|
|
|
68052
68723
|
// src/commands/harden.ts
|
|
68053
68724
|
function tryExec(cmd) {
|
|
68054
68725
|
try {
|
|
68055
|
-
return (0,
|
|
68726
|
+
return (0, import_node_child_process31.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
68056
68727
|
} catch {
|
|
68057
68728
|
return null;
|
|
68058
68729
|
}
|
|
68059
68730
|
}
|
|
68060
68731
|
function tryRead(path2) {
|
|
68061
68732
|
try {
|
|
68062
|
-
return (0,
|
|
68733
|
+
return (0, import_node_fs77.readFileSync)(path2, "utf-8");
|
|
68063
68734
|
} catch {
|
|
68064
68735
|
return null;
|
|
68065
68736
|
}
|
|
@@ -68173,8 +68844,8 @@ function checkSshWeakConfig() {
|
|
|
68173
68844
|
};
|
|
68174
68845
|
}
|
|
68175
68846
|
function checkAutoUpdates() {
|
|
68176
|
-
const unattended = (0,
|
|
68177
|
-
const dnfAuto = (0,
|
|
68847
|
+
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");
|
|
68848
|
+
const dnfAuto = (0, import_node_fs77.existsSync)("/etc/dnf/automatic.conf");
|
|
68178
68849
|
if (unattended || dnfAuto) {
|
|
68179
68850
|
return {
|
|
68180
68851
|
key: "auto-updates",
|
|
@@ -68300,7 +68971,7 @@ function checkFail2ban() {
|
|
|
68300
68971
|
explanation: "fail2ban is installed and running."
|
|
68301
68972
|
};
|
|
68302
68973
|
}
|
|
68303
|
-
if ((0,
|
|
68974
|
+
if ((0, import_node_fs77.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
68304
68975
|
return {
|
|
68305
68976
|
key: checkKey,
|
|
68306
68977
|
status: "warn",
|
|
@@ -68525,9 +69196,9 @@ async function hardenCommand(opts) {
|
|
|
68525
69196
|
}
|
|
68526
69197
|
|
|
68527
69198
|
// src/core/patches/index.ts
|
|
68528
|
-
var
|
|
68529
|
-
var
|
|
68530
|
-
var
|
|
69199
|
+
var import_node_fs78 = require("fs");
|
|
69200
|
+
var import_node_path53 = require("path");
|
|
69201
|
+
var import_node_child_process32 = require("child_process");
|
|
68531
69202
|
var import_node_util5 = require("util");
|
|
68532
69203
|
|
|
68533
69204
|
// src/core/patches/dpkg-version.ts
|
|
@@ -68585,9 +69256,9 @@ function compareDebianVersions(a, b) {
|
|
|
68585
69256
|
var OSV_QUERY = "https://api.osv.dev/v1/query";
|
|
68586
69257
|
var STALE_AFTER_MS = 2 * 864e5;
|
|
68587
69258
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
68588
|
-
var
|
|
69259
|
+
var RANK2 = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
68589
69260
|
var defaultExec = async (file, args) => {
|
|
68590
|
-
const { stdout } = await (0, import_node_util5.promisify)(
|
|
69261
|
+
const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process32.execFile)(file, args, {
|
|
68591
69262
|
timeout: 12e4,
|
|
68592
69263
|
maxBuffer: 32 * 1024 * 1024,
|
|
68593
69264
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -68686,9 +69357,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
68686
69357
|
function newestReleaseMtime(dir) {
|
|
68687
69358
|
try {
|
|
68688
69359
|
let newest = 0;
|
|
68689
|
-
for (const name of (0,
|
|
69360
|
+
for (const name of (0, import_node_fs78.readdirSync)(dir)) {
|
|
68690
69361
|
if (!/Release$/.test(name)) continue;
|
|
68691
|
-
newest = Math.max(newest, (0,
|
|
69362
|
+
newest = Math.max(newest, (0, import_node_fs78.statSync)((0, import_node_path53.join)(dir, name)).mtimeMs);
|
|
68692
69363
|
}
|
|
68693
69364
|
return newest > 0 ? new Date(newest) : null;
|
|
68694
69365
|
} catch {
|
|
@@ -68705,7 +69376,7 @@ async function checkPatches(opts = {}) {
|
|
|
68705
69376
|
let osText = opts.osRelease;
|
|
68706
69377
|
if (osText === void 0) {
|
|
68707
69378
|
try {
|
|
68708
|
-
osText = (0,
|
|
69379
|
+
osText = (0, import_node_fs78.readFileSync)("/etc/os-release", "utf-8");
|
|
68709
69380
|
} catch {
|
|
68710
69381
|
osText = "";
|
|
68711
69382
|
}
|
|
@@ -68786,12 +69457,12 @@ async function checkPatches(opts = {}) {
|
|
|
68786
69457
|
} catch (err) {
|
|
68787
69458
|
report.osv_error ??= err.message;
|
|
68788
69459
|
}
|
|
68789
|
-
pkg.cves.sort((a, b) =>
|
|
69460
|
+
pkg.cves.sort((a, b) => RANK2[b.severity] - RANK2[a.severity] || a.id.localeCompare(b.id));
|
|
68790
69461
|
if (pkg.cves.length > 0) pkg.severity = pkg.cves[0].severity;
|
|
68791
69462
|
pkg.binaries.sort();
|
|
68792
69463
|
}
|
|
68793
69464
|
report.packages = [...bySource.values()].sort(
|
|
68794
|
-
(a, b) =>
|
|
69465
|
+
(a, b) => RANK2[b.severity] - RANK2[a.severity] || b.cves.length - a.cves.length || a.source.localeCompare(b.source)
|
|
68795
69466
|
);
|
|
68796
69467
|
const counts = emptyCounts2();
|
|
68797
69468
|
counts.packages = report.packages.length;
|
|
@@ -68804,7 +69475,7 @@ async function checkPatches(opts = {}) {
|
|
|
68804
69475
|
}
|
|
68805
69476
|
function worstSeverity(report) {
|
|
68806
69477
|
if (report.packages.length === 0) return null;
|
|
68807
|
-
return report.packages.reduce((w, p) =>
|
|
69478
|
+
return report.packages.reduce((w, p) => RANK2[p.severity] > RANK2[w] ? p.severity : w, "info");
|
|
68808
69479
|
}
|
|
68809
69480
|
var MAX_DETAIL_PACKAGES = 30;
|
|
68810
69481
|
function patchFinding(report) {
|
|
@@ -68931,27 +69602,27 @@ async function patchesCommand(opts) {
|
|
|
68931
69602
|
}
|
|
68932
69603
|
|
|
68933
69604
|
// src/commands/feeds.ts
|
|
68934
|
-
var
|
|
68935
|
-
var
|
|
69605
|
+
var import_node_net25 = require("net");
|
|
69606
|
+
var import_node_path55 = require("path");
|
|
68936
69607
|
init_paths();
|
|
68937
69608
|
|
|
68938
69609
|
// src/commands/feeds-resolver.ts
|
|
68939
|
-
var
|
|
68940
|
-
var
|
|
68941
|
-
var
|
|
69610
|
+
var import_node_child_process33 = require("child_process");
|
|
69611
|
+
var import_node_fs79 = require("fs");
|
|
69612
|
+
var import_node_path54 = require("path");
|
|
68942
69613
|
var realIO = {
|
|
68943
|
-
exists: (p) => (0,
|
|
69614
|
+
exists: (p) => (0, import_node_fs79.existsSync)(p),
|
|
68944
69615
|
read: (p) => {
|
|
68945
69616
|
try {
|
|
68946
|
-
return (0,
|
|
69617
|
+
return (0, import_node_fs79.readFileSync)(p, "utf-8");
|
|
68947
69618
|
} catch {
|
|
68948
69619
|
return null;
|
|
68949
69620
|
}
|
|
68950
69621
|
},
|
|
68951
|
-
write: (p, c) => (0,
|
|
68952
|
-
remove: (p) => (0,
|
|
69622
|
+
write: (p, c) => (0, import_node_fs79.writeFileSync)(p, c),
|
|
69623
|
+
remove: (p) => (0, import_node_fs79.rmSync)(p, { force: true }),
|
|
68953
69624
|
run: (cmd, args) => {
|
|
68954
|
-
const r = (0,
|
|
69625
|
+
const r = (0, import_node_child_process33.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
68955
69626
|
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
68956
69627
|
}
|
|
68957
69628
|
};
|
|
@@ -68959,17 +69630,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
|
68959
69630
|
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
68960
69631
|
function hookContent(resolver, stateDir) {
|
|
68961
69632
|
const head2 = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
68962
|
-
return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0,
|
|
68963
|
-
` : `${head2}include: "${(0,
|
|
69633
|
+
return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
69634
|
+
` : `${head2}include: "${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
68964
69635
|
`;
|
|
68965
69636
|
}
|
|
68966
69637
|
function apparmorRule(stateDir) {
|
|
68967
|
-
return ` ${(0,
|
|
69638
|
+
return ` ${(0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
68968
69639
|
}
|
|
68969
69640
|
function detectResolvers(io = realIO) {
|
|
68970
69641
|
const found = [];
|
|
68971
|
-
if (io.exists((0,
|
|
68972
|
-
if (io.exists((0,
|
|
69642
|
+
if (io.exists((0, import_node_path54.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
69643
|
+
if (io.exists((0, import_node_path54.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
68973
69644
|
return found;
|
|
68974
69645
|
}
|
|
68975
69646
|
function check(resolver, io) {
|
|
@@ -68982,7 +69653,7 @@ function restartIfActive(resolver, io) {
|
|
|
68982
69653
|
}
|
|
68983
69654
|
function installHook(resolver, stateDir, io = realIO) {
|
|
68984
69655
|
const hook = RESOLVER_HOOKS[resolver];
|
|
68985
|
-
const file = (0,
|
|
69656
|
+
const file = (0, import_node_path54.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
68986
69657
|
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
68987
69658
|
io.write(hook, hookContent(resolver, stateDir));
|
|
68988
69659
|
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
@@ -69043,8 +69714,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
69043
69714
|
}
|
|
69044
69715
|
return failed ? 1 : 0;
|
|
69045
69716
|
}
|
|
69046
|
-
const hosts = io.read((0,
|
|
69047
|
-
const unbound = io.read((0,
|
|
69717
|
+
const hosts = io.read((0, import_node_path54.join)(stateDir, RESOLVER_FILES.hosts));
|
|
69718
|
+
const unbound = io.read((0, import_node_path54.join)(stateDir, RESOLVER_FILES.unbound));
|
|
69048
69719
|
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
69049
69720
|
for (const r of ["dnsmasq", "unbound"]) {
|
|
69050
69721
|
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
@@ -69056,11 +69727,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
69056
69727
|
// src/commands/feeds.ts
|
|
69057
69728
|
async function loadSet() {
|
|
69058
69729
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
69059
|
-
const path2 = (0,
|
|
69730
|
+
const path2 = (0, import_node_path55.join)(dir, "threat-feeds.json");
|
|
69060
69731
|
const set = readFeedCache(path2);
|
|
69061
69732
|
if (set) return { set, from: path2 };
|
|
69062
69733
|
}
|
|
69063
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
69734
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path55.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
69064
69735
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
69065
69736
|
}
|
|
69066
69737
|
async function feedsCommand(action, value, opts) {
|
|
@@ -69075,8 +69746,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
69075
69746
|
process.exitCode = 2;
|
|
69076
69747
|
return;
|
|
69077
69748
|
}
|
|
69078
|
-
const ipHit = (0,
|
|
69079
|
-
const domainHit = (0,
|
|
69749
|
+
const ipHit = (0, import_node_net25.isIP)(value) ? matchIp(value, set) : null;
|
|
69750
|
+
const domainHit = (0, import_node_net25.isIP)(value) ? null : matchDomain(value, set);
|
|
69080
69751
|
const listed = ipHit ?? domainHit?.indicator ?? null;
|
|
69081
69752
|
if (opts.json) {
|
|
69082
69753
|
console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
|
|
@@ -69114,21 +69785,21 @@ async function feedsCommand(action, value, opts) {
|
|
|
69114
69785
|
}
|
|
69115
69786
|
|
|
69116
69787
|
// src/commands/tor.ts
|
|
69117
|
-
var
|
|
69118
|
-
var
|
|
69119
|
-
var
|
|
69788
|
+
var import_node_fs80 = require("fs");
|
|
69789
|
+
var import_node_net26 = require("net");
|
|
69790
|
+
var import_node_path56 = require("path");
|
|
69120
69791
|
init_paths();
|
|
69121
69792
|
async function torCommand(action, value, opts) {
|
|
69122
69793
|
let exits = /* @__PURE__ */ new Set();
|
|
69123
69794
|
let from = "";
|
|
69124
69795
|
let updated = null;
|
|
69125
69796
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
69126
|
-
const path2 = (0,
|
|
69797
|
+
const path2 = (0, import_node_path56.join)(dir, "tor-exits.txt");
|
|
69127
69798
|
try {
|
|
69128
|
-
if (!(0,
|
|
69129
|
-
exits = parseTorExitList((0,
|
|
69799
|
+
if (!(0, import_node_fs80.existsSync)(path2)) continue;
|
|
69800
|
+
exits = parseTorExitList((0, import_node_fs80.readFileSync)(path2, "utf-8"));
|
|
69130
69801
|
from = path2;
|
|
69131
|
-
updated = (0,
|
|
69802
|
+
updated = (0, import_node_fs80.statSync)(path2).mtime;
|
|
69132
69803
|
break;
|
|
69133
69804
|
} catch {
|
|
69134
69805
|
}
|
|
@@ -69144,10 +69815,10 @@ async function torCommand(action, value, opts) {
|
|
|
69144
69815
|
} catch {
|
|
69145
69816
|
}
|
|
69146
69817
|
}
|
|
69147
|
-
const remediation = loadConfig((0,
|
|
69818
|
+
const remediation = loadConfig((0, import_node_path56.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
69148
69819
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
69149
69820
|
if (action === "check") {
|
|
69150
|
-
if (!value || !(0,
|
|
69821
|
+
if (!value || !(0, import_node_net26.isIP)(value)) {
|
|
69151
69822
|
console.error("Usage: threatcrush tor check <ip>");
|
|
69152
69823
|
process.exitCode = 2;
|
|
69153
69824
|
return;
|
|
@@ -69175,14 +69846,14 @@ async function torCommand(action, value, opts) {
|
|
|
69175
69846
|
}
|
|
69176
69847
|
|
|
69177
69848
|
// src/commands/reputation.ts
|
|
69178
|
-
var
|
|
69179
|
-
var
|
|
69180
|
-
var
|
|
69849
|
+
var import_node_os25 = require("os");
|
|
69850
|
+
var import_node_fs81 = require("fs");
|
|
69851
|
+
var import_node_path57 = require("path");
|
|
69181
69852
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
69182
|
-
var CONFIG_PATH4 = (0,
|
|
69853
|
+
var CONFIG_PATH4 = (0, import_node_path57.join)((0, import_node_os25.homedir)(), ".threatcrush", "config.json");
|
|
69183
69854
|
function readConfig3() {
|
|
69184
69855
|
try {
|
|
69185
|
-
return JSON.parse((0,
|
|
69856
|
+
return JSON.parse((0, import_node_fs81.readFileSync)(CONFIG_PATH4, "utf-8"));
|
|
69186
69857
|
} catch {
|
|
69187
69858
|
return {};
|
|
69188
69859
|
}
|
|
@@ -69370,7 +70041,7 @@ async function reputationSubscribeCommand(opts) {
|
|
|
69370
70041
|
}
|
|
69371
70042
|
|
|
69372
70043
|
// src/commands/privileged.ts
|
|
69373
|
-
var
|
|
70044
|
+
var import_node_fs82 = require("fs");
|
|
69374
70045
|
init_paths();
|
|
69375
70046
|
var SEV2 = {
|
|
69376
70047
|
critical: source_default.red.bold,
|
|
@@ -69383,19 +70054,19 @@ async function privilegedCommand(opts) {
|
|
|
69383
70054
|
const snapshot = takeSnapshot({
|
|
69384
70055
|
readFile: (p) => {
|
|
69385
70056
|
try {
|
|
69386
|
-
return (0,
|
|
70057
|
+
return (0, import_node_fs82.readFileSync)(p, "utf-8");
|
|
69387
70058
|
} catch {
|
|
69388
70059
|
return null;
|
|
69389
70060
|
}
|
|
69390
70061
|
},
|
|
69391
70062
|
readDir: (p) => {
|
|
69392
70063
|
try {
|
|
69393
|
-
return (0,
|
|
70064
|
+
return (0, import_node_fs82.readdirSync)(p);
|
|
69394
70065
|
} catch {
|
|
69395
70066
|
return null;
|
|
69396
70067
|
}
|
|
69397
70068
|
},
|
|
69398
|
-
exists: (p) => (0,
|
|
70069
|
+
exists: (p) => (0, import_node_fs82.existsSync)(p)
|
|
69399
70070
|
});
|
|
69400
70071
|
let events = [];
|
|
69401
70072
|
let ledgerNote = "";
|
|
@@ -69437,12 +70108,12 @@ async function privilegedCommand(opts) {
|
|
|
69437
70108
|
}
|
|
69438
70109
|
|
|
69439
70110
|
// src/commands/integrity.ts
|
|
69440
|
-
var
|
|
69441
|
-
var
|
|
70111
|
+
var import_node_fs83 = require("fs");
|
|
70112
|
+
var import_node_path58 = require("path");
|
|
69442
70113
|
init_paths();
|
|
69443
70114
|
function readState2(path2) {
|
|
69444
70115
|
try {
|
|
69445
|
-
return JSON.parse((0,
|
|
70116
|
+
return JSON.parse((0, import_node_fs83.readFileSync)(path2, "utf8"));
|
|
69446
70117
|
} catch {
|
|
69447
70118
|
return null;
|
|
69448
70119
|
}
|
|
@@ -69462,11 +70133,11 @@ function changedCount(baseline, observed) {
|
|
|
69462
70133
|
async function integrityCommand(action = "status", opts = {}) {
|
|
69463
70134
|
const config = loadConfig();
|
|
69464
70135
|
const settings = fileIntegritySettings(config.file_integrity);
|
|
69465
|
-
const systemBaseline = (0,
|
|
69466
|
-
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0,
|
|
70136
|
+
const systemBaseline = (0, import_node_path58.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
|
|
70137
|
+
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs83.existsSync)(systemBaseline);
|
|
69467
70138
|
const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
|
|
69468
|
-
const baselinePath = (0,
|
|
69469
|
-
const observedPath = (0,
|
|
70139
|
+
const baselinePath = (0, import_node_path58.join)(stateDir, "file-integrity-baseline.json");
|
|
70140
|
+
const observedPath = (0, import_node_path58.join)(stateDir, "file-integrity-observed.json");
|
|
69470
70141
|
if (action === "rebaseline") {
|
|
69471
70142
|
const watch4 = new FileIntegrityWatch({
|
|
69472
70143
|
bus: { publish: () => void 0 },
|
|
@@ -69534,13 +70205,13 @@ async function integrityCommand(action = "status", opts = {}) {
|
|
|
69534
70205
|
}
|
|
69535
70206
|
|
|
69536
70207
|
// src/commands/edr.ts
|
|
69537
|
-
var
|
|
70208
|
+
var import_node_fs85 = require("fs");
|
|
69538
70209
|
init_paths();
|
|
69539
70210
|
|
|
69540
70211
|
// src/daemon/auditd/rules.ts
|
|
69541
|
-
var
|
|
69542
|
-
var
|
|
69543
|
-
var
|
|
70212
|
+
var import_node_fs84 = require("fs");
|
|
70213
|
+
var import_node_child_process34 = require("child_process");
|
|
70214
|
+
var import_node_path59 = require("path");
|
|
69544
70215
|
var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
|
|
69545
70216
|
var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
|
|
69546
70217
|
var CONNECT_KEY2 = "threatcrush_edr_connect";
|
|
@@ -69548,10 +70219,10 @@ var LISTEN_KEY2 = "threatcrush_edr_listen";
|
|
|
69548
70219
|
function passwdByName() {
|
|
69549
70220
|
let raw = "";
|
|
69550
70221
|
try {
|
|
69551
|
-
raw = (0,
|
|
70222
|
+
raw = (0, import_node_child_process34.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
69552
70223
|
} catch {
|
|
69553
70224
|
try {
|
|
69554
|
-
raw = (0,
|
|
70225
|
+
raw = (0, import_node_fs84.readFileSync)("/etc/passwd", "utf8");
|
|
69555
70226
|
} catch {
|
|
69556
70227
|
return /* @__PURE__ */ new Map();
|
|
69557
70228
|
}
|
|
@@ -69570,8 +70241,8 @@ function existingExecutables(names) {
|
|
|
69570
70241
|
for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
|
|
69571
70242
|
const candidate = `${prefix}/${name}`;
|
|
69572
70243
|
try {
|
|
69573
|
-
if (!(0,
|
|
69574
|
-
paths.add((0,
|
|
70244
|
+
if (!(0, import_node_fs84.existsSync)(candidate) || !(0, import_node_fs84.statSync)(candidate).isFile()) continue;
|
|
70245
|
+
paths.add((0, import_node_fs84.realpathSync)(candidate));
|
|
69575
70246
|
} catch {
|
|
69576
70247
|
}
|
|
69577
70248
|
}
|
|
@@ -69580,9 +70251,9 @@ function existingExecutables(names) {
|
|
|
69580
70251
|
}
|
|
69581
70252
|
function existingDirectories(paths) {
|
|
69582
70253
|
return [...new Set(paths)].filter((path2) => {
|
|
69583
|
-
if (!(0,
|
|
70254
|
+
if (!(0, import_node_path59.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
|
|
69584
70255
|
try {
|
|
69585
|
-
return (0,
|
|
70256
|
+
return (0, import_node_fs84.statSync)(path2).isDirectory();
|
|
69586
70257
|
} catch {
|
|
69587
70258
|
return false;
|
|
69588
70259
|
}
|
|
@@ -69625,7 +70296,7 @@ function generateAuditRules(settings) {
|
|
|
69625
70296
|
}
|
|
69626
70297
|
|
|
69627
70298
|
// src/commands/edr.ts
|
|
69628
|
-
var
|
|
70299
|
+
var import_node_path60 = require("path");
|
|
69629
70300
|
async function edrCommand(action = "status", opts = {}) {
|
|
69630
70301
|
const settings = edrSettings(loadConfig().edr);
|
|
69631
70302
|
if (action === "rules") {
|
|
@@ -69650,8 +70321,8 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
69650
70321
|
}
|
|
69651
70322
|
let readable = false;
|
|
69652
70323
|
try {
|
|
69653
|
-
if ((0,
|
|
69654
|
-
readable = (0,
|
|
70324
|
+
if ((0, import_node_fs85.existsSync)(settings.auditLogPath)) (0, import_node_fs85.accessSync)(settings.auditLogPath, import_node_fs85.constants.R_OK);
|
|
70325
|
+
readable = (0, import_node_fs85.existsSync)(settings.auditLogPath);
|
|
69655
70326
|
} catch {
|
|
69656
70327
|
}
|
|
69657
70328
|
let events = [];
|
|
@@ -69663,7 +70334,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
69663
70334
|
stateNote = `the daemon state database (${PATHS.stateDb}) is not readable here`;
|
|
69664
70335
|
}
|
|
69665
70336
|
const selection = selectEdrSource(settings.source === "auditd" ? { configured: "auditd", bpftracePath: null, btfPresent: false, isRoot: false } : probeHost(settings.source));
|
|
69666
|
-
const daemonSource = readEdrSourceStatus((0,
|
|
70337
|
+
const daemonSource = readEdrSourceStatus((0, import_node_path60.join)(PATHS.stateDir, "edr-source.json"));
|
|
69667
70338
|
const report = {
|
|
69668
70339
|
enabled: settings.enabled,
|
|
69669
70340
|
source: settings.source,
|
|
@@ -69849,7 +70520,7 @@ async function allowlistCommand(opts) {
|
|
|
69849
70520
|
}
|
|
69850
70521
|
|
|
69851
70522
|
// src/commands/abuse.ts
|
|
69852
|
-
var
|
|
70523
|
+
var import_node_fs86 = require("fs");
|
|
69853
70524
|
init_paths();
|
|
69854
70525
|
function rows(records) {
|
|
69855
70526
|
if (records.length === 0) {
|
|
@@ -69909,7 +70580,7 @@ function abuseRetractCommand(id, opts = {}) {
|
|
|
69909
70580
|
);
|
|
69910
70581
|
}
|
|
69911
70582
|
function abuseStatusCommand(opts = {}) {
|
|
69912
|
-
const config = loadConfig((0,
|
|
70583
|
+
const config = loadConfig((0, import_node_fs86.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
69913
70584
|
const cfg = resolveConfig(config.abuse_reporter);
|
|
69914
70585
|
const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
|
|
69915
70586
|
const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
|
|
@@ -69932,11 +70603,11 @@ function abuseStatusCommand(opts = {}) {
|
|
|
69932
70603
|
init_paths();
|
|
69933
70604
|
|
|
69934
70605
|
// src/upgrade.ts
|
|
69935
|
-
var
|
|
70606
|
+
var import_node_child_process35 = require("child_process");
|
|
69936
70607
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
69937
70608
|
var defaultRunner = (cmd) => {
|
|
69938
70609
|
try {
|
|
69939
|
-
return (0,
|
|
70610
|
+
return (0, import_node_child_process35.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
69940
70611
|
} catch {
|
|
69941
70612
|
return null;
|
|
69942
70613
|
}
|
|
@@ -70077,9 +70748,9 @@ function installUserAgent(target = globalThis) {
|
|
|
70077
70748
|
}
|
|
70078
70749
|
|
|
70079
70750
|
// src/core/cloud-upload.ts
|
|
70080
|
-
var
|
|
70081
|
-
var
|
|
70082
|
-
var
|
|
70751
|
+
var import_node_child_process36 = require("child_process");
|
|
70752
|
+
var import_node_os26 = require("os");
|
|
70753
|
+
var import_node_path61 = require("path");
|
|
70083
70754
|
init_cli_config();
|
|
70084
70755
|
function uploadDisabled(upload, env3 = process.env) {
|
|
70085
70756
|
if (upload === false) return true;
|
|
@@ -70098,8 +70769,8 @@ function cleanUrl(raw) {
|
|
|
70098
70769
|
return raw.split(/[?#]/)[0];
|
|
70099
70770
|
}
|
|
70100
70771
|
}
|
|
70101
|
-
function repoTarget(path2, run3 = (args) => (0,
|
|
70102
|
-
const abs = (0,
|
|
70772
|
+
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()) {
|
|
70773
|
+
const abs = (0, import_node_path61.resolve)(path2);
|
|
70103
70774
|
try {
|
|
70104
70775
|
const root = run3(["rev-parse", "--show-toplevel"]);
|
|
70105
70776
|
const sub = abs === root ? "." : abs.slice(root.length + 1);
|
|
@@ -70112,9 +70783,9 @@ function repoTarget(path2, run3 = (args) => (0, import_node_child_process35.exec
|
|
|
70112
70783
|
const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
|
|
70113
70784
|
if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
|
|
70114
70785
|
}
|
|
70115
|
-
return { target: `${(0,
|
|
70786
|
+
return { target: `${(0, import_node_os26.hostname)()}:${root}`, root, sub };
|
|
70116
70787
|
} catch {
|
|
70117
|
-
return { target: `${(0,
|
|
70788
|
+
return { target: `${(0, import_node_os26.hostname)()}:${abs}`, root: abs, sub: "." };
|
|
70118
70789
|
}
|
|
70119
70790
|
}
|
|
70120
70791
|
async function uploadResult(result, opts) {
|
|
@@ -70471,25 +71142,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
70471
71142
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
70472
71143
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
70473
71144
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
70474
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
71145
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush", "install.json");
|
|
70475
71146
|
function detectPackageManager2() {
|
|
70476
71147
|
try {
|
|
70477
|
-
const npmGlobal = (0,
|
|
71148
|
+
const npmGlobal = (0, import_node_child_process37.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
70478
71149
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
70479
71150
|
} catch {
|
|
70480
71151
|
}
|
|
70481
71152
|
try {
|
|
70482
|
-
(0,
|
|
71153
|
+
(0, import_node_child_process37.execSync)("pnpm --version", { stdio: "pipe" });
|
|
70483
71154
|
return "pnpm";
|
|
70484
71155
|
} catch {
|
|
70485
71156
|
}
|
|
70486
71157
|
try {
|
|
70487
|
-
(0,
|
|
71158
|
+
(0, import_node_child_process37.execSync)("yarn --version", { stdio: "pipe" });
|
|
70488
71159
|
return "yarn";
|
|
70489
71160
|
} catch {
|
|
70490
71161
|
}
|
|
70491
71162
|
try {
|
|
70492
|
-
(0,
|
|
71163
|
+
(0, import_node_child_process37.execSync)("bun --version", { stdio: "pipe" });
|
|
70493
71164
|
return "bun";
|
|
70494
71165
|
} catch {
|
|
70495
71166
|
}
|
|
@@ -70497,14 +71168,14 @@ function detectPackageManager2() {
|
|
|
70497
71168
|
}
|
|
70498
71169
|
function readInstallConfig() {
|
|
70499
71170
|
try {
|
|
70500
|
-
return JSON.parse((0,
|
|
71171
|
+
return JSON.parse((0, import_node_fs87.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
70501
71172
|
} catch {
|
|
70502
71173
|
return {};
|
|
70503
71174
|
}
|
|
70504
71175
|
}
|
|
70505
71176
|
function packageLooksInstalled(pm, pkgName) {
|
|
70506
71177
|
try {
|
|
70507
|
-
const output = (0,
|
|
71178
|
+
const output = (0, import_node_child_process37.execSync)(globalListCommand(pm, pkgName), {
|
|
70508
71179
|
encoding: "utf-8",
|
|
70509
71180
|
stdio: ["pipe", "pipe", "pipe"]
|
|
70510
71181
|
});
|
|
@@ -70607,14 +71278,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
70607
71278
|
function restartSystemdDaemon() {
|
|
70608
71279
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
70609
71280
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
70610
|
-
if (!asRoot && (0,
|
|
71281
|
+
if (!asRoot && (0, import_node_child_process37.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
70611
71282
|
const [cmd, ...args] = argv;
|
|
70612
|
-
if ((0,
|
|
70613
|
-
return (0,
|
|
71283
|
+
if ((0, import_node_child_process37.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
71284
|
+
return (0, import_node_child_process37.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
70614
71285
|
}
|
|
70615
71286
|
function execQuiet(cmd) {
|
|
70616
71287
|
try {
|
|
70617
|
-
return (0,
|
|
71288
|
+
return (0, import_node_child_process37.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
70618
71289
|
} catch {
|
|
70619
71290
|
return null;
|
|
70620
71291
|
}
|
|
@@ -70946,7 +71617,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
70946
71617
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
70947
71618
|
console.log(LOGO2);
|
|
70948
71619
|
const logPath2 = PATHS.logFile;
|
|
70949
|
-
if (!(0,
|
|
71620
|
+
if (!(0, import_node_fs87.existsSync)(logPath2)) {
|
|
70950
71621
|
console.log(source_default.yellow(` No log file found at ${logPath2}`));
|
|
70951
71622
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
70952
71623
|
return;
|
|
@@ -70954,7 +71625,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
70954
71625
|
console.log(source_default.green(` Tailing ${logPath2}...
|
|
70955
71626
|
`));
|
|
70956
71627
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
70957
|
-
(0,
|
|
71628
|
+
(0, import_node_child_process37.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
|
|
70958
71629
|
});
|
|
70959
71630
|
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) => {
|
|
70960
71631
|
console.log(LOGO2);
|
|
@@ -70966,7 +71637,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
70966
71637
|
for (const cmd of commands2) {
|
|
70967
71638
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
70968
71639
|
`));
|
|
70969
|
-
(0,
|
|
71640
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
70970
71641
|
}
|
|
70971
71642
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
70972
71643
|
await reportIfStillStale();
|
|
@@ -70991,7 +71662,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
70991
71662
|
for (const cmd of commands) {
|
|
70992
71663
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
70993
71664
|
`));
|
|
70994
|
-
(0,
|
|
71665
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
70995
71666
|
}
|
|
70996
71667
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
70997
71668
|
if (installMode === "desktop") {
|
|
@@ -71042,7 +71713,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
71042
71713
|
for (const cmd of commands) {
|
|
71043
71714
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
71044
71715
|
`));
|
|
71045
|
-
(0,
|
|
71716
|
+
(0, import_node_child_process37.execSync)(cmd, { stdio: "inherit" });
|
|
71046
71717
|
}
|
|
71047
71718
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
71048
71719
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -71119,10 +71790,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
71119
71790
|
});
|
|
71120
71791
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
71121
71792
|
console.log(LOGO2);
|
|
71122
|
-
const configPath = (0,
|
|
71793
|
+
const configPath = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush", "config.json");
|
|
71123
71794
|
let email = "";
|
|
71124
71795
|
try {
|
|
71125
|
-
const config = JSON.parse((0,
|
|
71796
|
+
const config = JSON.parse((0, import_node_fs87.readFileSync)(configPath, "utf-8"));
|
|
71126
71797
|
email = config.email || "";
|
|
71127
71798
|
} catch {
|
|
71128
71799
|
}
|
|
@@ -71139,9 +71810,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
71139
71810
|
return;
|
|
71140
71811
|
}
|
|
71141
71812
|
try {
|
|
71142
|
-
const dir = (0,
|
|
71143
|
-
if (!(0,
|
|
71144
|
-
(0,
|
|
71813
|
+
const dir = (0, import_node_path62.join)((0, import_node_os27.homedir)(), ".threatcrush");
|
|
71814
|
+
if (!(0, import_node_fs87.existsSync)(dir)) (0, import_node_fs87.mkdirSync)(dir, { recursive: true });
|
|
71815
|
+
(0, import_node_fs87.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
71145
71816
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
71146
71817
|
} catch {
|
|
71147
71818
|
}
|