@profullstack/threatcrush 0.13.22 → 0.13.24
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/dist/daemon.js +66 -22
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +539 -413
- package/dist/index.js.map +1 -1
- package/dist/systemd/threatcrushd.service +7 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13920,6 +13920,91 @@ var init_demo = __esm({
|
|
|
13920
13920
|
}
|
|
13921
13921
|
});
|
|
13922
13922
|
|
|
13923
|
+
// src/tui/clipboard.ts
|
|
13924
|
+
function nativeHelpers(env2, platform) {
|
|
13925
|
+
const overSsh = !!(env2.SSH_CONNECTION || env2.SSH_TTY);
|
|
13926
|
+
const helpers = [];
|
|
13927
|
+
if (platform === "darwin" && !overSsh) helpers.push(["pbcopy", []]);
|
|
13928
|
+
if (env2.WAYLAND_DISPLAY) helpers.push(["wl-copy", []]);
|
|
13929
|
+
if (env2.DISPLAY) {
|
|
13930
|
+
helpers.push(["xclip", ["-selection", "clipboard"]]);
|
|
13931
|
+
helpers.push(["xsel", ["--clipboard", "--input"]]);
|
|
13932
|
+
}
|
|
13933
|
+
return helpers;
|
|
13934
|
+
}
|
|
13935
|
+
function copyToClipboard(text, deps = defaultDeps()) {
|
|
13936
|
+
const via = [];
|
|
13937
|
+
const { env: env2 } = deps;
|
|
13938
|
+
for (const [cmd, args] of nativeHelpers(env2, deps.platform)) {
|
|
13939
|
+
if (deps.run(cmd, args, text)) {
|
|
13940
|
+
via.push(cmd);
|
|
13941
|
+
break;
|
|
13942
|
+
}
|
|
13943
|
+
}
|
|
13944
|
+
if (env2.TMUX) {
|
|
13945
|
+
if (deps.run("tmux", ["load-buffer", "-w", "-"], text) || deps.run("tmux", ["load-buffer", "-"], text)) {
|
|
13946
|
+
via.push("tmux");
|
|
13947
|
+
}
|
|
13948
|
+
}
|
|
13949
|
+
try {
|
|
13950
|
+
deps.write(clipboardSequence(text));
|
|
13951
|
+
if (env2.TMUX) deps.write(clipboardSequence(text, true));
|
|
13952
|
+
via.push("osc52");
|
|
13953
|
+
} catch {
|
|
13954
|
+
}
|
|
13955
|
+
let file;
|
|
13956
|
+
try {
|
|
13957
|
+
const path = (0, import_node_path6.join)(deps.fileDir, "last-copy.txt");
|
|
13958
|
+
deps.saveFile(path, text.endsWith("\n") ? text : `${text}
|
|
13959
|
+
`);
|
|
13960
|
+
file = path;
|
|
13961
|
+
} catch {
|
|
13962
|
+
}
|
|
13963
|
+
return { via, file };
|
|
13964
|
+
}
|
|
13965
|
+
function describeCopy(result, home = (0, import_node_os3.homedir)()) {
|
|
13966
|
+
const file = result.file ? result.file.replace(home, "~") : null;
|
|
13967
|
+
const native = result.via.filter((v) => v !== "osc52");
|
|
13968
|
+
if (native.length > 0) {
|
|
13969
|
+
return `copied (${result.via.join(" + ")})${file ? ` \xB7 also ${file}` : ""}`;
|
|
13970
|
+
}
|
|
13971
|
+
if (result.via.includes("osc52")) {
|
|
13972
|
+
return `sent to terminal clipboard (OSC 52; iTerm2: allow clipboard access)${file ? ` \xB7 saved ${file}` : ""}`;
|
|
13973
|
+
}
|
|
13974
|
+
return file ? `could not reach a clipboard \xB7 saved ${file}` : "copy failed: no clipboard available";
|
|
13975
|
+
}
|
|
13976
|
+
var import_node_child_process, import_node_fs8, import_node_os3, import_node_path6, defaultDeps;
|
|
13977
|
+
var init_clipboard = __esm({
|
|
13978
|
+
"src/tui/clipboard.ts"() {
|
|
13979
|
+
"use strict";
|
|
13980
|
+
import_node_child_process = require("child_process");
|
|
13981
|
+
import_node_fs8 = require("fs");
|
|
13982
|
+
import_node_os3 = require("os");
|
|
13983
|
+
import_node_path6 = require("path");
|
|
13984
|
+
init_dist();
|
|
13985
|
+
defaultDeps = () => ({
|
|
13986
|
+
env: process.env,
|
|
13987
|
+
platform: process.platform,
|
|
13988
|
+
run: (cmd, args, input) => {
|
|
13989
|
+
try {
|
|
13990
|
+
const r = (0, import_node_child_process.spawnSync)(cmd, args, { input, stdio: ["pipe", "ignore", "ignore"], timeout: 1500 });
|
|
13991
|
+
return !r.error && r.status === 0;
|
|
13992
|
+
} catch {
|
|
13993
|
+
return false;
|
|
13994
|
+
}
|
|
13995
|
+
},
|
|
13996
|
+
write: (data) => {
|
|
13997
|
+
process.stdout.write(data);
|
|
13998
|
+
},
|
|
13999
|
+
saveFile: (path, text) => {
|
|
14000
|
+
(0, import_node_fs8.mkdirSync)((0, import_node_path6.dirname)(path), { recursive: true });
|
|
14001
|
+
(0, import_node_fs8.writeFileSync)(path, text, { mode: 384 });
|
|
14002
|
+
},
|
|
14003
|
+
fileDir: (0, import_node_path6.join)((0, import_node_os3.homedir)(), ".threatcrush")
|
|
14004
|
+
});
|
|
14005
|
+
}
|
|
14006
|
+
});
|
|
14007
|
+
|
|
13923
14008
|
// src/tui/dashboard.ts
|
|
13924
14009
|
var dashboard_exports = {};
|
|
13925
14010
|
__export(dashboard_exports, {
|
|
@@ -13941,12 +14026,8 @@ async function startDashboard(options = {}) {
|
|
|
13941
14026
|
};
|
|
13942
14027
|
const copyText = (text) => {
|
|
13943
14028
|
if (!text) return;
|
|
13944
|
-
|
|
13945
|
-
|
|
13946
|
-
dispatch({ type: "notice", text: `copied to clipboard: ${text.length > 60 ? `${text.slice(0, 57)}...` : text}`, tone: "ok" });
|
|
13947
|
-
} catch (err) {
|
|
13948
|
-
dispatch({ type: "notice", text: `copy failed: ${err.message}`, tone: "error" });
|
|
13949
|
-
}
|
|
14029
|
+
const result = copyToClipboard(text);
|
|
14030
|
+
dispatch({ type: "notice", text: describeCopy(result), tone: result.via.length > 0 || result.file ? "ok" : "error" });
|
|
13950
14031
|
};
|
|
13951
14032
|
let client = null;
|
|
13952
14033
|
let stopped = false;
|
|
@@ -14207,6 +14288,7 @@ var init_dashboard = __esm({
|
|
|
14207
14288
|
init_theme2();
|
|
14208
14289
|
init_view();
|
|
14209
14290
|
init_demo();
|
|
14291
|
+
init_clipboard();
|
|
14210
14292
|
RECONNECT_MS = 2e3;
|
|
14211
14293
|
POLL_MS = 2e3;
|
|
14212
14294
|
}
|
|
@@ -16371,13 +16453,13 @@ var source_default = chalk;
|
|
|
16371
16453
|
|
|
16372
16454
|
// src/index.ts
|
|
16373
16455
|
var import_readline = __toESM(require("readline"));
|
|
16374
|
-
var
|
|
16375
|
-
var
|
|
16376
|
-
var
|
|
16377
|
-
var
|
|
16456
|
+
var import_node_child_process16 = require("child_process");
|
|
16457
|
+
var import_node_fs41 = require("fs");
|
|
16458
|
+
var import_node_path28 = require("path");
|
|
16459
|
+
var import_node_os12 = require("os");
|
|
16378
16460
|
|
|
16379
16461
|
// src/commands/monitor.ts
|
|
16380
|
-
var
|
|
16462
|
+
var import_node_fs9 = require("fs");
|
|
16381
16463
|
|
|
16382
16464
|
// src/core/log-tail.ts
|
|
16383
16465
|
var import_node_fs = require("fs");
|
|
@@ -23504,9 +23586,9 @@ async function monitorCommand(options) {
|
|
|
23504
23586
|
const unreadable = [];
|
|
23505
23587
|
for (const s of LOG_SOURCES) {
|
|
23506
23588
|
if (moduleFilter && !moduleFilter.includes(s.name)) continue;
|
|
23507
|
-
if (!(0,
|
|
23589
|
+
if (!(0, import_node_fs9.existsSync)(s.path)) continue;
|
|
23508
23590
|
try {
|
|
23509
|
-
(0,
|
|
23591
|
+
(0, import_node_fs9.accessSync)(s.path, import_node_fs9.constants.R_OK);
|
|
23510
23592
|
availableSources.push(s);
|
|
23511
23593
|
} catch {
|
|
23512
23594
|
unreadable.push(s);
|
|
@@ -23523,11 +23605,11 @@ async function monitorCommand(options) {
|
|
|
23523
23605
|
logger.warn("No readable log files found to monitor.");
|
|
23524
23606
|
logger.info("Available log paths checked:");
|
|
23525
23607
|
for (const s of LOG_SOURCES) {
|
|
23526
|
-
const exists = (0,
|
|
23608
|
+
const exists = (0, import_node_fs9.existsSync)(s.path);
|
|
23527
23609
|
let readable = false;
|
|
23528
23610
|
if (exists) {
|
|
23529
23611
|
try {
|
|
23530
|
-
(0,
|
|
23612
|
+
(0, import_node_fs9.accessSync)(s.path, import_node_fs9.constants.R_OK);
|
|
23531
23613
|
readable = true;
|
|
23532
23614
|
} catch {
|
|
23533
23615
|
readable = false;
|
|
@@ -23669,14 +23751,14 @@ async function runDemoMode() {
|
|
|
23669
23751
|
}
|
|
23670
23752
|
|
|
23671
23753
|
// src/commands/watchdog.ts
|
|
23672
|
-
var
|
|
23673
|
-
var
|
|
23754
|
+
var import_node_fs11 = require("fs");
|
|
23755
|
+
var import_node_path8 = require("path");
|
|
23674
23756
|
init_paths();
|
|
23675
23757
|
|
|
23676
23758
|
// src/core/watchdog.ts
|
|
23677
|
-
var
|
|
23759
|
+
var import_node_fs10 = require("fs");
|
|
23678
23760
|
var import_node_crypto2 = require("crypto");
|
|
23679
|
-
var
|
|
23761
|
+
var import_node_path7 = require("path");
|
|
23680
23762
|
var WATCHDOG_DIRNAME = "watchdog";
|
|
23681
23763
|
var LOG_FILE = "attacks.jsonl";
|
|
23682
23764
|
var ROTATED_FILE = "attacks.1.jsonl";
|
|
@@ -23761,7 +23843,7 @@ function dedupeKey(r) {
|
|
|
23761
23843
|
}
|
|
23762
23844
|
function isShared(dir) {
|
|
23763
23845
|
try {
|
|
23764
|
-
return ((0,
|
|
23846
|
+
return ((0, import_node_fs10.statSync)(dir).mode & 1024) !== 0;
|
|
23765
23847
|
} catch {
|
|
23766
23848
|
return false;
|
|
23767
23849
|
}
|
|
@@ -23775,12 +23857,12 @@ var WatchdogLog = class {
|
|
|
23775
23857
|
stats = { logged: 0, answered: 0, errored: 0 };
|
|
23776
23858
|
constructor(dir, options = {}) {
|
|
23777
23859
|
this.dir = dir;
|
|
23778
|
-
this.file = (0,
|
|
23860
|
+
this.file = (0, import_node_path7.join)(dir, LOG_FILE);
|
|
23779
23861
|
this.shareGid = options.shareGid;
|
|
23780
|
-
(0,
|
|
23862
|
+
(0, import_node_fs10.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
|
|
23781
23863
|
if (this.shareGid !== void 0) {
|
|
23782
|
-
(0,
|
|
23783
|
-
(0,
|
|
23864
|
+
(0, import_node_fs10.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
|
|
23865
|
+
(0, import_node_fs10.chmodSync)(dir, 1528);
|
|
23784
23866
|
}
|
|
23785
23867
|
for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
|
|
23786
23868
|
}
|
|
@@ -23809,16 +23891,16 @@ var WatchdogLog = class {
|
|
|
23809
23891
|
const chunk = this.buffer.join("\n") + "\n";
|
|
23810
23892
|
this.buffer = [];
|
|
23811
23893
|
try {
|
|
23812
|
-
if ((0,
|
|
23813
|
-
(0,
|
|
23894
|
+
if ((0, import_node_fs10.statSync)(this.file).size > ROTATE_BYTES) {
|
|
23895
|
+
(0, import_node_fs10.renameSync)(this.file, (0, import_node_path7.join)(this.dir, ROTATED_FILE));
|
|
23814
23896
|
}
|
|
23815
23897
|
} catch {
|
|
23816
23898
|
}
|
|
23817
|
-
(0,
|
|
23899
|
+
(0, import_node_fs10.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
|
|
23818
23900
|
if (this.shareGid !== void 0) {
|
|
23819
23901
|
try {
|
|
23820
|
-
(0,
|
|
23821
|
-
(0,
|
|
23902
|
+
(0, import_node_fs10.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
|
|
23903
|
+
(0, import_node_fs10.chmodSync)(this.file, 432);
|
|
23822
23904
|
} catch {
|
|
23823
23905
|
}
|
|
23824
23906
|
}
|
|
@@ -23839,50 +23921,50 @@ function parseLines(text) {
|
|
|
23839
23921
|
function readTail(file, bytes) {
|
|
23840
23922
|
let fd;
|
|
23841
23923
|
try {
|
|
23842
|
-
fd = (0,
|
|
23924
|
+
fd = (0, import_node_fs10.openSync)(file, "r");
|
|
23843
23925
|
} catch (err) {
|
|
23844
23926
|
if (err.code === "ENOENT") return [];
|
|
23845
23927
|
throw err;
|
|
23846
23928
|
}
|
|
23847
23929
|
try {
|
|
23848
|
-
const size = (0,
|
|
23930
|
+
const size = (0, import_node_fs10.fstatSync)(fd).size;
|
|
23849
23931
|
const start = Math.max(0, size - bytes);
|
|
23850
23932
|
const buf = Buffer.alloc(size - start);
|
|
23851
|
-
(0,
|
|
23933
|
+
(0, import_node_fs10.readSync)(fd, buf, 0, buf.length, start);
|
|
23852
23934
|
let text = buf.toString("utf8");
|
|
23853
23935
|
if (start > 0) text = text.slice(text.indexOf("\n") + 1);
|
|
23854
23936
|
return parseLines(text);
|
|
23855
23937
|
} finally {
|
|
23856
|
-
(0,
|
|
23938
|
+
(0, import_node_fs10.closeSync)(fd);
|
|
23857
23939
|
}
|
|
23858
23940
|
}
|
|
23859
23941
|
function readAttacks(dir) {
|
|
23860
23942
|
const out = [];
|
|
23861
23943
|
for (const name of [ROTATED_FILE, LOG_FILE]) {
|
|
23862
|
-
const file = (0,
|
|
23863
|
-
if ((0,
|
|
23944
|
+
const file = (0, import_node_path7.join)(dir, name);
|
|
23945
|
+
if ((0, import_node_fs10.existsSync)(file)) out.push(...parseLines((0, import_node_fs10.readFileSync)(file, "utf8")));
|
|
23864
23946
|
}
|
|
23865
23947
|
return out;
|
|
23866
23948
|
}
|
|
23867
23949
|
function readTriage(dir) {
|
|
23868
|
-
const file = (0,
|
|
23869
|
-
if (!(0,
|
|
23950
|
+
const file = (0, import_node_path7.join)(dir, TRIAGE_FILE);
|
|
23951
|
+
if (!(0, import_node_fs10.existsSync)(file)) return {};
|
|
23870
23952
|
try {
|
|
23871
|
-
return JSON.parse((0,
|
|
23953
|
+
return JSON.parse((0, import_node_fs10.readFileSync)(file, "utf8"));
|
|
23872
23954
|
} catch {
|
|
23873
23955
|
return {};
|
|
23874
23956
|
}
|
|
23875
23957
|
}
|
|
23876
23958
|
function writeTriage(dir, map) {
|
|
23877
|
-
(0,
|
|
23878
|
-
const file = (0,
|
|
23959
|
+
(0, import_node_fs10.mkdirSync)(dir, { recursive: true });
|
|
23960
|
+
const file = (0, import_node_path7.join)(dir, TRIAGE_FILE);
|
|
23879
23961
|
const mode = isShared(dir) ? 432 : 384;
|
|
23880
|
-
(0,
|
|
23962
|
+
(0, import_node_fs10.writeFileSync)(`${file}.tmp`, JSON.stringify(map, null, 2) + "\n", { mode });
|
|
23881
23963
|
try {
|
|
23882
|
-
(0,
|
|
23964
|
+
(0, import_node_fs10.chmodSync)(`${file}.tmp`, mode);
|
|
23883
23965
|
} catch {
|
|
23884
23966
|
}
|
|
23885
|
-
(0,
|
|
23967
|
+
(0, import_node_fs10.renameSync)(`${file}.tmp`, file);
|
|
23886
23968
|
}
|
|
23887
23969
|
function setTriage(dir, id, update, now = /* @__PURE__ */ new Date()) {
|
|
23888
23970
|
const map = readTriage(dir);
|
|
@@ -24025,9 +24107,9 @@ function outcomeExplainer(o) {
|
|
|
24025
24107
|
function resolveWatchdogDir(dir) {
|
|
24026
24108
|
if (dir) return dir;
|
|
24027
24109
|
if (process.env.THREATCRUSH_WATCHDOG_DIR) return process.env.THREATCRUSH_WATCHDOG_DIR;
|
|
24028
|
-
const system = (0,
|
|
24029
|
-
if ((0,
|
|
24030
|
-
return (0,
|
|
24110
|
+
const system = (0, import_node_path8.join)("/var/lib/threatcrush", WATCHDOG_DIRNAME);
|
|
24111
|
+
if ((0, import_node_fs11.existsSync)(system)) return system;
|
|
24112
|
+
return (0, import_node_path8.join)(PATHS.stateDir, WATCHDOG_DIRNAME);
|
|
24031
24113
|
}
|
|
24032
24114
|
function load(dir) {
|
|
24033
24115
|
return groupFindings(readAttacks(dir), readTriage(dir));
|
|
@@ -24063,7 +24145,7 @@ function watchdogListCommand(opts) {
|
|
|
24063
24145
|
return;
|
|
24064
24146
|
}
|
|
24065
24147
|
if (findings.length === 0) {
|
|
24066
|
-
const empty = (0,
|
|
24148
|
+
const empty = (0, import_node_fs11.existsSync)((0, import_node_path8.join)(dir, "attacks.jsonl")) ? "Nothing to triage." + (opts.all ? "" : " (refused and triaged findings hidden; --all shows them)") : `No watchdog log at ${dir}. The daemon writes it: threatcrush start (or upgrade + restart an older daemon).`;
|
|
24067
24149
|
console.log(source_default.dim(empty));
|
|
24068
24150
|
return;
|
|
24069
24151
|
}
|
|
@@ -24130,8 +24212,8 @@ function watchdogPathCommand(opts) {
|
|
|
24130
24212
|
}
|
|
24131
24213
|
|
|
24132
24214
|
// src/commands/scan.ts
|
|
24133
|
-
var
|
|
24134
|
-
var
|
|
24215
|
+
var import_node_fs14 = require("fs");
|
|
24216
|
+
var import_node_path12 = require("path");
|
|
24135
24217
|
|
|
24136
24218
|
// ../../node_modules/.pnpm/ora@8.2.0/node_modules/ora/index.js
|
|
24137
24219
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
@@ -25058,7 +25140,7 @@ function ora(options) {
|
|
|
25058
25140
|
}
|
|
25059
25141
|
|
|
25060
25142
|
// src/core/run-result.ts
|
|
25061
|
-
var
|
|
25143
|
+
var import_node_os4 = __toESM(require("os"));
|
|
25062
25144
|
function emptyCounts() {
|
|
25063
25145
|
return { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
25064
25146
|
}
|
|
@@ -25068,7 +25150,7 @@ function summarize(findings) {
|
|
|
25068
25150
|
return counts;
|
|
25069
25151
|
}
|
|
25070
25152
|
function workerId() {
|
|
25071
|
-
return `${
|
|
25153
|
+
return `${import_node_os4.default.hostname()}/${process.pid}`;
|
|
25072
25154
|
}
|
|
25073
25155
|
|
|
25074
25156
|
// ../../packages/scan/src/node-rules.ts
|
|
@@ -28045,8 +28127,8 @@ function meetsFailThreshold(findings, threshold) {
|
|
|
28045
28127
|
}
|
|
28046
28128
|
|
|
28047
28129
|
// ../../packages/scan/src/node/walk.ts
|
|
28048
|
-
var
|
|
28049
|
-
var
|
|
28130
|
+
var import_node_fs12 = require("fs");
|
|
28131
|
+
var import_node_path9 = require("path");
|
|
28050
28132
|
function compileExcludes(patterns) {
|
|
28051
28133
|
const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
|
|
28052
28134
|
if (matchers.length === 0) return () => false;
|
|
@@ -28117,7 +28199,7 @@ function matchPrefix(parts, segs) {
|
|
|
28117
28199
|
}
|
|
28118
28200
|
function readIgnoreFile(root) {
|
|
28119
28201
|
try {
|
|
28120
|
-
return (0,
|
|
28202
|
+
return (0, import_node_fs12.readFileSync)((0, import_node_path9.join)(root, ".threatcrushignore"), "utf-8").split("\n");
|
|
28121
28203
|
} catch {
|
|
28122
28204
|
return [];
|
|
28123
28205
|
}
|
|
@@ -28133,16 +28215,16 @@ function scanPath(targetPath, options = {}) {
|
|
|
28133
28215
|
let excluded = 0;
|
|
28134
28216
|
const rootIsDirectory = (() => {
|
|
28135
28217
|
try {
|
|
28136
|
-
return (0,
|
|
28218
|
+
return (0, import_node_fs12.statSync)(targetPath).isDirectory();
|
|
28137
28219
|
} catch {
|
|
28138
28220
|
return true;
|
|
28139
28221
|
}
|
|
28140
28222
|
})();
|
|
28141
|
-
const walkRoot = rootIsDirectory ? targetPath : (0,
|
|
28223
|
+
const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path9.dirname)(targetPath);
|
|
28142
28224
|
const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
|
|
28143
28225
|
const scanFile = (fullPath, filename) => {
|
|
28144
28226
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
28145
|
-
const extension = (0,
|
|
28227
|
+
const extension = (0, import_node_path9.extname)(filename).toLowerCase();
|
|
28146
28228
|
const isManifest = filename === "package.json" || filename === "requirements.txt";
|
|
28147
28229
|
const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
|
|
28148
28230
|
const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
|
|
@@ -28154,26 +28236,26 @@ function scanPath(targetPath, options = {}) {
|
|
|
28154
28236
|
let handle;
|
|
28155
28237
|
let declared = null;
|
|
28156
28238
|
try {
|
|
28157
|
-
handle = (0,
|
|
28239
|
+
handle = (0, import_node_fs12.openSync)(fullPath, "r");
|
|
28158
28240
|
} catch {
|
|
28159
28241
|
unreadable.push(relativePath);
|
|
28160
28242
|
return;
|
|
28161
28243
|
}
|
|
28162
28244
|
try {
|
|
28163
|
-
if ((0,
|
|
28245
|
+
if ((0, import_node_fs12.fstatSync)(handle).size > maxFileBytes) return;
|
|
28164
28246
|
if (mayDeclareInterpreter) {
|
|
28165
28247
|
const prefix = Buffer.alloc(128);
|
|
28166
|
-
const read = (0,
|
|
28248
|
+
const read = (0, import_node_fs12.readSync)(handle, prefix, 0, prefix.length, 0);
|
|
28167
28249
|
declared = languageOfShebang(prefix.subarray(0, read).toString("utf-8").split("\n", 1)[0] ?? "");
|
|
28168
28250
|
if (!declared) return;
|
|
28169
28251
|
}
|
|
28170
|
-
text = (0,
|
|
28252
|
+
text = (0, import_node_fs12.readFileSync)(handle, "utf-8");
|
|
28171
28253
|
} catch {
|
|
28172
28254
|
unreadable.push(relativePath);
|
|
28173
28255
|
return;
|
|
28174
28256
|
} finally {
|
|
28175
28257
|
try {
|
|
28176
|
-
(0,
|
|
28258
|
+
(0, import_node_fs12.closeSync)(handle);
|
|
28177
28259
|
} catch {
|
|
28178
28260
|
}
|
|
28179
28261
|
}
|
|
@@ -28191,13 +28273,13 @@ function scanPath(targetPath, options = {}) {
|
|
|
28191
28273
|
const walk = (currentPath) => {
|
|
28192
28274
|
let entries;
|
|
28193
28275
|
try {
|
|
28194
|
-
entries = (0,
|
|
28276
|
+
entries = (0, import_node_fs12.readdirSync)(currentPath, { withFileTypes: true });
|
|
28195
28277
|
} catch {
|
|
28196
28278
|
unreadable.push(toRelative(walkRoot, currentPath));
|
|
28197
28279
|
return;
|
|
28198
28280
|
}
|
|
28199
28281
|
for (const entry of entries) {
|
|
28200
|
-
const fullPath = (0,
|
|
28282
|
+
const fullPath = (0, import_node_path9.join)(currentPath, entry.name);
|
|
28201
28283
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
28202
28284
|
if (entry.isDirectory()) {
|
|
28203
28285
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
@@ -28221,7 +28303,7 @@ function scanPath(targetPath, options = {}) {
|
|
|
28221
28303
|
} else if (isExcluded(toRelative(walkRoot, targetPath))) {
|
|
28222
28304
|
excluded += 1;
|
|
28223
28305
|
} else {
|
|
28224
|
-
scanFile(targetPath, (0,
|
|
28306
|
+
scanFile(targetPath, (0, import_node_path9.basename)(targetPath));
|
|
28225
28307
|
}
|
|
28226
28308
|
if (options.missingControls) findings.push(...controls.findings());
|
|
28227
28309
|
const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
|
|
@@ -28253,22 +28335,22 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
|
|
|
28253
28335
|
}
|
|
28254
28336
|
}
|
|
28255
28337
|
function toRelative(base, target) {
|
|
28256
|
-
const rel = (0,
|
|
28257
|
-
return (rel === "" ? target : rel).split(
|
|
28338
|
+
const rel = (0, import_node_path9.relative)(base, target);
|
|
28339
|
+
return (rel === "" ? target : rel).split(import_node_path9.sep).join("/");
|
|
28258
28340
|
}
|
|
28259
28341
|
|
|
28260
28342
|
// ../../packages/scan/src/node/dependencies.ts
|
|
28261
|
-
var
|
|
28262
|
-
var
|
|
28343
|
+
var import_node_fs13 = require("fs");
|
|
28344
|
+
var import_node_path10 = require("path");
|
|
28263
28345
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
28264
28346
|
async function scanDependencies(targetPath) {
|
|
28265
28347
|
const findings = [];
|
|
28266
28348
|
for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
|
|
28267
|
-
const lockPath = (0,
|
|
28268
|
-
if (!(0,
|
|
28349
|
+
const lockPath = (0, import_node_path10.join)(targetPath, file);
|
|
28350
|
+
if (!(0, import_node_fs13.existsSync)(lockPath)) continue;
|
|
28269
28351
|
let deps;
|
|
28270
28352
|
try {
|
|
28271
|
-
deps = dedupe(parse2((0,
|
|
28353
|
+
deps = dedupe(parse2((0, import_node_fs13.readFileSync)(lockPath, "utf-8")));
|
|
28272
28354
|
} catch {
|
|
28273
28355
|
continue;
|
|
28274
28356
|
}
|
|
@@ -28483,7 +28565,7 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
28483
28565
|
|
|
28484
28566
|
// ../../packages/scan/src/node/sarif.ts
|
|
28485
28567
|
var import_node_crypto3 = require("crypto");
|
|
28486
|
-
var
|
|
28568
|
+
var import_node_path11 = require("path");
|
|
28487
28569
|
var FINGERPRINT_KEY = "threatcrush/contentHash/v1";
|
|
28488
28570
|
function fingerprintOf(finding) {
|
|
28489
28571
|
const content = finding.excerpt.replace(/\s+/g, " ").trim();
|
|
@@ -28521,11 +28603,11 @@ function securitySeverity(severity) {
|
|
|
28521
28603
|
}
|
|
28522
28604
|
}
|
|
28523
28605
|
function toArtifactUri(filePath, base, prefix = "", root = base) {
|
|
28524
|
-
const absolute = (0,
|
|
28525
|
-
const relativePath = (0,
|
|
28606
|
+
const absolute = (0, import_node_path11.isAbsolute)(filePath) ? filePath : (0, import_node_path11.resolve)(root, filePath);
|
|
28607
|
+
const relativePath = (0, import_node_path11.relative)(base, absolute);
|
|
28526
28608
|
const escapedOut = relativePath.startsWith("..") || relativePath === "";
|
|
28527
28609
|
const chosen = escapedOut ? absolute : relativePath;
|
|
28528
|
-
const posix = chosen.split(
|
|
28610
|
+
const posix = chosen.split(import_node_path11.sep).join("/").replace(/^\.\//, "");
|
|
28529
28611
|
if (!prefix || escapedOut) return posix;
|
|
28530
28612
|
const trimmed = prefix.replace(/^\/+|\/+$/g, "");
|
|
28531
28613
|
return trimmed ? `${trimmed}/${posix}` : posix;
|
|
@@ -28615,11 +28697,11 @@ ${finding.consequence}` : `**${finding.title}**`
|
|
|
28615
28697
|
// src/commands/scan.ts
|
|
28616
28698
|
function readVersion() {
|
|
28617
28699
|
for (const candidate of [
|
|
28618
|
-
(0,
|
|
28619
|
-
(0,
|
|
28700
|
+
(0, import_node_path12.join)(__dirname, "..", "package.json"),
|
|
28701
|
+
(0, import_node_path12.join)(__dirname, "..", "..", "package.json")
|
|
28620
28702
|
]) {
|
|
28621
28703
|
try {
|
|
28622
|
-
return JSON.parse((0,
|
|
28704
|
+
return JSON.parse((0, import_node_fs14.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
|
|
28623
28705
|
} catch {
|
|
28624
28706
|
}
|
|
28625
28707
|
}
|
|
@@ -28686,7 +28768,7 @@ async function scanCommand(targetPath, options = {}) {
|
|
|
28686
28768
|
const say = machineReadable ? (line) => process.stderr.write(`${line}
|
|
28687
28769
|
`) : (line) => process.stdout.write(`${line}
|
|
28688
28770
|
`);
|
|
28689
|
-
if (!(0,
|
|
28771
|
+
if (!(0, import_node_fs14.existsSync)(targetPath)) {
|
|
28690
28772
|
say(source_default.red(`Scan target does not exist: ${targetPath}`));
|
|
28691
28773
|
process.exitCode = 2;
|
|
28692
28774
|
return failedResult(targetPath, `no such path: ${targetPath}`);
|
|
@@ -28782,7 +28864,7 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
28782
28864
|
// and it fails silently. `--path-prefix` covers the remaining case:
|
|
28783
28865
|
// a scan run from inside the subdirectory it is scanning.
|
|
28784
28866
|
base: process.cwd(),
|
|
28785
|
-
root: (0,
|
|
28867
|
+
root: (0, import_node_path12.resolve)(outcome.root)
|
|
28786
28868
|
}) : {
|
|
28787
28869
|
tool: "threatcrush",
|
|
28788
28870
|
version: PKG_VERSION2,
|
|
@@ -28796,8 +28878,8 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
28796
28878
|
const serialized = `${JSON.stringify(payload, null, 2)}
|
|
28797
28879
|
`;
|
|
28798
28880
|
if (options.output) {
|
|
28799
|
-
(0,
|
|
28800
|
-
(0,
|
|
28881
|
+
(0, import_node_fs14.mkdirSync)((0, import_node_path12.dirname)((0, import_node_path12.resolve)(options.output)), { recursive: true });
|
|
28882
|
+
(0, import_node_fs14.writeFileSync)(options.output, serialized, "utf-8");
|
|
28801
28883
|
say(
|
|
28802
28884
|
source_default.gray(
|
|
28803
28885
|
` ${format.toUpperCase()} written to ${options.output} (${outcome.findings.length} finding(s))`
|
|
@@ -28849,30 +28931,30 @@ function printHuman(outcome) {
|
|
|
28849
28931
|
}
|
|
28850
28932
|
|
|
28851
28933
|
// src/commands/init.ts
|
|
28852
|
-
var
|
|
28853
|
-
var
|
|
28934
|
+
var import_node_fs16 = require("fs");
|
|
28935
|
+
var import_node_child_process2 = require("child_process");
|
|
28854
28936
|
|
|
28855
28937
|
// src/core/cli-config.ts
|
|
28856
|
-
var
|
|
28857
|
-
var
|
|
28858
|
-
var
|
|
28859
|
-
var CLI_CONFIG_DIR = (0,
|
|
28860
|
-
var CLI_CONFIG_PATH = (0,
|
|
28938
|
+
var import_node_fs15 = require("fs");
|
|
28939
|
+
var import_node_path13 = require("path");
|
|
28940
|
+
var import_node_os5 = require("os");
|
|
28941
|
+
var CLI_CONFIG_DIR = (0, import_node_path13.join)((0, import_node_os5.homedir)(), ".threatcrush");
|
|
28942
|
+
var CLI_CONFIG_PATH = (0, import_node_path13.join)(CLI_CONFIG_DIR, "config.json");
|
|
28861
28943
|
function apiUrl() {
|
|
28862
28944
|
return process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
28863
28945
|
}
|
|
28864
28946
|
function readCliConfig() {
|
|
28865
28947
|
try {
|
|
28866
|
-
return JSON.parse((0,
|
|
28948
|
+
return JSON.parse((0, import_node_fs15.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
|
|
28867
28949
|
} catch {
|
|
28868
28950
|
return {};
|
|
28869
28951
|
}
|
|
28870
28952
|
}
|
|
28871
28953
|
function writeCliConfig(config) {
|
|
28872
|
-
if (!(0,
|
|
28873
|
-
(0,
|
|
28954
|
+
if (!(0, import_node_fs15.existsSync)(CLI_CONFIG_DIR)) (0, import_node_fs15.mkdirSync)(CLI_CONFIG_DIR, { recursive: true });
|
|
28955
|
+
(0, import_node_fs15.writeFileSync)(CLI_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
28874
28956
|
try {
|
|
28875
|
-
(0,
|
|
28957
|
+
(0, import_node_fs15.chmodSync)(CLI_CONFIG_PATH, 384);
|
|
28876
28958
|
} catch {
|
|
28877
28959
|
}
|
|
28878
28960
|
}
|
|
@@ -29035,13 +29117,13 @@ function ask(question, opts = {}) {
|
|
|
29035
29117
|
|
|
29036
29118
|
// src/core/link-login.ts
|
|
29037
29119
|
var import_node_crypto4 = require("crypto");
|
|
29038
|
-
var
|
|
29120
|
+
var import_node_os6 = require("os");
|
|
29039
29121
|
function createPkce() {
|
|
29040
29122
|
const verifier = (0, import_node_crypto4.randomBytes)(32).toString("base64url");
|
|
29041
29123
|
const challenge = (0, import_node_crypto4.createHash)("sha256").update(verifier).digest("base64url");
|
|
29042
29124
|
return { verifier, challenge };
|
|
29043
29125
|
}
|
|
29044
|
-
async function startLinkLogin(pkce, deviceName = (0,
|
|
29126
|
+
async function startLinkLogin(pkce, deviceName = (0, import_node_os6.hostname)()) {
|
|
29045
29127
|
const res = await fetch(`${apiUrl()}/api/auth/cli/start`, {
|
|
29046
29128
|
method: "POST",
|
|
29047
29129
|
headers: { "Content-Type": "application/json" },
|
|
@@ -29327,7 +29409,7 @@ var SERVICES_TO_DETECT = [
|
|
|
29327
29409
|
];
|
|
29328
29410
|
function isProcessRunning(name) {
|
|
29329
29411
|
try {
|
|
29330
|
-
(0,
|
|
29412
|
+
(0, import_node_child_process2.execSync)(`pgrep -x ${name}`, { stdio: "pipe" });
|
|
29331
29413
|
return true;
|
|
29332
29414
|
} catch {
|
|
29333
29415
|
return false;
|
|
@@ -29335,14 +29417,14 @@ function isProcessRunning(name) {
|
|
|
29335
29417
|
}
|
|
29336
29418
|
function binaryExists(name) {
|
|
29337
29419
|
try {
|
|
29338
|
-
(0,
|
|
29420
|
+
(0, import_node_child_process2.execSync)(`which ${name}`, { stdio: "pipe" });
|
|
29339
29421
|
return true;
|
|
29340
29422
|
} catch {
|
|
29341
29423
|
return false;
|
|
29342
29424
|
}
|
|
29343
29425
|
}
|
|
29344
29426
|
function findLogPath(paths) {
|
|
29345
|
-
return paths.find((p) => (0,
|
|
29427
|
+
return paths.find((p) => (0, import_node_fs16.existsSync)(p));
|
|
29346
29428
|
}
|
|
29347
29429
|
async function promptYesNo(question, fallback2) {
|
|
29348
29430
|
const hint = fallback2 ? "(Y/n)" : "(y/N)";
|
|
@@ -29486,11 +29568,11 @@ async function initCommand(opts = {}) {
|
|
|
29486
29568
|
}
|
|
29487
29569
|
} else {
|
|
29488
29570
|
const spinner2 = ora({ text: "Writing configuration files...", color: "green" }).start();
|
|
29489
|
-
(0,
|
|
29490
|
-
(0,
|
|
29491
|
-
(0,
|
|
29571
|
+
(0, import_node_fs16.mkdirSync)(confDDir, { recursive: true });
|
|
29572
|
+
(0, import_node_fs16.mkdirSync)("/var/log/threatcrush", { recursive: true });
|
|
29573
|
+
(0, import_node_fs16.mkdirSync)("/var/lib/threatcrush", { recursive: true });
|
|
29492
29574
|
const mainConfig = generateDefaultConfig(detected.map((d) => d.name));
|
|
29493
|
-
(0,
|
|
29575
|
+
(0, import_node_fs16.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
|
|
29494
29576
|
for (const svc of detected) {
|
|
29495
29577
|
const svcDef = SERVICES_TO_DETECT.find((s) => s.name === svc.name);
|
|
29496
29578
|
if (!svcDef) continue;
|
|
@@ -29499,7 +29581,7 @@ async function initCommand(opts = {}) {
|
|
|
29499
29581
|
...svcDef.moduleConfig,
|
|
29500
29582
|
log_path: svc.logPath || svcDef.logPaths[0]
|
|
29501
29583
|
});
|
|
29502
|
-
(0,
|
|
29584
|
+
(0, import_node_fs16.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
|
|
29503
29585
|
}
|
|
29504
29586
|
spinner2.succeed("Configuration written successfully");
|
|
29505
29587
|
console.log();
|
|
@@ -29517,8 +29599,8 @@ async function initCommand(opts = {}) {
|
|
|
29517
29599
|
}
|
|
29518
29600
|
function checkWriteAccess(dir) {
|
|
29519
29601
|
try {
|
|
29520
|
-
if (!(0,
|
|
29521
|
-
(0,
|
|
29602
|
+
if (!(0, import_node_fs16.existsSync)(dir)) {
|
|
29603
|
+
(0, import_node_fs16.mkdirSync)(dir, { recursive: true });
|
|
29522
29604
|
}
|
|
29523
29605
|
return true;
|
|
29524
29606
|
} catch {
|
|
@@ -29536,8 +29618,8 @@ var BUILTIN_MODULES = [
|
|
|
29536
29618
|
];
|
|
29537
29619
|
|
|
29538
29620
|
// src/core/module-loader.ts
|
|
29539
|
-
var
|
|
29540
|
-
var
|
|
29621
|
+
var import_node_fs17 = require("fs");
|
|
29622
|
+
var import_node_path14 = require("path");
|
|
29541
29623
|
var import_toml2 = __toESM(require_toml());
|
|
29542
29624
|
init_paths();
|
|
29543
29625
|
function discoverModules(moduleDir, confDir) {
|
|
@@ -29545,22 +29627,22 @@ function discoverModules(moduleDir, confDir) {
|
|
|
29545
29627
|
const configs = loadModuleConfigs(confDir || PATHS.confD);
|
|
29546
29628
|
const searchPaths = [
|
|
29547
29629
|
moduleDir || PATHS.moduleDir,
|
|
29548
|
-
(0,
|
|
29630
|
+
(0, import_node_path14.resolve)(process.cwd(), "modules")
|
|
29549
29631
|
];
|
|
29550
|
-
const builtinDir = (0,
|
|
29551
|
-
if ((0,
|
|
29632
|
+
const builtinDir = (0, import_node_path14.resolve)(__dirname || ".", "..", "modules");
|
|
29633
|
+
if ((0, import_node_fs17.existsSync)(builtinDir)) {
|
|
29552
29634
|
searchPaths.push(builtinDir);
|
|
29553
29635
|
}
|
|
29554
29636
|
for (const basePath of searchPaths) {
|
|
29555
|
-
if (!(0,
|
|
29556
|
-
const entries = (0,
|
|
29637
|
+
if (!(0, import_node_fs17.existsSync)(basePath)) continue;
|
|
29638
|
+
const entries = (0, import_node_fs17.readdirSync)(basePath, { withFileTypes: true });
|
|
29557
29639
|
for (const entry of entries) {
|
|
29558
29640
|
if (!entry.isDirectory()) continue;
|
|
29559
|
-
const modPath = (0,
|
|
29560
|
-
const manifestPath = (0,
|
|
29561
|
-
if (!(0,
|
|
29641
|
+
const modPath = (0, import_node_path14.join)(basePath, entry.name);
|
|
29642
|
+
const manifestPath = (0, import_node_path14.join)(modPath, "mod.toml");
|
|
29643
|
+
if (!(0, import_node_fs17.existsSync)(manifestPath)) continue;
|
|
29562
29644
|
try {
|
|
29563
|
-
const raw = (0,
|
|
29645
|
+
const raw = (0, import_node_fs17.readFileSync)(manifestPath, "utf-8");
|
|
29564
29646
|
const manifest = import_toml2.default.parse(raw);
|
|
29565
29647
|
const config = configs.get(manifest.module.name) || { enabled: true };
|
|
29566
29648
|
modules.push({
|
|
@@ -29586,21 +29668,21 @@ function discoverModules(moduleDir, confDir) {
|
|
|
29586
29668
|
init_ipc_client();
|
|
29587
29669
|
|
|
29588
29670
|
// src/daemon/pidfile.ts
|
|
29589
|
-
var
|
|
29671
|
+
var import_node_fs18 = require("fs");
|
|
29590
29672
|
init_paths();
|
|
29591
29673
|
function writePidFile() {
|
|
29592
29674
|
ensureRuntimeDirs();
|
|
29593
|
-
(0,
|
|
29675
|
+
(0, import_node_fs18.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
|
|
29594
29676
|
}
|
|
29595
29677
|
function readPidFile() {
|
|
29596
|
-
if (!(0,
|
|
29597
|
-
const raw = (0,
|
|
29678
|
+
if (!(0, import_node_fs18.existsSync)(PATHS.pidFile)) return null;
|
|
29679
|
+
const raw = (0, import_node_fs18.readFileSync)(PATHS.pidFile, "utf-8").trim();
|
|
29598
29680
|
const pid = parseInt(raw, 10);
|
|
29599
29681
|
return Number.isFinite(pid) ? pid : null;
|
|
29600
29682
|
}
|
|
29601
29683
|
function removePidFile() {
|
|
29602
29684
|
try {
|
|
29603
|
-
if ((0,
|
|
29685
|
+
if ((0, import_node_fs18.existsSync)(PATHS.pidFile)) (0, import_node_fs18.unlinkSync)(PATHS.pidFile);
|
|
29604
29686
|
} catch {
|
|
29605
29687
|
}
|
|
29606
29688
|
}
|
|
@@ -29612,7 +29694,7 @@ function procStatState(stat) {
|
|
|
29612
29694
|
function isZombie(pid) {
|
|
29613
29695
|
let stat;
|
|
29614
29696
|
try {
|
|
29615
|
-
stat = (0,
|
|
29697
|
+
stat = (0, import_node_fs18.readFileSync)(`/proc/${pid}/stat`, "utf-8");
|
|
29616
29698
|
} catch {
|
|
29617
29699
|
return false;
|
|
29618
29700
|
}
|
|
@@ -29641,24 +29723,24 @@ async function statusCommand() {
|
|
|
29641
29723
|
banner();
|
|
29642
29724
|
const pid = findRunningDaemon();
|
|
29643
29725
|
const client = new IpcClient();
|
|
29644
|
-
let
|
|
29726
|
+
let live2 = null;
|
|
29645
29727
|
try {
|
|
29646
29728
|
await client.connect();
|
|
29647
|
-
|
|
29729
|
+
live2 = await client.status();
|
|
29648
29730
|
} catch {
|
|
29649
29731
|
} finally {
|
|
29650
29732
|
client.close();
|
|
29651
29733
|
}
|
|
29652
29734
|
console.log(source_default.green.bold(" Daemon Status"));
|
|
29653
29735
|
console.log(source_default.gray(" " + "\u2500".repeat(60)));
|
|
29654
|
-
if (
|
|
29736
|
+
if (live2) {
|
|
29655
29737
|
console.log(` Status: ${source_default.green.bold("\u25CF RUNNING")}`);
|
|
29656
|
-
console.log(` PID: ${source_default.white(String(
|
|
29657
|
-
console.log(` Started: ${source_default.white(
|
|
29658
|
-
console.log(` Uptime: ${source_default.white(formatUptime2(
|
|
29659
|
-
console.log(` Version: ${source_default.white(
|
|
29660
|
-
console.log(` Mode: ${source_default.white(
|
|
29661
|
-
console.log(` Socket: ${source_default.gray(
|
|
29738
|
+
console.log(` PID: ${source_default.white(String(live2.pid))}`);
|
|
29739
|
+
console.log(` Started: ${source_default.white(live2.startedAt)}`);
|
|
29740
|
+
console.log(` Uptime: ${source_default.white(formatUptime2(live2.uptimeSeconds))}`);
|
|
29741
|
+
console.log(` Version: ${source_default.white(live2.version)}`);
|
|
29742
|
+
console.log(` Mode: ${source_default.white(live2.mode)}`);
|
|
29743
|
+
console.log(` Socket: ${source_default.gray(live2.paths.socket)}`);
|
|
29662
29744
|
} else if (pid) {
|
|
29663
29745
|
console.log(` Status: ${source_default.yellow.bold("\u25CF RUNNING (IPC unreachable)")}`);
|
|
29664
29746
|
console.log(` PID: ${source_default.white(String(pid))}`);
|
|
@@ -29670,8 +29752,8 @@ async function statusCommand() {
|
|
|
29670
29752
|
console.log();
|
|
29671
29753
|
console.log(source_default.green.bold(" Modules"));
|
|
29672
29754
|
console.log(source_default.gray(" " + "\u2500".repeat(60)));
|
|
29673
|
-
if (
|
|
29674
|
-
for (const mod of
|
|
29755
|
+
if (live2 && live2.modules.length > 0) {
|
|
29756
|
+
for (const mod of live2.modules) {
|
|
29675
29757
|
const dot = mod.status === "running" ? source_default.green("\u25CF") : mod.status === "loaded" ? source_default.cyan("\u25CB") : mod.status === "error" ? source_default.red("\u2717") : source_default.gray("\u25CB");
|
|
29676
29758
|
console.log(` ${dot} ${source_default.white.bold(mod.name.padEnd(18))} ${source_default.gray(mod.status.padEnd(10))} ${source_default.dim(`${mod.events} events`)}`);
|
|
29677
29759
|
}
|
|
@@ -29700,9 +29782,9 @@ async function statusCommand() {
|
|
|
29700
29782
|
}
|
|
29701
29783
|
console.log();
|
|
29702
29784
|
try {
|
|
29703
|
-
if (!
|
|
29704
|
-
const total =
|
|
29705
|
-
const threats =
|
|
29785
|
+
if (!live2) initStateDB(PATHS.stateDb);
|
|
29786
|
+
const total = live2 ? live2.counters.events : getEventCount();
|
|
29787
|
+
const threats = live2 ? live2.counters.threats : getThreatCount();
|
|
29706
29788
|
const last24h = getEventCount(new Date(Date.now() - 864e5));
|
|
29707
29789
|
const threats24h = getThreatCount(new Date(Date.now() - 864e5));
|
|
29708
29790
|
console.log(source_default.green.bold(" Event Statistics"));
|
|
@@ -29737,25 +29819,25 @@ function formatUptime2(seconds) {
|
|
|
29737
29819
|
}
|
|
29738
29820
|
|
|
29739
29821
|
// src/commands/modules.ts
|
|
29740
|
-
var
|
|
29741
|
-
var
|
|
29742
|
-
var
|
|
29822
|
+
var import_node_child_process3 = require("child_process");
|
|
29823
|
+
var import_node_fs20 = require("fs");
|
|
29824
|
+
var import_node_path16 = require("path");
|
|
29743
29825
|
var import_toml3 = __toESM(require_toml());
|
|
29744
29826
|
init_paths();
|
|
29745
29827
|
|
|
29746
29828
|
// src/daemon/module-trust.ts
|
|
29747
29829
|
var import_node_crypto5 = require("crypto");
|
|
29748
|
-
var
|
|
29749
|
-
var
|
|
29830
|
+
var import_node_fs19 = require("fs");
|
|
29831
|
+
var import_node_path15 = require("path");
|
|
29750
29832
|
init_paths();
|
|
29751
|
-
var TRUST_FILE = (0,
|
|
29752
|
-
var PUBLISHER_KEYS_FILE = (0,
|
|
29833
|
+
var TRUST_FILE = (0, import_node_path15.join)(PATHS.configDir, "trusted-modules.json");
|
|
29834
|
+
var PUBLISHER_KEYS_FILE = (0, import_node_path15.join)(PATHS.configDir, "publisher-keys.json");
|
|
29753
29835
|
var DIGEST_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".git"]);
|
|
29754
29836
|
function collectFiles(root, dir = root, out = []) {
|
|
29755
|
-
for (const entry of (0,
|
|
29837
|
+
for (const entry of (0, import_node_fs19.readdirSync)(dir, { withFileTypes: true }).sort(
|
|
29756
29838
|
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
29757
29839
|
)) {
|
|
29758
|
-
const full = (0,
|
|
29840
|
+
const full = (0, import_node_path15.join)(dir, entry.name);
|
|
29759
29841
|
if (entry.isSymbolicLink()) {
|
|
29760
29842
|
out.push({ path: full, isSymlink: true });
|
|
29761
29843
|
} else if (entry.isDirectory()) {
|
|
@@ -29770,24 +29852,24 @@ function collectFiles(root, dir = root, out = []) {
|
|
|
29770
29852
|
function computeModuleDigest(modulePath) {
|
|
29771
29853
|
const hash = (0, import_node_crypto5.createHash)("sha256");
|
|
29772
29854
|
for (const entry of collectFiles(modulePath)) {
|
|
29773
|
-
const relPath = (0,
|
|
29855
|
+
const relPath = (0, import_node_path15.relative)(modulePath, entry.path).split(import_node_path15.sep).join("/");
|
|
29774
29856
|
hash.update(relPath);
|
|
29775
29857
|
hash.update("\0");
|
|
29776
29858
|
if (entry.isSymlink) {
|
|
29777
29859
|
hash.update("symlink:");
|
|
29778
|
-
hash.update((0,
|
|
29860
|
+
hash.update((0, import_node_fs19.readlinkSync)(entry.path));
|
|
29779
29861
|
} else {
|
|
29780
29862
|
hash.update("file:");
|
|
29781
|
-
hash.update((0,
|
|
29863
|
+
hash.update((0, import_node_fs19.readFileSync)(entry.path));
|
|
29782
29864
|
}
|
|
29783
29865
|
hash.update("\0");
|
|
29784
29866
|
}
|
|
29785
29867
|
return hash.digest("hex");
|
|
29786
29868
|
}
|
|
29787
29869
|
function readTrustFile() {
|
|
29788
|
-
if (!(0,
|
|
29870
|
+
if (!(0, import_node_fs19.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
|
|
29789
29871
|
try {
|
|
29790
|
-
const parsed = JSON.parse((0,
|
|
29872
|
+
const parsed = JSON.parse((0, import_node_fs19.readFileSync)(TRUST_FILE, "utf-8"));
|
|
29791
29873
|
if (parsed.version !== 1 || typeof parsed.modules !== "object" || !parsed.modules) {
|
|
29792
29874
|
return { version: 1, modules: {} };
|
|
29793
29875
|
}
|
|
@@ -29797,9 +29879,9 @@ function readTrustFile() {
|
|
|
29797
29879
|
}
|
|
29798
29880
|
}
|
|
29799
29881
|
function writeTrustFile(file) {
|
|
29800
|
-
(0,
|
|
29882
|
+
(0, import_node_fs19.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
|
|
29801
29883
|
try {
|
|
29802
|
-
(0,
|
|
29884
|
+
(0, import_node_fs19.chmodSync)(TRUST_FILE, 384);
|
|
29803
29885
|
} catch {
|
|
29804
29886
|
}
|
|
29805
29887
|
}
|
|
@@ -29825,9 +29907,9 @@ function listTrustedModules() {
|
|
|
29825
29907
|
return readTrustFile().modules;
|
|
29826
29908
|
}
|
|
29827
29909
|
function readPublisherKeys() {
|
|
29828
|
-
if (!(0,
|
|
29910
|
+
if (!(0, import_node_fs19.existsSync)(PUBLISHER_KEYS_FILE)) return {};
|
|
29829
29911
|
try {
|
|
29830
|
-
const parsed = JSON.parse((0,
|
|
29912
|
+
const parsed = JSON.parse((0, import_node_fs19.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
|
|
29831
29913
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
29832
29914
|
} catch {
|
|
29833
29915
|
return {};
|
|
@@ -29836,16 +29918,16 @@ function readPublisherKeys() {
|
|
|
29836
29918
|
function verifyModuleSignature(modulePath, digest) {
|
|
29837
29919
|
const keys = readPublisherKeys();
|
|
29838
29920
|
const pinnedKeyIds = Object.keys(keys);
|
|
29839
|
-
const sigPath = (0,
|
|
29921
|
+
const sigPath = (0, import_node_path15.join)(modulePath, "mod.sig");
|
|
29840
29922
|
if (pinnedKeyIds.length === 0) {
|
|
29841
29923
|
return { ok: true };
|
|
29842
29924
|
}
|
|
29843
|
-
if (!(0,
|
|
29925
|
+
if (!(0, import_node_fs19.existsSync)(sigPath)) {
|
|
29844
29926
|
return { ok: false, reason: "publisher keys are pinned but the module ships no mod.sig" };
|
|
29845
29927
|
}
|
|
29846
29928
|
let parsed;
|
|
29847
29929
|
try {
|
|
29848
|
-
parsed = JSON.parse((0,
|
|
29930
|
+
parsed = JSON.parse((0, import_node_fs19.readFileSync)(sigPath, "utf-8"));
|
|
29849
29931
|
} catch {
|
|
29850
29932
|
return { ok: false, reason: "mod.sig is not valid JSON" };
|
|
29851
29933
|
}
|
|
@@ -29906,10 +29988,10 @@ function safeModuleDirName(name, label = "module name") {
|
|
|
29906
29988
|
return name;
|
|
29907
29989
|
}
|
|
29908
29990
|
function moduleDestination(dir, name, label) {
|
|
29909
|
-
return (0,
|
|
29991
|
+
return (0, import_node_path16.join)(dir, safeModuleDirName(name, label));
|
|
29910
29992
|
}
|
|
29911
29993
|
function assertSafeTarballEntries(tarPath) {
|
|
29912
|
-
const listing = (0,
|
|
29994
|
+
const listing = (0, import_node_child_process3.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
|
|
29913
29995
|
for (const entry of listing.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
29914
29996
|
const normalized = entry.replace(/\\/g, "/");
|
|
29915
29997
|
const segments = normalized.split("/");
|
|
@@ -29919,12 +30001,12 @@ function assertSafeTarballEntries(tarPath) {
|
|
|
29919
30001
|
}
|
|
29920
30002
|
}
|
|
29921
30003
|
function validateManifest(modPath) {
|
|
29922
|
-
const manifestPath = (0,
|
|
29923
|
-
if (!(0,
|
|
30004
|
+
const manifestPath = (0, import_node_path16.join)(modPath, "mod.toml");
|
|
30005
|
+
if (!(0, import_node_fs20.existsSync)(manifestPath)) {
|
|
29924
30006
|
return { ok: false, error: `mod.toml not found at ${manifestPath}` };
|
|
29925
30007
|
}
|
|
29926
30008
|
try {
|
|
29927
|
-
const raw = (0,
|
|
30009
|
+
const raw = (0, import_node_fs20.readFileSync)(manifestPath, "utf-8");
|
|
29928
30010
|
const parsed = import_toml3.default.parse(raw);
|
|
29929
30011
|
const name = parsed.module?.name;
|
|
29930
30012
|
const version = parsed.module?.version;
|
|
@@ -29986,8 +30068,8 @@ async function modulesInstallCommand(source) {
|
|
|
29986
30068
|
console.log();
|
|
29987
30069
|
const dir = modulesDir();
|
|
29988
30070
|
if (source.startsWith("./") || source.startsWith("/") || source.startsWith("~")) {
|
|
29989
|
-
const absPath = (0,
|
|
29990
|
-
if (!(0,
|
|
30071
|
+
const absPath = (0, import_node_path16.resolve)(source.startsWith("~") ? source.replace("~", process.env.HOME || "") : source);
|
|
30072
|
+
if (!(0, import_node_fs20.existsSync)(absPath)) {
|
|
29991
30073
|
console.log(source_default.red(` \u2717 Path not found: ${absPath}
|
|
29992
30074
|
`));
|
|
29993
30075
|
return;
|
|
@@ -30006,7 +30088,7 @@ async function modulesInstallCommand(source) {
|
|
|
30006
30088
|
`));
|
|
30007
30089
|
return;
|
|
30008
30090
|
}
|
|
30009
|
-
if ((0,
|
|
30091
|
+
if ((0, import_node_fs20.existsSync)(dest2)) {
|
|
30010
30092
|
console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
|
|
30011
30093
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
|
|
30012
30094
|
`));
|
|
@@ -30014,7 +30096,7 @@ async function modulesInstallCommand(source) {
|
|
|
30014
30096
|
}
|
|
30015
30097
|
const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
|
|
30016
30098
|
try {
|
|
30017
|
-
(0,
|
|
30099
|
+
(0, import_node_fs20.cpSync)(absPath, dest2, { recursive: true, dereference: true });
|
|
30018
30100
|
spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
|
|
30019
30101
|
} catch (err) {
|
|
30020
30102
|
spinner2.fail(`Copy failed: ${err.message}`);
|
|
@@ -30030,14 +30112,14 @@ async function modulesInstallCommand(source) {
|
|
|
30030
30112
|
let name;
|
|
30031
30113
|
let dest2;
|
|
30032
30114
|
try {
|
|
30033
|
-
name = safeModuleDirName((0,
|
|
30115
|
+
name = safeModuleDirName((0, import_node_path16.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
|
|
30034
30116
|
dest2 = moduleDestination(dir, name);
|
|
30035
30117
|
} catch (err) {
|
|
30036
30118
|
console.log(source_default.red(` x ${err.message}
|
|
30037
30119
|
`));
|
|
30038
30120
|
return;
|
|
30039
30121
|
}
|
|
30040
|
-
if ((0,
|
|
30122
|
+
if ((0, import_node_fs20.existsSync)(dest2)) {
|
|
30041
30123
|
console.log(source_default.yellow(` ! ${name} is already installed at ${dest2}`));
|
|
30042
30124
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${name}`)} first.
|
|
30043
30125
|
`));
|
|
@@ -30045,7 +30127,7 @@ async function modulesInstallCommand(source) {
|
|
|
30045
30127
|
}
|
|
30046
30128
|
const spinner2 = ora({ text: `Cloning ${gitUrl}...`, color: "green" }).start();
|
|
30047
30129
|
try {
|
|
30048
|
-
(0,
|
|
30130
|
+
(0, import_node_child_process3.execFileSync)("git", ["clone", "--depth", "1", "--", gitUrl, dest2], { stdio: "pipe" });
|
|
30049
30131
|
} catch (err) {
|
|
30050
30132
|
spinner2.fail(`Clone failed: ${err.message}`);
|
|
30051
30133
|
return;
|
|
@@ -30054,7 +30136,7 @@ async function modulesInstallCommand(source) {
|
|
|
30054
30136
|
if (!check.ok) {
|
|
30055
30137
|
spinner2.fail(check.error);
|
|
30056
30138
|
try {
|
|
30057
|
-
(0,
|
|
30139
|
+
(0, import_node_fs20.rmSync)(dest2, { recursive: true, force: true });
|
|
30058
30140
|
} catch {
|
|
30059
30141
|
}
|
|
30060
30142
|
return;
|
|
@@ -30101,7 +30183,7 @@ async function modulesInstallCommand(source) {
|
|
|
30101
30183
|
`));
|
|
30102
30184
|
return;
|
|
30103
30185
|
}
|
|
30104
|
-
if ((0,
|
|
30186
|
+
if ((0, import_node_fs20.existsSync)(dest)) {
|
|
30105
30187
|
console.log(source_default.yellow(` ! ${mod.slug} is already installed at ${dest}
|
|
30106
30188
|
`));
|
|
30107
30189
|
return;
|
|
@@ -30109,7 +30191,7 @@ async function modulesInstallCommand(source) {
|
|
|
30109
30191
|
if (install.npm_package) {
|
|
30110
30192
|
const npmSpinner = ora({ text: `Installing ${install.npm_package}...`, color: "green" }).start();
|
|
30111
30193
|
try {
|
|
30112
|
-
(0,
|
|
30194
|
+
(0, import_node_child_process3.execFileSync)("npm", ["install", "-g", "--", install.npm_package], { stdio: "pipe" });
|
|
30113
30195
|
npmSpinner.succeed(`Package ${install.npm_package} installed globally`);
|
|
30114
30196
|
} catch (err) {
|
|
30115
30197
|
npmSpinner.fail(`npm install failed: ${err.message}`);
|
|
@@ -30118,7 +30200,7 @@ async function modulesInstallCommand(source) {
|
|
|
30118
30200
|
} else if (install.git_url) {
|
|
30119
30201
|
const cloneSpinner = ora({ text: "Cloning module repository...", color: "green" }).start();
|
|
30120
30202
|
try {
|
|
30121
|
-
(0,
|
|
30203
|
+
(0, import_node_child_process3.execFileSync)("git", ["clone", "--depth", "1", "--", install.git_url, dest], { stdio: "pipe" });
|
|
30122
30204
|
} catch (err) {
|
|
30123
30205
|
cloneSpinner.fail(`Clone failed: ${err.message}`);
|
|
30124
30206
|
return;
|
|
@@ -30127,7 +30209,7 @@ async function modulesInstallCommand(source) {
|
|
|
30127
30209
|
if (!check.ok) {
|
|
30128
30210
|
cloneSpinner.fail(check.error);
|
|
30129
30211
|
try {
|
|
30130
|
-
(0,
|
|
30212
|
+
(0, import_node_fs20.rmSync)(dest, { recursive: true, force: true });
|
|
30131
30213
|
} catch {
|
|
30132
30214
|
}
|
|
30133
30215
|
return;
|
|
@@ -30141,11 +30223,11 @@ async function modulesInstallCommand(source) {
|
|
|
30141
30223
|
dlSpinner.fail(`HTTP ${res.status}`);
|
|
30142
30224
|
return;
|
|
30143
30225
|
}
|
|
30144
|
-
const tar = (0,
|
|
30145
|
-
(0,
|
|
30226
|
+
const tar = (0, import_node_path16.join)(dir, `${mod.slug}.tar.gz`);
|
|
30227
|
+
(0, import_node_fs20.writeFileSync)(tar, Buffer.from(await res.arrayBuffer()));
|
|
30146
30228
|
assertSafeTarballEntries(tar);
|
|
30147
|
-
(0,
|
|
30148
|
-
(0,
|
|
30229
|
+
(0, import_node_child_process3.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
|
|
30230
|
+
(0, import_node_fs20.rmSync)(tar, { force: true });
|
|
30149
30231
|
const check = validateManifest(dest);
|
|
30150
30232
|
if (!check.ok) {
|
|
30151
30233
|
dlSpinner.fail(check.error);
|
|
@@ -30177,7 +30259,7 @@ async function modulesRemoveCommand(name) {
|
|
|
30177
30259
|
`));
|
|
30178
30260
|
return;
|
|
30179
30261
|
}
|
|
30180
|
-
if (!(0,
|
|
30262
|
+
if (!(0, import_node_fs20.existsSync)(target)) {
|
|
30181
30263
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
30182
30264
|
`));
|
|
30183
30265
|
return;
|
|
@@ -30187,7 +30269,7 @@ async function modulesRemoveCommand(name) {
|
|
|
30187
30269
|
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
|
|
30188
30270
|
}
|
|
30189
30271
|
try {
|
|
30190
|
-
(0,
|
|
30272
|
+
(0, import_node_fs20.rmSync)(target, { recursive: true, force: true });
|
|
30191
30273
|
untrustModule(name);
|
|
30192
30274
|
console.log(source_default.green(` \u2713 Removed ${name} from ${dir}
|
|
30193
30275
|
`));
|
|
@@ -30212,7 +30294,7 @@ async function modulesTrustCommand(name) {
|
|
|
30212
30294
|
`));
|
|
30213
30295
|
return;
|
|
30214
30296
|
}
|
|
30215
|
-
if (!(0,
|
|
30297
|
+
if (!(0, import_node_fs20.existsSync)(target)) {
|
|
30216
30298
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
30217
30299
|
`));
|
|
30218
30300
|
return;
|
|
@@ -30647,7 +30729,7 @@ async function pentestCommand(targetUrl) {
|
|
|
30647
30729
|
}
|
|
30648
30730
|
|
|
30649
30731
|
// src/commands/ai-scan.ts
|
|
30650
|
-
var
|
|
30732
|
+
var import_node_fs21 = require("fs");
|
|
30651
30733
|
|
|
30652
30734
|
// src/aiscan/probes.ts
|
|
30653
30735
|
function makeCanary() {
|
|
@@ -30924,7 +31006,7 @@ async function aiScanMoshCommand(file, args) {
|
|
|
30924
31006
|
console.log();
|
|
30925
31007
|
let source;
|
|
30926
31008
|
try {
|
|
30927
|
-
source = (0,
|
|
31009
|
+
source = (0, import_node_fs21.readFileSync)(file, "utf-8");
|
|
30928
31010
|
} catch (err) {
|
|
30929
31011
|
logger.error(`Cannot read ${file}: ${err.message}`);
|
|
30930
31012
|
process.exitCode = 1;
|
|
@@ -30944,22 +31026,22 @@ async function aiScanMoshCommand(file, args) {
|
|
|
30944
31026
|
}
|
|
30945
31027
|
|
|
30946
31028
|
// src/commands/orgs.ts
|
|
30947
|
-
var
|
|
30948
|
-
var
|
|
30949
|
-
var
|
|
31029
|
+
var import_node_os7 = require("os");
|
|
31030
|
+
var import_node_fs22 = require("fs");
|
|
31031
|
+
var import_node_path17 = require("path");
|
|
30950
31032
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
30951
|
-
var CONFIG_PATH = (0,
|
|
31033
|
+
var CONFIG_PATH = (0, import_node_path17.join)((0, import_node_os7.homedir)(), ".threatcrush", "config.json");
|
|
30952
31034
|
function readConfig() {
|
|
30953
31035
|
try {
|
|
30954
|
-
return JSON.parse((0,
|
|
31036
|
+
return JSON.parse((0, import_node_fs22.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
30955
31037
|
} catch {
|
|
30956
31038
|
return {};
|
|
30957
31039
|
}
|
|
30958
31040
|
}
|
|
30959
31041
|
function writeConfig(config) {
|
|
30960
|
-
const dir = (0,
|
|
30961
|
-
if (!(0,
|
|
30962
|
-
(0,
|
|
31042
|
+
const dir = (0, import_node_path17.join)((0, import_node_os7.homedir)(), ".threatcrush");
|
|
31043
|
+
if (!(0, import_node_fs22.existsSync)(dir)) (0, import_node_fs22.mkdirSync)(dir, { recursive: true });
|
|
31044
|
+
(0, import_node_fs22.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
30963
31045
|
}
|
|
30964
31046
|
function getAuthHeaders() {
|
|
30965
31047
|
const config = readConfig();
|
|
@@ -31095,7 +31177,7 @@ async function useOrganization(slug) {
|
|
|
31095
31177
|
|
|
31096
31178
|
// src/commands/servers.ts
|
|
31097
31179
|
var import_node_readline2 = __toESM(require("readline"));
|
|
31098
|
-
var
|
|
31180
|
+
var import_node_os8 = require("os");
|
|
31099
31181
|
async function serversCommand(options) {
|
|
31100
31182
|
const { action, name, org } = options;
|
|
31101
31183
|
if (action === "list" || !action) {
|
|
@@ -31187,7 +31269,7 @@ async function chooseOrg(orgs, flag, ask2) {
|
|
|
31187
31269
|
async function linkServer(opts = {}, ask2 = askChoice) {
|
|
31188
31270
|
if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
|
|
31189
31271
|
const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
|
|
31190
|
-
const host = opts.hostname ?? (0,
|
|
31272
|
+
const host = opts.hostname ?? (0, import_node_os8.hostname)();
|
|
31191
31273
|
const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
|
|
31192
31274
|
if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
|
|
31193
31275
|
const { servers = [] } = await listRes.json();
|
|
@@ -31303,15 +31385,15 @@ function timeAgo(dateStr) {
|
|
|
31303
31385
|
}
|
|
31304
31386
|
|
|
31305
31387
|
// src/commands/connect.ts
|
|
31306
|
-
var
|
|
31307
|
-
var
|
|
31308
|
-
var
|
|
31309
|
-
var
|
|
31388
|
+
var import_node_os9 = require("os");
|
|
31389
|
+
var import_node_fs23 = require("fs");
|
|
31390
|
+
var import_node_path18 = require("path");
|
|
31391
|
+
var import_node_child_process4 = require("child_process");
|
|
31310
31392
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
31311
|
-
var CONFIG_PATH2 = (0,
|
|
31393
|
+
var CONFIG_PATH2 = (0, import_node_path18.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
|
|
31312
31394
|
function readConfig2() {
|
|
31313
31395
|
try {
|
|
31314
|
-
return JSON.parse((0,
|
|
31396
|
+
return JSON.parse((0, import_node_fs23.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
31315
31397
|
} catch {
|
|
31316
31398
|
return {};
|
|
31317
31399
|
}
|
|
@@ -31447,7 +31529,7 @@ async function sshConnect(options) {
|
|
|
31447
31529
|
sshArgs.push("-i", identity);
|
|
31448
31530
|
}
|
|
31449
31531
|
sshArgs.push(`${user}@${hostname3}`);
|
|
31450
|
-
const ssh = (0,
|
|
31532
|
+
const ssh = (0, import_node_child_process4.spawn)("ssh", sshArgs, { stdio: "inherit" });
|
|
31451
31533
|
ssh.on("error", (err) => {
|
|
31452
31534
|
console.log(source_default.red(`
|
|
31453
31535
|
SSH error: ${err.message}
|
|
@@ -31465,22 +31547,22 @@ async function sshConnect(options) {
|
|
|
31465
31547
|
}
|
|
31466
31548
|
|
|
31467
31549
|
// src/commands/daemon.ts
|
|
31468
|
-
var
|
|
31469
|
-
var import_node_fs34 = require("fs");
|
|
31470
|
-
var import_node_path24 = require("path");
|
|
31550
|
+
var import_node_child_process12 = require("child_process");
|
|
31471
31551
|
var import_node_fs35 = require("fs");
|
|
31552
|
+
var import_node_path25 = require("path");
|
|
31553
|
+
var import_node_fs36 = require("fs");
|
|
31472
31554
|
|
|
31473
31555
|
// src/daemon/index.ts
|
|
31474
|
-
var
|
|
31475
|
-
var
|
|
31476
|
-
var
|
|
31477
|
-
var
|
|
31556
|
+
var import_node_fs34 = require("fs");
|
|
31557
|
+
var import_node_child_process11 = require("child_process");
|
|
31558
|
+
var import_node_os10 = require("os");
|
|
31559
|
+
var import_node_path24 = require("path");
|
|
31478
31560
|
var import_node_util = require("util");
|
|
31479
31561
|
init_paths();
|
|
31480
31562
|
|
|
31481
31563
|
// src/daemon/ipc-server.ts
|
|
31482
31564
|
var import_node_net2 = require("net");
|
|
31483
|
-
var
|
|
31565
|
+
var import_node_fs24 = require("fs");
|
|
31484
31566
|
init_paths();
|
|
31485
31567
|
init_control_token();
|
|
31486
31568
|
|
|
@@ -31534,9 +31616,9 @@ var IpcServer = class {
|
|
|
31534
31616
|
controlToken = "";
|
|
31535
31617
|
async start() {
|
|
31536
31618
|
this.controlToken = issueControlToken();
|
|
31537
|
-
if ((0,
|
|
31619
|
+
if ((0, import_node_fs24.existsSync)(PATHS.socket)) {
|
|
31538
31620
|
try {
|
|
31539
|
-
(0,
|
|
31621
|
+
(0, import_node_fs24.unlinkSync)(PATHS.socket);
|
|
31540
31622
|
} catch {
|
|
31541
31623
|
}
|
|
31542
31624
|
}
|
|
@@ -31572,14 +31654,14 @@ var IpcServer = class {
|
|
|
31572
31654
|
return new Promise((resolve6) => {
|
|
31573
31655
|
if (!this.server) {
|
|
31574
31656
|
try {
|
|
31575
|
-
if ((0,
|
|
31657
|
+
if ((0, import_node_fs24.existsSync)(PATHS.socket)) (0, import_node_fs24.unlinkSync)(PATHS.socket);
|
|
31576
31658
|
} catch {
|
|
31577
31659
|
}
|
|
31578
31660
|
return resolve6();
|
|
31579
31661
|
}
|
|
31580
31662
|
this.server.close(() => {
|
|
31581
31663
|
try {
|
|
31582
|
-
if ((0,
|
|
31664
|
+
if ((0, import_node_fs24.existsSync)(PATHS.socket)) (0, import_node_fs24.unlinkSync)(PATHS.socket);
|
|
31583
31665
|
} catch {
|
|
31584
31666
|
}
|
|
31585
31667
|
resolve6();
|
|
@@ -31761,14 +31843,14 @@ var IpcServer = class {
|
|
|
31761
31843
|
};
|
|
31762
31844
|
|
|
31763
31845
|
// src/daemon/module-host.ts
|
|
31764
|
-
var
|
|
31765
|
-
var
|
|
31846
|
+
var import_node_fs28 = require("fs");
|
|
31847
|
+
var import_node_path19 = require("path");
|
|
31766
31848
|
var import_node_url = require("url");
|
|
31767
31849
|
var import_toml4 = __toESM(require_toml());
|
|
31768
31850
|
init_paths();
|
|
31769
31851
|
|
|
31770
31852
|
// src/daemon/watchers/log-watcher.ts
|
|
31771
|
-
var
|
|
31853
|
+
var import_node_fs25 = require("fs");
|
|
31772
31854
|
var DEFAULT_SOURCES = [
|
|
31773
31855
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
31774
31856
|
{ path: "/var/log/secure", module: "ssh-guard", category: "auth" },
|
|
@@ -31788,9 +31870,9 @@ var LogWatcher = class {
|
|
|
31788
31870
|
start() {
|
|
31789
31871
|
const started = [];
|
|
31790
31872
|
for (const src of this.sources) {
|
|
31791
|
-
if (!(0,
|
|
31873
|
+
if (!(0, import_node_fs25.existsSync)(src.path)) continue;
|
|
31792
31874
|
try {
|
|
31793
|
-
(0,
|
|
31875
|
+
(0, import_node_fs25.accessSync)(src.path, import_node_fs25.constants.R_OK);
|
|
31794
31876
|
} catch {
|
|
31795
31877
|
continue;
|
|
31796
31878
|
}
|
|
@@ -31906,7 +31988,7 @@ var LogWatcher = class {
|
|
|
31906
31988
|
};
|
|
31907
31989
|
|
|
31908
31990
|
// src/daemon/watchers/journal-watcher.ts
|
|
31909
|
-
var
|
|
31991
|
+
var import_node_child_process5 = require("child_process");
|
|
31910
31992
|
var SSHD_COMMS = ["sshd", "sshd-session"];
|
|
31911
31993
|
function isSshdRecord(entry) {
|
|
31912
31994
|
return entry._UID === "0" && SSHD_COMMS.includes(entry._COMM);
|
|
@@ -31945,14 +32027,14 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
31945
32027
|
return isRoot4 ? [] : ["--user"];
|
|
31946
32028
|
}
|
|
31947
32029
|
static isAvailable() {
|
|
31948
|
-
const probe = (0,
|
|
32030
|
+
const probe = (0, import_node_child_process5.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
|
|
31949
32031
|
stdio: ["ignore", "ignore", "ignore"]
|
|
31950
32032
|
});
|
|
31951
32033
|
return probe.status === 0;
|
|
31952
32034
|
}
|
|
31953
32035
|
start() {
|
|
31954
32036
|
if (!_JournalWatcher.isAvailable()) return false;
|
|
31955
|
-
const child = (0,
|
|
32037
|
+
const child = (0, import_node_child_process5.spawn)(
|
|
31956
32038
|
"journalctl",
|
|
31957
32039
|
[..._JournalWatcher.scopeArgs(), "-o", "json", "-f", "--since", "now"],
|
|
31958
32040
|
{ stdio: ["ignore", "pipe", "pipe"] }
|
|
@@ -31977,14 +32059,14 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
31977
32059
|
* nothing and looking like protection.
|
|
31978
32060
|
*/
|
|
31979
32061
|
startSshd() {
|
|
31980
|
-
const probe = (0,
|
|
32062
|
+
const probe = (0, import_node_child_process5.spawnSync)("journalctl", ["-q", "-n", "1", "-o", "cat", "--no-pager", "_UID=0"], {
|
|
31981
32063
|
stdio: ["ignore", "pipe", "ignore"],
|
|
31982
32064
|
encoding: "utf-8"
|
|
31983
32065
|
});
|
|
31984
32066
|
if (probe.error || probe.status !== 0) return "unavailable";
|
|
31985
32067
|
if (!probe.stdout.trim()) return "unreadable";
|
|
31986
32068
|
const matches2 = ["_UID=0", ...SSHD_COMMS.map((comm) => `_COMM=${comm}`)];
|
|
31987
|
-
const child = (0,
|
|
32069
|
+
const child = (0, import_node_child_process5.spawn)("journalctl", ["-o", "json", "-f", "--since", "now", ...matches2], {
|
|
31988
32070
|
stdio: ["ignore", "pipe", "ignore"]
|
|
31989
32071
|
});
|
|
31990
32072
|
if (!child.stdout) return "unavailable";
|
|
@@ -32086,8 +32168,8 @@ function realtimeToDate(rt) {
|
|
|
32086
32168
|
}
|
|
32087
32169
|
|
|
32088
32170
|
// src/modules/network-monitor/index.ts
|
|
32089
|
-
var
|
|
32090
|
-
var
|
|
32171
|
+
var import_node_child_process6 = require("child_process");
|
|
32172
|
+
var import_node_fs26 = require("fs");
|
|
32091
32173
|
var NetworkMonitor = class {
|
|
32092
32174
|
constructor(bus2) {
|
|
32093
32175
|
this.bus = bus2;
|
|
@@ -32149,9 +32231,9 @@ var NetworkMonitor = class {
|
|
|
32149
32231
|
return this.active;
|
|
32150
32232
|
}
|
|
32151
32233
|
hasConntrackOrSs() {
|
|
32152
|
-
const ss = (0,
|
|
32234
|
+
const ss = (0, import_node_child_process6.spawnSync)("ss", ["--version"], { stdio: "pipe" });
|
|
32153
32235
|
if (ss.status === 0) return true;
|
|
32154
|
-
return (0,
|
|
32236
|
+
return (0, import_node_fs26.existsSync)("/proc/net/tcp");
|
|
32155
32237
|
}
|
|
32156
32238
|
/**
|
|
32157
32239
|
* The TCP ports this host actually listens on.
|
|
@@ -32166,7 +32248,7 @@ var NetworkMonitor = class {
|
|
|
32166
32248
|
listeningPorts() {
|
|
32167
32249
|
const ports = /* @__PURE__ */ new Set();
|
|
32168
32250
|
try {
|
|
32169
|
-
const out = (0,
|
|
32251
|
+
const out = (0, import_node_child_process6.spawnSync)("ss", ["-ltnH"], { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"], timeout: 3e3 });
|
|
32170
32252
|
if (out.status === 0 && out.stdout) {
|
|
32171
32253
|
for (const line of out.stdout.split("\n")) {
|
|
32172
32254
|
const parts = line.trim().split(/\s+/);
|
|
@@ -32197,7 +32279,7 @@ var NetworkMonitor = class {
|
|
|
32197
32279
|
const listening = this.listeningPorts();
|
|
32198
32280
|
if (listening.size === 0) return records;
|
|
32199
32281
|
try {
|
|
32200
|
-
const ct = (0,
|
|
32282
|
+
const ct = (0, import_node_child_process6.spawnSync)("conntrack", ["-L", "-p", "tcp", "-o", "extended"], {
|
|
32201
32283
|
encoding: "utf-8",
|
|
32202
32284
|
stdio: ["pipe", "pipe", "pipe"],
|
|
32203
32285
|
timeout: 3e3
|
|
@@ -32217,7 +32299,7 @@ var NetworkMonitor = class {
|
|
|
32217
32299
|
} catch {
|
|
32218
32300
|
}
|
|
32219
32301
|
try {
|
|
32220
|
-
const ss = (0,
|
|
32302
|
+
const ss = (0, import_node_child_process6.spawnSync)("ss", ["-tnp", "-H"], {
|
|
32221
32303
|
encoding: "utf-8",
|
|
32222
32304
|
stdio: ["pipe", "pipe", "pipe"],
|
|
32223
32305
|
timeout: 3e3
|
|
@@ -32281,7 +32363,7 @@ var NetworkMonitor = class {
|
|
|
32281
32363
|
}
|
|
32282
32364
|
analyzeSynFlood(connections) {
|
|
32283
32365
|
try {
|
|
32284
|
-
const ss = (0,
|
|
32366
|
+
const ss = (0, import_node_child_process6.spawnSync)("ss", ["-tn", "state", "syn-recv", "-H"], {
|
|
32285
32367
|
encoding: "utf-8",
|
|
32286
32368
|
stdio: ["pipe", "pipe", "pipe"],
|
|
32287
32369
|
timeout: 3e3
|
|
@@ -32338,8 +32420,8 @@ var NetworkMonitor = class {
|
|
|
32338
32420
|
};
|
|
32339
32421
|
|
|
32340
32422
|
// src/modules/dns-monitor/index.ts
|
|
32341
|
-
var
|
|
32342
|
-
var
|
|
32423
|
+
var import_node_fs27 = require("fs");
|
|
32424
|
+
var import_node_child_process7 = require("child_process");
|
|
32343
32425
|
var import_node_readline3 = require("readline");
|
|
32344
32426
|
var DNS_LOG_SOURCES = [
|
|
32345
32427
|
"/var/log/syslog",
|
|
@@ -32408,7 +32490,7 @@ var DnsMonitor = class {
|
|
|
32408
32490
|
/** True if a systemd unit is loaded on this host (so we do not tail nothing). */
|
|
32409
32491
|
unitExists(unit) {
|
|
32410
32492
|
try {
|
|
32411
|
-
const r = (0,
|
|
32493
|
+
const r = (0, import_node_child_process7.spawnSync)("systemctl", ["show", unit, "--property=LoadState", "--value"], {
|
|
32412
32494
|
encoding: "utf-8",
|
|
32413
32495
|
stdio: ["ignore", "pipe", "ignore"],
|
|
32414
32496
|
timeout: 3e3
|
|
@@ -32420,9 +32502,9 @@ var DnsMonitor = class {
|
|
|
32420
32502
|
}
|
|
32421
32503
|
start() {
|
|
32422
32504
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
32423
|
-
if (!(0,
|
|
32505
|
+
if (!(0, import_node_fs27.existsSync)(p)) return false;
|
|
32424
32506
|
try {
|
|
32425
|
-
(0,
|
|
32507
|
+
(0, import_node_fs27.accessSync)(p, import_node_fs27.constants.R_OK);
|
|
32426
32508
|
return true;
|
|
32427
32509
|
} catch {
|
|
32428
32510
|
return false;
|
|
@@ -32481,7 +32563,7 @@ var DnsMonitor = class {
|
|
|
32481
32563
|
/** Follow one systemd unit's journal, feeding its lines to the same parser. */
|
|
32482
32564
|
tailJournalUnit(unit) {
|
|
32483
32565
|
try {
|
|
32484
|
-
const child = (0,
|
|
32566
|
+
const child = (0, import_node_child_process7.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
|
|
32485
32567
|
stdio: ["ignore", "pipe", "ignore"]
|
|
32486
32568
|
});
|
|
32487
32569
|
if (!child.stdout) return;
|
|
@@ -32755,15 +32837,15 @@ var ModuleHost = class {
|
|
|
32755
32837
|
}
|
|
32756
32838
|
}
|
|
32757
32839
|
async discoverAndStartInstalled() {
|
|
32758
|
-
if (!(0,
|
|
32840
|
+
if (!(0, import_node_fs28.existsSync)(PATHS.moduleDir)) return;
|
|
32759
32841
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
32760
|
-
const entries = (0,
|
|
32842
|
+
const entries = (0, import_node_fs28.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
32761
32843
|
for (const entry of entries) {
|
|
32762
32844
|
if (!entry.isDirectory()) continue;
|
|
32763
|
-
const manifestPath = (0,
|
|
32764
|
-
if (!(0,
|
|
32845
|
+
const manifestPath = (0, import_node_path19.join)(PATHS.moduleDir, entry.name, "mod.toml");
|
|
32846
|
+
if (!(0, import_node_fs28.existsSync)(manifestPath)) continue;
|
|
32765
32847
|
try {
|
|
32766
|
-
const manifest = import_toml4.default.parse((0,
|
|
32848
|
+
const manifest = import_toml4.default.parse((0, import_node_fs28.readFileSync)(manifestPath, "utf-8"));
|
|
32767
32849
|
const name = manifest.module?.name || entry.name;
|
|
32768
32850
|
const defaults = manifest.module?.config?.defaults || {};
|
|
32769
32851
|
const config = {
|
|
@@ -32777,7 +32859,7 @@ var ModuleHost = class {
|
|
|
32777
32859
|
source: "installed",
|
|
32778
32860
|
status: config.enabled === false ? "disabled" : "loaded",
|
|
32779
32861
|
events: 0,
|
|
32780
|
-
path: (0,
|
|
32862
|
+
path: (0, import_node_path19.join)(PATHS.moduleDir, entry.name),
|
|
32781
32863
|
config
|
|
32782
32864
|
};
|
|
32783
32865
|
this.modules.set(name, hosted);
|
|
@@ -32792,7 +32874,7 @@ var ModuleHost = class {
|
|
|
32792
32874
|
status: "error",
|
|
32793
32875
|
events: 0,
|
|
32794
32876
|
detail: `manifest load failed: ${String(err.message || err)}`,
|
|
32795
|
-
path: (0,
|
|
32877
|
+
path: (0, import_node_path19.join)(PATHS.moduleDir, entry.name)
|
|
32796
32878
|
});
|
|
32797
32879
|
}
|
|
32798
32880
|
}
|
|
@@ -32831,17 +32913,17 @@ var ModuleHost = class {
|
|
|
32831
32913
|
}
|
|
32832
32914
|
}
|
|
32833
32915
|
installedEntrypoint(modulePath) {
|
|
32834
|
-
const packageJson = (0,
|
|
32916
|
+
const packageJson = (0, import_node_path19.join)(modulePath, "package.json");
|
|
32835
32917
|
const candidates = [];
|
|
32836
|
-
if ((0,
|
|
32918
|
+
if ((0, import_node_fs28.existsSync)(packageJson)) {
|
|
32837
32919
|
try {
|
|
32838
|
-
const pkg = JSON.parse((0,
|
|
32839
|
-
if (pkg.main) candidates.push((0,
|
|
32920
|
+
const pkg = JSON.parse((0, import_node_fs28.readFileSync)(packageJson, "utf-8"));
|
|
32921
|
+
if (pkg.main) candidates.push((0, import_node_path19.join)(modulePath, pkg.main));
|
|
32840
32922
|
} catch {
|
|
32841
32923
|
}
|
|
32842
32924
|
}
|
|
32843
|
-
candidates.push((0,
|
|
32844
|
-
return candidates.find((candidate) => (0,
|
|
32925
|
+
candidates.push((0, import_node_path19.join)(modulePath, "dist", "index.js"), (0, import_node_path19.join)(modulePath, "index.js"));
|
|
32926
|
+
return candidates.find((candidate) => (0, import_node_fs28.existsSync)(candidate)) || null;
|
|
32845
32927
|
}
|
|
32846
32928
|
isThreatCrushModule(value) {
|
|
32847
32929
|
return Boolean(
|
|
@@ -33344,16 +33426,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
33344
33426
|
}
|
|
33345
33427
|
|
|
33346
33428
|
// src/daemon/workers/cloud-spool.ts
|
|
33347
|
-
var
|
|
33429
|
+
var import_node_fs29 = require("fs");
|
|
33348
33430
|
var import_promises = require("fs/promises");
|
|
33349
|
-
var
|
|
33431
|
+
var import_node_path20 = require("path");
|
|
33350
33432
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
33351
33433
|
var CloudSpool = class {
|
|
33352
33434
|
constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
|
|
33353
33435
|
this.path = path;
|
|
33354
33436
|
this.limits = limits;
|
|
33355
33437
|
try {
|
|
33356
|
-
(0,
|
|
33438
|
+
(0, import_node_fs29.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
|
|
33357
33439
|
} catch {
|
|
33358
33440
|
}
|
|
33359
33441
|
this.load();
|
|
@@ -33422,7 +33504,7 @@ var CloudSpool = class {
|
|
|
33422
33504
|
load() {
|
|
33423
33505
|
let raw;
|
|
33424
33506
|
try {
|
|
33425
|
-
raw = (0,
|
|
33507
|
+
raw = (0, import_node_fs29.readFileSync)(this.path, "utf-8");
|
|
33426
33508
|
} catch {
|
|
33427
33509
|
return;
|
|
33428
33510
|
}
|
|
@@ -33663,7 +33745,7 @@ var CloudSync = class {
|
|
|
33663
33745
|
var import_node_net6 = require("net");
|
|
33664
33746
|
|
|
33665
33747
|
// src/daemon/firewall/protected.ts
|
|
33666
|
-
var
|
|
33748
|
+
var import_node_child_process8 = require("child_process");
|
|
33667
33749
|
var import_node_net4 = require("net");
|
|
33668
33750
|
var DEFAULT_PROTECTED = [
|
|
33669
33751
|
"127.0.0.0/8",
|
|
@@ -33759,7 +33841,7 @@ function currentSshClient(env2 = process.env) {
|
|
|
33759
33841
|
function establishedSshPeers() {
|
|
33760
33842
|
const peers = /* @__PURE__ */ new Set();
|
|
33761
33843
|
try {
|
|
33762
|
-
const out = (0,
|
|
33844
|
+
const out = (0, import_node_child_process8.execFileSync)("ss", ["-tnpH"], {
|
|
33763
33845
|
encoding: "utf-8",
|
|
33764
33846
|
stdio: ["ignore", "pipe", "ignore"],
|
|
33765
33847
|
timeout: 3e3
|
|
@@ -33780,7 +33862,7 @@ function defaultGateways() {
|
|
|
33780
33862
|
const found = /* @__PURE__ */ new Set();
|
|
33781
33863
|
for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
|
|
33782
33864
|
try {
|
|
33783
|
-
const out = (0,
|
|
33865
|
+
const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
33784
33866
|
for (const line of out.split("\n")) {
|
|
33785
33867
|
const match = line.match(/\bvia\s+(\S+)/);
|
|
33786
33868
|
if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
|
|
@@ -34007,6 +34089,19 @@ var RemediationConsumer = class {
|
|
|
34007
34089
|
};
|
|
34008
34090
|
|
|
34009
34091
|
// src/daemon/rules/engine.ts
|
|
34092
|
+
var MAX_WINDOW_ENTRIES = 1e3;
|
|
34093
|
+
function live(window) {
|
|
34094
|
+
return window.times.length - window.head;
|
|
34095
|
+
}
|
|
34096
|
+
function expire(window, now) {
|
|
34097
|
+
const cutoff = now - window.windowMs;
|
|
34098
|
+
while (window.head < window.times.length && window.times[window.head] < cutoff) window.head++;
|
|
34099
|
+
if (window.head > 64 && window.head * 2 > window.times.length) {
|
|
34100
|
+
window.times = window.times.slice(window.head);
|
|
34101
|
+
window.ips = window.ips.slice(window.head);
|
|
34102
|
+
window.head = 0;
|
|
34103
|
+
}
|
|
34104
|
+
}
|
|
34010
34105
|
var RuleEngine = class {
|
|
34011
34106
|
constructor(onDetection) {
|
|
34012
34107
|
this.onDetection = onDetection;
|
|
@@ -34032,27 +34127,42 @@ var RuleEngine = class {
|
|
|
34032
34127
|
const windowKey = `${rule.id}:${groupBy}:${groupValue}`;
|
|
34033
34128
|
let window = this.windows.get(windowKey);
|
|
34034
34129
|
if (!window) {
|
|
34035
|
-
window = {
|
|
34130
|
+
window = {
|
|
34131
|
+
times: [],
|
|
34132
|
+
ips: [],
|
|
34133
|
+
head: 0,
|
|
34134
|
+
lastAlert: 0,
|
|
34135
|
+
windowMs: rule.window_seconds * 1e3,
|
|
34136
|
+
cooldownMs: rule.cooldown_seconds * 1e3
|
|
34137
|
+
};
|
|
34036
34138
|
this.windows.set(windowKey, window);
|
|
34037
34139
|
}
|
|
34038
|
-
window.
|
|
34039
|
-
|
|
34040
|
-
window
|
|
34041
|
-
|
|
34042
|
-
|
|
34043
|
-
|
|
34044
|
-
|
|
34045
|
-
|
|
34046
|
-
|
|
34140
|
+
window.times.push(now);
|
|
34141
|
+
window.ips.push(event.source_ip);
|
|
34142
|
+
expire(window, now);
|
|
34143
|
+
const cap = Math.max(rule.threshold, MAX_WINDOW_ENTRIES);
|
|
34144
|
+
let capped = false;
|
|
34145
|
+
if (live(window) > cap) {
|
|
34146
|
+
window.head = window.times.length - cap;
|
|
34147
|
+
capped = true;
|
|
34148
|
+
expire(window, now);
|
|
34149
|
+
}
|
|
34150
|
+
if (live(window) < rule.threshold) continue;
|
|
34151
|
+
if (window.lastAlert > 0 && now - window.lastAlert < window.cooldownMs) continue;
|
|
34152
|
+
const hits = live(window);
|
|
34153
|
+
const distinctIps = new Set(window.ips.slice(window.head).filter(Boolean)).size;
|
|
34047
34154
|
window.lastAlert = now;
|
|
34048
|
-
window.
|
|
34155
|
+
window.times = [];
|
|
34156
|
+
window.ips = [];
|
|
34157
|
+
window.head = 0;
|
|
34158
|
+
const hitsLabel = capped ? `${hits}+` : String(hits);
|
|
34049
34159
|
const aggregate = groupBy !== "source_ip";
|
|
34050
34160
|
const spread = aggregate ? ` from ${distinctIps} address${distinctIps === 1 ? "" : "es"}${groupBy === "endpoint" ? ` against ${groupValue}` : ""}` : "";
|
|
34051
34161
|
this.onDetection({
|
|
34052
34162
|
rule_id: rule.id,
|
|
34053
34163
|
severity: rule.severity,
|
|
34054
34164
|
title: rule.title,
|
|
34055
|
-
description: `${rule.description} (${
|
|
34165
|
+
description: `${rule.description} (${hitsLabel} events in ${rule.window_seconds}s${spread})`,
|
|
34056
34166
|
source_ip: aggregate ? void 0 : event.source_ip,
|
|
34057
34167
|
username: event.details?.user || void 0,
|
|
34058
34168
|
raw_metadata: {
|
|
@@ -34115,20 +34225,32 @@ var RuleEngine = class {
|
|
|
34115
34225
|
return event.details?.[field];
|
|
34116
34226
|
}
|
|
34117
34227
|
}
|
|
34118
|
-
|
|
34119
|
-
|
|
34120
|
-
|
|
34121
|
-
|
|
34122
|
-
|
|
34228
|
+
/**
|
|
34229
|
+
* Expire every window by its own rule's length, and forget windows with
|
|
34230
|
+
* nothing left in them once their cooldown is over (a cooldown must outlive
|
|
34231
|
+
* an empty window, or a source could re-trigger the moment it was forgotten).
|
|
34232
|
+
* Without the expiry, a window whose address never came back was kept forever.
|
|
34233
|
+
*/
|
|
34234
|
+
cleanup(now = Date.now()) {
|
|
34235
|
+
let removed = 0;
|
|
34236
|
+
for (const [key, window] of this.windows) {
|
|
34237
|
+
expire(window, now);
|
|
34238
|
+
if (live(window) === 0 && (window.lastAlert === 0 || now - window.lastAlert >= window.cooldownMs)) {
|
|
34123
34239
|
this.windows.delete(key);
|
|
34240
|
+
removed++;
|
|
34124
34241
|
}
|
|
34125
34242
|
}
|
|
34243
|
+
return removed;
|
|
34244
|
+
}
|
|
34245
|
+
/** How many windows are open, for tests and the status report. */
|
|
34246
|
+
windowCount() {
|
|
34247
|
+
return this.windows.size;
|
|
34126
34248
|
}
|
|
34127
34249
|
};
|
|
34128
34250
|
|
|
34129
34251
|
// src/daemon/rules/loader.ts
|
|
34130
|
-
var
|
|
34131
|
-
var
|
|
34252
|
+
var import_node_fs30 = require("fs");
|
|
34253
|
+
var import_node_path21 = require("path");
|
|
34132
34254
|
|
|
34133
34255
|
// src/daemon/rules/default-rules.ts
|
|
34134
34256
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -34529,11 +34651,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
34529
34651
|
function loadAllRules(customDir) {
|
|
34530
34652
|
const rules = [...DEFAULT_RULES];
|
|
34531
34653
|
const dir = customDir || RULES_DIR;
|
|
34532
|
-
if ((0,
|
|
34533
|
-
const files = (0,
|
|
34654
|
+
if ((0, import_node_fs30.existsSync)(dir)) {
|
|
34655
|
+
const files = (0, import_node_fs30.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
34534
34656
|
for (const file of files) {
|
|
34535
34657
|
try {
|
|
34536
|
-
const raw = (0,
|
|
34658
|
+
const raw = (0, import_node_fs30.readFileSync)((0, import_node_path21.join)(dir, file), "utf-8");
|
|
34537
34659
|
const parsed = JSON.parse(raw);
|
|
34538
34660
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
34539
34661
|
for (const rule of customRules) {
|
|
@@ -34564,9 +34686,9 @@ function loadAllRules(customDir) {
|
|
|
34564
34686
|
}
|
|
34565
34687
|
|
|
34566
34688
|
// src/daemon/firewall/adapters.ts
|
|
34567
|
-
var
|
|
34568
|
-
var
|
|
34569
|
-
var
|
|
34689
|
+
var import_node_child_process9 = require("child_process");
|
|
34690
|
+
var import_node_fs31 = require("fs");
|
|
34691
|
+
var import_node_path22 = require("path");
|
|
34570
34692
|
var import_node_net7 = require("net");
|
|
34571
34693
|
function assertValidFirewallIp(ip) {
|
|
34572
34694
|
if ((0, import_node_net7.isIP)(ip) !== 4) {
|
|
@@ -34579,9 +34701,9 @@ function assertBannableIp(ip) {
|
|
|
34579
34701
|
}
|
|
34580
34702
|
}
|
|
34581
34703
|
function writeIfAbsent(path, contents) {
|
|
34582
|
-
(0,
|
|
34704
|
+
(0, import_node_fs31.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
|
|
34583
34705
|
try {
|
|
34584
|
-
(0,
|
|
34706
|
+
(0, import_node_fs31.writeFileSync)(path, contents, { flag: "wx" });
|
|
34585
34707
|
} catch (err) {
|
|
34586
34708
|
if (err.code !== "EEXIST") throw err;
|
|
34587
34709
|
}
|
|
@@ -34600,11 +34722,11 @@ var Fail2banAdapter = class {
|
|
|
34600
34722
|
enforces = true;
|
|
34601
34723
|
jailReady = false;
|
|
34602
34724
|
isAvailable() {
|
|
34603
|
-
const result = (0,
|
|
34725
|
+
const result = (0, import_node_child_process9.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
34604
34726
|
return result.status === 0;
|
|
34605
34727
|
}
|
|
34606
34728
|
client(args) {
|
|
34607
|
-
return (0,
|
|
34729
|
+
return (0, import_node_child_process9.execFileSync)("fail2ban-client", args, {
|
|
34608
34730
|
encoding: "utf-8",
|
|
34609
34731
|
stdio: ["ignore", "pipe", "pipe"]
|
|
34610
34732
|
});
|
|
@@ -34696,35 +34818,35 @@ var NftablesAdapter = class {
|
|
|
34696
34818
|
table = "threatcrush";
|
|
34697
34819
|
set = "blocklist";
|
|
34698
34820
|
isAvailable() {
|
|
34699
|
-
const result = (0,
|
|
34821
|
+
const result = (0, import_node_child_process9.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
34700
34822
|
return result.status === 0;
|
|
34701
34823
|
}
|
|
34702
34824
|
ensureSetup() {
|
|
34703
34825
|
try {
|
|
34704
|
-
(0,
|
|
34826
|
+
(0, import_node_child_process9.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
34705
34827
|
} catch {
|
|
34706
|
-
(0,
|
|
34707
|
-
(0,
|
|
34708
|
-
(0,
|
|
34709
|
-
(0,
|
|
34828
|
+
(0, import_node_child_process9.execSync)(`nft add table inet ${this.table}`);
|
|
34829
|
+
(0, import_node_child_process9.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
34830
|
+
(0, import_node_child_process9.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
34831
|
+
(0, import_node_child_process9.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
34710
34832
|
}
|
|
34711
34833
|
}
|
|
34712
34834
|
async block(ip) {
|
|
34713
34835
|
assertValidFirewallIp(ip);
|
|
34714
34836
|
this.ensureSetup();
|
|
34715
|
-
(0,
|
|
34837
|
+
(0, import_node_child_process9.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
34716
34838
|
}
|
|
34717
34839
|
async unblock(ip) {
|
|
34718
34840
|
assertValidFirewallIp(ip);
|
|
34719
34841
|
try {
|
|
34720
|
-
(0,
|
|
34842
|
+
(0, import_node_child_process9.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
34721
34843
|
} catch {
|
|
34722
34844
|
}
|
|
34723
34845
|
}
|
|
34724
34846
|
async isBlocked(ip) {
|
|
34725
34847
|
assertValidFirewallIp(ip);
|
|
34726
34848
|
try {
|
|
34727
|
-
const output = (0,
|
|
34849
|
+
const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
34728
34850
|
return output.includes(ip);
|
|
34729
34851
|
} catch {
|
|
34730
34852
|
return false;
|
|
@@ -34732,7 +34854,7 @@ var NftablesAdapter = class {
|
|
|
34732
34854
|
}
|
|
34733
34855
|
async listBlocked() {
|
|
34734
34856
|
try {
|
|
34735
|
-
const output = (0,
|
|
34857
|
+
const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
34736
34858
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
34737
34859
|
if (!match) return [];
|
|
34738
34860
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -34745,34 +34867,34 @@ var IptablesAdapter = class {
|
|
|
34745
34867
|
name = "iptables";
|
|
34746
34868
|
chain = "THREATCRUSH";
|
|
34747
34869
|
isAvailable() {
|
|
34748
|
-
const result = (0,
|
|
34870
|
+
const result = (0, import_node_child_process9.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
34749
34871
|
return result.status === 0;
|
|
34750
34872
|
}
|
|
34751
34873
|
ensureChain() {
|
|
34752
34874
|
try {
|
|
34753
|
-
(0,
|
|
34875
|
+
(0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
34754
34876
|
} catch {
|
|
34755
|
-
(0,
|
|
34756
|
-
(0,
|
|
34877
|
+
(0, import_node_child_process9.execSync)(`iptables -N ${this.chain}`);
|
|
34878
|
+
(0, import_node_child_process9.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
34757
34879
|
}
|
|
34758
34880
|
}
|
|
34759
34881
|
async block(ip) {
|
|
34760
34882
|
assertValidFirewallIp(ip);
|
|
34761
34883
|
this.ensureChain();
|
|
34762
34884
|
if (await this.isBlocked(ip)) return;
|
|
34763
|
-
(0,
|
|
34885
|
+
(0, import_node_child_process9.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
34764
34886
|
}
|
|
34765
34887
|
async unblock(ip) {
|
|
34766
34888
|
assertValidFirewallIp(ip);
|
|
34767
34889
|
try {
|
|
34768
|
-
(0,
|
|
34890
|
+
(0, import_node_child_process9.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
34769
34891
|
} catch {
|
|
34770
34892
|
}
|
|
34771
34893
|
}
|
|
34772
34894
|
async isBlocked(ip) {
|
|
34773
34895
|
assertValidFirewallIp(ip);
|
|
34774
34896
|
try {
|
|
34775
|
-
const output = (0,
|
|
34897
|
+
const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
34776
34898
|
return output.includes(ip);
|
|
34777
34899
|
} catch {
|
|
34778
34900
|
return false;
|
|
@@ -34780,7 +34902,7 @@ var IptablesAdapter = class {
|
|
|
34780
34902
|
}
|
|
34781
34903
|
async listBlocked() {
|
|
34782
34904
|
try {
|
|
34783
|
-
const output = (0,
|
|
34905
|
+
const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
34784
34906
|
const ips = [];
|
|
34785
34907
|
for (const line of output.split("\n")) {
|
|
34786
34908
|
const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -34836,7 +34958,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
34836
34958
|
}
|
|
34837
34959
|
|
|
34838
34960
|
// src/daemon/firewall/remediation.ts
|
|
34839
|
-
var
|
|
34961
|
+
var import_node_fs32 = require("fs");
|
|
34840
34962
|
var import_node_net8 = require("net");
|
|
34841
34963
|
init_paths();
|
|
34842
34964
|
init_backoff();
|
|
@@ -34909,6 +35031,10 @@ function isSuccessfulAuth(message) {
|
|
|
34909
35031
|
}
|
|
34910
35032
|
function explainBlockFailure(err, backend) {
|
|
34911
35033
|
const raw = err.message || String(err);
|
|
35034
|
+
if (/EROFS|read-only file system/i.test(raw)) {
|
|
35035
|
+
const path = /open '([^']+)'/.exec(raw)?.[1];
|
|
35036
|
+
return `threatcrushd cannot write ${path ?? "its firewall config"} for ${backend}: the systemd unit mounts it read-only. Reinstall the unit and restart: sudo $(which threatcrush) install-service && sudo systemctl restart threatcrushd`;
|
|
35037
|
+
}
|
|
34912
35038
|
const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
|
|
34913
35039
|
if (!denied) return `${raw} (backend: ${backend})`;
|
|
34914
35040
|
const who = typeof process.getuid === "function" && process.getuid() === 0 ? "as root" : `as uid ${typeof process.getuid === "function" ? process.getuid() : "?"}`;
|
|
@@ -35162,7 +35288,7 @@ var RemediationManager = class {
|
|
|
35162
35288
|
*/
|
|
35163
35289
|
async reconcile() {
|
|
35164
35290
|
const now = Date.now();
|
|
35165
|
-
const
|
|
35291
|
+
const live2 = this.blocklist.filter((b) => b.expires_at > now);
|
|
35166
35292
|
const stale = this.blocklist.filter((b) => b.expires_at <= now);
|
|
35167
35293
|
for (const entry of stale) {
|
|
35168
35294
|
if (!entry.dry_run) {
|
|
@@ -35172,7 +35298,7 @@ var RemediationManager = class {
|
|
|
35172
35298
|
}
|
|
35173
35299
|
}
|
|
35174
35300
|
}
|
|
35175
|
-
this.blocklist =
|
|
35301
|
+
this.blocklist = live2;
|
|
35176
35302
|
this.saveState();
|
|
35177
35303
|
let applied = null;
|
|
35178
35304
|
try {
|
|
@@ -35180,7 +35306,7 @@ var RemediationManager = class {
|
|
|
35180
35306
|
} catch {
|
|
35181
35307
|
}
|
|
35182
35308
|
if (applied) {
|
|
35183
|
-
const known = new Set(
|
|
35309
|
+
const known = new Set(live2.filter((b) => !b.dry_run).map((b) => b.ip));
|
|
35184
35310
|
for (const ip of applied) {
|
|
35185
35311
|
if (known.has(ip)) continue;
|
|
35186
35312
|
this.logLine(`[firewall] reconcile: dropping stale rule for ${ip} (no record of why)`);
|
|
@@ -35191,7 +35317,7 @@ var RemediationManager = class {
|
|
|
35191
35317
|
}
|
|
35192
35318
|
}
|
|
35193
35319
|
if (this.config.dry_run) return;
|
|
35194
|
-
for (const entry of
|
|
35320
|
+
for (const entry of live2) {
|
|
35195
35321
|
if (applied?.includes(entry.ip)) continue;
|
|
35196
35322
|
try {
|
|
35197
35323
|
await this.adapter.block(entry.ip);
|
|
@@ -35246,7 +35372,7 @@ var RemediationManager = class {
|
|
|
35246
35372
|
}
|
|
35247
35373
|
logLine(line) {
|
|
35248
35374
|
try {
|
|
35249
|
-
(0,
|
|
35375
|
+
(0, import_node_fs32.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
35250
35376
|
`);
|
|
35251
35377
|
} catch {
|
|
35252
35378
|
}
|
|
@@ -35284,19 +35410,19 @@ function remediationSettings(section) {
|
|
|
35284
35410
|
init_backoff();
|
|
35285
35411
|
|
|
35286
35412
|
// src/daemon/watchdog-service.ts
|
|
35287
|
-
var
|
|
35288
|
-
var
|
|
35413
|
+
var import_node_fs33 = require("fs");
|
|
35414
|
+
var import_node_path23 = require("path");
|
|
35289
35415
|
function defaultShareGid() {
|
|
35290
35416
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
35291
35417
|
if (!isRoot4) return void 0;
|
|
35292
35418
|
try {
|
|
35293
|
-
return (0,
|
|
35419
|
+
return (0, import_node_fs33.statSync)("/var/log/auth.log").gid;
|
|
35294
35420
|
} catch {
|
|
35295
35421
|
return void 0;
|
|
35296
35422
|
}
|
|
35297
35423
|
}
|
|
35298
35424
|
function startWatchdog(opts) {
|
|
35299
|
-
const dir = opts.config?.dir ?? (0,
|
|
35425
|
+
const dir = opts.config?.dir ?? (0, import_node_path23.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
35300
35426
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
35301
35427
|
if (opts.config?.enabled === false) {
|
|
35302
35428
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -35390,7 +35516,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
35390
35516
|
}
|
|
35391
35517
|
|
|
35392
35518
|
// src/core/node-runtime.ts
|
|
35393
|
-
var
|
|
35519
|
+
var import_node_child_process10 = require("child_process");
|
|
35394
35520
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
35395
35521
|
function nodeMajor(version) {
|
|
35396
35522
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -35404,23 +35530,23 @@ function daemonNodeProblem(version) {
|
|
|
35404
35530
|
}
|
|
35405
35531
|
function versionOfNode(path) {
|
|
35406
35532
|
if (path === process.execPath) return process.versions.node;
|
|
35407
|
-
const res = (0,
|
|
35533
|
+
const res = (0, import_node_child_process10.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
35408
35534
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
35409
35535
|
}
|
|
35410
35536
|
|
|
35411
35537
|
// src/daemon/index.ts
|
|
35412
35538
|
function readVersion2() {
|
|
35413
35539
|
try {
|
|
35414
|
-
const pkg = JSON.parse((0,
|
|
35540
|
+
const pkg = JSON.parse((0, import_node_fs34.readFileSync)((0, import_node_path24.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
35415
35541
|
return pkg.version || "0.0.0";
|
|
35416
35542
|
} catch {
|
|
35417
35543
|
return "0.0.0";
|
|
35418
35544
|
}
|
|
35419
35545
|
}
|
|
35420
35546
|
async function runHardeningChecks() {
|
|
35421
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
35547
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
|
|
35422
35548
|
process.execPath,
|
|
35423
|
-
[(0,
|
|
35549
|
+
[(0, import_node_path24.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
35424
35550
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
35425
35551
|
);
|
|
35426
35552
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -35428,7 +35554,7 @@ async function runHardeningChecks() {
|
|
|
35428
35554
|
}
|
|
35429
35555
|
function logLine(line) {
|
|
35430
35556
|
try {
|
|
35431
|
-
(0,
|
|
35557
|
+
(0, import_node_fs34.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
35432
35558
|
`);
|
|
35433
35559
|
} catch {
|
|
35434
35560
|
}
|
|
@@ -35453,9 +35579,9 @@ async function runDaemon() {
|
|
|
35453
35579
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
35454
35580
|
const restartDaemon = () => {
|
|
35455
35581
|
if (PATHS.mode === "system") {
|
|
35456
|
-
(0,
|
|
35582
|
+
(0, import_node_child_process11.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
35457
35583
|
} else {
|
|
35458
|
-
(0,
|
|
35584
|
+
(0, import_node_child_process11.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
35459
35585
|
setTimeout(() => process.exit(0), 500).unref();
|
|
35460
35586
|
}
|
|
35461
35587
|
};
|
|
@@ -35470,7 +35596,7 @@ async function runDaemon() {
|
|
|
35470
35596
|
} catch (err) {
|
|
35471
35597
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
35472
35598
|
}
|
|
35473
|
-
const config = loadConfig((0,
|
|
35599
|
+
const config = loadConfig((0, import_node_fs34.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
35474
35600
|
configureAttackDetection(config.detection);
|
|
35475
35601
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
35476
35602
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -35511,7 +35637,7 @@ async function runDaemon() {
|
|
|
35511
35637
|
if (event.module !== "rule-engine") ruleEngine.evaluate(event);
|
|
35512
35638
|
});
|
|
35513
35639
|
logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
|
|
35514
|
-
setInterval(() => ruleEngine.cleanup(),
|
|
35640
|
+
setInterval(() => ruleEngine.cleanup(), 6e4);
|
|
35515
35641
|
const settings = remediationSettings(config.remediation);
|
|
35516
35642
|
const firewallAdapter = detectFirewallAdapter(config.remediation?.backend ?? "auto");
|
|
35517
35643
|
const remediation = new RemediationManager(firewallAdapter, bus, settings);
|
|
@@ -35547,9 +35673,9 @@ async function runDaemon() {
|
|
|
35547
35673
|
cloudSync = new CloudSync({
|
|
35548
35674
|
bus,
|
|
35549
35675
|
version,
|
|
35550
|
-
hostname: (0,
|
|
35676
|
+
hostname: (0, import_node_os10.hostname)(),
|
|
35551
35677
|
minSeverity,
|
|
35552
|
-
spoolPath: (0,
|
|
35678
|
+
spoolPath: (0, import_node_path24.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
35553
35679
|
log: logLine,
|
|
35554
35680
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
35555
35681
|
runHardening: runHardeningChecks
|
|
@@ -35631,7 +35757,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
35631
35757
|
function isRoot2() {
|
|
35632
35758
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
35633
35759
|
}
|
|
35634
|
-
var DAEMON_ENTRY = (0,
|
|
35760
|
+
var DAEMON_ENTRY = (0, import_node_path25.join)(__dirname, "daemon.js");
|
|
35635
35761
|
async function daemonForeground() {
|
|
35636
35762
|
await runDaemon();
|
|
35637
35763
|
}
|
|
@@ -35652,7 +35778,7 @@ async function daemonStart() {
|
|
|
35652
35778
|
return;
|
|
35653
35779
|
}
|
|
35654
35780
|
ensureRuntimeDirs();
|
|
35655
|
-
if (!(0,
|
|
35781
|
+
if (!(0, import_node_fs35.existsSync)(DAEMON_ENTRY)) {
|
|
35656
35782
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
35657
35783
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
35658
35784
|
return;
|
|
@@ -35660,8 +35786,8 @@ async function daemonStart() {
|
|
|
35660
35786
|
let out;
|
|
35661
35787
|
let err;
|
|
35662
35788
|
try {
|
|
35663
|
-
out = (0,
|
|
35664
|
-
err = (0,
|
|
35789
|
+
out = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
|
|
35790
|
+
err = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
|
|
35665
35791
|
} catch (e) {
|
|
35666
35792
|
const code = e.code;
|
|
35667
35793
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -35674,7 +35800,7 @@ async function daemonStart() {
|
|
|
35674
35800
|
}
|
|
35675
35801
|
return;
|
|
35676
35802
|
}
|
|
35677
|
-
const child = (0,
|
|
35803
|
+
const child = (0, import_node_child_process12.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
35678
35804
|
detached: true,
|
|
35679
35805
|
stdio: ["ignore", out, err],
|
|
35680
35806
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -35749,41 +35875,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
35749
35875
|
}
|
|
35750
35876
|
async function releaseStaleSocket() {
|
|
35751
35877
|
const deadline = Date.now() + 2e3;
|
|
35752
|
-
while ((0,
|
|
35878
|
+
while ((0, import_node_fs35.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
35753
35879
|
await new Promise((r) => setTimeout(r, 50));
|
|
35754
35880
|
}
|
|
35755
|
-
if ((0,
|
|
35881
|
+
if ((0, import_node_fs35.existsSync)(PATHS.socket)) {
|
|
35756
35882
|
try {
|
|
35757
|
-
(0,
|
|
35883
|
+
(0, import_node_fs35.unlinkSync)(PATHS.socket);
|
|
35758
35884
|
} catch {
|
|
35759
35885
|
}
|
|
35760
35886
|
}
|
|
35761
35887
|
}
|
|
35762
35888
|
|
|
35763
35889
|
// src/commands/service.ts
|
|
35764
|
-
var
|
|
35765
|
-
var
|
|
35766
|
-
var
|
|
35767
|
-
var
|
|
35890
|
+
var import_node_child_process13 = require("child_process");
|
|
35891
|
+
var import_node_fs37 = require("fs");
|
|
35892
|
+
var import_node_path26 = require("path");
|
|
35893
|
+
var import_node_os11 = require("os");
|
|
35768
35894
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
35769
35895
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
35770
35896
|
function resolveTemplate() {
|
|
35771
|
-
const templatePath = (0,
|
|
35772
|
-
if (!(0,
|
|
35897
|
+
const templatePath = (0, import_node_path26.join)(__dirname, "systemd", "threatcrushd.service");
|
|
35898
|
+
if (!(0, import_node_fs37.existsSync)(templatePath)) {
|
|
35773
35899
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
35774
35900
|
}
|
|
35775
|
-
return (0,
|
|
35901
|
+
return (0, import_node_fs37.readFileSync)(templatePath, "utf-8");
|
|
35776
35902
|
}
|
|
35777
35903
|
function stableBinPath(binPath) {
|
|
35778
35904
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
35779
35905
|
if (stable === binPath) return binPath;
|
|
35780
|
-
return (0,
|
|
35906
|
+
return (0, import_node_fs37.existsSync)(stable) ? stable : binPath;
|
|
35781
35907
|
}
|
|
35782
35908
|
function resolveBinPath() {
|
|
35783
35909
|
const arg = process.argv[1];
|
|
35784
|
-
if (arg && (0,
|
|
35910
|
+
if (arg && (0, import_node_fs37.existsSync)(arg)) return stableBinPath(arg);
|
|
35785
35911
|
try {
|
|
35786
|
-
return (0,
|
|
35912
|
+
return (0, import_node_child_process13.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
35787
35913
|
} catch {
|
|
35788
35914
|
return "threatcrush";
|
|
35789
35915
|
}
|
|
@@ -35791,11 +35917,11 @@ function resolveBinPath() {
|
|
|
35791
35917
|
function stableNodePath(execPath) {
|
|
35792
35918
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
35793
35919
|
if (stable === execPath) return execPath;
|
|
35794
|
-
return (0,
|
|
35920
|
+
return (0, import_node_fs37.existsSync)(stable) ? stable : execPath;
|
|
35795
35921
|
}
|
|
35796
35922
|
function looksLikeNodeScript(path) {
|
|
35797
35923
|
try {
|
|
35798
|
-
const head = (0,
|
|
35924
|
+
const head = (0, import_node_fs37.readFileSync)(path, "utf-8").slice(0, 120);
|
|
35799
35925
|
return /^#!.*\bnode\b/.test(head);
|
|
35800
35926
|
} catch {
|
|
35801
35927
|
return false;
|
|
@@ -35822,20 +35948,20 @@ function isRoot3() {
|
|
|
35822
35948
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
35823
35949
|
}
|
|
35824
35950
|
function reexecWithSudo(args) {
|
|
35825
|
-
if ((0,
|
|
35951
|
+
if ((0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
35826
35952
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
35827
35953
|
const bin = resolveBinPath();
|
|
35828
35954
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
35829
|
-
const result = (0,
|
|
35955
|
+
const result = (0, import_node_child_process13.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
35830
35956
|
return result.status === 0;
|
|
35831
35957
|
}
|
|
35832
35958
|
function callerHome() {
|
|
35833
35959
|
const user = process.env.SUDO_USER;
|
|
35834
35960
|
if (!user) return null;
|
|
35835
35961
|
try {
|
|
35836
|
-
const line = (0,
|
|
35962
|
+
const line = (0, import_node_child_process13.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
35837
35963
|
const home = line.split(":")[5];
|
|
35838
|
-
return home && (0,
|
|
35964
|
+
return home && (0, import_node_fs37.existsSync)(home) ? home : null;
|
|
35839
35965
|
} catch {
|
|
35840
35966
|
return null;
|
|
35841
35967
|
}
|
|
@@ -35843,13 +35969,13 @@ function callerHome() {
|
|
|
35843
35969
|
function stopUserModeDaemon() {
|
|
35844
35970
|
const home = callerHome();
|
|
35845
35971
|
if (!home) return;
|
|
35846
|
-
const runDir = (0,
|
|
35847
|
-
const pidFile = (0,
|
|
35848
|
-
const socket = (0,
|
|
35849
|
-
if (!(0,
|
|
35972
|
+
const runDir = (0, import_node_path26.join)(home, ".threatcrush", "run");
|
|
35973
|
+
const pidFile = (0, import_node_path26.join)(runDir, "threatcrushd.pid");
|
|
35974
|
+
const socket = (0, import_node_path26.join)(runDir, "threatcrushd.sock");
|
|
35975
|
+
if (!(0, import_node_fs37.existsSync)(pidFile) && !(0, import_node_fs37.existsSync)(socket)) return;
|
|
35850
35976
|
let pid = null;
|
|
35851
35977
|
try {
|
|
35852
|
-
pid = Number.parseInt((0,
|
|
35978
|
+
pid = Number.parseInt((0, import_node_fs37.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
35853
35979
|
} catch {
|
|
35854
35980
|
pid = null;
|
|
35855
35981
|
}
|
|
@@ -35862,13 +35988,13 @@ function stopUserModeDaemon() {
|
|
|
35862
35988
|
}
|
|
35863
35989
|
for (const path of [socket, pidFile]) {
|
|
35864
35990
|
try {
|
|
35865
|
-
if ((0,
|
|
35991
|
+
if ((0, import_node_fs37.existsSync)(path)) (0, import_node_fs37.rmSync)(path);
|
|
35866
35992
|
} catch {
|
|
35867
35993
|
}
|
|
35868
35994
|
}
|
|
35869
35995
|
}
|
|
35870
35996
|
function unitIsActive() {
|
|
35871
|
-
const result = (0,
|
|
35997
|
+
const result = (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
35872
35998
|
return result.status === 0;
|
|
35873
35999
|
}
|
|
35874
36000
|
async function installServiceCommand() {
|
|
@@ -35879,8 +36005,8 @@ async function installServiceCommand() {
|
|
|
35879
36005
|
return;
|
|
35880
36006
|
}
|
|
35881
36007
|
const noSystemd = systemdUnavailableReason({
|
|
35882
|
-
hasSystemctl: (0,
|
|
35883
|
-
booted: (0,
|
|
36008
|
+
hasSystemctl: (0, import_node_child_process13.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
36009
|
+
booted: (0, import_node_fs37.existsSync)("/run/systemd/system")
|
|
35884
36010
|
});
|
|
35885
36011
|
if (noSystemd) {
|
|
35886
36012
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -35902,7 +36028,7 @@ async function installServiceCommand() {
|
|
|
35902
36028
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
35903
36029
|
let nodePath = stableNodePath(process.execPath);
|
|
35904
36030
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
35905
|
-
binPath = (0,
|
|
36031
|
+
binPath = (0, import_node_fs37.realpathSync)(binPath);
|
|
35906
36032
|
nodePath = process.execPath;
|
|
35907
36033
|
}
|
|
35908
36034
|
if (isNodeScript) {
|
|
@@ -35915,9 +36041,9 @@ async function installServiceCommand() {
|
|
|
35915
36041
|
}
|
|
35916
36042
|
}
|
|
35917
36043
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
35918
|
-
const configDir = (0,
|
|
36044
|
+
const configDir = (0, import_node_path26.join)((0, import_node_os11.homedir)(), ".threatcrush");
|
|
35919
36045
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
35920
|
-
(0,
|
|
36046
|
+
(0, import_node_fs37.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
35921
36047
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
35922
36048
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
35923
36049
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -35931,8 +36057,8 @@ async function installServiceCommand() {
|
|
|
35931
36057
|
ensureSystemDirs(configDir);
|
|
35932
36058
|
stopUserModeDaemon();
|
|
35933
36059
|
try {
|
|
35934
|
-
(0,
|
|
35935
|
-
(0,
|
|
36060
|
+
(0, import_node_child_process13.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
36061
|
+
(0, import_node_child_process13.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
35936
36062
|
} catch (err) {
|
|
35937
36063
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
35938
36064
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -35966,20 +36092,20 @@ function ensureSystemDirs(configDir) {
|
|
|
35966
36092
|
];
|
|
35967
36093
|
let admGid = null;
|
|
35968
36094
|
try {
|
|
35969
|
-
admGid = (0,
|
|
36095
|
+
admGid = (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
|
|
35970
36096
|
} catch {
|
|
35971
36097
|
}
|
|
35972
36098
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
35973
36099
|
try {
|
|
35974
|
-
(0,
|
|
36100
|
+
(0, import_node_fs37.mkdirSync)(path, { recursive: true });
|
|
35975
36101
|
} catch {
|
|
35976
36102
|
}
|
|
35977
36103
|
try {
|
|
35978
36104
|
if (groupWritable && admGid !== null) {
|
|
35979
|
-
(0,
|
|
35980
|
-
(0,
|
|
36105
|
+
(0, import_node_fs37.chmodSync)(path, sticky ? 1533 : 509);
|
|
36106
|
+
(0, import_node_child_process13.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
35981
36107
|
} else {
|
|
35982
|
-
(0,
|
|
36108
|
+
(0, import_node_fs37.chmodSync)(path, 493);
|
|
35983
36109
|
}
|
|
35984
36110
|
} catch {
|
|
35985
36111
|
}
|
|
@@ -35999,29 +36125,29 @@ async function uninstallServiceCommand() {
|
|
|
35999
36125
|
return;
|
|
36000
36126
|
}
|
|
36001
36127
|
try {
|
|
36002
|
-
(0,
|
|
36128
|
+
(0, import_node_child_process13.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
36003
36129
|
} catch {
|
|
36004
36130
|
}
|
|
36005
36131
|
try {
|
|
36006
|
-
(0,
|
|
36132
|
+
(0, import_node_child_process13.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
36007
36133
|
} catch {
|
|
36008
36134
|
}
|
|
36009
36135
|
try {
|
|
36010
|
-
if ((0,
|
|
36011
|
-
(0,
|
|
36136
|
+
if ((0, import_node_fs37.existsSync)(UNIT_PATH)) {
|
|
36137
|
+
(0, import_node_child_process13.execSync)(`rm -f ${UNIT_PATH}`);
|
|
36012
36138
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
36013
36139
|
}
|
|
36014
36140
|
} catch {
|
|
36015
36141
|
}
|
|
36016
36142
|
try {
|
|
36017
|
-
(0,
|
|
36143
|
+
(0, import_node_child_process13.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
36018
36144
|
} catch {
|
|
36019
36145
|
}
|
|
36020
36146
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
36021
36147
|
}
|
|
36022
36148
|
|
|
36023
36149
|
// src/commands/save.ts
|
|
36024
|
-
var
|
|
36150
|
+
var import_node_fs38 = require("fs");
|
|
36025
36151
|
var import_toml5 = __toESM(require_toml());
|
|
36026
36152
|
init_paths();
|
|
36027
36153
|
var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
|
|
@@ -36059,9 +36185,9 @@ async function saveCommand(opts = {}) {
|
|
|
36059
36185
|
}
|
|
36060
36186
|
const path = opts.config ?? PATHS.configFile;
|
|
36061
36187
|
let config = {};
|
|
36062
|
-
if ((0,
|
|
36188
|
+
if ((0, import_node_fs38.existsSync)(path)) {
|
|
36063
36189
|
try {
|
|
36064
|
-
config = import_toml5.default.parse((0,
|
|
36190
|
+
config = import_toml5.default.parse((0, import_node_fs38.readFileSync)(path, "utf-8"));
|
|
36065
36191
|
} catch (err) {
|
|
36066
36192
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
36067
36193
|
`));
|
|
@@ -36173,8 +36299,8 @@ function welcomeCommand() {
|
|
|
36173
36299
|
}
|
|
36174
36300
|
|
|
36175
36301
|
// src/commands/properties.ts
|
|
36176
|
-
var
|
|
36177
|
-
var
|
|
36302
|
+
var import_node_fs39 = require("fs");
|
|
36303
|
+
var import_node_path27 = require("path");
|
|
36178
36304
|
var import_node_readline4 = __toESM(require("readline"));
|
|
36179
36305
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
36180
36306
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
@@ -36503,8 +36629,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
36503
36629
|
}
|
|
36504
36630
|
}
|
|
36505
36631
|
function parseImportFile(path) {
|
|
36506
|
-
const ext = (0,
|
|
36507
|
-
const raw = (0,
|
|
36632
|
+
const ext = (0, import_node_path27.extname)(path).toLowerCase();
|
|
36633
|
+
const raw = (0, import_node_fs39.readFileSync)(path, "utf-8");
|
|
36508
36634
|
if (ext === ".json") {
|
|
36509
36635
|
const parsed = JSON.parse(raw);
|
|
36510
36636
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -36699,18 +36825,18 @@ async function rulesCommand(opts) {
|
|
|
36699
36825
|
}
|
|
36700
36826
|
|
|
36701
36827
|
// src/commands/harden.ts
|
|
36702
|
-
var
|
|
36703
|
-
var
|
|
36828
|
+
var import_node_fs40 = require("fs");
|
|
36829
|
+
var import_node_child_process14 = require("child_process");
|
|
36704
36830
|
function tryExec(cmd) {
|
|
36705
36831
|
try {
|
|
36706
|
-
return (0,
|
|
36832
|
+
return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
36707
36833
|
} catch {
|
|
36708
36834
|
return null;
|
|
36709
36835
|
}
|
|
36710
36836
|
}
|
|
36711
36837
|
function tryRead(path) {
|
|
36712
36838
|
try {
|
|
36713
|
-
return (0,
|
|
36839
|
+
return (0, import_node_fs40.readFileSync)(path, "utf-8");
|
|
36714
36840
|
} catch {
|
|
36715
36841
|
return null;
|
|
36716
36842
|
}
|
|
@@ -36814,8 +36940,8 @@ function checkSshWeakConfig() {
|
|
|
36814
36940
|
};
|
|
36815
36941
|
}
|
|
36816
36942
|
function checkAutoUpdates() {
|
|
36817
|
-
const unattended = (0,
|
|
36818
|
-
const dnfAuto = (0,
|
|
36943
|
+
const unattended = (0, import_node_fs40.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs40.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
36944
|
+
const dnfAuto = (0, import_node_fs40.existsSync)("/etc/dnf/automatic.conf");
|
|
36819
36945
|
if (unattended || dnfAuto) {
|
|
36820
36946
|
return {
|
|
36821
36947
|
key: "auto-updates",
|
|
@@ -36941,7 +37067,7 @@ function checkFail2ban() {
|
|
|
36941
37067
|
explanation: "fail2ban is installed and running."
|
|
36942
37068
|
};
|
|
36943
37069
|
}
|
|
36944
|
-
if ((0,
|
|
37070
|
+
if ((0, import_node_fs40.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
36945
37071
|
return {
|
|
36946
37072
|
key: checkKey,
|
|
36947
37073
|
status: "warn",
|
|
@@ -37270,11 +37396,11 @@ async function allowlistCommand(opts) {
|
|
|
37270
37396
|
init_paths();
|
|
37271
37397
|
|
|
37272
37398
|
// src/upgrade.ts
|
|
37273
|
-
var
|
|
37399
|
+
var import_node_child_process15 = require("child_process");
|
|
37274
37400
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
37275
37401
|
var defaultRunner = (cmd) => {
|
|
37276
37402
|
try {
|
|
37277
|
-
return (0,
|
|
37403
|
+
return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
37278
37404
|
} catch {
|
|
37279
37405
|
return null;
|
|
37280
37406
|
}
|
|
@@ -37389,25 +37515,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
37389
37515
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
37390
37516
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
37391
37517
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
37392
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
37518
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "install.json");
|
|
37393
37519
|
function detectPackageManager() {
|
|
37394
37520
|
try {
|
|
37395
|
-
const npmGlobal = (0,
|
|
37521
|
+
const npmGlobal = (0, import_node_child_process16.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
37396
37522
|
if (npmGlobal.includes(PKG_NAME)) return "npm";
|
|
37397
37523
|
} catch {
|
|
37398
37524
|
}
|
|
37399
37525
|
try {
|
|
37400
|
-
(0,
|
|
37526
|
+
(0, import_node_child_process16.execSync)("pnpm --version", { stdio: "pipe" });
|
|
37401
37527
|
return "pnpm";
|
|
37402
37528
|
} catch {
|
|
37403
37529
|
}
|
|
37404
37530
|
try {
|
|
37405
|
-
(0,
|
|
37531
|
+
(0, import_node_child_process16.execSync)("yarn --version", { stdio: "pipe" });
|
|
37406
37532
|
return "yarn";
|
|
37407
37533
|
} catch {
|
|
37408
37534
|
}
|
|
37409
37535
|
try {
|
|
37410
|
-
(0,
|
|
37536
|
+
(0, import_node_child_process16.execSync)("bun --version", { stdio: "pipe" });
|
|
37411
37537
|
return "bun";
|
|
37412
37538
|
} catch {
|
|
37413
37539
|
}
|
|
@@ -37415,14 +37541,14 @@ function detectPackageManager() {
|
|
|
37415
37541
|
}
|
|
37416
37542
|
function readInstallConfig() {
|
|
37417
37543
|
try {
|
|
37418
|
-
return JSON.parse((0,
|
|
37544
|
+
return JSON.parse((0, import_node_fs41.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
37419
37545
|
} catch {
|
|
37420
37546
|
return {};
|
|
37421
37547
|
}
|
|
37422
37548
|
}
|
|
37423
37549
|
function packageLooksInstalled(pm, pkgName) {
|
|
37424
37550
|
try {
|
|
37425
|
-
const output = (0,
|
|
37551
|
+
const output = (0, import_node_child_process16.execSync)(globalListCommand(pm, pkgName), {
|
|
37426
37552
|
encoding: "utf-8",
|
|
37427
37553
|
stdio: ["pipe", "pipe", "pipe"]
|
|
37428
37554
|
});
|
|
@@ -37455,8 +37581,8 @@ async function liveDaemon() {
|
|
|
37455
37581
|
const client = new IpcClient();
|
|
37456
37582
|
try {
|
|
37457
37583
|
await client.connect();
|
|
37458
|
-
const
|
|
37459
|
-
return { pid, version:
|
|
37584
|
+
const live2 = await client.status();
|
|
37585
|
+
return { pid, version: live2.version ?? null };
|
|
37460
37586
|
} catch {
|
|
37461
37587
|
return { pid, version: null };
|
|
37462
37588
|
} finally {
|
|
@@ -37525,14 +37651,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
37525
37651
|
function restartSystemdDaemon() {
|
|
37526
37652
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
37527
37653
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
37528
|
-
if (!asRoot && (0,
|
|
37654
|
+
if (!asRoot && (0, import_node_child_process16.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
37529
37655
|
const [cmd, ...args] = argv;
|
|
37530
|
-
if ((0,
|
|
37531
|
-
return (0,
|
|
37656
|
+
if ((0, import_node_child_process16.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
37657
|
+
return (0, import_node_child_process16.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
37532
37658
|
}
|
|
37533
37659
|
function execQuiet(cmd) {
|
|
37534
37660
|
try {
|
|
37535
|
-
return (0,
|
|
37661
|
+
return (0, import_node_child_process16.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
37536
37662
|
} catch {
|
|
37537
37663
|
return null;
|
|
37538
37664
|
}
|
|
@@ -37708,7 +37834,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
37708
37834
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
37709
37835
|
console.log(LOGO2);
|
|
37710
37836
|
const logPath = PATHS.logFile;
|
|
37711
|
-
if (!(0,
|
|
37837
|
+
if (!(0, import_node_fs41.existsSync)(logPath)) {
|
|
37712
37838
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
37713
37839
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
37714
37840
|
return;
|
|
@@ -37716,7 +37842,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
37716
37842
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
37717
37843
|
`));
|
|
37718
37844
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
37719
|
-
(0,
|
|
37845
|
+
(0, import_node_child_process16.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
37720
37846
|
});
|
|
37721
37847
|
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) => {
|
|
37722
37848
|
console.log(LOGO2);
|
|
@@ -37728,7 +37854,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
37728
37854
|
for (const cmd of commands2) {
|
|
37729
37855
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37730
37856
|
`));
|
|
37731
|
-
(0,
|
|
37857
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37732
37858
|
}
|
|
37733
37859
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
37734
37860
|
await reportIfStillStale();
|
|
@@ -37753,7 +37879,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
37753
37879
|
for (const cmd of commands) {
|
|
37754
37880
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37755
37881
|
`));
|
|
37756
|
-
(0,
|
|
37882
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37757
37883
|
}
|
|
37758
37884
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
37759
37885
|
if (installMode === "desktop") {
|
|
@@ -37804,7 +37930,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
37804
37930
|
for (const cmd of commands) {
|
|
37805
37931
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37806
37932
|
`));
|
|
37807
|
-
(0,
|
|
37933
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37808
37934
|
}
|
|
37809
37935
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
37810
37936
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -37881,10 +38007,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
37881
38007
|
});
|
|
37882
38008
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
37883
38009
|
console.log(LOGO2);
|
|
37884
|
-
const configPath = (0,
|
|
38010
|
+
const configPath = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
|
|
37885
38011
|
let email = "";
|
|
37886
38012
|
try {
|
|
37887
|
-
const config = JSON.parse((0,
|
|
38013
|
+
const config = JSON.parse((0, import_node_fs41.readFileSync)(configPath, "utf-8"));
|
|
37888
38014
|
email = config.email || "";
|
|
37889
38015
|
} catch {
|
|
37890
38016
|
}
|
|
@@ -37901,9 +38027,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
37901
38027
|
return;
|
|
37902
38028
|
}
|
|
37903
38029
|
try {
|
|
37904
|
-
const dir = (0,
|
|
37905
|
-
if (!(0,
|
|
37906
|
-
(0,
|
|
38030
|
+
const dir = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush");
|
|
38031
|
+
if (!(0, import_node_fs41.existsSync)(dir)) (0, import_node_fs41.mkdirSync)(dir, { recursive: true });
|
|
38032
|
+
(0, import_node_fs41.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
37907
38033
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
37908
38034
|
} catch {
|
|
37909
38035
|
}
|