@profullstack/threatcrush 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/daemon.js +266 -262
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +1555 -689
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/daemon.js
CHANGED
|
@@ -9356,10 +9356,10 @@ var require_dist = __commonJS({
|
|
|
9356
9356
|
});
|
|
9357
9357
|
|
|
9358
9358
|
// src/daemon/index.ts
|
|
9359
|
-
var
|
|
9359
|
+
var import_node_fs45 = require("fs");
|
|
9360
9360
|
var import_node_child_process18 = require("child_process");
|
|
9361
9361
|
var import_node_os8 = require("os");
|
|
9362
|
-
var
|
|
9362
|
+
var import_node_path34 = require("path");
|
|
9363
9363
|
var import_node_util = require("util");
|
|
9364
9364
|
|
|
9365
9365
|
// src/daemon/paths.ts
|
|
@@ -19318,9 +19318,9 @@ function slackChannel(webhookUrl) {
|
|
|
19318
19318
|
|
|
19319
19319
|
// src/daemon/workers/runs-worker.ts
|
|
19320
19320
|
var import_promises = require("dns/promises");
|
|
19321
|
-
var
|
|
19321
|
+
var import_node_fs21 = require("fs");
|
|
19322
19322
|
var import_node_net6 = require("net");
|
|
19323
|
-
var
|
|
19323
|
+
var import_node_path16 = require("path");
|
|
19324
19324
|
|
|
19325
19325
|
// src/core/cli-config.ts
|
|
19326
19326
|
var import_node_fs15 = require("fs");
|
|
@@ -19528,8 +19528,8 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
19528
19528
|
}
|
|
19529
19529
|
|
|
19530
19530
|
// src/commands/scan.ts
|
|
19531
|
-
var
|
|
19532
|
-
var
|
|
19531
|
+
var import_node_fs20 = require("fs");
|
|
19532
|
+
var import_node_path15 = require("path");
|
|
19533
19533
|
|
|
19534
19534
|
// ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/utilities.js
|
|
19535
19535
|
function stringReplaceAll(string, substring, postfix) {
|
|
@@ -25158,14 +25158,18 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
25158
25158
|
var import_node_crypto4 = require("crypto");
|
|
25159
25159
|
var import_node_path13 = require("path");
|
|
25160
25160
|
|
|
25161
|
+
// src/scanverify/index.ts
|
|
25162
|
+
var import_node_fs19 = require("fs");
|
|
25163
|
+
var import_node_path14 = require("path");
|
|
25164
|
+
|
|
25161
25165
|
// src/commands/scan.ts
|
|
25162
25166
|
function readVersion() {
|
|
25163
25167
|
for (const candidate of [
|
|
25164
|
-
(0,
|
|
25165
|
-
(0,
|
|
25168
|
+
(0, import_node_path15.join)(__dirname, "..", "package.json"),
|
|
25169
|
+
(0, import_node_path15.join)(__dirname, "..", "..", "package.json")
|
|
25166
25170
|
]) {
|
|
25167
25171
|
try {
|
|
25168
|
-
return JSON.parse((0,
|
|
25172
|
+
return JSON.parse((0, import_node_fs20.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
|
|
25169
25173
|
} catch {
|
|
25170
25174
|
}
|
|
25171
25175
|
}
|
|
@@ -25413,24 +25417,24 @@ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0,
|
|
|
25413
25417
|
const inside = addresses.find((a) => !isPublicTarget(a));
|
|
25414
25418
|
return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
|
|
25415
25419
|
}
|
|
25416
|
-
function scanTargetError(target, roots, real =
|
|
25420
|
+
function scanTargetError(target, roots, real = import_node_fs21.realpathSync) {
|
|
25417
25421
|
if (roots.length === 0) {
|
|
25418
25422
|
return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
|
|
25419
25423
|
}
|
|
25420
25424
|
let path;
|
|
25421
25425
|
try {
|
|
25422
|
-
path = real((0,
|
|
25426
|
+
path = real((0, import_node_path16.resolve)(target));
|
|
25423
25427
|
} catch {
|
|
25424
25428
|
return `no such path: ${target}`;
|
|
25425
25429
|
}
|
|
25426
25430
|
for (const root of roots) {
|
|
25427
25431
|
let base;
|
|
25428
25432
|
try {
|
|
25429
|
-
base = real((0,
|
|
25433
|
+
base = real((0, import_node_path16.resolve)(root));
|
|
25430
25434
|
} catch {
|
|
25431
25435
|
continue;
|
|
25432
25436
|
}
|
|
25433
|
-
if (path === base || path.startsWith(base.endsWith(
|
|
25437
|
+
if (path === base || path.startsWith(base.endsWith(import_node_path16.sep) ? base : base + import_node_path16.sep)) return null;
|
|
25434
25438
|
}
|
|
25435
25439
|
return `${target} is outside [cloud] run_scan_paths`;
|
|
25436
25440
|
}
|
|
@@ -25581,16 +25585,16 @@ var RunsWorker = class {
|
|
|
25581
25585
|
};
|
|
25582
25586
|
|
|
25583
25587
|
// src/daemon/workers/cloud-spool.ts
|
|
25584
|
-
var
|
|
25588
|
+
var import_node_fs22 = require("fs");
|
|
25585
25589
|
var import_promises2 = require("fs/promises");
|
|
25586
|
-
var
|
|
25590
|
+
var import_node_path17 = require("path");
|
|
25587
25591
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
25588
25592
|
var CloudSpool = class {
|
|
25589
25593
|
constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
|
|
25590
25594
|
this.path = path;
|
|
25591
25595
|
this.limits = limits;
|
|
25592
25596
|
try {
|
|
25593
|
-
(0,
|
|
25597
|
+
(0, import_node_fs22.mkdirSync)((0, import_node_path17.dirname)(path), { recursive: true });
|
|
25594
25598
|
} catch {
|
|
25595
25599
|
}
|
|
25596
25600
|
this.load();
|
|
@@ -25659,7 +25663,7 @@ var CloudSpool = class {
|
|
|
25659
25663
|
load() {
|
|
25660
25664
|
let raw;
|
|
25661
25665
|
try {
|
|
25662
|
-
raw = (0,
|
|
25666
|
+
raw = (0, import_node_fs22.readFileSync)(this.path, "utf-8");
|
|
25663
25667
|
} catch {
|
|
25664
25668
|
return;
|
|
25665
25669
|
}
|
|
@@ -26136,31 +26140,31 @@ function resolveConfig(section) {
|
|
|
26136
26140
|
}
|
|
26137
26141
|
|
|
26138
26142
|
// src/core/abuse-report-log.ts
|
|
26139
|
-
var
|
|
26140
|
-
var
|
|
26143
|
+
var import_node_fs23 = require("fs");
|
|
26144
|
+
var import_node_path18 = require("path");
|
|
26141
26145
|
var ABUSE_DIRNAME = "abuse-reports";
|
|
26142
26146
|
var LOG_FILE = "reports.jsonl";
|
|
26143
26147
|
function resolveAbuseDir(dir) {
|
|
26144
26148
|
if (dir) return dir;
|
|
26145
26149
|
if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
|
|
26146
|
-
const system = (0,
|
|
26147
|
-
if ((0,
|
|
26148
|
-
return (0,
|
|
26150
|
+
const system = (0, import_node_path18.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
|
|
26151
|
+
if ((0, import_node_fs23.existsSync)(system)) return system;
|
|
26152
|
+
return (0, import_node_path18.join)(PATHS.stateDir, ABUSE_DIRNAME);
|
|
26149
26153
|
}
|
|
26150
26154
|
function logPath(dir) {
|
|
26151
|
-
return (0,
|
|
26155
|
+
return (0, import_node_path18.join)(resolveAbuseDir(dir), LOG_FILE);
|
|
26152
26156
|
}
|
|
26153
26157
|
function appendReport(record, dir) {
|
|
26154
26158
|
const path = logPath(dir);
|
|
26155
|
-
(0,
|
|
26156
|
-
(0,
|
|
26159
|
+
(0, import_node_fs23.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
|
|
26160
|
+
(0, import_node_fs23.appendFileSync)(path, `${JSON.stringify(record)}
|
|
26157
26161
|
`, { mode: 420 });
|
|
26158
26162
|
}
|
|
26159
26163
|
function readReports(dir) {
|
|
26160
26164
|
const path = logPath(dir);
|
|
26161
26165
|
let raw;
|
|
26162
26166
|
try {
|
|
26163
|
-
raw = (0,
|
|
26167
|
+
raw = (0, import_node_fs23.readFileSync)(path, "utf-8");
|
|
26164
26168
|
} catch {
|
|
26165
26169
|
return [];
|
|
26166
26170
|
}
|
|
@@ -26566,8 +26570,8 @@ var RemediationConsumer = class {
|
|
|
26566
26570
|
|
|
26567
26571
|
// src/daemon/workers/auto-update.ts
|
|
26568
26572
|
var import_node_child_process5 = require("child_process");
|
|
26569
|
-
var
|
|
26570
|
-
var
|
|
26573
|
+
var import_node_fs24 = require("fs");
|
|
26574
|
+
var import_node_path19 = require("path");
|
|
26571
26575
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
26572
26576
|
var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
|
|
26573
26577
|
var DEFAULT_INTERVAL_MS = 6 * 36e5;
|
|
@@ -26610,12 +26614,12 @@ function pickUpdate(doc, current, opts) {
|
|
|
26610
26614
|
return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
|
|
26611
26615
|
}
|
|
26612
26616
|
function installPlan(opts) {
|
|
26613
|
-
const expected = `${
|
|
26617
|
+
const expected = `${import_node_path19.sep}lib${import_node_path19.sep}node_modules${import_node_path19.sep}@profullstack${import_node_path19.sep}threatcrush`;
|
|
26614
26618
|
if (!opts.pkgRoot.endsWith(expected)) {
|
|
26615
26619
|
return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
|
|
26616
26620
|
}
|
|
26617
|
-
const nodeBin = (0,
|
|
26618
|
-
const npm = (0,
|
|
26621
|
+
const nodeBin = (0, import_node_path19.dirname)(opts.execPath);
|
|
26622
|
+
const npm = (0, import_node_path19.join)(nodeBin, "npm");
|
|
26619
26623
|
if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
|
|
26620
26624
|
if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
|
|
26621
26625
|
const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
|
|
@@ -26647,10 +26651,10 @@ function installPlan(opts) {
|
|
|
26647
26651
|
}
|
|
26648
26652
|
function ownerOf(path, passwd = "/etc/passwd") {
|
|
26649
26653
|
try {
|
|
26650
|
-
const st = (0,
|
|
26654
|
+
const st = (0, import_node_fs24.statSync)(path);
|
|
26651
26655
|
let home = st.uid === 0 ? "/root" : "";
|
|
26652
26656
|
try {
|
|
26653
|
-
for (const line of (0,
|
|
26657
|
+
for (const line of (0, import_node_fs24.readFileSync)(passwd, "utf8").split("\n")) {
|
|
26654
26658
|
const f = line.split(":");
|
|
26655
26659
|
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
26656
26660
|
}
|
|
@@ -26760,7 +26764,7 @@ var AutoUpdate = class {
|
|
|
26760
26764
|
uid: process.getuid?.() ?? -1,
|
|
26761
26765
|
owner: ownerOf(this.opts.pkgRoot),
|
|
26762
26766
|
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
26763
|
-
npmExists:
|
|
26767
|
+
npmExists: import_node_fs24.existsSync
|
|
26764
26768
|
});
|
|
26765
26769
|
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
26766
26770
|
this.recordAttempt(target);
|
|
@@ -26796,7 +26800,7 @@ var AutoUpdate = class {
|
|
|
26796
26800
|
}
|
|
26797
26801
|
lastAttempt() {
|
|
26798
26802
|
try {
|
|
26799
|
-
const v = JSON.parse((0,
|
|
26803
|
+
const v = JSON.parse((0, import_node_fs24.readFileSync)(this.opts.statePath, "utf8"));
|
|
26800
26804
|
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
26801
26805
|
} catch {
|
|
26802
26806
|
return null;
|
|
@@ -26804,7 +26808,7 @@ var AutoUpdate = class {
|
|
|
26804
26808
|
}
|
|
26805
26809
|
recordAttempt(version) {
|
|
26806
26810
|
try {
|
|
26807
|
-
(0,
|
|
26811
|
+
(0, import_node_fs24.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
26808
26812
|
} catch (err) {
|
|
26809
26813
|
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
26810
26814
|
}
|
|
@@ -26813,8 +26817,8 @@ var AutoUpdate = class {
|
|
|
26813
26817
|
|
|
26814
26818
|
// src/daemon/workers/threat-feeds.ts
|
|
26815
26819
|
var import_node_child_process6 = require("child_process");
|
|
26816
|
-
var
|
|
26817
|
-
var
|
|
26820
|
+
var import_node_fs25 = require("fs");
|
|
26821
|
+
var import_node_path20 = require("path");
|
|
26818
26822
|
var import_node_net10 = require("net");
|
|
26819
26823
|
var EGRESS_TABLE = "threatcrush_egress";
|
|
26820
26824
|
var DEFAULT_REFRESH_MS = 36e5;
|
|
@@ -26836,7 +26840,7 @@ function threatFeedSettings(section, env2 = process.env) {
|
|
|
26836
26840
|
function abusechAuthKey(section, env2 = process.env) {
|
|
26837
26841
|
if (section?.auth_key_file) {
|
|
26838
26842
|
try {
|
|
26839
|
-
const key2 = (0,
|
|
26843
|
+
const key2 = (0, import_node_fs25.readFileSync)(section.auth_key_file, "utf-8").trim();
|
|
26840
26844
|
if (key2) return key2;
|
|
26841
26845
|
} catch {
|
|
26842
26846
|
}
|
|
@@ -26999,14 +27003,14 @@ var ThreatFeeds = class {
|
|
|
26999
27003
|
*/
|
|
27000
27004
|
writeResolverFiles(set) {
|
|
27001
27005
|
const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
|
|
27002
|
-
const dir = this.opts.resolverDir ?? (0,
|
|
27006
|
+
const dir = this.opts.resolverDir ?? (0, import_node_path20.dirname)(this.opts.cachePath);
|
|
27003
27007
|
const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
|
|
27004
27008
|
const write = (name, content) => {
|
|
27005
|
-
const path = (0,
|
|
27009
|
+
const path = (0, import_node_path20.join)(dir, name);
|
|
27006
27010
|
if (this.resolverWritten.get(name) === content) return false;
|
|
27007
27011
|
try {
|
|
27008
|
-
(0,
|
|
27009
|
-
(0,
|
|
27012
|
+
(0, import_node_fs25.writeFileSync)(`${path}.tmp`, content);
|
|
27013
|
+
(0, import_node_fs25.renameSync)(`${path}.tmp`, path);
|
|
27010
27014
|
this.resolverWritten.set(name, content);
|
|
27011
27015
|
return true;
|
|
27012
27016
|
} catch (err) {
|
|
@@ -27017,11 +27021,11 @@ var ThreatFeeds = class {
|
|
|
27017
27021
|
const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
|
|
27018
27022
|
const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
|
|
27019
27023
|
const via = [];
|
|
27020
|
-
if ((0,
|
|
27024
|
+
if ((0, import_node_fs25.existsSync)(hooks.dnsmasq)) {
|
|
27021
27025
|
via.push("dnsmasq");
|
|
27022
27026
|
if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
|
|
27023
27027
|
}
|
|
27024
|
-
if ((0,
|
|
27028
|
+
if ((0, import_node_fs25.existsSync)(hooks.unbound)) {
|
|
27025
27029
|
via.push("unbound");
|
|
27026
27030
|
if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
|
|
27027
27031
|
this.run("systemctl", ["reload", "unbound.service"]);
|
|
@@ -27157,8 +27161,8 @@ var ThreatFeeds = class {
|
|
|
27157
27161
|
};
|
|
27158
27162
|
|
|
27159
27163
|
// src/daemon/workers/privilege-watch.ts
|
|
27160
|
-
var
|
|
27161
|
-
var
|
|
27164
|
+
var import_node_fs26 = require("fs");
|
|
27165
|
+
var import_node_path21 = require("path");
|
|
27162
27166
|
var import_node_child_process7 = require("child_process");
|
|
27163
27167
|
|
|
27164
27168
|
// src/core/privileges/index.ts
|
|
@@ -27384,31 +27388,31 @@ function countryName(code) {
|
|
|
27384
27388
|
var fsIO = {
|
|
27385
27389
|
readFile: (p) => {
|
|
27386
27390
|
try {
|
|
27387
|
-
return (0,
|
|
27391
|
+
return (0, import_node_fs26.readFileSync)(p, "utf-8");
|
|
27388
27392
|
} catch {
|
|
27389
27393
|
return null;
|
|
27390
27394
|
}
|
|
27391
27395
|
},
|
|
27392
27396
|
readDir: (p) => {
|
|
27393
27397
|
try {
|
|
27394
|
-
return (0,
|
|
27398
|
+
return (0, import_node_fs26.readdirSync)(p);
|
|
27395
27399
|
} catch {
|
|
27396
27400
|
return null;
|
|
27397
27401
|
}
|
|
27398
27402
|
},
|
|
27399
|
-
exists: (p) => (0,
|
|
27403
|
+
exists: (p) => (0, import_node_fs26.existsSync)(p)
|
|
27400
27404
|
};
|
|
27401
27405
|
function readJson(path) {
|
|
27402
27406
|
try {
|
|
27403
|
-
return JSON.parse((0,
|
|
27407
|
+
return JSON.parse((0, import_node_fs26.readFileSync)(path, "utf-8"));
|
|
27404
27408
|
} catch {
|
|
27405
27409
|
return null;
|
|
27406
27410
|
}
|
|
27407
27411
|
}
|
|
27408
27412
|
function writeJson(path, value) {
|
|
27409
|
-
(0,
|
|
27410
|
-
(0,
|
|
27411
|
-
(0,
|
|
27413
|
+
(0, import_node_fs26.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
|
|
27414
|
+
(0, import_node_fs26.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
|
|
27415
|
+
(0, import_node_fs26.renameSync)(`${path}.tmp`, path);
|
|
27412
27416
|
}
|
|
27413
27417
|
function defaultRun3(cmd, args) {
|
|
27414
27418
|
const res = (0, import_node_child_process7.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -27525,7 +27529,7 @@ var PrivilegeWatch = class {
|
|
|
27525
27529
|
for (const dir of dirs) {
|
|
27526
27530
|
if (this.watchers.has(dir) || !this.io.exists(dir)) continue;
|
|
27527
27531
|
try {
|
|
27528
|
-
const w = (0,
|
|
27532
|
+
const w = (0, import_node_fs26.watch)(dir, { persistent: false }, (_type2, name) => {
|
|
27529
27533
|
if (name && !String(name).startsWith("authorized_keys")) return;
|
|
27530
27534
|
if (this.debounce) clearTimeout(this.debounce);
|
|
27531
27535
|
this.debounce = setTimeout(() => {
|
|
@@ -27624,7 +27628,7 @@ var PrivilegeWatch = class {
|
|
|
27624
27628
|
* raised a "new country" alert on its first run; on dev2 it did, at once.
|
|
27625
27629
|
*/
|
|
27626
27630
|
async backfillLogins() {
|
|
27627
|
-
if ((0,
|
|
27631
|
+
if ((0, import_node_fs26.existsSync)(this.opts.loginsPath)) return;
|
|
27628
27632
|
const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
|
|
27629
27633
|
const byUser = parseAcceptedLogins(out ?? "");
|
|
27630
27634
|
const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
|
|
@@ -27637,7 +27641,7 @@ var PrivilegeWatch = class {
|
|
|
27637
27641
|
return;
|
|
27638
27642
|
}
|
|
27639
27643
|
}
|
|
27640
|
-
if ((0,
|
|
27644
|
+
if ((0, import_node_fs26.existsSync)(this.opts.loginsPath)) return;
|
|
27641
27645
|
const at = this.now().toISOString();
|
|
27642
27646
|
const history = {};
|
|
27643
27647
|
for (const [user, userIps] of byUser) {
|
|
@@ -27689,9 +27693,9 @@ var PrivilegeWatch = class {
|
|
|
27689
27693
|
};
|
|
27690
27694
|
|
|
27691
27695
|
// src/daemon/workers/command-history.ts
|
|
27692
|
-
var
|
|
27696
|
+
var import_node_fs27 = require("fs");
|
|
27693
27697
|
var import_node_child_process8 = require("child_process");
|
|
27694
|
-
var
|
|
27698
|
+
var import_node_path22 = require("path");
|
|
27695
27699
|
var import_node_zlib = require("zlib");
|
|
27696
27700
|
var import_node_crypto7 = require("crypto");
|
|
27697
27701
|
var POLL_MS2 = 6e4;
|
|
@@ -27714,7 +27718,7 @@ function historyAccounts() {
|
|
|
27714
27718
|
passwd = (0, import_node_child_process8.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
27715
27719
|
} catch {
|
|
27716
27720
|
try {
|
|
27717
|
-
passwd = (0,
|
|
27721
|
+
passwd = (0, import_node_fs27.readFileSync)("/etc/passwd", "utf8");
|
|
27718
27722
|
} catch {
|
|
27719
27723
|
return [];
|
|
27720
27724
|
}
|
|
@@ -27727,9 +27731,9 @@ function historyAccounts() {
|
|
|
27727
27731
|
const name = fields[0] ?? "";
|
|
27728
27732
|
const home = fields[5] ?? "";
|
|
27729
27733
|
const shell = fields[6] ?? "";
|
|
27730
|
-
if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0,
|
|
27734
|
+
if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path22.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
|
|
27731
27735
|
if (root ? uid !== 0 && uid < 1e3 : uid !== process.getuid?.()) return [];
|
|
27732
|
-
if (!HISTORY_TARGETS[(0,
|
|
27736
|
+
if (!HISTORY_TARGETS[(0, import_node_path22.basename)(shell)]) return [];
|
|
27733
27737
|
return [{ uid, gid, name, home, shell }];
|
|
27734
27738
|
});
|
|
27735
27739
|
}
|
|
@@ -27737,18 +27741,18 @@ function descriptorPath(directoryFd, name) {
|
|
|
27737
27741
|
return `/proc/self/fd/${directoryFd}/${name}`;
|
|
27738
27742
|
}
|
|
27739
27743
|
function openDirectoryChain(path) {
|
|
27740
|
-
if (!(0,
|
|
27741
|
-
const flags =
|
|
27742
|
-
let fd = (0,
|
|
27744
|
+
if (!(0, import_node_path22.isAbsolute)(path) || path.split(import_node_path22.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
|
|
27745
|
+
const flags = import_node_fs27.constants.O_RDONLY | import_node_fs27.constants.O_DIRECTORY | (import_node_fs27.constants.O_NOFOLLOW ?? 0);
|
|
27746
|
+
let fd = (0, import_node_fs27.openSync)("/", flags);
|
|
27743
27747
|
try {
|
|
27744
|
-
for (const part of path.split(
|
|
27745
|
-
const next = (0,
|
|
27746
|
-
(0,
|
|
27748
|
+
for (const part of path.split(import_node_path22.sep).filter((item) => item && item !== ".")) {
|
|
27749
|
+
const next = (0, import_node_fs27.openSync)(descriptorPath(fd, part), flags);
|
|
27750
|
+
(0, import_node_fs27.closeSync)(fd);
|
|
27747
27751
|
fd = next;
|
|
27748
27752
|
}
|
|
27749
27753
|
return fd;
|
|
27750
27754
|
} catch (error) {
|
|
27751
|
-
(0,
|
|
27755
|
+
(0, import_node_fs27.closeSync)(fd);
|
|
27752
27756
|
throw error;
|
|
27753
27757
|
}
|
|
27754
27758
|
}
|
|
@@ -27756,89 +27760,89 @@ function readExact(fd, size) {
|
|
|
27756
27760
|
const data = Buffer.alloc(size);
|
|
27757
27761
|
let offset = 0;
|
|
27758
27762
|
while (offset < data.length) {
|
|
27759
|
-
const read = (0,
|
|
27763
|
+
const read = (0, import_node_fs27.readSync)(fd, data, offset, data.length - offset, offset);
|
|
27760
27764
|
if (read === 0) break;
|
|
27761
27765
|
offset += read;
|
|
27762
27766
|
}
|
|
27763
27767
|
return offset === data.length ? data : null;
|
|
27764
27768
|
}
|
|
27765
27769
|
function privateDirectory(path) {
|
|
27766
|
-
(0,
|
|
27767
|
-
const stat = (0,
|
|
27770
|
+
(0, import_node_fs27.mkdirSync)(path, { recursive: true, mode: 448 });
|
|
27771
|
+
const stat = (0, import_node_fs27.lstatSync)(path);
|
|
27768
27772
|
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
|
|
27769
|
-
(0,
|
|
27773
|
+
(0, import_node_fs27.chmodSync)(path, 448);
|
|
27770
27774
|
}
|
|
27771
27775
|
function safeReadHistory(directoryFd, name, uid) {
|
|
27772
|
-
const noFollow =
|
|
27773
|
-
const fd = (0,
|
|
27776
|
+
const noFollow = import_node_fs27.constants.O_NOFOLLOW ?? 0;
|
|
27777
|
+
const fd = (0, import_node_fs27.openSync)(descriptorPath(directoryFd, name), import_node_fs27.constants.O_RDONLY | noFollow);
|
|
27774
27778
|
try {
|
|
27775
|
-
const opened = (0,
|
|
27779
|
+
const opened = (0, import_node_fs27.fstatSync)(fd);
|
|
27776
27780
|
if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
|
|
27777
27781
|
if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
|
|
27778
27782
|
const data = readExact(fd, opened.size);
|
|
27779
27783
|
if (data === null) return null;
|
|
27780
|
-
const after = (0,
|
|
27784
|
+
const after = (0, import_node_fs27.fstatSync)(fd);
|
|
27781
27785
|
if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
|
|
27782
27786
|
return data;
|
|
27783
27787
|
} finally {
|
|
27784
|
-
(0,
|
|
27788
|
+
(0, import_node_fs27.closeSync)(fd);
|
|
27785
27789
|
}
|
|
27786
27790
|
}
|
|
27787
27791
|
function atomicWrite(path, data, mode = 384, owner, parentFd) {
|
|
27788
|
-
const dirFd = parentFd ?? openDirectoryChain((0,
|
|
27792
|
+
const dirFd = parentFd ?? openDirectoryChain((0, import_node_path22.dirname)(path));
|
|
27789
27793
|
const ownsDirFd = parentFd === void 0;
|
|
27790
|
-
const name = (0,
|
|
27794
|
+
const name = (0, import_node_path22.basename)(path);
|
|
27791
27795
|
const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto7.randomUUID)()}.tmp`);
|
|
27792
27796
|
const destination = descriptorPath(dirFd, name);
|
|
27793
|
-
const noFollow =
|
|
27797
|
+
const noFollow = import_node_fs27.constants.O_NOFOLLOW ?? 0;
|
|
27794
27798
|
let fd;
|
|
27795
27799
|
try {
|
|
27796
|
-
fd = (0,
|
|
27800
|
+
fd = (0, import_node_fs27.openSync)(temp, import_node_fs27.constants.O_WRONLY | import_node_fs27.constants.O_CREAT | import_node_fs27.constants.O_EXCL | noFollow, mode);
|
|
27797
27801
|
let offset = 0;
|
|
27798
|
-
while (offset < data.length) offset += (0,
|
|
27799
|
-
(0,
|
|
27802
|
+
while (offset < data.length) offset += (0, import_node_fs27.writeSync)(fd, data, offset, data.length - offset);
|
|
27803
|
+
(0, import_node_fs27.fchmodSync)(fd, mode);
|
|
27800
27804
|
if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
|
|
27801
|
-
(0,
|
|
27805
|
+
(0, import_node_fs27.fchownSync)(fd, owner.uid, owner.gid);
|
|
27802
27806
|
}
|
|
27803
|
-
(0,
|
|
27804
|
-
(0,
|
|
27807
|
+
(0, import_node_fs27.fsyncSync)(fd);
|
|
27808
|
+
(0, import_node_fs27.closeSync)(fd);
|
|
27805
27809
|
fd = void 0;
|
|
27806
|
-
(0,
|
|
27810
|
+
(0, import_node_fs27.renameSync)(temp, destination);
|
|
27807
27811
|
} catch (error) {
|
|
27808
27812
|
if (fd !== void 0) {
|
|
27809
27813
|
try {
|
|
27810
|
-
(0,
|
|
27814
|
+
(0, import_node_fs27.closeSync)(fd);
|
|
27811
27815
|
} catch {
|
|
27812
27816
|
}
|
|
27813
27817
|
}
|
|
27814
27818
|
try {
|
|
27815
|
-
(0,
|
|
27819
|
+
(0, import_node_fs27.unlinkSync)(temp);
|
|
27816
27820
|
} catch {
|
|
27817
27821
|
}
|
|
27818
27822
|
throw error;
|
|
27819
27823
|
} finally {
|
|
27820
|
-
if (ownsDirFd) (0,
|
|
27824
|
+
if (ownsDirFd) (0, import_node_fs27.closeSync)(dirFd);
|
|
27821
27825
|
}
|
|
27822
27826
|
}
|
|
27823
27827
|
function readCurrentBackup(path) {
|
|
27824
27828
|
let fd;
|
|
27825
27829
|
try {
|
|
27826
|
-
const parentFd = openDirectoryChain((0,
|
|
27830
|
+
const parentFd = openDirectoryChain((0, import_node_path22.dirname)(path));
|
|
27827
27831
|
try {
|
|
27828
|
-
fd = (0,
|
|
27832
|
+
fd = (0, import_node_fs27.openSync)(descriptorPath(parentFd, (0, import_node_path22.basename)(path)), import_node_fs27.constants.O_RDONLY | (import_node_fs27.constants.O_NOFOLLOW ?? 0));
|
|
27829
27833
|
} finally {
|
|
27830
|
-
(0,
|
|
27834
|
+
(0, import_node_fs27.closeSync)(parentFd);
|
|
27831
27835
|
}
|
|
27832
|
-
const stat = (0,
|
|
27836
|
+
const stat = (0, import_node_fs27.fstatSync)(fd);
|
|
27833
27837
|
if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
|
|
27834
27838
|
const compressed = readExact(fd, stat.size);
|
|
27835
|
-
const after = (0,
|
|
27839
|
+
const after = (0, import_node_fs27.fstatSync)(fd);
|
|
27836
27840
|
if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
|
|
27837
27841
|
return (0, import_node_zlib.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
|
|
27838
27842
|
} catch {
|
|
27839
27843
|
return null;
|
|
27840
27844
|
} finally {
|
|
27841
|
-
if (fd !== void 0) (0,
|
|
27845
|
+
if (fd !== void 0) (0, import_node_fs27.closeSync)(fd);
|
|
27842
27846
|
}
|
|
27843
27847
|
}
|
|
27844
27848
|
function compactTime(date) {
|
|
@@ -27850,7 +27854,7 @@ var CommandHistoryWatcher = class {
|
|
|
27850
27854
|
this.pollMs = Math.max(1e4, opts.pollMs ?? POLL_MS2);
|
|
27851
27855
|
this.now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
27852
27856
|
this.listAccounts = opts.listAccounts ?? historyAccounts;
|
|
27853
|
-
this.root = (0,
|
|
27857
|
+
this.root = (0, import_node_path22.join)(opts.stateDir, "command-history");
|
|
27854
27858
|
}
|
|
27855
27859
|
opts;
|
|
27856
27860
|
timer = null;
|
|
@@ -27891,7 +27895,7 @@ var CommandHistoryWatcher = class {
|
|
|
27891
27895
|
try {
|
|
27892
27896
|
privateDirectory(this.root);
|
|
27893
27897
|
for (const account of this.listAccounts()) {
|
|
27894
|
-
if (!Number.isInteger(account.uid) || account.uid < 0 || !(0,
|
|
27898
|
+
if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path22.isAbsolute)(account.home)) continue;
|
|
27895
27899
|
const targets = this.targetsFor(account);
|
|
27896
27900
|
for (const relative4 of targets) this.scanFile(account, relative4);
|
|
27897
27901
|
}
|
|
@@ -27902,39 +27906,39 @@ var CommandHistoryWatcher = class {
|
|
|
27902
27906
|
}
|
|
27903
27907
|
}
|
|
27904
27908
|
targetsFor(account) {
|
|
27905
|
-
const targets = new Set(HISTORY_TARGETS[(0,
|
|
27909
|
+
const targets = new Set(HISTORY_TARGETS[(0, import_node_path22.basename)(account.shell)] ?? []);
|
|
27906
27910
|
for (const relative4 of Object.values(HISTORY_TARGETS).flat()) {
|
|
27907
27911
|
if (targets.has(relative4)) continue;
|
|
27908
|
-
const path = (0,
|
|
27912
|
+
const path = (0, import_node_path22.join)(account.home, relative4);
|
|
27909
27913
|
try {
|
|
27910
|
-
(0,
|
|
27914
|
+
(0, import_node_fs27.lstatSync)(path);
|
|
27911
27915
|
targets.add(relative4);
|
|
27912
27916
|
continue;
|
|
27913
27917
|
} catch (error) {
|
|
27914
27918
|
if (error.code !== "ENOENT") continue;
|
|
27915
27919
|
}
|
|
27916
|
-
const current = (0,
|
|
27920
|
+
const current = (0, import_node_path22.join)(this.root, String(account.uid), `${(0, import_node_path22.basename)(relative4)}.current.gz`);
|
|
27917
27921
|
if (readCurrentBackup(current) !== null) targets.add(relative4);
|
|
27918
27922
|
}
|
|
27919
27923
|
return [...targets];
|
|
27920
27924
|
}
|
|
27921
27925
|
scanFile(account, relative4) {
|
|
27922
|
-
const path = (0,
|
|
27923
|
-
const store = (0,
|
|
27926
|
+
const path = (0, import_node_path22.join)(account.home, relative4);
|
|
27927
|
+
const store = (0, import_node_path22.join)(this.root, String(account.uid), (0, import_node_path22.basename)(relative4));
|
|
27924
27928
|
const current = `${store}.current.gz`;
|
|
27925
27929
|
let userParentFd;
|
|
27926
27930
|
try {
|
|
27927
|
-
userParentFd = openDirectoryChain((0,
|
|
27931
|
+
userParentFd = openDirectoryChain((0, import_node_path22.dirname)(path));
|
|
27928
27932
|
} catch {
|
|
27929
|
-
this.opts.log(`[command-history] skipped uid=${account.uid} ${(0,
|
|
27933
|
+
this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path22.basename)(relative4)} because its parent path is missing or not a real directory`);
|
|
27930
27934
|
return;
|
|
27931
27935
|
}
|
|
27932
27936
|
try {
|
|
27933
|
-
privateDirectory((0,
|
|
27934
|
-
const userPath = descriptorPath(userParentFd, (0,
|
|
27937
|
+
privateDirectory((0, import_node_path22.dirname)(store));
|
|
27938
|
+
const userPath = descriptorPath(userParentFd, (0, import_node_path22.basename)(path));
|
|
27935
27939
|
let status;
|
|
27936
27940
|
try {
|
|
27937
|
-
status = (0,
|
|
27941
|
+
status = (0, import_node_fs27.lstatSync)(userPath);
|
|
27938
27942
|
} catch (error) {
|
|
27939
27943
|
if (error.code !== "ENOENT") throw error;
|
|
27940
27944
|
}
|
|
@@ -27949,7 +27953,7 @@ var CommandHistoryWatcher = class {
|
|
|
27949
27953
|
} else if (!status) {
|
|
27950
27954
|
this.restore(path, Buffer.alloc(0), account, userParentFd);
|
|
27951
27955
|
}
|
|
27952
|
-
const data = safeReadHistory(userParentFd, (0,
|
|
27956
|
+
const data = safeReadHistory(userParentFd, (0, import_node_path22.basename)(path), account.uid);
|
|
27953
27957
|
if (data === null) return;
|
|
27954
27958
|
const previous = backup;
|
|
27955
27959
|
if (previous?.equals(data)) {
|
|
@@ -27962,9 +27966,9 @@ var CommandHistoryWatcher = class {
|
|
|
27962
27966
|
atomicWrite(current, compressed);
|
|
27963
27967
|
this.pruneSnapshots(store);
|
|
27964
27968
|
} catch (error) {
|
|
27965
|
-
this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0,
|
|
27969
|
+
this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path22.basename)(relative4)}: ${error.message}`);
|
|
27966
27970
|
} finally {
|
|
27967
|
-
(0,
|
|
27971
|
+
(0, import_node_fs27.closeSync)(userParentFd);
|
|
27968
27972
|
}
|
|
27969
27973
|
}
|
|
27970
27974
|
restore(path, content, account, parentFd) {
|
|
@@ -27977,22 +27981,22 @@ var CommandHistoryWatcher = class {
|
|
|
27977
27981
|
module: "command-history",
|
|
27978
27982
|
category: "system",
|
|
27979
27983
|
severity: "medium",
|
|
27980
|
-
message: `Shell history for ${name} (${(0,
|
|
27981
|
-
details: { uid: account.uid, account: name, history_file: (0,
|
|
27984
|
+
message: `Shell history for ${name} (${(0, import_node_path22.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
|
|
27985
|
+
details: { uid: account.uid, account: name, history_file: (0, import_node_path22.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
|
|
27982
27986
|
};
|
|
27983
27987
|
this.opts.bus.publish(event);
|
|
27984
27988
|
this.opts.log(`[command-history] ${event.message}`);
|
|
27985
27989
|
}
|
|
27986
27990
|
pruneSnapshots(current) {
|
|
27987
|
-
const dir = (0,
|
|
27988
|
-
const prefix = `${(0,
|
|
27989
|
-
const snapshots = (0,
|
|
27991
|
+
const dir = (0, import_node_path22.dirname)(current);
|
|
27992
|
+
const prefix = `${(0, import_node_path22.basename)(current).replace(/\.current\.gz$/, "")}.`;
|
|
27993
|
+
const snapshots = (0, import_node_fs27.readdirSync)(dir).filter((name) => name !== (0, import_node_path22.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path22.join)(dir, name), name, time: (0, import_node_fs27.lstatSync)((0, import_node_path22.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
|
|
27990
27994
|
const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
|
|
27991
27995
|
const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
|
|
27992
27996
|
snapshots.forEach((snapshot, index) => {
|
|
27993
27997
|
if (snapshot.time < cutoff || index < removeCount) {
|
|
27994
27998
|
try {
|
|
27995
|
-
(0,
|
|
27999
|
+
(0, import_node_fs27.unlinkSync)(snapshot.path);
|
|
27996
28000
|
} catch {
|
|
27997
28001
|
}
|
|
27998
28002
|
}
|
|
@@ -28001,14 +28005,14 @@ var CommandHistoryWatcher = class {
|
|
|
28001
28005
|
};
|
|
28002
28006
|
|
|
28003
28007
|
// src/daemon/workers/file-integrity.ts
|
|
28004
|
-
var
|
|
28008
|
+
var import_node_fs28 = require("fs");
|
|
28005
28009
|
var import_promises4 = require("fs/promises");
|
|
28006
28010
|
var import_node_crypto8 = require("crypto");
|
|
28007
|
-
var
|
|
28011
|
+
var import_node_path24 = require("path");
|
|
28008
28012
|
|
|
28009
28013
|
// src/daemon/workers/writer-containment.ts
|
|
28010
28014
|
var import_promises3 = require("fs/promises");
|
|
28011
|
-
var
|
|
28015
|
+
var import_node_path23 = require("path");
|
|
28012
28016
|
var realWriterProcFs = {
|
|
28013
28017
|
async pids() {
|
|
28014
28018
|
try {
|
|
@@ -28106,7 +28110,7 @@ var WriterContainment = class {
|
|
|
28106
28110
|
if (info.pid <= 2 || info.ppid === 2) return true;
|
|
28107
28111
|
if (info.pid === this.selfPid || info.pid === this.parentPid) return true;
|
|
28108
28112
|
const path = stripDeleted(exe);
|
|
28109
|
-
const names = [info.comm, (0,
|
|
28113
|
+
const names = [info.comm, (0, import_node_path23.basename)(path)];
|
|
28110
28114
|
if (names.some((name) => name === "sshd" || name.startsWith("sshd-") || name.startsWith("systemd"))) return true;
|
|
28111
28115
|
return this.opts.settings.neverContain.some((entry) => entry.endsWith("/") ? path.startsWith(entry) : path === entry);
|
|
28112
28116
|
}
|
|
@@ -28123,7 +28127,7 @@ var WriterContainment = class {
|
|
|
28123
28127
|
return report;
|
|
28124
28128
|
}
|
|
28125
28129
|
const exact = new Set(files.slice(0, MAX_MATCH_FILES));
|
|
28126
|
-
const directories = [.../* @__PURE__ */ new Set([...files.map((file) => (0,
|
|
28130
|
+
const directories = [.../* @__PURE__ */ new Set([...files.map((file) => (0, import_node_path23.dirname)(file)), ...extraDirectories])].filter((dir) => dir !== "/").slice(0, MAX_MATCH_DIRECTORIES).map((dir) => dir.endsWith("/") ? dir : `${dir}/`);
|
|
28127
28131
|
if (files.length > MAX_MATCH_FILES) report.incomplete = true;
|
|
28128
28132
|
const deadline = this.nowMs() + (this.opts.budgetMs ?? DEFAULT_BUDGET_MS);
|
|
28129
28133
|
const exactHits = /* @__PURE__ */ new Map();
|
|
@@ -28227,7 +28231,7 @@ var WriterContainment = class {
|
|
|
28227
28231
|
}
|
|
28228
28232
|
};
|
|
28229
28233
|
function summarizeContainment(report) {
|
|
28230
|
-
const procs = report.processes.map((p) => `pid ${p.pid} (${(0,
|
|
28234
|
+
const procs = report.processes.map((p) => `pid ${p.pid} (${(0, import_node_path23.basename)(p.exe) || p.comm})`).join(", ");
|
|
28231
28235
|
switch (report.action) {
|
|
28232
28236
|
case "contained":
|
|
28233
28237
|
return `writer ${procs} ${report.mode === "kill" ? "killed (SIGKILL)" : "stopped (SIGSTOP)"}`;
|
|
@@ -28257,8 +28261,8 @@ var READ_CHUNK_BYTES = 64 * 1024;
|
|
|
28257
28261
|
var CANARY_CONTENT = "ThreatCrush file integrity canary v1\n";
|
|
28258
28262
|
function fileIntegritySettings(section) {
|
|
28259
28263
|
const safePath = (value) => {
|
|
28260
|
-
if (typeof value !== "string" || !(0,
|
|
28261
|
-
const path = (0,
|
|
28264
|
+
if (typeof value !== "string" || !(0, import_node_path24.isAbsolute)(value) || value.split(import_node_path24.sep).includes("..")) return null;
|
|
28265
|
+
const path = (0, import_node_path24.normalize)(value);
|
|
28262
28266
|
return path === "/" ? null : path;
|
|
28263
28267
|
};
|
|
28264
28268
|
const strings = (values) => Array.isArray(values) ? [...new Set(values.map(safePath).filter((path) => path !== null))] : [];
|
|
@@ -28288,7 +28292,7 @@ async function readState(path) {
|
|
|
28288
28292
|
}
|
|
28289
28293
|
}
|
|
28290
28294
|
async function writeState(path, state) {
|
|
28291
|
-
await (0, import_promises4.mkdir)((0,
|
|
28295
|
+
await (0, import_promises4.mkdir)((0, import_node_path24.dirname)(path), { recursive: true, mode: 448 });
|
|
28292
28296
|
const temp = `${path}.${process.pid}.${(0, import_node_crypto8.randomUUID)()}.tmp`;
|
|
28293
28297
|
await (0, import_promises4.writeFile)(temp, JSON.stringify(state), { mode: 384 });
|
|
28294
28298
|
await (0, import_promises4.rename)(temp, path);
|
|
@@ -28318,10 +28322,10 @@ var OPEN_FILE_FLAGS = import_promises4.constants.O_RDONLY | import_promises4.con
|
|
|
28318
28322
|
var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises4.constants.O_DIRECTORY;
|
|
28319
28323
|
var CREATE_FILE_FLAGS = import_promises4.constants.O_WRONLY | import_promises4.constants.O_CREAT | import_promises4.constants.O_EXCL | import_promises4.constants.O_NOFOLLOW;
|
|
28320
28324
|
function autoCanaryPath(directory) {
|
|
28321
|
-
return (0,
|
|
28325
|
+
return (0, import_node_path24.join)(directory, ".threatcrush-canary");
|
|
28322
28326
|
}
|
|
28323
28327
|
async function openAbsoluteDirectory(path) {
|
|
28324
|
-
const parts = path.split(
|
|
28328
|
+
const parts = path.split(import_node_path24.sep).filter((part) => part && part !== ".");
|
|
28325
28329
|
if (parts.includes("..")) throw new Error("invalid canary directory");
|
|
28326
28330
|
let directory = await (0, import_promises4.open)("/", OPEN_DIR_FLAGS);
|
|
28327
28331
|
try {
|
|
@@ -28344,9 +28348,9 @@ async function createAutoCanary(path) {
|
|
|
28344
28348
|
} catch (error) {
|
|
28345
28349
|
if (error.code !== "ENOENT") return false;
|
|
28346
28350
|
}
|
|
28347
|
-
const directory = await openAbsoluteDirectory((0,
|
|
28351
|
+
const directory = await openAbsoluteDirectory((0, import_node_path24.dirname)(path));
|
|
28348
28352
|
try {
|
|
28349
|
-
const file = await (0, import_promises4.open)(`/proc/self/fd/${directory.fd}/${(0,
|
|
28353
|
+
const file = await (0, import_promises4.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path24.basename)(path)}`, CREATE_FILE_FLAGS, 438);
|
|
28350
28354
|
try {
|
|
28351
28355
|
await file.chmod(438);
|
|
28352
28356
|
await file.writeFile(CANARY_CONTENT);
|
|
@@ -28363,7 +28367,7 @@ async function createAutoCanary(path) {
|
|
|
28363
28367
|
}
|
|
28364
28368
|
}
|
|
28365
28369
|
async function openAbsoluteTarget(path) {
|
|
28366
|
-
const parts = path.split(
|
|
28370
|
+
const parts = path.split(import_node_path24.sep).filter((part) => part && part !== ".");
|
|
28367
28371
|
if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
|
|
28368
28372
|
let directory = await (0, import_promises4.open)("/", OPEN_DIR_FLAGS);
|
|
28369
28373
|
try {
|
|
@@ -28398,7 +28402,7 @@ async function scanTargets(targets, canaries) {
|
|
|
28398
28402
|
}
|
|
28399
28403
|
let handle;
|
|
28400
28404
|
try {
|
|
28401
|
-
handle = parent ? await (0, import_promises4.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(
|
|
28405
|
+
handle = parent ? await (0, import_promises4.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(import_node_path24.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path);
|
|
28402
28406
|
const stat = await handle.stat();
|
|
28403
28407
|
if (stat.isDirectory()) {
|
|
28404
28408
|
directories.push(path);
|
|
@@ -28416,7 +28420,7 @@ async function scanTargets(targets, canaries) {
|
|
|
28416
28420
|
return;
|
|
28417
28421
|
}
|
|
28418
28422
|
for (const entry of entries2) {
|
|
28419
|
-
await walk((0,
|
|
28423
|
+
await walk((0, import_node_path24.join)(path, entry.name), handle);
|
|
28420
28424
|
if (!complete) return;
|
|
28421
28425
|
}
|
|
28422
28426
|
return;
|
|
@@ -28564,7 +28568,7 @@ var FileIntegrityWatch = class {
|
|
|
28564
28568
|
for (const path of wanted) {
|
|
28565
28569
|
if (this.watchers.has(path)) continue;
|
|
28566
28570
|
try {
|
|
28567
|
-
const watcher = (0,
|
|
28571
|
+
const watcher = (0, import_node_fs28.watch)(path, { persistent: false }, () => {
|
|
28568
28572
|
this.scheduleEventScan();
|
|
28569
28573
|
});
|
|
28570
28574
|
watcher.on("error", (error) => {
|
|
@@ -28636,7 +28640,7 @@ var FileIntegrityWatch = class {
|
|
|
28636
28640
|
if (current.complete) {
|
|
28637
28641
|
const directories = new Set(current.directories);
|
|
28638
28642
|
for (const path of Object.keys(current.files)) {
|
|
28639
|
-
if (!directories.has(path)) directories.add((0,
|
|
28643
|
+
if (!directories.has(path)) directories.add((0, import_node_path24.dirname)(path));
|
|
28640
28644
|
}
|
|
28641
28645
|
this.refreshWatchers([...directories]);
|
|
28642
28646
|
}
|
|
@@ -28761,15 +28765,15 @@ var FileIntegrityWatch = class {
|
|
|
28761
28765
|
};
|
|
28762
28766
|
|
|
28763
28767
|
// src/daemon/workers/edr.ts
|
|
28764
|
-
var
|
|
28765
|
-
var
|
|
28768
|
+
var import_node_fs30 = require("fs");
|
|
28769
|
+
var import_node_path26 = require("path");
|
|
28766
28770
|
var import_node_child_process10 = require("child_process");
|
|
28767
28771
|
|
|
28768
28772
|
// src/daemon/workers/edr-ebpf.ts
|
|
28769
28773
|
var import_node_child_process9 = require("child_process");
|
|
28770
|
-
var
|
|
28774
|
+
var import_node_fs29 = require("fs");
|
|
28771
28775
|
var import_node_net11 = require("net");
|
|
28772
|
-
var
|
|
28776
|
+
var import_node_path25 = require("path");
|
|
28773
28777
|
var BPFTRACE_RECORD_TAG = "TC1";
|
|
28774
28778
|
var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
|
|
28775
28779
|
var TCP_SYN_SENT = 2;
|
|
@@ -28910,11 +28914,11 @@ function selectEdrSource(probe) {
|
|
|
28910
28914
|
}
|
|
28911
28915
|
var BPFTRACE_DIRS = ["/usr/sbin", "/usr/bin", "/sbin", "/bin", "/usr/local/sbin", "/usr/local/bin", "/snap/bin"];
|
|
28912
28916
|
function findBpftrace(env2 = process.env) {
|
|
28913
|
-
const dirs = [...BPFTRACE_DIRS, ...(env2.PATH ?? "").split(
|
|
28917
|
+
const dirs = [...BPFTRACE_DIRS, ...(env2.PATH ?? "").split(import_node_path25.delimiter).filter((dir) => dir.startsWith("/"))];
|
|
28914
28918
|
for (const dir of new Set(dirs)) {
|
|
28915
|
-
const candidate = (0,
|
|
28919
|
+
const candidate = (0, import_node_path25.join)(dir, "bpftrace");
|
|
28916
28920
|
try {
|
|
28917
|
-
(0,
|
|
28921
|
+
(0, import_node_fs29.accessSync)(candidate, import_node_fs29.constants.X_OK);
|
|
28918
28922
|
return candidate;
|
|
28919
28923
|
} catch {
|
|
28920
28924
|
}
|
|
@@ -28925,7 +28929,7 @@ function probeHost(configured) {
|
|
|
28925
28929
|
return {
|
|
28926
28930
|
configured,
|
|
28927
28931
|
bpftracePath: configured === "auditd" ? null : findBpftrace(),
|
|
28928
|
-
btfPresent: (0,
|
|
28932
|
+
btfPresent: (0, import_node_fs29.existsSync)(BTF_VMLINUX_PATH),
|
|
28929
28933
|
isRoot: typeof process.getuid === "function" && process.getuid() === 0,
|
|
28930
28934
|
platform: process.platform
|
|
28931
28935
|
};
|
|
@@ -29111,8 +29115,8 @@ var SHELLS2 = /* @__PURE__ */ new Set(["sh", "bash", "dash", "zsh", "ksh", "fish
|
|
|
29111
29115
|
var DOWNLOADERS = /* @__PURE__ */ new Set(["curl", "wget"]);
|
|
29112
29116
|
var MINERS = /* @__PURE__ */ new Set(["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"]);
|
|
29113
29117
|
function safeAbsolutePath(value) {
|
|
29114
|
-
if (typeof value !== "string" || !(0,
|
|
29115
|
-
const path = (0,
|
|
29118
|
+
if (typeof value !== "string" || !(0, import_node_path26.isAbsolute)(value) || value.split(import_node_path26.sep).includes("..")) return null;
|
|
29119
|
+
const path = (0, import_node_path26.normalize)(value);
|
|
29116
29120
|
return path === "/" ? null : path;
|
|
29117
29121
|
}
|
|
29118
29122
|
function edrSettings(section) {
|
|
@@ -29161,7 +29165,7 @@ function parseAuditRecord(line) {
|
|
|
29161
29165
|
serial: header[2],
|
|
29162
29166
|
key: fields.key,
|
|
29163
29167
|
executable,
|
|
29164
|
-
comm: fields.comm ?? (0,
|
|
29168
|
+
comm: fields.comm ?? (0, import_node_path26.basename)(executable),
|
|
29165
29169
|
euid,
|
|
29166
29170
|
...Number.isInteger(pid) && pid > 0 ? { pid } : {},
|
|
29167
29171
|
...Number.isInteger(ppid) && ppid > 0 ? { ppid } : {}
|
|
@@ -29173,7 +29177,7 @@ function accountNames2() {
|
|
|
29173
29177
|
raw = (0, import_node_child_process10.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
29174
29178
|
} catch {
|
|
29175
29179
|
try {
|
|
29176
|
-
raw = (0,
|
|
29180
|
+
raw = (0, import_node_fs30.readFileSync)("/etc/passwd", "utf8");
|
|
29177
29181
|
} catch {
|
|
29178
29182
|
return /* @__PURE__ */ new Map();
|
|
29179
29183
|
}
|
|
@@ -29191,7 +29195,7 @@ function pathWithin(path, root) {
|
|
|
29191
29195
|
}
|
|
29192
29196
|
function executableInWorldWritableDirectory(executable) {
|
|
29193
29197
|
try {
|
|
29194
|
-
return ((0,
|
|
29198
|
+
return ((0, import_node_fs30.statSync)((0, import_node_path26.dirname)(executable)).mode & 2) !== 0;
|
|
29195
29199
|
} catch {
|
|
29196
29200
|
return false;
|
|
29197
29201
|
}
|
|
@@ -29210,7 +29214,7 @@ function ebpfEventToRecords(event, resolveExe, now = /* @__PURE__ */ new Date(),
|
|
|
29210
29214
|
source: "ebpf",
|
|
29211
29215
|
serial,
|
|
29212
29216
|
executable,
|
|
29213
|
-
comm: event.comm || (0,
|
|
29217
|
+
comm: event.comm || (0, import_node_path26.basename)(executable),
|
|
29214
29218
|
euid: event.euid,
|
|
29215
29219
|
pid: event.pid,
|
|
29216
29220
|
...event.ppid > 0 ? { ppid: event.ppid } : {}
|
|
@@ -29298,13 +29302,13 @@ var EdrWatch = class {
|
|
|
29298
29302
|
this.bpftrace.start();
|
|
29299
29303
|
}
|
|
29300
29304
|
startAuditd(reason) {
|
|
29301
|
-
if (!(0,
|
|
29305
|
+
if (!(0, import_node_fs30.existsSync)(this.opts.settings.auditLogPath)) {
|
|
29302
29306
|
this.opts.log(`[edr] audit log not found at ${this.opts.settings.auditLogPath}; auditd detections are unavailable`);
|
|
29303
29307
|
this.setSource("none", `${reason}; audit log not found at ${this.opts.settings.auditLogPath}`);
|
|
29304
29308
|
return;
|
|
29305
29309
|
}
|
|
29306
29310
|
try {
|
|
29307
|
-
(0,
|
|
29311
|
+
(0, import_node_fs30.accessSync)(this.opts.settings.auditLogPath, import_node_fs30.constants.R_OK);
|
|
29308
29312
|
this.tail = new LogTail(this.opts.settings.auditLogPath);
|
|
29309
29313
|
this.timer = setInterval(() => this.poll(), this.opts.settings.pollMs);
|
|
29310
29314
|
this.timer.unref?.();
|
|
@@ -29328,16 +29332,16 @@ var EdrWatch = class {
|
|
|
29328
29332
|
};
|
|
29329
29333
|
try {
|
|
29330
29334
|
const temp = `${path}.${process.pid}.tmp`;
|
|
29331
|
-
(0,
|
|
29335
|
+
(0, import_node_fs30.writeFileSync)(temp, `${JSON.stringify(status)}
|
|
29332
29336
|
`, { mode: 420 });
|
|
29333
|
-
(0,
|
|
29337
|
+
(0, import_node_fs30.renameSync)(temp, path);
|
|
29334
29338
|
} catch {
|
|
29335
29339
|
}
|
|
29336
29340
|
}
|
|
29337
29341
|
resolveEbpfExe(event) {
|
|
29338
29342
|
let exe = null;
|
|
29339
29343
|
try {
|
|
29340
|
-
exe = (0,
|
|
29344
|
+
exe = (0, import_node_fs30.readlinkSync)(`/proc/${event.pid}/exe`).replace(/ \(deleted\)$/, "");
|
|
29341
29345
|
} catch {
|
|
29342
29346
|
}
|
|
29343
29347
|
if (!exe && event.kind !== "exec") exe = this.ebpfExeCache.get(event.pid) ?? null;
|
|
@@ -29416,7 +29420,7 @@ var EdrWatch = class {
|
|
|
29416
29420
|
this.opts.bus.publish(event);
|
|
29417
29421
|
}
|
|
29418
29422
|
classify(execution) {
|
|
29419
|
-
const name = (0,
|
|
29423
|
+
const name = (0, import_node_path26.basename)(execution.executable).toLowerCase();
|
|
29420
29424
|
const account = this.usersById.get(execution.euid) ?? String(execution.euid);
|
|
29421
29425
|
let severity;
|
|
29422
29426
|
let ruleId;
|
|
@@ -29480,7 +29484,7 @@ var EdrWatch = class {
|
|
|
29480
29484
|
const path = this.opts.networkBaselinePath;
|
|
29481
29485
|
if (!path) return;
|
|
29482
29486
|
try {
|
|
29483
|
-
const parsed = JSON.parse((0,
|
|
29487
|
+
const parsed = JSON.parse((0, import_node_fs30.readFileSync)(path, "utf8"));
|
|
29484
29488
|
if (Array.isArray(parsed)) {
|
|
29485
29489
|
for (const value of parsed.slice(0, 1e4)) {
|
|
29486
29490
|
if (typeof value === "string" && value.startsWith("/")) this.outboundExecutables.add(value);
|
|
@@ -29497,9 +29501,9 @@ var EdrWatch = class {
|
|
|
29497
29501
|
if (!path) return;
|
|
29498
29502
|
try {
|
|
29499
29503
|
const temp = `${path}.${process.pid}.tmp`;
|
|
29500
|
-
(0,
|
|
29504
|
+
(0, import_node_fs30.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
|
|
29501
29505
|
`, { mode: 384 });
|
|
29502
|
-
(0,
|
|
29506
|
+
(0, import_node_fs30.renameSync)(temp, path);
|
|
29503
29507
|
this.baselineWriteFailed = false;
|
|
29504
29508
|
} catch (error) {
|
|
29505
29509
|
if (!this.baselineWriteFailed) this.opts.log(`[edr] could not persist outbound executable baseline: ${error.message.split("\n")[0]}`);
|
|
@@ -29520,7 +29524,7 @@ var EdrWatch = class {
|
|
|
29520
29524
|
const current = /* @__PURE__ */ new Map();
|
|
29521
29525
|
let pids;
|
|
29522
29526
|
try {
|
|
29523
|
-
pids = (0,
|
|
29527
|
+
pids = (0, import_node_fs30.readdirSync)("/proc");
|
|
29524
29528
|
} catch {
|
|
29525
29529
|
return;
|
|
29526
29530
|
}
|
|
@@ -29528,7 +29532,7 @@ var EdrWatch = class {
|
|
|
29528
29532
|
if (!/^\d+$/.test(pid)) continue;
|
|
29529
29533
|
const proc = `/proc/${pid}`;
|
|
29530
29534
|
try {
|
|
29531
|
-
const raw = (0,
|
|
29535
|
+
const raw = (0, import_node_fs30.readFileSync)(`${proc}/stat`, "utf8");
|
|
29532
29536
|
const end = raw.lastIndexOf(")");
|
|
29533
29537
|
if (end < 0) continue;
|
|
29534
29538
|
const fields = raw.slice(end + 1).trim().split(/\s+/);
|
|
@@ -29536,10 +29540,10 @@ var EdrWatch = class {
|
|
|
29536
29540
|
const systemTicks = Number(fields[12]);
|
|
29537
29541
|
const startTicks = fields[19];
|
|
29538
29542
|
if (!Number.isFinite(userTicks) || !Number.isFinite(systemTicks) || !startTicks) continue;
|
|
29539
|
-
let executable = (0,
|
|
29543
|
+
let executable = (0, import_node_fs30.readlinkSync)(`${proc}/exe`);
|
|
29540
29544
|
executable = executable.replace(/ \(deleted\)$/, "");
|
|
29541
29545
|
if (!this.opts.settings.tempExecPaths.some((path) => pathWithin(executable, path))) continue;
|
|
29542
|
-
const name = (0,
|
|
29546
|
+
const name = (0, import_node_path26.basename)(executable).toLowerCase();
|
|
29543
29547
|
if (MINERS.has(name)) continue;
|
|
29544
29548
|
const key = `${pid}:${startTicks}`;
|
|
29545
29549
|
const ticks = userTicks + systemTicks;
|
|
@@ -29575,8 +29579,8 @@ var EdrWatch = class {
|
|
|
29575
29579
|
};
|
|
29576
29580
|
|
|
29577
29581
|
// src/daemon/workers/ssh-intrusion.ts
|
|
29578
|
-
var
|
|
29579
|
-
var
|
|
29582
|
+
var import_node_fs31 = require("fs");
|
|
29583
|
+
var import_node_path27 = require("path");
|
|
29580
29584
|
var import_node_child_process11 = require("child_process");
|
|
29581
29585
|
|
|
29582
29586
|
// src/core/asn.ts
|
|
@@ -29770,32 +29774,32 @@ function parseKeyLoginsByFingerprint(text) {
|
|
|
29770
29774
|
}
|
|
29771
29775
|
function readJson2(path) {
|
|
29772
29776
|
try {
|
|
29773
|
-
return JSON.parse((0,
|
|
29777
|
+
return JSON.parse((0, import_node_fs31.readFileSync)(path, "utf-8"));
|
|
29774
29778
|
} catch {
|
|
29775
29779
|
return null;
|
|
29776
29780
|
}
|
|
29777
29781
|
}
|
|
29778
29782
|
function writeJson2(path, value) {
|
|
29779
|
-
(0,
|
|
29780
|
-
(0,
|
|
29781
|
-
(0,
|
|
29783
|
+
(0, import_node_fs31.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
|
|
29784
|
+
(0, import_node_fs31.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
|
|
29785
|
+
(0, import_node_fs31.renameSync)(`${path}.tmp`, path);
|
|
29782
29786
|
}
|
|
29783
29787
|
var fsIO2 = {
|
|
29784
29788
|
readFile: (p) => {
|
|
29785
29789
|
try {
|
|
29786
|
-
return (0,
|
|
29790
|
+
return (0, import_node_fs31.readFileSync)(p, "utf-8");
|
|
29787
29791
|
} catch {
|
|
29788
29792
|
return null;
|
|
29789
29793
|
}
|
|
29790
29794
|
},
|
|
29791
29795
|
readDir: (p) => {
|
|
29792
29796
|
try {
|
|
29793
|
-
return (0,
|
|
29797
|
+
return (0, import_node_fs31.readdirSync)(p);
|
|
29794
29798
|
} catch {
|
|
29795
29799
|
return null;
|
|
29796
29800
|
}
|
|
29797
29801
|
},
|
|
29798
|
-
exists: (p) => (0,
|
|
29802
|
+
exists: (p) => (0, import_node_fs31.existsSync)(p)
|
|
29799
29803
|
};
|
|
29800
29804
|
function defaultRun4(cmd, args) {
|
|
29801
29805
|
const res = (0, import_node_child_process11.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 6e4, maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -29996,23 +30000,23 @@ var SshIntrusionWatch = class {
|
|
|
29996
30000
|
};
|
|
29997
30001
|
|
|
29998
30002
|
// src/daemon/key-directory.ts
|
|
29999
|
-
var
|
|
30003
|
+
var import_node_fs32 = require("fs");
|
|
30000
30004
|
var fsIO3 = {
|
|
30001
30005
|
readFile: (p) => {
|
|
30002
30006
|
try {
|
|
30003
|
-
return (0,
|
|
30007
|
+
return (0, import_node_fs32.readFileSync)(p, "utf-8");
|
|
30004
30008
|
} catch {
|
|
30005
30009
|
return null;
|
|
30006
30010
|
}
|
|
30007
30011
|
},
|
|
30008
30012
|
readDir: (p) => {
|
|
30009
30013
|
try {
|
|
30010
|
-
return (0,
|
|
30014
|
+
return (0, import_node_fs32.readdirSync)(p);
|
|
30011
30015
|
} catch {
|
|
30012
30016
|
return null;
|
|
30013
30017
|
}
|
|
30014
30018
|
},
|
|
30015
|
-
exists: (p) => (0,
|
|
30019
|
+
exists: (p) => (0, import_node_fs32.existsSync)(p)
|
|
30016
30020
|
};
|
|
30017
30021
|
var KeyDirectory = class {
|
|
30018
30022
|
constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
|
|
@@ -30056,7 +30060,7 @@ function enrichLoginEvent(event, keys) {
|
|
|
30056
30060
|
}
|
|
30057
30061
|
|
|
30058
30062
|
// src/daemon/workers/lightning-watch.ts
|
|
30059
|
-
var
|
|
30063
|
+
var import_node_fs33 = require("fs");
|
|
30060
30064
|
var DEFAULT_CLN_LOGS = [
|
|
30061
30065
|
"/home/lightning/.lightning/cln.log",
|
|
30062
30066
|
"/root/.lightning/cln.log",
|
|
@@ -30112,9 +30116,9 @@ var LightningWatch = class {
|
|
|
30112
30116
|
if (this.opts.enabled === false) return [];
|
|
30113
30117
|
const found = [];
|
|
30114
30118
|
for (const path of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
|
|
30115
|
-
if (!(0,
|
|
30119
|
+
if (!(0, import_node_fs33.existsSync)(path)) continue;
|
|
30116
30120
|
try {
|
|
30117
|
-
(0,
|
|
30121
|
+
(0, import_node_fs33.accessSync)(path, import_node_fs33.constants.R_OK);
|
|
30118
30122
|
} catch {
|
|
30119
30123
|
continue;
|
|
30120
30124
|
}
|
|
@@ -30149,12 +30153,12 @@ var LightningWatch = class {
|
|
|
30149
30153
|
};
|
|
30150
30154
|
|
|
30151
30155
|
// src/daemon/workers/docker-logs.ts
|
|
30152
|
-
var
|
|
30156
|
+
var import_node_fs35 = require("fs");
|
|
30153
30157
|
var import_node_http = require("http");
|
|
30154
30158
|
var import_node_net13 = require("net");
|
|
30155
30159
|
|
|
30156
30160
|
// src/daemon/workers/postgres-shell.ts
|
|
30157
|
-
var
|
|
30161
|
+
var import_node_fs34 = require("fs");
|
|
30158
30162
|
var DEFAULT_ALLOW_CMDLINE = [
|
|
30159
30163
|
// Supabase's pgsodium reads its root key by running this script at startup.
|
|
30160
30164
|
String.raw`^(?:\S*/)?(?:ba|da)?sh (?:-c )?(?:\S*/)?pgsodium_getkey(?:\.sh)?$`,
|
|
@@ -30298,28 +30302,28 @@ function shellLogDetector(cooldownMs = 6e4, now = Date.now) {
|
|
|
30298
30302
|
var realProcFs = {
|
|
30299
30303
|
pids: () => {
|
|
30300
30304
|
try {
|
|
30301
|
-
return (0,
|
|
30305
|
+
return (0, import_node_fs34.readdirSync)("/proc").filter((n) => /^\d+$/.test(n)).map(Number);
|
|
30302
30306
|
} catch {
|
|
30303
30307
|
return [];
|
|
30304
30308
|
}
|
|
30305
30309
|
},
|
|
30306
30310
|
stat: (pid) => {
|
|
30307
30311
|
try {
|
|
30308
|
-
return (0,
|
|
30312
|
+
return (0, import_node_fs34.readFileSync)(`/proc/${pid}/stat`, "utf-8");
|
|
30309
30313
|
} catch {
|
|
30310
30314
|
return null;
|
|
30311
30315
|
}
|
|
30312
30316
|
},
|
|
30313
30317
|
cmdline: (pid) => {
|
|
30314
30318
|
try {
|
|
30315
|
-
return (0,
|
|
30319
|
+
return (0, import_node_fs34.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
|
|
30316
30320
|
} catch {
|
|
30317
30321
|
return null;
|
|
30318
30322
|
}
|
|
30319
30323
|
},
|
|
30320
30324
|
cgroup: (pid) => {
|
|
30321
30325
|
try {
|
|
30322
|
-
return (0,
|
|
30326
|
+
return (0, import_node_fs34.readFileSync)(`/proc/${pid}/cgroup`, "utf-8");
|
|
30323
30327
|
} catch {
|
|
30324
30328
|
return null;
|
|
30325
30329
|
}
|
|
@@ -30678,7 +30682,7 @@ var DockerLogsWatch = class {
|
|
|
30678
30682
|
start() {
|
|
30679
30683
|
const { settings } = this.opts;
|
|
30680
30684
|
if (!settings.enabled) return false;
|
|
30681
|
-
if (!this.opts.deps && !(0,
|
|
30685
|
+
if (!this.opts.deps && !(0, import_node_fs35.existsSync)(settings.socket)) return false;
|
|
30682
30686
|
this.opts.log(`[docker-logs] following containers named /${settings.namePattern.source}/ or with image /${settings.imagePattern.source}/ for Postgres auth failures`);
|
|
30683
30687
|
void this.poll();
|
|
30684
30688
|
this.timer = setInterval(() => {
|
|
@@ -30784,7 +30788,7 @@ var DockerLogsWatch = class {
|
|
|
30784
30788
|
};
|
|
30785
30789
|
|
|
30786
30790
|
// src/daemon/workers/login-watch.ts
|
|
30787
|
-
var
|
|
30791
|
+
var import_node_fs36 = require("fs");
|
|
30788
30792
|
var import_node_child_process12 = require("child_process");
|
|
30789
30793
|
var import_node_net14 = require("net");
|
|
30790
30794
|
var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
|
|
@@ -30900,7 +30904,7 @@ var realKillDeps = {
|
|
|
30900
30904
|
},
|
|
30901
30905
|
cmdline: (pid) => {
|
|
30902
30906
|
try {
|
|
30903
|
-
return (0,
|
|
30907
|
+
return (0, import_node_fs36.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
|
|
30904
30908
|
} catch {
|
|
30905
30909
|
return null;
|
|
30906
30910
|
}
|
|
@@ -30958,14 +30962,14 @@ function forcedCommandKeys(text) {
|
|
|
30958
30962
|
var realKeyFileIO = {
|
|
30959
30963
|
mtime: (p) => {
|
|
30960
30964
|
try {
|
|
30961
|
-
return (0,
|
|
30965
|
+
return (0, import_node_fs36.statSync)(p).mtimeMs;
|
|
30962
30966
|
} catch {
|
|
30963
30967
|
return null;
|
|
30964
30968
|
}
|
|
30965
30969
|
},
|
|
30966
30970
|
read: (p) => {
|
|
30967
30971
|
try {
|
|
30968
|
-
return (0,
|
|
30972
|
+
return (0, import_node_fs36.readFileSync)(p, "utf-8");
|
|
30969
30973
|
} catch {
|
|
30970
30974
|
return null;
|
|
30971
30975
|
}
|
|
@@ -31019,8 +31023,8 @@ var LoginWatch = class {
|
|
|
31019
31023
|
const users = new Set(this.opts.settings.sensitiveUsers);
|
|
31020
31024
|
try {
|
|
31021
31025
|
const { group, passwd } = this.opts.readAccounts?.() ?? {
|
|
31022
|
-
group: (0,
|
|
31023
|
-
passwd: (0,
|
|
31026
|
+
group: (0, import_node_fs36.readFileSync)("/etc/group", "utf-8"),
|
|
31027
|
+
passwd: (0, import_node_fs36.readFileSync)("/etc/passwd", "utf-8")
|
|
31024
31028
|
};
|
|
31025
31029
|
for (const u of groupMembers(group, passwd, this.opts.settings.sensitiveGroups)) users.add(u);
|
|
31026
31030
|
} catch {
|
|
@@ -31056,7 +31060,7 @@ var LoginWatch = class {
|
|
|
31056
31060
|
}
|
|
31057
31061
|
passwdText() {
|
|
31058
31062
|
try {
|
|
31059
|
-
return this.opts.readAccounts ? this.opts.readAccounts().passwd : (0,
|
|
31063
|
+
return this.opts.readAccounts ? this.opts.readAccounts().passwd : (0, import_node_fs36.readFileSync)("/etc/passwd", "utf-8");
|
|
31060
31064
|
} catch {
|
|
31061
31065
|
return "";
|
|
31062
31066
|
}
|
|
@@ -31182,8 +31186,8 @@ var LoginWatch = class {
|
|
|
31182
31186
|
};
|
|
31183
31187
|
|
|
31184
31188
|
// src/core/tor-exits.ts
|
|
31185
|
-
var
|
|
31186
|
-
var
|
|
31189
|
+
var import_node_fs37 = require("fs");
|
|
31190
|
+
var import_node_path28 = require("path");
|
|
31187
31191
|
var import_node_net15 = require("net");
|
|
31188
31192
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
31189
31193
|
function parseTorExitList(text) {
|
|
@@ -31255,10 +31259,10 @@ var TorExitList = class _TorExitList {
|
|
|
31255
31259
|
}
|
|
31256
31260
|
loadCache() {
|
|
31257
31261
|
try {
|
|
31258
|
-
if (!(0,
|
|
31259
|
-
const parsed = parseTorExitList((0,
|
|
31262
|
+
if (!(0, import_node_fs37.existsSync)(this.opts.cachePath)) return false;
|
|
31263
|
+
const parsed = parseTorExitList((0, import_node_fs37.readFileSync)(this.opts.cachePath, "utf-8"));
|
|
31260
31264
|
if (parsed.size === 0) return false;
|
|
31261
|
-
this.load(parsed, (0,
|
|
31265
|
+
this.load(parsed, (0, import_node_fs37.statSync)(this.opts.cachePath).mtimeMs);
|
|
31262
31266
|
this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
|
|
31263
31267
|
return true;
|
|
31264
31268
|
} catch (err) {
|
|
@@ -31290,9 +31294,9 @@ var TorExitList = class _TorExitList {
|
|
|
31290
31294
|
const before = this.exits.size;
|
|
31291
31295
|
this.load(parsed);
|
|
31292
31296
|
try {
|
|
31293
|
-
(0,
|
|
31294
|
-
(0,
|
|
31295
|
-
(0,
|
|
31297
|
+
(0, import_node_fs37.mkdirSync)((0, import_node_path28.dirname)(this.opts.cachePath), { recursive: true });
|
|
31298
|
+
(0, import_node_fs37.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
|
|
31299
|
+
(0, import_node_fs37.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
|
|
31296
31300
|
} catch (err) {
|
|
31297
31301
|
this.log(`[tor] could not save the exit list cache: ${err.message}`);
|
|
31298
31302
|
}
|
|
@@ -31606,7 +31610,7 @@ var RuleEngine = class {
|
|
|
31606
31610
|
|
|
31607
31611
|
// src/daemon/ssh-context/index.ts
|
|
31608
31612
|
var import_node_os7 = require("os");
|
|
31609
|
-
var
|
|
31613
|
+
var import_node_path29 = require("path");
|
|
31610
31614
|
|
|
31611
31615
|
// ../../packages/event-detail/src/verdict.ts
|
|
31612
31616
|
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
@@ -31802,7 +31806,7 @@ var SshAuthHistory = class {
|
|
|
31802
31806
|
};
|
|
31803
31807
|
|
|
31804
31808
|
// src/daemon/ssh-context/authorized-keys.ts
|
|
31805
|
-
var
|
|
31809
|
+
var import_node_fs38 = require("fs");
|
|
31806
31810
|
|
|
31807
31811
|
// src/core/host-scan/parsers.ts
|
|
31808
31812
|
var import_node_crypto9 = require("crypto");
|
|
@@ -31911,21 +31915,21 @@ function parsePasswd(text) {
|
|
|
31911
31915
|
var realKeyFilesIO = {
|
|
31912
31916
|
passwd: () => {
|
|
31913
31917
|
try {
|
|
31914
|
-
return (0,
|
|
31918
|
+
return (0, import_node_fs38.readFileSync)("/etc/passwd", "utf-8");
|
|
31915
31919
|
} catch {
|
|
31916
31920
|
return "";
|
|
31917
31921
|
}
|
|
31918
31922
|
},
|
|
31919
31923
|
mtime: (p) => {
|
|
31920
31924
|
try {
|
|
31921
|
-
return (0,
|
|
31925
|
+
return (0, import_node_fs38.statSync)(p).mtimeMs;
|
|
31922
31926
|
} catch {
|
|
31923
31927
|
return null;
|
|
31924
31928
|
}
|
|
31925
31929
|
},
|
|
31926
31930
|
read: (p) => {
|
|
31927
31931
|
try {
|
|
31928
|
-
return (0,
|
|
31932
|
+
return (0, import_node_fs38.readFileSync)(p, "utf-8");
|
|
31929
31933
|
} catch {
|
|
31930
31934
|
return null;
|
|
31931
31935
|
}
|
|
@@ -32000,7 +32004,7 @@ var AuthorizedKeysIndex = class {
|
|
|
32000
32004
|
var import_node_net17 = require("net");
|
|
32001
32005
|
var import_node_os6 = require("os");
|
|
32002
32006
|
var import_node_dns2 = require("dns");
|
|
32003
|
-
var
|
|
32007
|
+
var import_node_fs39 = require("fs");
|
|
32004
32008
|
function list(entries2) {
|
|
32005
32009
|
const b = new import_node_net17.BlockList();
|
|
32006
32010
|
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
@@ -32058,7 +32062,7 @@ function rangesDeps(cacheFile) {
|
|
|
32058
32062
|
},
|
|
32059
32063
|
load: () => {
|
|
32060
32064
|
try {
|
|
32061
|
-
const v = JSON.parse((0,
|
|
32065
|
+
const v = JSON.parse((0, import_node_fs39.readFileSync)(cacheFile, "utf-8"));
|
|
32062
32066
|
return typeof v.at === "number" && Array.isArray(v.cidrs) ? { at: v.at, cidrs: v.cidrs.map(String) } : null;
|
|
32063
32067
|
} catch {
|
|
32064
32068
|
return null;
|
|
@@ -32066,7 +32070,7 @@ function rangesDeps(cacheFile) {
|
|
|
32066
32070
|
},
|
|
32067
32071
|
save: (v) => {
|
|
32068
32072
|
try {
|
|
32069
|
-
(0,
|
|
32073
|
+
(0, import_node_fs39.writeFileSync)(cacheFile, JSON.stringify(v), { mode: 420 });
|
|
32070
32074
|
} catch {
|
|
32071
32075
|
}
|
|
32072
32076
|
},
|
|
@@ -32272,7 +32276,7 @@ var SshLoginEnricher = class {
|
|
|
32272
32276
|
const now = deps.now ?? Date.now;
|
|
32273
32277
|
this.history = deps.history ?? new SshAuthHistory(now);
|
|
32274
32278
|
this.keys = deps.keys ?? new AuthorizedKeysIndex();
|
|
32275
|
-
this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0,
|
|
32279
|
+
this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0, import_node_path29.join)(deps.stateDir ?? ".", "github-actions-ranges.json")), settings.githubRanges);
|
|
32276
32280
|
this.net = deps.net ?? new NetLookup();
|
|
32277
32281
|
this.sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
32278
32282
|
this.host = deps.host ?? (0, import_node_os7.hostname)();
|
|
@@ -32355,8 +32359,8 @@ var SshLoginEnricher = class {
|
|
|
32355
32359
|
};
|
|
32356
32360
|
|
|
32357
32361
|
// src/daemon/rules/loader.ts
|
|
32358
|
-
var
|
|
32359
|
-
var
|
|
32362
|
+
var import_node_fs40 = require("fs");
|
|
32363
|
+
var import_node_path30 = require("path");
|
|
32360
32364
|
|
|
32361
32365
|
// src/daemon/rules/default-rules.ts
|
|
32362
32366
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -33032,16 +33036,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
33032
33036
|
function loadAllRules(customDir) {
|
|
33033
33037
|
const rules = [...DEFAULT_RULES];
|
|
33034
33038
|
const dir = customDir || RULES_DIR;
|
|
33035
|
-
if ((0,
|
|
33039
|
+
if ((0, import_node_fs40.existsSync)(dir)) {
|
|
33036
33040
|
let files = [];
|
|
33037
33041
|
try {
|
|
33038
|
-
files = (0,
|
|
33042
|
+
files = (0, import_node_fs40.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
33039
33043
|
} catch (err) {
|
|
33040
33044
|
console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
|
|
33041
33045
|
}
|
|
33042
33046
|
for (const file of files) {
|
|
33043
33047
|
try {
|
|
33044
|
-
const raw = (0,
|
|
33048
|
+
const raw = (0, import_node_fs40.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
|
|
33045
33049
|
const parsed = JSON.parse(raw);
|
|
33046
33050
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
33047
33051
|
for (const rule of customRules) {
|
|
@@ -33073,8 +33077,8 @@ function loadAllRules(customDir) {
|
|
|
33073
33077
|
|
|
33074
33078
|
// src/daemon/firewall/adapters.ts
|
|
33075
33079
|
var import_node_child_process15 = require("child_process");
|
|
33076
|
-
var
|
|
33077
|
-
var
|
|
33080
|
+
var import_node_fs41 = require("fs");
|
|
33081
|
+
var import_node_path31 = require("path");
|
|
33078
33082
|
var import_node_net18 = require("net");
|
|
33079
33083
|
function assertValidFirewallIp(ip) {
|
|
33080
33084
|
if ((0, import_node_net18.isIP)(ip) !== 4) {
|
|
@@ -33087,9 +33091,9 @@ function assertBannableIp(ip) {
|
|
|
33087
33091
|
}
|
|
33088
33092
|
}
|
|
33089
33093
|
function writeIfAbsent(path, contents) {
|
|
33090
|
-
(0,
|
|
33094
|
+
(0, import_node_fs41.mkdirSync)((0, import_node_path31.dirname)(path), { recursive: true });
|
|
33091
33095
|
try {
|
|
33092
|
-
(0,
|
|
33096
|
+
(0, import_node_fs41.writeFileSync)(path, contents, { flag: "wx" });
|
|
33093
33097
|
} catch (err) {
|
|
33094
33098
|
if (err.code !== "EEXIST") throw err;
|
|
33095
33099
|
}
|
|
@@ -33348,7 +33352,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
33348
33352
|
}
|
|
33349
33353
|
|
|
33350
33354
|
// src/daemon/firewall/remediation.ts
|
|
33351
|
-
var
|
|
33355
|
+
var import_node_fs42 = require("fs");
|
|
33352
33356
|
var import_node_child_process16 = require("child_process");
|
|
33353
33357
|
var import_node_net19 = require("net");
|
|
33354
33358
|
|
|
@@ -33418,19 +33422,19 @@ var defaultDiscovery = {
|
|
|
33418
33422
|
const snapshot = takeSnapshot({
|
|
33419
33423
|
readFile: (p) => {
|
|
33420
33424
|
try {
|
|
33421
|
-
return (0,
|
|
33425
|
+
return (0, import_node_fs42.readFileSync)(p, "utf-8");
|
|
33422
33426
|
} catch {
|
|
33423
33427
|
return null;
|
|
33424
33428
|
}
|
|
33425
33429
|
},
|
|
33426
33430
|
readDir: (p) => {
|
|
33427
33431
|
try {
|
|
33428
|
-
return (0,
|
|
33432
|
+
return (0, import_node_fs42.readdirSync)(p);
|
|
33429
33433
|
} catch {
|
|
33430
33434
|
return null;
|
|
33431
33435
|
}
|
|
33432
33436
|
},
|
|
33433
|
-
exists: (p) => (0,
|
|
33437
|
+
exists: (p) => (0, import_node_fs42.existsSync)(p)
|
|
33434
33438
|
});
|
|
33435
33439
|
const out = /* @__PURE__ */ new Set();
|
|
33436
33440
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -33943,7 +33947,7 @@ var RemediationManager = class {
|
|
|
33943
33947
|
}
|
|
33944
33948
|
logLine(line) {
|
|
33945
33949
|
try {
|
|
33946
|
-
(0,
|
|
33950
|
+
(0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
33947
33951
|
`);
|
|
33948
33952
|
} catch {
|
|
33949
33953
|
}
|
|
@@ -33983,13 +33987,13 @@ function remediationSettings(section) {
|
|
|
33983
33987
|
}
|
|
33984
33988
|
|
|
33985
33989
|
// src/daemon/watchdog-service.ts
|
|
33986
|
-
var
|
|
33987
|
-
var
|
|
33990
|
+
var import_node_fs44 = require("fs");
|
|
33991
|
+
var import_node_path33 = require("path");
|
|
33988
33992
|
|
|
33989
33993
|
// src/core/watchdog.ts
|
|
33990
|
-
var
|
|
33994
|
+
var import_node_fs43 = require("fs");
|
|
33991
33995
|
var import_node_crypto10 = require("crypto");
|
|
33992
|
-
var
|
|
33996
|
+
var import_node_path32 = require("path");
|
|
33993
33997
|
var WATCHDOG_DIRNAME = "watchdog";
|
|
33994
33998
|
var LOG_FILE2 = "attacks.jsonl";
|
|
33995
33999
|
var ROTATED_FILE = "attacks.1.jsonl";
|
|
@@ -34078,12 +34082,12 @@ var WatchdogLog = class {
|
|
|
34078
34082
|
stats = { logged: 0, answered: 0, errored: 0 };
|
|
34079
34083
|
constructor(dir, options = {}) {
|
|
34080
34084
|
this.dir = dir;
|
|
34081
|
-
this.file = (0,
|
|
34085
|
+
this.file = (0, import_node_path32.join)(dir, LOG_FILE2);
|
|
34082
34086
|
this.shareGid = options.shareGid;
|
|
34083
|
-
(0,
|
|
34087
|
+
(0, import_node_fs43.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
|
|
34084
34088
|
if (this.shareGid !== void 0) {
|
|
34085
|
-
(0,
|
|
34086
|
-
(0,
|
|
34089
|
+
(0, import_node_fs43.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
|
|
34090
|
+
(0, import_node_fs43.chmodSync)(dir, 1528);
|
|
34087
34091
|
}
|
|
34088
34092
|
for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
|
|
34089
34093
|
}
|
|
@@ -34112,16 +34116,16 @@ var WatchdogLog = class {
|
|
|
34112
34116
|
const chunk = this.buffer.join("\n") + "\n";
|
|
34113
34117
|
this.buffer = [];
|
|
34114
34118
|
try {
|
|
34115
|
-
if ((0,
|
|
34116
|
-
(0,
|
|
34119
|
+
if ((0, import_node_fs43.statSync)(this.file).size > ROTATE_BYTES) {
|
|
34120
|
+
(0, import_node_fs43.renameSync)(this.file, (0, import_node_path32.join)(this.dir, ROTATED_FILE));
|
|
34117
34121
|
}
|
|
34118
34122
|
} catch {
|
|
34119
34123
|
}
|
|
34120
|
-
(0,
|
|
34124
|
+
(0, import_node_fs43.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
|
|
34121
34125
|
if (this.shareGid !== void 0) {
|
|
34122
34126
|
try {
|
|
34123
|
-
(0,
|
|
34124
|
-
(0,
|
|
34127
|
+
(0, import_node_fs43.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
|
|
34128
|
+
(0, import_node_fs43.chmodSync)(this.file, 432);
|
|
34125
34129
|
} catch {
|
|
34126
34130
|
}
|
|
34127
34131
|
}
|
|
@@ -34142,21 +34146,21 @@ function parseLines(text) {
|
|
|
34142
34146
|
function readTail(file, bytes) {
|
|
34143
34147
|
let fd;
|
|
34144
34148
|
try {
|
|
34145
|
-
fd = (0,
|
|
34149
|
+
fd = (0, import_node_fs43.openSync)(file, "r");
|
|
34146
34150
|
} catch (err) {
|
|
34147
34151
|
if (err.code === "ENOENT") return [];
|
|
34148
34152
|
throw err;
|
|
34149
34153
|
}
|
|
34150
34154
|
try {
|
|
34151
|
-
const size = (0,
|
|
34155
|
+
const size = (0, import_node_fs43.fstatSync)(fd).size;
|
|
34152
34156
|
const start = Math.max(0, size - bytes);
|
|
34153
34157
|
const buf = Buffer.alloc(size - start);
|
|
34154
|
-
(0,
|
|
34158
|
+
(0, import_node_fs43.readSync)(fd, buf, 0, buf.length, start);
|
|
34155
34159
|
let text = buf.toString("utf8");
|
|
34156
34160
|
if (start > 0) text = text.slice(text.indexOf("\n") + 1);
|
|
34157
34161
|
return parseLines(text);
|
|
34158
34162
|
} finally {
|
|
34159
|
-
(0,
|
|
34163
|
+
(0, import_node_fs43.closeSync)(fd);
|
|
34160
34164
|
}
|
|
34161
34165
|
}
|
|
34162
34166
|
|
|
@@ -34165,13 +34169,13 @@ function defaultShareGid() {
|
|
|
34165
34169
|
const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
34166
34170
|
if (!isRoot2) return void 0;
|
|
34167
34171
|
try {
|
|
34168
|
-
return (0,
|
|
34172
|
+
return (0, import_node_fs44.statSync)("/var/log/auth.log").gid;
|
|
34169
34173
|
} catch {
|
|
34170
34174
|
return void 0;
|
|
34171
34175
|
}
|
|
34172
34176
|
}
|
|
34173
34177
|
function startWatchdog(opts) {
|
|
34174
|
-
const dir = opts.config?.dir ?? (0,
|
|
34178
|
+
const dir = opts.config?.dir ?? (0, import_node_path33.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
34175
34179
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
34176
34180
|
if (opts.config?.enabled === false) {
|
|
34177
34181
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -34278,7 +34282,7 @@ function daemonNodeProblem(version) {
|
|
|
34278
34282
|
// src/daemon/index.ts
|
|
34279
34283
|
function readVersion2() {
|
|
34280
34284
|
try {
|
|
34281
|
-
const pkg = JSON.parse((0,
|
|
34285
|
+
const pkg = JSON.parse((0, import_node_fs45.readFileSync)((0, import_node_path34.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
34282
34286
|
return pkg.version || "0.0.0";
|
|
34283
34287
|
} catch {
|
|
34284
34288
|
return "0.0.0";
|
|
@@ -34287,7 +34291,7 @@ function readVersion2() {
|
|
|
34287
34291
|
async function runHardeningChecks() {
|
|
34288
34292
|
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process18.execFile)(
|
|
34289
34293
|
process.execPath,
|
|
34290
|
-
[(0,
|
|
34294
|
+
[(0, import_node_path34.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
34291
34295
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
34292
34296
|
);
|
|
34293
34297
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -34301,7 +34305,7 @@ async function runHardeningChecks() {
|
|
|
34301
34305
|
async function runPatchCheck() {
|
|
34302
34306
|
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process18.execFile)(
|
|
34303
34307
|
process.execPath,
|
|
34304
|
-
[(0,
|
|
34308
|
+
[(0, import_node_path34.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
34305
34309
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
34306
34310
|
);
|
|
34307
34311
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -34309,7 +34313,7 @@ async function runPatchCheck() {
|
|
|
34309
34313
|
}
|
|
34310
34314
|
function logLine(line) {
|
|
34311
34315
|
try {
|
|
34312
|
-
(0,
|
|
34316
|
+
(0, import_node_fs45.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
34313
34317
|
`);
|
|
34314
34318
|
} catch {
|
|
34315
34319
|
}
|
|
@@ -34351,7 +34355,7 @@ async function runDaemon() {
|
|
|
34351
34355
|
} catch (err) {
|
|
34352
34356
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
34353
34357
|
}
|
|
34354
|
-
const loaded = loadDaemonConfig(PATHS.configFile, (0,
|
|
34358
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path34.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
34355
34359
|
const config = loaded.config;
|
|
34356
34360
|
if (loaded.error) {
|
|
34357
34361
|
logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
|
|
@@ -34432,7 +34436,7 @@ async function runDaemon() {
|
|
|
34432
34436
|
const threatFeeds = new ThreatFeeds({
|
|
34433
34437
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
34434
34438
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
34435
|
-
cachePath: (0,
|
|
34439
|
+
cachePath: (0, import_node_path34.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
34436
34440
|
bus,
|
|
34437
34441
|
log: logLine
|
|
34438
34442
|
});
|
|
@@ -34440,9 +34444,9 @@ async function runDaemon() {
|
|
|
34440
34444
|
const privilegeWatch = new PrivilegeWatch({
|
|
34441
34445
|
settings: privilegeSettings(config.privileged),
|
|
34442
34446
|
bus,
|
|
34443
|
-
snapshotPath: (0,
|
|
34444
|
-
loginsPath: (0,
|
|
34445
|
-
cursorPath: (0,
|
|
34447
|
+
snapshotPath: (0, import_node_path34.join)(PATHS.stateDir, "privileges.json"),
|
|
34448
|
+
loginsPath: (0, import_node_path34.join)(PATHS.stateDir, "login-countries.json"),
|
|
34449
|
+
cursorPath: (0, import_node_path34.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
34446
34450
|
log: logLine
|
|
34447
34451
|
});
|
|
34448
34452
|
privilegeWatch.start();
|
|
@@ -34456,8 +34460,8 @@ async function runDaemon() {
|
|
|
34456
34460
|
const fileIntegrity = new FileIntegrityWatch({
|
|
34457
34461
|
bus,
|
|
34458
34462
|
settings: fileIntegritySettings(config.file_integrity),
|
|
34459
|
-
baselinePath: (0,
|
|
34460
|
-
observedPath: (0,
|
|
34463
|
+
baselinePath: (0, import_node_path34.join)(PATHS.stateDir, "file-integrity-baseline.json"),
|
|
34464
|
+
observedPath: (0, import_node_path34.join)(PATHS.stateDir, "file-integrity-observed.json"),
|
|
34461
34465
|
// `[remediation] dry_run` also covers the opt-in contain_writer response.
|
|
34462
34466
|
dryRun: () => remediation.status().dry_run,
|
|
34463
34467
|
log: logLine
|
|
@@ -34466,8 +34470,8 @@ async function runDaemon() {
|
|
|
34466
34470
|
const edr = new EdrWatch({
|
|
34467
34471
|
bus,
|
|
34468
34472
|
settings: edrSettings(config.edr),
|
|
34469
|
-
networkBaselinePath: (0,
|
|
34470
|
-
sourceStatusPath: (0,
|
|
34473
|
+
networkBaselinePath: (0, import_node_path34.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
34474
|
+
sourceStatusPath: (0, import_node_path34.join)(PATHS.stateDir, "edr-source.json"),
|
|
34471
34475
|
// Every traced connect is checked against the abuse.ch lists: this is what
|
|
34472
34476
|
// sees a one-second download or a container calling out, which the
|
|
34473
34477
|
// threat-feeds socket snapshot cannot.
|
|
@@ -34478,7 +34482,7 @@ async function runDaemon() {
|
|
|
34478
34482
|
});
|
|
34479
34483
|
edr.start();
|
|
34480
34484
|
const torExits = new TorExitList({
|
|
34481
|
-
cachePath: (0,
|
|
34485
|
+
cachePath: (0, import_node_path34.join)(PATHS.stateDir, "tor-exits.txt"),
|
|
34482
34486
|
url: config.remediation?.tor_exit_list_url,
|
|
34483
34487
|
log: logLine
|
|
34484
34488
|
});
|
|
@@ -34486,7 +34490,7 @@ async function runDaemon() {
|
|
|
34486
34490
|
bus,
|
|
34487
34491
|
manager: remediation,
|
|
34488
34492
|
tor: torExits,
|
|
34489
|
-
historyPath: (0,
|
|
34493
|
+
historyPath: (0, import_node_path34.join)(PATHS.stateDir, "key-logins.json"),
|
|
34490
34494
|
keyLoginWatch: config.privileged?.key_login_watch !== false,
|
|
34491
34495
|
log: logLine
|
|
34492
34496
|
});
|
|
@@ -34561,7 +34565,7 @@ async function runDaemon() {
|
|
|
34561
34565
|
version,
|
|
34562
34566
|
hostname: (0, import_node_os8.hostname)(),
|
|
34563
34567
|
minSeverity,
|
|
34564
|
-
spoolPath: (0,
|
|
34568
|
+
spoolPath: (0, import_node_path34.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
34565
34569
|
log: logLine,
|
|
34566
34570
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
34567
34571
|
runHardening: runHardeningChecks
|
|
@@ -34595,8 +34599,8 @@ async function runDaemon() {
|
|
|
34595
34599
|
const autoUpdate = autoUpdateRef = new AutoUpdate({
|
|
34596
34600
|
version,
|
|
34597
34601
|
settings: updateSettings(config.update),
|
|
34598
|
-
pkgRoot: (0,
|
|
34599
|
-
statePath: (0,
|
|
34602
|
+
pkgRoot: (0, import_node_path34.join)(__dirname, ".."),
|
|
34603
|
+
statePath: (0, import_node_path34.join)(PATHS.stateDir, "auto-update.json"),
|
|
34600
34604
|
bus,
|
|
34601
34605
|
log: logLine,
|
|
34602
34606
|
restartDaemon
|