@profullstack/threatcrush 0.13.23 → 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 +4 -0
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +461 -375
- 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
|
}
|
|
@@ -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]);
|
|
@@ -34167,8 +34249,8 @@ var RuleEngine = class {
|
|
|
34167
34249
|
};
|
|
34168
34250
|
|
|
34169
34251
|
// src/daemon/rules/loader.ts
|
|
34170
|
-
var
|
|
34171
|
-
var
|
|
34252
|
+
var import_node_fs30 = require("fs");
|
|
34253
|
+
var import_node_path21 = require("path");
|
|
34172
34254
|
|
|
34173
34255
|
// src/daemon/rules/default-rules.ts
|
|
34174
34256
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -34569,11 +34651,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
34569
34651
|
function loadAllRules(customDir) {
|
|
34570
34652
|
const rules = [...DEFAULT_RULES];
|
|
34571
34653
|
const dir = customDir || RULES_DIR;
|
|
34572
|
-
if ((0,
|
|
34573
|
-
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"));
|
|
34574
34656
|
for (const file of files) {
|
|
34575
34657
|
try {
|
|
34576
|
-
const raw = (0,
|
|
34658
|
+
const raw = (0, import_node_fs30.readFileSync)((0, import_node_path21.join)(dir, file), "utf-8");
|
|
34577
34659
|
const parsed = JSON.parse(raw);
|
|
34578
34660
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
34579
34661
|
for (const rule of customRules) {
|
|
@@ -34604,9 +34686,9 @@ function loadAllRules(customDir) {
|
|
|
34604
34686
|
}
|
|
34605
34687
|
|
|
34606
34688
|
// src/daemon/firewall/adapters.ts
|
|
34607
|
-
var
|
|
34608
|
-
var
|
|
34609
|
-
var
|
|
34689
|
+
var import_node_child_process9 = require("child_process");
|
|
34690
|
+
var import_node_fs31 = require("fs");
|
|
34691
|
+
var import_node_path22 = require("path");
|
|
34610
34692
|
var import_node_net7 = require("net");
|
|
34611
34693
|
function assertValidFirewallIp(ip) {
|
|
34612
34694
|
if ((0, import_node_net7.isIP)(ip) !== 4) {
|
|
@@ -34619,9 +34701,9 @@ function assertBannableIp(ip) {
|
|
|
34619
34701
|
}
|
|
34620
34702
|
}
|
|
34621
34703
|
function writeIfAbsent(path, contents) {
|
|
34622
|
-
(0,
|
|
34704
|
+
(0, import_node_fs31.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
|
|
34623
34705
|
try {
|
|
34624
|
-
(0,
|
|
34706
|
+
(0, import_node_fs31.writeFileSync)(path, contents, { flag: "wx" });
|
|
34625
34707
|
} catch (err) {
|
|
34626
34708
|
if (err.code !== "EEXIST") throw err;
|
|
34627
34709
|
}
|
|
@@ -34640,11 +34722,11 @@ var Fail2banAdapter = class {
|
|
|
34640
34722
|
enforces = true;
|
|
34641
34723
|
jailReady = false;
|
|
34642
34724
|
isAvailable() {
|
|
34643
|
-
const result = (0,
|
|
34725
|
+
const result = (0, import_node_child_process9.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
34644
34726
|
return result.status === 0;
|
|
34645
34727
|
}
|
|
34646
34728
|
client(args) {
|
|
34647
|
-
return (0,
|
|
34729
|
+
return (0, import_node_child_process9.execFileSync)("fail2ban-client", args, {
|
|
34648
34730
|
encoding: "utf-8",
|
|
34649
34731
|
stdio: ["ignore", "pipe", "pipe"]
|
|
34650
34732
|
});
|
|
@@ -34736,35 +34818,35 @@ var NftablesAdapter = class {
|
|
|
34736
34818
|
table = "threatcrush";
|
|
34737
34819
|
set = "blocklist";
|
|
34738
34820
|
isAvailable() {
|
|
34739
|
-
const result = (0,
|
|
34821
|
+
const result = (0, import_node_child_process9.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
34740
34822
|
return result.status === 0;
|
|
34741
34823
|
}
|
|
34742
34824
|
ensureSetup() {
|
|
34743
34825
|
try {
|
|
34744
|
-
(0,
|
|
34826
|
+
(0, import_node_child_process9.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
34745
34827
|
} catch {
|
|
34746
|
-
(0,
|
|
34747
|
-
(0,
|
|
34748
|
-
(0,
|
|
34749
|
-
(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`);
|
|
34750
34832
|
}
|
|
34751
34833
|
}
|
|
34752
34834
|
async block(ip) {
|
|
34753
34835
|
assertValidFirewallIp(ip);
|
|
34754
34836
|
this.ensureSetup();
|
|
34755
|
-
(0,
|
|
34837
|
+
(0, import_node_child_process9.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
34756
34838
|
}
|
|
34757
34839
|
async unblock(ip) {
|
|
34758
34840
|
assertValidFirewallIp(ip);
|
|
34759
34841
|
try {
|
|
34760
|
-
(0,
|
|
34842
|
+
(0, import_node_child_process9.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
34761
34843
|
} catch {
|
|
34762
34844
|
}
|
|
34763
34845
|
}
|
|
34764
34846
|
async isBlocked(ip) {
|
|
34765
34847
|
assertValidFirewallIp(ip);
|
|
34766
34848
|
try {
|
|
34767
|
-
const output = (0,
|
|
34849
|
+
const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
34768
34850
|
return output.includes(ip);
|
|
34769
34851
|
} catch {
|
|
34770
34852
|
return false;
|
|
@@ -34772,7 +34854,7 @@ var NftablesAdapter = class {
|
|
|
34772
34854
|
}
|
|
34773
34855
|
async listBlocked() {
|
|
34774
34856
|
try {
|
|
34775
|
-
const output = (0,
|
|
34857
|
+
const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
34776
34858
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
34777
34859
|
if (!match) return [];
|
|
34778
34860
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -34785,34 +34867,34 @@ var IptablesAdapter = class {
|
|
|
34785
34867
|
name = "iptables";
|
|
34786
34868
|
chain = "THREATCRUSH";
|
|
34787
34869
|
isAvailable() {
|
|
34788
|
-
const result = (0,
|
|
34870
|
+
const result = (0, import_node_child_process9.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
34789
34871
|
return result.status === 0;
|
|
34790
34872
|
}
|
|
34791
34873
|
ensureChain() {
|
|
34792
34874
|
try {
|
|
34793
|
-
(0,
|
|
34875
|
+
(0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
34794
34876
|
} catch {
|
|
34795
|
-
(0,
|
|
34796
|
-
(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}`);
|
|
34797
34879
|
}
|
|
34798
34880
|
}
|
|
34799
34881
|
async block(ip) {
|
|
34800
34882
|
assertValidFirewallIp(ip);
|
|
34801
34883
|
this.ensureChain();
|
|
34802
34884
|
if (await this.isBlocked(ip)) return;
|
|
34803
|
-
(0,
|
|
34885
|
+
(0, import_node_child_process9.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
34804
34886
|
}
|
|
34805
34887
|
async unblock(ip) {
|
|
34806
34888
|
assertValidFirewallIp(ip);
|
|
34807
34889
|
try {
|
|
34808
|
-
(0,
|
|
34890
|
+
(0, import_node_child_process9.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
34809
34891
|
} catch {
|
|
34810
34892
|
}
|
|
34811
34893
|
}
|
|
34812
34894
|
async isBlocked(ip) {
|
|
34813
34895
|
assertValidFirewallIp(ip);
|
|
34814
34896
|
try {
|
|
34815
|
-
const output = (0,
|
|
34897
|
+
const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
34816
34898
|
return output.includes(ip);
|
|
34817
34899
|
} catch {
|
|
34818
34900
|
return false;
|
|
@@ -34820,7 +34902,7 @@ var IptablesAdapter = class {
|
|
|
34820
34902
|
}
|
|
34821
34903
|
async listBlocked() {
|
|
34822
34904
|
try {
|
|
34823
|
-
const output = (0,
|
|
34905
|
+
const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
34824
34906
|
const ips = [];
|
|
34825
34907
|
for (const line of output.split("\n")) {
|
|
34826
34908
|
const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -34876,7 +34958,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
34876
34958
|
}
|
|
34877
34959
|
|
|
34878
34960
|
// src/daemon/firewall/remediation.ts
|
|
34879
|
-
var
|
|
34961
|
+
var import_node_fs32 = require("fs");
|
|
34880
34962
|
var import_node_net8 = require("net");
|
|
34881
34963
|
init_paths();
|
|
34882
34964
|
init_backoff();
|
|
@@ -34949,6 +35031,10 @@ function isSuccessfulAuth(message) {
|
|
|
34949
35031
|
}
|
|
34950
35032
|
function explainBlockFailure(err, backend) {
|
|
34951
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
|
+
}
|
|
34952
35038
|
const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
|
|
34953
35039
|
if (!denied) return `${raw} (backend: ${backend})`;
|
|
34954
35040
|
const who = typeof process.getuid === "function" && process.getuid() === 0 ? "as root" : `as uid ${typeof process.getuid === "function" ? process.getuid() : "?"}`;
|
|
@@ -35286,7 +35372,7 @@ var RemediationManager = class {
|
|
|
35286
35372
|
}
|
|
35287
35373
|
logLine(line) {
|
|
35288
35374
|
try {
|
|
35289
|
-
(0,
|
|
35375
|
+
(0, import_node_fs32.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
35290
35376
|
`);
|
|
35291
35377
|
} catch {
|
|
35292
35378
|
}
|
|
@@ -35324,19 +35410,19 @@ function remediationSettings(section) {
|
|
|
35324
35410
|
init_backoff();
|
|
35325
35411
|
|
|
35326
35412
|
// src/daemon/watchdog-service.ts
|
|
35327
|
-
var
|
|
35328
|
-
var
|
|
35413
|
+
var import_node_fs33 = require("fs");
|
|
35414
|
+
var import_node_path23 = require("path");
|
|
35329
35415
|
function defaultShareGid() {
|
|
35330
35416
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
35331
35417
|
if (!isRoot4) return void 0;
|
|
35332
35418
|
try {
|
|
35333
|
-
return (0,
|
|
35419
|
+
return (0, import_node_fs33.statSync)("/var/log/auth.log").gid;
|
|
35334
35420
|
} catch {
|
|
35335
35421
|
return void 0;
|
|
35336
35422
|
}
|
|
35337
35423
|
}
|
|
35338
35424
|
function startWatchdog(opts) {
|
|
35339
|
-
const dir = opts.config?.dir ?? (0,
|
|
35425
|
+
const dir = opts.config?.dir ?? (0, import_node_path23.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
35340
35426
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
35341
35427
|
if (opts.config?.enabled === false) {
|
|
35342
35428
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -35430,7 +35516,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
35430
35516
|
}
|
|
35431
35517
|
|
|
35432
35518
|
// src/core/node-runtime.ts
|
|
35433
|
-
var
|
|
35519
|
+
var import_node_child_process10 = require("child_process");
|
|
35434
35520
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
35435
35521
|
function nodeMajor(version) {
|
|
35436
35522
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -35444,23 +35530,23 @@ function daemonNodeProblem(version) {
|
|
|
35444
35530
|
}
|
|
35445
35531
|
function versionOfNode(path) {
|
|
35446
35532
|
if (path === process.execPath) return process.versions.node;
|
|
35447
|
-
const res = (0,
|
|
35533
|
+
const res = (0, import_node_child_process10.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
35448
35534
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
35449
35535
|
}
|
|
35450
35536
|
|
|
35451
35537
|
// src/daemon/index.ts
|
|
35452
35538
|
function readVersion2() {
|
|
35453
35539
|
try {
|
|
35454
|
-
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"));
|
|
35455
35541
|
return pkg.version || "0.0.0";
|
|
35456
35542
|
} catch {
|
|
35457
35543
|
return "0.0.0";
|
|
35458
35544
|
}
|
|
35459
35545
|
}
|
|
35460
35546
|
async function runHardeningChecks() {
|
|
35461
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
35547
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
|
|
35462
35548
|
process.execPath,
|
|
35463
|
-
[(0,
|
|
35549
|
+
[(0, import_node_path24.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
35464
35550
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
35465
35551
|
);
|
|
35466
35552
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -35468,7 +35554,7 @@ async function runHardeningChecks() {
|
|
|
35468
35554
|
}
|
|
35469
35555
|
function logLine(line) {
|
|
35470
35556
|
try {
|
|
35471
|
-
(0,
|
|
35557
|
+
(0, import_node_fs34.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
35472
35558
|
`);
|
|
35473
35559
|
} catch {
|
|
35474
35560
|
}
|
|
@@ -35493,9 +35579,9 @@ async function runDaemon() {
|
|
|
35493
35579
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
35494
35580
|
const restartDaemon = () => {
|
|
35495
35581
|
if (PATHS.mode === "system") {
|
|
35496
|
-
(0,
|
|
35582
|
+
(0, import_node_child_process11.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
35497
35583
|
} else {
|
|
35498
|
-
(0,
|
|
35584
|
+
(0, import_node_child_process11.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
35499
35585
|
setTimeout(() => process.exit(0), 500).unref();
|
|
35500
35586
|
}
|
|
35501
35587
|
};
|
|
@@ -35510,7 +35596,7 @@ async function runDaemon() {
|
|
|
35510
35596
|
} catch (err) {
|
|
35511
35597
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
35512
35598
|
}
|
|
35513
|
-
const config = loadConfig((0,
|
|
35599
|
+
const config = loadConfig((0, import_node_fs34.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
35514
35600
|
configureAttackDetection(config.detection);
|
|
35515
35601
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
35516
35602
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -35587,9 +35673,9 @@ async function runDaemon() {
|
|
|
35587
35673
|
cloudSync = new CloudSync({
|
|
35588
35674
|
bus,
|
|
35589
35675
|
version,
|
|
35590
|
-
hostname: (0,
|
|
35676
|
+
hostname: (0, import_node_os10.hostname)(),
|
|
35591
35677
|
minSeverity,
|
|
35592
|
-
spoolPath: (0,
|
|
35678
|
+
spoolPath: (0, import_node_path24.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
35593
35679
|
log: logLine,
|
|
35594
35680
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
35595
35681
|
runHardening: runHardeningChecks
|
|
@@ -35671,7 +35757,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
35671
35757
|
function isRoot2() {
|
|
35672
35758
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
35673
35759
|
}
|
|
35674
|
-
var DAEMON_ENTRY = (0,
|
|
35760
|
+
var DAEMON_ENTRY = (0, import_node_path25.join)(__dirname, "daemon.js");
|
|
35675
35761
|
async function daemonForeground() {
|
|
35676
35762
|
await runDaemon();
|
|
35677
35763
|
}
|
|
@@ -35692,7 +35778,7 @@ async function daemonStart() {
|
|
|
35692
35778
|
return;
|
|
35693
35779
|
}
|
|
35694
35780
|
ensureRuntimeDirs();
|
|
35695
|
-
if (!(0,
|
|
35781
|
+
if (!(0, import_node_fs35.existsSync)(DAEMON_ENTRY)) {
|
|
35696
35782
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
35697
35783
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
35698
35784
|
return;
|
|
@@ -35700,8 +35786,8 @@ async function daemonStart() {
|
|
|
35700
35786
|
let out;
|
|
35701
35787
|
let err;
|
|
35702
35788
|
try {
|
|
35703
|
-
out = (0,
|
|
35704
|
-
err = (0,
|
|
35789
|
+
out = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
|
|
35790
|
+
err = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
|
|
35705
35791
|
} catch (e) {
|
|
35706
35792
|
const code = e.code;
|
|
35707
35793
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -35714,7 +35800,7 @@ async function daemonStart() {
|
|
|
35714
35800
|
}
|
|
35715
35801
|
return;
|
|
35716
35802
|
}
|
|
35717
|
-
const child = (0,
|
|
35803
|
+
const child = (0, import_node_child_process12.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
35718
35804
|
detached: true,
|
|
35719
35805
|
stdio: ["ignore", out, err],
|
|
35720
35806
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -35789,41 +35875,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
35789
35875
|
}
|
|
35790
35876
|
async function releaseStaleSocket() {
|
|
35791
35877
|
const deadline = Date.now() + 2e3;
|
|
35792
|
-
while ((0,
|
|
35878
|
+
while ((0, import_node_fs35.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
35793
35879
|
await new Promise((r) => setTimeout(r, 50));
|
|
35794
35880
|
}
|
|
35795
|
-
if ((0,
|
|
35881
|
+
if ((0, import_node_fs35.existsSync)(PATHS.socket)) {
|
|
35796
35882
|
try {
|
|
35797
|
-
(0,
|
|
35883
|
+
(0, import_node_fs35.unlinkSync)(PATHS.socket);
|
|
35798
35884
|
} catch {
|
|
35799
35885
|
}
|
|
35800
35886
|
}
|
|
35801
35887
|
}
|
|
35802
35888
|
|
|
35803
35889
|
// src/commands/service.ts
|
|
35804
|
-
var
|
|
35805
|
-
var
|
|
35806
|
-
var
|
|
35807
|
-
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");
|
|
35808
35894
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
35809
35895
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
35810
35896
|
function resolveTemplate() {
|
|
35811
|
-
const templatePath = (0,
|
|
35812
|
-
if (!(0,
|
|
35897
|
+
const templatePath = (0, import_node_path26.join)(__dirname, "systemd", "threatcrushd.service");
|
|
35898
|
+
if (!(0, import_node_fs37.existsSync)(templatePath)) {
|
|
35813
35899
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
35814
35900
|
}
|
|
35815
|
-
return (0,
|
|
35901
|
+
return (0, import_node_fs37.readFileSync)(templatePath, "utf-8");
|
|
35816
35902
|
}
|
|
35817
35903
|
function stableBinPath(binPath) {
|
|
35818
35904
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
35819
35905
|
if (stable === binPath) return binPath;
|
|
35820
|
-
return (0,
|
|
35906
|
+
return (0, import_node_fs37.existsSync)(stable) ? stable : binPath;
|
|
35821
35907
|
}
|
|
35822
35908
|
function resolveBinPath() {
|
|
35823
35909
|
const arg = process.argv[1];
|
|
35824
|
-
if (arg && (0,
|
|
35910
|
+
if (arg && (0, import_node_fs37.existsSync)(arg)) return stableBinPath(arg);
|
|
35825
35911
|
try {
|
|
35826
|
-
return (0,
|
|
35912
|
+
return (0, import_node_child_process13.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
35827
35913
|
} catch {
|
|
35828
35914
|
return "threatcrush";
|
|
35829
35915
|
}
|
|
@@ -35831,11 +35917,11 @@ function resolveBinPath() {
|
|
|
35831
35917
|
function stableNodePath(execPath) {
|
|
35832
35918
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
35833
35919
|
if (stable === execPath) return execPath;
|
|
35834
|
-
return (0,
|
|
35920
|
+
return (0, import_node_fs37.existsSync)(stable) ? stable : execPath;
|
|
35835
35921
|
}
|
|
35836
35922
|
function looksLikeNodeScript(path) {
|
|
35837
35923
|
try {
|
|
35838
|
-
const head = (0,
|
|
35924
|
+
const head = (0, import_node_fs37.readFileSync)(path, "utf-8").slice(0, 120);
|
|
35839
35925
|
return /^#!.*\bnode\b/.test(head);
|
|
35840
35926
|
} catch {
|
|
35841
35927
|
return false;
|
|
@@ -35862,20 +35948,20 @@ function isRoot3() {
|
|
|
35862
35948
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
35863
35949
|
}
|
|
35864
35950
|
function reexecWithSudo(args) {
|
|
35865
|
-
if ((0,
|
|
35951
|
+
if ((0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
35866
35952
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
35867
35953
|
const bin = resolveBinPath();
|
|
35868
35954
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
35869
|
-
const result = (0,
|
|
35955
|
+
const result = (0, import_node_child_process13.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
35870
35956
|
return result.status === 0;
|
|
35871
35957
|
}
|
|
35872
35958
|
function callerHome() {
|
|
35873
35959
|
const user = process.env.SUDO_USER;
|
|
35874
35960
|
if (!user) return null;
|
|
35875
35961
|
try {
|
|
35876
|
-
const line = (0,
|
|
35962
|
+
const line = (0, import_node_child_process13.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
35877
35963
|
const home = line.split(":")[5];
|
|
35878
|
-
return home && (0,
|
|
35964
|
+
return home && (0, import_node_fs37.existsSync)(home) ? home : null;
|
|
35879
35965
|
} catch {
|
|
35880
35966
|
return null;
|
|
35881
35967
|
}
|
|
@@ -35883,13 +35969,13 @@ function callerHome() {
|
|
|
35883
35969
|
function stopUserModeDaemon() {
|
|
35884
35970
|
const home = callerHome();
|
|
35885
35971
|
if (!home) return;
|
|
35886
|
-
const runDir = (0,
|
|
35887
|
-
const pidFile = (0,
|
|
35888
|
-
const socket = (0,
|
|
35889
|
-
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;
|
|
35890
35976
|
let pid = null;
|
|
35891
35977
|
try {
|
|
35892
|
-
pid = Number.parseInt((0,
|
|
35978
|
+
pid = Number.parseInt((0, import_node_fs37.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
35893
35979
|
} catch {
|
|
35894
35980
|
pid = null;
|
|
35895
35981
|
}
|
|
@@ -35902,13 +35988,13 @@ function stopUserModeDaemon() {
|
|
|
35902
35988
|
}
|
|
35903
35989
|
for (const path of [socket, pidFile]) {
|
|
35904
35990
|
try {
|
|
35905
|
-
if ((0,
|
|
35991
|
+
if ((0, import_node_fs37.existsSync)(path)) (0, import_node_fs37.rmSync)(path);
|
|
35906
35992
|
} catch {
|
|
35907
35993
|
}
|
|
35908
35994
|
}
|
|
35909
35995
|
}
|
|
35910
35996
|
function unitIsActive() {
|
|
35911
|
-
const result = (0,
|
|
35997
|
+
const result = (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
35912
35998
|
return result.status === 0;
|
|
35913
35999
|
}
|
|
35914
36000
|
async function installServiceCommand() {
|
|
@@ -35919,8 +36005,8 @@ async function installServiceCommand() {
|
|
|
35919
36005
|
return;
|
|
35920
36006
|
}
|
|
35921
36007
|
const noSystemd = systemdUnavailableReason({
|
|
35922
|
-
hasSystemctl: (0,
|
|
35923
|
-
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")
|
|
35924
36010
|
});
|
|
35925
36011
|
if (noSystemd) {
|
|
35926
36012
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -35942,7 +36028,7 @@ async function installServiceCommand() {
|
|
|
35942
36028
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
35943
36029
|
let nodePath = stableNodePath(process.execPath);
|
|
35944
36030
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
35945
|
-
binPath = (0,
|
|
36031
|
+
binPath = (0, import_node_fs37.realpathSync)(binPath);
|
|
35946
36032
|
nodePath = process.execPath;
|
|
35947
36033
|
}
|
|
35948
36034
|
if (isNodeScript) {
|
|
@@ -35955,9 +36041,9 @@ async function installServiceCommand() {
|
|
|
35955
36041
|
}
|
|
35956
36042
|
}
|
|
35957
36043
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
35958
|
-
const configDir = (0,
|
|
36044
|
+
const configDir = (0, import_node_path26.join)((0, import_node_os11.homedir)(), ".threatcrush");
|
|
35959
36045
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
35960
|
-
(0,
|
|
36046
|
+
(0, import_node_fs37.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
35961
36047
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
35962
36048
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
35963
36049
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -35971,8 +36057,8 @@ async function installServiceCommand() {
|
|
|
35971
36057
|
ensureSystemDirs(configDir);
|
|
35972
36058
|
stopUserModeDaemon();
|
|
35973
36059
|
try {
|
|
35974
|
-
(0,
|
|
35975
|
-
(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" });
|
|
35976
36062
|
} catch (err) {
|
|
35977
36063
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
35978
36064
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -36006,20 +36092,20 @@ function ensureSystemDirs(configDir) {
|
|
|
36006
36092
|
];
|
|
36007
36093
|
let admGid = null;
|
|
36008
36094
|
try {
|
|
36009
|
-
admGid = (0,
|
|
36095
|
+
admGid = (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
|
|
36010
36096
|
} catch {
|
|
36011
36097
|
}
|
|
36012
36098
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
36013
36099
|
try {
|
|
36014
|
-
(0,
|
|
36100
|
+
(0, import_node_fs37.mkdirSync)(path, { recursive: true });
|
|
36015
36101
|
} catch {
|
|
36016
36102
|
}
|
|
36017
36103
|
try {
|
|
36018
36104
|
if (groupWritable && admGid !== null) {
|
|
36019
|
-
(0,
|
|
36020
|
-
(0,
|
|
36105
|
+
(0, import_node_fs37.chmodSync)(path, sticky ? 1533 : 509);
|
|
36106
|
+
(0, import_node_child_process13.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
36021
36107
|
} else {
|
|
36022
|
-
(0,
|
|
36108
|
+
(0, import_node_fs37.chmodSync)(path, 493);
|
|
36023
36109
|
}
|
|
36024
36110
|
} catch {
|
|
36025
36111
|
}
|
|
@@ -36039,29 +36125,29 @@ async function uninstallServiceCommand() {
|
|
|
36039
36125
|
return;
|
|
36040
36126
|
}
|
|
36041
36127
|
try {
|
|
36042
|
-
(0,
|
|
36128
|
+
(0, import_node_child_process13.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
36043
36129
|
} catch {
|
|
36044
36130
|
}
|
|
36045
36131
|
try {
|
|
36046
|
-
(0,
|
|
36132
|
+
(0, import_node_child_process13.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
36047
36133
|
} catch {
|
|
36048
36134
|
}
|
|
36049
36135
|
try {
|
|
36050
|
-
if ((0,
|
|
36051
|
-
(0,
|
|
36136
|
+
if ((0, import_node_fs37.existsSync)(UNIT_PATH)) {
|
|
36137
|
+
(0, import_node_child_process13.execSync)(`rm -f ${UNIT_PATH}`);
|
|
36052
36138
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
36053
36139
|
}
|
|
36054
36140
|
} catch {
|
|
36055
36141
|
}
|
|
36056
36142
|
try {
|
|
36057
|
-
(0,
|
|
36143
|
+
(0, import_node_child_process13.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
36058
36144
|
} catch {
|
|
36059
36145
|
}
|
|
36060
36146
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
36061
36147
|
}
|
|
36062
36148
|
|
|
36063
36149
|
// src/commands/save.ts
|
|
36064
|
-
var
|
|
36150
|
+
var import_node_fs38 = require("fs");
|
|
36065
36151
|
var import_toml5 = __toESM(require_toml());
|
|
36066
36152
|
init_paths();
|
|
36067
36153
|
var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
|
|
@@ -36099,9 +36185,9 @@ async function saveCommand(opts = {}) {
|
|
|
36099
36185
|
}
|
|
36100
36186
|
const path = opts.config ?? PATHS.configFile;
|
|
36101
36187
|
let config = {};
|
|
36102
|
-
if ((0,
|
|
36188
|
+
if ((0, import_node_fs38.existsSync)(path)) {
|
|
36103
36189
|
try {
|
|
36104
|
-
config = import_toml5.default.parse((0,
|
|
36190
|
+
config = import_toml5.default.parse((0, import_node_fs38.readFileSync)(path, "utf-8"));
|
|
36105
36191
|
} catch (err) {
|
|
36106
36192
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
36107
36193
|
`));
|
|
@@ -36213,8 +36299,8 @@ function welcomeCommand() {
|
|
|
36213
36299
|
}
|
|
36214
36300
|
|
|
36215
36301
|
// src/commands/properties.ts
|
|
36216
|
-
var
|
|
36217
|
-
var
|
|
36302
|
+
var import_node_fs39 = require("fs");
|
|
36303
|
+
var import_node_path27 = require("path");
|
|
36218
36304
|
var import_node_readline4 = __toESM(require("readline"));
|
|
36219
36305
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
36220
36306
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
@@ -36543,8 +36629,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
36543
36629
|
}
|
|
36544
36630
|
}
|
|
36545
36631
|
function parseImportFile(path) {
|
|
36546
|
-
const ext = (0,
|
|
36547
|
-
const raw = (0,
|
|
36632
|
+
const ext = (0, import_node_path27.extname)(path).toLowerCase();
|
|
36633
|
+
const raw = (0, import_node_fs39.readFileSync)(path, "utf-8");
|
|
36548
36634
|
if (ext === ".json") {
|
|
36549
36635
|
const parsed = JSON.parse(raw);
|
|
36550
36636
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -36739,18 +36825,18 @@ async function rulesCommand(opts) {
|
|
|
36739
36825
|
}
|
|
36740
36826
|
|
|
36741
36827
|
// src/commands/harden.ts
|
|
36742
|
-
var
|
|
36743
|
-
var
|
|
36828
|
+
var import_node_fs40 = require("fs");
|
|
36829
|
+
var import_node_child_process14 = require("child_process");
|
|
36744
36830
|
function tryExec(cmd) {
|
|
36745
36831
|
try {
|
|
36746
|
-
return (0,
|
|
36832
|
+
return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
36747
36833
|
} catch {
|
|
36748
36834
|
return null;
|
|
36749
36835
|
}
|
|
36750
36836
|
}
|
|
36751
36837
|
function tryRead(path) {
|
|
36752
36838
|
try {
|
|
36753
|
-
return (0,
|
|
36839
|
+
return (0, import_node_fs40.readFileSync)(path, "utf-8");
|
|
36754
36840
|
} catch {
|
|
36755
36841
|
return null;
|
|
36756
36842
|
}
|
|
@@ -36854,8 +36940,8 @@ function checkSshWeakConfig() {
|
|
|
36854
36940
|
};
|
|
36855
36941
|
}
|
|
36856
36942
|
function checkAutoUpdates() {
|
|
36857
|
-
const unattended = (0,
|
|
36858
|
-
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");
|
|
36859
36945
|
if (unattended || dnfAuto) {
|
|
36860
36946
|
return {
|
|
36861
36947
|
key: "auto-updates",
|
|
@@ -36981,7 +37067,7 @@ function checkFail2ban() {
|
|
|
36981
37067
|
explanation: "fail2ban is installed and running."
|
|
36982
37068
|
};
|
|
36983
37069
|
}
|
|
36984
|
-
if ((0,
|
|
37070
|
+
if ((0, import_node_fs40.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
36985
37071
|
return {
|
|
36986
37072
|
key: checkKey,
|
|
36987
37073
|
status: "warn",
|
|
@@ -37310,11 +37396,11 @@ async function allowlistCommand(opts) {
|
|
|
37310
37396
|
init_paths();
|
|
37311
37397
|
|
|
37312
37398
|
// src/upgrade.ts
|
|
37313
|
-
var
|
|
37399
|
+
var import_node_child_process15 = require("child_process");
|
|
37314
37400
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
37315
37401
|
var defaultRunner = (cmd) => {
|
|
37316
37402
|
try {
|
|
37317
|
-
return (0,
|
|
37403
|
+
return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
37318
37404
|
} catch {
|
|
37319
37405
|
return null;
|
|
37320
37406
|
}
|
|
@@ -37429,25 +37515,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
37429
37515
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
37430
37516
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
37431
37517
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
37432
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
37518
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "install.json");
|
|
37433
37519
|
function detectPackageManager() {
|
|
37434
37520
|
try {
|
|
37435
|
-
const npmGlobal = (0,
|
|
37521
|
+
const npmGlobal = (0, import_node_child_process16.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
37436
37522
|
if (npmGlobal.includes(PKG_NAME)) return "npm";
|
|
37437
37523
|
} catch {
|
|
37438
37524
|
}
|
|
37439
37525
|
try {
|
|
37440
|
-
(0,
|
|
37526
|
+
(0, import_node_child_process16.execSync)("pnpm --version", { stdio: "pipe" });
|
|
37441
37527
|
return "pnpm";
|
|
37442
37528
|
} catch {
|
|
37443
37529
|
}
|
|
37444
37530
|
try {
|
|
37445
|
-
(0,
|
|
37531
|
+
(0, import_node_child_process16.execSync)("yarn --version", { stdio: "pipe" });
|
|
37446
37532
|
return "yarn";
|
|
37447
37533
|
} catch {
|
|
37448
37534
|
}
|
|
37449
37535
|
try {
|
|
37450
|
-
(0,
|
|
37536
|
+
(0, import_node_child_process16.execSync)("bun --version", { stdio: "pipe" });
|
|
37451
37537
|
return "bun";
|
|
37452
37538
|
} catch {
|
|
37453
37539
|
}
|
|
@@ -37455,14 +37541,14 @@ function detectPackageManager() {
|
|
|
37455
37541
|
}
|
|
37456
37542
|
function readInstallConfig() {
|
|
37457
37543
|
try {
|
|
37458
|
-
return JSON.parse((0,
|
|
37544
|
+
return JSON.parse((0, import_node_fs41.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
37459
37545
|
} catch {
|
|
37460
37546
|
return {};
|
|
37461
37547
|
}
|
|
37462
37548
|
}
|
|
37463
37549
|
function packageLooksInstalled(pm, pkgName) {
|
|
37464
37550
|
try {
|
|
37465
|
-
const output = (0,
|
|
37551
|
+
const output = (0, import_node_child_process16.execSync)(globalListCommand(pm, pkgName), {
|
|
37466
37552
|
encoding: "utf-8",
|
|
37467
37553
|
stdio: ["pipe", "pipe", "pipe"]
|
|
37468
37554
|
});
|
|
@@ -37565,14 +37651,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
37565
37651
|
function restartSystemdDaemon() {
|
|
37566
37652
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
37567
37653
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
37568
|
-
if (!asRoot && (0,
|
|
37654
|
+
if (!asRoot && (0, import_node_child_process16.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
37569
37655
|
const [cmd, ...args] = argv;
|
|
37570
|
-
if ((0,
|
|
37571
|
-
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;
|
|
37572
37658
|
}
|
|
37573
37659
|
function execQuiet(cmd) {
|
|
37574
37660
|
try {
|
|
37575
|
-
return (0,
|
|
37661
|
+
return (0, import_node_child_process16.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
37576
37662
|
} catch {
|
|
37577
37663
|
return null;
|
|
37578
37664
|
}
|
|
@@ -37748,7 +37834,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
37748
37834
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
37749
37835
|
console.log(LOGO2);
|
|
37750
37836
|
const logPath = PATHS.logFile;
|
|
37751
|
-
if (!(0,
|
|
37837
|
+
if (!(0, import_node_fs41.existsSync)(logPath)) {
|
|
37752
37838
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
37753
37839
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
37754
37840
|
return;
|
|
@@ -37756,7 +37842,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
37756
37842
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
37757
37843
|
`));
|
|
37758
37844
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
37759
|
-
(0,
|
|
37845
|
+
(0, import_node_child_process16.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
37760
37846
|
});
|
|
37761
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) => {
|
|
37762
37848
|
console.log(LOGO2);
|
|
@@ -37768,7 +37854,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
37768
37854
|
for (const cmd of commands2) {
|
|
37769
37855
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37770
37856
|
`));
|
|
37771
|
-
(0,
|
|
37857
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37772
37858
|
}
|
|
37773
37859
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
37774
37860
|
await reportIfStillStale();
|
|
@@ -37793,7 +37879,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
37793
37879
|
for (const cmd of commands) {
|
|
37794
37880
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37795
37881
|
`));
|
|
37796
|
-
(0,
|
|
37882
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37797
37883
|
}
|
|
37798
37884
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
37799
37885
|
if (installMode === "desktop") {
|
|
@@ -37844,7 +37930,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
37844
37930
|
for (const cmd of commands) {
|
|
37845
37931
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
37846
37932
|
`));
|
|
37847
|
-
(0,
|
|
37933
|
+
(0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
|
|
37848
37934
|
}
|
|
37849
37935
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
37850
37936
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -37921,10 +38007,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
37921
38007
|
});
|
|
37922
38008
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
37923
38009
|
console.log(LOGO2);
|
|
37924
|
-
const configPath = (0,
|
|
38010
|
+
const configPath = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
|
|
37925
38011
|
let email = "";
|
|
37926
38012
|
try {
|
|
37927
|
-
const config = JSON.parse((0,
|
|
38013
|
+
const config = JSON.parse((0, import_node_fs41.readFileSync)(configPath, "utf-8"));
|
|
37928
38014
|
email = config.email || "";
|
|
37929
38015
|
} catch {
|
|
37930
38016
|
}
|
|
@@ -37941,9 +38027,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
37941
38027
|
return;
|
|
37942
38028
|
}
|
|
37943
38029
|
try {
|
|
37944
|
-
const dir = (0,
|
|
37945
|
-
if (!(0,
|
|
37946
|
-
(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));
|
|
37947
38033
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
37948
38034
|
} catch {
|
|
37949
38035
|
}
|