@profullstack/threatcrush 0.13.36 → 0.13.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/daemon.js +357 -127
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +582 -228
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24745,9 +24745,9 @@ var source_default = chalk;
|
|
|
24745
24745
|
|
|
24746
24746
|
// src/index.ts
|
|
24747
24747
|
var import_readline = __toESM(require("readline"));
|
|
24748
|
-
var
|
|
24749
|
-
var
|
|
24750
|
-
var
|
|
24748
|
+
var import_node_child_process22 = require("child_process");
|
|
24749
|
+
var import_node_fs49 = require("fs");
|
|
24750
|
+
var import_node_path36 = require("path");
|
|
24751
24751
|
var import_node_os13 = require("os");
|
|
24752
24752
|
|
|
24753
24753
|
// src/commands/monitor.ts
|
|
@@ -38315,35 +38315,35 @@ async function modulesInstallCommand(source) {
|
|
|
38315
38315
|
`));
|
|
38316
38316
|
return;
|
|
38317
38317
|
}
|
|
38318
|
-
const
|
|
38319
|
-
if (!
|
|
38320
|
-
console.log(source_default.red(` \u2717 ${
|
|
38318
|
+
const check2 = validateManifest(absPath);
|
|
38319
|
+
if (!check2.ok) {
|
|
38320
|
+
console.log(source_default.red(` \u2717 ${check2.error}
|
|
38321
38321
|
`));
|
|
38322
38322
|
return;
|
|
38323
38323
|
}
|
|
38324
38324
|
let dest2;
|
|
38325
38325
|
try {
|
|
38326
|
-
dest2 = moduleDestination(dir,
|
|
38326
|
+
dest2 = moduleDestination(dir, check2.name);
|
|
38327
38327
|
} catch (err) {
|
|
38328
38328
|
console.log(source_default.red(` x ${err.message}
|
|
38329
38329
|
`));
|
|
38330
38330
|
return;
|
|
38331
38331
|
}
|
|
38332
38332
|
if ((0, import_node_fs20.existsSync)(dest2)) {
|
|
38333
|
-
console.log(source_default.yellow(` ! ${
|
|
38334
|
-
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${
|
|
38333
|
+
console.log(source_default.yellow(` ! ${check2.name} is already installed at ${dest2}`));
|
|
38334
|
+
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check2.name}`)} first.
|
|
38335
38335
|
`));
|
|
38336
38336
|
return;
|
|
38337
38337
|
}
|
|
38338
38338
|
const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
|
|
38339
38339
|
try {
|
|
38340
38340
|
(0, import_node_fs20.cpSync)(absPath, dest2, { recursive: true, dereference: true });
|
|
38341
|
-
spinner2.succeed(`Installed ${source_default.white(
|
|
38341
|
+
spinner2.succeed(`Installed ${source_default.white(check2.name)} v${check2.version} \u2192 ${dest2}`);
|
|
38342
38342
|
} catch (err) {
|
|
38343
38343
|
spinner2.fail(`Copy failed: ${err.message}`);
|
|
38344
38344
|
return;
|
|
38345
38345
|
}
|
|
38346
|
-
printTrustRequired(
|
|
38346
|
+
printTrustRequired(check2.name);
|
|
38347
38347
|
notifyDaemonIfRunning();
|
|
38348
38348
|
console.log();
|
|
38349
38349
|
return;
|
|
@@ -38373,17 +38373,17 @@ async function modulesInstallCommand(source) {
|
|
|
38373
38373
|
spinner2.fail(`Clone failed: ${err.message}`);
|
|
38374
38374
|
return;
|
|
38375
38375
|
}
|
|
38376
|
-
const
|
|
38377
|
-
if (!
|
|
38378
|
-
spinner2.fail(
|
|
38376
|
+
const check2 = validateManifest(dest2);
|
|
38377
|
+
if (!check2.ok) {
|
|
38378
|
+
spinner2.fail(check2.error);
|
|
38379
38379
|
try {
|
|
38380
38380
|
(0, import_node_fs20.rmSync)(dest2, { recursive: true, force: true });
|
|
38381
38381
|
} catch {
|
|
38382
38382
|
}
|
|
38383
38383
|
return;
|
|
38384
38384
|
}
|
|
38385
|
-
spinner2.succeed(`Installed ${source_default.white(
|
|
38386
|
-
printTrustRequired(
|
|
38385
|
+
spinner2.succeed(`Installed ${source_default.white(check2.name)} v${check2.version} \u2192 ${dest2}`);
|
|
38386
|
+
printTrustRequired(check2.name);
|
|
38387
38387
|
notifyDaemonIfRunning();
|
|
38388
38388
|
console.log();
|
|
38389
38389
|
return;
|
|
@@ -38446,9 +38446,9 @@ async function modulesInstallCommand(source) {
|
|
|
38446
38446
|
cloneSpinner.fail(`Clone failed: ${err.message}`);
|
|
38447
38447
|
return;
|
|
38448
38448
|
}
|
|
38449
|
-
const
|
|
38450
|
-
if (!
|
|
38451
|
-
cloneSpinner.fail(
|
|
38449
|
+
const check2 = validateManifest(dest);
|
|
38450
|
+
if (!check2.ok) {
|
|
38451
|
+
cloneSpinner.fail(check2.error);
|
|
38452
38452
|
try {
|
|
38453
38453
|
(0, import_node_fs20.rmSync)(dest, { recursive: true, force: true });
|
|
38454
38454
|
} catch {
|
|
@@ -38469,9 +38469,9 @@ async function modulesInstallCommand(source) {
|
|
|
38469
38469
|
assertSafeTarballEntries(tar);
|
|
38470
38470
|
(0, import_node_child_process3.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
|
|
38471
38471
|
(0, import_node_fs20.rmSync)(tar, { force: true });
|
|
38472
|
-
const
|
|
38473
|
-
if (!
|
|
38474
|
-
dlSpinner.fail(
|
|
38472
|
+
const check2 = validateManifest(dest);
|
|
38473
|
+
if (!check2.ok) {
|
|
38474
|
+
dlSpinner.fail(check2.error);
|
|
38475
38475
|
return;
|
|
38476
38476
|
}
|
|
38477
38477
|
dlSpinner.succeed(`Installed ${mod.name} v${mod.version} \u2192 ${dest}`);
|
|
@@ -38505,9 +38505,9 @@ async function modulesRemoveCommand(name) {
|
|
|
38505
38505
|
`));
|
|
38506
38506
|
return;
|
|
38507
38507
|
}
|
|
38508
|
-
const
|
|
38509
|
-
if (
|
|
38510
|
-
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${
|
|
38508
|
+
const check2 = validateManifest(target);
|
|
38509
|
+
if (check2.ok && check2.name !== name) {
|
|
38510
|
+
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check2.name}"`));
|
|
38511
38511
|
}
|
|
38512
38512
|
try {
|
|
38513
38513
|
(0, import_node_fs20.rmSync)(target, { recursive: true, force: true });
|
|
@@ -38540,14 +38540,14 @@ async function modulesTrustCommand(name) {
|
|
|
38540
38540
|
`));
|
|
38541
38541
|
return;
|
|
38542
38542
|
}
|
|
38543
|
-
const
|
|
38544
|
-
if (!
|
|
38545
|
-
console.log(source_default.red(` \u2717 ${
|
|
38543
|
+
const check2 = validateManifest(target);
|
|
38544
|
+
if (!check2.ok) {
|
|
38545
|
+
console.log(source_default.red(` \u2717 ${check2.error}
|
|
38546
38546
|
`));
|
|
38547
38547
|
return;
|
|
38548
38548
|
}
|
|
38549
38549
|
const record = trustModule(name, target, target);
|
|
38550
|
-
console.log(source_default.green(` \u2713 Trusted ${source_default.white(name)} v${
|
|
38550
|
+
console.log(source_default.green(` \u2713 Trusted ${source_default.white(name)} v${check2.version}`));
|
|
38551
38551
|
console.log(source_default.dim(` digest ${record.digest.slice(0, 16)}\u2026`));
|
|
38552
38552
|
console.log(
|
|
38553
38553
|
source_default.dim(" threatcrushd will refuse to load it again if its contents change.\n")
|
|
@@ -38756,10 +38756,10 @@ async function collectPentestResults(targetUrl) {
|
|
|
38756
38756
|
headers[k] = v;
|
|
38757
38757
|
});
|
|
38758
38758
|
const body = await resp.text();
|
|
38759
|
-
for (const
|
|
38759
|
+
for (const check2 of PENTEST_CHECKS) {
|
|
38760
38760
|
try {
|
|
38761
|
-
if (
|
|
38762
|
-
results.push({ url: targetUrl, type:
|
|
38761
|
+
if (check2.test(body, body, headers)) {
|
|
38762
|
+
results.push({ url: targetUrl, type: check2.name, severity: check2.severity, message: check2.message });
|
|
38763
38763
|
}
|
|
38764
38764
|
} catch {
|
|
38765
38765
|
}
|
|
@@ -38827,14 +38827,14 @@ async function pentestCommand(targetUrl) {
|
|
|
38827
38827
|
const body = await resp.text();
|
|
38828
38828
|
spinner.succeed(`Got ${resp.status} response
|
|
38829
38829
|
`);
|
|
38830
|
-
for (const
|
|
38830
|
+
for (const check2 of PENTEST_CHECKS) {
|
|
38831
38831
|
try {
|
|
38832
|
-
if (
|
|
38832
|
+
if (check2.test(body, body, headers)) {
|
|
38833
38833
|
results.push({
|
|
38834
38834
|
url: targetUrl,
|
|
38835
|
-
type:
|
|
38836
|
-
severity:
|
|
38837
|
-
message:
|
|
38835
|
+
type: check2.name,
|
|
38836
|
+
severity: check2.severity,
|
|
38837
|
+
message: check2.message
|
|
38838
38838
|
});
|
|
38839
38839
|
}
|
|
38840
38840
|
} catch {
|
|
@@ -39789,16 +39789,16 @@ async function sshConnect(options) {
|
|
|
39789
39789
|
}
|
|
39790
39790
|
|
|
39791
39791
|
// src/commands/daemon.ts
|
|
39792
|
-
var
|
|
39793
|
-
var
|
|
39794
|
-
var
|
|
39795
|
-
var
|
|
39792
|
+
var import_node_child_process16 = require("child_process");
|
|
39793
|
+
var import_node_fs40 = require("fs");
|
|
39794
|
+
var import_node_path30 = require("path");
|
|
39795
|
+
var import_node_fs41 = require("fs");
|
|
39796
39796
|
|
|
39797
39797
|
// src/daemon/index.ts
|
|
39798
|
-
var
|
|
39799
|
-
var
|
|
39798
|
+
var import_node_fs39 = require("fs");
|
|
39799
|
+
var import_node_child_process15 = require("child_process");
|
|
39800
39800
|
var import_node_os11 = require("os");
|
|
39801
|
-
var
|
|
39801
|
+
var import_node_path29 = require("path");
|
|
39802
39802
|
var import_node_util = require("util");
|
|
39803
39803
|
init_paths();
|
|
39804
39804
|
|
|
@@ -40101,7 +40101,7 @@ function admGid(readGroup = () => (0, import_node_fs24.readFileSync)("/etc/group
|
|
|
40101
40101
|
}
|
|
40102
40102
|
|
|
40103
40103
|
// src/daemon/module-host.ts
|
|
40104
|
-
var
|
|
40104
|
+
var import_node_fs30 = require("fs");
|
|
40105
40105
|
var import_node_path21 = require("path");
|
|
40106
40106
|
var import_node_url = require("url");
|
|
40107
40107
|
var import_toml4 = __toESM(require_toml());
|
|
@@ -40678,17 +40678,18 @@ var NetworkMonitor = class {
|
|
|
40678
40678
|
};
|
|
40679
40679
|
|
|
40680
40680
|
// src/modules/dns-monitor/index.ts
|
|
40681
|
-
var
|
|
40681
|
+
var import_node_fs29 = require("fs");
|
|
40682
40682
|
var import_node_child_process8 = require("child_process");
|
|
40683
40683
|
var import_node_readline3 = require("readline");
|
|
40684
40684
|
|
|
40685
40685
|
// src/core/threat-feeds/index.ts
|
|
40686
|
-
var
|
|
40686
|
+
var import_node_fs28 = require("fs");
|
|
40687
40687
|
var import_node_path20 = require("path");
|
|
40688
40688
|
var import_node_net5 = require("net");
|
|
40689
40689
|
|
|
40690
40690
|
// src/daemon/firewall/protected.ts
|
|
40691
40691
|
var import_node_child_process7 = require("child_process");
|
|
40692
|
+
var import_node_fs27 = require("fs");
|
|
40692
40693
|
var import_node_net4 = require("net");
|
|
40693
40694
|
var DEFAULT_PROTECTED = [
|
|
40694
40695
|
"127.0.0.0/8",
|
|
@@ -40801,6 +40802,45 @@ function establishedSshPeers() {
|
|
|
40801
40802
|
}
|
|
40802
40803
|
return [...peers];
|
|
40803
40804
|
}
|
|
40805
|
+
function sshClientFromEnviron(environ) {
|
|
40806
|
+
for (const entry of environ.split("\0")) {
|
|
40807
|
+
const m = /^SSH_(?:CONNECTION|CLIENT)=(\S+)/.exec(entry);
|
|
40808
|
+
if (m && (0, import_node_net4.isIP)(m[1])) return m[1];
|
|
40809
|
+
}
|
|
40810
|
+
return null;
|
|
40811
|
+
}
|
|
40812
|
+
function moshClients(procDir = "/proc") {
|
|
40813
|
+
const found = /* @__PURE__ */ new Set();
|
|
40814
|
+
let pids = [];
|
|
40815
|
+
try {
|
|
40816
|
+
pids = (0, import_node_fs27.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
|
|
40817
|
+
} catch {
|
|
40818
|
+
return [];
|
|
40819
|
+
}
|
|
40820
|
+
for (const pid of pids) {
|
|
40821
|
+
try {
|
|
40822
|
+
if ((0, import_node_fs27.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
|
|
40823
|
+
const ip = sshClientFromEnviron((0, import_node_fs27.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
|
|
40824
|
+
if (ip) found.add(ip);
|
|
40825
|
+
} catch {
|
|
40826
|
+
}
|
|
40827
|
+
}
|
|
40828
|
+
return [...found];
|
|
40829
|
+
}
|
|
40830
|
+
function parseKeyLogins(text, skip = () => false) {
|
|
40831
|
+
const out = /* @__PURE__ */ new Map();
|
|
40832
|
+
for (const line2 of text.split("\n")) {
|
|
40833
|
+
const m = /^(\d+(?:\.\d+)?)\s.*Accepted publickey for \S+ from (\S+) port \d+ [^\s:]+(?:: \S+ (SHA256:\S+))?/.exec(line2);
|
|
40834
|
+
if (!m || !(0, import_node_net4.isIP)(m[2])) continue;
|
|
40835
|
+
if (m[3] && skip(m[3])) continue;
|
|
40836
|
+
const at = Math.round(Number(m[1]) * 1e3);
|
|
40837
|
+
if (at > (out.get(m[2]) ?? 0)) out.set(m[2], at);
|
|
40838
|
+
}
|
|
40839
|
+
return out;
|
|
40840
|
+
}
|
|
40841
|
+
function isAutomationKeyComment(comment) {
|
|
40842
|
+
return /github-actions|gitlab|jenkins|buildkite|circleci|drone|\bci\b|runner|deploy|backup|automation|\bbot\b/i.test(comment);
|
|
40843
|
+
}
|
|
40804
40844
|
function defaultGateways() {
|
|
40805
40845
|
const found = /* @__PURE__ */ new Set();
|
|
40806
40846
|
for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
|
|
@@ -40986,17 +41026,38 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
|
|
|
40986
41026
|
}
|
|
40987
41027
|
function readFeedCache(path) {
|
|
40988
41028
|
try {
|
|
40989
|
-
const set = JSON.parse((0,
|
|
41029
|
+
const set = JSON.parse((0, import_node_fs28.readFileSync)(path, "utf-8"));
|
|
40990
41030
|
return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
|
|
40991
41031
|
} catch {
|
|
40992
41032
|
return null;
|
|
40993
41033
|
}
|
|
40994
41034
|
}
|
|
40995
41035
|
function writeFeedCache(path, set) {
|
|
40996
|
-
(0,
|
|
41036
|
+
(0, import_node_fs28.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
|
|
40997
41037
|
const tmp = `${path}.tmp`;
|
|
40998
|
-
(0,
|
|
40999
|
-
(0,
|
|
41038
|
+
(0, import_node_fs28.writeFileSync)(tmp, JSON.stringify(set));
|
|
41039
|
+
(0, import_node_fs28.renameSync)(tmp, path);
|
|
41040
|
+
}
|
|
41041
|
+
var RESOLVER_FILES = {
|
|
41042
|
+
hosts: "blocked-domains.hosts",
|
|
41043
|
+
unbound: "blocked-domains.unbound.conf"
|
|
41044
|
+
};
|
|
41045
|
+
var RESOLVER_HOOKS = {
|
|
41046
|
+
dnsmasq: "/etc/dnsmasq.d/threatcrush.conf",
|
|
41047
|
+
unbound: "/etc/unbound/unbound.conf.d/threatcrush.conf"
|
|
41048
|
+
};
|
|
41049
|
+
var GENERATED = "# Written by threatcrushd from abuse.ch feeds; rewritten every refresh. Do not edit.";
|
|
41050
|
+
function hostsBlocklist(domains) {
|
|
41051
|
+
const lines = [GENERATED];
|
|
41052
|
+
for (const d of domains) lines.push(`0.0.0.0 ${d}`, `:: ${d}`);
|
|
41053
|
+
return `${lines.join("\n")}
|
|
41054
|
+
`;
|
|
41055
|
+
}
|
|
41056
|
+
function unboundBlocklist(domains) {
|
|
41057
|
+
const lines = [GENERATED, "server:"];
|
|
41058
|
+
for (const d of domains) lines.push(` local-zone: "${d}." always_nxdomain`);
|
|
41059
|
+
return `${lines.join("\n")}
|
|
41060
|
+
`;
|
|
41000
41061
|
}
|
|
41001
41062
|
var active = null;
|
|
41002
41063
|
function setActiveFeeds(set) {
|
|
@@ -41100,9 +41161,9 @@ var DnsMonitor = class {
|
|
|
41100
41161
|
}
|
|
41101
41162
|
start() {
|
|
41102
41163
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
41103
|
-
if (!(0,
|
|
41164
|
+
if (!(0, import_node_fs29.existsSync)(p)) return false;
|
|
41104
41165
|
try {
|
|
41105
|
-
(0,
|
|
41166
|
+
(0, import_node_fs29.accessSync)(p, import_node_fs29.constants.R_OK);
|
|
41106
41167
|
return true;
|
|
41107
41168
|
} catch {
|
|
41108
41169
|
return false;
|
|
@@ -41459,15 +41520,15 @@ var ModuleHost = class {
|
|
|
41459
41520
|
}
|
|
41460
41521
|
}
|
|
41461
41522
|
async discoverAndStartInstalled() {
|
|
41462
|
-
if (!(0,
|
|
41523
|
+
if (!(0, import_node_fs30.existsSync)(PATHS.moduleDir)) return;
|
|
41463
41524
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
41464
|
-
const entries = (0,
|
|
41525
|
+
const entries = (0, import_node_fs30.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
41465
41526
|
for (const entry of entries) {
|
|
41466
41527
|
if (!entry.isDirectory()) continue;
|
|
41467
41528
|
const manifestPath = (0, import_node_path21.join)(PATHS.moduleDir, entry.name, "mod.toml");
|
|
41468
|
-
if (!(0,
|
|
41529
|
+
if (!(0, import_node_fs30.existsSync)(manifestPath)) continue;
|
|
41469
41530
|
try {
|
|
41470
|
-
const manifest = import_toml4.default.parse((0,
|
|
41531
|
+
const manifest = import_toml4.default.parse((0, import_node_fs30.readFileSync)(manifestPath, "utf-8"));
|
|
41471
41532
|
const name = manifest.module?.name || entry.name;
|
|
41472
41533
|
const defaults = manifest.module?.config?.defaults || {};
|
|
41473
41534
|
const config = {
|
|
@@ -41537,15 +41598,15 @@ var ModuleHost = class {
|
|
|
41537
41598
|
installedEntrypoint(modulePath) {
|
|
41538
41599
|
const packageJson = (0, import_node_path21.join)(modulePath, "package.json");
|
|
41539
41600
|
const candidates = [];
|
|
41540
|
-
if ((0,
|
|
41601
|
+
if ((0, import_node_fs30.existsSync)(packageJson)) {
|
|
41541
41602
|
try {
|
|
41542
|
-
const pkg = JSON.parse((0,
|
|
41603
|
+
const pkg = JSON.parse((0, import_node_fs30.readFileSync)(packageJson, "utf-8"));
|
|
41543
41604
|
if (pkg.main) candidates.push((0, import_node_path21.join)(modulePath, pkg.main));
|
|
41544
41605
|
} catch {
|
|
41545
41606
|
}
|
|
41546
41607
|
}
|
|
41547
41608
|
candidates.push((0, import_node_path21.join)(modulePath, "dist", "index.js"), (0, import_node_path21.join)(modulePath, "index.js"));
|
|
41548
|
-
return candidates.find((candidate) => (0,
|
|
41609
|
+
return candidates.find((candidate) => (0, import_node_fs30.existsSync)(candidate)) || null;
|
|
41549
41610
|
}
|
|
41550
41611
|
isThreatCrushModule(value) {
|
|
41551
41612
|
return Boolean(
|
|
@@ -42054,7 +42115,7 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
42054
42115
|
}
|
|
42055
42116
|
|
|
42056
42117
|
// src/daemon/workers/cloud-spool.ts
|
|
42057
|
-
var
|
|
42118
|
+
var import_node_fs31 = require("fs");
|
|
42058
42119
|
var import_promises = require("fs/promises");
|
|
42059
42120
|
var import_node_path22 = require("path");
|
|
42060
42121
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
@@ -42063,7 +42124,7 @@ var CloudSpool = class {
|
|
|
42063
42124
|
this.path = path;
|
|
42064
42125
|
this.limits = limits;
|
|
42065
42126
|
try {
|
|
42066
|
-
(0,
|
|
42127
|
+
(0, import_node_fs31.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
|
|
42067
42128
|
} catch {
|
|
42068
42129
|
}
|
|
42069
42130
|
this.load();
|
|
@@ -42132,7 +42193,7 @@ var CloudSpool = class {
|
|
|
42132
42193
|
load() {
|
|
42133
42194
|
let raw;
|
|
42134
42195
|
try {
|
|
42135
|
-
raw = (0,
|
|
42196
|
+
raw = (0, import_node_fs31.readFileSync)(this.path, "utf-8");
|
|
42136
42197
|
} catch {
|
|
42137
42198
|
return;
|
|
42138
42199
|
}
|
|
@@ -42591,7 +42652,7 @@ var RemediationConsumer = class {
|
|
|
42591
42652
|
|
|
42592
42653
|
// src/daemon/workers/auto-update.ts
|
|
42593
42654
|
var import_node_child_process9 = require("child_process");
|
|
42594
|
-
var
|
|
42655
|
+
var import_node_fs32 = require("fs");
|
|
42595
42656
|
var import_node_path23 = require("path");
|
|
42596
42657
|
init_backoff();
|
|
42597
42658
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
@@ -42619,15 +42680,21 @@ function pickUpdate(doc, current, opts) {
|
|
|
42619
42680
|
if (!latest) return { version: null, reason: "registry has no latest tag" };
|
|
42620
42681
|
if (!isNewer(latest, current)) return { version: null, reason: `up to date (${current})` };
|
|
42621
42682
|
const major = (v) => Number.parseInt(v.replace(/^v/, ""), 10);
|
|
42683
|
+
let best = null;
|
|
42684
|
+
for (const [v, when] of Object.entries(doc.time ?? {})) {
|
|
42685
|
+
if (!/^\d+\.\d+\.\d+$/.test(v)) continue;
|
|
42686
|
+
if (!isNewer(v, current) || isNewer(v, latest)) continue;
|
|
42687
|
+
if (!opts.allowMajor && major(v) !== major(current)) continue;
|
|
42688
|
+
const published = Date.parse(when);
|
|
42689
|
+
if (!Number.isFinite(published) || opts.now - published < opts.minAgeMs) continue;
|
|
42690
|
+
if (!best || isNewer(v, best)) best = v;
|
|
42691
|
+
}
|
|
42692
|
+
if (best) return { version: best };
|
|
42622
42693
|
if (!opts.allowMajor && major(latest) !== major(current)) {
|
|
42623
42694
|
return { version: null, reason: `${latest} is a new major; set [update] allow_major = true to take it` };
|
|
42624
42695
|
}
|
|
42625
|
-
|
|
42626
|
-
|
|
42627
|
-
if (opts.now - published < opts.minAgeMs) {
|
|
42628
|
-
return { version: null, reason: `${latest} is younger than min_age; waiting` };
|
|
42629
|
-
}
|
|
42630
|
-
return { version: latest };
|
|
42696
|
+
if (!Number.isFinite(Date.parse(doc.time?.[latest] ?? ""))) return { version: null, reason: `no publish time for ${latest}` };
|
|
42697
|
+
return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
|
|
42631
42698
|
}
|
|
42632
42699
|
function installPlan(opts) {
|
|
42633
42700
|
const expected = `${import_node_path23.sep}lib${import_node_path23.sep}node_modules${import_node_path23.sep}@profullstack${import_node_path23.sep}threatcrush`;
|
|
@@ -42667,10 +42734,10 @@ function installPlan(opts) {
|
|
|
42667
42734
|
}
|
|
42668
42735
|
function ownerOf(path, passwd = "/etc/passwd") {
|
|
42669
42736
|
try {
|
|
42670
|
-
const st = (0,
|
|
42737
|
+
const st = (0, import_node_fs32.statSync)(path);
|
|
42671
42738
|
let home = st.uid === 0 ? "/root" : "";
|
|
42672
42739
|
try {
|
|
42673
|
-
for (const line2 of (0,
|
|
42740
|
+
for (const line2 of (0, import_node_fs32.readFileSync)(passwd, "utf8").split("\n")) {
|
|
42674
42741
|
const f = line2.split(":");
|
|
42675
42742
|
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
42676
42743
|
}
|
|
@@ -42762,7 +42829,7 @@ var AutoUpdate = class {
|
|
|
42762
42829
|
minAgeMs: this.opts.settings.minAgeMs,
|
|
42763
42830
|
now: this.now()
|
|
42764
42831
|
});
|
|
42765
|
-
if (pick.version === null) return this.note(pick.reason,
|
|
42832
|
+
if (pick.version === null) return this.note(pick.reason, !pick.reason.startsWith("up to date"));
|
|
42766
42833
|
const target = pick.version;
|
|
42767
42834
|
const last = this.lastAttempt();
|
|
42768
42835
|
if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
|
|
@@ -42775,7 +42842,7 @@ var AutoUpdate = class {
|
|
|
42775
42842
|
uid: process.getuid?.() ?? -1,
|
|
42776
42843
|
owner: ownerOf(this.opts.pkgRoot),
|
|
42777
42844
|
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
42778
|
-
npmExists:
|
|
42845
|
+
npmExists: import_node_fs32.existsSync
|
|
42779
42846
|
});
|
|
42780
42847
|
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
42781
42848
|
this.recordAttempt(target);
|
|
@@ -42810,7 +42877,7 @@ var AutoUpdate = class {
|
|
|
42810
42877
|
}
|
|
42811
42878
|
lastAttempt() {
|
|
42812
42879
|
try {
|
|
42813
|
-
const v = JSON.parse((0,
|
|
42880
|
+
const v = JSON.parse((0, import_node_fs32.readFileSync)(this.opts.statePath, "utf8"));
|
|
42814
42881
|
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
42815
42882
|
} catch {
|
|
42816
42883
|
return null;
|
|
@@ -42818,7 +42885,7 @@ var AutoUpdate = class {
|
|
|
42818
42885
|
}
|
|
42819
42886
|
recordAttempt(version) {
|
|
42820
42887
|
try {
|
|
42821
|
-
(0,
|
|
42888
|
+
(0, import_node_fs32.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
42822
42889
|
} catch (err) {
|
|
42823
42890
|
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
42824
42891
|
}
|
|
@@ -42827,6 +42894,8 @@ var AutoUpdate = class {
|
|
|
42827
42894
|
|
|
42828
42895
|
// src/daemon/workers/threat-feeds.ts
|
|
42829
42896
|
var import_node_child_process10 = require("child_process");
|
|
42897
|
+
var import_node_fs33 = require("fs");
|
|
42898
|
+
var import_node_path24 = require("path");
|
|
42830
42899
|
var import_node_net9 = require("net");
|
|
42831
42900
|
init_backoff();
|
|
42832
42901
|
var EGRESS_TABLE = "threatcrush_egress";
|
|
@@ -42838,6 +42907,7 @@ function threatFeedSettings(section) {
|
|
|
42838
42907
|
return {
|
|
42839
42908
|
enabled: section?.enabled !== false,
|
|
42840
42909
|
block: section?.block === true,
|
|
42910
|
+
blockDomains: section?.block_domains === true,
|
|
42841
42911
|
// abuse.ch asks for no more than one fetch per 5 minutes; hourly is plenty.
|
|
42842
42912
|
refreshMs: refresh ? Math.max(900, refresh) * 1e3 : DEFAULT_REFRESH_MS,
|
|
42843
42913
|
minConfidence: typeof section?.min_confidence === "number" ? section.min_confidence : 75,
|
|
@@ -42917,6 +42987,8 @@ var ThreatFeeds = class {
|
|
|
42917
42987
|
set = null;
|
|
42918
42988
|
alerted = /* @__PURE__ */ new Map();
|
|
42919
42989
|
blocking = false;
|
|
42990
|
+
/** Resolver blocklist content last written, by file name (see writeResolverFiles). */
|
|
42991
|
+
resolverWritten = /* @__PURE__ */ new Map();
|
|
42920
42992
|
run;
|
|
42921
42993
|
now;
|
|
42922
42994
|
get wantsBlock() {
|
|
@@ -42978,10 +43050,55 @@ var ThreatFeeds = class {
|
|
|
42978
43050
|
this.blocking = ok;
|
|
42979
43051
|
mode = ok ? "blocking egress" : "detecting (nft load failed)";
|
|
42980
43052
|
}
|
|
42981
|
-
const detail = `${ips.length} IPs, ${domains} domains, ${mode}`;
|
|
43053
|
+
const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}`;
|
|
42982
43054
|
this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);
|
|
42983
43055
|
this.opts.bus.announceModule("threat-feeds", "running", detail);
|
|
42984
43056
|
}
|
|
43057
|
+
/** Whether listed domains are refused at the resolver: opted in and enforcing. */
|
|
43058
|
+
get wantsDomainBlock() {
|
|
43059
|
+
return this.opts.settings.blockDomains && this.opts.enforcing;
|
|
43060
|
+
}
|
|
43061
|
+
/**
|
|
43062
|
+
* Rewrite the resolver blocklists in the state dir and reload any resolver
|
|
43063
|
+
* whose hook is installed — only when the content changed, so an hourly
|
|
43064
|
+
* refresh with nothing new costs no reload. With domain blocking off the
|
|
43065
|
+
* files are emptied, so an installed hook blocks nothing and the config
|
|
43066
|
+
* stays the one switch. Returns a status suffix for the log line.
|
|
43067
|
+
*/
|
|
43068
|
+
writeResolverFiles(set) {
|
|
43069
|
+
const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
|
|
43070
|
+
const dir = this.opts.resolverDir ?? (0, import_node_path24.dirname)(this.opts.cachePath);
|
|
43071
|
+
const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
|
|
43072
|
+
const write = (name, content) => {
|
|
43073
|
+
const path = (0, import_node_path24.join)(dir, name);
|
|
43074
|
+
if (this.resolverWritten.get(name) === content) return false;
|
|
43075
|
+
try {
|
|
43076
|
+
(0, import_node_fs33.writeFileSync)(`${path}.tmp`, content);
|
|
43077
|
+
(0, import_node_fs33.renameSync)(`${path}.tmp`, path);
|
|
43078
|
+
this.resolverWritten.set(name, content);
|
|
43079
|
+
return true;
|
|
43080
|
+
} catch (err) {
|
|
43081
|
+
this.opts.log(`[threat-feeds] could not write ${path}: ${err.message}`);
|
|
43082
|
+
return false;
|
|
43083
|
+
}
|
|
43084
|
+
};
|
|
43085
|
+
const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
|
|
43086
|
+
const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
|
|
43087
|
+
const via = [];
|
|
43088
|
+
if ((0, import_node_fs33.existsSync)(hooks.dnsmasq)) {
|
|
43089
|
+
via.push("dnsmasq");
|
|
43090
|
+
if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
|
|
43091
|
+
}
|
|
43092
|
+
if ((0, import_node_fs33.existsSync)(hooks.unbound)) {
|
|
43093
|
+
via.push("unbound");
|
|
43094
|
+
if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
|
|
43095
|
+
this.run("systemctl", ["reload", "unbound.service"]);
|
|
43096
|
+
}
|
|
43097
|
+
}
|
|
43098
|
+
if (!this.opts.settings.blockDomains) return "";
|
|
43099
|
+
if (!this.opts.enforcing) return "; domain blocking set but remediation is dry_run";
|
|
43100
|
+
return via.length ? `; ${domains.length} domains refused via ${via.join(" + ")}` : "; domain blocking set but no resolver hook (run `threatcrush feeds resolver install`)";
|
|
43101
|
+
}
|
|
42985
43102
|
removeBlocking() {
|
|
42986
43103
|
if (this.run("nft", ["list", "table", "inet", EGRESS_TABLE]) !== null) {
|
|
42987
43104
|
this.run("nft", ["delete", "table", "inet", EGRESS_TABLE]);
|
|
@@ -43033,8 +43150,8 @@ var ThreatFeeds = class {
|
|
|
43033
43150
|
};
|
|
43034
43151
|
|
|
43035
43152
|
// src/daemon/workers/privilege-watch.ts
|
|
43036
|
-
var
|
|
43037
|
-
var
|
|
43153
|
+
var import_node_fs34 = require("fs");
|
|
43154
|
+
var import_node_path25 = require("path");
|
|
43038
43155
|
var import_node_child_process11 = require("child_process");
|
|
43039
43156
|
|
|
43040
43157
|
// src/core/privileges/index.ts
|
|
@@ -43225,31 +43342,31 @@ function countryName(code) {
|
|
|
43225
43342
|
var fsIO = {
|
|
43226
43343
|
readFile: (p) => {
|
|
43227
43344
|
try {
|
|
43228
|
-
return (0,
|
|
43345
|
+
return (0, import_node_fs34.readFileSync)(p, "utf-8");
|
|
43229
43346
|
} catch {
|
|
43230
43347
|
return null;
|
|
43231
43348
|
}
|
|
43232
43349
|
},
|
|
43233
43350
|
readDir: (p) => {
|
|
43234
43351
|
try {
|
|
43235
|
-
return (0,
|
|
43352
|
+
return (0, import_node_fs34.readdirSync)(p);
|
|
43236
43353
|
} catch {
|
|
43237
43354
|
return null;
|
|
43238
43355
|
}
|
|
43239
43356
|
},
|
|
43240
|
-
exists: (p) => (0,
|
|
43357
|
+
exists: (p) => (0, import_node_fs34.existsSync)(p)
|
|
43241
43358
|
};
|
|
43242
43359
|
function readJson(path) {
|
|
43243
43360
|
try {
|
|
43244
|
-
return JSON.parse((0,
|
|
43361
|
+
return JSON.parse((0, import_node_fs34.readFileSync)(path, "utf-8"));
|
|
43245
43362
|
} catch {
|
|
43246
43363
|
return null;
|
|
43247
43364
|
}
|
|
43248
43365
|
}
|
|
43249
43366
|
function writeJson(path, value) {
|
|
43250
|
-
(0,
|
|
43251
|
-
(0,
|
|
43252
|
-
(0,
|
|
43367
|
+
(0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path), { recursive: true });
|
|
43368
|
+
(0, import_node_fs34.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
|
|
43369
|
+
(0, import_node_fs34.renameSync)(`${path}.tmp`, path);
|
|
43253
43370
|
}
|
|
43254
43371
|
function defaultRun3(cmd, args) {
|
|
43255
43372
|
const res = (0, import_node_child_process11.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -43405,7 +43522,7 @@ var PrivilegeWatch = class {
|
|
|
43405
43522
|
* raised a "new country" alert on its first run; on dev2 it did, at once.
|
|
43406
43523
|
*/
|
|
43407
43524
|
async backfillLogins() {
|
|
43408
|
-
if ((0,
|
|
43525
|
+
if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
|
|
43409
43526
|
const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
|
|
43410
43527
|
const byUser = parseAcceptedLogins(out ?? "");
|
|
43411
43528
|
const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
|
|
@@ -43418,7 +43535,7 @@ var PrivilegeWatch = class {
|
|
|
43418
43535
|
return;
|
|
43419
43536
|
}
|
|
43420
43537
|
}
|
|
43421
|
-
if ((0,
|
|
43538
|
+
if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
|
|
43422
43539
|
const at = this.now().toISOString();
|
|
43423
43540
|
const history = {};
|
|
43424
43541
|
for (const [user, userIps] of byUser) {
|
|
@@ -43630,8 +43747,8 @@ var RuleEngine = class {
|
|
|
43630
43747
|
};
|
|
43631
43748
|
|
|
43632
43749
|
// src/daemon/rules/loader.ts
|
|
43633
|
-
var
|
|
43634
|
-
var
|
|
43750
|
+
var import_node_fs35 = require("fs");
|
|
43751
|
+
var import_node_path26 = require("path");
|
|
43635
43752
|
|
|
43636
43753
|
// src/daemon/rules/default-rules.ts
|
|
43637
43754
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -44032,11 +44149,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
44032
44149
|
function loadAllRules(customDir) {
|
|
44033
44150
|
const rules = [...DEFAULT_RULES];
|
|
44034
44151
|
const dir = customDir || RULES_DIR;
|
|
44035
|
-
if ((0,
|
|
44036
|
-
const files = (0,
|
|
44152
|
+
if ((0, import_node_fs35.existsSync)(dir)) {
|
|
44153
|
+
const files = (0, import_node_fs35.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
44037
44154
|
for (const file of files) {
|
|
44038
44155
|
try {
|
|
44039
|
-
const raw = (0,
|
|
44156
|
+
const raw = (0, import_node_fs35.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
|
|
44040
44157
|
const parsed = JSON.parse(raw);
|
|
44041
44158
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
44042
44159
|
for (const rule of customRules) {
|
|
@@ -44068,8 +44185,8 @@ function loadAllRules(customDir) {
|
|
|
44068
44185
|
|
|
44069
44186
|
// src/daemon/firewall/adapters.ts
|
|
44070
44187
|
var import_node_child_process12 = require("child_process");
|
|
44071
|
-
var
|
|
44072
|
-
var
|
|
44188
|
+
var import_node_fs36 = require("fs");
|
|
44189
|
+
var import_node_path27 = require("path");
|
|
44073
44190
|
var import_node_net10 = require("net");
|
|
44074
44191
|
function assertValidFirewallIp(ip) {
|
|
44075
44192
|
if ((0, import_node_net10.isIP)(ip) !== 4) {
|
|
@@ -44082,9 +44199,9 @@ function assertBannableIp(ip) {
|
|
|
44082
44199
|
}
|
|
44083
44200
|
}
|
|
44084
44201
|
function writeIfAbsent(path, contents) {
|
|
44085
|
-
(0,
|
|
44202
|
+
(0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
|
|
44086
44203
|
try {
|
|
44087
|
-
(0,
|
|
44204
|
+
(0, import_node_fs36.writeFileSync)(path, contents, { flag: "wx" });
|
|
44088
44205
|
} catch (err) {
|
|
44089
44206
|
if (err.code !== "EEXIST") throw err;
|
|
44090
44207
|
}
|
|
@@ -44343,7 +44460,8 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
44343
44460
|
}
|
|
44344
44461
|
|
|
44345
44462
|
// src/daemon/firewall/remediation.ts
|
|
44346
|
-
var
|
|
44463
|
+
var import_node_fs37 = require("fs");
|
|
44464
|
+
var import_node_child_process13 = require("child_process");
|
|
44347
44465
|
var import_node_net11 = require("net");
|
|
44348
44466
|
init_paths();
|
|
44349
44467
|
init_backoff();
|
|
@@ -44402,8 +44520,46 @@ var DEFAULT_CONFIG2 = {
|
|
|
44402
44520
|
strike_memory_seconds: 30 * 86400,
|
|
44403
44521
|
allowlist: [],
|
|
44404
44522
|
protect_current_ssh_client: true,
|
|
44523
|
+
protect_recent_operators: true,
|
|
44524
|
+
operator_memory_seconds: 30 * 86400,
|
|
44405
44525
|
spare_verified_crawlers: true
|
|
44406
44526
|
};
|
|
44527
|
+
var defaultDiscovery = {
|
|
44528
|
+
sshPeers: () => [currentSshClient(), ...establishedSshPeers()].filter((ip) => Boolean(ip)),
|
|
44529
|
+
moshClients: () => moshClients(),
|
|
44530
|
+
automationKeys: () => {
|
|
44531
|
+
const snapshot = takeSnapshot({
|
|
44532
|
+
readFile: (p) => {
|
|
44533
|
+
try {
|
|
44534
|
+
return (0, import_node_fs37.readFileSync)(p, "utf-8");
|
|
44535
|
+
} catch {
|
|
44536
|
+
return null;
|
|
44537
|
+
}
|
|
44538
|
+
},
|
|
44539
|
+
readDir: (p) => {
|
|
44540
|
+
try {
|
|
44541
|
+
return (0, import_node_fs37.readdirSync)(p);
|
|
44542
|
+
} catch {
|
|
44543
|
+
return null;
|
|
44544
|
+
}
|
|
44545
|
+
},
|
|
44546
|
+
exists: (p) => (0, import_node_fs37.existsSync)(p)
|
|
44547
|
+
});
|
|
44548
|
+
const out = /* @__PURE__ */ new Set();
|
|
44549
|
+
for (const keys of Object.values(snapshot.keys)) {
|
|
44550
|
+
for (const [fp, k] of Object.entries(keys)) if (isAutomationKeyComment(k.comment)) out.add(fp);
|
|
44551
|
+
}
|
|
44552
|
+
return out;
|
|
44553
|
+
},
|
|
44554
|
+
keyLoginJournal: (sinceSeconds) => new Promise((resolve6) => {
|
|
44555
|
+
(0, import_node_child_process13.execFile)(
|
|
44556
|
+
"journalctl",
|
|
44557
|
+
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
44558
|
+
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
44559
|
+
(_err, stdout) => resolve6(stdout ?? "")
|
|
44560
|
+
);
|
|
44561
|
+
})
|
|
44562
|
+
};
|
|
44407
44563
|
var SEVERITY_RANK7 = {
|
|
44408
44564
|
info: 0,
|
|
44409
44565
|
low: 1,
|
|
@@ -44426,28 +44582,70 @@ function explainBlockFailure(err, backend) {
|
|
|
44426
44582
|
return `threatcrushd is running ${who} and cannot manage ${backend}. A ban is written by the daemon, not by whoever asked for it. Fix it with one command, which asks for root itself: threatcrush install-service`;
|
|
44427
44583
|
}
|
|
44428
44584
|
var RemediationManager = class {
|
|
44429
|
-
constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier()) {
|
|
44585
|
+
constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier(), discovery = defaultDiscovery) {
|
|
44430
44586
|
this.adapter = adapter;
|
|
44431
44587
|
this.bus = bus2;
|
|
44432
44588
|
this.verifyCrawler = verifyCrawler;
|
|
44589
|
+
this.discovery = discovery;
|
|
44433
44590
|
this.config = { ...DEFAULT_CONFIG2, ...config };
|
|
44434
44591
|
this.config.allowlist = [...this.config.allowlist];
|
|
44435
44592
|
this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
|
|
44436
44593
|
for (const gateway of defaultGateways()) this.protectedList.push(gateway);
|
|
44437
|
-
this.refreshSshProtection();
|
|
44438
44594
|
if (this.adapter.enforces === false) this.config.dry_run = true;
|
|
44439
44595
|
this.loadState();
|
|
44596
|
+
this.refreshSshProtection();
|
|
44440
44597
|
void this.reconcile();
|
|
44441
44598
|
this.startExpiryWorker();
|
|
44599
|
+
if (this.config.protect_recent_operators) void this.seedOperatorsFromJournal();
|
|
44442
44600
|
}
|
|
44443
44601
|
adapter;
|
|
44444
44602
|
bus;
|
|
44445
44603
|
verifyCrawler;
|
|
44604
|
+
discovery;
|
|
44446
44605
|
config;
|
|
44447
44606
|
blocklist = [];
|
|
44448
44607
|
strikes = {};
|
|
44449
44608
|
protectedList = [];
|
|
44609
|
+
/** Operator address → last time seen (ms), persisted. */
|
|
44610
|
+
operators = {};
|
|
44450
44611
|
expiryTimer = null;
|
|
44612
|
+
operatorTimer = null;
|
|
44613
|
+
/** Remembered operator addresses and when each was last seen. */
|
|
44614
|
+
getOperators() {
|
|
44615
|
+
return { ...this.operators };
|
|
44616
|
+
}
|
|
44617
|
+
/**
|
|
44618
|
+
* An address an operator really came from: never ban it, remember it, and
|
|
44619
|
+
* lift a ban that is already on it — the operator is the one who needs in.
|
|
44620
|
+
*/
|
|
44621
|
+
noteOperator(ip, at, remember = true) {
|
|
44622
|
+
if (Date.now() - at > this.config.operator_memory_seconds * 1e3) return;
|
|
44623
|
+
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
44624
|
+
if (!remember || !this.config.protect_recent_operators || isProtected(ip, DEFAULT_PROTECTED)) return;
|
|
44625
|
+
const known = this.operators[ip] ?? 0;
|
|
44626
|
+
if (at > known) {
|
|
44627
|
+
this.operators[ip] = at;
|
|
44628
|
+
if (!known) this.logLine(`[firewall] operator address remembered: ${ip}`);
|
|
44629
|
+
this.saveState();
|
|
44630
|
+
}
|
|
44631
|
+
if (this.blocklist.some((b) => b.ip === ip)) {
|
|
44632
|
+
void this.unban(ip, { forget: true, reason: "operator address (key login or live session)" });
|
|
44633
|
+
}
|
|
44634
|
+
}
|
|
44635
|
+
/**
|
|
44636
|
+
* Key-based SSH logins in the memory window, by keys that belong to people:
|
|
44637
|
+
* a key whose comment marks automation (a CI deploy key) logs in from
|
|
44638
|
+
* shared cloud runners, and remembering those would allowlist hundreds of
|
|
44639
|
+
* strangers' addresses — dev2 saw 308 distinct key-login IPs in 30 days.
|
|
44640
|
+
*/
|
|
44641
|
+
async seedOperatorsFromJournal() {
|
|
44642
|
+
try {
|
|
44643
|
+
const automation = this.discovery.automationKeys();
|
|
44644
|
+
const journal = await this.discovery.keyLoginJournal(this.config.operator_memory_seconds);
|
|
44645
|
+
for (const [ip, at] of parseKeyLogins(journal, (fp) => automation.has(fp))) this.noteOperator(ip, at);
|
|
44646
|
+
} catch {
|
|
44647
|
+
}
|
|
44648
|
+
}
|
|
44451
44649
|
/** Every address that can never be blocked, built-ins included. */
|
|
44452
44650
|
getProtected() {
|
|
44453
44651
|
return [...this.protectedList];
|
|
@@ -44462,10 +44660,9 @@ var RemediationManager = class {
|
|
|
44462
44660
|
*/
|
|
44463
44661
|
refreshSshProtection() {
|
|
44464
44662
|
if (!this.config.protect_current_ssh_client) return;
|
|
44465
|
-
const
|
|
44466
|
-
for (const ip of
|
|
44467
|
-
|
|
44468
|
-
}
|
|
44663
|
+
const now = Date.now();
|
|
44664
|
+
for (const ip of this.discovery.sshPeers()) this.noteOperator(ip, now, false);
|
|
44665
|
+
for (const ip of this.discovery.moshClients()) this.noteOperator(ip, now);
|
|
44469
44666
|
}
|
|
44470
44667
|
isAllowlisted(ip) {
|
|
44471
44668
|
return isProtected(ip, this.protectedList);
|
|
@@ -44664,7 +44861,9 @@ var RemediationManager = class {
|
|
|
44664
44861
|
}
|
|
44665
44862
|
stop() {
|
|
44666
44863
|
if (this.expiryTimer) clearInterval(this.expiryTimer);
|
|
44864
|
+
if (this.operatorTimer) clearInterval(this.operatorTimer);
|
|
44667
44865
|
this.expiryTimer = null;
|
|
44866
|
+
this.operatorTimer = null;
|
|
44668
44867
|
}
|
|
44669
44868
|
/**
|
|
44670
44869
|
* R5: bans survive a restart, their TTLs do not. Anything that expired while
|
|
@@ -44713,6 +44912,10 @@ var RemediationManager = class {
|
|
|
44713
44912
|
startExpiryWorker() {
|
|
44714
44913
|
this.expiryTimer = setInterval(() => void this.processExpiries(), 1e4);
|
|
44715
44914
|
this.expiryTimer.unref?.();
|
|
44915
|
+
if (this.config.protect_recent_operators) {
|
|
44916
|
+
this.operatorTimer = setInterval(() => void this.seedOperatorsFromJournal(), 36e5);
|
|
44917
|
+
this.operatorTimer.unref?.();
|
|
44918
|
+
}
|
|
44716
44919
|
}
|
|
44717
44920
|
async processExpiries() {
|
|
44718
44921
|
const now = Date.now();
|
|
@@ -44725,6 +44928,12 @@ var RemediationManager = class {
|
|
|
44725
44928
|
this.strikes = pruned;
|
|
44726
44929
|
this.saveState();
|
|
44727
44930
|
}
|
|
44931
|
+
const cutoff = now - this.config.operator_memory_seconds * 1e3;
|
|
44932
|
+
const stale = Object.keys(this.operators).filter((ip) => this.operators[ip] < cutoff);
|
|
44933
|
+
if (stale.length > 0) {
|
|
44934
|
+
for (const ip of stale) delete this.operators[ip];
|
|
44935
|
+
this.saveState();
|
|
44936
|
+
}
|
|
44728
44937
|
}
|
|
44729
44938
|
loadState() {
|
|
44730
44939
|
try {
|
|
@@ -44744,6 +44953,18 @@ var RemediationManager = class {
|
|
|
44744
44953
|
if (saved && typeof saved === "object") this.strikes = saved;
|
|
44745
44954
|
} catch {
|
|
44746
44955
|
}
|
|
44956
|
+
try {
|
|
44957
|
+
const saved = getModuleState("firewall-rules", "operators");
|
|
44958
|
+
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
44959
|
+
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
44960
|
+
for (const [ip, at] of Object.entries(saved)) {
|
|
44961
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net11.isIP)(ip)) continue;
|
|
44962
|
+
this.operators[ip] = at;
|
|
44963
|
+
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
44964
|
+
}
|
|
44965
|
+
}
|
|
44966
|
+
} catch {
|
|
44967
|
+
}
|
|
44747
44968
|
}
|
|
44748
44969
|
saveState() {
|
|
44749
44970
|
try {
|
|
@@ -44754,10 +44975,14 @@ var RemediationManager = class {
|
|
|
44754
44975
|
setModuleState("firewall-rules", "strikes", this.strikes);
|
|
44755
44976
|
} catch {
|
|
44756
44977
|
}
|
|
44978
|
+
try {
|
|
44979
|
+
setModuleState("firewall-rules", "operators", this.operators);
|
|
44980
|
+
} catch {
|
|
44981
|
+
}
|
|
44757
44982
|
}
|
|
44758
44983
|
logLine(line2) {
|
|
44759
44984
|
try {
|
|
44760
|
-
(0,
|
|
44985
|
+
(0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
44761
44986
|
`);
|
|
44762
44987
|
} catch {
|
|
44763
44988
|
}
|
|
@@ -44785,6 +45010,11 @@ function remediationSettings(section) {
|
|
|
44785
45010
|
if (typeof section.protect_current_ssh_client === "boolean") {
|
|
44786
45011
|
settings.protect_current_ssh_client = section.protect_current_ssh_client;
|
|
44787
45012
|
}
|
|
45013
|
+
if (typeof section.protect_recent_operators === "boolean") {
|
|
45014
|
+
settings.protect_recent_operators = section.protect_recent_operators;
|
|
45015
|
+
}
|
|
45016
|
+
const operatorMemory = parseDuration(section.operator_memory);
|
|
45017
|
+
if (operatorMemory) settings.operator_memory_seconds = operatorMemory;
|
|
44788
45018
|
if (typeof section.spare_verified_crawlers === "boolean") {
|
|
44789
45019
|
settings.spare_verified_crawlers = section.spare_verified_crawlers;
|
|
44790
45020
|
}
|
|
@@ -44795,19 +45025,19 @@ function remediationSettings(section) {
|
|
|
44795
45025
|
init_backoff();
|
|
44796
45026
|
|
|
44797
45027
|
// src/daemon/watchdog-service.ts
|
|
44798
|
-
var
|
|
44799
|
-
var
|
|
45028
|
+
var import_node_fs38 = require("fs");
|
|
45029
|
+
var import_node_path28 = require("path");
|
|
44800
45030
|
function defaultShareGid() {
|
|
44801
45031
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
44802
45032
|
if (!isRoot4) return void 0;
|
|
44803
45033
|
try {
|
|
44804
|
-
return (0,
|
|
45034
|
+
return (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
|
|
44805
45035
|
} catch {
|
|
44806
45036
|
return void 0;
|
|
44807
45037
|
}
|
|
44808
45038
|
}
|
|
44809
45039
|
function startWatchdog(opts) {
|
|
44810
|
-
const dir = opts.config?.dir ?? (0,
|
|
45040
|
+
const dir = opts.config?.dir ?? (0, import_node_path28.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
44811
45041
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
44812
45042
|
if (opts.config?.enabled === false) {
|
|
44813
45043
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -44901,7 +45131,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
44901
45131
|
}
|
|
44902
45132
|
|
|
44903
45133
|
// src/core/node-runtime.ts
|
|
44904
|
-
var
|
|
45134
|
+
var import_node_child_process14 = require("child_process");
|
|
44905
45135
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
44906
45136
|
function nodeMajor(version) {
|
|
44907
45137
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -44915,23 +45145,23 @@ function daemonNodeProblem(version) {
|
|
|
44915
45145
|
}
|
|
44916
45146
|
function versionOfNode(path) {
|
|
44917
45147
|
if (path === process.execPath) return process.versions.node;
|
|
44918
|
-
const res = (0,
|
|
45148
|
+
const res = (0, import_node_child_process14.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
44919
45149
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
44920
45150
|
}
|
|
44921
45151
|
|
|
44922
45152
|
// src/daemon/index.ts
|
|
44923
45153
|
function readVersion2() {
|
|
44924
45154
|
try {
|
|
44925
|
-
const pkg = JSON.parse((0,
|
|
45155
|
+
const pkg = JSON.parse((0, import_node_fs39.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
44926
45156
|
return pkg.version || "0.0.0";
|
|
44927
45157
|
} catch {
|
|
44928
45158
|
return "0.0.0";
|
|
44929
45159
|
}
|
|
44930
45160
|
}
|
|
44931
45161
|
async function runHardeningChecks() {
|
|
44932
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
45162
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
|
|
44933
45163
|
process.execPath,
|
|
44934
|
-
[(0,
|
|
45164
|
+
[(0, import_node_path29.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
44935
45165
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
44936
45166
|
);
|
|
44937
45167
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -44943,9 +45173,9 @@ async function runHardeningChecks() {
|
|
|
44943
45173
|
return patches ? [...findings, patches] : findings;
|
|
44944
45174
|
}
|
|
44945
45175
|
async function runPatchCheck() {
|
|
44946
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
45176
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
|
|
44947
45177
|
process.execPath,
|
|
44948
|
-
[(0,
|
|
45178
|
+
[(0, import_node_path29.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
44949
45179
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
44950
45180
|
);
|
|
44951
45181
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -44953,7 +45183,7 @@ async function runPatchCheck() {
|
|
|
44953
45183
|
}
|
|
44954
45184
|
function logLine(line2) {
|
|
44955
45185
|
try {
|
|
44956
|
-
(0,
|
|
45186
|
+
(0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
44957
45187
|
`);
|
|
44958
45188
|
} catch {
|
|
44959
45189
|
}
|
|
@@ -44978,9 +45208,9 @@ async function runDaemon() {
|
|
|
44978
45208
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
44979
45209
|
const restartDaemon = () => {
|
|
44980
45210
|
if (PATHS.mode === "system") {
|
|
44981
|
-
(0,
|
|
45211
|
+
(0, import_node_child_process15.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
44982
45212
|
} else {
|
|
44983
|
-
(0,
|
|
45213
|
+
(0, import_node_child_process15.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
44984
45214
|
setTimeout(() => process.exit(0), 500).unref();
|
|
44985
45215
|
}
|
|
44986
45216
|
};
|
|
@@ -44995,7 +45225,7 @@ async function runDaemon() {
|
|
|
44995
45225
|
} catch (err) {
|
|
44996
45226
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
44997
45227
|
}
|
|
44998
|
-
const config = loadConfig((0,
|
|
45228
|
+
const config = loadConfig((0, import_node_fs39.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
44999
45229
|
configureAttackDetection(config.detection);
|
|
45000
45230
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
45001
45231
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -45059,7 +45289,7 @@ async function runDaemon() {
|
|
|
45059
45289
|
const threatFeeds = new ThreatFeeds({
|
|
45060
45290
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
45061
45291
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
45062
|
-
cachePath: (0,
|
|
45292
|
+
cachePath: (0, import_node_path29.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
45063
45293
|
bus,
|
|
45064
45294
|
log: logLine
|
|
45065
45295
|
});
|
|
@@ -45067,9 +45297,9 @@ async function runDaemon() {
|
|
|
45067
45297
|
const privilegeWatch = new PrivilegeWatch({
|
|
45068
45298
|
settings: privilegeSettings(config.privileged),
|
|
45069
45299
|
bus,
|
|
45070
|
-
snapshotPath: (0,
|
|
45071
|
-
loginsPath: (0,
|
|
45072
|
-
cursorPath: (0,
|
|
45300
|
+
snapshotPath: (0, import_node_path29.join)(PATHS.stateDir, "privileges.json"),
|
|
45301
|
+
loginsPath: (0, import_node_path29.join)(PATHS.stateDir, "login-countries.json"),
|
|
45302
|
+
cursorPath: (0, import_node_path29.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
45073
45303
|
log: logLine
|
|
45074
45304
|
});
|
|
45075
45305
|
privilegeWatch.start();
|
|
@@ -45092,7 +45322,7 @@ async function runDaemon() {
|
|
|
45092
45322
|
version,
|
|
45093
45323
|
hostname: (0, import_node_os11.hostname)(),
|
|
45094
45324
|
minSeverity,
|
|
45095
|
-
spoolPath: (0,
|
|
45325
|
+
spoolPath: (0, import_node_path29.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
45096
45326
|
log: logLine,
|
|
45097
45327
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
45098
45328
|
runHardening: runHardeningChecks
|
|
@@ -45109,8 +45339,8 @@ async function runDaemon() {
|
|
|
45109
45339
|
const autoUpdate = new AutoUpdate({
|
|
45110
45340
|
version,
|
|
45111
45341
|
settings: updateSettings(config.update),
|
|
45112
|
-
pkgRoot: (0,
|
|
45113
|
-
statePath: (0,
|
|
45342
|
+
pkgRoot: (0, import_node_path29.join)(__dirname, ".."),
|
|
45343
|
+
statePath: (0, import_node_path29.join)(PATHS.stateDir, "auto-update.json"),
|
|
45114
45344
|
bus,
|
|
45115
45345
|
log: logLine,
|
|
45116
45346
|
restartDaemon
|
|
@@ -45196,7 +45426,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
45196
45426
|
function isRoot2() {
|
|
45197
45427
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
45198
45428
|
}
|
|
45199
|
-
var DAEMON_ENTRY = (0,
|
|
45429
|
+
var DAEMON_ENTRY = (0, import_node_path30.join)(__dirname, "daemon.js");
|
|
45200
45430
|
async function daemonForeground() {
|
|
45201
45431
|
await runDaemon();
|
|
45202
45432
|
}
|
|
@@ -45217,7 +45447,7 @@ async function daemonStart() {
|
|
|
45217
45447
|
return;
|
|
45218
45448
|
}
|
|
45219
45449
|
ensureRuntimeDirs();
|
|
45220
|
-
if (!(0,
|
|
45450
|
+
if (!(0, import_node_fs40.existsSync)(DAEMON_ENTRY)) {
|
|
45221
45451
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
45222
45452
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
45223
45453
|
return;
|
|
@@ -45225,8 +45455,8 @@ async function daemonStart() {
|
|
|
45225
45455
|
let out;
|
|
45226
45456
|
let err;
|
|
45227
45457
|
try {
|
|
45228
|
-
out = (0,
|
|
45229
|
-
err = (0,
|
|
45458
|
+
out = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
|
|
45459
|
+
err = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
|
|
45230
45460
|
} catch (e) {
|
|
45231
45461
|
const code = e.code;
|
|
45232
45462
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -45239,7 +45469,7 @@ async function daemonStart() {
|
|
|
45239
45469
|
}
|
|
45240
45470
|
return;
|
|
45241
45471
|
}
|
|
45242
|
-
const child = (0,
|
|
45472
|
+
const child = (0, import_node_child_process16.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
45243
45473
|
detached: true,
|
|
45244
45474
|
stdio: ["ignore", out, err],
|
|
45245
45475
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -45314,41 +45544,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
45314
45544
|
}
|
|
45315
45545
|
async function releaseStaleSocket() {
|
|
45316
45546
|
const deadline = Date.now() + 2e3;
|
|
45317
|
-
while ((0,
|
|
45547
|
+
while ((0, import_node_fs40.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
45318
45548
|
await new Promise((r) => setTimeout(r, 50));
|
|
45319
45549
|
}
|
|
45320
|
-
if ((0,
|
|
45550
|
+
if ((0, import_node_fs40.existsSync)(PATHS.socket)) {
|
|
45321
45551
|
try {
|
|
45322
|
-
(0,
|
|
45552
|
+
(0, import_node_fs40.unlinkSync)(PATHS.socket);
|
|
45323
45553
|
} catch {
|
|
45324
45554
|
}
|
|
45325
45555
|
}
|
|
45326
45556
|
}
|
|
45327
45557
|
|
|
45328
45558
|
// src/commands/service.ts
|
|
45329
|
-
var
|
|
45330
|
-
var
|
|
45331
|
-
var
|
|
45559
|
+
var import_node_child_process17 = require("child_process");
|
|
45560
|
+
var import_node_fs42 = require("fs");
|
|
45561
|
+
var import_node_path31 = require("path");
|
|
45332
45562
|
var import_node_os12 = require("os");
|
|
45333
45563
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
45334
45564
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
45335
45565
|
function resolveTemplate() {
|
|
45336
|
-
const templatePath = (0,
|
|
45337
|
-
if (!(0,
|
|
45566
|
+
const templatePath = (0, import_node_path31.join)(__dirname, "systemd", "threatcrushd.service");
|
|
45567
|
+
if (!(0, import_node_fs42.existsSync)(templatePath)) {
|
|
45338
45568
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
45339
45569
|
}
|
|
45340
|
-
return (0,
|
|
45570
|
+
return (0, import_node_fs42.readFileSync)(templatePath, "utf-8");
|
|
45341
45571
|
}
|
|
45342
45572
|
function stableBinPath(binPath) {
|
|
45343
45573
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
45344
45574
|
if (stable === binPath) return binPath;
|
|
45345
|
-
return (0,
|
|
45575
|
+
return (0, import_node_fs42.existsSync)(stable) ? stable : binPath;
|
|
45346
45576
|
}
|
|
45347
45577
|
function resolveBinPath() {
|
|
45348
45578
|
const arg = process.argv[1];
|
|
45349
|
-
if (arg && (0,
|
|
45579
|
+
if (arg && (0, import_node_fs42.existsSync)(arg)) return stableBinPath(arg);
|
|
45350
45580
|
try {
|
|
45351
|
-
return (0,
|
|
45581
|
+
return (0, import_node_child_process17.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
45352
45582
|
} catch {
|
|
45353
45583
|
return "threatcrush";
|
|
45354
45584
|
}
|
|
@@ -45356,11 +45586,11 @@ function resolveBinPath() {
|
|
|
45356
45586
|
function stableNodePath(execPath) {
|
|
45357
45587
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
45358
45588
|
if (stable === execPath) return execPath;
|
|
45359
|
-
return (0,
|
|
45589
|
+
return (0, import_node_fs42.existsSync)(stable) ? stable : execPath;
|
|
45360
45590
|
}
|
|
45361
45591
|
function looksLikeNodeScript(path) {
|
|
45362
45592
|
try {
|
|
45363
|
-
const head = (0,
|
|
45593
|
+
const head = (0, import_node_fs42.readFileSync)(path, "utf-8").slice(0, 120);
|
|
45364
45594
|
return /^#!.*\bnode\b/.test(head);
|
|
45365
45595
|
} catch {
|
|
45366
45596
|
return false;
|
|
@@ -45387,20 +45617,20 @@ function isRoot3() {
|
|
|
45387
45617
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
45388
45618
|
}
|
|
45389
45619
|
function reexecWithSudo(args) {
|
|
45390
|
-
if ((0,
|
|
45620
|
+
if ((0, import_node_child_process17.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
45391
45621
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
45392
45622
|
const bin = resolveBinPath();
|
|
45393
45623
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
45394
|
-
const result = (0,
|
|
45624
|
+
const result = (0, import_node_child_process17.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
45395
45625
|
return result.status === 0;
|
|
45396
45626
|
}
|
|
45397
45627
|
function callerHome() {
|
|
45398
45628
|
const user = process.env.SUDO_USER;
|
|
45399
45629
|
if (!user) return null;
|
|
45400
45630
|
try {
|
|
45401
|
-
const line2 = (0,
|
|
45631
|
+
const line2 = (0, import_node_child_process17.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
45402
45632
|
const home = line2.split(":")[5];
|
|
45403
|
-
return home && (0,
|
|
45633
|
+
return home && (0, import_node_fs42.existsSync)(home) ? home : null;
|
|
45404
45634
|
} catch {
|
|
45405
45635
|
return null;
|
|
45406
45636
|
}
|
|
@@ -45408,13 +45638,13 @@ function callerHome() {
|
|
|
45408
45638
|
function stopUserModeDaemon() {
|
|
45409
45639
|
const home = callerHome();
|
|
45410
45640
|
if (!home) return;
|
|
45411
|
-
const runDir = (0,
|
|
45412
|
-
const pidFile = (0,
|
|
45413
|
-
const socket = (0,
|
|
45414
|
-
if (!(0,
|
|
45641
|
+
const runDir = (0, import_node_path31.join)(home, ".threatcrush", "run");
|
|
45642
|
+
const pidFile = (0, import_node_path31.join)(runDir, "threatcrushd.pid");
|
|
45643
|
+
const socket = (0, import_node_path31.join)(runDir, "threatcrushd.sock");
|
|
45644
|
+
if (!(0, import_node_fs42.existsSync)(pidFile) && !(0, import_node_fs42.existsSync)(socket)) return;
|
|
45415
45645
|
let pid = null;
|
|
45416
45646
|
try {
|
|
45417
|
-
pid = Number.parseInt((0,
|
|
45647
|
+
pid = Number.parseInt((0, import_node_fs42.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
45418
45648
|
} catch {
|
|
45419
45649
|
pid = null;
|
|
45420
45650
|
}
|
|
@@ -45427,13 +45657,13 @@ function stopUserModeDaemon() {
|
|
|
45427
45657
|
}
|
|
45428
45658
|
for (const path of [socket, pidFile]) {
|
|
45429
45659
|
try {
|
|
45430
|
-
if ((0,
|
|
45660
|
+
if ((0, import_node_fs42.existsSync)(path)) (0, import_node_fs42.rmSync)(path);
|
|
45431
45661
|
} catch {
|
|
45432
45662
|
}
|
|
45433
45663
|
}
|
|
45434
45664
|
}
|
|
45435
45665
|
function unitIsActive() {
|
|
45436
|
-
const result = (0,
|
|
45666
|
+
const result = (0, import_node_child_process17.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
45437
45667
|
return result.status === 0;
|
|
45438
45668
|
}
|
|
45439
45669
|
async function installServiceCommand() {
|
|
@@ -45444,8 +45674,8 @@ async function installServiceCommand() {
|
|
|
45444
45674
|
return;
|
|
45445
45675
|
}
|
|
45446
45676
|
const noSystemd = systemdUnavailableReason({
|
|
45447
|
-
hasSystemctl: (0,
|
|
45448
|
-
booted: (0,
|
|
45677
|
+
hasSystemctl: (0, import_node_child_process17.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
45678
|
+
booted: (0, import_node_fs42.existsSync)("/run/systemd/system")
|
|
45449
45679
|
});
|
|
45450
45680
|
if (noSystemd) {
|
|
45451
45681
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -45467,7 +45697,7 @@ async function installServiceCommand() {
|
|
|
45467
45697
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
45468
45698
|
let nodePath = stableNodePath(process.execPath);
|
|
45469
45699
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
45470
|
-
binPath = (0,
|
|
45700
|
+
binPath = (0, import_node_fs42.realpathSync)(binPath);
|
|
45471
45701
|
nodePath = process.execPath;
|
|
45472
45702
|
}
|
|
45473
45703
|
if (isNodeScript) {
|
|
@@ -45480,9 +45710,9 @@ async function installServiceCommand() {
|
|
|
45480
45710
|
}
|
|
45481
45711
|
}
|
|
45482
45712
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
45483
|
-
const configDir = (0,
|
|
45713
|
+
const configDir = (0, import_node_path31.join)((0, import_node_os12.homedir)(), ".threatcrush");
|
|
45484
45714
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
45485
|
-
(0,
|
|
45715
|
+
(0, import_node_fs42.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
45486
45716
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
45487
45717
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
45488
45718
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -45497,8 +45727,8 @@ async function installServiceCommand() {
|
|
|
45497
45727
|
installLogrotate();
|
|
45498
45728
|
stopUserModeDaemon();
|
|
45499
45729
|
try {
|
|
45500
|
-
(0,
|
|
45501
|
-
(0,
|
|
45730
|
+
(0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
45731
|
+
(0, import_node_child_process17.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
45502
45732
|
} catch (err) {
|
|
45503
45733
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
45504
45734
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -45535,9 +45765,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
45535
45765
|
].join("\n");
|
|
45536
45766
|
}
|
|
45537
45767
|
function installLogrotate() {
|
|
45538
|
-
if (!(0,
|
|
45768
|
+
if (!(0, import_node_fs42.existsSync)((0, import_node_path31.dirname)(LOGROTATE_PATH))) return;
|
|
45539
45769
|
try {
|
|
45540
|
-
(0,
|
|
45770
|
+
(0, import_node_fs42.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
45541
45771
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
45542
45772
|
} catch (err) {
|
|
45543
45773
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -45559,20 +45789,20 @@ function ensureSystemDirs(configDir) {
|
|
|
45559
45789
|
];
|
|
45560
45790
|
let admGid2 = null;
|
|
45561
45791
|
try {
|
|
45562
|
-
admGid2 = (0,
|
|
45792
|
+
admGid2 = (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
|
|
45563
45793
|
} catch {
|
|
45564
45794
|
}
|
|
45565
45795
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
45566
45796
|
try {
|
|
45567
|
-
(0,
|
|
45797
|
+
(0, import_node_fs42.mkdirSync)(path, { recursive: true });
|
|
45568
45798
|
} catch {
|
|
45569
45799
|
}
|
|
45570
45800
|
try {
|
|
45571
45801
|
if (groupWritable && admGid2 !== null) {
|
|
45572
|
-
(0,
|
|
45573
|
-
(0,
|
|
45802
|
+
(0, import_node_fs42.chmodSync)(path, sticky ? 1533 : 509);
|
|
45803
|
+
(0, import_node_child_process17.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
45574
45804
|
} else {
|
|
45575
|
-
(0,
|
|
45805
|
+
(0, import_node_fs42.chmodSync)(path, 493);
|
|
45576
45806
|
}
|
|
45577
45807
|
} catch {
|
|
45578
45808
|
}
|
|
@@ -45592,29 +45822,29 @@ async function uninstallServiceCommand() {
|
|
|
45592
45822
|
return;
|
|
45593
45823
|
}
|
|
45594
45824
|
try {
|
|
45595
|
-
(0,
|
|
45825
|
+
(0, import_node_child_process17.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
45596
45826
|
} catch {
|
|
45597
45827
|
}
|
|
45598
45828
|
try {
|
|
45599
|
-
(0,
|
|
45829
|
+
(0, import_node_child_process17.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
45600
45830
|
} catch {
|
|
45601
45831
|
}
|
|
45602
45832
|
try {
|
|
45603
|
-
if ((0,
|
|
45604
|
-
(0,
|
|
45833
|
+
if ((0, import_node_fs42.existsSync)(UNIT_PATH)) {
|
|
45834
|
+
(0, import_node_child_process17.execSync)(`rm -f ${UNIT_PATH}`);
|
|
45605
45835
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
45606
45836
|
}
|
|
45607
45837
|
} catch {
|
|
45608
45838
|
}
|
|
45609
45839
|
try {
|
|
45610
|
-
(0,
|
|
45840
|
+
(0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
45611
45841
|
} catch {
|
|
45612
45842
|
}
|
|
45613
45843
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
45614
45844
|
}
|
|
45615
45845
|
|
|
45616
45846
|
// src/commands/save.ts
|
|
45617
|
-
var
|
|
45847
|
+
var import_node_fs43 = require("fs");
|
|
45618
45848
|
var import_toml5 = __toESM(require_toml());
|
|
45619
45849
|
init_cli_config();
|
|
45620
45850
|
init_paths();
|
|
@@ -45653,9 +45883,9 @@ async function saveCommand(opts = {}) {
|
|
|
45653
45883
|
}
|
|
45654
45884
|
const path = opts.config ?? PATHS.configFile;
|
|
45655
45885
|
let config = {};
|
|
45656
|
-
if ((0,
|
|
45886
|
+
if ((0, import_node_fs43.existsSync)(path)) {
|
|
45657
45887
|
try {
|
|
45658
|
-
config = import_toml5.default.parse((0,
|
|
45888
|
+
config = import_toml5.default.parse((0, import_node_fs43.readFileSync)(path, "utf-8"));
|
|
45659
45889
|
} catch (err) {
|
|
45660
45890
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
45661
45891
|
`));
|
|
@@ -45768,8 +45998,8 @@ function welcomeCommand() {
|
|
|
45768
45998
|
}
|
|
45769
45999
|
|
|
45770
46000
|
// src/commands/properties.ts
|
|
45771
|
-
var
|
|
45772
|
-
var
|
|
46001
|
+
var import_node_fs44 = require("fs");
|
|
46002
|
+
var import_node_path32 = require("path");
|
|
45773
46003
|
var import_node_readline4 = __toESM(require("readline"));
|
|
45774
46004
|
init_cli_config();
|
|
45775
46005
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -46099,8 +46329,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
46099
46329
|
}
|
|
46100
46330
|
}
|
|
46101
46331
|
function parseImportFile(path) {
|
|
46102
|
-
const ext = (0,
|
|
46103
|
-
const raw = (0,
|
|
46332
|
+
const ext = (0, import_node_path32.extname)(path).toLowerCase();
|
|
46333
|
+
const raw = (0, import_node_fs44.readFileSync)(path, "utf-8");
|
|
46104
46334
|
if (ext === ".json") {
|
|
46105
46335
|
const parsed = JSON.parse(raw);
|
|
46106
46336
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -46295,19 +46525,19 @@ async function rulesCommand(opts) {
|
|
|
46295
46525
|
}
|
|
46296
46526
|
|
|
46297
46527
|
// src/commands/harden.ts
|
|
46298
|
-
var
|
|
46299
|
-
var
|
|
46528
|
+
var import_node_fs45 = require("fs");
|
|
46529
|
+
var import_node_child_process18 = require("child_process");
|
|
46300
46530
|
init_cli_config();
|
|
46301
46531
|
function tryExec(cmd) {
|
|
46302
46532
|
try {
|
|
46303
|
-
return (0,
|
|
46533
|
+
return (0, import_node_child_process18.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
46304
46534
|
} catch {
|
|
46305
46535
|
return null;
|
|
46306
46536
|
}
|
|
46307
46537
|
}
|
|
46308
46538
|
function tryRead(path) {
|
|
46309
46539
|
try {
|
|
46310
|
-
return (0,
|
|
46540
|
+
return (0, import_node_fs45.readFileSync)(path, "utf-8");
|
|
46311
46541
|
} catch {
|
|
46312
46542
|
return null;
|
|
46313
46543
|
}
|
|
@@ -46411,8 +46641,8 @@ function checkSshWeakConfig() {
|
|
|
46411
46641
|
};
|
|
46412
46642
|
}
|
|
46413
46643
|
function checkAutoUpdates() {
|
|
46414
|
-
const unattended = (0,
|
|
46415
|
-
const dnfAuto = (0,
|
|
46644
|
+
const unattended = (0, import_node_fs45.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs45.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
46645
|
+
const dnfAuto = (0, import_node_fs45.existsSync)("/etc/dnf/automatic.conf");
|
|
46416
46646
|
if (unattended || dnfAuto) {
|
|
46417
46647
|
return {
|
|
46418
46648
|
key: "auto-updates",
|
|
@@ -46538,7 +46768,7 @@ function checkFail2ban() {
|
|
|
46538
46768
|
explanation: "fail2ban is installed and running."
|
|
46539
46769
|
};
|
|
46540
46770
|
}
|
|
46541
|
-
if ((0,
|
|
46771
|
+
if ((0, import_node_fs45.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
46542
46772
|
return {
|
|
46543
46773
|
key: checkKey,
|
|
46544
46774
|
status: "warn",
|
|
@@ -46724,9 +46954,9 @@ async function hardenCommand(opts) {
|
|
|
46724
46954
|
}
|
|
46725
46955
|
|
|
46726
46956
|
// src/core/patches/index.ts
|
|
46727
|
-
var
|
|
46728
|
-
var
|
|
46729
|
-
var
|
|
46957
|
+
var import_node_fs46 = require("fs");
|
|
46958
|
+
var import_node_path33 = require("path");
|
|
46959
|
+
var import_node_child_process19 = require("child_process");
|
|
46730
46960
|
var import_node_util2 = require("util");
|
|
46731
46961
|
|
|
46732
46962
|
// src/core/patches/dpkg-version.ts
|
|
@@ -46786,7 +47016,7 @@ var STALE_AFTER_MS = 2 * 864e5;
|
|
|
46786
47016
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
46787
47017
|
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
46788
47018
|
var defaultExec = async (file, args) => {
|
|
46789
|
-
const { stdout } = await (0, import_node_util2.promisify)(
|
|
47019
|
+
const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process19.execFile)(file, args, {
|
|
46790
47020
|
timeout: 12e4,
|
|
46791
47021
|
maxBuffer: 32 * 1024 * 1024,
|
|
46792
47022
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -46885,9 +47115,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
46885
47115
|
function newestReleaseMtime(dir) {
|
|
46886
47116
|
try {
|
|
46887
47117
|
let newest = 0;
|
|
46888
|
-
for (const name of (0,
|
|
47118
|
+
for (const name of (0, import_node_fs46.readdirSync)(dir)) {
|
|
46889
47119
|
if (!/Release$/.test(name)) continue;
|
|
46890
|
-
newest = Math.max(newest, (0,
|
|
47120
|
+
newest = Math.max(newest, (0, import_node_fs46.statSync)((0, import_node_path33.join)(dir, name)).mtimeMs);
|
|
46891
47121
|
}
|
|
46892
47122
|
return newest > 0 ? new Date(newest) : null;
|
|
46893
47123
|
} catch {
|
|
@@ -46904,7 +47134,7 @@ async function checkPatches(opts = {}) {
|
|
|
46904
47134
|
let osText = opts.osRelease;
|
|
46905
47135
|
if (osText === void 0) {
|
|
46906
47136
|
try {
|
|
46907
|
-
osText = (0,
|
|
47137
|
+
osText = (0, import_node_fs46.readFileSync)("/etc/os-release", "utf-8");
|
|
46908
47138
|
} catch {
|
|
46909
47139
|
osText = "";
|
|
46910
47140
|
}
|
|
@@ -47131,18 +47361,142 @@ async function patchesCommand(opts) {
|
|
|
47131
47361
|
|
|
47132
47362
|
// src/commands/feeds.ts
|
|
47133
47363
|
var import_node_net12 = require("net");
|
|
47134
|
-
var
|
|
47364
|
+
var import_node_path35 = require("path");
|
|
47135
47365
|
init_paths();
|
|
47366
|
+
|
|
47367
|
+
// src/commands/feeds-resolver.ts
|
|
47368
|
+
var import_node_child_process20 = require("child_process");
|
|
47369
|
+
var import_node_fs47 = require("fs");
|
|
47370
|
+
var import_node_path34 = require("path");
|
|
47371
|
+
var realIO = {
|
|
47372
|
+
exists: (p) => (0, import_node_fs47.existsSync)(p),
|
|
47373
|
+
read: (p) => {
|
|
47374
|
+
try {
|
|
47375
|
+
return (0, import_node_fs47.readFileSync)(p, "utf-8");
|
|
47376
|
+
} catch {
|
|
47377
|
+
return null;
|
|
47378
|
+
}
|
|
47379
|
+
},
|
|
47380
|
+
write: (p, c) => (0, import_node_fs47.writeFileSync)(p, c),
|
|
47381
|
+
remove: (p) => (0, import_node_fs47.rmSync)(p, { force: true }),
|
|
47382
|
+
run: (cmd, args) => {
|
|
47383
|
+
const r = (0, import_node_child_process20.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
47384
|
+
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
47385
|
+
}
|
|
47386
|
+
};
|
|
47387
|
+
var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
47388
|
+
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
47389
|
+
function hookContent(resolver, stateDir) {
|
|
47390
|
+
const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
47391
|
+
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
47392
|
+
` : `${head}include: "${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
47393
|
+
`;
|
|
47394
|
+
}
|
|
47395
|
+
function apparmorRule(stateDir) {
|
|
47396
|
+
return ` ${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
47397
|
+
}
|
|
47398
|
+
function detectResolvers(io = realIO) {
|
|
47399
|
+
const found = [];
|
|
47400
|
+
if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
47401
|
+
if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
47402
|
+
return found;
|
|
47403
|
+
}
|
|
47404
|
+
function check(resolver, io) {
|
|
47405
|
+
return resolver === "dnsmasq" ? io.run("dnsmasq", ["--test"]) : io.run("unbound-checkconf", []);
|
|
47406
|
+
}
|
|
47407
|
+
function restartIfActive(resolver, io) {
|
|
47408
|
+
if (io.run("systemctl", ["is-active", "--quiet", `${resolver}.service`]).code !== 0) return "not running; takes effect when it starts";
|
|
47409
|
+
const r = io.run("systemctl", ["restart", `${resolver}.service`]);
|
|
47410
|
+
return r.code === 0 ? "restarted" : `restart failed: ${r.out.split("\n")[0]}`;
|
|
47411
|
+
}
|
|
47412
|
+
function installHook(resolver, stateDir, io = realIO) {
|
|
47413
|
+
const hook = RESOLVER_HOOKS[resolver];
|
|
47414
|
+
const file = (0, import_node_path34.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
47415
|
+
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
47416
|
+
io.write(hook, hookContent(resolver, stateDir));
|
|
47417
|
+
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
47418
|
+
const local = io.read(APPARMOR_LOCAL) ?? "";
|
|
47419
|
+
if (!local.includes(apparmorRule(stateDir))) io.write(APPARMOR_LOCAL, `${local.replace(/\n?$/, "\n")}${apparmorRule(stateDir)}
|
|
47420
|
+
`);
|
|
47421
|
+
if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
|
|
47422
|
+
}
|
|
47423
|
+
const checked = check(resolver, io);
|
|
47424
|
+
if (checked.code !== 0) {
|
|
47425
|
+
removeHook(resolver, stateDir, io, { restart: false });
|
|
47426
|
+
return { ok: false, message: `${resolver} rejected the config, so nothing was changed: ${checked.out.split("\n").slice(-2).join(" ")}` };
|
|
47427
|
+
}
|
|
47428
|
+
return { ok: true, message: `${hook} installed; ${resolver} ${restartIfActive(resolver, io)}` };
|
|
47429
|
+
}
|
|
47430
|
+
function removeHook(resolver, stateDir, io = realIO, opts = { restart: true }) {
|
|
47431
|
+
const hook = RESOLVER_HOOKS[resolver];
|
|
47432
|
+
const had = io.exists(hook);
|
|
47433
|
+
io.remove(hook);
|
|
47434
|
+
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
47435
|
+
const local = io.read(APPARMOR_LOCAL) ?? "";
|
|
47436
|
+
const kept = local.split("\n").filter((l) => l !== apparmorRule(stateDir)).join("\n");
|
|
47437
|
+
if (kept !== local) {
|
|
47438
|
+
io.write(APPARMOR_LOCAL, kept);
|
|
47439
|
+
if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
|
|
47440
|
+
}
|
|
47441
|
+
}
|
|
47442
|
+
if (!had) return `${resolver}: no hook installed`;
|
|
47443
|
+
return `${hook} removed${opts.restart ? `; ${resolver} ${restartIfActive(resolver, io)}` : ""}`;
|
|
47444
|
+
}
|
|
47445
|
+
function countListed(text, pattern) {
|
|
47446
|
+
return text ? (text.match(pattern) ?? []).length : 0;
|
|
47447
|
+
}
|
|
47448
|
+
function resolverCommand(sub, stateDir, io = realIO) {
|
|
47449
|
+
const found = detectResolvers(io);
|
|
47450
|
+
const root = typeof process.getuid !== "function" || process.getuid() === 0;
|
|
47451
|
+
if (sub === "install" || sub === "remove") {
|
|
47452
|
+
if (!root) {
|
|
47453
|
+
console.error(`Run as root: sudo $(which threatcrush) feeds resolver ${sub}`);
|
|
47454
|
+
return 1;
|
|
47455
|
+
}
|
|
47456
|
+
if (sub === "install" && found.length === 0) {
|
|
47457
|
+
console.error("No dnsmasq or unbound here. systemd-resolved cannot refuse names from a list; listed domains stay detection-only (dns-monitor), and listed IPs can still be blocked with [threat_feeds] block = true.");
|
|
47458
|
+
return 1;
|
|
47459
|
+
}
|
|
47460
|
+
let failed = false;
|
|
47461
|
+
for (const resolver of sub === "install" ? found : ["dnsmasq", "unbound"]) {
|
|
47462
|
+
if (sub === "install") {
|
|
47463
|
+
const r = installHook(resolver, stateDir, io);
|
|
47464
|
+
failed ||= !r.ok;
|
|
47465
|
+
console.log(`${r.ok ? source_default.green("\u2713") : source_default.red("\u2717")} ${r.message}`);
|
|
47466
|
+
} else {
|
|
47467
|
+
console.log(` ${removeHook(resolver, stateDir, io)}`);
|
|
47468
|
+
}
|
|
47469
|
+
}
|
|
47470
|
+
if (sub === "install" && !failed) {
|
|
47471
|
+
console.log(source_default.gray(" Now set [threat_feeds] block_domains = true (with [remediation] in enforce mode) and restart threatcrushd; until then the lists stay empty."));
|
|
47472
|
+
}
|
|
47473
|
+
return failed ? 1 : 0;
|
|
47474
|
+
}
|
|
47475
|
+
const hosts = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts));
|
|
47476
|
+
const unbound = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound));
|
|
47477
|
+
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
47478
|
+
for (const r of ["dnsmasq", "unbound"]) {
|
|
47479
|
+
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
47480
|
+
}
|
|
47481
|
+
console.log(` listed now: ${countListed(hosts, /^0\.0\.0\.0 /gm)} names in ${RESOLVER_FILES.hosts}, ${countListed(unbound, /local-zone:/g)} zones in ${RESOLVER_FILES.unbound}`);
|
|
47482
|
+
return 0;
|
|
47483
|
+
}
|
|
47484
|
+
|
|
47485
|
+
// src/commands/feeds.ts
|
|
47136
47486
|
async function loadSet() {
|
|
47137
47487
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
47138
|
-
const path = (0,
|
|
47488
|
+
const path = (0, import_node_path35.join)(dir, "threat-feeds.json");
|
|
47139
47489
|
const set = readFeedCache(path);
|
|
47140
47490
|
if (set) return { set, from: path };
|
|
47141
47491
|
}
|
|
47142
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
47492
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path35.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
47143
47493
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
47144
47494
|
}
|
|
47145
47495
|
async function feedsCommand(action, value, opts) {
|
|
47496
|
+
if (action === "resolver") {
|
|
47497
|
+
process.exitCode = resolverCommand(value, SYSTEM_PATHS.stateDir);
|
|
47498
|
+
return;
|
|
47499
|
+
}
|
|
47146
47500
|
const { set, from } = await loadSet();
|
|
47147
47501
|
if (action === "check") {
|
|
47148
47502
|
if (!value) {
|
|
@@ -47179,7 +47533,7 @@ async function feedsCommand(action, value, opts) {
|
|
|
47179
47533
|
}
|
|
47180
47534
|
|
|
47181
47535
|
// src/commands/privileged.ts
|
|
47182
|
-
var
|
|
47536
|
+
var import_node_fs48 = require("fs");
|
|
47183
47537
|
init_paths();
|
|
47184
47538
|
var SEV2 = {
|
|
47185
47539
|
critical: source_default.red.bold,
|
|
@@ -47192,19 +47546,19 @@ async function privilegedCommand(opts) {
|
|
|
47192
47546
|
const snapshot = takeSnapshot({
|
|
47193
47547
|
readFile: (p) => {
|
|
47194
47548
|
try {
|
|
47195
|
-
return (0,
|
|
47549
|
+
return (0, import_node_fs48.readFileSync)(p, "utf-8");
|
|
47196
47550
|
} catch {
|
|
47197
47551
|
return null;
|
|
47198
47552
|
}
|
|
47199
47553
|
},
|
|
47200
47554
|
readDir: (p) => {
|
|
47201
47555
|
try {
|
|
47202
|
-
return (0,
|
|
47556
|
+
return (0, import_node_fs48.readdirSync)(p);
|
|
47203
47557
|
} catch {
|
|
47204
47558
|
return null;
|
|
47205
47559
|
}
|
|
47206
47560
|
},
|
|
47207
|
-
exists: (p) => (0,
|
|
47561
|
+
exists: (p) => (0, import_node_fs48.existsSync)(p)
|
|
47208
47562
|
});
|
|
47209
47563
|
let events = [];
|
|
47210
47564
|
let ledgerNote = "";
|
|
@@ -47389,11 +47743,11 @@ async function allowlistCommand(opts) {
|
|
|
47389
47743
|
init_paths();
|
|
47390
47744
|
|
|
47391
47745
|
// src/upgrade.ts
|
|
47392
|
-
var
|
|
47746
|
+
var import_node_child_process21 = require("child_process");
|
|
47393
47747
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
47394
47748
|
var defaultRunner = (cmd) => {
|
|
47395
47749
|
try {
|
|
47396
|
-
return (0,
|
|
47750
|
+
return (0, import_node_child_process21.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
47397
47751
|
} catch {
|
|
47398
47752
|
return null;
|
|
47399
47753
|
}
|
|
@@ -47508,25 +47862,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
47508
47862
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
47509
47863
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
47510
47864
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
47511
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
47865
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
|
|
47512
47866
|
function detectPackageManager() {
|
|
47513
47867
|
try {
|
|
47514
|
-
const npmGlobal = (0,
|
|
47868
|
+
const npmGlobal = (0, import_node_child_process22.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
47515
47869
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
47516
47870
|
} catch {
|
|
47517
47871
|
}
|
|
47518
47872
|
try {
|
|
47519
|
-
(0,
|
|
47873
|
+
(0, import_node_child_process22.execSync)("pnpm --version", { stdio: "pipe" });
|
|
47520
47874
|
return "pnpm";
|
|
47521
47875
|
} catch {
|
|
47522
47876
|
}
|
|
47523
47877
|
try {
|
|
47524
|
-
(0,
|
|
47878
|
+
(0, import_node_child_process22.execSync)("yarn --version", { stdio: "pipe" });
|
|
47525
47879
|
return "yarn";
|
|
47526
47880
|
} catch {
|
|
47527
47881
|
}
|
|
47528
47882
|
try {
|
|
47529
|
-
(0,
|
|
47883
|
+
(0, import_node_child_process22.execSync)("bun --version", { stdio: "pipe" });
|
|
47530
47884
|
return "bun";
|
|
47531
47885
|
} catch {
|
|
47532
47886
|
}
|
|
@@ -47534,14 +47888,14 @@ function detectPackageManager() {
|
|
|
47534
47888
|
}
|
|
47535
47889
|
function readInstallConfig() {
|
|
47536
47890
|
try {
|
|
47537
|
-
return JSON.parse((0,
|
|
47891
|
+
return JSON.parse((0, import_node_fs49.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
47538
47892
|
} catch {
|
|
47539
47893
|
return {};
|
|
47540
47894
|
}
|
|
47541
47895
|
}
|
|
47542
47896
|
function packageLooksInstalled(pm, pkgName) {
|
|
47543
47897
|
try {
|
|
47544
|
-
const output = (0,
|
|
47898
|
+
const output = (0, import_node_child_process22.execSync)(globalListCommand(pm, pkgName), {
|
|
47545
47899
|
encoding: "utf-8",
|
|
47546
47900
|
stdio: ["pipe", "pipe", "pipe"]
|
|
47547
47901
|
});
|
|
@@ -47644,14 +47998,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
47644
47998
|
function restartSystemdDaemon() {
|
|
47645
47999
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
47646
48000
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
47647
|
-
if (!asRoot && (0,
|
|
48001
|
+
if (!asRoot && (0, import_node_child_process22.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
47648
48002
|
const [cmd, ...args] = argv;
|
|
47649
|
-
if ((0,
|
|
47650
|
-
return (0,
|
|
48003
|
+
if ((0, import_node_child_process22.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
48004
|
+
return (0, import_node_child_process22.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
47651
48005
|
}
|
|
47652
48006
|
function execQuiet(cmd) {
|
|
47653
48007
|
try {
|
|
47654
|
-
return (0,
|
|
48008
|
+
return (0, import_node_child_process22.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
47655
48009
|
} catch {
|
|
47656
48010
|
return null;
|
|
47657
48011
|
}
|
|
@@ -47804,7 +48158,7 @@ program2.command("harden").description("Run hardening security scan").option("--
|
|
|
47804
48158
|
program2.command("patches").description("List OS packages with a security update waiting, and the CVEs it fixes (Debian/Ubuntu)").option("--json", "Output the report as JSON").option("--no-upload", "Do not upload the result to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
|
|
47805
48159
|
await patchesCommand(opts);
|
|
47806
48160
|
});
|
|
47807
|
-
program2.command("feeds [action] [value]").description("Show the abuse.ch C2/malware list the daemon matches; `feeds check <ip|domain>` looks one up (exit 1 when listed)").option("--json", "Output as JSON").action(async (action, value, opts) => {
|
|
48161
|
+
program2.command("feeds [action] [value]").description("Show the abuse.ch C2/malware list the daemon matches; `feeds check <ip|domain>` looks one up (exit 1 when listed); `feeds resolver install|remove|status` lets dnsmasq/unbound refuse the listed domains").option("--json", "Output as JSON").action(async (action, value, opts) => {
|
|
47808
48162
|
await feedsCommand(action, value, opts);
|
|
47809
48163
|
});
|
|
47810
48164
|
program2.command("privileged").description("Who can become root here (uid 0, sudo groups, sudoers, SSH keys) and the daemon's record of changes and sudo commands").option("--json", "Output as JSON").option("--limit <n>", "How many recent events to show", "25").action(async (opts) => {
|
|
@@ -47846,7 +48200,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
47846
48200
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
47847
48201
|
console.log(LOGO2);
|
|
47848
48202
|
const logPath = PATHS.logFile;
|
|
47849
|
-
if (!(0,
|
|
48203
|
+
if (!(0, import_node_fs49.existsSync)(logPath)) {
|
|
47850
48204
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
47851
48205
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
47852
48206
|
return;
|
|
@@ -47854,7 +48208,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
47854
48208
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
47855
48209
|
`));
|
|
47856
48210
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
47857
|
-
(0,
|
|
48211
|
+
(0, import_node_child_process22.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
47858
48212
|
});
|
|
47859
48213
|
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) => {
|
|
47860
48214
|
console.log(LOGO2);
|
|
@@ -47866,7 +48220,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
47866
48220
|
for (const cmd of commands2) {
|
|
47867
48221
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47868
48222
|
`));
|
|
47869
|
-
(0,
|
|
48223
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47870
48224
|
}
|
|
47871
48225
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
47872
48226
|
await reportIfStillStale();
|
|
@@ -47891,7 +48245,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
47891
48245
|
for (const cmd of commands) {
|
|
47892
48246
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47893
48247
|
`));
|
|
47894
|
-
(0,
|
|
48248
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47895
48249
|
}
|
|
47896
48250
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
47897
48251
|
if (installMode === "desktop") {
|
|
@@ -47942,7 +48296,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
47942
48296
|
for (const cmd of commands) {
|
|
47943
48297
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47944
48298
|
`));
|
|
47945
|
-
(0,
|
|
48299
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47946
48300
|
}
|
|
47947
48301
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
47948
48302
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -48019,10 +48373,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
48019
48373
|
});
|
|
48020
48374
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
48021
48375
|
console.log(LOGO2);
|
|
48022
|
-
const configPath = (0,
|
|
48376
|
+
const configPath = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
|
|
48023
48377
|
let email = "";
|
|
48024
48378
|
try {
|
|
48025
|
-
const config = JSON.parse((0,
|
|
48379
|
+
const config = JSON.parse((0, import_node_fs49.readFileSync)(configPath, "utf-8"));
|
|
48026
48380
|
email = config.email || "";
|
|
48027
48381
|
} catch {
|
|
48028
48382
|
}
|
|
@@ -48039,9 +48393,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
48039
48393
|
return;
|
|
48040
48394
|
}
|
|
48041
48395
|
try {
|
|
48042
|
-
const dir = (0,
|
|
48043
|
-
if (!(0,
|
|
48044
|
-
(0,
|
|
48396
|
+
const dir = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush");
|
|
48397
|
+
if (!(0, import_node_fs49.existsSync)(dir)) (0, import_node_fs49.mkdirSync)(dir, { recursive: true });
|
|
48398
|
+
(0, import_node_fs49.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
48045
48399
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
48046
48400
|
} catch {
|
|
48047
48401
|
}
|