@profullstack/threatcrush 0.13.31 → 0.13.33
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 +15 -1
- package/dist/daemon.js +330 -65
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +833 -157
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7380,11 +7380,11 @@ function solve(total, items, gap = 0) {
|
|
|
7380
7380
|
}
|
|
7381
7381
|
}
|
|
7382
7382
|
let assigned = 0;
|
|
7383
|
-
const
|
|
7384
|
-
|
|
7383
|
+
const order2 = [...pending];
|
|
7384
|
+
order2.forEach((i, k) => {
|
|
7385
7385
|
const p = parsed[i];
|
|
7386
7386
|
const exact = remainingFr > 0 ? pool * p.fr / remainingFr : 0;
|
|
7387
|
-
const v = k ===
|
|
7387
|
+
const v = k === order2.length - 1 ? Math.max(0, pool - assigned) : Math.floor(exact);
|
|
7388
7388
|
out[i] = v;
|
|
7389
7389
|
assigned += v;
|
|
7390
7390
|
});
|
|
@@ -24745,9 +24745,9 @@ var source_default = chalk;
|
|
|
24745
24745
|
|
|
24746
24746
|
// src/index.ts
|
|
24747
24747
|
var import_readline = __toESM(require("readline"));
|
|
24748
|
-
var
|
|
24749
|
-
var
|
|
24750
|
-
var
|
|
24748
|
+
var import_node_child_process18 = require("child_process");
|
|
24749
|
+
var import_node_fs43 = require("fs");
|
|
24750
|
+
var import_node_path31 = require("path");
|
|
24751
24751
|
var import_node_os13 = require("os");
|
|
24752
24752
|
|
|
24753
24753
|
// src/commands/monitor.ts
|
|
@@ -31639,6 +31639,7 @@ function loadConfig(configPath) {
|
|
|
31639
31639
|
detection: parsed.detection,
|
|
31640
31640
|
cloud: parsed.cloud,
|
|
31641
31641
|
watchdog: parsed.watchdog,
|
|
31642
|
+
update: parsed.update,
|
|
31642
31643
|
storage: parsed.storage,
|
|
31643
31644
|
license: parsed.license
|
|
31644
31645
|
};
|
|
@@ -31672,7 +31673,8 @@ function generateDefaultConfig(detectedServices) {
|
|
|
31672
31673
|
modules: DEFAULT_CONFIG.modules,
|
|
31673
31674
|
// Written out so the opt-out is discoverable; these are also the defaults
|
|
31674
31675
|
// when the section is absent.
|
|
31675
|
-
cloud: { enabled: true, min_severity: "medium" }
|
|
31676
|
+
cloud: { enabled: true, min_severity: "medium" },
|
|
31677
|
+
update: { auto: true, interval: "6h", min_age: "2h" }
|
|
31676
31678
|
};
|
|
31677
31679
|
return import_toml.default.stringify(config);
|
|
31678
31680
|
}
|
|
@@ -36678,12 +36680,12 @@ var import_node_path12 = require("path");
|
|
|
36678
36680
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
36679
36681
|
async function scanDependencies(targetPath) {
|
|
36680
36682
|
const findings = [];
|
|
36681
|
-
for (const { file, ecosystem, parse:
|
|
36683
|
+
for (const { file, ecosystem, parse: parse3 } of LOCKFILES) {
|
|
36682
36684
|
const lockPath = (0, import_node_path12.join)(targetPath, file);
|
|
36683
36685
|
if (!(0, import_node_fs14.existsSync)(lockPath)) continue;
|
|
36684
36686
|
let deps;
|
|
36685
36687
|
try {
|
|
36686
|
-
deps = dedupe(
|
|
36688
|
+
deps = dedupe(parse3((0, import_node_fs14.readFileSync)(lockPath, "utf-8")));
|
|
36687
36689
|
} catch {
|
|
36688
36690
|
continue;
|
|
36689
36691
|
}
|
|
@@ -39777,16 +39779,16 @@ async function sshConnect(options) {
|
|
|
39777
39779
|
}
|
|
39778
39780
|
|
|
39779
39781
|
// src/commands/daemon.ts
|
|
39780
|
-
var
|
|
39781
|
-
var import_node_fs35 = require("fs");
|
|
39782
|
-
var import_node_path26 = require("path");
|
|
39782
|
+
var import_node_child_process13 = require("child_process");
|
|
39783
39783
|
var import_node_fs36 = require("fs");
|
|
39784
|
+
var import_node_path27 = require("path");
|
|
39785
|
+
var import_node_fs37 = require("fs");
|
|
39784
39786
|
|
|
39785
39787
|
// src/daemon/index.ts
|
|
39786
|
-
var
|
|
39787
|
-
var
|
|
39788
|
+
var import_node_fs35 = require("fs");
|
|
39789
|
+
var import_node_child_process12 = require("child_process");
|
|
39788
39790
|
var import_node_os11 = require("os");
|
|
39789
|
-
var
|
|
39791
|
+
var import_node_path26 = require("path");
|
|
39790
39792
|
var import_node_util = require("util");
|
|
39791
39793
|
init_paths();
|
|
39792
39794
|
|
|
@@ -41672,7 +41674,8 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
41672
41674
|
severity: r.severity,
|
|
41673
41675
|
title: r.title.slice(0, MAX_TITLE_CHARS),
|
|
41674
41676
|
recommendation: r.recommendation,
|
|
41675
|
-
observed_at: observedAt.toISOString()
|
|
41677
|
+
observed_at: observedAt.toISOString(),
|
|
41678
|
+
...r.details ? { details: trimMetadata(r.details) } : {}
|
|
41676
41679
|
}));
|
|
41677
41680
|
}
|
|
41678
41681
|
|
|
@@ -42341,6 +42344,242 @@ var RemediationConsumer = class {
|
|
|
42341
42344
|
}
|
|
42342
42345
|
};
|
|
42343
42346
|
|
|
42347
|
+
// src/daemon/workers/auto-update.ts
|
|
42348
|
+
var import_node_child_process9 = require("child_process");
|
|
42349
|
+
var import_node_fs30 = require("fs");
|
|
42350
|
+
var import_node_path22 = require("path");
|
|
42351
|
+
init_backoff();
|
|
42352
|
+
var PKG_NAME = "@profullstack/threatcrush";
|
|
42353
|
+
var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
|
|
42354
|
+
var DEFAULT_INTERVAL_MS = 6 * 36e5;
|
|
42355
|
+
var DEFAULT_MIN_AGE_MS = 2 * 36e5;
|
|
42356
|
+
var RETRY_AFTER_MS = 24 * 36e5;
|
|
42357
|
+
function isNewer(a, b) {
|
|
42358
|
+
const parse3 = (v) => {
|
|
42359
|
+
const [core, pre] = v.replace(/^v/, "").split("-", 2);
|
|
42360
|
+
return { nums: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: pre ?? null };
|
|
42361
|
+
};
|
|
42362
|
+
const x = parse3(a);
|
|
42363
|
+
const y = parse3(b);
|
|
42364
|
+
for (let i = 0; i < 3; i++) {
|
|
42365
|
+
if ((x.nums[i] ?? 0) !== (y.nums[i] ?? 0)) return (x.nums[i] ?? 0) > (y.nums[i] ?? 0);
|
|
42366
|
+
}
|
|
42367
|
+
if (x.pre === y.pre) return false;
|
|
42368
|
+
if (x.pre === null) return true;
|
|
42369
|
+
if (y.pre === null) return false;
|
|
42370
|
+
return x.pre > y.pre;
|
|
42371
|
+
}
|
|
42372
|
+
function pickUpdate(doc, current, opts) {
|
|
42373
|
+
const latest = doc["dist-tags"]?.latest;
|
|
42374
|
+
if (!latest) return { version: null, reason: "registry has no latest tag" };
|
|
42375
|
+
if (!isNewer(latest, current)) return { version: null, reason: `up to date (${current})` };
|
|
42376
|
+
const major = (v) => Number.parseInt(v.replace(/^v/, ""), 10);
|
|
42377
|
+
if (!opts.allowMajor && major(latest) !== major(current)) {
|
|
42378
|
+
return { version: null, reason: `${latest} is a new major; set [update] allow_major = true to take it` };
|
|
42379
|
+
}
|
|
42380
|
+
const published = Date.parse(doc.time?.[latest] ?? "");
|
|
42381
|
+
if (!Number.isFinite(published)) return { version: null, reason: `no publish time for ${latest}` };
|
|
42382
|
+
if (opts.now - published < opts.minAgeMs) {
|
|
42383
|
+
return { version: null, reason: `${latest} is younger than min_age; waiting` };
|
|
42384
|
+
}
|
|
42385
|
+
return { version: latest };
|
|
42386
|
+
}
|
|
42387
|
+
function installPlan(opts) {
|
|
42388
|
+
const expected = `${import_node_path22.sep}lib${import_node_path22.sep}node_modules${import_node_path22.sep}@profullstack${import_node_path22.sep}threatcrush`;
|
|
42389
|
+
if (!opts.pkgRoot.endsWith(expected)) {
|
|
42390
|
+
return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
|
|
42391
|
+
}
|
|
42392
|
+
const nodeBin = (0, import_node_path22.dirname)(opts.execPath);
|
|
42393
|
+
const npm = (0, import_node_path22.join)(nodeBin, "npm");
|
|
42394
|
+
if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
|
|
42395
|
+
if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
|
|
42396
|
+
const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
|
|
42397
|
+
const path = `${nodeBin}:/usr/local/bin:/usr/bin:/bin`;
|
|
42398
|
+
if (opts.underSystemd && opts.uid === 0) {
|
|
42399
|
+
return {
|
|
42400
|
+
kind: "run",
|
|
42401
|
+
argv: [
|
|
42402
|
+
"systemd-run",
|
|
42403
|
+
"--wait",
|
|
42404
|
+
"--collect",
|
|
42405
|
+
"--quiet",
|
|
42406
|
+
`--unit=threatcrush-autoupdate-${opts.version.replace(/[^0-9A-Za-z]/g, "-")}`,
|
|
42407
|
+
`--uid=${opts.owner.uid}`,
|
|
42408
|
+
`--gid=${opts.owner.gid}`,
|
|
42409
|
+
`--setenv=HOME=${opts.owner.home}`,
|
|
42410
|
+
`--setenv=PATH=${path}`,
|
|
42411
|
+
...npmArgs
|
|
42412
|
+
]
|
|
42413
|
+
};
|
|
42414
|
+
}
|
|
42415
|
+
if (opts.uid === opts.owner.uid) {
|
|
42416
|
+
return { kind: "run", argv: npmArgs, env: { PATH: path } };
|
|
42417
|
+
}
|
|
42418
|
+
return {
|
|
42419
|
+
kind: "unsupported",
|
|
42420
|
+
reason: `install is owned by uid ${opts.owner.uid}, daemon runs as ${opts.uid}; run \`threatcrush update\` as that user`
|
|
42421
|
+
};
|
|
42422
|
+
}
|
|
42423
|
+
function ownerOf(path, passwd = "/etc/passwd") {
|
|
42424
|
+
try {
|
|
42425
|
+
const st = (0, import_node_fs30.statSync)(path);
|
|
42426
|
+
let home = st.uid === 0 ? "/root" : "";
|
|
42427
|
+
try {
|
|
42428
|
+
for (const line2 of (0, import_node_fs30.readFileSync)(passwd, "utf8").split("\n")) {
|
|
42429
|
+
const f = line2.split(":");
|
|
42430
|
+
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
42431
|
+
}
|
|
42432
|
+
} catch {
|
|
42433
|
+
}
|
|
42434
|
+
return home ? { uid: st.uid, gid: st.gid, home } : null;
|
|
42435
|
+
} catch {
|
|
42436
|
+
return null;
|
|
42437
|
+
}
|
|
42438
|
+
}
|
|
42439
|
+
function updateSettings(section, env2 = process.env) {
|
|
42440
|
+
const interval = parseDuration(section?.interval);
|
|
42441
|
+
const minAge = parseDuration(section?.min_age);
|
|
42442
|
+
return {
|
|
42443
|
+
enabled: section?.auto !== false && env2.THREATCRUSH_AUTO_UPDATE !== "0",
|
|
42444
|
+
intervalMs: interval ? Math.max(15 * 60, interval) * 1e3 : DEFAULT_INTERVAL_MS,
|
|
42445
|
+
minAgeMs: minAge !== null ? minAge * 1e3 : DEFAULT_MIN_AGE_MS,
|
|
42446
|
+
allowMajor: section?.allow_major === true
|
|
42447
|
+
};
|
|
42448
|
+
}
|
|
42449
|
+
function defaultRun(argv, env2) {
|
|
42450
|
+
return new Promise((resolve6) => {
|
|
42451
|
+
const child = (0, import_node_child_process9.spawn)(argv[0], argv.slice(1), {
|
|
42452
|
+
env: { ...process.env, ...env2 },
|
|
42453
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
42454
|
+
});
|
|
42455
|
+
let output = "";
|
|
42456
|
+
const keep = (b) => {
|
|
42457
|
+
output = (output + b.toString()).slice(-4e3);
|
|
42458
|
+
};
|
|
42459
|
+
child.stdout?.on("data", keep);
|
|
42460
|
+
child.stderr?.on("data", keep);
|
|
42461
|
+
child.on("error", (err) => resolve6({ code: -1, output: err.message }));
|
|
42462
|
+
child.on("close", (code) => resolve6({ code: code ?? -1, output }));
|
|
42463
|
+
});
|
|
42464
|
+
}
|
|
42465
|
+
var AutoUpdate = class {
|
|
42466
|
+
constructor(opts) {
|
|
42467
|
+
this.opts = opts;
|
|
42468
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
42469
|
+
this.run = opts.run ?? defaultRun;
|
|
42470
|
+
this.now = opts.now ?? Date.now;
|
|
42471
|
+
this.random = opts.random ?? Math.random;
|
|
42472
|
+
}
|
|
42473
|
+
opts;
|
|
42474
|
+
timer = null;
|
|
42475
|
+
busy = false;
|
|
42476
|
+
fetchImpl;
|
|
42477
|
+
run;
|
|
42478
|
+
now;
|
|
42479
|
+
random;
|
|
42480
|
+
start() {
|
|
42481
|
+
if (!this.opts.settings.enabled) {
|
|
42482
|
+
this.opts.log("[update] auto-update off ([update] auto = false or THREATCRUSH_AUTO_UPDATE=0)");
|
|
42483
|
+
return;
|
|
42484
|
+
}
|
|
42485
|
+
this.schedule(10 * 6e4 + this.random() * 30 * 6e4);
|
|
42486
|
+
}
|
|
42487
|
+
stop() {
|
|
42488
|
+
if (this.timer) clearTimeout(this.timer);
|
|
42489
|
+
this.timer = null;
|
|
42490
|
+
}
|
|
42491
|
+
schedule(ms) {
|
|
42492
|
+
this.timer = setTimeout(() => {
|
|
42493
|
+
void this.check().finally(() => {
|
|
42494
|
+
if (this.timer !== null) this.schedule(this.opts.settings.intervalMs + this.random() * 36e5);
|
|
42495
|
+
});
|
|
42496
|
+
}, ms);
|
|
42497
|
+
this.timer.unref?.();
|
|
42498
|
+
}
|
|
42499
|
+
/** One check; returns what it did, for logs and tests. */
|
|
42500
|
+
async check() {
|
|
42501
|
+
if (this.busy) return "busy";
|
|
42502
|
+
this.busy = true;
|
|
42503
|
+
try {
|
|
42504
|
+
let doc;
|
|
42505
|
+
try {
|
|
42506
|
+
const res = await this.fetchImpl(REGISTRY, {
|
|
42507
|
+
headers: { accept: "application/json" },
|
|
42508
|
+
signal: AbortSignal.timeout(2e4)
|
|
42509
|
+
});
|
|
42510
|
+
if (!res.ok) return this.note(`registry answered ${res.status}`);
|
|
42511
|
+
doc = await res.json();
|
|
42512
|
+
} catch (err) {
|
|
42513
|
+
return this.note(`registry unreachable: ${err.message}`);
|
|
42514
|
+
}
|
|
42515
|
+
const pick = pickUpdate(doc, this.opts.version, {
|
|
42516
|
+
allowMajor: this.opts.settings.allowMajor,
|
|
42517
|
+
minAgeMs: this.opts.settings.minAgeMs,
|
|
42518
|
+
now: this.now()
|
|
42519
|
+
});
|
|
42520
|
+
if (pick.version === null) return this.note(pick.reason, false);
|
|
42521
|
+
const target = pick.version;
|
|
42522
|
+
const last = this.lastAttempt();
|
|
42523
|
+
if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
|
|
42524
|
+
return this.note(`${target} was tried at ${new Date(last.at).toISOString()} and did not take; retrying after a day`);
|
|
42525
|
+
}
|
|
42526
|
+
const plan = installPlan({
|
|
42527
|
+
version: target,
|
|
42528
|
+
pkgRoot: this.opts.pkgRoot,
|
|
42529
|
+
execPath: process.execPath,
|
|
42530
|
+
uid: process.getuid?.() ?? -1,
|
|
42531
|
+
owner: ownerOf(this.opts.pkgRoot),
|
|
42532
|
+
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
42533
|
+
npmExists: import_node_fs30.existsSync
|
|
42534
|
+
});
|
|
42535
|
+
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
42536
|
+
this.recordAttempt(target);
|
|
42537
|
+
this.event(`updating ThreatCrush ${this.opts.version} \u2192 ${target}`, { from: this.opts.version, to: target });
|
|
42538
|
+
this.opts.log(`[update] installing ${target}: ${plan.argv.join(" ")}`);
|
|
42539
|
+
const { code, output } = await this.run(plan.argv, plan.env);
|
|
42540
|
+
if (code !== 0) {
|
|
42541
|
+
const tail = output.trim().split("\n").slice(-3).join(" | ");
|
|
42542
|
+
this.event(`auto-update to ${target} failed (exit ${code})`, { to: target, code, output: tail });
|
|
42543
|
+
return this.note(`install of ${target} failed (exit ${code}): ${tail}`);
|
|
42544
|
+
}
|
|
42545
|
+
this.opts.log(`[update] ${target} installed; restarting onto it`);
|
|
42546
|
+
this.opts.restartDaemon();
|
|
42547
|
+
return `updated to ${target}`;
|
|
42548
|
+
} finally {
|
|
42549
|
+
this.busy = false;
|
|
42550
|
+
}
|
|
42551
|
+
}
|
|
42552
|
+
note(line2, log = true) {
|
|
42553
|
+
if (log) this.opts.log(`[update] ${line2}`);
|
|
42554
|
+
return line2;
|
|
42555
|
+
}
|
|
42556
|
+
event(message, details) {
|
|
42557
|
+
this.opts.bus.publish({
|
|
42558
|
+
timestamp: new Date(this.now()),
|
|
42559
|
+
module: "auto-update",
|
|
42560
|
+
category: "system",
|
|
42561
|
+
severity: "info",
|
|
42562
|
+
message,
|
|
42563
|
+
details
|
|
42564
|
+
});
|
|
42565
|
+
}
|
|
42566
|
+
lastAttempt() {
|
|
42567
|
+
try {
|
|
42568
|
+
const v = JSON.parse((0, import_node_fs30.readFileSync)(this.opts.statePath, "utf8"));
|
|
42569
|
+
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
42570
|
+
} catch {
|
|
42571
|
+
return null;
|
|
42572
|
+
}
|
|
42573
|
+
}
|
|
42574
|
+
recordAttempt(version) {
|
|
42575
|
+
try {
|
|
42576
|
+
(0, import_node_fs30.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
42577
|
+
} catch (err) {
|
|
42578
|
+
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
42579
|
+
}
|
|
42580
|
+
}
|
|
42581
|
+
};
|
|
42582
|
+
|
|
42344
42583
|
// src/daemon/rules/engine.ts
|
|
42345
42584
|
var MAX_WINDOW_ENTRIES = 1e3;
|
|
42346
42585
|
function live(window) {
|
|
@@ -42502,8 +42741,8 @@ var RuleEngine = class {
|
|
|
42502
42741
|
};
|
|
42503
42742
|
|
|
42504
42743
|
// src/daemon/rules/loader.ts
|
|
42505
|
-
var
|
|
42506
|
-
var
|
|
42744
|
+
var import_node_fs31 = require("fs");
|
|
42745
|
+
var import_node_path23 = require("path");
|
|
42507
42746
|
|
|
42508
42747
|
// src/daemon/rules/default-rules.ts
|
|
42509
42748
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -42904,11 +43143,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
42904
43143
|
function loadAllRules(customDir) {
|
|
42905
43144
|
const rules = [...DEFAULT_RULES];
|
|
42906
43145
|
const dir = customDir || RULES_DIR;
|
|
42907
|
-
if ((0,
|
|
42908
|
-
const files = (0,
|
|
43146
|
+
if ((0, import_node_fs31.existsSync)(dir)) {
|
|
43147
|
+
const files = (0, import_node_fs31.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
42909
43148
|
for (const file of files) {
|
|
42910
43149
|
try {
|
|
42911
|
-
const raw = (0,
|
|
43150
|
+
const raw = (0, import_node_fs31.readFileSync)((0, import_node_path23.join)(dir, file), "utf-8");
|
|
42912
43151
|
const parsed = JSON.parse(raw);
|
|
42913
43152
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
42914
43153
|
for (const rule of customRules) {
|
|
@@ -42939,9 +43178,9 @@ function loadAllRules(customDir) {
|
|
|
42939
43178
|
}
|
|
42940
43179
|
|
|
42941
43180
|
// src/daemon/firewall/adapters.ts
|
|
42942
|
-
var
|
|
42943
|
-
var
|
|
42944
|
-
var
|
|
43181
|
+
var import_node_child_process10 = require("child_process");
|
|
43182
|
+
var import_node_fs32 = require("fs");
|
|
43183
|
+
var import_node_path24 = require("path");
|
|
42945
43184
|
var import_node_net8 = require("net");
|
|
42946
43185
|
function assertValidFirewallIp(ip) {
|
|
42947
43186
|
if ((0, import_node_net8.isIP)(ip) !== 4) {
|
|
@@ -42954,9 +43193,9 @@ function assertBannableIp(ip) {
|
|
|
42954
43193
|
}
|
|
42955
43194
|
}
|
|
42956
43195
|
function writeIfAbsent(path, contents) {
|
|
42957
|
-
(0,
|
|
43196
|
+
(0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
|
|
42958
43197
|
try {
|
|
42959
|
-
(0,
|
|
43198
|
+
(0, import_node_fs32.writeFileSync)(path, contents, { flag: "wx" });
|
|
42960
43199
|
} catch (err) {
|
|
42961
43200
|
if (err.code !== "EEXIST") throw err;
|
|
42962
43201
|
}
|
|
@@ -42975,11 +43214,11 @@ var Fail2banAdapter = class {
|
|
|
42975
43214
|
enforces = true;
|
|
42976
43215
|
jailReady = false;
|
|
42977
43216
|
isAvailable() {
|
|
42978
|
-
const result = (0,
|
|
43217
|
+
const result = (0, import_node_child_process10.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
42979
43218
|
return result.status === 0;
|
|
42980
43219
|
}
|
|
42981
43220
|
client(args) {
|
|
42982
|
-
return (0,
|
|
43221
|
+
return (0, import_node_child_process10.execFileSync)("fail2ban-client", args, {
|
|
42983
43222
|
encoding: "utf-8",
|
|
42984
43223
|
stdio: ["ignore", "pipe", "pipe"]
|
|
42985
43224
|
});
|
|
@@ -43075,35 +43314,35 @@ var NftablesAdapter = class {
|
|
|
43075
43314
|
table = "threatcrush";
|
|
43076
43315
|
set = "blocklist";
|
|
43077
43316
|
isAvailable() {
|
|
43078
|
-
const result = (0,
|
|
43317
|
+
const result = (0, import_node_child_process10.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
43079
43318
|
return result.status === 0;
|
|
43080
43319
|
}
|
|
43081
43320
|
ensureSetup() {
|
|
43082
43321
|
try {
|
|
43083
|
-
(0,
|
|
43322
|
+
(0, import_node_child_process10.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
43084
43323
|
} catch {
|
|
43085
|
-
(0,
|
|
43086
|
-
(0,
|
|
43087
|
-
(0,
|
|
43088
|
-
(0,
|
|
43324
|
+
(0, import_node_child_process10.execSync)(`nft add table inet ${this.table}`);
|
|
43325
|
+
(0, import_node_child_process10.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
43326
|
+
(0, import_node_child_process10.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
43327
|
+
(0, import_node_child_process10.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
43089
43328
|
}
|
|
43090
43329
|
}
|
|
43091
43330
|
async block(ip) {
|
|
43092
43331
|
assertValidFirewallIp(ip);
|
|
43093
43332
|
this.ensureSetup();
|
|
43094
|
-
(0,
|
|
43333
|
+
(0, import_node_child_process10.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
43095
43334
|
}
|
|
43096
43335
|
async unblock(ip) {
|
|
43097
43336
|
assertValidFirewallIp(ip);
|
|
43098
43337
|
try {
|
|
43099
|
-
(0,
|
|
43338
|
+
(0, import_node_child_process10.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
43100
43339
|
} catch {
|
|
43101
43340
|
}
|
|
43102
43341
|
}
|
|
43103
43342
|
async isBlocked(ip) {
|
|
43104
43343
|
assertValidFirewallIp(ip);
|
|
43105
43344
|
try {
|
|
43106
|
-
const output = (0,
|
|
43345
|
+
const output = (0, import_node_child_process10.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
43107
43346
|
return output.includes(ip);
|
|
43108
43347
|
} catch {
|
|
43109
43348
|
return false;
|
|
@@ -43111,7 +43350,7 @@ var NftablesAdapter = class {
|
|
|
43111
43350
|
}
|
|
43112
43351
|
async listBlocked() {
|
|
43113
43352
|
try {
|
|
43114
|
-
const output = (0,
|
|
43353
|
+
const output = (0, import_node_child_process10.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
43115
43354
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
43116
43355
|
if (!match) return [];
|
|
43117
43356
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -43124,34 +43363,34 @@ var IptablesAdapter = class {
|
|
|
43124
43363
|
name = "iptables";
|
|
43125
43364
|
chain = "THREATCRUSH";
|
|
43126
43365
|
isAvailable() {
|
|
43127
|
-
const result = (0,
|
|
43366
|
+
const result = (0, import_node_child_process10.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
43128
43367
|
return result.status === 0;
|
|
43129
43368
|
}
|
|
43130
43369
|
ensureChain() {
|
|
43131
43370
|
try {
|
|
43132
|
-
(0,
|
|
43371
|
+
(0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
43133
43372
|
} catch {
|
|
43134
|
-
(0,
|
|
43135
|
-
(0,
|
|
43373
|
+
(0, import_node_child_process10.execSync)(`iptables -N ${this.chain}`);
|
|
43374
|
+
(0, import_node_child_process10.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
43136
43375
|
}
|
|
43137
43376
|
}
|
|
43138
43377
|
async block(ip) {
|
|
43139
43378
|
assertValidFirewallIp(ip);
|
|
43140
43379
|
this.ensureChain();
|
|
43141
43380
|
if (await this.isBlocked(ip)) return;
|
|
43142
|
-
(0,
|
|
43381
|
+
(0, import_node_child_process10.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
43143
43382
|
}
|
|
43144
43383
|
async unblock(ip) {
|
|
43145
43384
|
assertValidFirewallIp(ip);
|
|
43146
43385
|
try {
|
|
43147
|
-
(0,
|
|
43386
|
+
(0, import_node_child_process10.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
43148
43387
|
} catch {
|
|
43149
43388
|
}
|
|
43150
43389
|
}
|
|
43151
43390
|
async isBlocked(ip) {
|
|
43152
43391
|
assertValidFirewallIp(ip);
|
|
43153
43392
|
try {
|
|
43154
|
-
const output = (0,
|
|
43393
|
+
const output = (0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
43155
43394
|
return output.includes(ip);
|
|
43156
43395
|
} catch {
|
|
43157
43396
|
return false;
|
|
@@ -43159,7 +43398,7 @@ var IptablesAdapter = class {
|
|
|
43159
43398
|
}
|
|
43160
43399
|
async listBlocked() {
|
|
43161
43400
|
try {
|
|
43162
|
-
const output = (0,
|
|
43401
|
+
const output = (0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
43163
43402
|
const ips = [];
|
|
43164
43403
|
for (const line2 of output.split("\n")) {
|
|
43165
43404
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -43215,7 +43454,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
43215
43454
|
}
|
|
43216
43455
|
|
|
43217
43456
|
// src/daemon/firewall/remediation.ts
|
|
43218
|
-
var
|
|
43457
|
+
var import_node_fs33 = require("fs");
|
|
43219
43458
|
var import_node_net9 = require("net");
|
|
43220
43459
|
init_paths();
|
|
43221
43460
|
init_backoff();
|
|
@@ -43629,7 +43868,7 @@ var RemediationManager = class {
|
|
|
43629
43868
|
}
|
|
43630
43869
|
logLine(line2) {
|
|
43631
43870
|
try {
|
|
43632
|
-
(0,
|
|
43871
|
+
(0, import_node_fs33.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
43633
43872
|
`);
|
|
43634
43873
|
} catch {
|
|
43635
43874
|
}
|
|
@@ -43667,19 +43906,19 @@ function remediationSettings(section) {
|
|
|
43667
43906
|
init_backoff();
|
|
43668
43907
|
|
|
43669
43908
|
// src/daemon/watchdog-service.ts
|
|
43670
|
-
var
|
|
43671
|
-
var
|
|
43909
|
+
var import_node_fs34 = require("fs");
|
|
43910
|
+
var import_node_path25 = require("path");
|
|
43672
43911
|
function defaultShareGid() {
|
|
43673
43912
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
43674
43913
|
if (!isRoot4) return void 0;
|
|
43675
43914
|
try {
|
|
43676
|
-
return (0,
|
|
43915
|
+
return (0, import_node_fs34.statSync)("/var/log/auth.log").gid;
|
|
43677
43916
|
} catch {
|
|
43678
43917
|
return void 0;
|
|
43679
43918
|
}
|
|
43680
43919
|
}
|
|
43681
43920
|
function startWatchdog(opts) {
|
|
43682
|
-
const dir = opts.config?.dir ?? (0,
|
|
43921
|
+
const dir = opts.config?.dir ?? (0, import_node_path25.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
43683
43922
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
43684
43923
|
if (opts.config?.enabled === false) {
|
|
43685
43924
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -43773,7 +44012,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
43773
44012
|
}
|
|
43774
44013
|
|
|
43775
44014
|
// src/core/node-runtime.ts
|
|
43776
|
-
var
|
|
44015
|
+
var import_node_child_process11 = require("child_process");
|
|
43777
44016
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
43778
44017
|
function nodeMajor(version) {
|
|
43779
44018
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -43787,31 +44026,45 @@ function daemonNodeProblem(version) {
|
|
|
43787
44026
|
}
|
|
43788
44027
|
function versionOfNode(path) {
|
|
43789
44028
|
if (path === process.execPath) return process.versions.node;
|
|
43790
|
-
const res = (0,
|
|
44029
|
+
const res = (0, import_node_child_process11.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
43791
44030
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
43792
44031
|
}
|
|
43793
44032
|
|
|
43794
44033
|
// src/daemon/index.ts
|
|
43795
44034
|
function readVersion2() {
|
|
43796
44035
|
try {
|
|
43797
|
-
const pkg = JSON.parse((0,
|
|
44036
|
+
const pkg = JSON.parse((0, import_node_fs35.readFileSync)((0, import_node_path26.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
43798
44037
|
return pkg.version || "0.0.0";
|
|
43799
44038
|
} catch {
|
|
43800
44039
|
return "0.0.0";
|
|
43801
44040
|
}
|
|
43802
44041
|
}
|
|
43803
44042
|
async function runHardeningChecks() {
|
|
43804
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
44043
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process12.execFile)(
|
|
43805
44044
|
process.execPath,
|
|
43806
|
-
[(0,
|
|
44045
|
+
[(0, import_node_path26.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
43807
44046
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
43808
44047
|
);
|
|
43809
44048
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
43810
|
-
|
|
44049
|
+
const findings = Array.isArray(parsed.findings) ? parsed.findings : [];
|
|
44050
|
+
const patches = await runPatchCheck().catch((err) => {
|
|
44051
|
+
logLine(`[cloud] patch check failed: ${err.message.split("\n")[0]}`);
|
|
44052
|
+
return null;
|
|
44053
|
+
});
|
|
44054
|
+
return patches ? [...findings, patches] : findings;
|
|
44055
|
+
}
|
|
44056
|
+
async function runPatchCheck() {
|
|
44057
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process12.execFile)(
|
|
44058
|
+
process.execPath,
|
|
44059
|
+
[(0, import_node_path26.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
44060
|
+
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
44061
|
+
);
|
|
44062
|
+
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
44063
|
+
return parsed.finding ?? null;
|
|
43811
44064
|
}
|
|
43812
44065
|
function logLine(line2) {
|
|
43813
44066
|
try {
|
|
43814
|
-
(0,
|
|
44067
|
+
(0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
43815
44068
|
`);
|
|
43816
44069
|
} catch {
|
|
43817
44070
|
}
|
|
@@ -43836,9 +44089,9 @@ async function runDaemon() {
|
|
|
43836
44089
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
43837
44090
|
const restartDaemon = () => {
|
|
43838
44091
|
if (PATHS.mode === "system") {
|
|
43839
|
-
(0,
|
|
44092
|
+
(0, import_node_child_process12.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
43840
44093
|
} else {
|
|
43841
|
-
(0,
|
|
44094
|
+
(0, import_node_child_process12.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
43842
44095
|
setTimeout(() => process.exit(0), 500).unref();
|
|
43843
44096
|
}
|
|
43844
44097
|
};
|
|
@@ -43853,7 +44106,7 @@ async function runDaemon() {
|
|
|
43853
44106
|
} catch (err) {
|
|
43854
44107
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
43855
44108
|
}
|
|
43856
|
-
const config = loadConfig((0,
|
|
44109
|
+
const config = loadConfig((0, import_node_fs35.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
43857
44110
|
configureAttackDetection(config.detection);
|
|
43858
44111
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
43859
44112
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -43932,7 +44185,7 @@ async function runDaemon() {
|
|
|
43932
44185
|
version,
|
|
43933
44186
|
hostname: (0, import_node_os11.hostname)(),
|
|
43934
44187
|
minSeverity,
|
|
43935
|
-
spoolPath: (0,
|
|
44188
|
+
spoolPath: (0, import_node_path26.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
43936
44189
|
log: logLine,
|
|
43937
44190
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
43938
44191
|
runHardening: runHardeningChecks
|
|
@@ -43946,6 +44199,16 @@ async function runDaemon() {
|
|
|
43946
44199
|
logLine(link ? `[cloud] reporting as server ${link.serverId} (org ${link.orgId}), detections >= ${minSeverity}` : "[cloud] not linked; run `threatcrush login` and `threatcrush servers link` to report to the dashboard");
|
|
43947
44200
|
}
|
|
43948
44201
|
const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
|
|
44202
|
+
const autoUpdate = new AutoUpdate({
|
|
44203
|
+
version,
|
|
44204
|
+
settings: updateSettings(config.update),
|
|
44205
|
+
pkgRoot: (0, import_node_path26.join)(__dirname, ".."),
|
|
44206
|
+
statePath: (0, import_node_path26.join)(PATHS.stateDir, "auto-update.json"),
|
|
44207
|
+
bus,
|
|
44208
|
+
log: logLine,
|
|
44209
|
+
restartDaemon
|
|
44210
|
+
});
|
|
44211
|
+
autoUpdate.start();
|
|
43949
44212
|
const ipc = new IpcServer(version, moduleHost, remediation, () => watchdog.status());
|
|
43950
44213
|
await ipc.start();
|
|
43951
44214
|
logLine(`[daemon] ipc listening on ${PATHS.socket}`);
|
|
@@ -43979,6 +44242,10 @@ async function runDaemon() {
|
|
|
43979
44242
|
watchdog.stop();
|
|
43980
44243
|
} catch {
|
|
43981
44244
|
}
|
|
44245
|
+
try {
|
|
44246
|
+
autoUpdate.stop();
|
|
44247
|
+
} catch {
|
|
44248
|
+
}
|
|
43982
44249
|
try {
|
|
43983
44250
|
await ipc.stop();
|
|
43984
44251
|
} catch {
|
|
@@ -44014,7 +44281,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
44014
44281
|
function isRoot2() {
|
|
44015
44282
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
44016
44283
|
}
|
|
44017
|
-
var DAEMON_ENTRY = (0,
|
|
44284
|
+
var DAEMON_ENTRY = (0, import_node_path27.join)(__dirname, "daemon.js");
|
|
44018
44285
|
async function daemonForeground() {
|
|
44019
44286
|
await runDaemon();
|
|
44020
44287
|
}
|
|
@@ -44035,7 +44302,7 @@ async function daemonStart() {
|
|
|
44035
44302
|
return;
|
|
44036
44303
|
}
|
|
44037
44304
|
ensureRuntimeDirs();
|
|
44038
|
-
if (!(0,
|
|
44305
|
+
if (!(0, import_node_fs36.existsSync)(DAEMON_ENTRY)) {
|
|
44039
44306
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
44040
44307
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
44041
44308
|
return;
|
|
@@ -44043,8 +44310,8 @@ async function daemonStart() {
|
|
|
44043
44310
|
let out;
|
|
44044
44311
|
let err;
|
|
44045
44312
|
try {
|
|
44046
|
-
out = (0,
|
|
44047
|
-
err = (0,
|
|
44313
|
+
out = (0, import_node_fs37.openSync)(PATHS.logFile, "a");
|
|
44314
|
+
err = (0, import_node_fs37.openSync)(PATHS.logFile, "a");
|
|
44048
44315
|
} catch (e) {
|
|
44049
44316
|
const code = e.code;
|
|
44050
44317
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -44057,7 +44324,7 @@ async function daemonStart() {
|
|
|
44057
44324
|
}
|
|
44058
44325
|
return;
|
|
44059
44326
|
}
|
|
44060
|
-
const child = (0,
|
|
44327
|
+
const child = (0, import_node_child_process13.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
44061
44328
|
detached: true,
|
|
44062
44329
|
stdio: ["ignore", out, err],
|
|
44063
44330
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -44132,41 +44399,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
44132
44399
|
}
|
|
44133
44400
|
async function releaseStaleSocket() {
|
|
44134
44401
|
const deadline = Date.now() + 2e3;
|
|
44135
|
-
while ((0,
|
|
44402
|
+
while ((0, import_node_fs36.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
44136
44403
|
await new Promise((r) => setTimeout(r, 50));
|
|
44137
44404
|
}
|
|
44138
|
-
if ((0,
|
|
44405
|
+
if ((0, import_node_fs36.existsSync)(PATHS.socket)) {
|
|
44139
44406
|
try {
|
|
44140
|
-
(0,
|
|
44407
|
+
(0, import_node_fs36.unlinkSync)(PATHS.socket);
|
|
44141
44408
|
} catch {
|
|
44142
44409
|
}
|
|
44143
44410
|
}
|
|
44144
44411
|
}
|
|
44145
44412
|
|
|
44146
44413
|
// src/commands/service.ts
|
|
44147
|
-
var
|
|
44148
|
-
var
|
|
44149
|
-
var
|
|
44414
|
+
var import_node_child_process14 = require("child_process");
|
|
44415
|
+
var import_node_fs38 = require("fs");
|
|
44416
|
+
var import_node_path28 = require("path");
|
|
44150
44417
|
var import_node_os12 = require("os");
|
|
44151
44418
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
44152
44419
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
44153
44420
|
function resolveTemplate() {
|
|
44154
|
-
const templatePath = (0,
|
|
44155
|
-
if (!(0,
|
|
44421
|
+
const templatePath = (0, import_node_path28.join)(__dirname, "systemd", "threatcrushd.service");
|
|
44422
|
+
if (!(0, import_node_fs38.existsSync)(templatePath)) {
|
|
44156
44423
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
44157
44424
|
}
|
|
44158
|
-
return (0,
|
|
44425
|
+
return (0, import_node_fs38.readFileSync)(templatePath, "utf-8");
|
|
44159
44426
|
}
|
|
44160
44427
|
function stableBinPath(binPath) {
|
|
44161
44428
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
44162
44429
|
if (stable === binPath) return binPath;
|
|
44163
|
-
return (0,
|
|
44430
|
+
return (0, import_node_fs38.existsSync)(stable) ? stable : binPath;
|
|
44164
44431
|
}
|
|
44165
44432
|
function resolveBinPath() {
|
|
44166
44433
|
const arg = process.argv[1];
|
|
44167
|
-
if (arg && (0,
|
|
44434
|
+
if (arg && (0, import_node_fs38.existsSync)(arg)) return stableBinPath(arg);
|
|
44168
44435
|
try {
|
|
44169
|
-
return (0,
|
|
44436
|
+
return (0, import_node_child_process14.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
44170
44437
|
} catch {
|
|
44171
44438
|
return "threatcrush";
|
|
44172
44439
|
}
|
|
@@ -44174,11 +44441,11 @@ function resolveBinPath() {
|
|
|
44174
44441
|
function stableNodePath(execPath) {
|
|
44175
44442
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
44176
44443
|
if (stable === execPath) return execPath;
|
|
44177
|
-
return (0,
|
|
44444
|
+
return (0, import_node_fs38.existsSync)(stable) ? stable : execPath;
|
|
44178
44445
|
}
|
|
44179
44446
|
function looksLikeNodeScript(path) {
|
|
44180
44447
|
try {
|
|
44181
|
-
const head = (0,
|
|
44448
|
+
const head = (0, import_node_fs38.readFileSync)(path, "utf-8").slice(0, 120);
|
|
44182
44449
|
return /^#!.*\bnode\b/.test(head);
|
|
44183
44450
|
} catch {
|
|
44184
44451
|
return false;
|
|
@@ -44205,20 +44472,20 @@ function isRoot3() {
|
|
|
44205
44472
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
44206
44473
|
}
|
|
44207
44474
|
function reexecWithSudo(args) {
|
|
44208
|
-
if ((0,
|
|
44475
|
+
if ((0, import_node_child_process14.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
44209
44476
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
44210
44477
|
const bin = resolveBinPath();
|
|
44211
44478
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
44212
|
-
const result = (0,
|
|
44479
|
+
const result = (0, import_node_child_process14.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
44213
44480
|
return result.status === 0;
|
|
44214
44481
|
}
|
|
44215
44482
|
function callerHome() {
|
|
44216
44483
|
const user = process.env.SUDO_USER;
|
|
44217
44484
|
if (!user) return null;
|
|
44218
44485
|
try {
|
|
44219
|
-
const line2 = (0,
|
|
44486
|
+
const line2 = (0, import_node_child_process14.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
44220
44487
|
const home = line2.split(":")[5];
|
|
44221
|
-
return home && (0,
|
|
44488
|
+
return home && (0, import_node_fs38.existsSync)(home) ? home : null;
|
|
44222
44489
|
} catch {
|
|
44223
44490
|
return null;
|
|
44224
44491
|
}
|
|
@@ -44226,13 +44493,13 @@ function callerHome() {
|
|
|
44226
44493
|
function stopUserModeDaemon() {
|
|
44227
44494
|
const home = callerHome();
|
|
44228
44495
|
if (!home) return;
|
|
44229
|
-
const runDir = (0,
|
|
44230
|
-
const pidFile = (0,
|
|
44231
|
-
const socket = (0,
|
|
44232
|
-
if (!(0,
|
|
44496
|
+
const runDir = (0, import_node_path28.join)(home, ".threatcrush", "run");
|
|
44497
|
+
const pidFile = (0, import_node_path28.join)(runDir, "threatcrushd.pid");
|
|
44498
|
+
const socket = (0, import_node_path28.join)(runDir, "threatcrushd.sock");
|
|
44499
|
+
if (!(0, import_node_fs38.existsSync)(pidFile) && !(0, import_node_fs38.existsSync)(socket)) return;
|
|
44233
44500
|
let pid = null;
|
|
44234
44501
|
try {
|
|
44235
|
-
pid = Number.parseInt((0,
|
|
44502
|
+
pid = Number.parseInt((0, import_node_fs38.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
44236
44503
|
} catch {
|
|
44237
44504
|
pid = null;
|
|
44238
44505
|
}
|
|
@@ -44245,13 +44512,13 @@ function stopUserModeDaemon() {
|
|
|
44245
44512
|
}
|
|
44246
44513
|
for (const path of [socket, pidFile]) {
|
|
44247
44514
|
try {
|
|
44248
|
-
if ((0,
|
|
44515
|
+
if ((0, import_node_fs38.existsSync)(path)) (0, import_node_fs38.rmSync)(path);
|
|
44249
44516
|
} catch {
|
|
44250
44517
|
}
|
|
44251
44518
|
}
|
|
44252
44519
|
}
|
|
44253
44520
|
function unitIsActive() {
|
|
44254
|
-
const result = (0,
|
|
44521
|
+
const result = (0, import_node_child_process14.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
44255
44522
|
return result.status === 0;
|
|
44256
44523
|
}
|
|
44257
44524
|
async function installServiceCommand() {
|
|
@@ -44262,8 +44529,8 @@ async function installServiceCommand() {
|
|
|
44262
44529
|
return;
|
|
44263
44530
|
}
|
|
44264
44531
|
const noSystemd = systemdUnavailableReason({
|
|
44265
|
-
hasSystemctl: (0,
|
|
44266
|
-
booted: (0,
|
|
44532
|
+
hasSystemctl: (0, import_node_child_process14.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
44533
|
+
booted: (0, import_node_fs38.existsSync)("/run/systemd/system")
|
|
44267
44534
|
});
|
|
44268
44535
|
if (noSystemd) {
|
|
44269
44536
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -44285,7 +44552,7 @@ async function installServiceCommand() {
|
|
|
44285
44552
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
44286
44553
|
let nodePath = stableNodePath(process.execPath);
|
|
44287
44554
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
44288
|
-
binPath = (0,
|
|
44555
|
+
binPath = (0, import_node_fs38.realpathSync)(binPath);
|
|
44289
44556
|
nodePath = process.execPath;
|
|
44290
44557
|
}
|
|
44291
44558
|
if (isNodeScript) {
|
|
@@ -44298,9 +44565,9 @@ async function installServiceCommand() {
|
|
|
44298
44565
|
}
|
|
44299
44566
|
}
|
|
44300
44567
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
44301
|
-
const configDir = (0,
|
|
44568
|
+
const configDir = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush");
|
|
44302
44569
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
44303
|
-
(0,
|
|
44570
|
+
(0, import_node_fs38.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
44304
44571
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
44305
44572
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
44306
44573
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -44315,8 +44582,8 @@ async function installServiceCommand() {
|
|
|
44315
44582
|
installLogrotate();
|
|
44316
44583
|
stopUserModeDaemon();
|
|
44317
44584
|
try {
|
|
44318
|
-
(0,
|
|
44319
|
-
(0,
|
|
44585
|
+
(0, import_node_child_process14.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
44586
|
+
(0, import_node_child_process14.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
44320
44587
|
} catch (err) {
|
|
44321
44588
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
44322
44589
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -44353,9 +44620,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
44353
44620
|
].join("\n");
|
|
44354
44621
|
}
|
|
44355
44622
|
function installLogrotate() {
|
|
44356
|
-
if (!(0,
|
|
44623
|
+
if (!(0, import_node_fs38.existsSync)((0, import_node_path28.dirname)(LOGROTATE_PATH))) return;
|
|
44357
44624
|
try {
|
|
44358
|
-
(0,
|
|
44625
|
+
(0, import_node_fs38.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
44359
44626
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
44360
44627
|
} catch (err) {
|
|
44361
44628
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -44377,20 +44644,20 @@ function ensureSystemDirs(configDir) {
|
|
|
44377
44644
|
];
|
|
44378
44645
|
let admGid2 = null;
|
|
44379
44646
|
try {
|
|
44380
|
-
admGid2 = (0,
|
|
44647
|
+
admGid2 = (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
|
|
44381
44648
|
} catch {
|
|
44382
44649
|
}
|
|
44383
44650
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
44384
44651
|
try {
|
|
44385
|
-
(0,
|
|
44652
|
+
(0, import_node_fs38.mkdirSync)(path, { recursive: true });
|
|
44386
44653
|
} catch {
|
|
44387
44654
|
}
|
|
44388
44655
|
try {
|
|
44389
44656
|
if (groupWritable && admGid2 !== null) {
|
|
44390
|
-
(0,
|
|
44391
|
-
(0,
|
|
44657
|
+
(0, import_node_fs38.chmodSync)(path, sticky ? 1533 : 509);
|
|
44658
|
+
(0, import_node_child_process14.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
44392
44659
|
} else {
|
|
44393
|
-
(0,
|
|
44660
|
+
(0, import_node_fs38.chmodSync)(path, 493);
|
|
44394
44661
|
}
|
|
44395
44662
|
} catch {
|
|
44396
44663
|
}
|
|
@@ -44410,29 +44677,29 @@ async function uninstallServiceCommand() {
|
|
|
44410
44677
|
return;
|
|
44411
44678
|
}
|
|
44412
44679
|
try {
|
|
44413
|
-
(0,
|
|
44680
|
+
(0, import_node_child_process14.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
44414
44681
|
} catch {
|
|
44415
44682
|
}
|
|
44416
44683
|
try {
|
|
44417
|
-
(0,
|
|
44684
|
+
(0, import_node_child_process14.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
44418
44685
|
} catch {
|
|
44419
44686
|
}
|
|
44420
44687
|
try {
|
|
44421
|
-
if ((0,
|
|
44422
|
-
(0,
|
|
44688
|
+
if ((0, import_node_fs38.existsSync)(UNIT_PATH)) {
|
|
44689
|
+
(0, import_node_child_process14.execSync)(`rm -f ${UNIT_PATH}`);
|
|
44423
44690
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
44424
44691
|
}
|
|
44425
44692
|
} catch {
|
|
44426
44693
|
}
|
|
44427
44694
|
try {
|
|
44428
|
-
(0,
|
|
44695
|
+
(0, import_node_child_process14.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
44429
44696
|
} catch {
|
|
44430
44697
|
}
|
|
44431
44698
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
44432
44699
|
}
|
|
44433
44700
|
|
|
44434
44701
|
// src/commands/save.ts
|
|
44435
|
-
var
|
|
44702
|
+
var import_node_fs39 = require("fs");
|
|
44436
44703
|
var import_toml5 = __toESM(require_toml());
|
|
44437
44704
|
init_cli_config();
|
|
44438
44705
|
init_paths();
|
|
@@ -44471,9 +44738,9 @@ async function saveCommand(opts = {}) {
|
|
|
44471
44738
|
}
|
|
44472
44739
|
const path = opts.config ?? PATHS.configFile;
|
|
44473
44740
|
let config = {};
|
|
44474
|
-
if ((0,
|
|
44741
|
+
if ((0, import_node_fs39.existsSync)(path)) {
|
|
44475
44742
|
try {
|
|
44476
|
-
config = import_toml5.default.parse((0,
|
|
44743
|
+
config = import_toml5.default.parse((0, import_node_fs39.readFileSync)(path, "utf-8"));
|
|
44477
44744
|
} catch (err) {
|
|
44478
44745
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
44479
44746
|
`));
|
|
@@ -44586,8 +44853,8 @@ function welcomeCommand() {
|
|
|
44586
44853
|
}
|
|
44587
44854
|
|
|
44588
44855
|
// src/commands/properties.ts
|
|
44589
|
-
var
|
|
44590
|
-
var
|
|
44856
|
+
var import_node_fs40 = require("fs");
|
|
44857
|
+
var import_node_path29 = require("path");
|
|
44591
44858
|
var import_node_readline4 = __toESM(require("readline"));
|
|
44592
44859
|
init_cli_config();
|
|
44593
44860
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -44917,8 +45184,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
44917
45184
|
}
|
|
44918
45185
|
}
|
|
44919
45186
|
function parseImportFile(path) {
|
|
44920
|
-
const ext = (0,
|
|
44921
|
-
const raw = (0,
|
|
45187
|
+
const ext = (0, import_node_path29.extname)(path).toLowerCase();
|
|
45188
|
+
const raw = (0, import_node_fs40.readFileSync)(path, "utf-8");
|
|
44922
45189
|
if (ext === ".json") {
|
|
44923
45190
|
const parsed = JSON.parse(raw);
|
|
44924
45191
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -45113,19 +45380,19 @@ async function rulesCommand(opts) {
|
|
|
45113
45380
|
}
|
|
45114
45381
|
|
|
45115
45382
|
// src/commands/harden.ts
|
|
45116
|
-
var
|
|
45117
|
-
var
|
|
45383
|
+
var import_node_fs41 = require("fs");
|
|
45384
|
+
var import_node_child_process15 = require("child_process");
|
|
45118
45385
|
init_cli_config();
|
|
45119
45386
|
function tryExec(cmd) {
|
|
45120
45387
|
try {
|
|
45121
|
-
return (0,
|
|
45388
|
+
return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45122
45389
|
} catch {
|
|
45123
45390
|
return null;
|
|
45124
45391
|
}
|
|
45125
45392
|
}
|
|
45126
45393
|
function tryRead(path) {
|
|
45127
45394
|
try {
|
|
45128
|
-
return (0,
|
|
45395
|
+
return (0, import_node_fs41.readFileSync)(path, "utf-8");
|
|
45129
45396
|
} catch {
|
|
45130
45397
|
return null;
|
|
45131
45398
|
}
|
|
@@ -45229,8 +45496,8 @@ function checkSshWeakConfig() {
|
|
|
45229
45496
|
};
|
|
45230
45497
|
}
|
|
45231
45498
|
function checkAutoUpdates() {
|
|
45232
|
-
const unattended = (0,
|
|
45233
|
-
const dnfAuto = (0,
|
|
45499
|
+
const unattended = (0, import_node_fs41.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs41.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
45500
|
+
const dnfAuto = (0, import_node_fs41.existsSync)("/etc/dnf/automatic.conf");
|
|
45234
45501
|
if (unattended || dnfAuto) {
|
|
45235
45502
|
return {
|
|
45236
45503
|
key: "auto-updates",
|
|
@@ -45356,7 +45623,7 @@ function checkFail2ban() {
|
|
|
45356
45623
|
explanation: "fail2ban is installed and running."
|
|
45357
45624
|
};
|
|
45358
45625
|
}
|
|
45359
|
-
if ((0,
|
|
45626
|
+
if ((0, import_node_fs41.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
45360
45627
|
return {
|
|
45361
45628
|
key: checkKey,
|
|
45362
45629
|
status: "warn",
|
|
@@ -45541,6 +45808,412 @@ async function hardenCommand(opts) {
|
|
|
45541
45808
|
if (opts.upload !== false) await uploadFindings(results, false);
|
|
45542
45809
|
}
|
|
45543
45810
|
|
|
45811
|
+
// src/core/patches/index.ts
|
|
45812
|
+
var import_node_fs42 = require("fs");
|
|
45813
|
+
var import_node_path30 = require("path");
|
|
45814
|
+
var import_node_child_process16 = require("child_process");
|
|
45815
|
+
var import_node_util2 = require("util");
|
|
45816
|
+
|
|
45817
|
+
// src/core/patches/dpkg-version.ts
|
|
45818
|
+
function parse2(version) {
|
|
45819
|
+
let rest = version.trim();
|
|
45820
|
+
let epoch = 0;
|
|
45821
|
+
const colon = rest.indexOf(":");
|
|
45822
|
+
if (colon > 0 && /^\d+$/.test(rest.slice(0, colon))) {
|
|
45823
|
+
epoch = Number(rest.slice(0, colon));
|
|
45824
|
+
rest = rest.slice(colon + 1);
|
|
45825
|
+
}
|
|
45826
|
+
const dash = rest.lastIndexOf("-");
|
|
45827
|
+
return dash >= 0 ? { epoch, upstream: rest.slice(0, dash), revision: rest.slice(dash + 1) } : { epoch, upstream: rest, revision: "" };
|
|
45828
|
+
}
|
|
45829
|
+
function order(ch) {
|
|
45830
|
+
if (ch === void 0) return 0;
|
|
45831
|
+
if (ch === "~") return -1;
|
|
45832
|
+
if (/[A-Za-z]/.test(ch)) return ch.charCodeAt(0);
|
|
45833
|
+
return ch.charCodeAt(0) + 256;
|
|
45834
|
+
}
|
|
45835
|
+
function compareFragment(a, b) {
|
|
45836
|
+
let i = 0;
|
|
45837
|
+
let j = 0;
|
|
45838
|
+
while (i < a.length || j < b.length) {
|
|
45839
|
+
let firstDiff = 0;
|
|
45840
|
+
while (i < a.length && !/\d/.test(a[i]) || j < b.length && !/\d/.test(b[j])) {
|
|
45841
|
+
const ac = i < a.length && !/\d/.test(a[i]) ? a[i] : void 0;
|
|
45842
|
+
const bc = j < b.length && !/\d/.test(b[j]) ? b[j] : void 0;
|
|
45843
|
+
const diff = order(ac) - order(bc);
|
|
45844
|
+
if (diff !== 0) return diff;
|
|
45845
|
+
i++;
|
|
45846
|
+
j++;
|
|
45847
|
+
}
|
|
45848
|
+
while (a[i] === "0") i++;
|
|
45849
|
+
while (b[j] === "0") j++;
|
|
45850
|
+
while (i < a.length && /\d/.test(a[i]) && j < b.length && /\d/.test(b[j])) {
|
|
45851
|
+
if (!firstDiff) firstDiff = a.charCodeAt(i) - b.charCodeAt(j);
|
|
45852
|
+
i++;
|
|
45853
|
+
j++;
|
|
45854
|
+
}
|
|
45855
|
+
if (i < a.length && /\d/.test(a[i])) return 1;
|
|
45856
|
+
if (j < b.length && /\d/.test(b[j])) return -1;
|
|
45857
|
+
if (firstDiff) return firstDiff;
|
|
45858
|
+
}
|
|
45859
|
+
return 0;
|
|
45860
|
+
}
|
|
45861
|
+
function compareDebianVersions(a, b) {
|
|
45862
|
+
const x = parse2(a);
|
|
45863
|
+
const y = parse2(b);
|
|
45864
|
+
if (x.epoch !== y.epoch) return x.epoch - y.epoch;
|
|
45865
|
+
return compareFragment(x.upstream, y.upstream) || compareFragment(x.revision, y.revision);
|
|
45866
|
+
}
|
|
45867
|
+
|
|
45868
|
+
// src/core/patches/index.ts
|
|
45869
|
+
var OSV_QUERY = "https://api.osv.dev/v1/query";
|
|
45870
|
+
var STALE_AFTER_MS = 2 * 864e5;
|
|
45871
|
+
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
45872
|
+
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
45873
|
+
var defaultExec = async (file, args) => {
|
|
45874
|
+
const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process16.execFile)(file, args, {
|
|
45875
|
+
timeout: 12e4,
|
|
45876
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
45877
|
+
env: { ...process.env, LC_ALL: "C" }
|
|
45878
|
+
});
|
|
45879
|
+
return stdout;
|
|
45880
|
+
};
|
|
45881
|
+
function parseOsRelease(text) {
|
|
45882
|
+
const out = {};
|
|
45883
|
+
for (const line2 of text.split("\n")) {
|
|
45884
|
+
const m = /^([A-Z_]+)=(.*)$/.exec(line2.trim());
|
|
45885
|
+
if (m) out[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
45886
|
+
}
|
|
45887
|
+
return out;
|
|
45888
|
+
}
|
|
45889
|
+
function osvEcosystem(os3) {
|
|
45890
|
+
if (os3.ID === "ubuntu" && os3.VERSION_ID) {
|
|
45891
|
+
return /LTS/.test(os3.VERSION ?? "") ? `Ubuntu:${os3.VERSION_ID}:LTS` : `Ubuntu:${os3.VERSION_ID}`;
|
|
45892
|
+
}
|
|
45893
|
+
if (os3.ID === "debian" && os3.VERSION_ID) return `Debian:${os3.VERSION_ID.split(".")[0]}`;
|
|
45894
|
+
return null;
|
|
45895
|
+
}
|
|
45896
|
+
function parseAptSimulation(text) {
|
|
45897
|
+
const out = [];
|
|
45898
|
+
for (const line2 of text.split("\n")) {
|
|
45899
|
+
const m = /^Inst (\S+) \[([^\]]+)\] \((\S+) ([^[)]*)/.exec(line2);
|
|
45900
|
+
if (!m) continue;
|
|
45901
|
+
const origins = m[4];
|
|
45902
|
+
out.push({
|
|
45903
|
+
name: m[1],
|
|
45904
|
+
installed: m[2],
|
|
45905
|
+
candidate: m[3],
|
|
45906
|
+
security: /-security\b|Debian-Security/i.test(origins)
|
|
45907
|
+
});
|
|
45908
|
+
}
|
|
45909
|
+
return out;
|
|
45910
|
+
}
|
|
45911
|
+
function parseSourceMap(text) {
|
|
45912
|
+
const out = /* @__PURE__ */ new Map();
|
|
45913
|
+
for (const line2 of text.split("\n")) {
|
|
45914
|
+
const [binary, source, version] = line2.trim().split("|");
|
|
45915
|
+
if (binary && source && version) out.set(binary.split(":")[0], { source, version });
|
|
45916
|
+
}
|
|
45917
|
+
return out;
|
|
45918
|
+
}
|
|
45919
|
+
function parseCandidateSources(text) {
|
|
45920
|
+
const out = /* @__PURE__ */ new Map();
|
|
45921
|
+
for (const stanza of text.split(/\n\s*\n/)) {
|
|
45922
|
+
const pkg = /^Package: (\S+)/m.exec(stanza)?.[1];
|
|
45923
|
+
const version = /^Version: (\S+)/m.exec(stanza)?.[1];
|
|
45924
|
+
if (!pkg || !version) continue;
|
|
45925
|
+
const src = /^Source: (\S+)(?: \(([^)]+)\))?/m.exec(stanza);
|
|
45926
|
+
out.set(`${pkg}=${version}`, { source: src?.[1] ?? pkg, version: src?.[2] ?? version });
|
|
45927
|
+
}
|
|
45928
|
+
return out;
|
|
45929
|
+
}
|
|
45930
|
+
function advisorySeverity(rec, ecosystem, source) {
|
|
45931
|
+
const label = (rec.severity?.find((s) => s.type === "Ubuntu")?.score ?? rec.database_specific?.severity ?? rec.affected?.find((a) => a.package?.ecosystem === ecosystem && a.package?.name === source)?.ecosystem_specific?.urgency ?? "").toLowerCase();
|
|
45932
|
+
if (label === "negligible" || label === "unimportant") return "info";
|
|
45933
|
+
if (label === "moderate") return "medium";
|
|
45934
|
+
if (SEVERITIES2.includes(label)) return label;
|
|
45935
|
+
return "medium";
|
|
45936
|
+
}
|
|
45937
|
+
function fixedByUpdate(rec, ecosystem, source, installed, candidate) {
|
|
45938
|
+
for (const a of rec.affected ?? []) {
|
|
45939
|
+
if (a.package?.ecosystem !== ecosystem || a.package?.name !== source) continue;
|
|
45940
|
+
for (const range of a.ranges ?? []) {
|
|
45941
|
+
for (const ev of range.events ?? []) {
|
|
45942
|
+
const fixed = ev.fixed;
|
|
45943
|
+
if (!fixed) continue;
|
|
45944
|
+
if (compareDebianVersions(installed, fixed) < 0 && compareDebianVersions(fixed, candidate) <= 0) return true;
|
|
45945
|
+
}
|
|
45946
|
+
}
|
|
45947
|
+
}
|
|
45948
|
+
return false;
|
|
45949
|
+
}
|
|
45950
|
+
function displayId(rec) {
|
|
45951
|
+
return rec.upstream?.find((u) => u.startsWith("CVE-")) ?? rec.aliases?.find((u) => u.startsWith("CVE-")) ?? rec.id;
|
|
45952
|
+
}
|
|
45953
|
+
async function osvRecords(doFetch, ecosystem, source, version) {
|
|
45954
|
+
const out = [];
|
|
45955
|
+
let pageToken;
|
|
45956
|
+
for (let page = 0; page < 20; page++) {
|
|
45957
|
+
const res = await doFetch(OSV_QUERY, {
|
|
45958
|
+
method: "POST",
|
|
45959
|
+
headers: { "Content-Type": "application/json" },
|
|
45960
|
+
body: JSON.stringify({ package: { name: source, ecosystem }, version, ...pageToken ? { page_token: pageToken } : {} })
|
|
45961
|
+
});
|
|
45962
|
+
if (!res.ok) throw new Error(`OSV query for ${source} failed: HTTP ${res.status}`);
|
|
45963
|
+
const body = await res.json();
|
|
45964
|
+
out.push(...body.vulns ?? []);
|
|
45965
|
+
pageToken = body.next_page_token;
|
|
45966
|
+
if (!pageToken) break;
|
|
45967
|
+
}
|
|
45968
|
+
return out;
|
|
45969
|
+
}
|
|
45970
|
+
function newestReleaseMtime(dir) {
|
|
45971
|
+
try {
|
|
45972
|
+
let newest = 0;
|
|
45973
|
+
for (const name of (0, import_node_fs42.readdirSync)(dir)) {
|
|
45974
|
+
if (!/Release$/.test(name)) continue;
|
|
45975
|
+
newest = Math.max(newest, (0, import_node_fs42.statSync)((0, import_node_path30.join)(dir, name)).mtimeMs);
|
|
45976
|
+
}
|
|
45977
|
+
return newest > 0 ? new Date(newest) : null;
|
|
45978
|
+
} catch {
|
|
45979
|
+
return null;
|
|
45980
|
+
}
|
|
45981
|
+
}
|
|
45982
|
+
function emptyCounts2() {
|
|
45983
|
+
return { info: 0, low: 0, medium: 0, high: 0, critical: 0, cves: 0, packages: 0 };
|
|
45984
|
+
}
|
|
45985
|
+
async function checkPatches(opts = {}) {
|
|
45986
|
+
const exec = opts.exec ?? defaultExec;
|
|
45987
|
+
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
45988
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
45989
|
+
let osText = opts.osRelease;
|
|
45990
|
+
if (osText === void 0) {
|
|
45991
|
+
try {
|
|
45992
|
+
osText = (0, import_node_fs42.readFileSync)("/etc/os-release", "utf-8");
|
|
45993
|
+
} catch {
|
|
45994
|
+
osText = "";
|
|
45995
|
+
}
|
|
45996
|
+
}
|
|
45997
|
+
const os3 = parseOsRelease(osText);
|
|
45998
|
+
const ecosystem = osvEcosystem(os3);
|
|
45999
|
+
const base = {
|
|
46000
|
+
supported: false,
|
|
46001
|
+
os: os3.PRETTY_NAME ?? os3.ID ?? "unknown",
|
|
46002
|
+
ecosystem,
|
|
46003
|
+
checked_at: now.toISOString(),
|
|
46004
|
+
lists_updated_at: null,
|
|
46005
|
+
lists_stale: false,
|
|
46006
|
+
upgradable: 0,
|
|
46007
|
+
packages: [],
|
|
46008
|
+
counts: emptyCounts2()
|
|
46009
|
+
};
|
|
46010
|
+
if (!ecosystem) {
|
|
46011
|
+
return { ...base, reason: `patch status supports Debian and Ubuntu; this is ${base.os}` };
|
|
46012
|
+
}
|
|
46013
|
+
let simulation;
|
|
46014
|
+
try {
|
|
46015
|
+
simulation = await exec("apt-get", ["-s", "-o", "Debug::NoLocking=1", "dist-upgrade"]);
|
|
46016
|
+
} catch (err) {
|
|
46017
|
+
return { ...base, reason: `apt-get simulation failed: ${err.message.split("\n")[0]}` };
|
|
46018
|
+
}
|
|
46019
|
+
const listsAt = newestReleaseMtime(opts.aptListsDir ?? "/var/lib/apt/lists");
|
|
46020
|
+
const report = {
|
|
46021
|
+
...base,
|
|
46022
|
+
supported: true,
|
|
46023
|
+
lists_updated_at: listsAt?.toISOString() ?? null,
|
|
46024
|
+
lists_stale: !listsAt || now.getTime() - listsAt.getTime() > (opts.staleAfterMs ?? STALE_AFTER_MS)
|
|
46025
|
+
};
|
|
46026
|
+
const upgrades = parseAptSimulation(simulation);
|
|
46027
|
+
report.upgradable = upgrades.length;
|
|
46028
|
+
const security = upgrades.filter((u) => u.security);
|
|
46029
|
+
if (security.length === 0) return report;
|
|
46030
|
+
const installedSources = parseSourceMap(await exec("dpkg-query", [
|
|
46031
|
+
"-W",
|
|
46032
|
+
"-f=${Package}|${source:Package}|${source:Version}\n",
|
|
46033
|
+
...security.map((u) => u.name)
|
|
46034
|
+
]).catch(() => ""));
|
|
46035
|
+
const candidateSources = parseCandidateSources(await exec("apt-cache", [
|
|
46036
|
+
"show",
|
|
46037
|
+
"--no-all-versions",
|
|
46038
|
+
...security.map((u) => `${u.name}=${u.candidate}`)
|
|
46039
|
+
]).catch(() => ""));
|
|
46040
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
46041
|
+
for (const u of security) {
|
|
46042
|
+
const inst = installedSources.get(u.name) ?? { source: u.name, version: u.installed };
|
|
46043
|
+
const cand = candidateSources.get(`${u.name}=${u.candidate}`) ?? { source: inst.source, version: u.candidate };
|
|
46044
|
+
const key = `${inst.source}|${inst.version}`;
|
|
46045
|
+
const entry = bySource.get(key);
|
|
46046
|
+
if (entry) {
|
|
46047
|
+
entry.binaries.push(u.name);
|
|
46048
|
+
if (compareDebianVersions(cand.version, entry.candidate) > 0) entry.candidate = cand.version;
|
|
46049
|
+
} else {
|
|
46050
|
+
bySource.set(key, {
|
|
46051
|
+
binaries: [u.name],
|
|
46052
|
+
source: inst.source,
|
|
46053
|
+
installed: inst.version,
|
|
46054
|
+
candidate: cand.version,
|
|
46055
|
+
severity: "medium",
|
|
46056
|
+
cves: []
|
|
46057
|
+
});
|
|
46058
|
+
}
|
|
46059
|
+
}
|
|
46060
|
+
for (const pkg of bySource.values()) {
|
|
46061
|
+
try {
|
|
46062
|
+
const seen = /* @__PURE__ */ new Set();
|
|
46063
|
+
for (const rec of await osvRecords(doFetch, ecosystem, pkg.source, pkg.installed)) {
|
|
46064
|
+
if (!fixedByUpdate(rec, ecosystem, pkg.source, pkg.installed, pkg.candidate)) continue;
|
|
46065
|
+
const id = displayId(rec);
|
|
46066
|
+
if (seen.has(id)) continue;
|
|
46067
|
+
seen.add(id);
|
|
46068
|
+
pkg.cves.push({ id, severity: advisorySeverity(rec, ecosystem, pkg.source) });
|
|
46069
|
+
}
|
|
46070
|
+
} catch (err) {
|
|
46071
|
+
report.osv_error ??= err.message;
|
|
46072
|
+
}
|
|
46073
|
+
pkg.cves.sort((a, b) => RANK[b.severity] - RANK[a.severity] || a.id.localeCompare(b.id));
|
|
46074
|
+
if (pkg.cves.length > 0) pkg.severity = pkg.cves[0].severity;
|
|
46075
|
+
pkg.binaries.sort();
|
|
46076
|
+
}
|
|
46077
|
+
report.packages = [...bySource.values()].sort(
|
|
46078
|
+
(a, b) => RANK[b.severity] - RANK[a.severity] || b.cves.length - a.cves.length || a.source.localeCompare(b.source)
|
|
46079
|
+
);
|
|
46080
|
+
const counts = emptyCounts2();
|
|
46081
|
+
counts.packages = report.packages.length;
|
|
46082
|
+
for (const pkg of report.packages) {
|
|
46083
|
+
counts.cves += pkg.cves.length;
|
|
46084
|
+
for (const cve of pkg.cves) counts[cve.severity]++;
|
|
46085
|
+
}
|
|
46086
|
+
report.counts = counts;
|
|
46087
|
+
return report;
|
|
46088
|
+
}
|
|
46089
|
+
function worstSeverity(report) {
|
|
46090
|
+
if (report.packages.length === 0) return null;
|
|
46091
|
+
return report.packages.reduce((w, p) => RANK[p.severity] > RANK[w] ? p.severity : w, "info");
|
|
46092
|
+
}
|
|
46093
|
+
var MAX_DETAIL_PACKAGES = 30;
|
|
46094
|
+
function patchFinding(report) {
|
|
46095
|
+
const details = {
|
|
46096
|
+
kind: "os-patches",
|
|
46097
|
+
supported: report.supported,
|
|
46098
|
+
os: report.os,
|
|
46099
|
+
ecosystem: report.ecosystem,
|
|
46100
|
+
checked_at: report.checked_at,
|
|
46101
|
+
lists_updated_at: report.lists_updated_at,
|
|
46102
|
+
lists_stale: report.lists_stale,
|
|
46103
|
+
upgradable: report.upgradable,
|
|
46104
|
+
counts: report.counts,
|
|
46105
|
+
packages: report.packages.slice(0, MAX_DETAIL_PACKAGES).map((p) => ({
|
|
46106
|
+
source: p.source,
|
|
46107
|
+
installed: p.installed,
|
|
46108
|
+
candidate: p.candidate,
|
|
46109
|
+
severity: p.severity,
|
|
46110
|
+
binaries: p.binaries.slice(0, 10),
|
|
46111
|
+
cve_count: p.cves.length,
|
|
46112
|
+
cves: p.cves.slice(0, 10).map((c2) => c2.id)
|
|
46113
|
+
})),
|
|
46114
|
+
...report.packages.length > MAX_DETAIL_PACKAGES ? { packages_truncated: report.packages.length } : {},
|
|
46115
|
+
...report.osv_error ? { osv_error: report.osv_error } : {}
|
|
46116
|
+
};
|
|
46117
|
+
if (!report.supported) {
|
|
46118
|
+
return {
|
|
46119
|
+
key: "os-patches",
|
|
46120
|
+
status: "warn",
|
|
46121
|
+
severity: "info",
|
|
46122
|
+
title: "OS patch status unavailable",
|
|
46123
|
+
explanation: report.reason ?? "Patch status could not be checked on this system.",
|
|
46124
|
+
details
|
|
46125
|
+
};
|
|
46126
|
+
}
|
|
46127
|
+
const worst = worstSeverity(report);
|
|
46128
|
+
const staleNote = report.lists_stale ? ` Package lists were last refreshed ${report.lists_updated_at ? report.lists_updated_at.slice(0, 10) : "never"}, so newer fixes may be missing.` : "";
|
|
46129
|
+
if (!worst) {
|
|
46130
|
+
return {
|
|
46131
|
+
key: "os-patches",
|
|
46132
|
+
status: report.lists_stale ? "warn" : "pass",
|
|
46133
|
+
severity: report.lists_stale ? "low" : "high",
|
|
46134
|
+
title: report.lists_stale ? "No pending security updates (package lists stale)" : "No pending security updates",
|
|
46135
|
+
explanation: `apt has no security updates waiting.${staleNote}`,
|
|
46136
|
+
recommendation: report.lists_stale ? "Run `sudo apt-get update` (or enable unattended-upgrades) so fixes are seen." : void 0,
|
|
46137
|
+
details
|
|
46138
|
+
};
|
|
46139
|
+
}
|
|
46140
|
+
const c = report.counts;
|
|
46141
|
+
const parts = [c.critical && `${c.critical} critical`, c.high && `${c.high} high`].filter(Boolean);
|
|
46142
|
+
const cveText = c.cves > 0 ? `${c.cves} CVE${c.cves === 1 ? "" : "s"}${parts.length ? ` (${parts.join(", ")})` : ""}` : "unnamed advisories";
|
|
46143
|
+
const top = report.packages.slice(0, 5).map((p) => `${p.source} ${p.installed} \u2192 ${p.candidate}`).join("; ");
|
|
46144
|
+
return {
|
|
46145
|
+
key: "os-patches",
|
|
46146
|
+
status: worst === "critical" || worst === "high" ? "fail" : "warn",
|
|
46147
|
+
severity: worst,
|
|
46148
|
+
title: `${c.packages} package${c.packages === 1 ? "" : "s"} with security fixes available: ${cveText}`,
|
|
46149
|
+
explanation: `Security updates are waiting for ${c.packages} source package${c.packages === 1 ? "" : "s"}: ${top}${report.packages.length > 5 ? "; \u2026" : ""}.${staleNote}`,
|
|
46150
|
+
recommendation: "Apply them: `sudo apt-get update && sudo apt-get upgrade`, then restart affected services (or reboot for a kernel or libc update).",
|
|
46151
|
+
details
|
|
46152
|
+
};
|
|
46153
|
+
}
|
|
46154
|
+
|
|
46155
|
+
// src/commands/patches.ts
|
|
46156
|
+
var SEVERITY_COLOR = {
|
|
46157
|
+
critical: source_default.red.bold,
|
|
46158
|
+
high: source_default.red,
|
|
46159
|
+
medium: source_default.yellow,
|
|
46160
|
+
low: source_default.cyan,
|
|
46161
|
+
info: source_default.gray
|
|
46162
|
+
};
|
|
46163
|
+
async function patchesCommand(opts) {
|
|
46164
|
+
if (!opts.json) {
|
|
46165
|
+
banner();
|
|
46166
|
+
logger.info("Checking OS packages for pending security updates...\n");
|
|
46167
|
+
}
|
|
46168
|
+
const spinner = opts.json ? null : ora({ text: "Asking apt and OSV...", color: "green" }).start();
|
|
46169
|
+
const report = await checkPatches();
|
|
46170
|
+
const finding = patchFinding(report);
|
|
46171
|
+
if (opts.json) {
|
|
46172
|
+
console.log(JSON.stringify({ report, finding }, null, 2));
|
|
46173
|
+
if (opts.upload !== false) await uploadFindings([finding], true);
|
|
46174
|
+
return;
|
|
46175
|
+
}
|
|
46176
|
+
if (!report.supported) {
|
|
46177
|
+
spinner?.warn(report.reason ?? "Patch status unavailable on this system\n");
|
|
46178
|
+
console.log();
|
|
46179
|
+
return;
|
|
46180
|
+
}
|
|
46181
|
+
spinner?.succeed("Patch check complete\n");
|
|
46182
|
+
console.log(` ${source_default.white.bold("System:")} ${report.os} ${source_default.gray(`(${report.ecosystem})`)}`);
|
|
46183
|
+
const listsAge = report.lists_updated_at ? report.lists_updated_at.replace("T", " ").slice(0, 16) + " UTC" : "unknown";
|
|
46184
|
+
console.log(` ${source_default.white.bold("Package lists:")} ${report.lists_stale ? source_default.yellow(`${listsAge} (stale; run sudo apt-get update)`) : listsAge}`);
|
|
46185
|
+
console.log(` ${source_default.white.bold("Upgradable:")} ${report.upgradable} package(s), ${report.counts.packages} with security fixes`);
|
|
46186
|
+
console.log(source_default.gray(" " + "\u2500".repeat(60)));
|
|
46187
|
+
console.log();
|
|
46188
|
+
if (report.packages.length === 0) {
|
|
46189
|
+
console.log(` ${source_default.green("\u2713")} No security updates waiting.
|
|
46190
|
+
`);
|
|
46191
|
+
} else {
|
|
46192
|
+
for (const p of report.packages) {
|
|
46193
|
+
const sev = SEVERITY_COLOR[p.severity](p.severity.toUpperCase().padEnd(8));
|
|
46194
|
+
console.log(` ${sev} ${source_default.white.bold(p.source)} ${source_default.gray(p.installed)} \u2192 ${source_default.green(p.candidate)}`);
|
|
46195
|
+
if (p.cves.length > 0) {
|
|
46196
|
+
const shown = p.cves.slice(0, 6).map((c2) => SEVERITY_COLOR[c2.severity](c2.id)).join(" ");
|
|
46197
|
+
console.log(` ${shown}${p.cves.length > 6 ? source_default.gray(` +${p.cves.length - 6} more`) : ""}`);
|
|
46198
|
+
} else {
|
|
46199
|
+
console.log(source_default.gray(" security update; no matching advisory in OSV"));
|
|
46200
|
+
}
|
|
46201
|
+
if (p.binaries.length > 1 || p.binaries[0] !== p.source) {
|
|
46202
|
+
console.log(source_default.gray(` packages: ${p.binaries.join(", ")}`));
|
|
46203
|
+
}
|
|
46204
|
+
}
|
|
46205
|
+
console.log();
|
|
46206
|
+
const c = report.counts;
|
|
46207
|
+
console.log(source_default.gray(" " + "\u2500".repeat(60)));
|
|
46208
|
+
console.log(` ${source_default.white.bold(`${c.cves} CVE(s) fixed by pending updates:`)} ${source_default.red(`${c.critical} critical`)} ${source_default.red(`${c.high} high`)} ${source_default.yellow(`${c.medium} medium`)} ${source_default.cyan(`${c.low} low`)}`);
|
|
46209
|
+
if (finding.recommendation) console.log(` ${source_default.yellow("Fix:")} ${finding.recommendation}`);
|
|
46210
|
+
console.log();
|
|
46211
|
+
}
|
|
46212
|
+
if (report.osv_error) console.log(source_default.yellow(` ! CVE lookup incomplete: ${report.osv_error}
|
|
46213
|
+
`));
|
|
46214
|
+
if (opts.upload !== false) await uploadFindings([finding], false);
|
|
46215
|
+
}
|
|
46216
|
+
|
|
45544
46217
|
// src/commands/firewall.ts
|
|
45545
46218
|
init_ipc_client();
|
|
45546
46219
|
init_paths();
|
|
@@ -45685,11 +46358,11 @@ async function allowlistCommand(opts) {
|
|
|
45685
46358
|
init_paths();
|
|
45686
46359
|
|
|
45687
46360
|
// src/upgrade.ts
|
|
45688
|
-
var
|
|
46361
|
+
var import_node_child_process17 = require("child_process");
|
|
45689
46362
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
45690
46363
|
var defaultRunner = (cmd) => {
|
|
45691
46364
|
try {
|
|
45692
|
-
return (0,
|
|
46365
|
+
return (0, import_node_child_process17.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45693
46366
|
} catch {
|
|
45694
46367
|
return null;
|
|
45695
46368
|
}
|
|
@@ -45802,27 +46475,27 @@ ${source_default.green(" \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u25
|
|
|
45802
46475
|
${source_default.dim(" C R U S H")}
|
|
45803
46476
|
`;
|
|
45804
46477
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
45805
|
-
var
|
|
46478
|
+
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
45806
46479
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
45807
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
46480
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
|
|
45808
46481
|
function detectPackageManager() {
|
|
45809
46482
|
try {
|
|
45810
|
-
const npmGlobal = (0,
|
|
45811
|
-
if (npmGlobal.includes(
|
|
46483
|
+
const npmGlobal = (0, import_node_child_process18.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
46484
|
+
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
45812
46485
|
} catch {
|
|
45813
46486
|
}
|
|
45814
46487
|
try {
|
|
45815
|
-
(0,
|
|
46488
|
+
(0, import_node_child_process18.execSync)("pnpm --version", { stdio: "pipe" });
|
|
45816
46489
|
return "pnpm";
|
|
45817
46490
|
} catch {
|
|
45818
46491
|
}
|
|
45819
46492
|
try {
|
|
45820
|
-
(0,
|
|
46493
|
+
(0, import_node_child_process18.execSync)("yarn --version", { stdio: "pipe" });
|
|
45821
46494
|
return "yarn";
|
|
45822
46495
|
} catch {
|
|
45823
46496
|
}
|
|
45824
46497
|
try {
|
|
45825
|
-
(0,
|
|
46498
|
+
(0, import_node_child_process18.execSync)("bun --version", { stdio: "pipe" });
|
|
45826
46499
|
return "bun";
|
|
45827
46500
|
} catch {
|
|
45828
46501
|
}
|
|
@@ -45830,14 +46503,14 @@ function detectPackageManager() {
|
|
|
45830
46503
|
}
|
|
45831
46504
|
function readInstallConfig() {
|
|
45832
46505
|
try {
|
|
45833
|
-
return JSON.parse((0,
|
|
46506
|
+
return JSON.parse((0, import_node_fs43.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
45834
46507
|
} catch {
|
|
45835
46508
|
return {};
|
|
45836
46509
|
}
|
|
45837
46510
|
}
|
|
45838
46511
|
function packageLooksInstalled(pm, pkgName) {
|
|
45839
46512
|
try {
|
|
45840
|
-
const output = (0,
|
|
46513
|
+
const output = (0, import_node_child_process18.execSync)(globalListCommand(pm, pkgName), {
|
|
45841
46514
|
encoding: "utf-8",
|
|
45842
46515
|
stdio: ["pipe", "pipe", "pipe"]
|
|
45843
46516
|
});
|
|
@@ -45853,7 +46526,7 @@ function upgradeCommands(pkgName) {
|
|
|
45853
46526
|
}
|
|
45854
46527
|
async function reportIfStillStale() {
|
|
45855
46528
|
const warning = shadowedUpdateWarning(
|
|
45856
|
-
await latestPublishedVersion(
|
|
46529
|
+
await latestPublishedVersion(PKG_NAME2),
|
|
45857
46530
|
activeCliVersion(),
|
|
45858
46531
|
activeCliPath()
|
|
45859
46532
|
);
|
|
@@ -45940,14 +46613,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
45940
46613
|
function restartSystemdDaemon() {
|
|
45941
46614
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
45942
46615
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
45943
|
-
if (!asRoot && (0,
|
|
46616
|
+
if (!asRoot && (0, import_node_child_process18.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
45944
46617
|
const [cmd, ...args] = argv;
|
|
45945
|
-
if ((0,
|
|
45946
|
-
return (0,
|
|
46618
|
+
if ((0, import_node_child_process18.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
46619
|
+
return (0, import_node_child_process18.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
45947
46620
|
}
|
|
45948
46621
|
function execQuiet(cmd) {
|
|
45949
46622
|
try {
|
|
45950
|
-
return (0,
|
|
46623
|
+
return (0, import_node_child_process18.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45951
46624
|
} catch {
|
|
45952
46625
|
return null;
|
|
45953
46626
|
}
|
|
@@ -46097,6 +46770,9 @@ program2.command("rules").description("Manage detection rules").argument("[actio
|
|
|
46097
46770
|
program2.command("harden").description("Run hardening security scan").option("--json", "Output results as JSON").option("--no-upload", "Do not upload findings to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
|
|
46098
46771
|
await hardenCommand(opts);
|
|
46099
46772
|
});
|
|
46773
|
+
program2.command("patches").description("List OS packages with a security update waiting, and the CVEs it fixes (Debian/Ubuntu)").option("--json", "Output the report as JSON").option("--no-upload", "Do not upload the result to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
|
|
46774
|
+
await patchesCommand(opts);
|
|
46775
|
+
});
|
|
46100
46776
|
program2.command("block").description("Block an IP address via the firewall").argument("<ip>", "IP address to block").option("--ttl <duration>", "Block duration (e.g. 1h, 30m, 1d)").action(async (ip, opts) => {
|
|
46101
46777
|
await blockCommand(ip, opts);
|
|
46102
46778
|
});
|
|
@@ -46133,7 +46809,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
46133
46809
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
46134
46810
|
console.log(LOGO2);
|
|
46135
46811
|
const logPath = PATHS.logFile;
|
|
46136
|
-
if (!(0,
|
|
46812
|
+
if (!(0, import_node_fs43.existsSync)(logPath)) {
|
|
46137
46813
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
46138
46814
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
46139
46815
|
return;
|
|
@@ -46141,19 +46817,19 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
46141
46817
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
46142
46818
|
`));
|
|
46143
46819
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
46144
|
-
(0,
|
|
46820
|
+
(0, import_node_child_process18.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
46145
46821
|
});
|
|
46146
46822
|
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) => {
|
|
46147
46823
|
console.log(LOGO2);
|
|
46148
46824
|
if (opts.modules) {
|
|
46149
46825
|
console.log(LOGO2);
|
|
46150
46826
|
console.log(source_default.yellow(" Updating modules...\n"));
|
|
46151
|
-
const commands2 = upgradeCommands(
|
|
46827
|
+
const commands2 = upgradeCommands(PKG_NAME2);
|
|
46152
46828
|
try {
|
|
46153
46829
|
for (const cmd of commands2) {
|
|
46154
46830
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46155
46831
|
`));
|
|
46156
|
-
(0,
|
|
46832
|
+
(0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
|
|
46157
46833
|
}
|
|
46158
46834
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
46159
46835
|
await reportIfStillStale();
|
|
@@ -46166,19 +46842,19 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
46166
46842
|
}
|
|
46167
46843
|
return;
|
|
46168
46844
|
}
|
|
46169
|
-
const holders = globalHolders(
|
|
46845
|
+
const holders = globalHolders(PKG_NAME2);
|
|
46170
46846
|
const installConfig = readInstallConfig();
|
|
46171
46847
|
const installMode = opts.cli ? "server" : opts.desktop ? "desktop" : installConfig.installMode || "server";
|
|
46172
46848
|
console.log(source_default.dim(` Detected package manager: ${holders.join(", ") || detectPackageManager()}`));
|
|
46173
46849
|
console.log(source_default.dim(` Install mode: ${installMode}`));
|
|
46174
46850
|
console.log(source_default.dim(` Current version: ${PKG_VERSION}
|
|
46175
46851
|
`));
|
|
46176
|
-
const commands = upgradeCommands(
|
|
46852
|
+
const commands = upgradeCommands(PKG_NAME2);
|
|
46177
46853
|
try {
|
|
46178
46854
|
for (const cmd of commands) {
|
|
46179
46855
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46180
46856
|
`));
|
|
46181
|
-
(0,
|
|
46857
|
+
(0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
|
|
46182
46858
|
}
|
|
46183
46859
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
46184
46860
|
if (installMode === "desktop") {
|
|
@@ -46213,9 +46889,9 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
46213
46889
|
}
|
|
46214
46890
|
const installConfig = readInstallConfig();
|
|
46215
46891
|
const installMode = installConfig.installMode || "server";
|
|
46216
|
-
const holders = globalHolders(
|
|
46892
|
+
const holders = globalHolders(PKG_NAME2);
|
|
46217
46893
|
const pms = holders.length > 0 ? holders : [detectPackageManager()];
|
|
46218
|
-
const commands = pms.map((pm) => globalInstallCommand(pm,
|
|
46894
|
+
const commands = pms.map((pm) => globalInstallCommand(pm, PKG_NAME2, "remove"));
|
|
46219
46895
|
for (const pm of pms) {
|
|
46220
46896
|
if (installMode === "desktop" && packageLooksInstalled(pm, DESKTOP_PKG_NAME)) {
|
|
46221
46897
|
commands.push(globalInstallCommand(pm, DESKTOP_PKG_NAME, "remove"));
|
|
@@ -46229,7 +46905,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
46229
46905
|
for (const cmd of commands) {
|
|
46230
46906
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46231
46907
|
`));
|
|
46232
|
-
(0,
|
|
46908
|
+
(0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
|
|
46233
46909
|
}
|
|
46234
46910
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
46235
46911
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -46306,10 +46982,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
46306
46982
|
});
|
|
46307
46983
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
46308
46984
|
console.log(LOGO2);
|
|
46309
|
-
const configPath = (0,
|
|
46985
|
+
const configPath = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
|
|
46310
46986
|
let email = "";
|
|
46311
46987
|
try {
|
|
46312
|
-
const config = JSON.parse((0,
|
|
46988
|
+
const config = JSON.parse((0, import_node_fs43.readFileSync)(configPath, "utf-8"));
|
|
46313
46989
|
email = config.email || "";
|
|
46314
46990
|
} catch {
|
|
46315
46991
|
}
|
|
@@ -46326,9 +47002,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
46326
47002
|
return;
|
|
46327
47003
|
}
|
|
46328
47004
|
try {
|
|
46329
|
-
const dir = (0,
|
|
46330
|
-
if (!(0,
|
|
46331
|
-
(0,
|
|
47005
|
+
const dir = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush");
|
|
47006
|
+
if (!(0, import_node_fs43.existsSync)(dir)) (0, import_node_fs43.mkdirSync)(dir, { recursive: true });
|
|
47007
|
+
(0, import_node_fs43.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
46332
47008
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
46333
47009
|
} catch {
|
|
46334
47010
|
}
|