@profullstack/threatcrush 0.13.59 → 0.13.60
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 +7 -1
- package/dist/daemon.js +346 -242
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +488 -366
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -1643,20 +1643,20 @@ var require_parse_async = __commonJS({
|
|
|
1643
1643
|
const index = 0;
|
|
1644
1644
|
const blocksize = opts.blocksize || 40960;
|
|
1645
1645
|
const parser = new TOMLParser();
|
|
1646
|
-
return new Promise((
|
|
1647
|
-
setImmediate(parseAsyncNext, index, blocksize,
|
|
1646
|
+
return new Promise((resolve4, reject) => {
|
|
1647
|
+
setImmediate(parseAsyncNext, index, blocksize, resolve4, reject);
|
|
1648
1648
|
});
|
|
1649
|
-
function parseAsyncNext(index2, blocksize2,
|
|
1649
|
+
function parseAsyncNext(index2, blocksize2, resolve4, reject) {
|
|
1650
1650
|
if (index2 >= str3.length) {
|
|
1651
1651
|
try {
|
|
1652
|
-
return
|
|
1652
|
+
return resolve4(parser.finish());
|
|
1653
1653
|
} catch (err) {
|
|
1654
1654
|
return reject(prettyError(err, str3));
|
|
1655
1655
|
}
|
|
1656
1656
|
}
|
|
1657
1657
|
try {
|
|
1658
1658
|
parser.parse(str3.slice(index2, index2 + blocksize2));
|
|
1659
|
-
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2,
|
|
1659
|
+
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve4, reject);
|
|
1660
1660
|
} catch (err) {
|
|
1661
1661
|
reject(prettyError(err, str3));
|
|
1662
1662
|
}
|
|
@@ -1682,7 +1682,7 @@ var require_parse_stream = __commonJS({
|
|
|
1682
1682
|
function parseReadable(stm) {
|
|
1683
1683
|
const parser = new TOMLParser();
|
|
1684
1684
|
stm.setEncoding("utf8");
|
|
1685
|
-
return new Promise((
|
|
1685
|
+
return new Promise((resolve4, reject) => {
|
|
1686
1686
|
let readable;
|
|
1687
1687
|
let ended = false;
|
|
1688
1688
|
let errored = false;
|
|
@@ -1690,7 +1690,7 @@ var require_parse_stream = __commonJS({
|
|
|
1690
1690
|
ended = true;
|
|
1691
1691
|
if (readable) return;
|
|
1692
1692
|
try {
|
|
1693
|
-
|
|
1693
|
+
resolve4(parser.finish());
|
|
1694
1694
|
} catch (err) {
|
|
1695
1695
|
reject(err);
|
|
1696
1696
|
}
|
|
@@ -2026,10 +2026,10 @@ var require_toml = __commonJS({
|
|
|
2026
2026
|
});
|
|
2027
2027
|
|
|
2028
2028
|
// src/daemon/index.ts
|
|
2029
|
-
var
|
|
2029
|
+
var import_node_fs31 = require("fs");
|
|
2030
2030
|
var import_node_child_process11 = require("child_process");
|
|
2031
2031
|
var import_node_os5 = require("os");
|
|
2032
|
-
var
|
|
2032
|
+
var import_node_path24 = require("path");
|
|
2033
2033
|
var import_node_util = require("util");
|
|
2034
2034
|
|
|
2035
2035
|
// src/daemon/paths.ts
|
|
@@ -2451,7 +2451,7 @@ var IpcServer = class {
|
|
|
2451
2451
|
} catch {
|
|
2452
2452
|
}
|
|
2453
2453
|
}
|
|
2454
|
-
return new Promise((
|
|
2454
|
+
return new Promise((resolve4, reject) => {
|
|
2455
2455
|
this.server = (0, import_node_net.createServer)((sock) => this.handleClient(sock));
|
|
2456
2456
|
this.server.on("error", reject);
|
|
2457
2457
|
this.server.listen(PATHS.socket, () => {
|
|
@@ -2470,7 +2470,7 @@ var IpcServer = class {
|
|
|
2470
2470
|
}
|
|
2471
2471
|
}
|
|
2472
2472
|
}
|
|
2473
|
-
|
|
2473
|
+
resolve4();
|
|
2474
2474
|
});
|
|
2475
2475
|
});
|
|
2476
2476
|
}
|
|
@@ -2482,20 +2482,20 @@ var IpcServer = class {
|
|
|
2482
2482
|
}
|
|
2483
2483
|
}
|
|
2484
2484
|
this.clients.clear();
|
|
2485
|
-
return new Promise((
|
|
2485
|
+
return new Promise((resolve4) => {
|
|
2486
2486
|
if (!this.server) {
|
|
2487
2487
|
try {
|
|
2488
2488
|
if ((0, import_node_fs4.existsSync)(PATHS.socket)) (0, import_node_fs4.unlinkSync)(PATHS.socket);
|
|
2489
2489
|
} catch {
|
|
2490
2490
|
}
|
|
2491
|
-
return
|
|
2491
|
+
return resolve4();
|
|
2492
2492
|
}
|
|
2493
2493
|
this.server.close(() => {
|
|
2494
2494
|
try {
|
|
2495
2495
|
if ((0, import_node_fs4.existsSync)(PATHS.socket)) (0, import_node_fs4.unlinkSync)(PATHS.socket);
|
|
2496
2496
|
} catch {
|
|
2497
2497
|
}
|
|
2498
|
-
|
|
2498
|
+
resolve4();
|
|
2499
2499
|
});
|
|
2500
2500
|
});
|
|
2501
2501
|
}
|
|
@@ -11553,6 +11553,12 @@ function slackChannel(webhookUrl) {
|
|
|
11553
11553
|
};
|
|
11554
11554
|
}
|
|
11555
11555
|
|
|
11556
|
+
// src/daemon/workers/runs-worker.ts
|
|
11557
|
+
var import_promises = require("dns/promises");
|
|
11558
|
+
var import_node_fs20 = require("fs");
|
|
11559
|
+
var import_node_net5 = require("net");
|
|
11560
|
+
var import_node_path14 = require("path");
|
|
11561
|
+
|
|
11556
11562
|
// src/core/cli-config.ts
|
|
11557
11563
|
var import_node_fs15 = require("fs");
|
|
11558
11564
|
var import_node_path8 = require("path");
|
|
@@ -11648,6 +11654,106 @@ async function cloudFetch(path, init = {}) {
|
|
|
11648
11654
|
return send();
|
|
11649
11655
|
}
|
|
11650
11656
|
|
|
11657
|
+
// src/core/cloud-events.ts
|
|
11658
|
+
var import_node_crypto3 = require("crypto");
|
|
11659
|
+
var import_node_net4 = require("net");
|
|
11660
|
+
function currentLink() {
|
|
11661
|
+
if (!hasSession()) return null;
|
|
11662
|
+
const cfg = readCliConfig();
|
|
11663
|
+
if (!cfg.server_id || !cfg.server_org_id) return null;
|
|
11664
|
+
return { serverId: cfg.server_id, orgId: cfg.server_org_id };
|
|
11665
|
+
}
|
|
11666
|
+
var SEVERITY_RANK4 = {
|
|
11667
|
+
info: 0,
|
|
11668
|
+
low: 1,
|
|
11669
|
+
medium: 2,
|
|
11670
|
+
high: 3,
|
|
11671
|
+
critical: 4
|
|
11672
|
+
};
|
|
11673
|
+
var MAX_TITLE_CHARS = 300;
|
|
11674
|
+
var MAX_METADATA_BYTES = 16 * 1024;
|
|
11675
|
+
var MAX_STRING_CHARS = 1024;
|
|
11676
|
+
function jsonBytes(value) {
|
|
11677
|
+
try {
|
|
11678
|
+
return Buffer.byteLength(JSON.stringify(value) ?? "");
|
|
11679
|
+
} catch {
|
|
11680
|
+
return Infinity;
|
|
11681
|
+
}
|
|
11682
|
+
}
|
|
11683
|
+
function trimMetadata(meta) {
|
|
11684
|
+
const entries = [];
|
|
11685
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
11686
|
+
if (value === void 0 || typeof value === "function") continue;
|
|
11687
|
+
const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
|
|
11688
|
+
if (jsonBytes(cut) === Infinity) continue;
|
|
11689
|
+
entries.push([key, cut]);
|
|
11690
|
+
}
|
|
11691
|
+
let out = Object.fromEntries(entries);
|
|
11692
|
+
let truncated = entries.length !== Object.keys(meta).length;
|
|
11693
|
+
if (jsonBytes(out) > MAX_METADATA_BYTES) {
|
|
11694
|
+
truncated = true;
|
|
11695
|
+
const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
|
|
11696
|
+
while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
|
|
11697
|
+
bySize.pop();
|
|
11698
|
+
}
|
|
11699
|
+
out = Object.fromEntries(bySize);
|
|
11700
|
+
}
|
|
11701
|
+
return truncated ? { ...out, _truncated: true } : out;
|
|
11702
|
+
}
|
|
11703
|
+
function str(value) {
|
|
11704
|
+
return typeof value === "string" && value ? value : void 0;
|
|
11705
|
+
}
|
|
11706
|
+
function detectionEvent(serverId, event) {
|
|
11707
|
+
const { rule_id, username, user, description, ...rest } = event.details ?? {};
|
|
11708
|
+
const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
|
|
11709
|
+
return {
|
|
11710
|
+
type: "detection",
|
|
11711
|
+
server_id: serverId,
|
|
11712
|
+
severity: event.severity,
|
|
11713
|
+
title: title.slice(0, MAX_TITLE_CHARS) || event.module,
|
|
11714
|
+
rule_id: str(rule_id) ?? event.module,
|
|
11715
|
+
description: str(description),
|
|
11716
|
+
source_ip: event.source_ip && (0, import_node_net4.isIP)(event.source_ip) ? event.source_ip : void 0,
|
|
11717
|
+
username: str(username) ?? str(user),
|
|
11718
|
+
raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
|
|
11719
|
+
detected_at: event.timestamp.toISOString()
|
|
11720
|
+
};
|
|
11721
|
+
}
|
|
11722
|
+
function remediationEvent(serverId, event) {
|
|
11723
|
+
const d = event.details ?? {};
|
|
11724
|
+
if (d.action !== "block" && d.action !== "unblock") return null;
|
|
11725
|
+
if (d.origin === "cloud" || !event.source_ip) return null;
|
|
11726
|
+
const at = event.timestamp;
|
|
11727
|
+
const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
|
|
11728
|
+
return {
|
|
11729
|
+
type: "remediation",
|
|
11730
|
+
server_id: serverId,
|
|
11731
|
+
event_id: (0, import_node_crypto3.randomUUID)(),
|
|
11732
|
+
action_type: d.action,
|
|
11733
|
+
target_value: event.source_ip,
|
|
11734
|
+
status: d.failed === true ? "failed" : "executed",
|
|
11735
|
+
rule_id: str(d.rule_id),
|
|
11736
|
+
reason: str(d.reason),
|
|
11737
|
+
error: str(d.error),
|
|
11738
|
+
dry_run: d.dry_run === true,
|
|
11739
|
+
executed_at: at.toISOString(),
|
|
11740
|
+
expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
|
|
11741
|
+
};
|
|
11742
|
+
}
|
|
11743
|
+
function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
|
|
11744
|
+
return results.map((r) => ({
|
|
11745
|
+
type: "hardening_finding",
|
|
11746
|
+
server_id: serverId,
|
|
11747
|
+
finding_key: r.key,
|
|
11748
|
+
status: r.status,
|
|
11749
|
+
severity: r.severity,
|
|
11750
|
+
title: r.title.slice(0, MAX_TITLE_CHARS),
|
|
11751
|
+
recommendation: r.recommendation,
|
|
11752
|
+
observed_at: observedAt.toISOString(),
|
|
11753
|
+
...r.details ? { details: trimMetadata(r.details) } : {}
|
|
11754
|
+
}));
|
|
11755
|
+
}
|
|
11756
|
+
|
|
11651
11757
|
// src/commands/scan.ts
|
|
11652
11758
|
var import_node_fs19 = require("fs");
|
|
11653
11759
|
var import_node_path13 = require("path");
|
|
@@ -15725,7 +15831,7 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
15725
15831
|
}
|
|
15726
15832
|
|
|
15727
15833
|
// ../../packages/scan/src/node/sarif.ts
|
|
15728
|
-
var
|
|
15834
|
+
var import_node_crypto4 = require("crypto");
|
|
15729
15835
|
var import_node_path12 = require("path");
|
|
15730
15836
|
|
|
15731
15837
|
// src/commands/scan.ts
|
|
@@ -15949,16 +16055,77 @@ async function collectPentestResults(targetUrl) {
|
|
|
15949
16055
|
// src/daemon/workers/runs-worker.ts
|
|
15950
16056
|
var POLL_INTERVAL_MS = 3e4;
|
|
15951
16057
|
var SCHEDULE_INTERVAL_MS = 12e4;
|
|
16058
|
+
var NOT_PUBLIC = [
|
|
16059
|
+
...DEFAULT_PROTECTED,
|
|
16060
|
+
"0.0.0.0/8",
|
|
16061
|
+
"100.64.0.0/10",
|
|
16062
|
+
"192.0.0.0/24",
|
|
16063
|
+
"198.18.0.0/15",
|
|
16064
|
+
"224.0.0.0/3",
|
|
16065
|
+
"::/128",
|
|
16066
|
+
"::ffff:0:0/96",
|
|
16067
|
+
"64:ff9b::/96",
|
|
16068
|
+
"ff00::/8"
|
|
16069
|
+
];
|
|
16070
|
+
function isPublicTarget(ip) {
|
|
16071
|
+
return (0, import_node_net5.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
|
|
16072
|
+
}
|
|
16073
|
+
async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises.lookup)(h, { all: true })).map((a) => a.address)) {
|
|
16074
|
+
let url;
|
|
16075
|
+
try {
|
|
16076
|
+
url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
|
|
16077
|
+
} catch {
|
|
16078
|
+
return `not a URL: ${rawUrl}`;
|
|
16079
|
+
}
|
|
16080
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return `not an http(s) URL: ${rawUrl}`;
|
|
16081
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
16082
|
+
let addresses;
|
|
16083
|
+
try {
|
|
16084
|
+
addresses = (0, import_node_net5.isIP)(host) ? [host] : await resolveHost(host);
|
|
16085
|
+
} catch (err) {
|
|
16086
|
+
return `cannot resolve ${host}: ${err.message}`;
|
|
16087
|
+
}
|
|
16088
|
+
if (addresses.length === 0) return `cannot resolve ${host}`;
|
|
16089
|
+
const inside = addresses.find((a) => !isPublicTarget(a));
|
|
16090
|
+
return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
|
|
16091
|
+
}
|
|
16092
|
+
function scanTargetError(target, roots, real = import_node_fs20.realpathSync) {
|
|
16093
|
+
if (roots.length === 0) {
|
|
16094
|
+
return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
|
|
16095
|
+
}
|
|
16096
|
+
let path;
|
|
16097
|
+
try {
|
|
16098
|
+
path = real((0, import_node_path14.resolve)(target));
|
|
16099
|
+
} catch {
|
|
16100
|
+
return `no such path: ${target}`;
|
|
16101
|
+
}
|
|
16102
|
+
for (const root of roots) {
|
|
16103
|
+
let base;
|
|
16104
|
+
try {
|
|
16105
|
+
base = real((0, import_node_path14.resolve)(root));
|
|
16106
|
+
} catch {
|
|
16107
|
+
continue;
|
|
16108
|
+
}
|
|
16109
|
+
if (path === base || path.startsWith(base.endsWith(import_node_path14.sep) ? base : base + import_node_path14.sep)) return null;
|
|
16110
|
+
}
|
|
16111
|
+
return `${target} is outside [cloud] run_scan_paths`;
|
|
16112
|
+
}
|
|
15952
16113
|
var RunsWorker = class {
|
|
15953
|
-
constructor(bus2) {
|
|
16114
|
+
constructor(bus2, opts = { enabled: false, scanRoots: [] }) {
|
|
15954
16115
|
this.bus = bus2;
|
|
16116
|
+
this.opts = opts;
|
|
15955
16117
|
}
|
|
15956
16118
|
bus;
|
|
16119
|
+
opts;
|
|
15957
16120
|
pollTimer = null;
|
|
15958
16121
|
scheduleTimer = null;
|
|
15959
16122
|
running = false;
|
|
15960
16123
|
orgIds = [];
|
|
15961
16124
|
async start() {
|
|
16125
|
+
if (!this.opts.enabled) {
|
|
16126
|
+
this.opts.log?.("[runs] dashboard property runs off (set [cloud] runs = true to run them on this machine)");
|
|
16127
|
+
return;
|
|
16128
|
+
}
|
|
15962
16129
|
if (!hasSession()) return;
|
|
15963
16130
|
try {
|
|
15964
16131
|
await this.refreshOrgs();
|
|
@@ -15980,7 +16147,7 @@ var RunsWorker = class {
|
|
|
15980
16147
|
async scheduleTick() {
|
|
15981
16148
|
if (!hasSession()) return;
|
|
15982
16149
|
try {
|
|
15983
|
-
|
|
16150
|
+
await this.refreshOrgs();
|
|
15984
16151
|
for (const orgId of this.orgIds) {
|
|
15985
16152
|
try {
|
|
15986
16153
|
await cloudFetch(`/api/orgs/${orgId}/schedules/tick`, { method: "POST" });
|
|
@@ -15995,7 +16162,7 @@ var RunsWorker = class {
|
|
|
15995
16162
|
if (!hasSession()) return;
|
|
15996
16163
|
this.running = true;
|
|
15997
16164
|
try {
|
|
15998
|
-
|
|
16165
|
+
await this.refreshOrgs();
|
|
15999
16166
|
for (const orgId of this.orgIds) {
|
|
16000
16167
|
const claimed = await this.claimOne(orgId);
|
|
16001
16168
|
if (!claimed) continue;
|
|
@@ -16007,11 +16174,10 @@ var RunsWorker = class {
|
|
|
16007
16174
|
this.running = false;
|
|
16008
16175
|
}
|
|
16009
16176
|
}
|
|
16177
|
+
/** Only the org this server is linked to: never every org its user is in. */
|
|
16010
16178
|
async refreshOrgs() {
|
|
16011
|
-
const
|
|
16012
|
-
|
|
16013
|
-
const data = await res.json();
|
|
16014
|
-
this.orgIds = (data.organizations || []).map((o) => o.id);
|
|
16179
|
+
const link = currentLink();
|
|
16180
|
+
this.orgIds = link ? [link.orgId] : [];
|
|
16015
16181
|
}
|
|
16016
16182
|
async claimOne(orgId) {
|
|
16017
16183
|
try {
|
|
@@ -16038,6 +16204,18 @@ var RunsWorker = class {
|
|
|
16038
16204
|
error: "property target missing"
|
|
16039
16205
|
};
|
|
16040
16206
|
}
|
|
16207
|
+
const refused = run.type === "scan" ? scanTargetError(target, this.opts.scanRoots) : await pentestTargetError(target);
|
|
16208
|
+
if (refused) {
|
|
16209
|
+
this.opts.log?.(`[runs] refused ${run.type} ${target}: ${refused}`);
|
|
16210
|
+
return {
|
|
16211
|
+
type: run.type,
|
|
16212
|
+
target,
|
|
16213
|
+
findings: [],
|
|
16214
|
+
severity_summary: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
|
|
16215
|
+
summary: `refused: ${refused}`,
|
|
16216
|
+
error: refused
|
|
16217
|
+
};
|
|
16218
|
+
}
|
|
16041
16219
|
this.bus.announceModule("runs-worker", "running", `${run.type} ${run.property?.name || target}`);
|
|
16042
16220
|
try {
|
|
16043
16221
|
if (run.type === "scan") return await runScan(target);
|
|
@@ -16078,117 +16256,17 @@ var RunsWorker = class {
|
|
|
16078
16256
|
}
|
|
16079
16257
|
};
|
|
16080
16258
|
|
|
16081
|
-
// src/core/cloud-events.ts
|
|
16082
|
-
var import_node_crypto4 = require("crypto");
|
|
16083
|
-
var import_node_net4 = require("net");
|
|
16084
|
-
function currentLink() {
|
|
16085
|
-
if (!hasSession()) return null;
|
|
16086
|
-
const cfg = readCliConfig();
|
|
16087
|
-
if (!cfg.server_id || !cfg.server_org_id) return null;
|
|
16088
|
-
return { serverId: cfg.server_id, orgId: cfg.server_org_id };
|
|
16089
|
-
}
|
|
16090
|
-
var SEVERITY_RANK4 = {
|
|
16091
|
-
info: 0,
|
|
16092
|
-
low: 1,
|
|
16093
|
-
medium: 2,
|
|
16094
|
-
high: 3,
|
|
16095
|
-
critical: 4
|
|
16096
|
-
};
|
|
16097
|
-
var MAX_TITLE_CHARS = 300;
|
|
16098
|
-
var MAX_METADATA_BYTES = 16 * 1024;
|
|
16099
|
-
var MAX_STRING_CHARS = 1024;
|
|
16100
|
-
function jsonBytes(value) {
|
|
16101
|
-
try {
|
|
16102
|
-
return Buffer.byteLength(JSON.stringify(value) ?? "");
|
|
16103
|
-
} catch {
|
|
16104
|
-
return Infinity;
|
|
16105
|
-
}
|
|
16106
|
-
}
|
|
16107
|
-
function trimMetadata(meta) {
|
|
16108
|
-
const entries = [];
|
|
16109
|
-
for (const [key, value] of Object.entries(meta)) {
|
|
16110
|
-
if (value === void 0 || typeof value === "function") continue;
|
|
16111
|
-
const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
|
|
16112
|
-
if (jsonBytes(cut) === Infinity) continue;
|
|
16113
|
-
entries.push([key, cut]);
|
|
16114
|
-
}
|
|
16115
|
-
let out = Object.fromEntries(entries);
|
|
16116
|
-
let truncated = entries.length !== Object.keys(meta).length;
|
|
16117
|
-
if (jsonBytes(out) > MAX_METADATA_BYTES) {
|
|
16118
|
-
truncated = true;
|
|
16119
|
-
const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
|
|
16120
|
-
while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
|
|
16121
|
-
bySize.pop();
|
|
16122
|
-
}
|
|
16123
|
-
out = Object.fromEntries(bySize);
|
|
16124
|
-
}
|
|
16125
|
-
return truncated ? { ...out, _truncated: true } : out;
|
|
16126
|
-
}
|
|
16127
|
-
function str(value) {
|
|
16128
|
-
return typeof value === "string" && value ? value : void 0;
|
|
16129
|
-
}
|
|
16130
|
-
function detectionEvent(serverId, event) {
|
|
16131
|
-
const { rule_id, username, user, description, ...rest } = event.details ?? {};
|
|
16132
|
-
const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
|
|
16133
|
-
return {
|
|
16134
|
-
type: "detection",
|
|
16135
|
-
server_id: serverId,
|
|
16136
|
-
severity: event.severity,
|
|
16137
|
-
title: title.slice(0, MAX_TITLE_CHARS) || event.module,
|
|
16138
|
-
rule_id: str(rule_id) ?? event.module,
|
|
16139
|
-
description: str(description),
|
|
16140
|
-
source_ip: event.source_ip && (0, import_node_net4.isIP)(event.source_ip) ? event.source_ip : void 0,
|
|
16141
|
-
username: str(username) ?? str(user),
|
|
16142
|
-
raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
|
|
16143
|
-
detected_at: event.timestamp.toISOString()
|
|
16144
|
-
};
|
|
16145
|
-
}
|
|
16146
|
-
function remediationEvent(serverId, event) {
|
|
16147
|
-
const d = event.details ?? {};
|
|
16148
|
-
if (d.action !== "block" && d.action !== "unblock") return null;
|
|
16149
|
-
if (d.origin === "cloud" || !event.source_ip) return null;
|
|
16150
|
-
const at = event.timestamp;
|
|
16151
|
-
const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
|
|
16152
|
-
return {
|
|
16153
|
-
type: "remediation",
|
|
16154
|
-
server_id: serverId,
|
|
16155
|
-
event_id: (0, import_node_crypto4.randomUUID)(),
|
|
16156
|
-
action_type: d.action,
|
|
16157
|
-
target_value: event.source_ip,
|
|
16158
|
-
status: d.failed === true ? "failed" : "executed",
|
|
16159
|
-
rule_id: str(d.rule_id),
|
|
16160
|
-
reason: str(d.reason),
|
|
16161
|
-
error: str(d.error),
|
|
16162
|
-
dry_run: d.dry_run === true,
|
|
16163
|
-
executed_at: at.toISOString(),
|
|
16164
|
-
expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
|
|
16165
|
-
};
|
|
16166
|
-
}
|
|
16167
|
-
function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
|
|
16168
|
-
return results.map((r) => ({
|
|
16169
|
-
type: "hardening_finding",
|
|
16170
|
-
server_id: serverId,
|
|
16171
|
-
finding_key: r.key,
|
|
16172
|
-
status: r.status,
|
|
16173
|
-
severity: r.severity,
|
|
16174
|
-
title: r.title.slice(0, MAX_TITLE_CHARS),
|
|
16175
|
-
recommendation: r.recommendation,
|
|
16176
|
-
observed_at: observedAt.toISOString(),
|
|
16177
|
-
...r.details ? { details: trimMetadata(r.details) } : {}
|
|
16178
|
-
}));
|
|
16179
|
-
}
|
|
16180
|
-
|
|
16181
16259
|
// src/daemon/workers/cloud-spool.ts
|
|
16182
|
-
var
|
|
16183
|
-
var
|
|
16184
|
-
var
|
|
16260
|
+
var import_node_fs21 = require("fs");
|
|
16261
|
+
var import_promises2 = require("fs/promises");
|
|
16262
|
+
var import_node_path15 = require("path");
|
|
16185
16263
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
16186
16264
|
var CloudSpool = class {
|
|
16187
16265
|
constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
|
|
16188
16266
|
this.path = path;
|
|
16189
16267
|
this.limits = limits;
|
|
16190
16268
|
try {
|
|
16191
|
-
(0,
|
|
16269
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path15.dirname)(path), { recursive: true });
|
|
16192
16270
|
} catch {
|
|
16193
16271
|
}
|
|
16194
16272
|
this.load();
|
|
@@ -16257,7 +16335,7 @@ var CloudSpool = class {
|
|
|
16257
16335
|
load() {
|
|
16258
16336
|
let raw;
|
|
16259
16337
|
try {
|
|
16260
|
-
raw = (0,
|
|
16338
|
+
raw = (0, import_node_fs21.readFileSync)(this.path, "utf-8");
|
|
16261
16339
|
} catch {
|
|
16262
16340
|
return;
|
|
16263
16341
|
}
|
|
@@ -16288,13 +16366,13 @@ var CloudSpool = class {
|
|
|
16288
16366
|
const body = this.lines.length > 0 ? `${this.lines.join("\n")}
|
|
16289
16367
|
` : "";
|
|
16290
16368
|
const tmp = `${this.path}.tmp`;
|
|
16291
|
-
await (0,
|
|
16292
|
-
await (0,
|
|
16369
|
+
await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
|
|
16370
|
+
await (0, import_promises2.rename)(tmp, this.path);
|
|
16293
16371
|
} else if (this.pendingAppend.length > 0) {
|
|
16294
16372
|
const chunk = `${this.pendingAppend.join("\n")}
|
|
16295
16373
|
`;
|
|
16296
16374
|
this.pendingAppend = [];
|
|
16297
|
-
await (0,
|
|
16375
|
+
await (0, import_promises2.appendFile)(this.path, chunk, { mode: 384 });
|
|
16298
16376
|
}
|
|
16299
16377
|
}).catch(() => {
|
|
16300
16378
|
this.needsRewrite = true;
|
|
@@ -16498,7 +16576,7 @@ var CloudSync = class {
|
|
|
16498
16576
|
var import_node_crypto5 = require("crypto");
|
|
16499
16577
|
|
|
16500
16578
|
// src/daemon/workers/abuse-evidence.ts
|
|
16501
|
-
var
|
|
16579
|
+
var import_node_net6 = require("net");
|
|
16502
16580
|
var NEVER_REPORT_RANGES = [
|
|
16503
16581
|
...DEFAULT_PROTECTED,
|
|
16504
16582
|
"100.64.0.0/10",
|
|
@@ -16574,7 +16652,7 @@ function summarizeEvidence(events) {
|
|
|
16574
16652
|
};
|
|
16575
16653
|
}
|
|
16576
16654
|
function isReportable(ip, evidence, config, now = Date.now()) {
|
|
16577
|
-
if ((0,
|
|
16655
|
+
if ((0, import_node_net6.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
|
|
16578
16656
|
if (isProtected(ip, config.neverReport)) {
|
|
16579
16657
|
return { reportable: false, reason: "address is in a never-report range (private/CGNAT/reserved/allowlisted)" };
|
|
16580
16658
|
}
|
|
@@ -16723,31 +16801,31 @@ function resolveConfig(section) {
|
|
|
16723
16801
|
}
|
|
16724
16802
|
|
|
16725
16803
|
// src/core/abuse-report-log.ts
|
|
16726
|
-
var
|
|
16727
|
-
var
|
|
16804
|
+
var import_node_fs22 = require("fs");
|
|
16805
|
+
var import_node_path16 = require("path");
|
|
16728
16806
|
var ABUSE_DIRNAME = "abuse-reports";
|
|
16729
16807
|
var LOG_FILE = "reports.jsonl";
|
|
16730
16808
|
function resolveAbuseDir(dir) {
|
|
16731
16809
|
if (dir) return dir;
|
|
16732
16810
|
if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
|
|
16733
|
-
const system = (0,
|
|
16734
|
-
if ((0,
|
|
16735
|
-
return (0,
|
|
16811
|
+
const system = (0, import_node_path16.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
|
|
16812
|
+
if ((0, import_node_fs22.existsSync)(system)) return system;
|
|
16813
|
+
return (0, import_node_path16.join)(PATHS.stateDir, ABUSE_DIRNAME);
|
|
16736
16814
|
}
|
|
16737
16815
|
function logPath(dir) {
|
|
16738
|
-
return (0,
|
|
16816
|
+
return (0, import_node_path16.join)(resolveAbuseDir(dir), LOG_FILE);
|
|
16739
16817
|
}
|
|
16740
16818
|
function appendReport(record, dir) {
|
|
16741
16819
|
const path = logPath(dir);
|
|
16742
|
-
(0,
|
|
16743
|
-
(0,
|
|
16820
|
+
(0, import_node_fs22.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
|
|
16821
|
+
(0, import_node_fs22.appendFileSync)(path, `${JSON.stringify(record)}
|
|
16744
16822
|
`, { mode: 420 });
|
|
16745
16823
|
}
|
|
16746
16824
|
function readReports(dir) {
|
|
16747
16825
|
const path = logPath(dir);
|
|
16748
16826
|
let raw;
|
|
16749
16827
|
try {
|
|
16750
|
-
raw = (0,
|
|
16828
|
+
raw = (0, import_node_fs22.readFileSync)(path, "utf-8");
|
|
16751
16829
|
} catch {
|
|
16752
16830
|
return [];
|
|
16753
16831
|
}
|
|
@@ -16905,18 +16983,25 @@ var AbuseReporter = class {
|
|
|
16905
16983
|
};
|
|
16906
16984
|
|
|
16907
16985
|
// src/daemon/workers/remediation-consumer.ts
|
|
16908
|
-
var
|
|
16986
|
+
var import_node_net8 = require("net");
|
|
16909
16987
|
|
|
16910
16988
|
// src/daemon/workers/allowlist-sync.ts
|
|
16911
|
-
var
|
|
16989
|
+
var import_node_net7 = require("net");
|
|
16912
16990
|
function isAddressOrCidr(value) {
|
|
16913
16991
|
const [network, prefix, extra] = value.split("/");
|
|
16914
|
-
const family = (0,
|
|
16992
|
+
const family = (0, import_node_net7.isIP)(network);
|
|
16915
16993
|
if (family === 0 || extra !== void 0) return false;
|
|
16916
16994
|
if (prefix === void 0) return true;
|
|
16917
16995
|
if (!/^\d{1,3}$/.test(prefix)) return false;
|
|
16918
16996
|
return Number(prefix) <= (family === 4 ? 32 : 128);
|
|
16919
16997
|
}
|
|
16998
|
+
var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
|
|
16999
|
+
function isCloudAllowEntry(value) {
|
|
17000
|
+
if (!isAddressOrCidr(value)) return false;
|
|
17001
|
+
const [network, prefix] = value.split("/");
|
|
17002
|
+
if (prefix === void 0) return true;
|
|
17003
|
+
return Number(prefix) >= CLOUD_MIN_PREFIX[(0, import_node_net7.isIP)(network)];
|
|
17004
|
+
}
|
|
16920
17005
|
var AllowlistSync = class {
|
|
16921
17006
|
constructor(manager, opts) {
|
|
16922
17007
|
this.manager = manager;
|
|
@@ -16952,7 +17037,8 @@ var AllowlistSync = class {
|
|
|
16952
17037
|
for (const entry of entries) {
|
|
16953
17038
|
if (entry.type !== "ip" && entry.type !== "cidr") continue;
|
|
16954
17039
|
const value = String(entry.value ?? "").trim();
|
|
16955
|
-
if (
|
|
17040
|
+
if (isCloudAllowEntry(value)) wanted.add(value);
|
|
17041
|
+
else if (isAddressOrCidr(value)) this.opts.log(`[cloud] org allowlist: ignoring ${value} (wider than /${CLOUD_MIN_PREFIX[(0, import_node_net7.isIP)(value.split("/")[0])]})`);
|
|
16956
17042
|
}
|
|
16957
17043
|
const added2 = [];
|
|
16958
17044
|
const protectedNow = new Set(this.manager.getProtected());
|
|
@@ -17060,7 +17146,7 @@ var RemediationConsumer = class {
|
|
|
17060
17146
|
try {
|
|
17061
17147
|
switch (action.action_type) {
|
|
17062
17148
|
case "block": {
|
|
17063
|
-
if ((0,
|
|
17149
|
+
if ((0, import_node_net8.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
|
|
17064
17150
|
let ttlSeconds = this.manager.status().max_ban_seconds;
|
|
17065
17151
|
if (action.expires_at) {
|
|
17066
17152
|
const until = Date.parse(action.expires_at);
|
|
@@ -17079,7 +17165,7 @@ var RemediationConsumer = class {
|
|
|
17079
17165
|
return { status: "executed", dry_run: result.entry?.dry_run === true, executed_at };
|
|
17080
17166
|
}
|
|
17081
17167
|
case "unblock": {
|
|
17082
|
-
if ((0,
|
|
17168
|
+
if ((0, import_node_net8.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
|
|
17083
17169
|
const wasBanned = this.manager.getBlocklist().some((b) => b.ip === target);
|
|
17084
17170
|
const result = await this.manager.unban(target, {
|
|
17085
17171
|
forget: true,
|
|
@@ -17092,13 +17178,16 @@ var RemediationConsumer = class {
|
|
|
17092
17178
|
return { status: "executed", dry_run: this.manager.status().dry_run, executed_at };
|
|
17093
17179
|
}
|
|
17094
17180
|
case "allowlist_add":
|
|
17095
|
-
if (!
|
|
17181
|
+
if (!isCloudAllowEntry(target)) return failed(`not an IP address or CIDR the dashboard may protect: ${target}`);
|
|
17096
17182
|
this.manager.addToAllowlist(target);
|
|
17097
17183
|
return { status: "executed", executed_at };
|
|
17098
17184
|
case "allowlist_remove":
|
|
17099
17185
|
if (DEFAULT_PROTECTED.includes(target)) {
|
|
17100
17186
|
return failed(`${target} is a built-in protected range and cannot be removed`);
|
|
17101
17187
|
}
|
|
17188
|
+
if (this.manager.isPinned(target)) {
|
|
17189
|
+
return failed(`${target} is protected by this server's own configuration and cannot be removed from the dashboard`);
|
|
17190
|
+
}
|
|
17102
17191
|
this.manager.removeFromAllowlist(target);
|
|
17103
17192
|
return { status: "executed", executed_at };
|
|
17104
17193
|
case "restart": {
|
|
@@ -17131,8 +17220,8 @@ var RemediationConsumer = class {
|
|
|
17131
17220
|
|
|
17132
17221
|
// src/daemon/workers/auto-update.ts
|
|
17133
17222
|
var import_node_child_process5 = require("child_process");
|
|
17134
|
-
var
|
|
17135
|
-
var
|
|
17223
|
+
var import_node_fs23 = require("fs");
|
|
17224
|
+
var import_node_path17 = require("path");
|
|
17136
17225
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
17137
17226
|
var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
|
|
17138
17227
|
var DEFAULT_INTERVAL_MS = 6 * 36e5;
|
|
@@ -17175,12 +17264,12 @@ function pickUpdate(doc, current, opts) {
|
|
|
17175
17264
|
return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
|
|
17176
17265
|
}
|
|
17177
17266
|
function installPlan(opts) {
|
|
17178
|
-
const expected = `${
|
|
17267
|
+
const expected = `${import_node_path17.sep}lib${import_node_path17.sep}node_modules${import_node_path17.sep}@profullstack${import_node_path17.sep}threatcrush`;
|
|
17179
17268
|
if (!opts.pkgRoot.endsWith(expected)) {
|
|
17180
17269
|
return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
|
|
17181
17270
|
}
|
|
17182
|
-
const nodeBin = (0,
|
|
17183
|
-
const npm = (0,
|
|
17271
|
+
const nodeBin = (0, import_node_path17.dirname)(opts.execPath);
|
|
17272
|
+
const npm = (0, import_node_path17.join)(nodeBin, "npm");
|
|
17184
17273
|
if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
|
|
17185
17274
|
if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
|
|
17186
17275
|
const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
|
|
@@ -17212,10 +17301,10 @@ function installPlan(opts) {
|
|
|
17212
17301
|
}
|
|
17213
17302
|
function ownerOf(path, passwd = "/etc/passwd") {
|
|
17214
17303
|
try {
|
|
17215
|
-
const st = (0,
|
|
17304
|
+
const st = (0, import_node_fs23.statSync)(path);
|
|
17216
17305
|
let home = st.uid === 0 ? "/root" : "";
|
|
17217
17306
|
try {
|
|
17218
|
-
for (const line of (0,
|
|
17307
|
+
for (const line of (0, import_node_fs23.readFileSync)(passwd, "utf8").split("\n")) {
|
|
17219
17308
|
const f = line.split(":");
|
|
17220
17309
|
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
17221
17310
|
}
|
|
@@ -17237,7 +17326,7 @@ function updateSettings(section, env2 = process.env) {
|
|
|
17237
17326
|
};
|
|
17238
17327
|
}
|
|
17239
17328
|
function defaultRun(argv, env2) {
|
|
17240
|
-
return new Promise((
|
|
17329
|
+
return new Promise((resolve4) => {
|
|
17241
17330
|
const child = (0, import_node_child_process5.spawn)(argv[0], argv.slice(1), {
|
|
17242
17331
|
env: { ...process.env, ...env2 },
|
|
17243
17332
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -17248,8 +17337,8 @@ function defaultRun(argv, env2) {
|
|
|
17248
17337
|
};
|
|
17249
17338
|
child.stdout?.on("data", keep);
|
|
17250
17339
|
child.stderr?.on("data", keep);
|
|
17251
|
-
child.on("error", (err) =>
|
|
17252
|
-
child.on("close", (code) =>
|
|
17340
|
+
child.on("error", (err) => resolve4({ code: -1, output: err.message }));
|
|
17341
|
+
child.on("close", (code) => resolve4({ code: code ?? -1, output }));
|
|
17253
17342
|
});
|
|
17254
17343
|
}
|
|
17255
17344
|
var AutoUpdate = class {
|
|
@@ -17325,7 +17414,7 @@ var AutoUpdate = class {
|
|
|
17325
17414
|
uid: process.getuid?.() ?? -1,
|
|
17326
17415
|
owner: ownerOf(this.opts.pkgRoot),
|
|
17327
17416
|
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
17328
|
-
npmExists:
|
|
17417
|
+
npmExists: import_node_fs23.existsSync
|
|
17329
17418
|
});
|
|
17330
17419
|
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
17331
17420
|
this.recordAttempt(target);
|
|
@@ -17361,7 +17450,7 @@ var AutoUpdate = class {
|
|
|
17361
17450
|
}
|
|
17362
17451
|
lastAttempt() {
|
|
17363
17452
|
try {
|
|
17364
|
-
const v = JSON.parse((0,
|
|
17453
|
+
const v = JSON.parse((0, import_node_fs23.readFileSync)(this.opts.statePath, "utf8"));
|
|
17365
17454
|
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
17366
17455
|
} catch {
|
|
17367
17456
|
return null;
|
|
@@ -17369,7 +17458,7 @@ var AutoUpdate = class {
|
|
|
17369
17458
|
}
|
|
17370
17459
|
recordAttempt(version) {
|
|
17371
17460
|
try {
|
|
17372
|
-
(0,
|
|
17461
|
+
(0, import_node_fs23.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
17373
17462
|
} catch (err) {
|
|
17374
17463
|
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
17375
17464
|
}
|
|
@@ -17378,9 +17467,9 @@ var AutoUpdate = class {
|
|
|
17378
17467
|
|
|
17379
17468
|
// src/daemon/workers/threat-feeds.ts
|
|
17380
17469
|
var import_node_child_process6 = require("child_process");
|
|
17381
|
-
var
|
|
17382
|
-
var
|
|
17383
|
-
var
|
|
17470
|
+
var import_node_fs24 = require("fs");
|
|
17471
|
+
var import_node_path18 = require("path");
|
|
17472
|
+
var import_node_net9 = require("net");
|
|
17384
17473
|
var EGRESS_TABLE = "threatcrush_egress";
|
|
17385
17474
|
var DEFAULT_REFRESH_MS = 36e5;
|
|
17386
17475
|
var POLL_MS = 15e3;
|
|
@@ -17398,8 +17487,8 @@ function threatFeedSettings(section) {
|
|
|
17398
17487
|
};
|
|
17399
17488
|
}
|
|
17400
17489
|
function egressRuleset(ips) {
|
|
17401
|
-
const v4 = ips.filter((ip) => (0,
|
|
17402
|
-
const v6 = ips.filter((ip) => (0,
|
|
17490
|
+
const v4 = ips.filter((ip) => (0, import_node_net9.isIP)(ip) === 4);
|
|
17491
|
+
const v6 = ips.filter((ip) => (0, import_node_net9.isIP)(ip) === 6);
|
|
17403
17492
|
const set = (name, type, items) => ` set ${name} { type ${type};${items.length ? ` elements = { ${items.join(", ")} }` : ""} }`;
|
|
17404
17493
|
const chain = (name, hook) => [
|
|
17405
17494
|
` chain ${name} {`,
|
|
@@ -17424,7 +17513,7 @@ function splitAddr(addr) {
|
|
|
17424
17513
|
const m = /^\[?(.+?)\]?:(\d+|\*)$/.exec(addr);
|
|
17425
17514
|
if (!m) return null;
|
|
17426
17515
|
const ip = m[1].replace(/%.*$/, "").replace(/^::ffff:/i, "");
|
|
17427
|
-
return (0,
|
|
17516
|
+
return (0, import_node_net9.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
|
|
17428
17517
|
}
|
|
17429
17518
|
function parseSs(text) {
|
|
17430
17519
|
const out = [];
|
|
@@ -17550,14 +17639,14 @@ var ThreatFeeds = class {
|
|
|
17550
17639
|
*/
|
|
17551
17640
|
writeResolverFiles(set) {
|
|
17552
17641
|
const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
|
|
17553
|
-
const dir = this.opts.resolverDir ?? (0,
|
|
17642
|
+
const dir = this.opts.resolverDir ?? (0, import_node_path18.dirname)(this.opts.cachePath);
|
|
17554
17643
|
const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
|
|
17555
17644
|
const write = (name, content) => {
|
|
17556
|
-
const path = (0,
|
|
17645
|
+
const path = (0, import_node_path18.join)(dir, name);
|
|
17557
17646
|
if (this.resolverWritten.get(name) === content) return false;
|
|
17558
17647
|
try {
|
|
17559
|
-
(0,
|
|
17560
|
-
(0,
|
|
17648
|
+
(0, import_node_fs24.writeFileSync)(`${path}.tmp`, content);
|
|
17649
|
+
(0, import_node_fs24.renameSync)(`${path}.tmp`, path);
|
|
17561
17650
|
this.resolverWritten.set(name, content);
|
|
17562
17651
|
return true;
|
|
17563
17652
|
} catch (err) {
|
|
@@ -17568,11 +17657,11 @@ var ThreatFeeds = class {
|
|
|
17568
17657
|
const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
|
|
17569
17658
|
const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
|
|
17570
17659
|
const via = [];
|
|
17571
|
-
if ((0,
|
|
17660
|
+
if ((0, import_node_fs24.existsSync)(hooks.dnsmasq)) {
|
|
17572
17661
|
via.push("dnsmasq");
|
|
17573
17662
|
if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
|
|
17574
17663
|
}
|
|
17575
|
-
if ((0,
|
|
17664
|
+
if ((0, import_node_fs24.existsSync)(hooks.unbound)) {
|
|
17576
17665
|
via.push("unbound");
|
|
17577
17666
|
if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
|
|
17578
17667
|
this.run("systemctl", ["reload", "unbound.service"]);
|
|
@@ -17633,8 +17722,8 @@ var ThreatFeeds = class {
|
|
|
17633
17722
|
};
|
|
17634
17723
|
|
|
17635
17724
|
// src/daemon/workers/privilege-watch.ts
|
|
17636
|
-
var
|
|
17637
|
-
var
|
|
17725
|
+
var import_node_fs25 = require("fs");
|
|
17726
|
+
var import_node_path19 = require("path");
|
|
17638
17727
|
var import_node_child_process7 = require("child_process");
|
|
17639
17728
|
|
|
17640
17729
|
// src/core/privileges/index.ts
|
|
@@ -17825,31 +17914,31 @@ function countryName(code) {
|
|
|
17825
17914
|
var fsIO = {
|
|
17826
17915
|
readFile: (p) => {
|
|
17827
17916
|
try {
|
|
17828
|
-
return (0,
|
|
17917
|
+
return (0, import_node_fs25.readFileSync)(p, "utf-8");
|
|
17829
17918
|
} catch {
|
|
17830
17919
|
return null;
|
|
17831
17920
|
}
|
|
17832
17921
|
},
|
|
17833
17922
|
readDir: (p) => {
|
|
17834
17923
|
try {
|
|
17835
|
-
return (0,
|
|
17924
|
+
return (0, import_node_fs25.readdirSync)(p);
|
|
17836
17925
|
} catch {
|
|
17837
17926
|
return null;
|
|
17838
17927
|
}
|
|
17839
17928
|
},
|
|
17840
|
-
exists: (p) => (0,
|
|
17929
|
+
exists: (p) => (0, import_node_fs25.existsSync)(p)
|
|
17841
17930
|
};
|
|
17842
17931
|
function readJson(path) {
|
|
17843
17932
|
try {
|
|
17844
|
-
return JSON.parse((0,
|
|
17933
|
+
return JSON.parse((0, import_node_fs25.readFileSync)(path, "utf-8"));
|
|
17845
17934
|
} catch {
|
|
17846
17935
|
return null;
|
|
17847
17936
|
}
|
|
17848
17937
|
}
|
|
17849
17938
|
function writeJson(path, value) {
|
|
17850
|
-
(0,
|
|
17851
|
-
(0,
|
|
17852
|
-
(0,
|
|
17939
|
+
(0, import_node_fs25.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
|
|
17940
|
+
(0, import_node_fs25.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
|
|
17941
|
+
(0, import_node_fs25.renameSync)(`${path}.tmp`, path);
|
|
17853
17942
|
}
|
|
17854
17943
|
function defaultRun3(cmd, args) {
|
|
17855
17944
|
const res = (0, import_node_child_process7.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -18005,7 +18094,7 @@ var PrivilegeWatch = class {
|
|
|
18005
18094
|
* raised a "new country" alert on its first run; on dev2 it did, at once.
|
|
18006
18095
|
*/
|
|
18007
18096
|
async backfillLogins() {
|
|
18008
|
-
if ((0,
|
|
18097
|
+
if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
|
|
18009
18098
|
const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
|
|
18010
18099
|
const byUser = parseAcceptedLogins(out ?? "");
|
|
18011
18100
|
const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
|
|
@@ -18018,7 +18107,7 @@ var PrivilegeWatch = class {
|
|
|
18018
18107
|
return;
|
|
18019
18108
|
}
|
|
18020
18109
|
}
|
|
18021
|
-
if ((0,
|
|
18110
|
+
if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
|
|
18022
18111
|
const at = this.now().toISOString();
|
|
18023
18112
|
const history = {};
|
|
18024
18113
|
for (const [user, userIps] of byUser) {
|
|
@@ -18230,8 +18319,8 @@ var RuleEngine = class {
|
|
|
18230
18319
|
};
|
|
18231
18320
|
|
|
18232
18321
|
// src/daemon/rules/loader.ts
|
|
18233
|
-
var
|
|
18234
|
-
var
|
|
18322
|
+
var import_node_fs26 = require("fs");
|
|
18323
|
+
var import_node_path20 = require("path");
|
|
18235
18324
|
|
|
18236
18325
|
// src/daemon/rules/default-rules.ts
|
|
18237
18326
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -18701,11 +18790,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
18701
18790
|
function loadAllRules(customDir) {
|
|
18702
18791
|
const rules = [...DEFAULT_RULES];
|
|
18703
18792
|
const dir = customDir || RULES_DIR;
|
|
18704
|
-
if ((0,
|
|
18705
|
-
const files = (0,
|
|
18793
|
+
if ((0, import_node_fs26.existsSync)(dir)) {
|
|
18794
|
+
const files = (0, import_node_fs26.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
18706
18795
|
for (const file of files) {
|
|
18707
18796
|
try {
|
|
18708
|
-
const raw = (0,
|
|
18797
|
+
const raw = (0, import_node_fs26.readFileSync)((0, import_node_path20.join)(dir, file), "utf-8");
|
|
18709
18798
|
const parsed = JSON.parse(raw);
|
|
18710
18799
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
18711
18800
|
for (const rule of customRules) {
|
|
@@ -18737,23 +18826,23 @@ function loadAllRules(customDir) {
|
|
|
18737
18826
|
|
|
18738
18827
|
// src/daemon/firewall/adapters.ts
|
|
18739
18828
|
var import_node_child_process8 = require("child_process");
|
|
18740
|
-
var
|
|
18741
|
-
var
|
|
18742
|
-
var
|
|
18829
|
+
var import_node_fs27 = require("fs");
|
|
18830
|
+
var import_node_path21 = require("path");
|
|
18831
|
+
var import_node_net10 = require("net");
|
|
18743
18832
|
function assertValidFirewallIp(ip) {
|
|
18744
|
-
if ((0,
|
|
18833
|
+
if ((0, import_node_net10.isIP)(ip) !== 4) {
|
|
18745
18834
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
18746
18835
|
}
|
|
18747
18836
|
}
|
|
18748
18837
|
function assertBannableIp(ip) {
|
|
18749
|
-
if ((0,
|
|
18838
|
+
if ((0, import_node_net10.isIP)(ip) === 0) {
|
|
18750
18839
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
18751
18840
|
}
|
|
18752
18841
|
}
|
|
18753
18842
|
function writeIfAbsent(path, contents) {
|
|
18754
|
-
(0,
|
|
18843
|
+
(0, import_node_fs27.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
|
|
18755
18844
|
try {
|
|
18756
|
-
(0,
|
|
18845
|
+
(0, import_node_fs27.writeFileSync)(path, contents, { flag: "wx" });
|
|
18757
18846
|
} catch (err) {
|
|
18758
18847
|
if (err.code !== "EEXIST") throw err;
|
|
18759
18848
|
}
|
|
@@ -18852,7 +18941,7 @@ var Fail2banAdapter = class {
|
|
|
18852
18941
|
const status = this.client(["status", this.jail]);
|
|
18853
18942
|
const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
18854
18943
|
if (!line) return [];
|
|
18855
|
-
return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
18944
|
+
return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net10.isIP)(s) !== 0);
|
|
18856
18945
|
} catch {
|
|
18857
18946
|
return [];
|
|
18858
18947
|
}
|
|
@@ -18862,10 +18951,10 @@ var Fail2banAdapter = class {
|
|
|
18862
18951
|
function parseBannedList(output) {
|
|
18863
18952
|
const found = [];
|
|
18864
18953
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
18865
|
-
if ((0,
|
|
18954
|
+
if ((0, import_node_net10.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
18866
18955
|
}
|
|
18867
18956
|
if (found.length > 0) return found;
|
|
18868
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
18957
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net10.isIP)(s) !== 0);
|
|
18869
18958
|
}
|
|
18870
18959
|
var NftablesAdapter = class {
|
|
18871
18960
|
name = "nftables";
|
|
@@ -19012,9 +19101,9 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
19012
19101
|
}
|
|
19013
19102
|
|
|
19014
19103
|
// src/daemon/firewall/remediation.ts
|
|
19015
|
-
var
|
|
19104
|
+
var import_node_fs28 = require("fs");
|
|
19016
19105
|
var import_node_child_process9 = require("child_process");
|
|
19017
|
-
var
|
|
19106
|
+
var import_node_net11 = require("net");
|
|
19018
19107
|
|
|
19019
19108
|
// src/daemon/firewall/crawlers.ts
|
|
19020
19109
|
var import_node_dns = require("dns");
|
|
@@ -19081,19 +19170,19 @@ var defaultDiscovery = {
|
|
|
19081
19170
|
const snapshot = takeSnapshot({
|
|
19082
19171
|
readFile: (p) => {
|
|
19083
19172
|
try {
|
|
19084
|
-
return (0,
|
|
19173
|
+
return (0, import_node_fs28.readFileSync)(p, "utf-8");
|
|
19085
19174
|
} catch {
|
|
19086
19175
|
return null;
|
|
19087
19176
|
}
|
|
19088
19177
|
},
|
|
19089
19178
|
readDir: (p) => {
|
|
19090
19179
|
try {
|
|
19091
|
-
return (0,
|
|
19180
|
+
return (0, import_node_fs28.readdirSync)(p);
|
|
19092
19181
|
} catch {
|
|
19093
19182
|
return null;
|
|
19094
19183
|
}
|
|
19095
19184
|
},
|
|
19096
|
-
exists: (p) => (0,
|
|
19185
|
+
exists: (p) => (0, import_node_fs28.existsSync)(p)
|
|
19097
19186
|
});
|
|
19098
19187
|
const out = /* @__PURE__ */ new Set();
|
|
19099
19188
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -19101,12 +19190,12 @@ var defaultDiscovery = {
|
|
|
19101
19190
|
}
|
|
19102
19191
|
return out;
|
|
19103
19192
|
},
|
|
19104
|
-
keyLoginJournal: (sinceSeconds) => new Promise((
|
|
19193
|
+
keyLoginJournal: (sinceSeconds) => new Promise((resolve4) => {
|
|
19105
19194
|
(0, import_node_child_process9.execFile)(
|
|
19106
19195
|
"journalctl",
|
|
19107
19196
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
19108
19197
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
19109
|
-
(_err, stdout) =>
|
|
19198
|
+
(_err, stdout) => resolve4(stdout ?? "")
|
|
19110
19199
|
);
|
|
19111
19200
|
})
|
|
19112
19201
|
};
|
|
@@ -19141,6 +19230,7 @@ var RemediationManager = class {
|
|
|
19141
19230
|
this.config.allowlist = [...this.config.allowlist];
|
|
19142
19231
|
this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
|
|
19143
19232
|
for (const gateway of defaultGateways()) this.protectedList.push(gateway);
|
|
19233
|
+
this.pinned = new Set(this.protectedList);
|
|
19144
19234
|
if (this.adapter.enforces === false) this.config.dry_run = true;
|
|
19145
19235
|
this.loadState();
|
|
19146
19236
|
this.refreshSshProtection();
|
|
@@ -19156,6 +19246,12 @@ var RemediationManager = class {
|
|
|
19156
19246
|
blocklist = [];
|
|
19157
19247
|
strikes = {};
|
|
19158
19248
|
protectedList = [];
|
|
19249
|
+
/**
|
|
19250
|
+
* What was protected at start: built-ins, shared infrastructure, the
|
|
19251
|
+
* operator's `[remediation] allowlist`, default gateways. The dashboard may
|
|
19252
|
+
* add to the protected set but never take these out of it.
|
|
19253
|
+
*/
|
|
19254
|
+
pinned = /* @__PURE__ */ new Set();
|
|
19159
19255
|
/** Operator address → last time seen (ms), persisted. */
|
|
19160
19256
|
operators = {};
|
|
19161
19257
|
expiryTimer = null;
|
|
@@ -19228,7 +19324,7 @@ var RemediationManager = class {
|
|
|
19228
19324
|
if (remediation?.action !== "block") return;
|
|
19229
19325
|
}
|
|
19230
19326
|
const ip = event.source_ip;
|
|
19231
|
-
if (!ip || (0,
|
|
19327
|
+
if (!ip || (0, import_node_net11.isIP)(ip) === 0) return;
|
|
19232
19328
|
if (this.isAllowlisted(ip)) return;
|
|
19233
19329
|
if (this.blocklist.some((b) => b.ip === ip)) return;
|
|
19234
19330
|
if (this.config.spare_verified_crawlers) {
|
|
@@ -19247,7 +19343,7 @@ var RemediationManager = class {
|
|
|
19247
19343
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
19248
19344
|
*/
|
|
19249
19345
|
async ban(ip, reason, opts = {}) {
|
|
19250
|
-
if ((0,
|
|
19346
|
+
if ((0, import_node_net11.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
19251
19347
|
if (this.isAllowlisted(ip)) {
|
|
19252
19348
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
19253
19349
|
}
|
|
@@ -19404,6 +19500,10 @@ var RemediationManager = class {
|
|
|
19404
19500
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
19405
19501
|
if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
|
|
19406
19502
|
}
|
|
19503
|
+
/** Protected since start (built-in, shared infrastructure, operator config, gateway): not removable from the cloud. */
|
|
19504
|
+
isPinned(ip) {
|
|
19505
|
+
return this.pinned.has(ip);
|
|
19506
|
+
}
|
|
19407
19507
|
removeFromAllowlist(ip) {
|
|
19408
19508
|
if (DEFAULT_PROTECTED.includes(ip)) return;
|
|
19409
19509
|
this.protectedList = this.protectedList.filter((a) => a !== ip);
|
|
@@ -19510,7 +19610,7 @@ var RemediationManager = class {
|
|
|
19510
19610
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
19511
19611
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
19512
19612
|
for (const [ip, at] of Object.entries(saved)) {
|
|
19513
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
19613
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net11.isIP)(ip)) continue;
|
|
19514
19614
|
this.operators[ip] = at;
|
|
19515
19615
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
19516
19616
|
}
|
|
@@ -19534,7 +19634,7 @@ var RemediationManager = class {
|
|
|
19534
19634
|
}
|
|
19535
19635
|
logLine(line) {
|
|
19536
19636
|
try {
|
|
19537
|
-
(0,
|
|
19637
|
+
(0, import_node_fs28.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
19538
19638
|
`);
|
|
19539
19639
|
} catch {
|
|
19540
19640
|
}
|
|
@@ -19573,13 +19673,13 @@ function remediationSettings(section) {
|
|
|
19573
19673
|
}
|
|
19574
19674
|
|
|
19575
19675
|
// src/daemon/watchdog-service.ts
|
|
19576
|
-
var
|
|
19577
|
-
var
|
|
19676
|
+
var import_node_fs30 = require("fs");
|
|
19677
|
+
var import_node_path23 = require("path");
|
|
19578
19678
|
|
|
19579
19679
|
// src/core/watchdog.ts
|
|
19580
|
-
var
|
|
19680
|
+
var import_node_fs29 = require("fs");
|
|
19581
19681
|
var import_node_crypto7 = require("crypto");
|
|
19582
|
-
var
|
|
19682
|
+
var import_node_path22 = require("path");
|
|
19583
19683
|
var WATCHDOG_DIRNAME = "watchdog";
|
|
19584
19684
|
var LOG_FILE2 = "attacks.jsonl";
|
|
19585
19685
|
var ROTATED_FILE = "attacks.1.jsonl";
|
|
@@ -19668,12 +19768,12 @@ var WatchdogLog = class {
|
|
|
19668
19768
|
stats = { logged: 0, answered: 0, errored: 0 };
|
|
19669
19769
|
constructor(dir, options = {}) {
|
|
19670
19770
|
this.dir = dir;
|
|
19671
|
-
this.file = (0,
|
|
19771
|
+
this.file = (0, import_node_path22.join)(dir, LOG_FILE2);
|
|
19672
19772
|
this.shareGid = options.shareGid;
|
|
19673
|
-
(0,
|
|
19773
|
+
(0, import_node_fs29.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
|
|
19674
19774
|
if (this.shareGid !== void 0) {
|
|
19675
|
-
(0,
|
|
19676
|
-
(0,
|
|
19775
|
+
(0, import_node_fs29.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
|
|
19776
|
+
(0, import_node_fs29.chmodSync)(dir, 1528);
|
|
19677
19777
|
}
|
|
19678
19778
|
for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
|
|
19679
19779
|
}
|
|
@@ -19702,16 +19802,16 @@ var WatchdogLog = class {
|
|
|
19702
19802
|
const chunk = this.buffer.join("\n") + "\n";
|
|
19703
19803
|
this.buffer = [];
|
|
19704
19804
|
try {
|
|
19705
|
-
if ((0,
|
|
19706
|
-
(0,
|
|
19805
|
+
if ((0, import_node_fs29.statSync)(this.file).size > ROTATE_BYTES) {
|
|
19806
|
+
(0, import_node_fs29.renameSync)(this.file, (0, import_node_path22.join)(this.dir, ROTATED_FILE));
|
|
19707
19807
|
}
|
|
19708
19808
|
} catch {
|
|
19709
19809
|
}
|
|
19710
|
-
(0,
|
|
19810
|
+
(0, import_node_fs29.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
|
|
19711
19811
|
if (this.shareGid !== void 0) {
|
|
19712
19812
|
try {
|
|
19713
|
-
(0,
|
|
19714
|
-
(0,
|
|
19813
|
+
(0, import_node_fs29.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
|
|
19814
|
+
(0, import_node_fs29.chmodSync)(this.file, 432);
|
|
19715
19815
|
} catch {
|
|
19716
19816
|
}
|
|
19717
19817
|
}
|
|
@@ -19732,21 +19832,21 @@ function parseLines(text) {
|
|
|
19732
19832
|
function readTail(file, bytes) {
|
|
19733
19833
|
let fd;
|
|
19734
19834
|
try {
|
|
19735
|
-
fd = (0,
|
|
19835
|
+
fd = (0, import_node_fs29.openSync)(file, "r");
|
|
19736
19836
|
} catch (err) {
|
|
19737
19837
|
if (err.code === "ENOENT") return [];
|
|
19738
19838
|
throw err;
|
|
19739
19839
|
}
|
|
19740
19840
|
try {
|
|
19741
|
-
const size = (0,
|
|
19841
|
+
const size = (0, import_node_fs29.fstatSync)(fd).size;
|
|
19742
19842
|
const start = Math.max(0, size - bytes);
|
|
19743
19843
|
const buf = Buffer.alloc(size - start);
|
|
19744
|
-
(0,
|
|
19844
|
+
(0, import_node_fs29.readSync)(fd, buf, 0, buf.length, start);
|
|
19745
19845
|
let text = buf.toString("utf8");
|
|
19746
19846
|
if (start > 0) text = text.slice(text.indexOf("\n") + 1);
|
|
19747
19847
|
return parseLines(text);
|
|
19748
19848
|
} finally {
|
|
19749
|
-
(0,
|
|
19849
|
+
(0, import_node_fs29.closeSync)(fd);
|
|
19750
19850
|
}
|
|
19751
19851
|
}
|
|
19752
19852
|
|
|
@@ -19755,13 +19855,13 @@ function defaultShareGid() {
|
|
|
19755
19855
|
const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
19756
19856
|
if (!isRoot2) return void 0;
|
|
19757
19857
|
try {
|
|
19758
|
-
return (0,
|
|
19858
|
+
return (0, import_node_fs30.statSync)("/var/log/auth.log").gid;
|
|
19759
19859
|
} catch {
|
|
19760
19860
|
return void 0;
|
|
19761
19861
|
}
|
|
19762
19862
|
}
|
|
19763
19863
|
function startWatchdog(opts) {
|
|
19764
|
-
const dir = opts.config?.dir ?? (0,
|
|
19864
|
+
const dir = opts.config?.dir ?? (0, import_node_path23.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
19765
19865
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
19766
19866
|
if (opts.config?.enabled === false) {
|
|
19767
19867
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -19868,7 +19968,7 @@ function daemonNodeProblem(version) {
|
|
|
19868
19968
|
// src/daemon/index.ts
|
|
19869
19969
|
function readVersion2() {
|
|
19870
19970
|
try {
|
|
19871
|
-
const pkg = JSON.parse((0,
|
|
19971
|
+
const pkg = JSON.parse((0, import_node_fs31.readFileSync)((0, import_node_path24.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
19872
19972
|
return pkg.version || "0.0.0";
|
|
19873
19973
|
} catch {
|
|
19874
19974
|
return "0.0.0";
|
|
@@ -19877,7 +19977,7 @@ function readVersion2() {
|
|
|
19877
19977
|
async function runHardeningChecks() {
|
|
19878
19978
|
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
|
|
19879
19979
|
process.execPath,
|
|
19880
|
-
[(0,
|
|
19980
|
+
[(0, import_node_path24.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
19881
19981
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
19882
19982
|
);
|
|
19883
19983
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -19891,7 +19991,7 @@ async function runHardeningChecks() {
|
|
|
19891
19991
|
async function runPatchCheck() {
|
|
19892
19992
|
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
|
|
19893
19993
|
process.execPath,
|
|
19894
|
-
[(0,
|
|
19994
|
+
[(0, import_node_path24.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
19895
19995
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
19896
19996
|
);
|
|
19897
19997
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -19899,7 +19999,7 @@ async function runPatchCheck() {
|
|
|
19899
19999
|
}
|
|
19900
20000
|
function logLine(line) {
|
|
19901
20001
|
try {
|
|
19902
|
-
(0,
|
|
20002
|
+
(0, import_node_fs31.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
19903
20003
|
`);
|
|
19904
20004
|
} catch {
|
|
19905
20005
|
}
|
|
@@ -19941,7 +20041,7 @@ async function runDaemon() {
|
|
|
19941
20041
|
} catch (err) {
|
|
19942
20042
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
19943
20043
|
}
|
|
19944
|
-
const config = loadConfig((0,
|
|
20044
|
+
const config = loadConfig((0, import_node_fs31.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
19945
20045
|
configureAttackDetection(config.detection);
|
|
19946
20046
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
19947
20047
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -20005,7 +20105,7 @@ async function runDaemon() {
|
|
|
20005
20105
|
const threatFeeds = new ThreatFeeds({
|
|
20006
20106
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
20007
20107
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
20008
|
-
cachePath: (0,
|
|
20108
|
+
cachePath: (0, import_node_path24.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
20009
20109
|
bus,
|
|
20010
20110
|
log: logLine
|
|
20011
20111
|
});
|
|
@@ -20013,14 +20113,18 @@ async function runDaemon() {
|
|
|
20013
20113
|
const privilegeWatch = new PrivilegeWatch({
|
|
20014
20114
|
settings: privilegeSettings(config.privileged),
|
|
20015
20115
|
bus,
|
|
20016
|
-
snapshotPath: (0,
|
|
20017
|
-
loginsPath: (0,
|
|
20018
|
-
cursorPath: (0,
|
|
20116
|
+
snapshotPath: (0, import_node_path24.join)(PATHS.stateDir, "privileges.json"),
|
|
20117
|
+
loginsPath: (0, import_node_path24.join)(PATHS.stateDir, "login-countries.json"),
|
|
20118
|
+
cursorPath: (0, import_node_path24.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
20019
20119
|
log: logLine
|
|
20020
20120
|
});
|
|
20021
20121
|
privilegeWatch.start();
|
|
20022
20122
|
new AlertDispatcher(bus, config);
|
|
20023
|
-
const runsWorker = new RunsWorker(bus
|
|
20123
|
+
const runsWorker = new RunsWorker(bus, {
|
|
20124
|
+
enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
|
|
20125
|
+
scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
|
|
20126
|
+
log: logLine
|
|
20127
|
+
});
|
|
20024
20128
|
try {
|
|
20025
20129
|
await runsWorker.start();
|
|
20026
20130
|
} catch (err) {
|
|
@@ -20039,7 +20143,7 @@ async function runDaemon() {
|
|
|
20039
20143
|
version,
|
|
20040
20144
|
hostname: (0, import_node_os5.hostname)(),
|
|
20041
20145
|
minSeverity,
|
|
20042
|
-
spoolPath: (0,
|
|
20146
|
+
spoolPath: (0, import_node_path24.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
20043
20147
|
log: logLine,
|
|
20044
20148
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
20045
20149
|
runHardening: runHardeningChecks
|
|
@@ -20063,8 +20167,8 @@ async function runDaemon() {
|
|
|
20063
20167
|
const autoUpdate = autoUpdateRef = new AutoUpdate({
|
|
20064
20168
|
version,
|
|
20065
20169
|
settings: updateSettings(config.update),
|
|
20066
|
-
pkgRoot: (0,
|
|
20067
|
-
statePath: (0,
|
|
20170
|
+
pkgRoot: (0, import_node_path24.join)(__dirname, ".."),
|
|
20171
|
+
statePath: (0, import_node_path24.join)(PATHS.stateDir, "auto-update.json"),
|
|
20068
20172
|
bus,
|
|
20069
20173
|
log: logLine,
|
|
20070
20174
|
restartDaemon
|