@profullstack/threatcrush 0.13.64 → 0.13.65
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 +14 -1
- package/dist/daemon.js +720 -126
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +851 -251
- package/dist/index.js.map +1 -1
- package/dist/systemd/threatcrushd.service +5 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23425,9 +23425,9 @@ var source_default = chalk;
|
|
|
23425
23425
|
|
|
23426
23426
|
// src/index.ts
|
|
23427
23427
|
var import_readline = __toESM(require("readline"));
|
|
23428
|
-
var
|
|
23429
|
-
var
|
|
23430
|
-
var
|
|
23428
|
+
var import_node_child_process26 = require("child_process");
|
|
23429
|
+
var import_node_fs61 = require("fs");
|
|
23430
|
+
var import_node_path47 = require("path");
|
|
23431
23431
|
var import_node_os18 = require("os");
|
|
23432
23432
|
|
|
23433
23433
|
// src/commands/monitor.ts
|
|
@@ -30243,6 +30243,39 @@ function parseNginxLog(line2) {
|
|
|
30243
30243
|
fields
|
|
30244
30244
|
};
|
|
30245
30245
|
}
|
|
30246
|
+
function parseCaddyAccessLog(line2) {
|
|
30247
|
+
let entry;
|
|
30248
|
+
try {
|
|
30249
|
+
entry = JSON.parse(line2);
|
|
30250
|
+
} catch {
|
|
30251
|
+
return null;
|
|
30252
|
+
}
|
|
30253
|
+
if (entry.logger !== "http.log.access") return null;
|
|
30254
|
+
const request = entry.request;
|
|
30255
|
+
if (!request || typeof request !== "object" || Array.isArray(request)) return null;
|
|
30256
|
+
const req = request;
|
|
30257
|
+
const host = typeof req.host === "string" ? req.host.toLowerCase() : "";
|
|
30258
|
+
if (host !== "agent.database.pit.world") return null;
|
|
30259
|
+
const required = [req.method, req.uri, entry.status, entry.size];
|
|
30260
|
+
if (required.some((value) => typeof value !== "string" && typeof value !== "number")) return null;
|
|
30261
|
+
const timestamp = typeof entry.ts === "number" ? new Date(entry.ts * 1e3) : /* @__PURE__ */ new Date();
|
|
30262
|
+
return {
|
|
30263
|
+
timestamp: Number.isNaN(timestamp.getTime()) ? /* @__PURE__ */ new Date() : timestamp,
|
|
30264
|
+
raw: line2,
|
|
30265
|
+
source: "nginx",
|
|
30266
|
+
fields: {
|
|
30267
|
+
ip: typeof req.client_ip === "string" ? req.client_ip : typeof req.remote_ip === "string" ? req.remote_ip : "",
|
|
30268
|
+
method: String(req.method),
|
|
30269
|
+
path: String(req.uri).split("?")[0],
|
|
30270
|
+
protocol: typeof req.proto === "string" ? req.proto : "",
|
|
30271
|
+
status: String(entry.status),
|
|
30272
|
+
size: String(entry.size),
|
|
30273
|
+
referer: "",
|
|
30274
|
+
user_agent: "",
|
|
30275
|
+
host
|
|
30276
|
+
}
|
|
30277
|
+
};
|
|
30278
|
+
}
|
|
30246
30279
|
function parseAuthLog(line2) {
|
|
30247
30280
|
const match = line2.match(AUTH_REGEX);
|
|
30248
30281
|
if (!match) return null;
|
|
@@ -30289,10 +30322,20 @@ function sshdPeerIp(message) {
|
|
|
30289
30322
|
function classifySshAuth(entry) {
|
|
30290
30323
|
const { ip, user, message } = entry.fields;
|
|
30291
30324
|
if (/failed password/i.test(message)) {
|
|
30292
|
-
return {
|
|
30325
|
+
return {
|
|
30326
|
+
severity: "high",
|
|
30327
|
+
message: `Failed SSH login for ${user || "unknown"} from ${ip || "unknown"}`,
|
|
30328
|
+
source_ip: ip,
|
|
30329
|
+
...user ? { details: { user } } : {}
|
|
30330
|
+
};
|
|
30293
30331
|
}
|
|
30294
30332
|
if (/invalid user/i.test(message)) {
|
|
30295
|
-
return {
|
|
30333
|
+
return {
|
|
30334
|
+
severity: "high",
|
|
30335
|
+
message: `Invalid SSH user: ${user || "unknown"} from ${ip || "unknown"}`,
|
|
30336
|
+
source_ip: ip,
|
|
30337
|
+
...user ? { details: { user } } : {}
|
|
30338
|
+
};
|
|
30296
30339
|
}
|
|
30297
30340
|
if (/accepted/i.test(message)) {
|
|
30298
30341
|
const login2 = parseAcceptedLogin(message);
|
|
@@ -30301,7 +30344,7 @@ function classifySshAuth(entry) {
|
|
|
30301
30344
|
severity: "info",
|
|
30302
30345
|
message: `SSH login accepted for ${login2?.user || user || "unknown"}`,
|
|
30303
30346
|
source_ip: sourceIp,
|
|
30304
|
-
...login2 ? { details: { ssh_user: login2.user, auth_method: login2.method, port: login2.port, ...login2.key_type ? { key_type: login2.key_type } : {}, ...login2.fingerprint ? { fingerprint: login2.fingerprint } : {} } } : {}
|
|
30347
|
+
...login2 ? { details: { user: login2.user, ssh_user: login2.user, auth_method: login2.method, port: login2.port, ...login2.key_type ? { key_type: login2.key_type } : {}, ...login2.fingerprint ? { fingerprint: login2.fingerprint } : {} } } : {}
|
|
30305
30348
|
};
|
|
30306
30349
|
}
|
|
30307
30350
|
return null;
|
|
@@ -30435,6 +30478,7 @@ function parseConfigText(raw) {
|
|
|
30435
30478
|
update: parsed.update,
|
|
30436
30479
|
threat_feeds: parsed.threat_feeds,
|
|
30437
30480
|
privileged: parsed.privileged,
|
|
30481
|
+
command_history: parsed.command_history,
|
|
30438
30482
|
lightning: parsed.lightning,
|
|
30439
30483
|
storage: parsed.storage,
|
|
30440
30484
|
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
@@ -30494,6 +30538,7 @@ function generateDefaultConfig(detectedServices) {
|
|
|
30494
30538
|
// when the section is absent.
|
|
30495
30539
|
cloud: { enabled: true, min_severity: "medium" },
|
|
30496
30540
|
update: { auto: true, interval: "6h", min_age: "2h" },
|
|
30541
|
+
command_history: { enabled: false },
|
|
30497
30542
|
// Reporting to shared reputation feeds (PRD 0015). On by default but inert
|
|
30498
30543
|
// until a key is set: nothing is reported without ABUSEIPDB_API_KEY or the
|
|
30499
30544
|
// key below, and only corroborated, handshake-verified sources ever are.
|
|
@@ -37584,6 +37629,14 @@ function isSuppressed(suppressions, index, ruleId) {
|
|
|
37584
37629
|
if (!rules) return false;
|
|
37585
37630
|
return rules.has("*") || rules.has(ruleId);
|
|
37586
37631
|
}
|
|
37632
|
+
function pemPlaceholder(lines, index) {
|
|
37633
|
+
const first = lines[index] ?? "";
|
|
37634
|
+
const header2 = /-----BEGIN ((?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?)-----/.exec(first);
|
|
37635
|
+
if (!header2) return false;
|
|
37636
|
+
const tail = [first.slice(header2.index + header2[0].length), ...lines.slice(index + 1, index + 21)].join("\n").replace(/\\n/g, "\n");
|
|
37637
|
+
const end = tail.indexOf(`-----END ${header2[1]}-----`);
|
|
37638
|
+
return end >= 0 && ["your-pem-body-here", "your-private-key-here", "your-private-key-body-here"].includes(tail.slice(0, end).trim().toLowerCase());
|
|
37639
|
+
}
|
|
37587
37640
|
function isTestPath(relativePath) {
|
|
37588
37641
|
const p = relativePath.replace(/\\/g, "/");
|
|
37589
37642
|
return /(?:^|\/)(?:tests?|__tests__|__mocks__|spec|specs|fixtures?|mocks?|e2e|testdata|testutils?|harness)\//i.test(p) || /(?:^|\/)(?:test|conftest)_[^/]+$/i.test(p) || /[._-](?:test|spec)\.[a-z]+$/i.test(p) || /_test\.[a-z]+$/i.test(p);
|
|
@@ -37779,7 +37832,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
37779
37832
|
test: inTests,
|
|
37780
37833
|
"test-block": inlineTests.has(index),
|
|
37781
37834
|
suppressed: foreignSecurityMark(line2),
|
|
37782
|
-
placeholder: isPlaceholderAttribute(line2, value),
|
|
37835
|
+
placeholder: isPlaceholderAttribute(line2, value) || rule.id === "secret-private-key" && pemPlaceholder(lines, index),
|
|
37783
37836
|
"self-describing": rule.keywordShaped === true && describesItsOwnKey(line2, value)
|
|
37784
37837
|
});
|
|
37785
37838
|
findings2.push({
|
|
@@ -40055,19 +40108,12 @@ async function modulesCommand(opts) {
|
|
|
40055
40108
|
}
|
|
40056
40109
|
|
|
40057
40110
|
// src/commands/pentest.ts
|
|
40058
|
-
function decodeMarkupForXssDetection(html) {
|
|
40059
|
-
return html.replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'|'/gi, "'").replace(/&#x([0-9a-f]+);?/gi, (_, hex3) => String.fromCodePoint(parseInt(hex3, 16))).replace(/&#([0-9]+);?/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10)));
|
|
40060
|
-
}
|
|
40061
|
-
function containsXssPayload(html) {
|
|
40062
|
-
const candidate = decodeMarkupForXssDetection(html);
|
|
40063
|
-
return /<script\b[^>]*>[\s\S]*?\b(?:alert|confirm|prompt)\s*\(/i.test(candidate) || /<[a-z][^>]*\bon(?:error|load|mouseover|focus)\s*=\s*[^>]*(?:alert|confirm|prompt)\s*\(/i.test(candidate);
|
|
40064
|
-
}
|
|
40065
40111
|
var PENTEST_CHECKS = [
|
|
40066
40112
|
{
|
|
40067
|
-
name: "XSS
|
|
40068
|
-
test: (html) =>
|
|
40069
|
-
severity: "
|
|
40070
|
-
message: "
|
|
40113
|
+
name: "XSS Reflected",
|
|
40114
|
+
test: (html) => /<script>alert\(1\)<\/script>|<img\s+src=x\s+onerror=alert/i.test(html),
|
|
40115
|
+
severity: "critical",
|
|
40116
|
+
message: "Reflected XSS payload rendered in response"
|
|
40071
40117
|
},
|
|
40072
40118
|
{
|
|
40073
40119
|
name: "Open Redirect",
|
|
@@ -41475,16 +41521,16 @@ async function sshConnect(options) {
|
|
|
41475
41521
|
}
|
|
41476
41522
|
|
|
41477
41523
|
// src/commands/daemon.ts
|
|
41478
|
-
var
|
|
41479
|
-
var import_node_fs48 = require("fs");
|
|
41480
|
-
var import_node_path37 = require("path");
|
|
41524
|
+
var import_node_child_process19 = require("child_process");
|
|
41481
41525
|
var import_node_fs49 = require("fs");
|
|
41526
|
+
var import_node_path38 = require("path");
|
|
41527
|
+
var import_node_fs50 = require("fs");
|
|
41482
41528
|
|
|
41483
41529
|
// src/daemon/index.ts
|
|
41484
|
-
var
|
|
41485
|
-
var
|
|
41530
|
+
var import_node_fs48 = require("fs");
|
|
41531
|
+
var import_node_child_process18 = require("child_process");
|
|
41486
41532
|
var import_node_os14 = require("os");
|
|
41487
|
-
var
|
|
41533
|
+
var import_node_path37 = require("path");
|
|
41488
41534
|
var import_node_util4 = require("util");
|
|
41489
41535
|
init_paths();
|
|
41490
41536
|
|
|
@@ -41803,8 +41849,11 @@ var DEFAULT_SOURCES = [
|
|
|
41803
41849
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
41804
41850
|
{ path: "/var/log/secure", module: "ssh-guard", category: "auth" },
|
|
41805
41851
|
{ path: "/var/log/nginx/access.log", module: "log-watcher", category: "web" },
|
|
41852
|
+
{ path: "/var/log/caddy/agent.database.pit.world.access.log", module: "log-watcher", category: "web" },
|
|
41806
41853
|
{ path: "/var/log/syslog", module: "log-watcher", category: "system" }
|
|
41807
41854
|
];
|
|
41855
|
+
var AGENTDB_API_PATH = /^\/v1\/(?:list_databases|inspect_schema|query_readonly|explain_query|cluster_health|backup_status|audit\/events|backup\/(?:create|verify)|tokens(?:\/revoke)?)$/;
|
|
41856
|
+
var AGENTDB_HOST = "agent.database.pit.world";
|
|
41808
41857
|
var LogWatcher = class {
|
|
41809
41858
|
constructor(bus2, sources = DEFAULT_SOURCES) {
|
|
41810
41859
|
this.bus = bus2;
|
|
@@ -41865,7 +41914,8 @@ var LogWatcher = class {
|
|
|
41865
41914
|
});
|
|
41866
41915
|
}
|
|
41867
41916
|
process(line2, src) {
|
|
41868
|
-
const
|
|
41917
|
+
const caddy = parseCaddyAccessLog(line2);
|
|
41918
|
+
const parsed = caddy ?? autoDetectParser(line2);
|
|
41869
41919
|
if (!parsed) return;
|
|
41870
41920
|
let severity = "info";
|
|
41871
41921
|
let message = line2;
|
|
@@ -41883,7 +41933,7 @@ var LogWatcher = class {
|
|
|
41883
41933
|
({ severity, message, source_ip: sourceIp } = verdict);
|
|
41884
41934
|
if (verdict.details) Object.assign(details, verdict.details);
|
|
41885
41935
|
} else if (parsed.source === "nginx") {
|
|
41886
|
-
const entry = parseNginxLog(line2);
|
|
41936
|
+
const entry = caddy ?? parseNginxLog(line2);
|
|
41887
41937
|
if (!entry) return;
|
|
41888
41938
|
sourceIp = entry.fields.ip;
|
|
41889
41939
|
const status = parseInt(entry.fields.status, 10);
|
|
@@ -41897,6 +41947,16 @@ var LogWatcher = class {
|
|
|
41897
41947
|
if (Number.isFinite(status)) details.status = status;
|
|
41898
41948
|
if (entry.fields.method) details.method = entry.fields.method;
|
|
41899
41949
|
if (entry.fields.path) details.url = entry.fields.path.slice(0, 2048);
|
|
41950
|
+
const agentDbHost = entry.fields.host?.toLowerCase();
|
|
41951
|
+
const isAgentDbApi = AGENTDB_API_PATH.test(reqPath) && (!agentDbHost || agentDbHost === AGENTDB_HOST);
|
|
41952
|
+
if (isAgentDbApi) {
|
|
41953
|
+
details.url = reqPath;
|
|
41954
|
+
details.service = "agentdb";
|
|
41955
|
+
const responseBytes = Number(entry.fields.size);
|
|
41956
|
+
if (Number.isSafeInteger(responseBytes) && responseBytes >= 0) {
|
|
41957
|
+
details.response_bytes = responseBytes;
|
|
41958
|
+
}
|
|
41959
|
+
}
|
|
41900
41960
|
if (crs.score > 0) {
|
|
41901
41961
|
Object.assign(details, {
|
|
41902
41962
|
attack_type: crs.attackType,
|
|
@@ -41907,7 +41967,10 @@ var LogWatcher = class {
|
|
|
41907
41967
|
}
|
|
41908
41968
|
if (attack) {
|
|
41909
41969
|
severity = attack;
|
|
41910
|
-
message = `Attack [${type}]: ${entry.fields.method} ${entry.fields.path}`;
|
|
41970
|
+
message = `Attack [${type}]: ${entry.fields.method} ${isAgentDbApi ? reqPath : entry.fields.path}`;
|
|
41971
|
+
} else if (isAgentDbApi) {
|
|
41972
|
+
severity = status >= 500 ? "medium" : status >= 400 ? "low" : "info";
|
|
41973
|
+
message = `AgentDB API ${status}: ${entry.fields.method} ${reqPath}`;
|
|
41911
41974
|
} else if (status >= 500) {
|
|
41912
41975
|
severity = "medium";
|
|
41913
41976
|
message = `Server error ${status}: ${entry.fields.method} ${entry.fields.path}`;
|
|
@@ -41940,9 +42003,50 @@ var LogWatcher = class {
|
|
|
41940
42003
|
}
|
|
41941
42004
|
};
|
|
41942
42005
|
|
|
42006
|
+
// src/daemon/watchers/journal-provenance.ts
|
|
42007
|
+
var JournalProvenance = class {
|
|
42008
|
+
peers = /* @__PURE__ */ new Map();
|
|
42009
|
+
fields(entry) {
|
|
42010
|
+
const details = {};
|
|
42011
|
+
for (const [source, dest] of Object.entries({ _PID: "pid", _BOOT_ID: "boot_id", __CURSOR: "journal_cursor", _AUDIT_SESSION: "audit_session", _AUDIT_LOGINUID: "login_uid" })) {
|
|
42012
|
+
if (typeof entry[source] === "string") details[dest] = entry[source].slice(0, 200);
|
|
42013
|
+
}
|
|
42014
|
+
const trusted = entry._UID === "0" && ["sshd", "sshd-session", "sshd-auth"].includes(String(entry._COMM));
|
|
42015
|
+
if (!trusted || typeof entry.MESSAGE !== "string") return { details };
|
|
42016
|
+
const at = Number(entry.__REALTIME_TIMESTAMP) / 1e3;
|
|
42017
|
+
const key = typeof entry._BOOT_ID === "string" && typeof entry._PID === "string" ? `${entry._BOOT_ID}:${entry._PID}` : null;
|
|
42018
|
+
for (const [k, peer2] of this.peers) if (!Number.isFinite(at) || at - peer2.at > 12e4 || at < peer2.at) this.peers.delete(k);
|
|
42019
|
+
const direct = sshdPeerIp(entry.MESSAGE);
|
|
42020
|
+
if (direct && key && Number.isFinite(at)) {
|
|
42021
|
+
this.peers.delete(key);
|
|
42022
|
+
this.peers.set(key, { ip: direct, at });
|
|
42023
|
+
if (this.peers.size > 512) this.peers.delete(this.peers.keys().next().value);
|
|
42024
|
+
}
|
|
42025
|
+
const peer = key ? this.peers.get(key) : void 0;
|
|
42026
|
+
const source_ip = direct ?? (peer && Number.isFinite(at) && at >= peer.at && at - peer.at <= 12e4 ? peer.ip : void 0);
|
|
42027
|
+
if (source_ip) details.source_ip_basis = direct ? "current sshd record" : "same boot and sshd PID within 120 seconds";
|
|
42028
|
+
return { ...source_ip ? { source_ip } : {}, details };
|
|
42029
|
+
}
|
|
42030
|
+
};
|
|
42031
|
+
|
|
41943
42032
|
// src/daemon/watchers/journal-watcher.ts
|
|
41944
42033
|
var import_node_child_process6 = require("child_process");
|
|
41945
42034
|
var SSHD_COMMS = ["sshd", "sshd-session"];
|
|
42035
|
+
var accountNames = /* @__PURE__ */ new Map();
|
|
42036
|
+
function accountNameForUid(value) {
|
|
42037
|
+
if (typeof value !== "string" || !/^\d+$/.test(value)) return null;
|
|
42038
|
+
if (accountNames.has(value)) return accountNames.get(value) ?? null;
|
|
42039
|
+
const result = (0, import_node_child_process6.spawnSync)("getent", ["passwd", value], {
|
|
42040
|
+
encoding: "utf-8",
|
|
42041
|
+
timeout: 1e3,
|
|
42042
|
+
maxBuffer: 4096,
|
|
42043
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
42044
|
+
});
|
|
42045
|
+
const name = result.status === 0 ? result.stdout.split(":", 1)[0] : "";
|
|
42046
|
+
const resolved = /^[a-zA-Z0-9_.@-]{1,256}$/.test(name) ? name : null;
|
|
42047
|
+
accountNames.set(value, resolved);
|
|
42048
|
+
return resolved;
|
|
42049
|
+
}
|
|
41946
42050
|
function isSshdRecord(entry) {
|
|
41947
42051
|
return entry._UID === "0" && SSHD_COMMS.includes(entry._COMM);
|
|
41948
42052
|
}
|
|
@@ -41951,6 +42055,7 @@ function sshEventFromJournal(entry) {
|
|
|
41951
42055
|
const timestamp = realtimeToDate(entry.__REALTIME_TIMESTAMP) || /* @__PURE__ */ new Date();
|
|
41952
42056
|
const verdict = classifySshAuth(parseAuthMessage(entry._COMM, entry.MESSAGE, timestamp));
|
|
41953
42057
|
if (!verdict) return null;
|
|
42058
|
+
const systemAccount = accountNameForUid(entry._UID);
|
|
41954
42059
|
return {
|
|
41955
42060
|
timestamp,
|
|
41956
42061
|
module: "ssh-guard",
|
|
@@ -41958,7 +42063,12 @@ function sshEventFromJournal(entry) {
|
|
|
41958
42063
|
severity: verdict.severity,
|
|
41959
42064
|
message: verdict.message,
|
|
41960
42065
|
source_ip: verdict.source_ip,
|
|
41961
|
-
|
|
42066
|
+
details: {
|
|
42067
|
+
...verdict.details ?? {},
|
|
42068
|
+
...typeof entry._UID === "string" && /^\d+$/.test(entry._UID) ? { system_uid: entry._UID } : {},
|
|
42069
|
+
...systemAccount ? { system_account: systemAccount } : {},
|
|
42070
|
+
...typeof entry._COMM === "string" ? { process: entry._COMM } : {}
|
|
42071
|
+
}
|
|
41962
42072
|
};
|
|
41963
42073
|
}
|
|
41964
42074
|
function sshdLineFromJournal(entry) {
|
|
@@ -41978,6 +42088,7 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
41978
42088
|
buffer = "";
|
|
41979
42089
|
sshdBuffer = "";
|
|
41980
42090
|
moduleName = "user-journal";
|
|
42091
|
+
provenance = new JournalProvenance();
|
|
41981
42092
|
active = false;
|
|
41982
42093
|
// When the daemon runs as root (system mode), tail the SYSTEM journal so
|
|
41983
42094
|
// we pick up sshd / sudo / kernel / UFW events. Falling back to --user
|
|
@@ -42036,8 +42147,9 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
42036
42147
|
this.sshdBuffer = this.drain(this.sshdBuffer + chunk2, (entry) => {
|
|
42037
42148
|
const line2 = sshdLineFromJournal(entry);
|
|
42038
42149
|
if (line2) this.bus.sshdLine?.(line2);
|
|
42150
|
+
const context = this.provenance.fields(entry);
|
|
42039
42151
|
const event = sshEventFromJournal(entry);
|
|
42040
|
-
if (event) this.emit(event);
|
|
42152
|
+
if (event) this.emit({ ...event, source_ip: event.source_ip ?? context.source_ip, details: { ...event.details, ...context.details } });
|
|
42041
42153
|
});
|
|
42042
42154
|
});
|
|
42043
42155
|
child.on("error", () => {
|
|
@@ -42084,6 +42196,7 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
42084
42196
|
return buffer;
|
|
42085
42197
|
}
|
|
42086
42198
|
handleEntry(entry) {
|
|
42199
|
+
const context = this.provenance.fields(entry);
|
|
42087
42200
|
if (this.sshdProc && isSshdRecord(entry)) return;
|
|
42088
42201
|
const message = entry.MESSAGE;
|
|
42089
42202
|
if (!message) return;
|
|
@@ -42096,7 +42209,17 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
42096
42209
|
module: this.moduleName,
|
|
42097
42210
|
category: "system",
|
|
42098
42211
|
severity: bumpedSeverity,
|
|
42099
|
-
|
|
42212
|
+
...context.source_ip ? { source_ip: context.source_ip } : {},
|
|
42213
|
+
message: `[${ident}] ${message}`.slice(0, 500),
|
|
42214
|
+
details: {
|
|
42215
|
+
...context.details,
|
|
42216
|
+
...typeof entry._UID === "string" && /^\d+$/.test(entry._UID) ? { system_uid: entry._UID } : {},
|
|
42217
|
+
...accountNameForUid(entry._UID) ? { system_account: accountNameForUid(entry._UID) } : {},
|
|
42218
|
+
...typeof entry._COMM === "string" ? { process: entry._COMM } : {},
|
|
42219
|
+
...typeof entry.SYSLOG_IDENTIFIER === "string" ? { identifier: entry.SYSLOG_IDENTIFIER } : {},
|
|
42220
|
+
...typeof entry._PID === "string" ? { pid: entry._PID } : {},
|
|
42221
|
+
...typeof entry._SYSTEMD_UNIT === "string" ? { unit: entry._SYSTEMD_UNIT } : {}
|
|
42222
|
+
}
|
|
42100
42223
|
});
|
|
42101
42224
|
}
|
|
42102
42225
|
emit(event) {
|
|
@@ -43730,7 +43853,7 @@ function str2(value) {
|
|
|
43730
43853
|
return typeof value === "string" && value ? value : void 0;
|
|
43731
43854
|
}
|
|
43732
43855
|
function detectionEvent(serverId, event) {
|
|
43733
|
-
const { rule_id, username, user, description, ...rest } = event.details ?? {};
|
|
43856
|
+
const { rule_id, username, user, ssh_user, account, description, ...rest } = event.details ?? {};
|
|
43734
43857
|
const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
|
|
43735
43858
|
return {
|
|
43736
43859
|
type: "detection",
|
|
@@ -43740,7 +43863,7 @@ function detectionEvent(serverId, event) {
|
|
|
43740
43863
|
rule_id: str2(rule_id) ?? event.module,
|
|
43741
43864
|
description: str2(description),
|
|
43742
43865
|
source_ip: event.source_ip && (0, import_node_net8.isIP)(event.source_ip) ? event.source_ip : void 0,
|
|
43743
|
-
username: str2(username) ?? str2(user),
|
|
43866
|
+
username: str2(username) ?? str2(user) ?? str2(ssh_user) ?? str2(account),
|
|
43744
43867
|
raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
|
|
43745
43868
|
detected_at: event.timestamp.toISOString()
|
|
43746
43869
|
};
|
|
@@ -46026,10 +46149,325 @@ var PrivilegeWatch = class {
|
|
|
46026
46149
|
}
|
|
46027
46150
|
};
|
|
46028
46151
|
|
|
46029
|
-
// src/daemon/workers/
|
|
46152
|
+
// src/daemon/workers/command-history.ts
|
|
46030
46153
|
var import_node_fs40 = require("fs");
|
|
46031
|
-
var import_node_path31 = require("path");
|
|
46032
46154
|
var import_node_child_process13 = require("child_process");
|
|
46155
|
+
var import_node_path31 = require("path");
|
|
46156
|
+
var import_node_zlib2 = require("zlib");
|
|
46157
|
+
var import_node_crypto10 = require("crypto");
|
|
46158
|
+
var POLL_MS3 = 6e4;
|
|
46159
|
+
var MAX_HISTORY_BYTES = 4 * 1024 * 1024;
|
|
46160
|
+
var MAX_COMPRESSED_HISTORY_BYTES = MAX_HISTORY_BYTES + 65536;
|
|
46161
|
+
var MAX_SNAPSHOTS = 96;
|
|
46162
|
+
var SNAPSHOT_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
46163
|
+
var HISTORY_TARGETS = {
|
|
46164
|
+
bash: [".bash_history"],
|
|
46165
|
+
zsh: [".zsh_history"],
|
|
46166
|
+
fish: [".local/share/fish/fish_history"],
|
|
46167
|
+
ksh: [".sh_history"]
|
|
46168
|
+
};
|
|
46169
|
+
function commandHistorySettings(section) {
|
|
46170
|
+
return { enabled: section?.enabled === true };
|
|
46171
|
+
}
|
|
46172
|
+
function historyAccounts() {
|
|
46173
|
+
let passwd;
|
|
46174
|
+
try {
|
|
46175
|
+
passwd = (0, import_node_child_process13.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
46176
|
+
} catch {
|
|
46177
|
+
try {
|
|
46178
|
+
passwd = (0, import_node_fs40.readFileSync)("/etc/passwd", "utf8");
|
|
46179
|
+
} catch {
|
|
46180
|
+
return [];
|
|
46181
|
+
}
|
|
46182
|
+
}
|
|
46183
|
+
const root = typeof process.getuid === "function" && process.getuid() === 0;
|
|
46184
|
+
return passwd.split("\n").flatMap((line2) => {
|
|
46185
|
+
const fields = line2.split(":");
|
|
46186
|
+
const uid = Number(fields[2]);
|
|
46187
|
+
const gid = Number(fields[3]);
|
|
46188
|
+
const name = fields[0] ?? "";
|
|
46189
|
+
const home = fields[5] ?? "";
|
|
46190
|
+
const shell = fields[6] ?? "";
|
|
46191
|
+
if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path31.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
|
|
46192
|
+
if (root ? uid !== 0 && uid < 1e3 : uid !== process.getuid?.()) return [];
|
|
46193
|
+
if (!HISTORY_TARGETS[(0, import_node_path31.basename)(shell)]) return [];
|
|
46194
|
+
return [{ uid, gid, name, home, shell }];
|
|
46195
|
+
});
|
|
46196
|
+
}
|
|
46197
|
+
function historyWritableHomes() {
|
|
46198
|
+
return [...new Set(historyAccounts().map((account) => account.home))].filter((home) => /^\/[A-Za-z0-9._/-]+$/.test(home));
|
|
46199
|
+
}
|
|
46200
|
+
function descriptorPath(directoryFd, name) {
|
|
46201
|
+
return `/proc/self/fd/${directoryFd}/${name}`;
|
|
46202
|
+
}
|
|
46203
|
+
function openDirectoryChain(path2) {
|
|
46204
|
+
if (!(0, import_node_path31.isAbsolute)(path2) || path2.split(import_node_path31.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
|
|
46205
|
+
const flags = import_node_fs40.constants.O_RDONLY | import_node_fs40.constants.O_DIRECTORY | (import_node_fs40.constants.O_NOFOLLOW ?? 0);
|
|
46206
|
+
let fd = (0, import_node_fs40.openSync)("/", flags);
|
|
46207
|
+
try {
|
|
46208
|
+
for (const part of path2.split(import_node_path31.sep).filter((item) => item && item !== ".")) {
|
|
46209
|
+
const next = (0, import_node_fs40.openSync)(descriptorPath(fd, part), flags);
|
|
46210
|
+
(0, import_node_fs40.closeSync)(fd);
|
|
46211
|
+
fd = next;
|
|
46212
|
+
}
|
|
46213
|
+
return fd;
|
|
46214
|
+
} catch (error2) {
|
|
46215
|
+
(0, import_node_fs40.closeSync)(fd);
|
|
46216
|
+
throw error2;
|
|
46217
|
+
}
|
|
46218
|
+
}
|
|
46219
|
+
function readExact(fd, size) {
|
|
46220
|
+
const data = Buffer.alloc(size);
|
|
46221
|
+
let offset = 0;
|
|
46222
|
+
while (offset < data.length) {
|
|
46223
|
+
const read = (0, import_node_fs40.readSync)(fd, data, offset, data.length - offset, offset);
|
|
46224
|
+
if (read === 0) break;
|
|
46225
|
+
offset += read;
|
|
46226
|
+
}
|
|
46227
|
+
return offset === data.length ? data : null;
|
|
46228
|
+
}
|
|
46229
|
+
function privateDirectory(path2) {
|
|
46230
|
+
(0, import_node_fs40.mkdirSync)(path2, { recursive: true, mode: 448 });
|
|
46231
|
+
const stat = (0, import_node_fs40.lstatSync)(path2);
|
|
46232
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
|
|
46233
|
+
(0, import_node_fs40.chmodSync)(path2, 448);
|
|
46234
|
+
}
|
|
46235
|
+
function safeReadHistory(directoryFd, name, uid) {
|
|
46236
|
+
const noFollow = import_node_fs40.constants.O_NOFOLLOW ?? 0;
|
|
46237
|
+
const fd = (0, import_node_fs40.openSync)(descriptorPath(directoryFd, name), import_node_fs40.constants.O_RDONLY | noFollow);
|
|
46238
|
+
try {
|
|
46239
|
+
const opened = (0, import_node_fs40.fstatSync)(fd);
|
|
46240
|
+
if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
|
|
46241
|
+
if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
|
|
46242
|
+
const data = readExact(fd, opened.size);
|
|
46243
|
+
if (data === null) return null;
|
|
46244
|
+
const after = (0, import_node_fs40.fstatSync)(fd);
|
|
46245
|
+
if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
|
|
46246
|
+
return data;
|
|
46247
|
+
} finally {
|
|
46248
|
+
(0, import_node_fs40.closeSync)(fd);
|
|
46249
|
+
}
|
|
46250
|
+
}
|
|
46251
|
+
function atomicWrite(path2, data, mode = 384, owner, parentFd) {
|
|
46252
|
+
const dirFd = parentFd ?? openDirectoryChain((0, import_node_path31.dirname)(path2));
|
|
46253
|
+
const ownsDirFd = parentFd === void 0;
|
|
46254
|
+
const name = (0, import_node_path31.basename)(path2);
|
|
46255
|
+
const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto10.randomUUID)()}.tmp`);
|
|
46256
|
+
const destination = descriptorPath(dirFd, name);
|
|
46257
|
+
const noFollow = import_node_fs40.constants.O_NOFOLLOW ?? 0;
|
|
46258
|
+
let fd;
|
|
46259
|
+
try {
|
|
46260
|
+
fd = (0, import_node_fs40.openSync)(temp, import_node_fs40.constants.O_WRONLY | import_node_fs40.constants.O_CREAT | import_node_fs40.constants.O_EXCL | noFollow, mode);
|
|
46261
|
+
let offset = 0;
|
|
46262
|
+
while (offset < data.length) offset += (0, import_node_fs40.writeSync)(fd, data, offset, data.length - offset);
|
|
46263
|
+
(0, import_node_fs40.fchmodSync)(fd, mode);
|
|
46264
|
+
if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
|
|
46265
|
+
(0, import_node_fs40.fchownSync)(fd, owner.uid, owner.gid);
|
|
46266
|
+
}
|
|
46267
|
+
(0, import_node_fs40.fsyncSync)(fd);
|
|
46268
|
+
(0, import_node_fs40.closeSync)(fd);
|
|
46269
|
+
fd = void 0;
|
|
46270
|
+
(0, import_node_fs40.renameSync)(temp, destination);
|
|
46271
|
+
} catch (error2) {
|
|
46272
|
+
if (fd !== void 0) {
|
|
46273
|
+
try {
|
|
46274
|
+
(0, import_node_fs40.closeSync)(fd);
|
|
46275
|
+
} catch {
|
|
46276
|
+
}
|
|
46277
|
+
}
|
|
46278
|
+
try {
|
|
46279
|
+
(0, import_node_fs40.unlinkSync)(temp);
|
|
46280
|
+
} catch {
|
|
46281
|
+
}
|
|
46282
|
+
throw error2;
|
|
46283
|
+
} finally {
|
|
46284
|
+
if (ownsDirFd) (0, import_node_fs40.closeSync)(dirFd);
|
|
46285
|
+
}
|
|
46286
|
+
}
|
|
46287
|
+
function readCurrentBackup(path2) {
|
|
46288
|
+
let fd;
|
|
46289
|
+
try {
|
|
46290
|
+
const parentFd = openDirectoryChain((0, import_node_path31.dirname)(path2));
|
|
46291
|
+
try {
|
|
46292
|
+
fd = (0, import_node_fs40.openSync)(descriptorPath(parentFd, (0, import_node_path31.basename)(path2)), import_node_fs40.constants.O_RDONLY | (import_node_fs40.constants.O_NOFOLLOW ?? 0));
|
|
46293
|
+
} finally {
|
|
46294
|
+
(0, import_node_fs40.closeSync)(parentFd);
|
|
46295
|
+
}
|
|
46296
|
+
const stat = (0, import_node_fs40.fstatSync)(fd);
|
|
46297
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
|
|
46298
|
+
const compressed = readExact(fd, stat.size);
|
|
46299
|
+
const after = (0, import_node_fs40.fstatSync)(fd);
|
|
46300
|
+
if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
|
|
46301
|
+
return (0, import_node_zlib2.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
|
|
46302
|
+
} catch {
|
|
46303
|
+
return null;
|
|
46304
|
+
} finally {
|
|
46305
|
+
if (fd !== void 0) (0, import_node_fs40.closeSync)(fd);
|
|
46306
|
+
}
|
|
46307
|
+
}
|
|
46308
|
+
function compactTime(date) {
|
|
46309
|
+
return date.toISOString().replace(/[-:]/g, "").replace(/\.(\d{3})Z$/, "$1Z");
|
|
46310
|
+
}
|
|
46311
|
+
var CommandHistoryWatcher = class {
|
|
46312
|
+
constructor(opts) {
|
|
46313
|
+
this.opts = opts;
|
|
46314
|
+
this.pollMs = Math.max(1e4, opts.pollMs ?? POLL_MS3);
|
|
46315
|
+
this.now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
46316
|
+
this.listAccounts = opts.listAccounts ?? historyAccounts;
|
|
46317
|
+
this.root = (0, import_node_path31.join)(opts.stateDir, "command-history");
|
|
46318
|
+
}
|
|
46319
|
+
opts;
|
|
46320
|
+
timer = null;
|
|
46321
|
+
scanning = false;
|
|
46322
|
+
pollMs;
|
|
46323
|
+
now;
|
|
46324
|
+
listAccounts;
|
|
46325
|
+
root;
|
|
46326
|
+
start() {
|
|
46327
|
+
if (!this.opts.settings.enabled) {
|
|
46328
|
+
this.opts.log("[command-history] disabled; set [command_history] enabled = true to collect local shell history");
|
|
46329
|
+
return;
|
|
46330
|
+
}
|
|
46331
|
+
if (process.platform !== "linux") {
|
|
46332
|
+
this.opts.log("[command-history] unavailable: only Linux account history paths are supported");
|
|
46333
|
+
return;
|
|
46334
|
+
}
|
|
46335
|
+
try {
|
|
46336
|
+
privateDirectory(this.root);
|
|
46337
|
+
} catch (error2) {
|
|
46338
|
+
this.opts.log(`[command-history] cannot create private storage: ${error2.message}`);
|
|
46339
|
+
return;
|
|
46340
|
+
}
|
|
46341
|
+
this.opts.log(`[command-history] enabled; private snapshots under ${this.root}, checking every ${Math.round(this.pollMs / 1e3)}s`);
|
|
46342
|
+
void this.scanOnce();
|
|
46343
|
+
this.timer = setInterval(() => {
|
|
46344
|
+
void this.scanOnce();
|
|
46345
|
+
}, this.pollMs);
|
|
46346
|
+
this.timer.unref();
|
|
46347
|
+
}
|
|
46348
|
+
stop() {
|
|
46349
|
+
if (this.timer) clearInterval(this.timer);
|
|
46350
|
+
this.timer = null;
|
|
46351
|
+
}
|
|
46352
|
+
async scanOnce() {
|
|
46353
|
+
if (this.scanning || !this.opts.settings.enabled || process.platform !== "linux") return;
|
|
46354
|
+
this.scanning = true;
|
|
46355
|
+
try {
|
|
46356
|
+
privateDirectory(this.root);
|
|
46357
|
+
for (const account of this.listAccounts()) {
|
|
46358
|
+
if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path31.isAbsolute)(account.home)) continue;
|
|
46359
|
+
const targets = this.targetsFor(account);
|
|
46360
|
+
for (const relative4 of targets) this.scanFile(account, relative4);
|
|
46361
|
+
}
|
|
46362
|
+
} catch (error2) {
|
|
46363
|
+
this.opts.log(`[command-history] scan failed: ${error2.message}`);
|
|
46364
|
+
} finally {
|
|
46365
|
+
this.scanning = false;
|
|
46366
|
+
}
|
|
46367
|
+
}
|
|
46368
|
+
targetsFor(account) {
|
|
46369
|
+
const targets = new Set(HISTORY_TARGETS[(0, import_node_path31.basename)(account.shell)] ?? []);
|
|
46370
|
+
for (const relative4 of Object.values(HISTORY_TARGETS).flat()) {
|
|
46371
|
+
if (targets.has(relative4)) continue;
|
|
46372
|
+
const path2 = (0, import_node_path31.join)(account.home, relative4);
|
|
46373
|
+
try {
|
|
46374
|
+
(0, import_node_fs40.lstatSync)(path2);
|
|
46375
|
+
targets.add(relative4);
|
|
46376
|
+
continue;
|
|
46377
|
+
} catch (error2) {
|
|
46378
|
+
if (error2.code !== "ENOENT") continue;
|
|
46379
|
+
}
|
|
46380
|
+
const current = (0, import_node_path31.join)(this.root, String(account.uid), `${(0, import_node_path31.basename)(relative4)}.current.gz`);
|
|
46381
|
+
if (readCurrentBackup(current) !== null) targets.add(relative4);
|
|
46382
|
+
}
|
|
46383
|
+
return [...targets];
|
|
46384
|
+
}
|
|
46385
|
+
scanFile(account, relative4) {
|
|
46386
|
+
const path2 = (0, import_node_path31.join)(account.home, relative4);
|
|
46387
|
+
const store = (0, import_node_path31.join)(this.root, String(account.uid), (0, import_node_path31.basename)(relative4));
|
|
46388
|
+
const current = `${store}.current.gz`;
|
|
46389
|
+
let userParentFd;
|
|
46390
|
+
try {
|
|
46391
|
+
userParentFd = openDirectoryChain((0, import_node_path31.dirname)(path2));
|
|
46392
|
+
} catch {
|
|
46393
|
+
this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path31.basename)(relative4)} because its parent path is missing or not a real directory`);
|
|
46394
|
+
return;
|
|
46395
|
+
}
|
|
46396
|
+
try {
|
|
46397
|
+
privateDirectory((0, import_node_path31.dirname)(store));
|
|
46398
|
+
const userPath = descriptorPath(userParentFd, (0, import_node_path31.basename)(path2));
|
|
46399
|
+
let status;
|
|
46400
|
+
try {
|
|
46401
|
+
status = (0, import_node_fs40.lstatSync)(userPath);
|
|
46402
|
+
} catch (error2) {
|
|
46403
|
+
if (error2.code !== "ENOENT") throw error2;
|
|
46404
|
+
}
|
|
46405
|
+
const backup = readCurrentBackup(current);
|
|
46406
|
+
const suspicious = status && (!status.isFile() || status.isSymbolicLink() || status.nlink !== 1 || status.uid !== account.uid);
|
|
46407
|
+
const missingWithBackup = !status && backup !== null;
|
|
46408
|
+
if (suspicious || missingWithBackup) {
|
|
46409
|
+
const reason = !status ? "deleted" : status.isSymbolicLink() ? "symlinked" : !status.isFile() ? "not a regular file" : status.nlink !== 1 ? "hard-linked" : "owned by another account";
|
|
46410
|
+
const restored = backup ?? Buffer.alloc(0);
|
|
46411
|
+
this.restore(path2, restored, account, userParentFd);
|
|
46412
|
+
this.emitTamper(account, relative4, reason, backup !== null);
|
|
46413
|
+
} else if (!status) {
|
|
46414
|
+
this.restore(path2, Buffer.alloc(0), account, userParentFd);
|
|
46415
|
+
}
|
|
46416
|
+
const data = safeReadHistory(userParentFd, (0, import_node_path31.basename)(path2), account.uid);
|
|
46417
|
+
if (data === null) return;
|
|
46418
|
+
const previous = backup;
|
|
46419
|
+
if (previous?.equals(data)) {
|
|
46420
|
+
this.pruneSnapshots(current);
|
|
46421
|
+
return;
|
|
46422
|
+
}
|
|
46423
|
+
const compressed = (0, import_node_zlib2.gzipSync)(data, { level: 6 });
|
|
46424
|
+
const stamp = compactTime(this.now());
|
|
46425
|
+
atomicWrite(`${store}.${stamp}-${(0, import_node_crypto10.randomUUID)().slice(0, 8)}.gz`, compressed);
|
|
46426
|
+
atomicWrite(current, compressed);
|
|
46427
|
+
this.pruneSnapshots(store);
|
|
46428
|
+
} catch (error2) {
|
|
46429
|
+
this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path31.basename)(relative4)}: ${error2.message}`);
|
|
46430
|
+
} finally {
|
|
46431
|
+
(0, import_node_fs40.closeSync)(userParentFd);
|
|
46432
|
+
}
|
|
46433
|
+
}
|
|
46434
|
+
restore(path2, content, account, parentFd) {
|
|
46435
|
+
atomicWrite(path2, content, 384, account, parentFd);
|
|
46436
|
+
}
|
|
46437
|
+
emitTamper(account, relative4, reason, hadBackup) {
|
|
46438
|
+
const name = /^[A-Za-z0-9_.-]{1,64}$/.test(account.name) ? account.name : `uid ${account.uid}`;
|
|
46439
|
+
const event = {
|
|
46440
|
+
timestamp: this.now(),
|
|
46441
|
+
module: "command-history",
|
|
46442
|
+
category: "system",
|
|
46443
|
+
severity: "medium",
|
|
46444
|
+
message: `Shell history for ${name} (${(0, import_node_path31.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
|
|
46445
|
+
details: { uid: account.uid, account: name, history_file: (0, import_node_path31.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
|
|
46446
|
+
};
|
|
46447
|
+
this.opts.bus.publish(event);
|
|
46448
|
+
this.opts.log(`[command-history] ${event.message}`);
|
|
46449
|
+
}
|
|
46450
|
+
pruneSnapshots(current) {
|
|
46451
|
+
const dir = (0, import_node_path31.dirname)(current);
|
|
46452
|
+
const prefix = `${(0, import_node_path31.basename)(current).replace(/\.current\.gz$/, "")}.`;
|
|
46453
|
+
const snapshots = (0, import_node_fs40.readdirSync)(dir).filter((name) => name !== (0, import_node_path31.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path31.join)(dir, name), name, time: (0, import_node_fs40.lstatSync)((0, import_node_path31.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
|
|
46454
|
+
const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
|
|
46455
|
+
const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
|
|
46456
|
+
snapshots.forEach((snapshot, index) => {
|
|
46457
|
+
if (snapshot.time < cutoff || index < removeCount) {
|
|
46458
|
+
try {
|
|
46459
|
+
(0, import_node_fs40.unlinkSync)(snapshot.path);
|
|
46460
|
+
} catch {
|
|
46461
|
+
}
|
|
46462
|
+
}
|
|
46463
|
+
});
|
|
46464
|
+
}
|
|
46465
|
+
};
|
|
46466
|
+
|
|
46467
|
+
// src/daemon/workers/ssh-intrusion.ts
|
|
46468
|
+
var import_node_fs41 = require("fs");
|
|
46469
|
+
var import_node_path32 = require("path");
|
|
46470
|
+
var import_node_child_process14 = require("child_process");
|
|
46033
46471
|
|
|
46034
46472
|
// src/core/asn.ts
|
|
46035
46473
|
var import_node_dns = require("dns");
|
|
@@ -46222,35 +46660,35 @@ function parseKeyLoginsByFingerprint(text) {
|
|
|
46222
46660
|
}
|
|
46223
46661
|
function readJson2(path2) {
|
|
46224
46662
|
try {
|
|
46225
|
-
return JSON.parse((0,
|
|
46663
|
+
return JSON.parse((0, import_node_fs41.readFileSync)(path2, "utf-8"));
|
|
46226
46664
|
} catch {
|
|
46227
46665
|
return null;
|
|
46228
46666
|
}
|
|
46229
46667
|
}
|
|
46230
46668
|
function writeJson2(path2, value) {
|
|
46231
|
-
(0,
|
|
46232
|
-
(0,
|
|
46233
|
-
(0,
|
|
46669
|
+
(0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
|
|
46670
|
+
(0, import_node_fs41.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
|
|
46671
|
+
(0, import_node_fs41.renameSync)(`${path2}.tmp`, path2);
|
|
46234
46672
|
}
|
|
46235
46673
|
var fsIO2 = {
|
|
46236
46674
|
readFile: (p) => {
|
|
46237
46675
|
try {
|
|
46238
|
-
return (0,
|
|
46676
|
+
return (0, import_node_fs41.readFileSync)(p, "utf-8");
|
|
46239
46677
|
} catch {
|
|
46240
46678
|
return null;
|
|
46241
46679
|
}
|
|
46242
46680
|
},
|
|
46243
46681
|
readDir: (p) => {
|
|
46244
46682
|
try {
|
|
46245
|
-
return (0,
|
|
46683
|
+
return (0, import_node_fs41.readdirSync)(p);
|
|
46246
46684
|
} catch {
|
|
46247
46685
|
return null;
|
|
46248
46686
|
}
|
|
46249
46687
|
},
|
|
46250
|
-
exists: (p) => (0,
|
|
46688
|
+
exists: (p) => (0, import_node_fs41.existsSync)(p)
|
|
46251
46689
|
};
|
|
46252
46690
|
function defaultRun4(cmd, args) {
|
|
46253
|
-
const res = (0,
|
|
46691
|
+
const res = (0, import_node_child_process14.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 6e4, maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
46254
46692
|
return res.status === 0 ? res.stdout : null;
|
|
46255
46693
|
}
|
|
46256
46694
|
var SshIntrusionWatch = class {
|
|
@@ -46448,7 +46886,7 @@ var SshIntrusionWatch = class {
|
|
|
46448
46886
|
};
|
|
46449
46887
|
|
|
46450
46888
|
// src/daemon/workers/lightning-watch.ts
|
|
46451
|
-
var
|
|
46889
|
+
var import_node_fs42 = require("fs");
|
|
46452
46890
|
var DEFAULT_CLN_LOGS = [
|
|
46453
46891
|
"/home/lightning/.lightning/cln.log",
|
|
46454
46892
|
"/root/.lightning/cln.log",
|
|
@@ -46504,9 +46942,9 @@ var LightningWatch = class {
|
|
|
46504
46942
|
if (this.opts.enabled === false) return [];
|
|
46505
46943
|
const found = [];
|
|
46506
46944
|
for (const path2 of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
|
|
46507
|
-
if (!(0,
|
|
46945
|
+
if (!(0, import_node_fs42.existsSync)(path2)) continue;
|
|
46508
46946
|
try {
|
|
46509
|
-
(0,
|
|
46947
|
+
(0, import_node_fs42.accessSync)(path2, import_node_fs42.constants.R_OK);
|
|
46510
46948
|
} catch {
|
|
46511
46949
|
continue;
|
|
46512
46950
|
}
|
|
@@ -46541,8 +46979,8 @@ var LightningWatch = class {
|
|
|
46541
46979
|
};
|
|
46542
46980
|
|
|
46543
46981
|
// src/core/tor-exits.ts
|
|
46544
|
-
var
|
|
46545
|
-
var
|
|
46982
|
+
var import_node_fs43 = require("fs");
|
|
46983
|
+
var import_node_path33 = require("path");
|
|
46546
46984
|
var import_node_net15 = require("net");
|
|
46547
46985
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
46548
46986
|
function parseTorExitList(text) {
|
|
@@ -46610,10 +47048,10 @@ var TorExitList = class _TorExitList {
|
|
|
46610
47048
|
}
|
|
46611
47049
|
loadCache() {
|
|
46612
47050
|
try {
|
|
46613
|
-
if (!(0,
|
|
46614
|
-
const parsed = parseTorExitList((0,
|
|
47051
|
+
if (!(0, import_node_fs43.existsSync)(this.opts.cachePath)) return false;
|
|
47052
|
+
const parsed = parseTorExitList((0, import_node_fs43.readFileSync)(this.opts.cachePath, "utf-8"));
|
|
46615
47053
|
if (parsed.size === 0) return false;
|
|
46616
|
-
this.load(parsed, (0,
|
|
47054
|
+
this.load(parsed, (0, import_node_fs43.statSync)(this.opts.cachePath).mtimeMs);
|
|
46617
47055
|
this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
|
|
46618
47056
|
return true;
|
|
46619
47057
|
} catch (err) {
|
|
@@ -46645,9 +47083,9 @@ var TorExitList = class _TorExitList {
|
|
|
46645
47083
|
const before2 = this.exits.size;
|
|
46646
47084
|
this.load(parsed);
|
|
46647
47085
|
try {
|
|
46648
|
-
(0,
|
|
46649
|
-
(0,
|
|
46650
|
-
(0,
|
|
47086
|
+
(0, import_node_fs43.mkdirSync)((0, import_node_path33.dirname)(this.opts.cachePath), { recursive: true });
|
|
47087
|
+
(0, import_node_fs43.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
|
|
47088
|
+
(0, import_node_fs43.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
|
|
46651
47089
|
} catch (err) {
|
|
46652
47090
|
this.log(`[tor] could not save the exit list cache: ${err.message}`);
|
|
46653
47091
|
}
|
|
@@ -46672,7 +47110,35 @@ function expire(window, now) {
|
|
|
46672
47110
|
}
|
|
46673
47111
|
var EVIDENCE_MESSAGE_CHARS = 500;
|
|
46674
47112
|
var EVIDENCE_FIELD_CHARS = 200;
|
|
46675
|
-
var EVIDENCE_FIELDS = [
|
|
47113
|
+
var EVIDENCE_FIELDS = [
|
|
47114
|
+
"unit",
|
|
47115
|
+
"identifier",
|
|
47116
|
+
"process",
|
|
47117
|
+
"comm",
|
|
47118
|
+
"pid",
|
|
47119
|
+
"user",
|
|
47120
|
+
"ssh_user",
|
|
47121
|
+
"username",
|
|
47122
|
+
"account",
|
|
47123
|
+
"runas",
|
|
47124
|
+
"command",
|
|
47125
|
+
"system_account",
|
|
47126
|
+
"system_uid",
|
|
47127
|
+
"fingerprint",
|
|
47128
|
+
"key_type",
|
|
47129
|
+
"auth_method",
|
|
47130
|
+
"port",
|
|
47131
|
+
"path",
|
|
47132
|
+
"method",
|
|
47133
|
+
"status",
|
|
47134
|
+
"host",
|
|
47135
|
+
"priority",
|
|
47136
|
+
"boot_id",
|
|
47137
|
+
"journal_cursor",
|
|
47138
|
+
"audit_session",
|
|
47139
|
+
"login_uid",
|
|
47140
|
+
"source_ip_basis"
|
|
47141
|
+
];
|
|
46676
47142
|
function evidenceOf(event) {
|
|
46677
47143
|
const details = event.details ?? {};
|
|
46678
47144
|
const out = {
|
|
@@ -46749,7 +47215,7 @@ var RuleEngine = class {
|
|
|
46749
47215
|
title: rule.title,
|
|
46750
47216
|
description: `${rule.description} (${hitsLabel} events in ${rule.window_seconds}s${spread})`,
|
|
46751
47217
|
source_ip: aggregate ? void 0 : event.source_ip,
|
|
46752
|
-
username: event.details?.user || void 0,
|
|
47218
|
+
username: (event.details?.user ?? event.details?.ssh_user ?? event.details?.username ?? event.details?.account) || void 0,
|
|
46753
47219
|
raw_metadata: {
|
|
46754
47220
|
rule_version: rule.version,
|
|
46755
47221
|
tags: rule.tags,
|
|
@@ -46837,8 +47303,8 @@ var RuleEngine = class {
|
|
|
46837
47303
|
};
|
|
46838
47304
|
|
|
46839
47305
|
// src/daemon/rules/loader.ts
|
|
46840
|
-
var
|
|
46841
|
-
var
|
|
47306
|
+
var import_node_fs44 = require("fs");
|
|
47307
|
+
var import_node_path34 = require("path");
|
|
46842
47308
|
|
|
46843
47309
|
// src/daemon/rules/default-rules.ts
|
|
46844
47310
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -47300,6 +47766,127 @@ var DEFAULT_RULES = [
|
|
|
47300
47766
|
description: "Confirm whether a capture tool or new bridge is expected on this host"
|
|
47301
47767
|
},
|
|
47302
47768
|
enabled: true
|
|
47769
|
+
},
|
|
47770
|
+
{
|
|
47771
|
+
id: "agentdb-auth-failure-burst",
|
|
47772
|
+
title: "AgentDB Authentication Failure Burst",
|
|
47773
|
+
description: "Repeated rejected credentials against the AgentDB API",
|
|
47774
|
+
version: "1.0.0",
|
|
47775
|
+
category: "auth",
|
|
47776
|
+
severity: "high",
|
|
47777
|
+
source_types: ["log-watcher"],
|
|
47778
|
+
match: {
|
|
47779
|
+
field: "service",
|
|
47780
|
+
operator: "equals",
|
|
47781
|
+
value: "agentdb",
|
|
47782
|
+
and: [{ field: "status", operator: "regex", value: "^(401|403)$" }]
|
|
47783
|
+
},
|
|
47784
|
+
threshold: 5,
|
|
47785
|
+
window_seconds: 60,
|
|
47786
|
+
cooldown_seconds: 300,
|
|
47787
|
+
tags: ["agentdb", "auth", "credential-abuse"],
|
|
47788
|
+
remediation: { action: "alert", description: "Review the source and rotate any credential that may have leaked" },
|
|
47789
|
+
enabled: true
|
|
47790
|
+
},
|
|
47791
|
+
{
|
|
47792
|
+
id: "agentdb-query-burst",
|
|
47793
|
+
title: "AgentDB Query Burst",
|
|
47794
|
+
description: "An unusually large number of database reads reached the service",
|
|
47795
|
+
version: "1.0.0",
|
|
47796
|
+
category: "web",
|
|
47797
|
+
severity: "high",
|
|
47798
|
+
source_types: ["log-watcher"],
|
|
47799
|
+
match: {
|
|
47800
|
+
field: "service",
|
|
47801
|
+
operator: "equals",
|
|
47802
|
+
value: "agentdb",
|
|
47803
|
+
and: [
|
|
47804
|
+
{ field: "path", operator: "equals", value: "/v1/query_readonly" },
|
|
47805
|
+
{ field: "status", operator: "regex", value: "^2[0-9][0-9]$" }
|
|
47806
|
+
]
|
|
47807
|
+
},
|
|
47808
|
+
threshold: 60,
|
|
47809
|
+
window_seconds: 60,
|
|
47810
|
+
cooldown_seconds: 300,
|
|
47811
|
+
group_by: "endpoint",
|
|
47812
|
+
tags: ["agentdb", "data-access", "possible-exfiltration"],
|
|
47813
|
+
remediation: { action: "alert", description: "Check the token owner and audit query volume before revoking credentials" },
|
|
47814
|
+
enabled: true
|
|
47815
|
+
},
|
|
47816
|
+
{
|
|
47817
|
+
id: "agentdb-token-creation-burst",
|
|
47818
|
+
title: "AgentDB Credential Creation Burst",
|
|
47819
|
+
description: "An operator credential created several service tokens in a short period",
|
|
47820
|
+
version: "1.0.0",
|
|
47821
|
+
category: "auth",
|
|
47822
|
+
severity: "high",
|
|
47823
|
+
source_types: ["log-watcher"],
|
|
47824
|
+
match: {
|
|
47825
|
+
field: "service",
|
|
47826
|
+
operator: "equals",
|
|
47827
|
+
value: "agentdb",
|
|
47828
|
+
and: [
|
|
47829
|
+
{ field: "path", operator: "equals", value: "/v1/tokens" },
|
|
47830
|
+
{ field: "status", operator: "regex", value: "^2[0-9][0-9]$" }
|
|
47831
|
+
]
|
|
47832
|
+
},
|
|
47833
|
+
threshold: 3,
|
|
47834
|
+
window_seconds: 60,
|
|
47835
|
+
cooldown_seconds: 600,
|
|
47836
|
+
group_by: "endpoint",
|
|
47837
|
+
tags: ["agentdb", "credentials", "persistence"],
|
|
47838
|
+
remediation: { action: "alert", description: "Check operator access and identify any newly issued token" },
|
|
47839
|
+
enabled: true
|
|
47840
|
+
},
|
|
47841
|
+
{
|
|
47842
|
+
id: "agentdb-large-query-exports",
|
|
47843
|
+
title: "Repeated Large AgentDB Query Responses",
|
|
47844
|
+
description: "Several large read-only query responses were served in a short period",
|
|
47845
|
+
version: "1.0.0",
|
|
47846
|
+
category: "web",
|
|
47847
|
+
severity: "high",
|
|
47848
|
+
source_types: ["log-watcher"],
|
|
47849
|
+
match: {
|
|
47850
|
+
field: "service",
|
|
47851
|
+
operator: "equals",
|
|
47852
|
+
value: "agentdb",
|
|
47853
|
+
and: [
|
|
47854
|
+
{ field: "path", operator: "equals", value: "/v1/query_readonly" },
|
|
47855
|
+
{ field: "status", operator: "regex", value: "^2[0-9][0-9]$" },
|
|
47856
|
+
{ field: "response_bytes", operator: "regex", value: "^[1-9][0-9]{6,}$" }
|
|
47857
|
+
]
|
|
47858
|
+
},
|
|
47859
|
+
threshold: 3,
|
|
47860
|
+
window_seconds: 600,
|
|
47861
|
+
cooldown_seconds: 600,
|
|
47862
|
+
group_by: "endpoint",
|
|
47863
|
+
tags: ["agentdb", "data-access", "large-export"],
|
|
47864
|
+
remediation: { action: "alert", description: "Review the source and revoke the token if this export was not expected" },
|
|
47865
|
+
enabled: true
|
|
47866
|
+
},
|
|
47867
|
+
{
|
|
47868
|
+
id: "agentdb-query-throttled",
|
|
47869
|
+
title: "AgentDB Read Limit Triggered",
|
|
47870
|
+
description: "AgentDB rejected a query because the client reached a service limit",
|
|
47871
|
+
version: "1.0.0",
|
|
47872
|
+
category: "web",
|
|
47873
|
+
severity: "medium",
|
|
47874
|
+
source_types: ["log-watcher"],
|
|
47875
|
+
match: {
|
|
47876
|
+
field: "service",
|
|
47877
|
+
operator: "equals",
|
|
47878
|
+
value: "agentdb",
|
|
47879
|
+
and: [
|
|
47880
|
+
{ field: "path", operator: "equals", value: "/v1/query_readonly" },
|
|
47881
|
+
{ field: "status", operator: "equals", value: "429" }
|
|
47882
|
+
]
|
|
47883
|
+
},
|
|
47884
|
+
threshold: 1,
|
|
47885
|
+
window_seconds: 60,
|
|
47886
|
+
cooldown_seconds: 300,
|
|
47887
|
+
tags: ["agentdb", "rate-limit", "data-access"],
|
|
47888
|
+
remediation: { action: "alert", description: "Review AgentDB audit metadata for the token and request pattern" },
|
|
47889
|
+
enabled: true
|
|
47303
47890
|
}
|
|
47304
47891
|
];
|
|
47305
47892
|
|
|
@@ -47308,11 +47895,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
47308
47895
|
function loadAllRules(customDir) {
|
|
47309
47896
|
const rules = [...DEFAULT_RULES];
|
|
47310
47897
|
const dir = customDir || RULES_DIR;
|
|
47311
|
-
if ((0,
|
|
47312
|
-
const files = (0,
|
|
47898
|
+
if ((0, import_node_fs44.existsSync)(dir)) {
|
|
47899
|
+
const files = (0, import_node_fs44.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
47313
47900
|
for (const file of files) {
|
|
47314
47901
|
try {
|
|
47315
|
-
const raw = (0,
|
|
47902
|
+
const raw = (0, import_node_fs44.readFileSync)((0, import_node_path34.join)(dir, file), "utf-8");
|
|
47316
47903
|
const parsed = JSON.parse(raw);
|
|
47317
47904
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
47318
47905
|
for (const rule of customRules) {
|
|
@@ -47343,9 +47930,9 @@ function loadAllRules(customDir) {
|
|
|
47343
47930
|
}
|
|
47344
47931
|
|
|
47345
47932
|
// src/daemon/firewall/adapters.ts
|
|
47346
|
-
var
|
|
47347
|
-
var
|
|
47348
|
-
var
|
|
47933
|
+
var import_node_child_process15 = require("child_process");
|
|
47934
|
+
var import_node_fs45 = require("fs");
|
|
47935
|
+
var import_node_path35 = require("path");
|
|
47349
47936
|
var import_node_net16 = require("net");
|
|
47350
47937
|
function assertValidFirewallIp(ip) {
|
|
47351
47938
|
if ((0, import_node_net16.isIP)(ip) !== 4) {
|
|
@@ -47358,9 +47945,9 @@ function assertBannableIp(ip) {
|
|
|
47358
47945
|
}
|
|
47359
47946
|
}
|
|
47360
47947
|
function writeIfAbsent(path2, contents) {
|
|
47361
|
-
(0,
|
|
47948
|
+
(0, import_node_fs45.mkdirSync)((0, import_node_path35.dirname)(path2), { recursive: true });
|
|
47362
47949
|
try {
|
|
47363
|
-
(0,
|
|
47950
|
+
(0, import_node_fs45.writeFileSync)(path2, contents, { flag: "wx" });
|
|
47364
47951
|
} catch (err) {
|
|
47365
47952
|
if (err.code !== "EEXIST") throw err;
|
|
47366
47953
|
}
|
|
@@ -47379,11 +47966,11 @@ var Fail2banAdapter = class {
|
|
|
47379
47966
|
enforces = true;
|
|
47380
47967
|
jailReady = false;
|
|
47381
47968
|
isAvailable() {
|
|
47382
|
-
const result = (0,
|
|
47969
|
+
const result = (0, import_node_child_process15.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
47383
47970
|
return result.status === 0;
|
|
47384
47971
|
}
|
|
47385
47972
|
client(args) {
|
|
47386
|
-
return (0,
|
|
47973
|
+
return (0, import_node_child_process15.execFileSync)("fail2ban-client", args, {
|
|
47387
47974
|
encoding: "utf-8",
|
|
47388
47975
|
stdio: ["ignore", "pipe", "pipe"]
|
|
47389
47976
|
});
|
|
@@ -47479,35 +48066,35 @@ var NftablesAdapter = class {
|
|
|
47479
48066
|
table = "threatcrush";
|
|
47480
48067
|
set = "blocklist";
|
|
47481
48068
|
isAvailable() {
|
|
47482
|
-
const result = (0,
|
|
48069
|
+
const result = (0, import_node_child_process15.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
47483
48070
|
return result.status === 0;
|
|
47484
48071
|
}
|
|
47485
48072
|
ensureSetup() {
|
|
47486
48073
|
try {
|
|
47487
|
-
(0,
|
|
48074
|
+
(0, import_node_child_process15.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
47488
48075
|
} catch {
|
|
47489
|
-
(0,
|
|
47490
|
-
(0,
|
|
47491
|
-
(0,
|
|
47492
|
-
(0,
|
|
48076
|
+
(0, import_node_child_process15.execSync)(`nft add table inet ${this.table}`);
|
|
48077
|
+
(0, import_node_child_process15.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
48078
|
+
(0, import_node_child_process15.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
48079
|
+
(0, import_node_child_process15.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
47493
48080
|
}
|
|
47494
48081
|
}
|
|
47495
48082
|
async block(ip) {
|
|
47496
48083
|
assertValidFirewallIp(ip);
|
|
47497
48084
|
this.ensureSetup();
|
|
47498
|
-
(0,
|
|
48085
|
+
(0, import_node_child_process15.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
47499
48086
|
}
|
|
47500
48087
|
async unblock(ip) {
|
|
47501
48088
|
assertValidFirewallIp(ip);
|
|
47502
48089
|
try {
|
|
47503
|
-
(0,
|
|
48090
|
+
(0, import_node_child_process15.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
47504
48091
|
} catch {
|
|
47505
48092
|
}
|
|
47506
48093
|
}
|
|
47507
48094
|
async isBlocked(ip) {
|
|
47508
48095
|
assertValidFirewallIp(ip);
|
|
47509
48096
|
try {
|
|
47510
|
-
const output = (0,
|
|
48097
|
+
const output = (0, import_node_child_process15.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
47511
48098
|
return output.includes(ip);
|
|
47512
48099
|
} catch {
|
|
47513
48100
|
return false;
|
|
@@ -47515,7 +48102,7 @@ var NftablesAdapter = class {
|
|
|
47515
48102
|
}
|
|
47516
48103
|
async listBlocked() {
|
|
47517
48104
|
try {
|
|
47518
|
-
const output = (0,
|
|
48105
|
+
const output = (0, import_node_child_process15.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
47519
48106
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
47520
48107
|
if (!match) return [];
|
|
47521
48108
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -47528,34 +48115,34 @@ var IptablesAdapter = class {
|
|
|
47528
48115
|
name = "iptables";
|
|
47529
48116
|
chain = "THREATCRUSH";
|
|
47530
48117
|
isAvailable() {
|
|
47531
|
-
const result = (0,
|
|
48118
|
+
const result = (0, import_node_child_process15.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
47532
48119
|
return result.status === 0;
|
|
47533
48120
|
}
|
|
47534
48121
|
ensureChain() {
|
|
47535
48122
|
try {
|
|
47536
|
-
(0,
|
|
48123
|
+
(0, import_node_child_process15.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
47537
48124
|
} catch {
|
|
47538
|
-
(0,
|
|
47539
|
-
(0,
|
|
48125
|
+
(0, import_node_child_process15.execSync)(`iptables -N ${this.chain}`);
|
|
48126
|
+
(0, import_node_child_process15.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
47540
48127
|
}
|
|
47541
48128
|
}
|
|
47542
48129
|
async block(ip) {
|
|
47543
48130
|
assertValidFirewallIp(ip);
|
|
47544
48131
|
this.ensureChain();
|
|
47545
48132
|
if (await this.isBlocked(ip)) return;
|
|
47546
|
-
(0,
|
|
48133
|
+
(0, import_node_child_process15.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
47547
48134
|
}
|
|
47548
48135
|
async unblock(ip) {
|
|
47549
48136
|
assertValidFirewallIp(ip);
|
|
47550
48137
|
try {
|
|
47551
|
-
(0,
|
|
48138
|
+
(0, import_node_child_process15.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
47552
48139
|
} catch {
|
|
47553
48140
|
}
|
|
47554
48141
|
}
|
|
47555
48142
|
async isBlocked(ip) {
|
|
47556
48143
|
assertValidFirewallIp(ip);
|
|
47557
48144
|
try {
|
|
47558
|
-
const output = (0,
|
|
48145
|
+
const output = (0, import_node_child_process15.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
47559
48146
|
return output.includes(ip);
|
|
47560
48147
|
} catch {
|
|
47561
48148
|
return false;
|
|
@@ -47563,7 +48150,7 @@ var IptablesAdapter = class {
|
|
|
47563
48150
|
}
|
|
47564
48151
|
async listBlocked() {
|
|
47565
48152
|
try {
|
|
47566
|
-
const output = (0,
|
|
48153
|
+
const output = (0, import_node_child_process15.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
47567
48154
|
const ips = [];
|
|
47568
48155
|
for (const line2 of output.split("\n")) {
|
|
47569
48156
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -47619,8 +48206,8 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
47619
48206
|
}
|
|
47620
48207
|
|
|
47621
48208
|
// src/daemon/firewall/remediation.ts
|
|
47622
|
-
var
|
|
47623
|
-
var
|
|
48209
|
+
var import_node_fs46 = require("fs");
|
|
48210
|
+
var import_node_child_process16 = require("child_process");
|
|
47624
48211
|
var import_node_net17 = require("net");
|
|
47625
48212
|
init_paths();
|
|
47626
48213
|
init_backoff();
|
|
@@ -47691,19 +48278,19 @@ var defaultDiscovery = {
|
|
|
47691
48278
|
const snapshot = takeSnapshot({
|
|
47692
48279
|
readFile: (p) => {
|
|
47693
48280
|
try {
|
|
47694
|
-
return (0,
|
|
48281
|
+
return (0, import_node_fs46.readFileSync)(p, "utf-8");
|
|
47695
48282
|
} catch {
|
|
47696
48283
|
return null;
|
|
47697
48284
|
}
|
|
47698
48285
|
},
|
|
47699
48286
|
readDir: (p) => {
|
|
47700
48287
|
try {
|
|
47701
|
-
return (0,
|
|
48288
|
+
return (0, import_node_fs46.readdirSync)(p);
|
|
47702
48289
|
} catch {
|
|
47703
48290
|
return null;
|
|
47704
48291
|
}
|
|
47705
48292
|
},
|
|
47706
|
-
exists: (p) => (0,
|
|
48293
|
+
exists: (p) => (0, import_node_fs46.existsSync)(p)
|
|
47707
48294
|
});
|
|
47708
48295
|
const out = /* @__PURE__ */ new Set();
|
|
47709
48296
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -47712,7 +48299,7 @@ var defaultDiscovery = {
|
|
|
47712
48299
|
return out;
|
|
47713
48300
|
},
|
|
47714
48301
|
keyLoginJournal: (sinceSeconds) => new Promise((resolve8) => {
|
|
47715
|
-
(0,
|
|
48302
|
+
(0, import_node_child_process16.execFile)(
|
|
47716
48303
|
"journalctl",
|
|
47717
48304
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
47718
48305
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
@@ -48216,7 +48803,7 @@ var RemediationManager = class {
|
|
|
48216
48803
|
}
|
|
48217
48804
|
logLine(line2) {
|
|
48218
48805
|
try {
|
|
48219
|
-
(0,
|
|
48806
|
+
(0, import_node_fs46.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
48220
48807
|
`);
|
|
48221
48808
|
} catch {
|
|
48222
48809
|
}
|
|
@@ -48260,19 +48847,19 @@ function remediationSettings(section) {
|
|
|
48260
48847
|
init_backoff();
|
|
48261
48848
|
|
|
48262
48849
|
// src/daemon/watchdog-service.ts
|
|
48263
|
-
var
|
|
48264
|
-
var
|
|
48850
|
+
var import_node_fs47 = require("fs");
|
|
48851
|
+
var import_node_path36 = require("path");
|
|
48265
48852
|
function defaultShareGid() {
|
|
48266
48853
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
48267
48854
|
if (!isRoot4) return void 0;
|
|
48268
48855
|
try {
|
|
48269
|
-
return (0,
|
|
48856
|
+
return (0, import_node_fs47.statSync)("/var/log/auth.log").gid;
|
|
48270
48857
|
} catch {
|
|
48271
48858
|
return void 0;
|
|
48272
48859
|
}
|
|
48273
48860
|
}
|
|
48274
48861
|
function startWatchdog(opts) {
|
|
48275
|
-
const dir = opts.config?.dir ?? (0,
|
|
48862
|
+
const dir = opts.config?.dir ?? (0, import_node_path36.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
48276
48863
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
48277
48864
|
if (opts.config?.enabled === false) {
|
|
48278
48865
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -48366,7 +48953,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
48366
48953
|
}
|
|
48367
48954
|
|
|
48368
48955
|
// src/core/node-runtime.ts
|
|
48369
|
-
var
|
|
48956
|
+
var import_node_child_process17 = require("child_process");
|
|
48370
48957
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
48371
48958
|
function nodeMajor(version) {
|
|
48372
48959
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -48380,23 +48967,23 @@ function daemonNodeProblem(version) {
|
|
|
48380
48967
|
}
|
|
48381
48968
|
function versionOfNode(path2) {
|
|
48382
48969
|
if (path2 === process.execPath) return process.versions.node;
|
|
48383
|
-
const res = (0,
|
|
48970
|
+
const res = (0, import_node_child_process17.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
48384
48971
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
48385
48972
|
}
|
|
48386
48973
|
|
|
48387
48974
|
// src/daemon/index.ts
|
|
48388
48975
|
function readVersion2() {
|
|
48389
48976
|
try {
|
|
48390
|
-
const pkg = JSON.parse((0,
|
|
48977
|
+
const pkg = JSON.parse((0, import_node_fs48.readFileSync)((0, import_node_path37.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
48391
48978
|
return pkg.version || "0.0.0";
|
|
48392
48979
|
} catch {
|
|
48393
48980
|
return "0.0.0";
|
|
48394
48981
|
}
|
|
48395
48982
|
}
|
|
48396
48983
|
async function runHardeningChecks() {
|
|
48397
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
48984
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process18.execFile)(
|
|
48398
48985
|
process.execPath,
|
|
48399
|
-
[(0,
|
|
48986
|
+
[(0, import_node_path37.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
48400
48987
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
48401
48988
|
);
|
|
48402
48989
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -48408,9 +48995,9 @@ async function runHardeningChecks() {
|
|
|
48408
48995
|
return patches ? [...findings2, patches] : findings2;
|
|
48409
48996
|
}
|
|
48410
48997
|
async function runPatchCheck() {
|
|
48411
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
48998
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process18.execFile)(
|
|
48412
48999
|
process.execPath,
|
|
48413
|
-
[(0,
|
|
49000
|
+
[(0, import_node_path37.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
48414
49001
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
48415
49002
|
);
|
|
48416
49003
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -48418,7 +49005,7 @@ async function runPatchCheck() {
|
|
|
48418
49005
|
}
|
|
48419
49006
|
function logLine(line2) {
|
|
48420
49007
|
try {
|
|
48421
|
-
(0,
|
|
49008
|
+
(0, import_node_fs48.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
48422
49009
|
`);
|
|
48423
49010
|
} catch {
|
|
48424
49011
|
}
|
|
@@ -48443,9 +49030,9 @@ async function runDaemon() {
|
|
|
48443
49030
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
48444
49031
|
const restartDaemon = () => {
|
|
48445
49032
|
if (PATHS.mode === "system") {
|
|
48446
|
-
(0,
|
|
49033
|
+
(0, import_node_child_process18.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
48447
49034
|
} else {
|
|
48448
|
-
(0,
|
|
49035
|
+
(0, import_node_child_process18.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
48449
49036
|
setTimeout(() => process.exit(0), 500).unref();
|
|
48450
49037
|
}
|
|
48451
49038
|
};
|
|
@@ -48460,7 +49047,7 @@ async function runDaemon() {
|
|
|
48460
49047
|
} catch (err) {
|
|
48461
49048
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
48462
49049
|
}
|
|
48463
|
-
const loaded = loadDaemonConfig(PATHS.configFile, (0,
|
|
49050
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path37.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
48464
49051
|
const config = loaded.config;
|
|
48465
49052
|
if (loaded.error) {
|
|
48466
49053
|
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)"}`);
|
|
@@ -48528,7 +49115,7 @@ async function runDaemon() {
|
|
|
48528
49115
|
const threatFeeds = new ThreatFeeds({
|
|
48529
49116
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
48530
49117
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
48531
|
-
cachePath: (0,
|
|
49118
|
+
cachePath: (0, import_node_path37.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
48532
49119
|
bus,
|
|
48533
49120
|
log: logLine
|
|
48534
49121
|
});
|
|
@@ -48536,14 +49123,21 @@ async function runDaemon() {
|
|
|
48536
49123
|
const privilegeWatch = new PrivilegeWatch({
|
|
48537
49124
|
settings: privilegeSettings(config.privileged),
|
|
48538
49125
|
bus,
|
|
48539
|
-
snapshotPath: (0,
|
|
48540
|
-
loginsPath: (0,
|
|
48541
|
-
cursorPath: (0,
|
|
49126
|
+
snapshotPath: (0, import_node_path37.join)(PATHS.stateDir, "privileges.json"),
|
|
49127
|
+
loginsPath: (0, import_node_path37.join)(PATHS.stateDir, "login-countries.json"),
|
|
49128
|
+
cursorPath: (0, import_node_path37.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
48542
49129
|
log: logLine
|
|
48543
49130
|
});
|
|
48544
49131
|
privilegeWatch.start();
|
|
49132
|
+
const commandHistory = new CommandHistoryWatcher({
|
|
49133
|
+
settings: commandHistorySettings(config.command_history),
|
|
49134
|
+
bus,
|
|
49135
|
+
stateDir: PATHS.stateDir,
|
|
49136
|
+
log: logLine
|
|
49137
|
+
});
|
|
49138
|
+
commandHistory.start();
|
|
48545
49139
|
const torExits = new TorExitList({
|
|
48546
|
-
cachePath: (0,
|
|
49140
|
+
cachePath: (0, import_node_path37.join)(PATHS.stateDir, "tor-exits.txt"),
|
|
48547
49141
|
url: config.remediation?.tor_exit_list_url,
|
|
48548
49142
|
log: logLine
|
|
48549
49143
|
});
|
|
@@ -48551,7 +49145,7 @@ async function runDaemon() {
|
|
|
48551
49145
|
bus,
|
|
48552
49146
|
manager: remediation,
|
|
48553
49147
|
tor: torExits,
|
|
48554
|
-
historyPath: (0,
|
|
49148
|
+
historyPath: (0, import_node_path37.join)(PATHS.stateDir, "key-logins.json"),
|
|
48555
49149
|
keyLoginWatch: config.privileged?.key_login_watch !== false,
|
|
48556
49150
|
log: logLine
|
|
48557
49151
|
});
|
|
@@ -48598,7 +49192,7 @@ async function runDaemon() {
|
|
|
48598
49192
|
version,
|
|
48599
49193
|
hostname: (0, import_node_os14.hostname)(),
|
|
48600
49194
|
minSeverity,
|
|
48601
|
-
spoolPath: (0,
|
|
49195
|
+
spoolPath: (0, import_node_path37.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
48602
49196
|
log: logLine,
|
|
48603
49197
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
48604
49198
|
runHardening: runHardeningChecks
|
|
@@ -48631,8 +49225,8 @@ async function runDaemon() {
|
|
|
48631
49225
|
const autoUpdate = autoUpdateRef = new AutoUpdate({
|
|
48632
49226
|
version,
|
|
48633
49227
|
settings: updateSettings(config.update),
|
|
48634
|
-
pkgRoot: (0,
|
|
48635
|
-
statePath: (0,
|
|
49228
|
+
pkgRoot: (0, import_node_path37.join)(__dirname, ".."),
|
|
49229
|
+
statePath: (0, import_node_path37.join)(PATHS.stateDir, "auto-update.json"),
|
|
48636
49230
|
bus,
|
|
48637
49231
|
log: logLine,
|
|
48638
49232
|
restartDaemon
|
|
@@ -48687,6 +49281,10 @@ async function runDaemon() {
|
|
|
48687
49281
|
privilegeWatch.stop();
|
|
48688
49282
|
} catch {
|
|
48689
49283
|
}
|
|
49284
|
+
try {
|
|
49285
|
+
commandHistory.stop();
|
|
49286
|
+
} catch {
|
|
49287
|
+
}
|
|
48690
49288
|
try {
|
|
48691
49289
|
sshIntrusion.stop();
|
|
48692
49290
|
} catch {
|
|
@@ -48730,7 +49328,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
48730
49328
|
function isRoot2() {
|
|
48731
49329
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
48732
49330
|
}
|
|
48733
|
-
var DAEMON_ENTRY = (0,
|
|
49331
|
+
var DAEMON_ENTRY = (0, import_node_path38.join)(__dirname, "daemon.js");
|
|
48734
49332
|
async function daemonForeground() {
|
|
48735
49333
|
await runDaemon();
|
|
48736
49334
|
}
|
|
@@ -48751,7 +49349,7 @@ async function daemonStart() {
|
|
|
48751
49349
|
return;
|
|
48752
49350
|
}
|
|
48753
49351
|
ensureRuntimeDirs();
|
|
48754
|
-
if (!(0,
|
|
49352
|
+
if (!(0, import_node_fs49.existsSync)(DAEMON_ENTRY)) {
|
|
48755
49353
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
48756
49354
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
48757
49355
|
return;
|
|
@@ -48759,8 +49357,8 @@ async function daemonStart() {
|
|
|
48759
49357
|
let out;
|
|
48760
49358
|
let err;
|
|
48761
49359
|
try {
|
|
48762
|
-
out = (0,
|
|
48763
|
-
err = (0,
|
|
49360
|
+
out = (0, import_node_fs50.openSync)(PATHS.logFile, "a");
|
|
49361
|
+
err = (0, import_node_fs50.openSync)(PATHS.logFile, "a");
|
|
48764
49362
|
} catch (e) {
|
|
48765
49363
|
const code = e.code;
|
|
48766
49364
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -48773,7 +49371,7 @@ async function daemonStart() {
|
|
|
48773
49371
|
}
|
|
48774
49372
|
return;
|
|
48775
49373
|
}
|
|
48776
|
-
const child = (0,
|
|
49374
|
+
const child = (0, import_node_child_process19.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
48777
49375
|
detached: true,
|
|
48778
49376
|
stdio: ["ignore", out, err],
|
|
48779
49377
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -48848,41 +49446,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
48848
49446
|
}
|
|
48849
49447
|
async function releaseStaleSocket() {
|
|
48850
49448
|
const deadline = Date.now() + 2e3;
|
|
48851
|
-
while ((0,
|
|
49449
|
+
while ((0, import_node_fs49.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
48852
49450
|
await new Promise((r) => setTimeout(r, 50));
|
|
48853
49451
|
}
|
|
48854
|
-
if ((0,
|
|
49452
|
+
if ((0, import_node_fs49.existsSync)(PATHS.socket)) {
|
|
48855
49453
|
try {
|
|
48856
|
-
(0,
|
|
49454
|
+
(0, import_node_fs49.unlinkSync)(PATHS.socket);
|
|
48857
49455
|
} catch {
|
|
48858
49456
|
}
|
|
48859
49457
|
}
|
|
48860
49458
|
}
|
|
48861
49459
|
|
|
48862
49460
|
// src/commands/service.ts
|
|
48863
|
-
var
|
|
48864
|
-
var
|
|
48865
|
-
var
|
|
49461
|
+
var import_node_child_process20 = require("child_process");
|
|
49462
|
+
var import_node_fs51 = require("fs");
|
|
49463
|
+
var import_node_path39 = require("path");
|
|
48866
49464
|
var import_node_os15 = require("os");
|
|
48867
49465
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
48868
49466
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
48869
49467
|
function resolveTemplate() {
|
|
48870
|
-
const templatePath = (0,
|
|
48871
|
-
if (!(0,
|
|
49468
|
+
const templatePath = (0, import_node_path39.join)(__dirname, "systemd", "threatcrushd.service");
|
|
49469
|
+
if (!(0, import_node_fs51.existsSync)(templatePath)) {
|
|
48872
49470
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
48873
49471
|
}
|
|
48874
|
-
return (0,
|
|
49472
|
+
return (0, import_node_fs51.readFileSync)(templatePath, "utf-8");
|
|
48875
49473
|
}
|
|
48876
49474
|
function stableBinPath(binPath) {
|
|
48877
49475
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
48878
49476
|
if (stable === binPath) return binPath;
|
|
48879
|
-
return (0,
|
|
49477
|
+
return (0, import_node_fs51.existsSync)(stable) ? stable : binPath;
|
|
48880
49478
|
}
|
|
48881
49479
|
function resolveBinPath() {
|
|
48882
49480
|
const arg = process.argv[1];
|
|
48883
|
-
if (arg && (0,
|
|
49481
|
+
if (arg && (0, import_node_fs51.existsSync)(arg)) return stableBinPath(arg);
|
|
48884
49482
|
try {
|
|
48885
|
-
return (0,
|
|
49483
|
+
return (0, import_node_child_process20.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
48886
49484
|
} catch {
|
|
48887
49485
|
return "threatcrush";
|
|
48888
49486
|
}
|
|
@@ -48890,11 +49488,11 @@ function resolveBinPath() {
|
|
|
48890
49488
|
function stableNodePath(execPath) {
|
|
48891
49489
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
48892
49490
|
if (stable === execPath) return execPath;
|
|
48893
|
-
return (0,
|
|
49491
|
+
return (0, import_node_fs51.existsSync)(stable) ? stable : execPath;
|
|
48894
49492
|
}
|
|
48895
49493
|
function looksLikeNodeScript(path2) {
|
|
48896
49494
|
try {
|
|
48897
|
-
const head = (0,
|
|
49495
|
+
const head = (0, import_node_fs51.readFileSync)(path2, "utf-8").slice(0, 120);
|
|
48898
49496
|
return /^#!.*\bnode\b/.test(head);
|
|
48899
49497
|
} catch {
|
|
48900
49498
|
return false;
|
|
@@ -48904,7 +49502,7 @@ function execStartCommand(binPath, nodePath, isNodeScript) {
|
|
|
48904
49502
|
return isNodeScript ? `${nodePath} ${binPath} daemon` : `${binPath} daemon`;
|
|
48905
49503
|
}
|
|
48906
49504
|
function renderUnit(template, opts) {
|
|
48907
|
-
return template.replaceAll("{{BIN_PATH}} daemon", opts.exec).replaceAll("{{BIN_PATH}}", opts.binPath).replaceAll("{{CONFIG_DIR}}", opts.configDir);
|
|
49505
|
+
return template.replaceAll("{{BIN_PATH}} daemon", opts.exec).replaceAll("{{BIN_PATH}}", opts.binPath).replaceAll("{{CONFIG_DIR}}", opts.configDir).replaceAll("{{HISTORY_PATHS}}", (opts.historyPaths ?? []).map((path2) => `-${path2}`).join(" ")).replace(/ReadWritePaths=([^\n]*)/, (_line, paths) => `ReadWritePaths=${paths.split(/\s+/).filter(Boolean).join(" ")}`);
|
|
48908
49506
|
}
|
|
48909
49507
|
function nodeVersionDir(path2) {
|
|
48910
49508
|
const m = path2.match(
|
|
@@ -48921,20 +49519,20 @@ function isRoot3() {
|
|
|
48921
49519
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
48922
49520
|
}
|
|
48923
49521
|
function reexecWithSudo(args) {
|
|
48924
|
-
if ((0,
|
|
49522
|
+
if ((0, import_node_child_process20.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
48925
49523
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
48926
49524
|
const bin = resolveBinPath();
|
|
48927
49525
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
48928
|
-
const result = (0,
|
|
49526
|
+
const result = (0, import_node_child_process20.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
48929
49527
|
return result.status === 0;
|
|
48930
49528
|
}
|
|
48931
49529
|
function callerHome() {
|
|
48932
49530
|
const user = process.env.SUDO_USER;
|
|
48933
49531
|
if (!user) return null;
|
|
48934
49532
|
try {
|
|
48935
|
-
const line2 = (0,
|
|
49533
|
+
const line2 = (0, import_node_child_process20.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
48936
49534
|
const home = line2.split(":")[5];
|
|
48937
|
-
return home && (0,
|
|
49535
|
+
return home && (0, import_node_fs51.existsSync)(home) ? home : null;
|
|
48938
49536
|
} catch {
|
|
48939
49537
|
return null;
|
|
48940
49538
|
}
|
|
@@ -48942,13 +49540,13 @@ function callerHome() {
|
|
|
48942
49540
|
function stopUserModeDaemon() {
|
|
48943
49541
|
const home = callerHome();
|
|
48944
49542
|
if (!home) return;
|
|
48945
|
-
const runDir = (0,
|
|
48946
|
-
const pidFile = (0,
|
|
48947
|
-
const socket = (0,
|
|
48948
|
-
if (!(0,
|
|
49543
|
+
const runDir = (0, import_node_path39.join)(home, ".threatcrush", "run");
|
|
49544
|
+
const pidFile = (0, import_node_path39.join)(runDir, "threatcrushd.pid");
|
|
49545
|
+
const socket = (0, import_node_path39.join)(runDir, "threatcrushd.sock");
|
|
49546
|
+
if (!(0, import_node_fs51.existsSync)(pidFile) && !(0, import_node_fs51.existsSync)(socket)) return;
|
|
48949
49547
|
let pid = null;
|
|
48950
49548
|
try {
|
|
48951
|
-
pid = Number.parseInt((0,
|
|
49549
|
+
pid = Number.parseInt((0, import_node_fs51.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
48952
49550
|
} catch {
|
|
48953
49551
|
pid = null;
|
|
48954
49552
|
}
|
|
@@ -48961,13 +49559,13 @@ function stopUserModeDaemon() {
|
|
|
48961
49559
|
}
|
|
48962
49560
|
for (const path2 of [socket, pidFile]) {
|
|
48963
49561
|
try {
|
|
48964
|
-
if ((0,
|
|
49562
|
+
if ((0, import_node_fs51.existsSync)(path2)) (0, import_node_fs51.rmSync)(path2);
|
|
48965
49563
|
} catch {
|
|
48966
49564
|
}
|
|
48967
49565
|
}
|
|
48968
49566
|
}
|
|
48969
49567
|
function unitIsActive() {
|
|
48970
|
-
const result = (0,
|
|
49568
|
+
const result = (0, import_node_child_process20.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
48971
49569
|
return result.status === 0;
|
|
48972
49570
|
}
|
|
48973
49571
|
async function installServiceCommand() {
|
|
@@ -48978,8 +49576,8 @@ async function installServiceCommand() {
|
|
|
48978
49576
|
return;
|
|
48979
49577
|
}
|
|
48980
49578
|
const noSystemd = systemdUnavailableReason({
|
|
48981
|
-
hasSystemctl: (0,
|
|
48982
|
-
booted: (0,
|
|
49579
|
+
hasSystemctl: (0, import_node_child_process20.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
49580
|
+
booted: (0, import_node_fs51.existsSync)("/run/systemd/system")
|
|
48983
49581
|
});
|
|
48984
49582
|
if (noSystemd) {
|
|
48985
49583
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -49001,7 +49599,7 @@ async function installServiceCommand() {
|
|
|
49001
49599
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
49002
49600
|
let nodePath = stableNodePath(process.execPath);
|
|
49003
49601
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
49004
|
-
binPath = (0,
|
|
49602
|
+
binPath = (0, import_node_fs51.realpathSync)(binPath);
|
|
49005
49603
|
nodePath = process.execPath;
|
|
49006
49604
|
}
|
|
49007
49605
|
if (isNodeScript) {
|
|
@@ -49014,9 +49612,11 @@ async function installServiceCommand() {
|
|
|
49014
49612
|
}
|
|
49015
49613
|
}
|
|
49016
49614
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
49017
|
-
const configDir = (0,
|
|
49018
|
-
const
|
|
49019
|
-
|
|
49615
|
+
const configDir = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush");
|
|
49616
|
+
const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
|
|
49617
|
+
const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
|
|
49618
|
+
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
|
|
49619
|
+
(0, import_node_fs51.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
49020
49620
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
49021
49621
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
49022
49622
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -49031,8 +49631,8 @@ async function installServiceCommand() {
|
|
|
49031
49631
|
installLogrotate();
|
|
49032
49632
|
stopUserModeDaemon();
|
|
49033
49633
|
try {
|
|
49034
|
-
(0,
|
|
49035
|
-
(0,
|
|
49634
|
+
(0, import_node_child_process20.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
49635
|
+
(0, import_node_child_process20.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
49036
49636
|
} catch (err) {
|
|
49037
49637
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
49038
49638
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -49069,9 +49669,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
49069
49669
|
].join("\n");
|
|
49070
49670
|
}
|
|
49071
49671
|
function installLogrotate() {
|
|
49072
|
-
if (!(0,
|
|
49672
|
+
if (!(0, import_node_fs51.existsSync)((0, import_node_path39.dirname)(LOGROTATE_PATH))) return;
|
|
49073
49673
|
try {
|
|
49074
|
-
(0,
|
|
49674
|
+
(0, import_node_fs51.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
49075
49675
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
49076
49676
|
} catch (err) {
|
|
49077
49677
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -49093,20 +49693,20 @@ function ensureSystemDirs(configDir) {
|
|
|
49093
49693
|
];
|
|
49094
49694
|
let admGid2 = null;
|
|
49095
49695
|
try {
|
|
49096
|
-
admGid2 = (0,
|
|
49696
|
+
admGid2 = (0, import_node_fs51.statSync)("/var/log/auth.log").gid;
|
|
49097
49697
|
} catch {
|
|
49098
49698
|
}
|
|
49099
49699
|
for (const { path: path2, groupWritable, sticky } of dirs) {
|
|
49100
49700
|
try {
|
|
49101
|
-
(0,
|
|
49701
|
+
(0, import_node_fs51.mkdirSync)(path2, { recursive: true });
|
|
49102
49702
|
} catch {
|
|
49103
49703
|
}
|
|
49104
49704
|
try {
|
|
49105
49705
|
if (groupWritable && admGid2 !== null) {
|
|
49106
|
-
(0,
|
|
49107
|
-
(0,
|
|
49706
|
+
(0, import_node_fs51.chmodSync)(path2, sticky ? 1533 : 509);
|
|
49707
|
+
(0, import_node_child_process20.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
|
|
49108
49708
|
} else {
|
|
49109
|
-
(0,
|
|
49709
|
+
(0, import_node_fs51.chmodSync)(path2, 493);
|
|
49110
49710
|
}
|
|
49111
49711
|
} catch {
|
|
49112
49712
|
}
|
|
@@ -49126,29 +49726,29 @@ async function uninstallServiceCommand() {
|
|
|
49126
49726
|
return;
|
|
49127
49727
|
}
|
|
49128
49728
|
try {
|
|
49129
|
-
(0,
|
|
49729
|
+
(0, import_node_child_process20.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
49130
49730
|
} catch {
|
|
49131
49731
|
}
|
|
49132
49732
|
try {
|
|
49133
|
-
(0,
|
|
49733
|
+
(0, import_node_child_process20.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
49134
49734
|
} catch {
|
|
49135
49735
|
}
|
|
49136
49736
|
try {
|
|
49137
|
-
if ((0,
|
|
49138
|
-
(0,
|
|
49737
|
+
if ((0, import_node_fs51.existsSync)(UNIT_PATH)) {
|
|
49738
|
+
(0, import_node_child_process20.execSync)(`rm -f ${UNIT_PATH}`);
|
|
49139
49739
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
49140
49740
|
}
|
|
49141
49741
|
} catch {
|
|
49142
49742
|
}
|
|
49143
49743
|
try {
|
|
49144
|
-
(0,
|
|
49744
|
+
(0, import_node_child_process20.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
49145
49745
|
} catch {
|
|
49146
49746
|
}
|
|
49147
49747
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
49148
49748
|
}
|
|
49149
49749
|
|
|
49150
49750
|
// src/commands/save.ts
|
|
49151
|
-
var
|
|
49751
|
+
var import_node_fs52 = require("fs");
|
|
49152
49752
|
var import_toml5 = __toESM(require_toml());
|
|
49153
49753
|
init_cli_config();
|
|
49154
49754
|
init_paths();
|
|
@@ -49187,9 +49787,9 @@ async function saveCommand(opts = {}) {
|
|
|
49187
49787
|
}
|
|
49188
49788
|
const path2 = opts.config ?? PATHS.configFile;
|
|
49189
49789
|
let config = {};
|
|
49190
|
-
if ((0,
|
|
49790
|
+
if ((0, import_node_fs52.existsSync)(path2)) {
|
|
49191
49791
|
try {
|
|
49192
|
-
config = import_toml5.default.parse((0,
|
|
49792
|
+
config = import_toml5.default.parse((0, import_node_fs52.readFileSync)(path2, "utf-8"));
|
|
49193
49793
|
} catch (err) {
|
|
49194
49794
|
console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
|
|
49195
49795
|
`));
|
|
@@ -49302,8 +49902,8 @@ function welcomeCommand() {
|
|
|
49302
49902
|
}
|
|
49303
49903
|
|
|
49304
49904
|
// src/commands/properties.ts
|
|
49305
|
-
var
|
|
49306
|
-
var
|
|
49905
|
+
var import_node_fs53 = require("fs");
|
|
49906
|
+
var import_node_path40 = require("path");
|
|
49307
49907
|
var import_node_readline4 = __toESM(require("readline"));
|
|
49308
49908
|
init_cli_config();
|
|
49309
49909
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -49633,8 +50233,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
49633
50233
|
}
|
|
49634
50234
|
}
|
|
49635
50235
|
function parseImportFile(path2) {
|
|
49636
|
-
const ext = (0,
|
|
49637
|
-
const raw = (0,
|
|
50236
|
+
const ext = (0, import_node_path40.extname)(path2).toLowerCase();
|
|
50237
|
+
const raw = (0, import_node_fs53.readFileSync)(path2, "utf-8");
|
|
49638
50238
|
if (ext === ".json") {
|
|
49639
50239
|
const parsed = JSON.parse(raw);
|
|
49640
50240
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -49829,19 +50429,19 @@ async function rulesCommand(opts) {
|
|
|
49829
50429
|
}
|
|
49830
50430
|
|
|
49831
50431
|
// src/commands/harden.ts
|
|
49832
|
-
var
|
|
49833
|
-
var
|
|
50432
|
+
var import_node_fs54 = require("fs");
|
|
50433
|
+
var import_node_child_process21 = require("child_process");
|
|
49834
50434
|
init_cli_config();
|
|
49835
50435
|
function tryExec(cmd) {
|
|
49836
50436
|
try {
|
|
49837
|
-
return (0,
|
|
50437
|
+
return (0, import_node_child_process21.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
49838
50438
|
} catch {
|
|
49839
50439
|
return null;
|
|
49840
50440
|
}
|
|
49841
50441
|
}
|
|
49842
50442
|
function tryRead(path2) {
|
|
49843
50443
|
try {
|
|
49844
|
-
return (0,
|
|
50444
|
+
return (0, import_node_fs54.readFileSync)(path2, "utf-8");
|
|
49845
50445
|
} catch {
|
|
49846
50446
|
return null;
|
|
49847
50447
|
}
|
|
@@ -49945,8 +50545,8 @@ function checkSshWeakConfig() {
|
|
|
49945
50545
|
};
|
|
49946
50546
|
}
|
|
49947
50547
|
function checkAutoUpdates() {
|
|
49948
|
-
const unattended = (0,
|
|
49949
|
-
const dnfAuto = (0,
|
|
50548
|
+
const unattended = (0, import_node_fs54.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs54.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
50549
|
+
const dnfAuto = (0, import_node_fs54.existsSync)("/etc/dnf/automatic.conf");
|
|
49950
50550
|
if (unattended || dnfAuto) {
|
|
49951
50551
|
return {
|
|
49952
50552
|
key: "auto-updates",
|
|
@@ -50072,7 +50672,7 @@ function checkFail2ban() {
|
|
|
50072
50672
|
explanation: "fail2ban is installed and running."
|
|
50073
50673
|
};
|
|
50074
50674
|
}
|
|
50075
|
-
if ((0,
|
|
50675
|
+
if ((0, import_node_fs54.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
50076
50676
|
return {
|
|
50077
50677
|
key: checkKey,
|
|
50078
50678
|
status: "warn",
|
|
@@ -50258,9 +50858,9 @@ async function hardenCommand(opts) {
|
|
|
50258
50858
|
}
|
|
50259
50859
|
|
|
50260
50860
|
// src/core/patches/index.ts
|
|
50261
|
-
var
|
|
50262
|
-
var
|
|
50263
|
-
var
|
|
50861
|
+
var import_node_fs55 = require("fs");
|
|
50862
|
+
var import_node_path41 = require("path");
|
|
50863
|
+
var import_node_child_process22 = require("child_process");
|
|
50264
50864
|
var import_node_util5 = require("util");
|
|
50265
50865
|
|
|
50266
50866
|
// src/core/patches/dpkg-version.ts
|
|
@@ -50320,7 +50920,7 @@ var STALE_AFTER_MS = 2 * 864e5;
|
|
|
50320
50920
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
50321
50921
|
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
50322
50922
|
var defaultExec = async (file, args) => {
|
|
50323
|
-
const { stdout } = await (0, import_node_util5.promisify)(
|
|
50923
|
+
const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process22.execFile)(file, args, {
|
|
50324
50924
|
timeout: 12e4,
|
|
50325
50925
|
maxBuffer: 32 * 1024 * 1024,
|
|
50326
50926
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -50419,9 +51019,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
50419
51019
|
function newestReleaseMtime(dir) {
|
|
50420
51020
|
try {
|
|
50421
51021
|
let newest = 0;
|
|
50422
|
-
for (const name of (0,
|
|
51022
|
+
for (const name of (0, import_node_fs55.readdirSync)(dir)) {
|
|
50423
51023
|
if (!/Release$/.test(name)) continue;
|
|
50424
|
-
newest = Math.max(newest, (0,
|
|
51024
|
+
newest = Math.max(newest, (0, import_node_fs55.statSync)((0, import_node_path41.join)(dir, name)).mtimeMs);
|
|
50425
51025
|
}
|
|
50426
51026
|
return newest > 0 ? new Date(newest) : null;
|
|
50427
51027
|
} catch {
|
|
@@ -50438,7 +51038,7 @@ async function checkPatches(opts = {}) {
|
|
|
50438
51038
|
let osText = opts.osRelease;
|
|
50439
51039
|
if (osText === void 0) {
|
|
50440
51040
|
try {
|
|
50441
|
-
osText = (0,
|
|
51041
|
+
osText = (0, import_node_fs55.readFileSync)("/etc/os-release", "utf-8");
|
|
50442
51042
|
} catch {
|
|
50443
51043
|
osText = "";
|
|
50444
51044
|
}
|
|
@@ -50665,26 +51265,26 @@ async function patchesCommand(opts) {
|
|
|
50665
51265
|
|
|
50666
51266
|
// src/commands/feeds.ts
|
|
50667
51267
|
var import_node_net18 = require("net");
|
|
50668
|
-
var
|
|
51268
|
+
var import_node_path43 = require("path");
|
|
50669
51269
|
init_paths();
|
|
50670
51270
|
|
|
50671
51271
|
// src/commands/feeds-resolver.ts
|
|
50672
|
-
var
|
|
50673
|
-
var
|
|
50674
|
-
var
|
|
51272
|
+
var import_node_child_process23 = require("child_process");
|
|
51273
|
+
var import_node_fs56 = require("fs");
|
|
51274
|
+
var import_node_path42 = require("path");
|
|
50675
51275
|
var realIO = {
|
|
50676
|
-
exists: (p) => (0,
|
|
51276
|
+
exists: (p) => (0, import_node_fs56.existsSync)(p),
|
|
50677
51277
|
read: (p) => {
|
|
50678
51278
|
try {
|
|
50679
|
-
return (0,
|
|
51279
|
+
return (0, import_node_fs56.readFileSync)(p, "utf-8");
|
|
50680
51280
|
} catch {
|
|
50681
51281
|
return null;
|
|
50682
51282
|
}
|
|
50683
51283
|
},
|
|
50684
|
-
write: (p, c) => (0,
|
|
50685
|
-
remove: (p) => (0,
|
|
51284
|
+
write: (p, c) => (0, import_node_fs56.writeFileSync)(p, c),
|
|
51285
|
+
remove: (p) => (0, import_node_fs56.rmSync)(p, { force: true }),
|
|
50686
51286
|
run: (cmd, args) => {
|
|
50687
|
-
const r = (0,
|
|
51287
|
+
const r = (0, import_node_child_process23.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
50688
51288
|
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
50689
51289
|
}
|
|
50690
51290
|
};
|
|
@@ -50692,17 +51292,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
|
50692
51292
|
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
50693
51293
|
function hookContent(resolver, stateDir) {
|
|
50694
51294
|
const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
50695
|
-
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0,
|
|
50696
|
-
` : `${head}include: "${(0,
|
|
51295
|
+
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path42.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
51296
|
+
` : `${head}include: "${(0, import_node_path42.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
50697
51297
|
`;
|
|
50698
51298
|
}
|
|
50699
51299
|
function apparmorRule(stateDir) {
|
|
50700
|
-
return ` ${(0,
|
|
51300
|
+
return ` ${(0, import_node_path42.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
50701
51301
|
}
|
|
50702
51302
|
function detectResolvers(io = realIO) {
|
|
50703
51303
|
const found = [];
|
|
50704
|
-
if (io.exists((0,
|
|
50705
|
-
if (io.exists((0,
|
|
51304
|
+
if (io.exists((0, import_node_path42.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
51305
|
+
if (io.exists((0, import_node_path42.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
50706
51306
|
return found;
|
|
50707
51307
|
}
|
|
50708
51308
|
function check(resolver, io) {
|
|
@@ -50715,7 +51315,7 @@ function restartIfActive(resolver, io) {
|
|
|
50715
51315
|
}
|
|
50716
51316
|
function installHook(resolver, stateDir, io = realIO) {
|
|
50717
51317
|
const hook = RESOLVER_HOOKS[resolver];
|
|
50718
|
-
const file = (0,
|
|
51318
|
+
const file = (0, import_node_path42.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
50719
51319
|
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
50720
51320
|
io.write(hook, hookContent(resolver, stateDir));
|
|
50721
51321
|
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
@@ -50776,8 +51376,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
50776
51376
|
}
|
|
50777
51377
|
return failed ? 1 : 0;
|
|
50778
51378
|
}
|
|
50779
|
-
const hosts = io.read((0,
|
|
50780
|
-
const unbound = io.read((0,
|
|
51379
|
+
const hosts = io.read((0, import_node_path42.join)(stateDir, RESOLVER_FILES.hosts));
|
|
51380
|
+
const unbound = io.read((0, import_node_path42.join)(stateDir, RESOLVER_FILES.unbound));
|
|
50781
51381
|
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
50782
51382
|
for (const r of ["dnsmasq", "unbound"]) {
|
|
50783
51383
|
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
@@ -50789,11 +51389,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
|
|
|
50789
51389
|
// src/commands/feeds.ts
|
|
50790
51390
|
async function loadSet() {
|
|
50791
51391
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
50792
|
-
const path2 = (0,
|
|
51392
|
+
const path2 = (0, import_node_path43.join)(dir, "threat-feeds.json");
|
|
50793
51393
|
const set = readFeedCache(path2);
|
|
50794
51394
|
if (set) return { set, from: path2 };
|
|
50795
51395
|
}
|
|
50796
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
51396
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path43.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
50797
51397
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
50798
51398
|
}
|
|
50799
51399
|
async function feedsCommand(action, value, opts) {
|
|
@@ -50837,21 +51437,21 @@ async function feedsCommand(action, value, opts) {
|
|
|
50837
51437
|
}
|
|
50838
51438
|
|
|
50839
51439
|
// src/commands/tor.ts
|
|
50840
|
-
var
|
|
51440
|
+
var import_node_fs57 = require("fs");
|
|
50841
51441
|
var import_node_net19 = require("net");
|
|
50842
|
-
var
|
|
51442
|
+
var import_node_path44 = require("path");
|
|
50843
51443
|
init_paths();
|
|
50844
51444
|
async function torCommand(action, value, opts) {
|
|
50845
51445
|
let exits = /* @__PURE__ */ new Set();
|
|
50846
51446
|
let from = "";
|
|
50847
51447
|
let updated = null;
|
|
50848
51448
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
50849
|
-
const path2 = (0,
|
|
51449
|
+
const path2 = (0, import_node_path44.join)(dir, "tor-exits.txt");
|
|
50850
51450
|
try {
|
|
50851
|
-
if (!(0,
|
|
50852
|
-
exits = parseTorExitList((0,
|
|
51451
|
+
if (!(0, import_node_fs57.existsSync)(path2)) continue;
|
|
51452
|
+
exits = parseTorExitList((0, import_node_fs57.readFileSync)(path2, "utf-8"));
|
|
50853
51453
|
from = path2;
|
|
50854
|
-
updated = (0,
|
|
51454
|
+
updated = (0, import_node_fs57.statSync)(path2).mtime;
|
|
50855
51455
|
break;
|
|
50856
51456
|
} catch {
|
|
50857
51457
|
}
|
|
@@ -50867,7 +51467,7 @@ async function torCommand(action, value, opts) {
|
|
|
50867
51467
|
} catch {
|
|
50868
51468
|
}
|
|
50869
51469
|
}
|
|
50870
|
-
const remediation = loadConfig((0,
|
|
51470
|
+
const remediation = loadConfig((0, import_node_path44.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
50871
51471
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
50872
51472
|
if (action === "check") {
|
|
50873
51473
|
if (!value || !(0, import_node_net19.isIP)(value)) {
|
|
@@ -50899,13 +51499,13 @@ async function torCommand(action, value, opts) {
|
|
|
50899
51499
|
|
|
50900
51500
|
// src/commands/reputation.ts
|
|
50901
51501
|
var import_node_os16 = require("os");
|
|
50902
|
-
var
|
|
50903
|
-
var
|
|
51502
|
+
var import_node_fs58 = require("fs");
|
|
51503
|
+
var import_node_path45 = require("path");
|
|
50904
51504
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
50905
|
-
var CONFIG_PATH4 = (0,
|
|
51505
|
+
var CONFIG_PATH4 = (0, import_node_path45.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
|
|
50906
51506
|
function readConfig3() {
|
|
50907
51507
|
try {
|
|
50908
|
-
return JSON.parse((0,
|
|
51508
|
+
return JSON.parse((0, import_node_fs58.readFileSync)(CONFIG_PATH4, "utf-8"));
|
|
50909
51509
|
} catch {
|
|
50910
51510
|
return {};
|
|
50911
51511
|
}
|
|
@@ -51093,7 +51693,7 @@ async function reputationSubscribeCommand(opts) {
|
|
|
51093
51693
|
}
|
|
51094
51694
|
|
|
51095
51695
|
// src/commands/privileged.ts
|
|
51096
|
-
var
|
|
51696
|
+
var import_node_fs59 = require("fs");
|
|
51097
51697
|
init_paths();
|
|
51098
51698
|
var SEV2 = {
|
|
51099
51699
|
critical: source_default.red.bold,
|
|
@@ -51106,19 +51706,19 @@ async function privilegedCommand(opts) {
|
|
|
51106
51706
|
const snapshot = takeSnapshot({
|
|
51107
51707
|
readFile: (p) => {
|
|
51108
51708
|
try {
|
|
51109
|
-
return (0,
|
|
51709
|
+
return (0, import_node_fs59.readFileSync)(p, "utf-8");
|
|
51110
51710
|
} catch {
|
|
51111
51711
|
return null;
|
|
51112
51712
|
}
|
|
51113
51713
|
},
|
|
51114
51714
|
readDir: (p) => {
|
|
51115
51715
|
try {
|
|
51116
|
-
return (0,
|
|
51716
|
+
return (0, import_node_fs59.readdirSync)(p);
|
|
51117
51717
|
} catch {
|
|
51118
51718
|
return null;
|
|
51119
51719
|
}
|
|
51120
51720
|
},
|
|
51121
|
-
exists: (p) => (0,
|
|
51721
|
+
exists: (p) => (0, import_node_fs59.existsSync)(p)
|
|
51122
51722
|
});
|
|
51123
51723
|
let events = [];
|
|
51124
51724
|
let ledgerNote = "";
|
|
@@ -51300,7 +51900,7 @@ async function allowlistCommand(opts) {
|
|
|
51300
51900
|
}
|
|
51301
51901
|
|
|
51302
51902
|
// src/commands/abuse.ts
|
|
51303
|
-
var
|
|
51903
|
+
var import_node_fs60 = require("fs");
|
|
51304
51904
|
init_paths();
|
|
51305
51905
|
function rows(records) {
|
|
51306
51906
|
if (records.length === 0) {
|
|
@@ -51360,7 +51960,7 @@ function abuseRetractCommand(id, opts = {}) {
|
|
|
51360
51960
|
);
|
|
51361
51961
|
}
|
|
51362
51962
|
function abuseStatusCommand(opts = {}) {
|
|
51363
|
-
const config = loadConfig((0,
|
|
51963
|
+
const config = loadConfig((0, import_node_fs60.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
51364
51964
|
const cfg = resolveConfig(config.abuse_reporter);
|
|
51365
51965
|
const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
|
|
51366
51966
|
const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
|
|
@@ -51383,11 +51983,11 @@ function abuseStatusCommand(opts = {}) {
|
|
|
51383
51983
|
init_paths();
|
|
51384
51984
|
|
|
51385
51985
|
// src/upgrade.ts
|
|
51386
|
-
var
|
|
51986
|
+
var import_node_child_process24 = require("child_process");
|
|
51387
51987
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
51388
51988
|
var defaultRunner = (cmd) => {
|
|
51389
51989
|
try {
|
|
51390
|
-
return (0,
|
|
51990
|
+
return (0, import_node_child_process24.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
51391
51991
|
} catch {
|
|
51392
51992
|
return null;
|
|
51393
51993
|
}
|
|
@@ -51528,9 +52128,9 @@ function installUserAgent(target = globalThis) {
|
|
|
51528
52128
|
}
|
|
51529
52129
|
|
|
51530
52130
|
// src/core/cloud-upload.ts
|
|
51531
|
-
var
|
|
52131
|
+
var import_node_child_process25 = require("child_process");
|
|
51532
52132
|
var import_node_os17 = require("os");
|
|
51533
|
-
var
|
|
52133
|
+
var import_node_path46 = require("path");
|
|
51534
52134
|
init_cli_config();
|
|
51535
52135
|
function uploadDisabled(upload, env3 = process.env) {
|
|
51536
52136
|
if (upload === false) return true;
|
|
@@ -51549,8 +52149,8 @@ function cleanUrl(raw) {
|
|
|
51549
52149
|
return raw.split(/[?#]/)[0];
|
|
51550
52150
|
}
|
|
51551
52151
|
}
|
|
51552
|
-
function repoTarget(path2, run = (args) => (0,
|
|
51553
|
-
const abs = (0,
|
|
52152
|
+
function repoTarget(path2, run = (args) => (0, import_node_child_process25.execFileSync)("git", args, { cwd: (0, import_node_path46.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
|
|
52153
|
+
const abs = (0, import_node_path46.resolve)(path2);
|
|
51554
52154
|
try {
|
|
51555
52155
|
const root = run(["rev-parse", "--show-toplevel"]);
|
|
51556
52156
|
const sub = abs === root ? "." : abs.slice(root.length + 1);
|
|
@@ -51922,25 +52522,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
51922
52522
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
51923
52523
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
51924
52524
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
51925
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
52525
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path47.join)((0, import_node_os18.homedir)(), ".threatcrush", "install.json");
|
|
51926
52526
|
function detectPackageManager() {
|
|
51927
52527
|
try {
|
|
51928
|
-
const npmGlobal = (0,
|
|
52528
|
+
const npmGlobal = (0, import_node_child_process26.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
51929
52529
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
51930
52530
|
} catch {
|
|
51931
52531
|
}
|
|
51932
52532
|
try {
|
|
51933
|
-
(0,
|
|
52533
|
+
(0, import_node_child_process26.execSync)("pnpm --version", { stdio: "pipe" });
|
|
51934
52534
|
return "pnpm";
|
|
51935
52535
|
} catch {
|
|
51936
52536
|
}
|
|
51937
52537
|
try {
|
|
51938
|
-
(0,
|
|
52538
|
+
(0, import_node_child_process26.execSync)("yarn --version", { stdio: "pipe" });
|
|
51939
52539
|
return "yarn";
|
|
51940
52540
|
} catch {
|
|
51941
52541
|
}
|
|
51942
52542
|
try {
|
|
51943
|
-
(0,
|
|
52543
|
+
(0, import_node_child_process26.execSync)("bun --version", { stdio: "pipe" });
|
|
51944
52544
|
return "bun";
|
|
51945
52545
|
} catch {
|
|
51946
52546
|
}
|
|
@@ -51948,14 +52548,14 @@ function detectPackageManager() {
|
|
|
51948
52548
|
}
|
|
51949
52549
|
function readInstallConfig() {
|
|
51950
52550
|
try {
|
|
51951
|
-
return JSON.parse((0,
|
|
52551
|
+
return JSON.parse((0, import_node_fs61.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
51952
52552
|
} catch {
|
|
51953
52553
|
return {};
|
|
51954
52554
|
}
|
|
51955
52555
|
}
|
|
51956
52556
|
function packageLooksInstalled(pm, pkgName) {
|
|
51957
52557
|
try {
|
|
51958
|
-
const output = (0,
|
|
52558
|
+
const output = (0, import_node_child_process26.execSync)(globalListCommand(pm, pkgName), {
|
|
51959
52559
|
encoding: "utf-8",
|
|
51960
52560
|
stdio: ["pipe", "pipe", "pipe"]
|
|
51961
52561
|
});
|
|
@@ -52058,14 +52658,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
52058
52658
|
function restartSystemdDaemon() {
|
|
52059
52659
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
52060
52660
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
52061
|
-
if (!asRoot && (0,
|
|
52661
|
+
if (!asRoot && (0, import_node_child_process26.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
52062
52662
|
const [cmd, ...args] = argv;
|
|
52063
|
-
if ((0,
|
|
52064
|
-
return (0,
|
|
52663
|
+
if ((0, import_node_child_process26.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
52664
|
+
return (0, import_node_child_process26.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
52065
52665
|
}
|
|
52066
52666
|
function execQuiet(cmd) {
|
|
52067
52667
|
try {
|
|
52068
|
-
return (0,
|
|
52668
|
+
return (0, import_node_child_process26.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
52069
52669
|
} catch {
|
|
52070
52670
|
return null;
|
|
52071
52671
|
}
|
|
@@ -52361,7 +52961,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
52361
52961
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
52362
52962
|
console.log(LOGO2);
|
|
52363
52963
|
const logPath2 = PATHS.logFile;
|
|
52364
|
-
if (!(0,
|
|
52964
|
+
if (!(0, import_node_fs61.existsSync)(logPath2)) {
|
|
52365
52965
|
console.log(source_default.yellow(` No log file found at ${logPath2}`));
|
|
52366
52966
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
52367
52967
|
return;
|
|
@@ -52369,7 +52969,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
52369
52969
|
console.log(source_default.green(` Tailing ${logPath2}...
|
|
52370
52970
|
`));
|
|
52371
52971
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
52372
|
-
(0,
|
|
52972
|
+
(0, import_node_child_process26.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
|
|
52373
52973
|
});
|
|
52374
52974
|
program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
|
|
52375
52975
|
console.log(LOGO2);
|
|
@@ -52381,7 +52981,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
52381
52981
|
for (const cmd of commands2) {
|
|
52382
52982
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
52383
52983
|
`));
|
|
52384
|
-
(0,
|
|
52984
|
+
(0, import_node_child_process26.execSync)(cmd, { stdio: "inherit" });
|
|
52385
52985
|
}
|
|
52386
52986
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
52387
52987
|
await reportIfStillStale();
|
|
@@ -52406,7 +53006,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
52406
53006
|
for (const cmd of commands) {
|
|
52407
53007
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
52408
53008
|
`));
|
|
52409
|
-
(0,
|
|
53009
|
+
(0, import_node_child_process26.execSync)(cmd, { stdio: "inherit" });
|
|
52410
53010
|
}
|
|
52411
53011
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
52412
53012
|
if (installMode === "desktop") {
|
|
@@ -52457,7 +53057,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
52457
53057
|
for (const cmd of commands) {
|
|
52458
53058
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
52459
53059
|
`));
|
|
52460
|
-
(0,
|
|
53060
|
+
(0, import_node_child_process26.execSync)(cmd, { stdio: "inherit" });
|
|
52461
53061
|
}
|
|
52462
53062
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
52463
53063
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -52534,10 +53134,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
52534
53134
|
});
|
|
52535
53135
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
52536
53136
|
console.log(LOGO2);
|
|
52537
|
-
const configPath = (0,
|
|
53137
|
+
const configPath = (0, import_node_path47.join)((0, import_node_os18.homedir)(), ".threatcrush", "config.json");
|
|
52538
53138
|
let email = "";
|
|
52539
53139
|
try {
|
|
52540
|
-
const config = JSON.parse((0,
|
|
53140
|
+
const config = JSON.parse((0, import_node_fs61.readFileSync)(configPath, "utf-8"));
|
|
52541
53141
|
email = config.email || "";
|
|
52542
53142
|
} catch {
|
|
52543
53143
|
}
|
|
@@ -52554,9 +53154,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
52554
53154
|
return;
|
|
52555
53155
|
}
|
|
52556
53156
|
try {
|
|
52557
|
-
const dir = (0,
|
|
52558
|
-
if (!(0,
|
|
52559
|
-
(0,
|
|
53157
|
+
const dir = (0, import_node_path47.join)((0, import_node_os18.homedir)(), ".threatcrush");
|
|
53158
|
+
if (!(0, import_node_fs61.existsSync)(dir)) (0, import_node_fs61.mkdirSync)(dir, { recursive: true });
|
|
53159
|
+
(0, import_node_fs61.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
52560
53160
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
52561
53161
|
} catch {
|
|
52562
53162
|
}
|