@profullstack/threatcrush 0.13.52 → 0.13.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/index.js +303 -226
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23426,8 +23426,8 @@ var source_default = chalk;
|
|
|
23426
23426
|
// src/index.ts
|
|
23427
23427
|
var import_readline = __toESM(require("readline"));
|
|
23428
23428
|
var import_node_child_process23 = require("child_process");
|
|
23429
|
-
var
|
|
23430
|
-
var
|
|
23429
|
+
var import_node_fs55 = require("fs");
|
|
23430
|
+
var import_node_path41 = require("path");
|
|
23431
23431
|
var import_node_os16 = require("os");
|
|
23432
23432
|
|
|
23433
23433
|
// src/commands/monitor.ts
|
|
@@ -40314,7 +40314,7 @@ async function pentestCommand(targetUrl) {
|
|
|
40314
40314
|
}
|
|
40315
40315
|
|
|
40316
40316
|
// src/commands/ai-scan.ts
|
|
40317
|
-
var
|
|
40317
|
+
var import_node_fs23 = require("fs");
|
|
40318
40318
|
|
|
40319
40319
|
// src/aiscan/probes.ts
|
|
40320
40320
|
function makeCanary() {
|
|
@@ -40530,6 +40530,66 @@ ${stripShebang(source)}
|
|
|
40530
40530
|
return { scans };
|
|
40531
40531
|
}
|
|
40532
40532
|
|
|
40533
|
+
// src/core/usage-ping.ts
|
|
40534
|
+
var import_node_crypto6 = require("crypto");
|
|
40535
|
+
var import_node_fs22 = require("fs");
|
|
40536
|
+
var import_node_path19 = require("path");
|
|
40537
|
+
init_cli_config();
|
|
40538
|
+
var STATE_FILE = "usage-ping.json";
|
|
40539
|
+
function usagePingDisabled(env3 = process.env) {
|
|
40540
|
+
const v = (env3.THREATCRUSH_TELEMETRY ?? "").trim().toLowerCase();
|
|
40541
|
+
if (["0", "off", "false", "no"].includes(v)) return true;
|
|
40542
|
+
const dnt = (env3.DO_NOT_TRACK ?? "").trim().toLowerCase();
|
|
40543
|
+
return dnt !== "" && dnt !== "0" && dnt !== "false";
|
|
40544
|
+
}
|
|
40545
|
+
function installId(dir = CLI_CONFIG_DIR) {
|
|
40546
|
+
const file = (0, import_node_path19.join)(dir, STATE_FILE);
|
|
40547
|
+
try {
|
|
40548
|
+
const j = JSON.parse((0, import_node_fs22.readFileSync)(file, "utf-8"));
|
|
40549
|
+
if (j.install_id) return { id: j.install_id, fresh: false };
|
|
40550
|
+
} catch {
|
|
40551
|
+
}
|
|
40552
|
+
const id = (0, import_node_crypto6.randomUUID)();
|
|
40553
|
+
try {
|
|
40554
|
+
if (!(0, import_node_fs22.existsSync)(dir)) (0, import_node_fs22.mkdirSync)(dir, { recursive: true });
|
|
40555
|
+
(0, import_node_fs22.writeFileSync)(file, JSON.stringify({ install_id: id, created_at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
|
|
40556
|
+
} catch {
|
|
40557
|
+
}
|
|
40558
|
+
return { id, fresh: true };
|
|
40559
|
+
}
|
|
40560
|
+
function pingBody(p, id, env3 = process.env) {
|
|
40561
|
+
return {
|
|
40562
|
+
...p,
|
|
40563
|
+
version: PKG_VERSION,
|
|
40564
|
+
platform: process.platform,
|
|
40565
|
+
arch: process.arch,
|
|
40566
|
+
node: process.version,
|
|
40567
|
+
ci: Boolean(env3.CI || env3.GITHUB_ACTIONS),
|
|
40568
|
+
install_id: id
|
|
40569
|
+
};
|
|
40570
|
+
}
|
|
40571
|
+
async function sendUsagePing(p, opts = {}) {
|
|
40572
|
+
const env3 = opts.env ?? process.env;
|
|
40573
|
+
if (usagePingDisabled(env3)) return false;
|
|
40574
|
+
try {
|
|
40575
|
+
const { id, fresh } = installId(opts.dir);
|
|
40576
|
+
if (fresh) {
|
|
40577
|
+
(opts.notice ?? ((s) => process.stderr.write(s + "\n")))(
|
|
40578
|
+
"threatcrush: sends an anonymous usage count per ai-scan run (no targets, no findings text). Turn off with THREATCRUSH_TELEMETRY=0."
|
|
40579
|
+
);
|
|
40580
|
+
}
|
|
40581
|
+
const res = await (opts.fetchImpl ?? fetch)(`${apiUrl()}/api/telemetry`, {
|
|
40582
|
+
method: "POST",
|
|
40583
|
+
headers: { "content-type": "application/json" },
|
|
40584
|
+
body: JSON.stringify(pingBody(p, id, env3)),
|
|
40585
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 2e3)
|
|
40586
|
+
});
|
|
40587
|
+
return res.ok;
|
|
40588
|
+
} catch {
|
|
40589
|
+
return false;
|
|
40590
|
+
}
|
|
40591
|
+
}
|
|
40592
|
+
|
|
40533
40593
|
// src/commands/ai-scan.ts
|
|
40534
40594
|
function parseHeaders(pairs = []) {
|
|
40535
40595
|
const out = {};
|
|
@@ -40557,6 +40617,7 @@ async function aiScanCommand(url, opts) {
|
|
|
40557
40617
|
logger.info(`Probing ${source_default.white(url)} with ${probes.length} check(s)...
|
|
40558
40618
|
`);
|
|
40559
40619
|
const spinner = ora({ text: "Running probes...", color: "green" }).start();
|
|
40620
|
+
const t0 = Date.now();
|
|
40560
40621
|
const result = await runAiScan(url, send, {
|
|
40561
40622
|
categories,
|
|
40562
40623
|
delayMs: opts.delay ? Number(opts.delay) : 0,
|
|
@@ -40565,6 +40626,14 @@ async function aiScanCommand(url, opts) {
|
|
|
40565
40626
|
}
|
|
40566
40627
|
});
|
|
40567
40628
|
spinner.stop();
|
|
40629
|
+
await sendUsagePing({
|
|
40630
|
+
event: "ai-scan",
|
|
40631
|
+
probes: probes.length,
|
|
40632
|
+
findings: result.findings.length,
|
|
40633
|
+
severity: result.severity_summary,
|
|
40634
|
+
duration_ms: Date.now() - t0,
|
|
40635
|
+
failed: Boolean(result.error)
|
|
40636
|
+
});
|
|
40568
40637
|
if (opts.json) {
|
|
40569
40638
|
console.log(JSON.stringify(result, null, 2));
|
|
40570
40639
|
return result;
|
|
@@ -40591,13 +40660,21 @@ async function aiScanMoshCommand(file, args) {
|
|
|
40591
40660
|
console.log();
|
|
40592
40661
|
let source;
|
|
40593
40662
|
try {
|
|
40594
|
-
source = (0,
|
|
40663
|
+
source = (0, import_node_fs23.readFileSync)(file, "utf-8");
|
|
40595
40664
|
} catch (err) {
|
|
40596
40665
|
logger.error(`Cannot read ${file}: ${err.message}`);
|
|
40597
40666
|
process.exitCode = 1;
|
|
40598
40667
|
return;
|
|
40599
40668
|
}
|
|
40669
|
+
const t0 = Date.now();
|
|
40600
40670
|
const res = await runMosh(source, { argv: args, out: (s) => console.log(" " + s) });
|
|
40671
|
+
await sendUsagePing({
|
|
40672
|
+
event: "ai-scan-run",
|
|
40673
|
+
scans: res.scans.length,
|
|
40674
|
+
findings: res.scans.reduce((n, s) => n + s.findings.length, 0),
|
|
40675
|
+
duration_ms: Date.now() - t0,
|
|
40676
|
+
failed: Boolean(res.failed)
|
|
40677
|
+
});
|
|
40601
40678
|
if (res.failed) {
|
|
40602
40679
|
console.log();
|
|
40603
40680
|
console.log(` ${source_default.red("\u2717 script failed:")} ${res.failed}`);
|
|
@@ -40612,21 +40689,21 @@ async function aiScanMoshCommand(file, args) {
|
|
|
40612
40689
|
|
|
40613
40690
|
// src/commands/orgs.ts
|
|
40614
40691
|
var import_node_os9 = require("os");
|
|
40615
|
-
var
|
|
40616
|
-
var
|
|
40692
|
+
var import_node_fs24 = require("fs");
|
|
40693
|
+
var import_node_path20 = require("path");
|
|
40617
40694
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
40618
|
-
var CONFIG_PATH = (0,
|
|
40695
|
+
var CONFIG_PATH = (0, import_node_path20.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
|
|
40619
40696
|
function readConfig() {
|
|
40620
40697
|
try {
|
|
40621
|
-
return JSON.parse((0,
|
|
40698
|
+
return JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
40622
40699
|
} catch {
|
|
40623
40700
|
return {};
|
|
40624
40701
|
}
|
|
40625
40702
|
}
|
|
40626
40703
|
function writeConfig(config) {
|
|
40627
|
-
const dir = (0,
|
|
40628
|
-
if (!(0,
|
|
40629
|
-
(0,
|
|
40704
|
+
const dir = (0, import_node_path20.join)((0, import_node_os9.homedir)(), ".threatcrush");
|
|
40705
|
+
if (!(0, import_node_fs24.existsSync)(dir)) (0, import_node_fs24.mkdirSync)(dir, { recursive: true });
|
|
40706
|
+
(0, import_node_fs24.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
40630
40707
|
}
|
|
40631
40708
|
function getAuthHeaders() {
|
|
40632
40709
|
const config = readConfig();
|
|
@@ -40762,13 +40839,13 @@ async function useOrganization(slug) {
|
|
|
40762
40839
|
|
|
40763
40840
|
// src/commands/credits.ts
|
|
40764
40841
|
var import_node_os10 = require("os");
|
|
40765
|
-
var
|
|
40766
|
-
var
|
|
40842
|
+
var import_node_fs25 = require("fs");
|
|
40843
|
+
var import_node_path21 = require("path");
|
|
40767
40844
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
40768
|
-
var CONFIG_PATH2 = (0,
|
|
40845
|
+
var CONFIG_PATH2 = (0, import_node_path21.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
|
|
40769
40846
|
function sessionToken() {
|
|
40770
40847
|
try {
|
|
40771
|
-
const cfg = JSON.parse((0,
|
|
40848
|
+
const cfg = JSON.parse((0, import_node_fs25.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
40772
40849
|
return cfg.token ?? null;
|
|
40773
40850
|
} catch {
|
|
40774
40851
|
return null;
|
|
@@ -41055,14 +41132,14 @@ function timeAgo(dateStr) {
|
|
|
41055
41132
|
|
|
41056
41133
|
// src/commands/connect.ts
|
|
41057
41134
|
var import_node_os12 = require("os");
|
|
41058
|
-
var
|
|
41059
|
-
var
|
|
41135
|
+
var import_node_fs26 = require("fs");
|
|
41136
|
+
var import_node_path22 = require("path");
|
|
41060
41137
|
var import_node_child_process5 = require("child_process");
|
|
41061
41138
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
41062
|
-
var CONFIG_PATH3 = (0,
|
|
41139
|
+
var CONFIG_PATH3 = (0, import_node_path22.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
|
|
41063
41140
|
function readConfig2() {
|
|
41064
41141
|
try {
|
|
41065
|
-
return JSON.parse((0,
|
|
41142
|
+
return JSON.parse((0, import_node_fs26.readFileSync)(CONFIG_PATH3, "utf-8"));
|
|
41066
41143
|
} catch {
|
|
41067
41144
|
return {};
|
|
41068
41145
|
}
|
|
@@ -41217,21 +41294,21 @@ async function sshConnect(options) {
|
|
|
41217
41294
|
|
|
41218
41295
|
// src/commands/daemon.ts
|
|
41219
41296
|
var import_node_child_process17 = require("child_process");
|
|
41220
|
-
var import_node_fs43 = require("fs");
|
|
41221
|
-
var import_node_path33 = require("path");
|
|
41222
41297
|
var import_node_fs44 = require("fs");
|
|
41298
|
+
var import_node_path34 = require("path");
|
|
41299
|
+
var import_node_fs45 = require("fs");
|
|
41223
41300
|
|
|
41224
41301
|
// src/daemon/index.ts
|
|
41225
|
-
var
|
|
41302
|
+
var import_node_fs43 = require("fs");
|
|
41226
41303
|
var import_node_child_process16 = require("child_process");
|
|
41227
41304
|
var import_node_os13 = require("os");
|
|
41228
|
-
var
|
|
41305
|
+
var import_node_path33 = require("path");
|
|
41229
41306
|
var import_node_util4 = require("util");
|
|
41230
41307
|
init_paths();
|
|
41231
41308
|
|
|
41232
41309
|
// src/daemon/ipc-server.ts
|
|
41233
41310
|
var import_node_net3 = require("net");
|
|
41234
|
-
var
|
|
41311
|
+
var import_node_fs27 = require("fs");
|
|
41235
41312
|
init_paths();
|
|
41236
41313
|
init_control_token();
|
|
41237
41314
|
|
|
@@ -41285,9 +41362,9 @@ var IpcServer = class {
|
|
|
41285
41362
|
controlToken = "";
|
|
41286
41363
|
async start() {
|
|
41287
41364
|
this.controlToken = issueControlToken();
|
|
41288
|
-
if ((0,
|
|
41365
|
+
if ((0, import_node_fs27.existsSync)(PATHS.socket)) {
|
|
41289
41366
|
try {
|
|
41290
|
-
(0,
|
|
41367
|
+
(0, import_node_fs27.unlinkSync)(PATHS.socket);
|
|
41291
41368
|
} catch {
|
|
41292
41369
|
}
|
|
41293
41370
|
}
|
|
@@ -41325,14 +41402,14 @@ var IpcServer = class {
|
|
|
41325
41402
|
return new Promise((resolve6) => {
|
|
41326
41403
|
if (!this.server) {
|
|
41327
41404
|
try {
|
|
41328
|
-
if ((0,
|
|
41405
|
+
if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
|
|
41329
41406
|
} catch {
|
|
41330
41407
|
}
|
|
41331
41408
|
return resolve6();
|
|
41332
41409
|
}
|
|
41333
41410
|
this.server.close(() => {
|
|
41334
41411
|
try {
|
|
41335
|
-
if ((0,
|
|
41412
|
+
if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
|
|
41336
41413
|
} catch {
|
|
41337
41414
|
}
|
|
41338
41415
|
resolve6();
|
|
@@ -41512,7 +41589,7 @@ var IpcServer = class {
|
|
|
41512
41589
|
}
|
|
41513
41590
|
}
|
|
41514
41591
|
};
|
|
41515
|
-
function admGid(readGroup = () => (0,
|
|
41592
|
+
function admGid(readGroup = () => (0, import_node_fs27.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs27.statSync)("/var/log/auth.log")) {
|
|
41516
41593
|
try {
|
|
41517
41594
|
for (const line2 of readGroup().split("\n")) {
|
|
41518
41595
|
const [name, , gid] = line2.split(":");
|
|
@@ -41528,14 +41605,14 @@ function admGid(readGroup = () => (0, import_node_fs26.readFileSync)("/etc/group
|
|
|
41528
41605
|
}
|
|
41529
41606
|
|
|
41530
41607
|
// src/daemon/module-host.ts
|
|
41531
|
-
var
|
|
41532
|
-
var
|
|
41608
|
+
var import_node_fs33 = require("fs");
|
|
41609
|
+
var import_node_path24 = require("path");
|
|
41533
41610
|
var import_node_url = require("url");
|
|
41534
41611
|
var import_toml4 = __toESM(require_toml());
|
|
41535
41612
|
init_paths();
|
|
41536
41613
|
|
|
41537
41614
|
// src/daemon/watchers/log-watcher.ts
|
|
41538
|
-
var
|
|
41615
|
+
var import_node_fs28 = require("fs");
|
|
41539
41616
|
var DEFAULT_SOURCES = [
|
|
41540
41617
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
41541
41618
|
{ path: "/var/log/secure", module: "ssh-guard", category: "auth" },
|
|
@@ -41555,9 +41632,9 @@ var LogWatcher = class {
|
|
|
41555
41632
|
start() {
|
|
41556
41633
|
const started = [];
|
|
41557
41634
|
for (const src of this.sources) {
|
|
41558
|
-
if (!(0,
|
|
41635
|
+
if (!(0, import_node_fs28.existsSync)(src.path)) continue;
|
|
41559
41636
|
try {
|
|
41560
|
-
(0,
|
|
41637
|
+
(0, import_node_fs28.accessSync)(src.path, import_node_fs28.constants.R_OK);
|
|
41561
41638
|
} catch {
|
|
41562
41639
|
continue;
|
|
41563
41640
|
}
|
|
@@ -41854,7 +41931,7 @@ function realtimeToDate(rt) {
|
|
|
41854
41931
|
|
|
41855
41932
|
// src/modules/network-monitor/index.ts
|
|
41856
41933
|
var import_node_child_process7 = require("child_process");
|
|
41857
|
-
var
|
|
41934
|
+
var import_node_fs29 = require("fs");
|
|
41858
41935
|
var NetworkMonitor = class {
|
|
41859
41936
|
constructor(bus2) {
|
|
41860
41937
|
this.bus = bus2;
|
|
@@ -41918,7 +41995,7 @@ var NetworkMonitor = class {
|
|
|
41918
41995
|
hasConntrackOrSs() {
|
|
41919
41996
|
const ss = (0, import_node_child_process7.spawnSync)("ss", ["--version"], { stdio: "pipe" });
|
|
41920
41997
|
if (ss.status === 0) return true;
|
|
41921
|
-
return (0,
|
|
41998
|
+
return (0, import_node_fs29.existsSync)("/proc/net/tcp");
|
|
41922
41999
|
}
|
|
41923
42000
|
/**
|
|
41924
42001
|
* The TCP ports this host actually listens on.
|
|
@@ -42105,18 +42182,18 @@ var NetworkMonitor = class {
|
|
|
42105
42182
|
};
|
|
42106
42183
|
|
|
42107
42184
|
// src/modules/dns-monitor/index.ts
|
|
42108
|
-
var
|
|
42185
|
+
var import_node_fs32 = require("fs");
|
|
42109
42186
|
var import_node_child_process9 = require("child_process");
|
|
42110
42187
|
var import_node_readline3 = require("readline");
|
|
42111
42188
|
|
|
42112
42189
|
// src/core/threat-feeds/index.ts
|
|
42113
|
-
var
|
|
42114
|
-
var
|
|
42190
|
+
var import_node_fs31 = require("fs");
|
|
42191
|
+
var import_node_path23 = require("path");
|
|
42115
42192
|
var import_node_net5 = require("net");
|
|
42116
42193
|
|
|
42117
42194
|
// src/daemon/firewall/protected.ts
|
|
42118
42195
|
var import_node_child_process8 = require("child_process");
|
|
42119
|
-
var
|
|
42196
|
+
var import_node_fs30 = require("fs");
|
|
42120
42197
|
var import_node_net4 = require("net");
|
|
42121
42198
|
var DEFAULT_PROTECTED = [
|
|
42122
42199
|
"127.0.0.0/8",
|
|
@@ -42272,14 +42349,14 @@ function moshClients(procDir = "/proc") {
|
|
|
42272
42349
|
const found = /* @__PURE__ */ new Set();
|
|
42273
42350
|
let pids = [];
|
|
42274
42351
|
try {
|
|
42275
|
-
pids = (0,
|
|
42352
|
+
pids = (0, import_node_fs30.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
|
|
42276
42353
|
} catch {
|
|
42277
42354
|
return [];
|
|
42278
42355
|
}
|
|
42279
42356
|
for (const pid of pids) {
|
|
42280
42357
|
try {
|
|
42281
|
-
if ((0,
|
|
42282
|
-
const ip = sshClientFromEnviron((0,
|
|
42358
|
+
if ((0, import_node_fs30.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
|
|
42359
|
+
const ip = sshClientFromEnviron((0, import_node_fs30.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
|
|
42283
42360
|
if (ip) found.add(ip);
|
|
42284
42361
|
} catch {
|
|
42285
42362
|
}
|
|
@@ -42485,17 +42562,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
|
|
|
42485
42562
|
}
|
|
42486
42563
|
function readFeedCache(path2) {
|
|
42487
42564
|
try {
|
|
42488
|
-
const set = JSON.parse((0,
|
|
42565
|
+
const set = JSON.parse((0, import_node_fs31.readFileSync)(path2, "utf-8"));
|
|
42489
42566
|
return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
|
|
42490
42567
|
} catch {
|
|
42491
42568
|
return null;
|
|
42492
42569
|
}
|
|
42493
42570
|
}
|
|
42494
42571
|
function writeFeedCache(path2, set) {
|
|
42495
|
-
(0,
|
|
42572
|
+
(0, import_node_fs31.mkdirSync)((0, import_node_path23.dirname)(path2), { recursive: true });
|
|
42496
42573
|
const tmp = `${path2}.tmp`;
|
|
42497
|
-
(0,
|
|
42498
|
-
(0,
|
|
42574
|
+
(0, import_node_fs31.writeFileSync)(tmp, JSON.stringify(set));
|
|
42575
|
+
(0, import_node_fs31.renameSync)(tmp, path2);
|
|
42499
42576
|
}
|
|
42500
42577
|
var RESOLVER_FILES = {
|
|
42501
42578
|
hosts: "blocked-domains.hosts",
|
|
@@ -42620,9 +42697,9 @@ var DnsMonitor = class {
|
|
|
42620
42697
|
}
|
|
42621
42698
|
start() {
|
|
42622
42699
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
42623
|
-
if (!(0,
|
|
42700
|
+
if (!(0, import_node_fs32.existsSync)(p)) return false;
|
|
42624
42701
|
try {
|
|
42625
|
-
(0,
|
|
42702
|
+
(0, import_node_fs32.accessSync)(p, import_node_fs32.constants.R_OK);
|
|
42626
42703
|
return true;
|
|
42627
42704
|
} catch {
|
|
42628
42705
|
return false;
|
|
@@ -42979,15 +43056,15 @@ var ModuleHost = class {
|
|
|
42979
43056
|
}
|
|
42980
43057
|
}
|
|
42981
43058
|
async discoverAndStartInstalled() {
|
|
42982
|
-
if (!(0,
|
|
43059
|
+
if (!(0, import_node_fs33.existsSync)(PATHS.moduleDir)) return;
|
|
42983
43060
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
42984
|
-
const entries = (0,
|
|
43061
|
+
const entries = (0, import_node_fs33.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
42985
43062
|
for (const entry of entries) {
|
|
42986
43063
|
if (!entry.isDirectory()) continue;
|
|
42987
|
-
const manifestPath = (0,
|
|
42988
|
-
if (!(0,
|
|
43064
|
+
const manifestPath = (0, import_node_path24.join)(PATHS.moduleDir, entry.name, "mod.toml");
|
|
43065
|
+
if (!(0, import_node_fs33.existsSync)(manifestPath)) continue;
|
|
42989
43066
|
try {
|
|
42990
|
-
const manifest = import_toml4.default.parse((0,
|
|
43067
|
+
const manifest = import_toml4.default.parse((0, import_node_fs33.readFileSync)(manifestPath, "utf-8"));
|
|
42991
43068
|
const name = manifest.module?.name || entry.name;
|
|
42992
43069
|
const defaults = manifest.module?.config?.defaults || {};
|
|
42993
43070
|
const config = {
|
|
@@ -43001,7 +43078,7 @@ var ModuleHost = class {
|
|
|
43001
43078
|
source: "installed",
|
|
43002
43079
|
status: config.enabled === false ? "disabled" : "loaded",
|
|
43003
43080
|
events: 0,
|
|
43004
|
-
path: (0,
|
|
43081
|
+
path: (0, import_node_path24.join)(PATHS.moduleDir, entry.name),
|
|
43005
43082
|
config
|
|
43006
43083
|
};
|
|
43007
43084
|
this.modules.set(name, hosted);
|
|
@@ -43016,7 +43093,7 @@ var ModuleHost = class {
|
|
|
43016
43093
|
status: "error",
|
|
43017
43094
|
events: 0,
|
|
43018
43095
|
detail: `manifest load failed: ${String(err.message || err)}`,
|
|
43019
|
-
path: (0,
|
|
43096
|
+
path: (0, import_node_path24.join)(PATHS.moduleDir, entry.name)
|
|
43020
43097
|
});
|
|
43021
43098
|
}
|
|
43022
43099
|
}
|
|
@@ -43055,17 +43132,17 @@ var ModuleHost = class {
|
|
|
43055
43132
|
}
|
|
43056
43133
|
}
|
|
43057
43134
|
installedEntrypoint(modulePath) {
|
|
43058
|
-
const packageJson = (0,
|
|
43135
|
+
const packageJson = (0, import_node_path24.join)(modulePath, "package.json");
|
|
43059
43136
|
const candidates = [];
|
|
43060
|
-
if ((0,
|
|
43137
|
+
if ((0, import_node_fs33.existsSync)(packageJson)) {
|
|
43061
43138
|
try {
|
|
43062
|
-
const pkg = JSON.parse((0,
|
|
43063
|
-
if (pkg.main) candidates.push((0,
|
|
43139
|
+
const pkg = JSON.parse((0, import_node_fs33.readFileSync)(packageJson, "utf-8"));
|
|
43140
|
+
if (pkg.main) candidates.push((0, import_node_path24.join)(modulePath, pkg.main));
|
|
43064
43141
|
} catch {
|
|
43065
43142
|
}
|
|
43066
43143
|
}
|
|
43067
|
-
candidates.push((0,
|
|
43068
|
-
return candidates.find((candidate) => (0,
|
|
43144
|
+
candidates.push((0, import_node_path24.join)(modulePath, "dist", "index.js"), (0, import_node_path24.join)(modulePath, "index.js"));
|
|
43145
|
+
return candidates.find((candidate) => (0, import_node_fs33.existsSync)(candidate)) || null;
|
|
43069
43146
|
}
|
|
43070
43147
|
isThreatCrushModule(value) {
|
|
43071
43148
|
return Boolean(
|
|
@@ -43473,7 +43550,7 @@ var RunsWorker = class {
|
|
|
43473
43550
|
init_cli_config();
|
|
43474
43551
|
|
|
43475
43552
|
// src/core/cloud-events.ts
|
|
43476
|
-
var
|
|
43553
|
+
var import_node_crypto7 = require("crypto");
|
|
43477
43554
|
var import_node_net6 = require("net");
|
|
43478
43555
|
init_cli_config();
|
|
43479
43556
|
function currentLink() {
|
|
@@ -43547,7 +43624,7 @@ function remediationEvent(serverId, event) {
|
|
|
43547
43624
|
return {
|
|
43548
43625
|
type: "remediation",
|
|
43549
43626
|
server_id: serverId,
|
|
43550
|
-
event_id: (0,
|
|
43627
|
+
event_id: (0, import_node_crypto7.randomUUID)(),
|
|
43551
43628
|
action_type: d.action,
|
|
43552
43629
|
target_value: event.source_ip,
|
|
43553
43630
|
status: d.failed === true ? "failed" : "executed",
|
|
@@ -43574,16 +43651,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
43574
43651
|
}
|
|
43575
43652
|
|
|
43576
43653
|
// src/daemon/workers/cloud-spool.ts
|
|
43577
|
-
var
|
|
43654
|
+
var import_node_fs34 = require("fs");
|
|
43578
43655
|
var import_promises = require("fs/promises");
|
|
43579
|
-
var
|
|
43656
|
+
var import_node_path25 = require("path");
|
|
43580
43657
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
43581
43658
|
var CloudSpool = class {
|
|
43582
43659
|
constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
|
|
43583
43660
|
this.path = path2;
|
|
43584
43661
|
this.limits = limits;
|
|
43585
43662
|
try {
|
|
43586
|
-
(0,
|
|
43663
|
+
(0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path2), { recursive: true });
|
|
43587
43664
|
} catch {
|
|
43588
43665
|
}
|
|
43589
43666
|
this.load();
|
|
@@ -43652,7 +43729,7 @@ var CloudSpool = class {
|
|
|
43652
43729
|
load() {
|
|
43653
43730
|
let raw;
|
|
43654
43731
|
try {
|
|
43655
|
-
raw = (0,
|
|
43732
|
+
raw = (0, import_node_fs34.readFileSync)(this.path, "utf-8");
|
|
43656
43733
|
} catch {
|
|
43657
43734
|
return;
|
|
43658
43735
|
}
|
|
@@ -43890,7 +43967,7 @@ var CloudSync = class {
|
|
|
43890
43967
|
};
|
|
43891
43968
|
|
|
43892
43969
|
// src/daemon/workers/abuse-reporter.ts
|
|
43893
|
-
var
|
|
43970
|
+
var import_node_crypto8 = require("crypto");
|
|
43894
43971
|
|
|
43895
43972
|
// src/daemon/workers/abuse-evidence.ts
|
|
43896
43973
|
var import_node_net7 = require("net");
|
|
@@ -44119,32 +44196,32 @@ function resolveConfig(section) {
|
|
|
44119
44196
|
}
|
|
44120
44197
|
|
|
44121
44198
|
// src/core/abuse-report-log.ts
|
|
44122
|
-
var
|
|
44123
|
-
var
|
|
44199
|
+
var import_node_fs35 = require("fs");
|
|
44200
|
+
var import_node_path26 = require("path");
|
|
44124
44201
|
init_paths();
|
|
44125
44202
|
var ABUSE_DIRNAME = "abuse-reports";
|
|
44126
44203
|
var LOG_FILE2 = "reports.jsonl";
|
|
44127
44204
|
function resolveAbuseDir(dir) {
|
|
44128
44205
|
if (dir) return dir;
|
|
44129
44206
|
if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
|
|
44130
|
-
const system = (0,
|
|
44131
|
-
if ((0,
|
|
44132
|
-
return (0,
|
|
44207
|
+
const system = (0, import_node_path26.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
|
|
44208
|
+
if ((0, import_node_fs35.existsSync)(system)) return system;
|
|
44209
|
+
return (0, import_node_path26.join)(PATHS.stateDir, ABUSE_DIRNAME);
|
|
44133
44210
|
}
|
|
44134
44211
|
function logPath(dir) {
|
|
44135
|
-
return (0,
|
|
44212
|
+
return (0, import_node_path26.join)(resolveAbuseDir(dir), LOG_FILE2);
|
|
44136
44213
|
}
|
|
44137
44214
|
function appendReport(record, dir) {
|
|
44138
44215
|
const path2 = logPath(dir);
|
|
44139
|
-
(0,
|
|
44140
|
-
(0,
|
|
44216
|
+
(0, import_node_fs35.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
|
|
44217
|
+
(0, import_node_fs35.appendFileSync)(path2, `${JSON.stringify(record)}
|
|
44141
44218
|
`, { mode: 420 });
|
|
44142
44219
|
}
|
|
44143
44220
|
function readReports(dir) {
|
|
44144
44221
|
const path2 = logPath(dir);
|
|
44145
44222
|
let raw;
|
|
44146
44223
|
try {
|
|
44147
|
-
raw = (0,
|
|
44224
|
+
raw = (0, import_node_fs35.readFileSync)(path2, "utf-8");
|
|
44148
44225
|
} catch {
|
|
44149
44226
|
return [];
|
|
44150
44227
|
}
|
|
@@ -44283,7 +44360,7 @@ var AbuseReporter = class {
|
|
|
44283
44360
|
const payload = buildPayload(ip, evidence);
|
|
44284
44361
|
const results = this.cfg.dryRun ? [] : await dispatch(payload, this.cfg.destinations, this.cfg.keys);
|
|
44285
44362
|
const record = {
|
|
44286
|
-
id: (0,
|
|
44363
|
+
id: (0, import_node_crypto8.randomUUID)().slice(0, 8),
|
|
44287
44364
|
ip,
|
|
44288
44365
|
reported_at: new Date(now).toISOString(),
|
|
44289
44366
|
mode: this.cfg.dryRun ? "dry_run" : "live",
|
|
@@ -44541,8 +44618,8 @@ var RemediationConsumer = class {
|
|
|
44541
44618
|
|
|
44542
44619
|
// src/daemon/workers/auto-update.ts
|
|
44543
44620
|
var import_node_child_process10 = require("child_process");
|
|
44544
|
-
var
|
|
44545
|
-
var
|
|
44621
|
+
var import_node_fs36 = require("fs");
|
|
44622
|
+
var import_node_path27 = require("path");
|
|
44546
44623
|
init_backoff();
|
|
44547
44624
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
44548
44625
|
var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
|
|
@@ -44586,12 +44663,12 @@ function pickUpdate(doc, current, opts) {
|
|
|
44586
44663
|
return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
|
|
44587
44664
|
}
|
|
44588
44665
|
function installPlan(opts) {
|
|
44589
|
-
const expected = `${
|
|
44666
|
+
const expected = `${import_node_path27.sep}lib${import_node_path27.sep}node_modules${import_node_path27.sep}@profullstack${import_node_path27.sep}threatcrush`;
|
|
44590
44667
|
if (!opts.pkgRoot.endsWith(expected)) {
|
|
44591
44668
|
return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
|
|
44592
44669
|
}
|
|
44593
|
-
const nodeBin = (0,
|
|
44594
|
-
const npm = (0,
|
|
44670
|
+
const nodeBin = (0, import_node_path27.dirname)(opts.execPath);
|
|
44671
|
+
const npm = (0, import_node_path27.join)(nodeBin, "npm");
|
|
44595
44672
|
if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
|
|
44596
44673
|
if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
|
|
44597
44674
|
const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
|
|
@@ -44623,10 +44700,10 @@ function installPlan(opts) {
|
|
|
44623
44700
|
}
|
|
44624
44701
|
function ownerOf(path2, passwd = "/etc/passwd") {
|
|
44625
44702
|
try {
|
|
44626
|
-
const st = (0,
|
|
44703
|
+
const st = (0, import_node_fs36.statSync)(path2);
|
|
44627
44704
|
let home = st.uid === 0 ? "/root" : "";
|
|
44628
44705
|
try {
|
|
44629
|
-
for (const line2 of (0,
|
|
44706
|
+
for (const line2 of (0, import_node_fs36.readFileSync)(passwd, "utf8").split("\n")) {
|
|
44630
44707
|
const f = line2.split(":");
|
|
44631
44708
|
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
44632
44709
|
}
|
|
@@ -44731,7 +44808,7 @@ var AutoUpdate = class {
|
|
|
44731
44808
|
uid: process.getuid?.() ?? -1,
|
|
44732
44809
|
owner: ownerOf(this.opts.pkgRoot),
|
|
44733
44810
|
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
44734
|
-
npmExists:
|
|
44811
|
+
npmExists: import_node_fs36.existsSync
|
|
44735
44812
|
});
|
|
44736
44813
|
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
44737
44814
|
this.recordAttempt(target);
|
|
@@ -44766,7 +44843,7 @@ var AutoUpdate = class {
|
|
|
44766
44843
|
}
|
|
44767
44844
|
lastAttempt() {
|
|
44768
44845
|
try {
|
|
44769
|
-
const v = JSON.parse((0,
|
|
44846
|
+
const v = JSON.parse((0, import_node_fs36.readFileSync)(this.opts.statePath, "utf8"));
|
|
44770
44847
|
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
44771
44848
|
} catch {
|
|
44772
44849
|
return null;
|
|
@@ -44774,7 +44851,7 @@ var AutoUpdate = class {
|
|
|
44774
44851
|
}
|
|
44775
44852
|
recordAttempt(version) {
|
|
44776
44853
|
try {
|
|
44777
|
-
(0,
|
|
44854
|
+
(0, import_node_fs36.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
44778
44855
|
} catch (err) {
|
|
44779
44856
|
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
44780
44857
|
}
|
|
@@ -44783,8 +44860,8 @@ var AutoUpdate = class {
|
|
|
44783
44860
|
|
|
44784
44861
|
// src/daemon/workers/threat-feeds.ts
|
|
44785
44862
|
var import_node_child_process11 = require("child_process");
|
|
44786
|
-
var
|
|
44787
|
-
var
|
|
44863
|
+
var import_node_fs37 = require("fs");
|
|
44864
|
+
var import_node_path28 = require("path");
|
|
44788
44865
|
var import_node_net10 = require("net");
|
|
44789
44866
|
init_backoff();
|
|
44790
44867
|
var EGRESS_TABLE = "threatcrush_egress";
|
|
@@ -44956,14 +45033,14 @@ var ThreatFeeds = class {
|
|
|
44956
45033
|
*/
|
|
44957
45034
|
writeResolverFiles(set) {
|
|
44958
45035
|
const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
|
|
44959
|
-
const dir = this.opts.resolverDir ?? (0,
|
|
45036
|
+
const dir = this.opts.resolverDir ?? (0, import_node_path28.dirname)(this.opts.cachePath);
|
|
44960
45037
|
const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
|
|
44961
45038
|
const write = (name, content) => {
|
|
44962
|
-
const path2 = (0,
|
|
45039
|
+
const path2 = (0, import_node_path28.join)(dir, name);
|
|
44963
45040
|
if (this.resolverWritten.get(name) === content) return false;
|
|
44964
45041
|
try {
|
|
44965
|
-
(0,
|
|
44966
|
-
(0,
|
|
45042
|
+
(0, import_node_fs37.writeFileSync)(`${path2}.tmp`, content);
|
|
45043
|
+
(0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
|
|
44967
45044
|
this.resolverWritten.set(name, content);
|
|
44968
45045
|
return true;
|
|
44969
45046
|
} catch (err) {
|
|
@@ -44974,11 +45051,11 @@ var ThreatFeeds = class {
|
|
|
44974
45051
|
const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
|
|
44975
45052
|
const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
|
|
44976
45053
|
const via = [];
|
|
44977
|
-
if ((0,
|
|
45054
|
+
if ((0, import_node_fs37.existsSync)(hooks.dnsmasq)) {
|
|
44978
45055
|
via.push("dnsmasq");
|
|
44979
45056
|
if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
|
|
44980
45057
|
}
|
|
44981
|
-
if ((0,
|
|
45058
|
+
if ((0, import_node_fs37.existsSync)(hooks.unbound)) {
|
|
44982
45059
|
via.push("unbound");
|
|
44983
45060
|
if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
|
|
44984
45061
|
this.run("systemctl", ["reload", "unbound.service"]);
|
|
@@ -45039,12 +45116,12 @@ var ThreatFeeds = class {
|
|
|
45039
45116
|
};
|
|
45040
45117
|
|
|
45041
45118
|
// src/daemon/workers/privilege-watch.ts
|
|
45042
|
-
var
|
|
45043
|
-
var
|
|
45119
|
+
var import_node_fs38 = require("fs");
|
|
45120
|
+
var import_node_path29 = require("path");
|
|
45044
45121
|
var import_node_child_process12 = require("child_process");
|
|
45045
45122
|
|
|
45046
45123
|
// src/core/privileges/index.ts
|
|
45047
|
-
var
|
|
45124
|
+
var import_node_crypto9 = require("crypto");
|
|
45048
45125
|
var ADMIN_GROUPS = ["sudo", "wheel", "admin"];
|
|
45049
45126
|
function parseUsers(text) {
|
|
45050
45127
|
const out = [];
|
|
@@ -45085,7 +45162,7 @@ function sudoReadsIncluded(name) {
|
|
|
45085
45162
|
}
|
|
45086
45163
|
function keyFingerprint(blobBase64) {
|
|
45087
45164
|
if (!/^[A-Za-z0-9+/]+=*$/.test(blobBase64)) return null;
|
|
45088
|
-
const digest = (0,
|
|
45165
|
+
const digest = (0, import_node_crypto9.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
|
|
45089
45166
|
return `SHA256:${digest.replace(/=+$/, "")}`;
|
|
45090
45167
|
}
|
|
45091
45168
|
function parseAuthorizedKeys(text) {
|
|
@@ -45231,31 +45308,31 @@ function countryName(code) {
|
|
|
45231
45308
|
var fsIO = {
|
|
45232
45309
|
readFile: (p) => {
|
|
45233
45310
|
try {
|
|
45234
|
-
return (0,
|
|
45311
|
+
return (0, import_node_fs38.readFileSync)(p, "utf-8");
|
|
45235
45312
|
} catch {
|
|
45236
45313
|
return null;
|
|
45237
45314
|
}
|
|
45238
45315
|
},
|
|
45239
45316
|
readDir: (p) => {
|
|
45240
45317
|
try {
|
|
45241
|
-
return (0,
|
|
45318
|
+
return (0, import_node_fs38.readdirSync)(p);
|
|
45242
45319
|
} catch {
|
|
45243
45320
|
return null;
|
|
45244
45321
|
}
|
|
45245
45322
|
},
|
|
45246
|
-
exists: (p) => (0,
|
|
45323
|
+
exists: (p) => (0, import_node_fs38.existsSync)(p)
|
|
45247
45324
|
};
|
|
45248
45325
|
function readJson(path2) {
|
|
45249
45326
|
try {
|
|
45250
|
-
return JSON.parse((0,
|
|
45327
|
+
return JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
|
|
45251
45328
|
} catch {
|
|
45252
45329
|
return null;
|
|
45253
45330
|
}
|
|
45254
45331
|
}
|
|
45255
45332
|
function writeJson(path2, value) {
|
|
45256
|
-
(0,
|
|
45257
|
-
(0,
|
|
45258
|
-
(0,
|
|
45333
|
+
(0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
|
|
45334
|
+
(0, import_node_fs38.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
|
|
45335
|
+
(0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
|
|
45259
45336
|
}
|
|
45260
45337
|
function defaultRun3(cmd, args) {
|
|
45261
45338
|
const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -45411,7 +45488,7 @@ var PrivilegeWatch = class {
|
|
|
45411
45488
|
* raised a "new country" alert on its first run; on dev2 it did, at once.
|
|
45412
45489
|
*/
|
|
45413
45490
|
async backfillLogins() {
|
|
45414
|
-
if ((0,
|
|
45491
|
+
if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
|
|
45415
45492
|
const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
|
|
45416
45493
|
const byUser = parseAcceptedLogins(out ?? "");
|
|
45417
45494
|
const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
|
|
@@ -45424,7 +45501,7 @@ var PrivilegeWatch = class {
|
|
|
45424
45501
|
return;
|
|
45425
45502
|
}
|
|
45426
45503
|
}
|
|
45427
|
-
if ((0,
|
|
45504
|
+
if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
|
|
45428
45505
|
const at = this.now().toISOString();
|
|
45429
45506
|
const history = {};
|
|
45430
45507
|
for (const [user, userIps] of byUser) {
|
|
@@ -45636,8 +45713,8 @@ var RuleEngine = class {
|
|
|
45636
45713
|
};
|
|
45637
45714
|
|
|
45638
45715
|
// src/daemon/rules/loader.ts
|
|
45639
|
-
var
|
|
45640
|
-
var
|
|
45716
|
+
var import_node_fs39 = require("fs");
|
|
45717
|
+
var import_node_path30 = require("path");
|
|
45641
45718
|
|
|
45642
45719
|
// src/daemon/rules/default-rules.ts
|
|
45643
45720
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -46107,11 +46184,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
46107
46184
|
function loadAllRules(customDir) {
|
|
46108
46185
|
const rules = [...DEFAULT_RULES];
|
|
46109
46186
|
const dir = customDir || RULES_DIR;
|
|
46110
|
-
if ((0,
|
|
46111
|
-
const files = (0,
|
|
46187
|
+
if ((0, import_node_fs39.existsSync)(dir)) {
|
|
46188
|
+
const files = (0, import_node_fs39.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
46112
46189
|
for (const file of files) {
|
|
46113
46190
|
try {
|
|
46114
|
-
const raw = (0,
|
|
46191
|
+
const raw = (0, import_node_fs39.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
|
|
46115
46192
|
const parsed = JSON.parse(raw);
|
|
46116
46193
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
46117
46194
|
for (const rule of customRules) {
|
|
@@ -46143,8 +46220,8 @@ function loadAllRules(customDir) {
|
|
|
46143
46220
|
|
|
46144
46221
|
// src/daemon/firewall/adapters.ts
|
|
46145
46222
|
var import_node_child_process13 = require("child_process");
|
|
46146
|
-
var
|
|
46147
|
-
var
|
|
46223
|
+
var import_node_fs40 = require("fs");
|
|
46224
|
+
var import_node_path31 = require("path");
|
|
46148
46225
|
var import_node_net11 = require("net");
|
|
46149
46226
|
function assertValidFirewallIp(ip) {
|
|
46150
46227
|
if ((0, import_node_net11.isIP)(ip) !== 4) {
|
|
@@ -46157,9 +46234,9 @@ function assertBannableIp(ip) {
|
|
|
46157
46234
|
}
|
|
46158
46235
|
}
|
|
46159
46236
|
function writeIfAbsent(path2, contents) {
|
|
46160
|
-
(0,
|
|
46237
|
+
(0, import_node_fs40.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
|
|
46161
46238
|
try {
|
|
46162
|
-
(0,
|
|
46239
|
+
(0, import_node_fs40.writeFileSync)(path2, contents, { flag: "wx" });
|
|
46163
46240
|
} catch (err) {
|
|
46164
46241
|
if (err.code !== "EEXIST") throw err;
|
|
46165
46242
|
}
|
|
@@ -46418,7 +46495,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
46418
46495
|
}
|
|
46419
46496
|
|
|
46420
46497
|
// src/daemon/firewall/remediation.ts
|
|
46421
|
-
var
|
|
46498
|
+
var import_node_fs41 = require("fs");
|
|
46422
46499
|
var import_node_child_process14 = require("child_process");
|
|
46423
46500
|
var import_node_net12 = require("net");
|
|
46424
46501
|
init_paths();
|
|
@@ -46489,19 +46566,19 @@ var defaultDiscovery = {
|
|
|
46489
46566
|
const snapshot = takeSnapshot({
|
|
46490
46567
|
readFile: (p) => {
|
|
46491
46568
|
try {
|
|
46492
|
-
return (0,
|
|
46569
|
+
return (0, import_node_fs41.readFileSync)(p, "utf-8");
|
|
46493
46570
|
} catch {
|
|
46494
46571
|
return null;
|
|
46495
46572
|
}
|
|
46496
46573
|
},
|
|
46497
46574
|
readDir: (p) => {
|
|
46498
46575
|
try {
|
|
46499
|
-
return (0,
|
|
46576
|
+
return (0, import_node_fs41.readdirSync)(p);
|
|
46500
46577
|
} catch {
|
|
46501
46578
|
return null;
|
|
46502
46579
|
}
|
|
46503
46580
|
},
|
|
46504
|
-
exists: (p) => (0,
|
|
46581
|
+
exists: (p) => (0, import_node_fs41.existsSync)(p)
|
|
46505
46582
|
});
|
|
46506
46583
|
const out = /* @__PURE__ */ new Set();
|
|
46507
46584
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -46942,7 +47019,7 @@ var RemediationManager = class {
|
|
|
46942
47019
|
}
|
|
46943
47020
|
logLine(line2) {
|
|
46944
47021
|
try {
|
|
46945
|
-
(0,
|
|
47022
|
+
(0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
46946
47023
|
`);
|
|
46947
47024
|
} catch {
|
|
46948
47025
|
}
|
|
@@ -46985,19 +47062,19 @@ function remediationSettings(section) {
|
|
|
46985
47062
|
init_backoff();
|
|
46986
47063
|
|
|
46987
47064
|
// src/daemon/watchdog-service.ts
|
|
46988
|
-
var
|
|
46989
|
-
var
|
|
47065
|
+
var import_node_fs42 = require("fs");
|
|
47066
|
+
var import_node_path32 = require("path");
|
|
46990
47067
|
function defaultShareGid() {
|
|
46991
47068
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
46992
47069
|
if (!isRoot4) return void 0;
|
|
46993
47070
|
try {
|
|
46994
|
-
return (0,
|
|
47071
|
+
return (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
|
|
46995
47072
|
} catch {
|
|
46996
47073
|
return void 0;
|
|
46997
47074
|
}
|
|
46998
47075
|
}
|
|
46999
47076
|
function startWatchdog(opts) {
|
|
47000
|
-
const dir = opts.config?.dir ?? (0,
|
|
47077
|
+
const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
47001
47078
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
47002
47079
|
if (opts.config?.enabled === false) {
|
|
47003
47080
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -47112,7 +47189,7 @@ function versionOfNode(path2) {
|
|
|
47112
47189
|
// src/daemon/index.ts
|
|
47113
47190
|
function readVersion2() {
|
|
47114
47191
|
try {
|
|
47115
|
-
const pkg = JSON.parse((0,
|
|
47192
|
+
const pkg = JSON.parse((0, import_node_fs43.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
47116
47193
|
return pkg.version || "0.0.0";
|
|
47117
47194
|
} catch {
|
|
47118
47195
|
return "0.0.0";
|
|
@@ -47121,7 +47198,7 @@ function readVersion2() {
|
|
|
47121
47198
|
async function runHardeningChecks() {
|
|
47122
47199
|
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
|
|
47123
47200
|
process.execPath,
|
|
47124
|
-
[(0,
|
|
47201
|
+
[(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
47125
47202
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
47126
47203
|
);
|
|
47127
47204
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -47135,7 +47212,7 @@ async function runHardeningChecks() {
|
|
|
47135
47212
|
async function runPatchCheck() {
|
|
47136
47213
|
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
|
|
47137
47214
|
process.execPath,
|
|
47138
|
-
[(0,
|
|
47215
|
+
[(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
47139
47216
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
47140
47217
|
);
|
|
47141
47218
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -47143,7 +47220,7 @@ async function runPatchCheck() {
|
|
|
47143
47220
|
}
|
|
47144
47221
|
function logLine(line2) {
|
|
47145
47222
|
try {
|
|
47146
|
-
(0,
|
|
47223
|
+
(0, import_node_fs43.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
47147
47224
|
`);
|
|
47148
47225
|
} catch {
|
|
47149
47226
|
}
|
|
@@ -47185,7 +47262,7 @@ async function runDaemon() {
|
|
|
47185
47262
|
} catch (err) {
|
|
47186
47263
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
47187
47264
|
}
|
|
47188
|
-
const config = loadConfig((0,
|
|
47265
|
+
const config = loadConfig((0, import_node_fs43.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
47189
47266
|
configureAttackDetection(config.detection);
|
|
47190
47267
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
47191
47268
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -47249,7 +47326,7 @@ async function runDaemon() {
|
|
|
47249
47326
|
const threatFeeds = new ThreatFeeds({
|
|
47250
47327
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
47251
47328
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
47252
|
-
cachePath: (0,
|
|
47329
|
+
cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
47253
47330
|
bus,
|
|
47254
47331
|
log: logLine
|
|
47255
47332
|
});
|
|
@@ -47257,9 +47334,9 @@ async function runDaemon() {
|
|
|
47257
47334
|
const privilegeWatch = new PrivilegeWatch({
|
|
47258
47335
|
settings: privilegeSettings(config.privileged),
|
|
47259
47336
|
bus,
|
|
47260
|
-
snapshotPath: (0,
|
|
47261
|
-
loginsPath: (0,
|
|
47262
|
-
cursorPath: (0,
|
|
47337
|
+
snapshotPath: (0, import_node_path33.join)(PATHS.stateDir, "privileges.json"),
|
|
47338
|
+
loginsPath: (0, import_node_path33.join)(PATHS.stateDir, "login-countries.json"),
|
|
47339
|
+
cursorPath: (0, import_node_path33.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
47263
47340
|
log: logLine
|
|
47264
47341
|
});
|
|
47265
47342
|
privilegeWatch.start();
|
|
@@ -47282,7 +47359,7 @@ async function runDaemon() {
|
|
|
47282
47359
|
version,
|
|
47283
47360
|
hostname: (0, import_node_os13.hostname)(),
|
|
47284
47361
|
minSeverity,
|
|
47285
|
-
spoolPath: (0,
|
|
47362
|
+
spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
47286
47363
|
log: logLine,
|
|
47287
47364
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
47288
47365
|
runHardening: runHardeningChecks
|
|
@@ -47301,8 +47378,8 @@ async function runDaemon() {
|
|
|
47301
47378
|
const autoUpdate = new AutoUpdate({
|
|
47302
47379
|
version,
|
|
47303
47380
|
settings: updateSettings(config.update),
|
|
47304
|
-
pkgRoot: (0,
|
|
47305
|
-
statePath: (0,
|
|
47381
|
+
pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
|
|
47382
|
+
statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
|
|
47306
47383
|
bus,
|
|
47307
47384
|
log: logLine,
|
|
47308
47385
|
restartDaemon
|
|
@@ -47392,7 +47469,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
47392
47469
|
function isRoot2() {
|
|
47393
47470
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
47394
47471
|
}
|
|
47395
|
-
var DAEMON_ENTRY = (0,
|
|
47472
|
+
var DAEMON_ENTRY = (0, import_node_path34.join)(__dirname, "daemon.js");
|
|
47396
47473
|
async function daemonForeground() {
|
|
47397
47474
|
await runDaemon();
|
|
47398
47475
|
}
|
|
@@ -47413,7 +47490,7 @@ async function daemonStart() {
|
|
|
47413
47490
|
return;
|
|
47414
47491
|
}
|
|
47415
47492
|
ensureRuntimeDirs();
|
|
47416
|
-
if (!(0,
|
|
47493
|
+
if (!(0, import_node_fs44.existsSync)(DAEMON_ENTRY)) {
|
|
47417
47494
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
47418
47495
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
47419
47496
|
return;
|
|
@@ -47421,8 +47498,8 @@ async function daemonStart() {
|
|
|
47421
47498
|
let out;
|
|
47422
47499
|
let err;
|
|
47423
47500
|
try {
|
|
47424
|
-
out = (0,
|
|
47425
|
-
err = (0,
|
|
47501
|
+
out = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
|
|
47502
|
+
err = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
|
|
47426
47503
|
} catch (e) {
|
|
47427
47504
|
const code = e.code;
|
|
47428
47505
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -47510,12 +47587,12 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
47510
47587
|
}
|
|
47511
47588
|
async function releaseStaleSocket() {
|
|
47512
47589
|
const deadline = Date.now() + 2e3;
|
|
47513
|
-
while ((0,
|
|
47590
|
+
while ((0, import_node_fs44.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
47514
47591
|
await new Promise((r) => setTimeout(r, 50));
|
|
47515
47592
|
}
|
|
47516
|
-
if ((0,
|
|
47593
|
+
if ((0, import_node_fs44.existsSync)(PATHS.socket)) {
|
|
47517
47594
|
try {
|
|
47518
|
-
(0,
|
|
47595
|
+
(0, import_node_fs44.unlinkSync)(PATHS.socket);
|
|
47519
47596
|
} catch {
|
|
47520
47597
|
}
|
|
47521
47598
|
}
|
|
@@ -47523,26 +47600,26 @@ async function releaseStaleSocket() {
|
|
|
47523
47600
|
|
|
47524
47601
|
// src/commands/service.ts
|
|
47525
47602
|
var import_node_child_process18 = require("child_process");
|
|
47526
|
-
var
|
|
47527
|
-
var
|
|
47603
|
+
var import_node_fs46 = require("fs");
|
|
47604
|
+
var import_node_path35 = require("path");
|
|
47528
47605
|
var import_node_os14 = require("os");
|
|
47529
47606
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
47530
47607
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
47531
47608
|
function resolveTemplate() {
|
|
47532
|
-
const templatePath = (0,
|
|
47533
|
-
if (!(0,
|
|
47609
|
+
const templatePath = (0, import_node_path35.join)(__dirname, "systemd", "threatcrushd.service");
|
|
47610
|
+
if (!(0, import_node_fs46.existsSync)(templatePath)) {
|
|
47534
47611
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
47535
47612
|
}
|
|
47536
|
-
return (0,
|
|
47613
|
+
return (0, import_node_fs46.readFileSync)(templatePath, "utf-8");
|
|
47537
47614
|
}
|
|
47538
47615
|
function stableBinPath(binPath) {
|
|
47539
47616
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
47540
47617
|
if (stable === binPath) return binPath;
|
|
47541
|
-
return (0,
|
|
47618
|
+
return (0, import_node_fs46.existsSync)(stable) ? stable : binPath;
|
|
47542
47619
|
}
|
|
47543
47620
|
function resolveBinPath() {
|
|
47544
47621
|
const arg = process.argv[1];
|
|
47545
|
-
if (arg && (0,
|
|
47622
|
+
if (arg && (0, import_node_fs46.existsSync)(arg)) return stableBinPath(arg);
|
|
47546
47623
|
try {
|
|
47547
47624
|
return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
47548
47625
|
} catch {
|
|
@@ -47552,11 +47629,11 @@ function resolveBinPath() {
|
|
|
47552
47629
|
function stableNodePath(execPath) {
|
|
47553
47630
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
47554
47631
|
if (stable === execPath) return execPath;
|
|
47555
|
-
return (0,
|
|
47632
|
+
return (0, import_node_fs46.existsSync)(stable) ? stable : execPath;
|
|
47556
47633
|
}
|
|
47557
47634
|
function looksLikeNodeScript(path2) {
|
|
47558
47635
|
try {
|
|
47559
|
-
const head = (0,
|
|
47636
|
+
const head = (0, import_node_fs46.readFileSync)(path2, "utf-8").slice(0, 120);
|
|
47560
47637
|
return /^#!.*\bnode\b/.test(head);
|
|
47561
47638
|
} catch {
|
|
47562
47639
|
return false;
|
|
@@ -47596,7 +47673,7 @@ function callerHome() {
|
|
|
47596
47673
|
try {
|
|
47597
47674
|
const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
47598
47675
|
const home = line2.split(":")[5];
|
|
47599
|
-
return home && (0,
|
|
47676
|
+
return home && (0, import_node_fs46.existsSync)(home) ? home : null;
|
|
47600
47677
|
} catch {
|
|
47601
47678
|
return null;
|
|
47602
47679
|
}
|
|
@@ -47604,13 +47681,13 @@ function callerHome() {
|
|
|
47604
47681
|
function stopUserModeDaemon() {
|
|
47605
47682
|
const home = callerHome();
|
|
47606
47683
|
if (!home) return;
|
|
47607
|
-
const runDir = (0,
|
|
47608
|
-
const pidFile = (0,
|
|
47609
|
-
const socket = (0,
|
|
47610
|
-
if (!(0,
|
|
47684
|
+
const runDir = (0, import_node_path35.join)(home, ".threatcrush", "run");
|
|
47685
|
+
const pidFile = (0, import_node_path35.join)(runDir, "threatcrushd.pid");
|
|
47686
|
+
const socket = (0, import_node_path35.join)(runDir, "threatcrushd.sock");
|
|
47687
|
+
if (!(0, import_node_fs46.existsSync)(pidFile) && !(0, import_node_fs46.existsSync)(socket)) return;
|
|
47611
47688
|
let pid = null;
|
|
47612
47689
|
try {
|
|
47613
|
-
pid = Number.parseInt((0,
|
|
47690
|
+
pid = Number.parseInt((0, import_node_fs46.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
47614
47691
|
} catch {
|
|
47615
47692
|
pid = null;
|
|
47616
47693
|
}
|
|
@@ -47623,7 +47700,7 @@ function stopUserModeDaemon() {
|
|
|
47623
47700
|
}
|
|
47624
47701
|
for (const path2 of [socket, pidFile]) {
|
|
47625
47702
|
try {
|
|
47626
|
-
if ((0,
|
|
47703
|
+
if ((0, import_node_fs46.existsSync)(path2)) (0, import_node_fs46.rmSync)(path2);
|
|
47627
47704
|
} catch {
|
|
47628
47705
|
}
|
|
47629
47706
|
}
|
|
@@ -47641,7 +47718,7 @@ async function installServiceCommand() {
|
|
|
47641
47718
|
}
|
|
47642
47719
|
const noSystemd = systemdUnavailableReason({
|
|
47643
47720
|
hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
47644
|
-
booted: (0,
|
|
47721
|
+
booted: (0, import_node_fs46.existsSync)("/run/systemd/system")
|
|
47645
47722
|
});
|
|
47646
47723
|
if (noSystemd) {
|
|
47647
47724
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -47663,7 +47740,7 @@ async function installServiceCommand() {
|
|
|
47663
47740
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
47664
47741
|
let nodePath = stableNodePath(process.execPath);
|
|
47665
47742
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
47666
|
-
binPath = (0,
|
|
47743
|
+
binPath = (0, import_node_fs46.realpathSync)(binPath);
|
|
47667
47744
|
nodePath = process.execPath;
|
|
47668
47745
|
}
|
|
47669
47746
|
if (isNodeScript) {
|
|
@@ -47676,9 +47753,9 @@ async function installServiceCommand() {
|
|
|
47676
47753
|
}
|
|
47677
47754
|
}
|
|
47678
47755
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
47679
|
-
const configDir = (0,
|
|
47756
|
+
const configDir = (0, import_node_path35.join)((0, import_node_os14.homedir)(), ".threatcrush");
|
|
47680
47757
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
47681
|
-
(0,
|
|
47758
|
+
(0, import_node_fs46.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
47682
47759
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
47683
47760
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
47684
47761
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -47731,9 +47808,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
47731
47808
|
].join("\n");
|
|
47732
47809
|
}
|
|
47733
47810
|
function installLogrotate() {
|
|
47734
|
-
if (!(0,
|
|
47811
|
+
if (!(0, import_node_fs46.existsSync)((0, import_node_path35.dirname)(LOGROTATE_PATH))) return;
|
|
47735
47812
|
try {
|
|
47736
|
-
(0,
|
|
47813
|
+
(0, import_node_fs46.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
47737
47814
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
47738
47815
|
} catch (err) {
|
|
47739
47816
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -47755,20 +47832,20 @@ function ensureSystemDirs(configDir) {
|
|
|
47755
47832
|
];
|
|
47756
47833
|
let admGid2 = null;
|
|
47757
47834
|
try {
|
|
47758
|
-
admGid2 = (0,
|
|
47835
|
+
admGid2 = (0, import_node_fs46.statSync)("/var/log/auth.log").gid;
|
|
47759
47836
|
} catch {
|
|
47760
47837
|
}
|
|
47761
47838
|
for (const { path: path2, groupWritable, sticky } of dirs) {
|
|
47762
47839
|
try {
|
|
47763
|
-
(0,
|
|
47840
|
+
(0, import_node_fs46.mkdirSync)(path2, { recursive: true });
|
|
47764
47841
|
} catch {
|
|
47765
47842
|
}
|
|
47766
47843
|
try {
|
|
47767
47844
|
if (groupWritable && admGid2 !== null) {
|
|
47768
|
-
(0,
|
|
47845
|
+
(0, import_node_fs46.chmodSync)(path2, sticky ? 1533 : 509);
|
|
47769
47846
|
(0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
|
|
47770
47847
|
} else {
|
|
47771
|
-
(0,
|
|
47848
|
+
(0, import_node_fs46.chmodSync)(path2, 493);
|
|
47772
47849
|
}
|
|
47773
47850
|
} catch {
|
|
47774
47851
|
}
|
|
@@ -47796,7 +47873,7 @@ async function uninstallServiceCommand() {
|
|
|
47796
47873
|
} catch {
|
|
47797
47874
|
}
|
|
47798
47875
|
try {
|
|
47799
|
-
if ((0,
|
|
47876
|
+
if ((0, import_node_fs46.existsSync)(UNIT_PATH)) {
|
|
47800
47877
|
(0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
|
|
47801
47878
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
47802
47879
|
}
|
|
@@ -47810,7 +47887,7 @@ async function uninstallServiceCommand() {
|
|
|
47810
47887
|
}
|
|
47811
47888
|
|
|
47812
47889
|
// src/commands/save.ts
|
|
47813
|
-
var
|
|
47890
|
+
var import_node_fs47 = require("fs");
|
|
47814
47891
|
var import_toml5 = __toESM(require_toml());
|
|
47815
47892
|
init_cli_config();
|
|
47816
47893
|
init_paths();
|
|
@@ -47849,9 +47926,9 @@ async function saveCommand(opts = {}) {
|
|
|
47849
47926
|
}
|
|
47850
47927
|
const path2 = opts.config ?? PATHS.configFile;
|
|
47851
47928
|
let config = {};
|
|
47852
|
-
if ((0,
|
|
47929
|
+
if ((0, import_node_fs47.existsSync)(path2)) {
|
|
47853
47930
|
try {
|
|
47854
|
-
config = import_toml5.default.parse((0,
|
|
47931
|
+
config = import_toml5.default.parse((0, import_node_fs47.readFileSync)(path2, "utf-8"));
|
|
47855
47932
|
} catch (err) {
|
|
47856
47933
|
console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
|
|
47857
47934
|
`));
|
|
@@ -47964,8 +48041,8 @@ function welcomeCommand() {
|
|
|
47964
48041
|
}
|
|
47965
48042
|
|
|
47966
48043
|
// src/commands/properties.ts
|
|
47967
|
-
var
|
|
47968
|
-
var
|
|
48044
|
+
var import_node_fs48 = require("fs");
|
|
48045
|
+
var import_node_path36 = require("path");
|
|
47969
48046
|
var import_node_readline4 = __toESM(require("readline"));
|
|
47970
48047
|
init_cli_config();
|
|
47971
48048
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -48295,8 +48372,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
48295
48372
|
}
|
|
48296
48373
|
}
|
|
48297
48374
|
function parseImportFile(path2) {
|
|
48298
|
-
const ext = (0,
|
|
48299
|
-
const raw = (0,
|
|
48375
|
+
const ext = (0, import_node_path36.extname)(path2).toLowerCase();
|
|
48376
|
+
const raw = (0, import_node_fs48.readFileSync)(path2, "utf-8");
|
|
48300
48377
|
if (ext === ".json") {
|
|
48301
48378
|
const parsed = JSON.parse(raw);
|
|
48302
48379
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -48491,7 +48568,7 @@ async function rulesCommand(opts) {
|
|
|
48491
48568
|
}
|
|
48492
48569
|
|
|
48493
48570
|
// src/commands/harden.ts
|
|
48494
|
-
var
|
|
48571
|
+
var import_node_fs49 = require("fs");
|
|
48495
48572
|
var import_node_child_process19 = require("child_process");
|
|
48496
48573
|
init_cli_config();
|
|
48497
48574
|
function tryExec(cmd) {
|
|
@@ -48503,7 +48580,7 @@ function tryExec(cmd) {
|
|
|
48503
48580
|
}
|
|
48504
48581
|
function tryRead(path2) {
|
|
48505
48582
|
try {
|
|
48506
|
-
return (0,
|
|
48583
|
+
return (0, import_node_fs49.readFileSync)(path2, "utf-8");
|
|
48507
48584
|
} catch {
|
|
48508
48585
|
return null;
|
|
48509
48586
|
}
|
|
@@ -48607,8 +48684,8 @@ function checkSshWeakConfig() {
|
|
|
48607
48684
|
};
|
|
48608
48685
|
}
|
|
48609
48686
|
function checkAutoUpdates() {
|
|
48610
|
-
const unattended = (0,
|
|
48611
|
-
const dnfAuto = (0,
|
|
48687
|
+
const unattended = (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
48688
|
+
const dnfAuto = (0, import_node_fs49.existsSync)("/etc/dnf/automatic.conf");
|
|
48612
48689
|
if (unattended || dnfAuto) {
|
|
48613
48690
|
return {
|
|
48614
48691
|
key: "auto-updates",
|
|
@@ -48734,7 +48811,7 @@ function checkFail2ban() {
|
|
|
48734
48811
|
explanation: "fail2ban is installed and running."
|
|
48735
48812
|
};
|
|
48736
48813
|
}
|
|
48737
|
-
if ((0,
|
|
48814
|
+
if ((0, import_node_fs49.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
48738
48815
|
return {
|
|
48739
48816
|
key: checkKey,
|
|
48740
48817
|
status: "warn",
|
|
@@ -48920,8 +48997,8 @@ async function hardenCommand(opts) {
|
|
|
48920
48997
|
}
|
|
48921
48998
|
|
|
48922
48999
|
// src/core/patches/index.ts
|
|
48923
|
-
var
|
|
48924
|
-
var
|
|
49000
|
+
var import_node_fs50 = require("fs");
|
|
49001
|
+
var import_node_path37 = require("path");
|
|
48925
49002
|
var import_node_child_process20 = require("child_process");
|
|
48926
49003
|
var import_node_util5 = require("util");
|
|
48927
49004
|
|
|
@@ -49081,9 +49158,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
49081
49158
|
function newestReleaseMtime(dir) {
|
|
49082
49159
|
try {
|
|
49083
49160
|
let newest = 0;
|
|
49084
|
-
for (const name of (0,
|
|
49161
|
+
for (const name of (0, import_node_fs50.readdirSync)(dir)) {
|
|
49085
49162
|
if (!/Release$/.test(name)) continue;
|
|
49086
|
-
newest = Math.max(newest, (0,
|
|
49163
|
+
newest = Math.max(newest, (0, import_node_fs50.statSync)((0, import_node_path37.join)(dir, name)).mtimeMs);
|
|
49087
49164
|
}
|
|
49088
49165
|
return newest > 0 ? new Date(newest) : null;
|
|
49089
49166
|
} catch {
|
|
@@ -49100,7 +49177,7 @@ async function checkPatches(opts = {}) {
|
|
|
49100
49177
|
let osText = opts.osRelease;
|
|
49101
49178
|
if (osText === void 0) {
|
|
49102
49179
|
try {
|
|
49103
|
-
osText = (0,
|
|
49180
|
+
osText = (0, import_node_fs50.readFileSync)("/etc/os-release", "utf-8");
|
|
49104
49181
|
} catch {
|
|
49105
49182
|
osText = "";
|
|
49106
49183
|
}
|
|
@@ -49327,24 +49404,24 @@ async function patchesCommand(opts) {
|
|
|
49327
49404
|
|
|
49328
49405
|
// src/commands/feeds.ts
|
|
49329
49406
|
var import_node_net13 = require("net");
|
|
49330
|
-
var
|
|
49407
|
+
var import_node_path39 = require("path");
|
|
49331
49408
|
init_paths();
|
|
49332
49409
|
|
|
49333
49410
|
// src/commands/feeds-resolver.ts
|
|
49334
49411
|
var import_node_child_process21 = require("child_process");
|
|
49335
|
-
var
|
|
49336
|
-
var
|
|
49412
|
+
var import_node_fs51 = require("fs");
|
|
49413
|
+
var import_node_path38 = require("path");
|
|
49337
49414
|
var realIO = {
|
|
49338
|
-
exists: (p) => (0,
|
|
49415
|
+
exists: (p) => (0, import_node_fs51.existsSync)(p),
|
|
49339
49416
|
read: (p) => {
|
|
49340
49417
|
try {
|
|
49341
|
-
return (0,
|
|
49418
|
+
return (0, import_node_fs51.readFileSync)(p, "utf-8");
|
|
49342
49419
|
} catch {
|
|
49343
49420
|
return null;
|
|
49344
49421
|
}
|
|
49345
49422
|
},
|
|
49346
|
-
write: (p, c) => (0,
|
|
49347
|
-
remove: (p) => (0,
|
|
49423
|
+
write: (p, c) => (0, import_node_fs51.writeFileSync)(p, c),
|
|
49424
|
+
remove: (p) => (0, import_node_fs51.rmSync)(p, { force: true }),
|
|
49348
49425
|
run: (cmd, args) => {
|
|
49349
49426
|
const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
49350
49427
|
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
@@ -49354,17 +49431,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
|
49354
49431
|
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
49355
49432
|
function hookContent(resolver, stateDir) {
|
|
49356
49433
|
const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
49357
|
-
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0,
|
|
49358
|
-
` : `${head}include: "${(0,
|
|
49434
|
+
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
49435
|
+
` : `${head}include: "${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
49359
49436
|
`;
|
|
49360
49437
|
}
|
|
49361
49438
|
function apparmorRule(stateDir) {
|
|
49362
|
-
return ` ${(0,
|
|
49439
|
+
return ` ${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
49363
49440
|
}
|
|
49364
49441
|
function detectResolvers(io = realIO) {
|
|
49365
49442
|
const found = [];
|
|
49366
|
-
if (io.exists((0,
|
|
49367
|
-
if (io.exists((0,
|
|
49443
|
+
if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
49444
|
+
if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
49368
49445
|
return found;
|
|
49369
49446
|
}
|
|
49370
49447
|
function check(resolver, io) {
|
|
@@ -49377,7 +49454,7 @@ function restartIfActive(resolver, io) {
|
|
|
49377
49454
|
}
|
|
49378
49455
|
function installHook(resolver, stateDir, io = realIO) {
|
|
49379
49456
|
const hook = RESOLVER_HOOKS[resolver];
|
|
49380
|
-
const file = (0,
|
|
49457
|
+
const file = (0, import_node_path38.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
49381
49458
|
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
49382
49459
|
io.write(hook, hookContent(resolver, stateDir));
|
|
49383
49460
|
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
@@ -49438,8 +49515,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
49438
49515
|
}
|
|
49439
49516
|
return failed ? 1 : 0;
|
|
49440
49517
|
}
|
|
49441
|
-
const hosts = io.read((0,
|
|
49442
|
-
const unbound = io.read((0,
|
|
49518
|
+
const hosts = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts));
|
|
49519
|
+
const unbound = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound));
|
|
49443
49520
|
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
49444
49521
|
for (const r of ["dnsmasq", "unbound"]) {
|
|
49445
49522
|
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
@@ -49451,11 +49528,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
49451
49528
|
// src/commands/feeds.ts
|
|
49452
49529
|
async function loadSet() {
|
|
49453
49530
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
49454
|
-
const path2 = (0,
|
|
49531
|
+
const path2 = (0, import_node_path39.join)(dir, "threat-feeds.json");
|
|
49455
49532
|
const set = readFeedCache(path2);
|
|
49456
49533
|
if (set) return { set, from: path2 };
|
|
49457
49534
|
}
|
|
49458
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
49535
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path39.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
49459
49536
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
49460
49537
|
}
|
|
49461
49538
|
async function feedsCommand(action, value, opts) {
|
|
@@ -49500,13 +49577,13 @@ async function feedsCommand(action, value, opts) {
|
|
|
49500
49577
|
|
|
49501
49578
|
// src/commands/reputation.ts
|
|
49502
49579
|
var import_node_os15 = require("os");
|
|
49503
|
-
var
|
|
49504
|
-
var
|
|
49580
|
+
var import_node_fs52 = require("fs");
|
|
49581
|
+
var import_node_path40 = require("path");
|
|
49505
49582
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
49506
|
-
var CONFIG_PATH4 = (0,
|
|
49583
|
+
var CONFIG_PATH4 = (0, import_node_path40.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
|
|
49507
49584
|
function readConfig3() {
|
|
49508
49585
|
try {
|
|
49509
|
-
return JSON.parse((0,
|
|
49586
|
+
return JSON.parse((0, import_node_fs52.readFileSync)(CONFIG_PATH4, "utf-8"));
|
|
49510
49587
|
} catch {
|
|
49511
49588
|
return {};
|
|
49512
49589
|
}
|
|
@@ -49694,7 +49771,7 @@ async function reputationSubscribeCommand(opts) {
|
|
|
49694
49771
|
}
|
|
49695
49772
|
|
|
49696
49773
|
// src/commands/privileged.ts
|
|
49697
|
-
var
|
|
49774
|
+
var import_node_fs53 = require("fs");
|
|
49698
49775
|
init_paths();
|
|
49699
49776
|
var SEV2 = {
|
|
49700
49777
|
critical: source_default.red.bold,
|
|
@@ -49707,19 +49784,19 @@ async function privilegedCommand(opts) {
|
|
|
49707
49784
|
const snapshot = takeSnapshot({
|
|
49708
49785
|
readFile: (p) => {
|
|
49709
49786
|
try {
|
|
49710
|
-
return (0,
|
|
49787
|
+
return (0, import_node_fs53.readFileSync)(p, "utf-8");
|
|
49711
49788
|
} catch {
|
|
49712
49789
|
return null;
|
|
49713
49790
|
}
|
|
49714
49791
|
},
|
|
49715
49792
|
readDir: (p) => {
|
|
49716
49793
|
try {
|
|
49717
|
-
return (0,
|
|
49794
|
+
return (0, import_node_fs53.readdirSync)(p);
|
|
49718
49795
|
} catch {
|
|
49719
49796
|
return null;
|
|
49720
49797
|
}
|
|
49721
49798
|
},
|
|
49722
|
-
exists: (p) => (0,
|
|
49799
|
+
exists: (p) => (0, import_node_fs53.existsSync)(p)
|
|
49723
49800
|
});
|
|
49724
49801
|
let events = [];
|
|
49725
49802
|
let ledgerNote = "";
|
|
@@ -49901,7 +49978,7 @@ async function allowlistCommand(opts) {
|
|
|
49901
49978
|
}
|
|
49902
49979
|
|
|
49903
49980
|
// src/commands/abuse.ts
|
|
49904
|
-
var
|
|
49981
|
+
var import_node_fs54 = require("fs");
|
|
49905
49982
|
init_paths();
|
|
49906
49983
|
function rows(records) {
|
|
49907
49984
|
if (records.length === 0) {
|
|
@@ -49961,7 +50038,7 @@ function abuseRetractCommand(id, opts = {}) {
|
|
|
49961
50038
|
);
|
|
49962
50039
|
}
|
|
49963
50040
|
function abuseStatusCommand(opts = {}) {
|
|
49964
|
-
const config = loadConfig((0,
|
|
50041
|
+
const config = loadConfig((0, import_node_fs54.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
49965
50042
|
const cfg = resolveConfig(config.abuse_reporter);
|
|
49966
50043
|
const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
|
|
49967
50044
|
const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
|
|
@@ -50142,7 +50219,7 @@ ${source_default.dim(" C R U S H")}
|
|
|
50142
50219
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
50143
50220
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
50144
50221
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
50145
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
50222
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush", "install.json");
|
|
50146
50223
|
function detectPackageManager() {
|
|
50147
50224
|
try {
|
|
50148
50225
|
const npmGlobal = (0, import_node_child_process23.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
@@ -50168,7 +50245,7 @@ function detectPackageManager() {
|
|
|
50168
50245
|
}
|
|
50169
50246
|
function readInstallConfig() {
|
|
50170
50247
|
try {
|
|
50171
|
-
return JSON.parse((0,
|
|
50248
|
+
return JSON.parse((0, import_node_fs55.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
50172
50249
|
} catch {
|
|
50173
50250
|
return {};
|
|
50174
50251
|
}
|
|
@@ -50508,7 +50585,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
50508
50585
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
50509
50586
|
console.log(LOGO2);
|
|
50510
50587
|
const logPath2 = PATHS.logFile;
|
|
50511
|
-
if (!(0,
|
|
50588
|
+
if (!(0, import_node_fs55.existsSync)(logPath2)) {
|
|
50512
50589
|
console.log(source_default.yellow(` No log file found at ${logPath2}`));
|
|
50513
50590
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
50514
50591
|
return;
|
|
@@ -50681,10 +50758,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
50681
50758
|
});
|
|
50682
50759
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
50683
50760
|
console.log(LOGO2);
|
|
50684
|
-
const configPath = (0,
|
|
50761
|
+
const configPath = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
|
|
50685
50762
|
let email = "";
|
|
50686
50763
|
try {
|
|
50687
|
-
const config = JSON.parse((0,
|
|
50764
|
+
const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
|
|
50688
50765
|
email = config.email || "";
|
|
50689
50766
|
} catch {
|
|
50690
50767
|
}
|
|
@@ -50701,9 +50778,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
50701
50778
|
return;
|
|
50702
50779
|
}
|
|
50703
50780
|
try {
|
|
50704
|
-
const dir = (0,
|
|
50705
|
-
if (!(0,
|
|
50706
|
-
(0,
|
|
50781
|
+
const dir = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush");
|
|
50782
|
+
if (!(0, import_node_fs55.existsSync)(dir)) (0, import_node_fs55.mkdirSync)(dir, { recursive: true });
|
|
50783
|
+
(0, import_node_fs55.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
50707
50784
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
50708
50785
|
} catch {
|
|
50709
50786
|
}
|