@profullstack/threatcrush 0.13.35 → 0.13.37
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 +412 -119
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +637 -220
- 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";
|
|
@@ -42667,10 +42728,10 @@ function installPlan(opts) {
|
|
|
42667
42728
|
}
|
|
42668
42729
|
function ownerOf(path, passwd = "/etc/passwd") {
|
|
42669
42730
|
try {
|
|
42670
|
-
const st = (0,
|
|
42731
|
+
const st = (0, import_node_fs32.statSync)(path);
|
|
42671
42732
|
let home = st.uid === 0 ? "/root" : "";
|
|
42672
42733
|
try {
|
|
42673
|
-
for (const line2 of (0,
|
|
42734
|
+
for (const line2 of (0, import_node_fs32.readFileSync)(passwd, "utf8").split("\n")) {
|
|
42674
42735
|
const f = line2.split(":");
|
|
42675
42736
|
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
42676
42737
|
}
|
|
@@ -42775,7 +42836,7 @@ var AutoUpdate = class {
|
|
|
42775
42836
|
uid: process.getuid?.() ?? -1,
|
|
42776
42837
|
owner: ownerOf(this.opts.pkgRoot),
|
|
42777
42838
|
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
42778
|
-
npmExists:
|
|
42839
|
+
npmExists: import_node_fs32.existsSync
|
|
42779
42840
|
});
|
|
42780
42841
|
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
42781
42842
|
this.recordAttempt(target);
|
|
@@ -42810,7 +42871,7 @@ var AutoUpdate = class {
|
|
|
42810
42871
|
}
|
|
42811
42872
|
lastAttempt() {
|
|
42812
42873
|
try {
|
|
42813
|
-
const v = JSON.parse((0,
|
|
42874
|
+
const v = JSON.parse((0, import_node_fs32.readFileSync)(this.opts.statePath, "utf8"));
|
|
42814
42875
|
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
42815
42876
|
} catch {
|
|
42816
42877
|
return null;
|
|
@@ -42818,7 +42879,7 @@ var AutoUpdate = class {
|
|
|
42818
42879
|
}
|
|
42819
42880
|
recordAttempt(version) {
|
|
42820
42881
|
try {
|
|
42821
|
-
(0,
|
|
42882
|
+
(0, import_node_fs32.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
42822
42883
|
} catch (err) {
|
|
42823
42884
|
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
42824
42885
|
}
|
|
@@ -42827,6 +42888,8 @@ var AutoUpdate = class {
|
|
|
42827
42888
|
|
|
42828
42889
|
// src/daemon/workers/threat-feeds.ts
|
|
42829
42890
|
var import_node_child_process10 = require("child_process");
|
|
42891
|
+
var import_node_fs33 = require("fs");
|
|
42892
|
+
var import_node_path24 = require("path");
|
|
42830
42893
|
var import_node_net9 = require("net");
|
|
42831
42894
|
init_backoff();
|
|
42832
42895
|
var EGRESS_TABLE = "threatcrush_egress";
|
|
@@ -42838,6 +42901,7 @@ function threatFeedSettings(section) {
|
|
|
42838
42901
|
return {
|
|
42839
42902
|
enabled: section?.enabled !== false,
|
|
42840
42903
|
block: section?.block === true,
|
|
42904
|
+
blockDomains: section?.block_domains === true,
|
|
42841
42905
|
// abuse.ch asks for no more than one fetch per 5 minutes; hourly is plenty.
|
|
42842
42906
|
refreshMs: refresh ? Math.max(900, refresh) * 1e3 : DEFAULT_REFRESH_MS,
|
|
42843
42907
|
minConfidence: typeof section?.min_confidence === "number" ? section.min_confidence : 75,
|
|
@@ -42917,6 +42981,8 @@ var ThreatFeeds = class {
|
|
|
42917
42981
|
set = null;
|
|
42918
42982
|
alerted = /* @__PURE__ */ new Map();
|
|
42919
42983
|
blocking = false;
|
|
42984
|
+
/** Resolver blocklist content last written, by file name (see writeResolverFiles). */
|
|
42985
|
+
resolverWritten = /* @__PURE__ */ new Map();
|
|
42920
42986
|
run;
|
|
42921
42987
|
now;
|
|
42922
42988
|
get wantsBlock() {
|
|
@@ -42978,10 +43044,55 @@ var ThreatFeeds = class {
|
|
|
42978
43044
|
this.blocking = ok;
|
|
42979
43045
|
mode = ok ? "blocking egress" : "detecting (nft load failed)";
|
|
42980
43046
|
}
|
|
42981
|
-
const detail = `${ips.length} IPs, ${domains} domains, ${mode}`;
|
|
43047
|
+
const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}`;
|
|
42982
43048
|
this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);
|
|
42983
43049
|
this.opts.bus.announceModule("threat-feeds", "running", detail);
|
|
42984
43050
|
}
|
|
43051
|
+
/** Whether listed domains are refused at the resolver: opted in and enforcing. */
|
|
43052
|
+
get wantsDomainBlock() {
|
|
43053
|
+
return this.opts.settings.blockDomains && this.opts.enforcing;
|
|
43054
|
+
}
|
|
43055
|
+
/**
|
|
43056
|
+
* Rewrite the resolver blocklists in the state dir and reload any resolver
|
|
43057
|
+
* whose hook is installed — only when the content changed, so an hourly
|
|
43058
|
+
* refresh with nothing new costs no reload. With domain blocking off the
|
|
43059
|
+
* files are emptied, so an installed hook blocks nothing and the config
|
|
43060
|
+
* stays the one switch. Returns a status suffix for the log line.
|
|
43061
|
+
*/
|
|
43062
|
+
writeResolverFiles(set) {
|
|
43063
|
+
const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
|
|
43064
|
+
const dir = this.opts.resolverDir ?? (0, import_node_path24.dirname)(this.opts.cachePath);
|
|
43065
|
+
const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
|
|
43066
|
+
const write = (name, content) => {
|
|
43067
|
+
const path = (0, import_node_path24.join)(dir, name);
|
|
43068
|
+
if (this.resolverWritten.get(name) === content) return false;
|
|
43069
|
+
try {
|
|
43070
|
+
(0, import_node_fs33.writeFileSync)(`${path}.tmp`, content);
|
|
43071
|
+
(0, import_node_fs33.renameSync)(`${path}.tmp`, path);
|
|
43072
|
+
this.resolverWritten.set(name, content);
|
|
43073
|
+
return true;
|
|
43074
|
+
} catch (err) {
|
|
43075
|
+
this.opts.log(`[threat-feeds] could not write ${path}: ${err.message}`);
|
|
43076
|
+
return false;
|
|
43077
|
+
}
|
|
43078
|
+
};
|
|
43079
|
+
const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
|
|
43080
|
+
const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
|
|
43081
|
+
const via = [];
|
|
43082
|
+
if ((0, import_node_fs33.existsSync)(hooks.dnsmasq)) {
|
|
43083
|
+
via.push("dnsmasq");
|
|
43084
|
+
if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
|
|
43085
|
+
}
|
|
43086
|
+
if ((0, import_node_fs33.existsSync)(hooks.unbound)) {
|
|
43087
|
+
via.push("unbound");
|
|
43088
|
+
if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
|
|
43089
|
+
this.run("systemctl", ["reload", "unbound.service"]);
|
|
43090
|
+
}
|
|
43091
|
+
}
|
|
43092
|
+
if (!this.opts.settings.blockDomains) return "";
|
|
43093
|
+
if (!this.opts.enforcing) return "; domain blocking set but remediation is dry_run";
|
|
43094
|
+
return via.length ? `; ${domains.length} domains refused via ${via.join(" + ")}` : "; domain blocking set but no resolver hook (run `threatcrush feeds resolver install`)";
|
|
43095
|
+
}
|
|
42985
43096
|
removeBlocking() {
|
|
42986
43097
|
if (this.run("nft", ["list", "table", "inet", EGRESS_TABLE]) !== null) {
|
|
42987
43098
|
this.run("nft", ["delete", "table", "inet", EGRESS_TABLE]);
|
|
@@ -43033,8 +43144,8 @@ var ThreatFeeds = class {
|
|
|
43033
43144
|
};
|
|
43034
43145
|
|
|
43035
43146
|
// src/daemon/workers/privilege-watch.ts
|
|
43036
|
-
var
|
|
43037
|
-
var
|
|
43147
|
+
var import_node_fs34 = require("fs");
|
|
43148
|
+
var import_node_path25 = require("path");
|
|
43038
43149
|
var import_node_child_process11 = require("child_process");
|
|
43039
43150
|
|
|
43040
43151
|
// src/core/privileges/index.ts
|
|
@@ -43225,31 +43336,31 @@ function countryName(code) {
|
|
|
43225
43336
|
var fsIO = {
|
|
43226
43337
|
readFile: (p) => {
|
|
43227
43338
|
try {
|
|
43228
|
-
return (0,
|
|
43339
|
+
return (0, import_node_fs34.readFileSync)(p, "utf-8");
|
|
43229
43340
|
} catch {
|
|
43230
43341
|
return null;
|
|
43231
43342
|
}
|
|
43232
43343
|
},
|
|
43233
43344
|
readDir: (p) => {
|
|
43234
43345
|
try {
|
|
43235
|
-
return (0,
|
|
43346
|
+
return (0, import_node_fs34.readdirSync)(p);
|
|
43236
43347
|
} catch {
|
|
43237
43348
|
return null;
|
|
43238
43349
|
}
|
|
43239
43350
|
},
|
|
43240
|
-
exists: (p) => (0,
|
|
43351
|
+
exists: (p) => (0, import_node_fs34.existsSync)(p)
|
|
43241
43352
|
};
|
|
43242
43353
|
function readJson(path) {
|
|
43243
43354
|
try {
|
|
43244
|
-
return JSON.parse((0,
|
|
43355
|
+
return JSON.parse((0, import_node_fs34.readFileSync)(path, "utf-8"));
|
|
43245
43356
|
} catch {
|
|
43246
43357
|
return null;
|
|
43247
43358
|
}
|
|
43248
43359
|
}
|
|
43249
43360
|
function writeJson(path, value) {
|
|
43250
|
-
(0,
|
|
43251
|
-
(0,
|
|
43252
|
-
(0,
|
|
43361
|
+
(0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path), { recursive: true });
|
|
43362
|
+
(0, import_node_fs34.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
|
|
43363
|
+
(0, import_node_fs34.renameSync)(`${path}.tmp`, path);
|
|
43253
43364
|
}
|
|
43254
43365
|
function defaultRun3(cmd, args) {
|
|
43255
43366
|
const res = (0, import_node_child_process11.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -43267,6 +43378,36 @@ async function geolocateViaThreatcrush(ip, fetchImpl = fetch) {
|
|
|
43267
43378
|
const code = body.results?.[ip]?.countryCode;
|
|
43268
43379
|
return typeof code === "string" && /^[A-Z]{2}$/.test(code) ? { countryCode: code } : null;
|
|
43269
43380
|
}
|
|
43381
|
+
async function geolocateManyViaThreatcrush(ips, fetchImpl = fetch) {
|
|
43382
|
+
const out = /* @__PURE__ */ new Map();
|
|
43383
|
+
for (let i = 0; i < ips.length; i += 200) {
|
|
43384
|
+
const chunk2 = ips.slice(i, i + 200);
|
|
43385
|
+
const res = await fetchImpl("https://threatcrush.com/api/geo", {
|
|
43386
|
+
method: "POST",
|
|
43387
|
+
headers: { "Content-Type": "application/json" },
|
|
43388
|
+
body: JSON.stringify({ ips: chunk2 }),
|
|
43389
|
+
signal: AbortSignal.timeout(15e3)
|
|
43390
|
+
});
|
|
43391
|
+
if (!res.ok) throw new Error(`geo lookup failed: HTTP ${res.status}`);
|
|
43392
|
+
const body = await res.json();
|
|
43393
|
+
for (const ip of chunk2) {
|
|
43394
|
+
const code = body.results?.[ip]?.countryCode;
|
|
43395
|
+
if (typeof code === "string" && /^[A-Z]{2}$/.test(code)) out.set(ip, code);
|
|
43396
|
+
}
|
|
43397
|
+
}
|
|
43398
|
+
return out;
|
|
43399
|
+
}
|
|
43400
|
+
function parseAcceptedLogins(text) {
|
|
43401
|
+
const out = /* @__PURE__ */ new Map();
|
|
43402
|
+
for (const m of text.matchAll(/Accepted \S+ for (\S+) from (\S+) port/g)) {
|
|
43403
|
+
const [, user, ip] = m;
|
|
43404
|
+
if (isProtected(ip, DEFAULT_PROTECTED)) continue;
|
|
43405
|
+
const ips = out.get(user) ?? /* @__PURE__ */ new Set();
|
|
43406
|
+
ips.add(ip);
|
|
43407
|
+
out.set(user, ips);
|
|
43408
|
+
}
|
|
43409
|
+
return out;
|
|
43410
|
+
}
|
|
43270
43411
|
var PrivilegeWatch = class {
|
|
43271
43412
|
constructor(opts) {
|
|
43272
43413
|
this.opts = opts;
|
|
@@ -43290,7 +43431,10 @@ var PrivilegeWatch = class {
|
|
|
43290
43431
|
}
|
|
43291
43432
|
this.checkSnapshot();
|
|
43292
43433
|
this.readSudoLedger();
|
|
43293
|
-
if (this.opts.settings.geo)
|
|
43434
|
+
if (this.opts.settings.geo) {
|
|
43435
|
+
this.opts.bus.on("event", this.onEvent);
|
|
43436
|
+
void this.backfillLogins();
|
|
43437
|
+
}
|
|
43294
43438
|
const timer = setInterval(() => {
|
|
43295
43439
|
this.checkSnapshot();
|
|
43296
43440
|
this.readSudoLedger();
|
|
@@ -43365,6 +43509,42 @@ var PrivilegeWatch = class {
|
|
|
43365
43509
|
}
|
|
43366
43510
|
}
|
|
43367
43511
|
}
|
|
43512
|
+
/**
|
|
43513
|
+
* Seed the login history from the last 30 days of sshd logins, once, when
|
|
43514
|
+
* there is none. Learning only from logins after install meant regular
|
|
43515
|
+
* automation from another country (a backup box pulling every four hours)
|
|
43516
|
+
* raised a "new country" alert on its first run; on dev2 it did, at once.
|
|
43517
|
+
*/
|
|
43518
|
+
async backfillLogins() {
|
|
43519
|
+
if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
|
|
43520
|
+
const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
|
|
43521
|
+
const byUser = parseAcceptedLogins(out ?? "");
|
|
43522
|
+
const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
|
|
43523
|
+
let codes = /* @__PURE__ */ new Map();
|
|
43524
|
+
if (ips.length > 0) {
|
|
43525
|
+
try {
|
|
43526
|
+
codes = await (this.opts.geolocateMany ?? geolocateManyViaThreatcrush)(ips);
|
|
43527
|
+
} catch (err) {
|
|
43528
|
+
this.opts.log(`[privileged] login backfill geolocation failed: ${err.message}`);
|
|
43529
|
+
return;
|
|
43530
|
+
}
|
|
43531
|
+
}
|
|
43532
|
+
if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
|
|
43533
|
+
const at = this.now().toISOString();
|
|
43534
|
+
const history = {};
|
|
43535
|
+
for (const [user, userIps] of byUser) {
|
|
43536
|
+
for (const ip of userIps) {
|
|
43537
|
+
const code = codes.get(ip);
|
|
43538
|
+
if (code) (history[user] ??= {})[code] = { first: at, last: at };
|
|
43539
|
+
}
|
|
43540
|
+
}
|
|
43541
|
+
try {
|
|
43542
|
+
writeJson(this.opts.loginsPath, history);
|
|
43543
|
+
} catch {
|
|
43544
|
+
}
|
|
43545
|
+
const summary = Object.entries(history).map(([u, c]) => `${u}: ${Object.keys(c).join("/")}`).join(", ");
|
|
43546
|
+
this.opts.log(`[privileged] login baseline from the last 30 days: ${summary || "no public SSH logins"}`);
|
|
43547
|
+
}
|
|
43368
43548
|
/** An accepted SSH login from a country new for that user. */
|
|
43369
43549
|
async checkLogin(event) {
|
|
43370
43550
|
if (event.module !== "ssh-guard" || !event.source_ip) return;
|
|
@@ -43561,8 +43741,8 @@ var RuleEngine = class {
|
|
|
43561
43741
|
};
|
|
43562
43742
|
|
|
43563
43743
|
// src/daemon/rules/loader.ts
|
|
43564
|
-
var
|
|
43565
|
-
var
|
|
43744
|
+
var import_node_fs35 = require("fs");
|
|
43745
|
+
var import_node_path26 = require("path");
|
|
43566
43746
|
|
|
43567
43747
|
// src/daemon/rules/default-rules.ts
|
|
43568
43748
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -43963,11 +44143,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
43963
44143
|
function loadAllRules(customDir) {
|
|
43964
44144
|
const rules = [...DEFAULT_RULES];
|
|
43965
44145
|
const dir = customDir || RULES_DIR;
|
|
43966
|
-
if ((0,
|
|
43967
|
-
const files = (0,
|
|
44146
|
+
if ((0, import_node_fs35.existsSync)(dir)) {
|
|
44147
|
+
const files = (0, import_node_fs35.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
43968
44148
|
for (const file of files) {
|
|
43969
44149
|
try {
|
|
43970
|
-
const raw = (0,
|
|
44150
|
+
const raw = (0, import_node_fs35.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
|
|
43971
44151
|
const parsed = JSON.parse(raw);
|
|
43972
44152
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
43973
44153
|
for (const rule of customRules) {
|
|
@@ -43999,8 +44179,8 @@ function loadAllRules(customDir) {
|
|
|
43999
44179
|
|
|
44000
44180
|
// src/daemon/firewall/adapters.ts
|
|
44001
44181
|
var import_node_child_process12 = require("child_process");
|
|
44002
|
-
var
|
|
44003
|
-
var
|
|
44182
|
+
var import_node_fs36 = require("fs");
|
|
44183
|
+
var import_node_path27 = require("path");
|
|
44004
44184
|
var import_node_net10 = require("net");
|
|
44005
44185
|
function assertValidFirewallIp(ip) {
|
|
44006
44186
|
if ((0, import_node_net10.isIP)(ip) !== 4) {
|
|
@@ -44013,9 +44193,9 @@ function assertBannableIp(ip) {
|
|
|
44013
44193
|
}
|
|
44014
44194
|
}
|
|
44015
44195
|
function writeIfAbsent(path, contents) {
|
|
44016
|
-
(0,
|
|
44196
|
+
(0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
|
|
44017
44197
|
try {
|
|
44018
|
-
(0,
|
|
44198
|
+
(0, import_node_fs36.writeFileSync)(path, contents, { flag: "wx" });
|
|
44019
44199
|
} catch (err) {
|
|
44020
44200
|
if (err.code !== "EEXIST") throw err;
|
|
44021
44201
|
}
|
|
@@ -44274,7 +44454,8 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
44274
44454
|
}
|
|
44275
44455
|
|
|
44276
44456
|
// src/daemon/firewall/remediation.ts
|
|
44277
|
-
var
|
|
44457
|
+
var import_node_fs37 = require("fs");
|
|
44458
|
+
var import_node_child_process13 = require("child_process");
|
|
44278
44459
|
var import_node_net11 = require("net");
|
|
44279
44460
|
init_paths();
|
|
44280
44461
|
init_backoff();
|
|
@@ -44333,8 +44514,46 @@ var DEFAULT_CONFIG2 = {
|
|
|
44333
44514
|
strike_memory_seconds: 30 * 86400,
|
|
44334
44515
|
allowlist: [],
|
|
44335
44516
|
protect_current_ssh_client: true,
|
|
44517
|
+
protect_recent_operators: true,
|
|
44518
|
+
operator_memory_seconds: 30 * 86400,
|
|
44336
44519
|
spare_verified_crawlers: true
|
|
44337
44520
|
};
|
|
44521
|
+
var defaultDiscovery = {
|
|
44522
|
+
sshPeers: () => [currentSshClient(), ...establishedSshPeers()].filter((ip) => Boolean(ip)),
|
|
44523
|
+
moshClients: () => moshClients(),
|
|
44524
|
+
automationKeys: () => {
|
|
44525
|
+
const snapshot = takeSnapshot({
|
|
44526
|
+
readFile: (p) => {
|
|
44527
|
+
try {
|
|
44528
|
+
return (0, import_node_fs37.readFileSync)(p, "utf-8");
|
|
44529
|
+
} catch {
|
|
44530
|
+
return null;
|
|
44531
|
+
}
|
|
44532
|
+
},
|
|
44533
|
+
readDir: (p) => {
|
|
44534
|
+
try {
|
|
44535
|
+
return (0, import_node_fs37.readdirSync)(p);
|
|
44536
|
+
} catch {
|
|
44537
|
+
return null;
|
|
44538
|
+
}
|
|
44539
|
+
},
|
|
44540
|
+
exists: (p) => (0, import_node_fs37.existsSync)(p)
|
|
44541
|
+
});
|
|
44542
|
+
const out = /* @__PURE__ */ new Set();
|
|
44543
|
+
for (const keys of Object.values(snapshot.keys)) {
|
|
44544
|
+
for (const [fp, k] of Object.entries(keys)) if (isAutomationKeyComment(k.comment)) out.add(fp);
|
|
44545
|
+
}
|
|
44546
|
+
return out;
|
|
44547
|
+
},
|
|
44548
|
+
keyLoginJournal: (sinceSeconds) => new Promise((resolve6) => {
|
|
44549
|
+
(0, import_node_child_process13.execFile)(
|
|
44550
|
+
"journalctl",
|
|
44551
|
+
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
44552
|
+
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
44553
|
+
(_err, stdout) => resolve6(stdout ?? "")
|
|
44554
|
+
);
|
|
44555
|
+
})
|
|
44556
|
+
};
|
|
44338
44557
|
var SEVERITY_RANK7 = {
|
|
44339
44558
|
info: 0,
|
|
44340
44559
|
low: 1,
|
|
@@ -44357,28 +44576,70 @@ function explainBlockFailure(err, backend) {
|
|
|
44357
44576
|
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`;
|
|
44358
44577
|
}
|
|
44359
44578
|
var RemediationManager = class {
|
|
44360
|
-
constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier()) {
|
|
44579
|
+
constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier(), discovery = defaultDiscovery) {
|
|
44361
44580
|
this.adapter = adapter;
|
|
44362
44581
|
this.bus = bus2;
|
|
44363
44582
|
this.verifyCrawler = verifyCrawler;
|
|
44583
|
+
this.discovery = discovery;
|
|
44364
44584
|
this.config = { ...DEFAULT_CONFIG2, ...config };
|
|
44365
44585
|
this.config.allowlist = [...this.config.allowlist];
|
|
44366
44586
|
this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
|
|
44367
44587
|
for (const gateway of defaultGateways()) this.protectedList.push(gateway);
|
|
44368
|
-
this.refreshSshProtection();
|
|
44369
44588
|
if (this.adapter.enforces === false) this.config.dry_run = true;
|
|
44370
44589
|
this.loadState();
|
|
44590
|
+
this.refreshSshProtection();
|
|
44371
44591
|
void this.reconcile();
|
|
44372
44592
|
this.startExpiryWorker();
|
|
44593
|
+
if (this.config.protect_recent_operators) void this.seedOperatorsFromJournal();
|
|
44373
44594
|
}
|
|
44374
44595
|
adapter;
|
|
44375
44596
|
bus;
|
|
44376
44597
|
verifyCrawler;
|
|
44598
|
+
discovery;
|
|
44377
44599
|
config;
|
|
44378
44600
|
blocklist = [];
|
|
44379
44601
|
strikes = {};
|
|
44380
44602
|
protectedList = [];
|
|
44603
|
+
/** Operator address → last time seen (ms), persisted. */
|
|
44604
|
+
operators = {};
|
|
44381
44605
|
expiryTimer = null;
|
|
44606
|
+
operatorTimer = null;
|
|
44607
|
+
/** Remembered operator addresses and when each was last seen. */
|
|
44608
|
+
getOperators() {
|
|
44609
|
+
return { ...this.operators };
|
|
44610
|
+
}
|
|
44611
|
+
/**
|
|
44612
|
+
* An address an operator really came from: never ban it, remember it, and
|
|
44613
|
+
* lift a ban that is already on it — the operator is the one who needs in.
|
|
44614
|
+
*/
|
|
44615
|
+
noteOperator(ip, at, remember = true) {
|
|
44616
|
+
if (Date.now() - at > this.config.operator_memory_seconds * 1e3) return;
|
|
44617
|
+
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
44618
|
+
if (!remember || !this.config.protect_recent_operators || isProtected(ip, DEFAULT_PROTECTED)) return;
|
|
44619
|
+
const known = this.operators[ip] ?? 0;
|
|
44620
|
+
if (at > known) {
|
|
44621
|
+
this.operators[ip] = at;
|
|
44622
|
+
if (!known) this.logLine(`[firewall] operator address remembered: ${ip}`);
|
|
44623
|
+
this.saveState();
|
|
44624
|
+
}
|
|
44625
|
+
if (this.blocklist.some((b) => b.ip === ip)) {
|
|
44626
|
+
void this.unban(ip, { forget: true, reason: "operator address (key login or live session)" });
|
|
44627
|
+
}
|
|
44628
|
+
}
|
|
44629
|
+
/**
|
|
44630
|
+
* Key-based SSH logins in the memory window, by keys that belong to people:
|
|
44631
|
+
* a key whose comment marks automation (a CI deploy key) logs in from
|
|
44632
|
+
* shared cloud runners, and remembering those would allowlist hundreds of
|
|
44633
|
+
* strangers' addresses — dev2 saw 308 distinct key-login IPs in 30 days.
|
|
44634
|
+
*/
|
|
44635
|
+
async seedOperatorsFromJournal() {
|
|
44636
|
+
try {
|
|
44637
|
+
const automation = this.discovery.automationKeys();
|
|
44638
|
+
const journal = await this.discovery.keyLoginJournal(this.config.operator_memory_seconds);
|
|
44639
|
+
for (const [ip, at] of parseKeyLogins(journal, (fp) => automation.has(fp))) this.noteOperator(ip, at);
|
|
44640
|
+
} catch {
|
|
44641
|
+
}
|
|
44642
|
+
}
|
|
44382
44643
|
/** Every address that can never be blocked, built-ins included. */
|
|
44383
44644
|
getProtected() {
|
|
44384
44645
|
return [...this.protectedList];
|
|
@@ -44393,10 +44654,9 @@ var RemediationManager = class {
|
|
|
44393
44654
|
*/
|
|
44394
44655
|
refreshSshProtection() {
|
|
44395
44656
|
if (!this.config.protect_current_ssh_client) return;
|
|
44396
|
-
const
|
|
44397
|
-
for (const ip of
|
|
44398
|
-
|
|
44399
|
-
}
|
|
44657
|
+
const now = Date.now();
|
|
44658
|
+
for (const ip of this.discovery.sshPeers()) this.noteOperator(ip, now, false);
|
|
44659
|
+
for (const ip of this.discovery.moshClients()) this.noteOperator(ip, now);
|
|
44400
44660
|
}
|
|
44401
44661
|
isAllowlisted(ip) {
|
|
44402
44662
|
return isProtected(ip, this.protectedList);
|
|
@@ -44595,7 +44855,9 @@ var RemediationManager = class {
|
|
|
44595
44855
|
}
|
|
44596
44856
|
stop() {
|
|
44597
44857
|
if (this.expiryTimer) clearInterval(this.expiryTimer);
|
|
44858
|
+
if (this.operatorTimer) clearInterval(this.operatorTimer);
|
|
44598
44859
|
this.expiryTimer = null;
|
|
44860
|
+
this.operatorTimer = null;
|
|
44599
44861
|
}
|
|
44600
44862
|
/**
|
|
44601
44863
|
* R5: bans survive a restart, their TTLs do not. Anything that expired while
|
|
@@ -44644,6 +44906,10 @@ var RemediationManager = class {
|
|
|
44644
44906
|
startExpiryWorker() {
|
|
44645
44907
|
this.expiryTimer = setInterval(() => void this.processExpiries(), 1e4);
|
|
44646
44908
|
this.expiryTimer.unref?.();
|
|
44909
|
+
if (this.config.protect_recent_operators) {
|
|
44910
|
+
this.operatorTimer = setInterval(() => void this.seedOperatorsFromJournal(), 36e5);
|
|
44911
|
+
this.operatorTimer.unref?.();
|
|
44912
|
+
}
|
|
44647
44913
|
}
|
|
44648
44914
|
async processExpiries() {
|
|
44649
44915
|
const now = Date.now();
|
|
@@ -44656,6 +44922,12 @@ var RemediationManager = class {
|
|
|
44656
44922
|
this.strikes = pruned;
|
|
44657
44923
|
this.saveState();
|
|
44658
44924
|
}
|
|
44925
|
+
const cutoff = now - this.config.operator_memory_seconds * 1e3;
|
|
44926
|
+
const stale = Object.keys(this.operators).filter((ip) => this.operators[ip] < cutoff);
|
|
44927
|
+
if (stale.length > 0) {
|
|
44928
|
+
for (const ip of stale) delete this.operators[ip];
|
|
44929
|
+
this.saveState();
|
|
44930
|
+
}
|
|
44659
44931
|
}
|
|
44660
44932
|
loadState() {
|
|
44661
44933
|
try {
|
|
@@ -44675,6 +44947,18 @@ var RemediationManager = class {
|
|
|
44675
44947
|
if (saved && typeof saved === "object") this.strikes = saved;
|
|
44676
44948
|
} catch {
|
|
44677
44949
|
}
|
|
44950
|
+
try {
|
|
44951
|
+
const saved = getModuleState("firewall-rules", "operators");
|
|
44952
|
+
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
44953
|
+
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
44954
|
+
for (const [ip, at] of Object.entries(saved)) {
|
|
44955
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net11.isIP)(ip)) continue;
|
|
44956
|
+
this.operators[ip] = at;
|
|
44957
|
+
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
44958
|
+
}
|
|
44959
|
+
}
|
|
44960
|
+
} catch {
|
|
44961
|
+
}
|
|
44678
44962
|
}
|
|
44679
44963
|
saveState() {
|
|
44680
44964
|
try {
|
|
@@ -44685,10 +44969,14 @@ var RemediationManager = class {
|
|
|
44685
44969
|
setModuleState("firewall-rules", "strikes", this.strikes);
|
|
44686
44970
|
} catch {
|
|
44687
44971
|
}
|
|
44972
|
+
try {
|
|
44973
|
+
setModuleState("firewall-rules", "operators", this.operators);
|
|
44974
|
+
} catch {
|
|
44975
|
+
}
|
|
44688
44976
|
}
|
|
44689
44977
|
logLine(line2) {
|
|
44690
44978
|
try {
|
|
44691
|
-
(0,
|
|
44979
|
+
(0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
44692
44980
|
`);
|
|
44693
44981
|
} catch {
|
|
44694
44982
|
}
|
|
@@ -44716,6 +45004,11 @@ function remediationSettings(section) {
|
|
|
44716
45004
|
if (typeof section.protect_current_ssh_client === "boolean") {
|
|
44717
45005
|
settings.protect_current_ssh_client = section.protect_current_ssh_client;
|
|
44718
45006
|
}
|
|
45007
|
+
if (typeof section.protect_recent_operators === "boolean") {
|
|
45008
|
+
settings.protect_recent_operators = section.protect_recent_operators;
|
|
45009
|
+
}
|
|
45010
|
+
const operatorMemory = parseDuration(section.operator_memory);
|
|
45011
|
+
if (operatorMemory) settings.operator_memory_seconds = operatorMemory;
|
|
44719
45012
|
if (typeof section.spare_verified_crawlers === "boolean") {
|
|
44720
45013
|
settings.spare_verified_crawlers = section.spare_verified_crawlers;
|
|
44721
45014
|
}
|
|
@@ -44726,19 +45019,19 @@ function remediationSettings(section) {
|
|
|
44726
45019
|
init_backoff();
|
|
44727
45020
|
|
|
44728
45021
|
// src/daemon/watchdog-service.ts
|
|
44729
|
-
var
|
|
44730
|
-
var
|
|
45022
|
+
var import_node_fs38 = require("fs");
|
|
45023
|
+
var import_node_path28 = require("path");
|
|
44731
45024
|
function defaultShareGid() {
|
|
44732
45025
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
44733
45026
|
if (!isRoot4) return void 0;
|
|
44734
45027
|
try {
|
|
44735
|
-
return (0,
|
|
45028
|
+
return (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
|
|
44736
45029
|
} catch {
|
|
44737
45030
|
return void 0;
|
|
44738
45031
|
}
|
|
44739
45032
|
}
|
|
44740
45033
|
function startWatchdog(opts) {
|
|
44741
|
-
const dir = opts.config?.dir ?? (0,
|
|
45034
|
+
const dir = opts.config?.dir ?? (0, import_node_path28.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
44742
45035
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
44743
45036
|
if (opts.config?.enabled === false) {
|
|
44744
45037
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -44832,7 +45125,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
44832
45125
|
}
|
|
44833
45126
|
|
|
44834
45127
|
// src/core/node-runtime.ts
|
|
44835
|
-
var
|
|
45128
|
+
var import_node_child_process14 = require("child_process");
|
|
44836
45129
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
44837
45130
|
function nodeMajor(version) {
|
|
44838
45131
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -44846,23 +45139,23 @@ function daemonNodeProblem(version) {
|
|
|
44846
45139
|
}
|
|
44847
45140
|
function versionOfNode(path) {
|
|
44848
45141
|
if (path === process.execPath) return process.versions.node;
|
|
44849
|
-
const res = (0,
|
|
45142
|
+
const res = (0, import_node_child_process14.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
44850
45143
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
44851
45144
|
}
|
|
44852
45145
|
|
|
44853
45146
|
// src/daemon/index.ts
|
|
44854
45147
|
function readVersion2() {
|
|
44855
45148
|
try {
|
|
44856
|
-
const pkg = JSON.parse((0,
|
|
45149
|
+
const pkg = JSON.parse((0, import_node_fs39.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
44857
45150
|
return pkg.version || "0.0.0";
|
|
44858
45151
|
} catch {
|
|
44859
45152
|
return "0.0.0";
|
|
44860
45153
|
}
|
|
44861
45154
|
}
|
|
44862
45155
|
async function runHardeningChecks() {
|
|
44863
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
45156
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
|
|
44864
45157
|
process.execPath,
|
|
44865
|
-
[(0,
|
|
45158
|
+
[(0, import_node_path29.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
44866
45159
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
44867
45160
|
);
|
|
44868
45161
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -44874,9 +45167,9 @@ async function runHardeningChecks() {
|
|
|
44874
45167
|
return patches ? [...findings, patches] : findings;
|
|
44875
45168
|
}
|
|
44876
45169
|
async function runPatchCheck() {
|
|
44877
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
45170
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
|
|
44878
45171
|
process.execPath,
|
|
44879
|
-
[(0,
|
|
45172
|
+
[(0, import_node_path29.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
44880
45173
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
44881
45174
|
);
|
|
44882
45175
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -44884,7 +45177,7 @@ async function runPatchCheck() {
|
|
|
44884
45177
|
}
|
|
44885
45178
|
function logLine(line2) {
|
|
44886
45179
|
try {
|
|
44887
|
-
(0,
|
|
45180
|
+
(0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
44888
45181
|
`);
|
|
44889
45182
|
} catch {
|
|
44890
45183
|
}
|
|
@@ -44909,9 +45202,9 @@ async function runDaemon() {
|
|
|
44909
45202
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
44910
45203
|
const restartDaemon = () => {
|
|
44911
45204
|
if (PATHS.mode === "system") {
|
|
44912
|
-
(0,
|
|
45205
|
+
(0, import_node_child_process15.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
44913
45206
|
} else {
|
|
44914
|
-
(0,
|
|
45207
|
+
(0, import_node_child_process15.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
44915
45208
|
setTimeout(() => process.exit(0), 500).unref();
|
|
44916
45209
|
}
|
|
44917
45210
|
};
|
|
@@ -44926,7 +45219,7 @@ async function runDaemon() {
|
|
|
44926
45219
|
} catch (err) {
|
|
44927
45220
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
44928
45221
|
}
|
|
44929
|
-
const config = loadConfig((0,
|
|
45222
|
+
const config = loadConfig((0, import_node_fs39.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
44930
45223
|
configureAttackDetection(config.detection);
|
|
44931
45224
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
44932
45225
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -44990,7 +45283,7 @@ async function runDaemon() {
|
|
|
44990
45283
|
const threatFeeds = new ThreatFeeds({
|
|
44991
45284
|
settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
|
|
44992
45285
|
enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
|
|
44993
|
-
cachePath: (0,
|
|
45286
|
+
cachePath: (0, import_node_path29.join)(PATHS.stateDir, "threat-feeds.json"),
|
|
44994
45287
|
bus,
|
|
44995
45288
|
log: logLine
|
|
44996
45289
|
});
|
|
@@ -44998,9 +45291,9 @@ async function runDaemon() {
|
|
|
44998
45291
|
const privilegeWatch = new PrivilegeWatch({
|
|
44999
45292
|
settings: privilegeSettings(config.privileged),
|
|
45000
45293
|
bus,
|
|
45001
|
-
snapshotPath: (0,
|
|
45002
|
-
loginsPath: (0,
|
|
45003
|
-
cursorPath: (0,
|
|
45294
|
+
snapshotPath: (0, import_node_path29.join)(PATHS.stateDir, "privileges.json"),
|
|
45295
|
+
loginsPath: (0, import_node_path29.join)(PATHS.stateDir, "login-countries.json"),
|
|
45296
|
+
cursorPath: (0, import_node_path29.join)(PATHS.stateDir, "sudo-cursor.json"),
|
|
45004
45297
|
log: logLine
|
|
45005
45298
|
});
|
|
45006
45299
|
privilegeWatch.start();
|
|
@@ -45023,7 +45316,7 @@ async function runDaemon() {
|
|
|
45023
45316
|
version,
|
|
45024
45317
|
hostname: (0, import_node_os11.hostname)(),
|
|
45025
45318
|
minSeverity,
|
|
45026
|
-
spoolPath: (0,
|
|
45319
|
+
spoolPath: (0, import_node_path29.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
45027
45320
|
log: logLine,
|
|
45028
45321
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
45029
45322
|
runHardening: runHardeningChecks
|
|
@@ -45040,8 +45333,8 @@ async function runDaemon() {
|
|
|
45040
45333
|
const autoUpdate = new AutoUpdate({
|
|
45041
45334
|
version,
|
|
45042
45335
|
settings: updateSettings(config.update),
|
|
45043
|
-
pkgRoot: (0,
|
|
45044
|
-
statePath: (0,
|
|
45336
|
+
pkgRoot: (0, import_node_path29.join)(__dirname, ".."),
|
|
45337
|
+
statePath: (0, import_node_path29.join)(PATHS.stateDir, "auto-update.json"),
|
|
45045
45338
|
bus,
|
|
45046
45339
|
log: logLine,
|
|
45047
45340
|
restartDaemon
|
|
@@ -45127,7 +45420,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
45127
45420
|
function isRoot2() {
|
|
45128
45421
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
45129
45422
|
}
|
|
45130
|
-
var DAEMON_ENTRY = (0,
|
|
45423
|
+
var DAEMON_ENTRY = (0, import_node_path30.join)(__dirname, "daemon.js");
|
|
45131
45424
|
async function daemonForeground() {
|
|
45132
45425
|
await runDaemon();
|
|
45133
45426
|
}
|
|
@@ -45148,7 +45441,7 @@ async function daemonStart() {
|
|
|
45148
45441
|
return;
|
|
45149
45442
|
}
|
|
45150
45443
|
ensureRuntimeDirs();
|
|
45151
|
-
if (!(0,
|
|
45444
|
+
if (!(0, import_node_fs40.existsSync)(DAEMON_ENTRY)) {
|
|
45152
45445
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
45153
45446
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
45154
45447
|
return;
|
|
@@ -45156,8 +45449,8 @@ async function daemonStart() {
|
|
|
45156
45449
|
let out;
|
|
45157
45450
|
let err;
|
|
45158
45451
|
try {
|
|
45159
|
-
out = (0,
|
|
45160
|
-
err = (0,
|
|
45452
|
+
out = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
|
|
45453
|
+
err = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
|
|
45161
45454
|
} catch (e) {
|
|
45162
45455
|
const code = e.code;
|
|
45163
45456
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -45170,7 +45463,7 @@ async function daemonStart() {
|
|
|
45170
45463
|
}
|
|
45171
45464
|
return;
|
|
45172
45465
|
}
|
|
45173
|
-
const child = (0,
|
|
45466
|
+
const child = (0, import_node_child_process16.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
45174
45467
|
detached: true,
|
|
45175
45468
|
stdio: ["ignore", out, err],
|
|
45176
45469
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -45245,41 +45538,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
45245
45538
|
}
|
|
45246
45539
|
async function releaseStaleSocket() {
|
|
45247
45540
|
const deadline = Date.now() + 2e3;
|
|
45248
|
-
while ((0,
|
|
45541
|
+
while ((0, import_node_fs40.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
45249
45542
|
await new Promise((r) => setTimeout(r, 50));
|
|
45250
45543
|
}
|
|
45251
|
-
if ((0,
|
|
45544
|
+
if ((0, import_node_fs40.existsSync)(PATHS.socket)) {
|
|
45252
45545
|
try {
|
|
45253
|
-
(0,
|
|
45546
|
+
(0, import_node_fs40.unlinkSync)(PATHS.socket);
|
|
45254
45547
|
} catch {
|
|
45255
45548
|
}
|
|
45256
45549
|
}
|
|
45257
45550
|
}
|
|
45258
45551
|
|
|
45259
45552
|
// src/commands/service.ts
|
|
45260
|
-
var
|
|
45261
|
-
var
|
|
45262
|
-
var
|
|
45553
|
+
var import_node_child_process17 = require("child_process");
|
|
45554
|
+
var import_node_fs42 = require("fs");
|
|
45555
|
+
var import_node_path31 = require("path");
|
|
45263
45556
|
var import_node_os12 = require("os");
|
|
45264
45557
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
45265
45558
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
45266
45559
|
function resolveTemplate() {
|
|
45267
|
-
const templatePath = (0,
|
|
45268
|
-
if (!(0,
|
|
45560
|
+
const templatePath = (0, import_node_path31.join)(__dirname, "systemd", "threatcrushd.service");
|
|
45561
|
+
if (!(0, import_node_fs42.existsSync)(templatePath)) {
|
|
45269
45562
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
45270
45563
|
}
|
|
45271
|
-
return (0,
|
|
45564
|
+
return (0, import_node_fs42.readFileSync)(templatePath, "utf-8");
|
|
45272
45565
|
}
|
|
45273
45566
|
function stableBinPath(binPath) {
|
|
45274
45567
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
45275
45568
|
if (stable === binPath) return binPath;
|
|
45276
|
-
return (0,
|
|
45569
|
+
return (0, import_node_fs42.existsSync)(stable) ? stable : binPath;
|
|
45277
45570
|
}
|
|
45278
45571
|
function resolveBinPath() {
|
|
45279
45572
|
const arg = process.argv[1];
|
|
45280
|
-
if (arg && (0,
|
|
45573
|
+
if (arg && (0, import_node_fs42.existsSync)(arg)) return stableBinPath(arg);
|
|
45281
45574
|
try {
|
|
45282
|
-
return (0,
|
|
45575
|
+
return (0, import_node_child_process17.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
45283
45576
|
} catch {
|
|
45284
45577
|
return "threatcrush";
|
|
45285
45578
|
}
|
|
@@ -45287,11 +45580,11 @@ function resolveBinPath() {
|
|
|
45287
45580
|
function stableNodePath(execPath) {
|
|
45288
45581
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
45289
45582
|
if (stable === execPath) return execPath;
|
|
45290
|
-
return (0,
|
|
45583
|
+
return (0, import_node_fs42.existsSync)(stable) ? stable : execPath;
|
|
45291
45584
|
}
|
|
45292
45585
|
function looksLikeNodeScript(path) {
|
|
45293
45586
|
try {
|
|
45294
|
-
const head = (0,
|
|
45587
|
+
const head = (0, import_node_fs42.readFileSync)(path, "utf-8").slice(0, 120);
|
|
45295
45588
|
return /^#!.*\bnode\b/.test(head);
|
|
45296
45589
|
} catch {
|
|
45297
45590
|
return false;
|
|
@@ -45318,20 +45611,20 @@ function isRoot3() {
|
|
|
45318
45611
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
45319
45612
|
}
|
|
45320
45613
|
function reexecWithSudo(args) {
|
|
45321
|
-
if ((0,
|
|
45614
|
+
if ((0, import_node_child_process17.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
45322
45615
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
45323
45616
|
const bin = resolveBinPath();
|
|
45324
45617
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
45325
|
-
const result = (0,
|
|
45618
|
+
const result = (0, import_node_child_process17.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
45326
45619
|
return result.status === 0;
|
|
45327
45620
|
}
|
|
45328
45621
|
function callerHome() {
|
|
45329
45622
|
const user = process.env.SUDO_USER;
|
|
45330
45623
|
if (!user) return null;
|
|
45331
45624
|
try {
|
|
45332
|
-
const line2 = (0,
|
|
45625
|
+
const line2 = (0, import_node_child_process17.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
45333
45626
|
const home = line2.split(":")[5];
|
|
45334
|
-
return home && (0,
|
|
45627
|
+
return home && (0, import_node_fs42.existsSync)(home) ? home : null;
|
|
45335
45628
|
} catch {
|
|
45336
45629
|
return null;
|
|
45337
45630
|
}
|
|
@@ -45339,13 +45632,13 @@ function callerHome() {
|
|
|
45339
45632
|
function stopUserModeDaemon() {
|
|
45340
45633
|
const home = callerHome();
|
|
45341
45634
|
if (!home) return;
|
|
45342
|
-
const runDir = (0,
|
|
45343
|
-
const pidFile = (0,
|
|
45344
|
-
const socket = (0,
|
|
45345
|
-
if (!(0,
|
|
45635
|
+
const runDir = (0, import_node_path31.join)(home, ".threatcrush", "run");
|
|
45636
|
+
const pidFile = (0, import_node_path31.join)(runDir, "threatcrushd.pid");
|
|
45637
|
+
const socket = (0, import_node_path31.join)(runDir, "threatcrushd.sock");
|
|
45638
|
+
if (!(0, import_node_fs42.existsSync)(pidFile) && !(0, import_node_fs42.existsSync)(socket)) return;
|
|
45346
45639
|
let pid = null;
|
|
45347
45640
|
try {
|
|
45348
|
-
pid = Number.parseInt((0,
|
|
45641
|
+
pid = Number.parseInt((0, import_node_fs42.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
45349
45642
|
} catch {
|
|
45350
45643
|
pid = null;
|
|
45351
45644
|
}
|
|
@@ -45358,13 +45651,13 @@ function stopUserModeDaemon() {
|
|
|
45358
45651
|
}
|
|
45359
45652
|
for (const path of [socket, pidFile]) {
|
|
45360
45653
|
try {
|
|
45361
|
-
if ((0,
|
|
45654
|
+
if ((0, import_node_fs42.existsSync)(path)) (0, import_node_fs42.rmSync)(path);
|
|
45362
45655
|
} catch {
|
|
45363
45656
|
}
|
|
45364
45657
|
}
|
|
45365
45658
|
}
|
|
45366
45659
|
function unitIsActive() {
|
|
45367
|
-
const result = (0,
|
|
45660
|
+
const result = (0, import_node_child_process17.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
45368
45661
|
return result.status === 0;
|
|
45369
45662
|
}
|
|
45370
45663
|
async function installServiceCommand() {
|
|
@@ -45375,8 +45668,8 @@ async function installServiceCommand() {
|
|
|
45375
45668
|
return;
|
|
45376
45669
|
}
|
|
45377
45670
|
const noSystemd = systemdUnavailableReason({
|
|
45378
|
-
hasSystemctl: (0,
|
|
45379
|
-
booted: (0,
|
|
45671
|
+
hasSystemctl: (0, import_node_child_process17.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
45672
|
+
booted: (0, import_node_fs42.existsSync)("/run/systemd/system")
|
|
45380
45673
|
});
|
|
45381
45674
|
if (noSystemd) {
|
|
45382
45675
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -45398,7 +45691,7 @@ async function installServiceCommand() {
|
|
|
45398
45691
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
45399
45692
|
let nodePath = stableNodePath(process.execPath);
|
|
45400
45693
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
45401
|
-
binPath = (0,
|
|
45694
|
+
binPath = (0, import_node_fs42.realpathSync)(binPath);
|
|
45402
45695
|
nodePath = process.execPath;
|
|
45403
45696
|
}
|
|
45404
45697
|
if (isNodeScript) {
|
|
@@ -45411,9 +45704,9 @@ async function installServiceCommand() {
|
|
|
45411
45704
|
}
|
|
45412
45705
|
}
|
|
45413
45706
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
45414
|
-
const configDir = (0,
|
|
45707
|
+
const configDir = (0, import_node_path31.join)((0, import_node_os12.homedir)(), ".threatcrush");
|
|
45415
45708
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
45416
|
-
(0,
|
|
45709
|
+
(0, import_node_fs42.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
45417
45710
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
45418
45711
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
45419
45712
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -45428,8 +45721,8 @@ async function installServiceCommand() {
|
|
|
45428
45721
|
installLogrotate();
|
|
45429
45722
|
stopUserModeDaemon();
|
|
45430
45723
|
try {
|
|
45431
|
-
(0,
|
|
45432
|
-
(0,
|
|
45724
|
+
(0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
45725
|
+
(0, import_node_child_process17.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
45433
45726
|
} catch (err) {
|
|
45434
45727
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
45435
45728
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -45466,9 +45759,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
45466
45759
|
].join("\n");
|
|
45467
45760
|
}
|
|
45468
45761
|
function installLogrotate() {
|
|
45469
|
-
if (!(0,
|
|
45762
|
+
if (!(0, import_node_fs42.existsSync)((0, import_node_path31.dirname)(LOGROTATE_PATH))) return;
|
|
45470
45763
|
try {
|
|
45471
|
-
(0,
|
|
45764
|
+
(0, import_node_fs42.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
45472
45765
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
45473
45766
|
} catch (err) {
|
|
45474
45767
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -45490,20 +45783,20 @@ function ensureSystemDirs(configDir) {
|
|
|
45490
45783
|
];
|
|
45491
45784
|
let admGid2 = null;
|
|
45492
45785
|
try {
|
|
45493
|
-
admGid2 = (0,
|
|
45786
|
+
admGid2 = (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
|
|
45494
45787
|
} catch {
|
|
45495
45788
|
}
|
|
45496
45789
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
45497
45790
|
try {
|
|
45498
|
-
(0,
|
|
45791
|
+
(0, import_node_fs42.mkdirSync)(path, { recursive: true });
|
|
45499
45792
|
} catch {
|
|
45500
45793
|
}
|
|
45501
45794
|
try {
|
|
45502
45795
|
if (groupWritable && admGid2 !== null) {
|
|
45503
|
-
(0,
|
|
45504
|
-
(0,
|
|
45796
|
+
(0, import_node_fs42.chmodSync)(path, sticky ? 1533 : 509);
|
|
45797
|
+
(0, import_node_child_process17.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
45505
45798
|
} else {
|
|
45506
|
-
(0,
|
|
45799
|
+
(0, import_node_fs42.chmodSync)(path, 493);
|
|
45507
45800
|
}
|
|
45508
45801
|
} catch {
|
|
45509
45802
|
}
|
|
@@ -45523,29 +45816,29 @@ async function uninstallServiceCommand() {
|
|
|
45523
45816
|
return;
|
|
45524
45817
|
}
|
|
45525
45818
|
try {
|
|
45526
|
-
(0,
|
|
45819
|
+
(0, import_node_child_process17.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
45527
45820
|
} catch {
|
|
45528
45821
|
}
|
|
45529
45822
|
try {
|
|
45530
|
-
(0,
|
|
45823
|
+
(0, import_node_child_process17.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
45531
45824
|
} catch {
|
|
45532
45825
|
}
|
|
45533
45826
|
try {
|
|
45534
|
-
if ((0,
|
|
45535
|
-
(0,
|
|
45827
|
+
if ((0, import_node_fs42.existsSync)(UNIT_PATH)) {
|
|
45828
|
+
(0, import_node_child_process17.execSync)(`rm -f ${UNIT_PATH}`);
|
|
45536
45829
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
45537
45830
|
}
|
|
45538
45831
|
} catch {
|
|
45539
45832
|
}
|
|
45540
45833
|
try {
|
|
45541
|
-
(0,
|
|
45834
|
+
(0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
45542
45835
|
} catch {
|
|
45543
45836
|
}
|
|
45544
45837
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
45545
45838
|
}
|
|
45546
45839
|
|
|
45547
45840
|
// src/commands/save.ts
|
|
45548
|
-
var
|
|
45841
|
+
var import_node_fs43 = require("fs");
|
|
45549
45842
|
var import_toml5 = __toESM(require_toml());
|
|
45550
45843
|
init_cli_config();
|
|
45551
45844
|
init_paths();
|
|
@@ -45584,9 +45877,9 @@ async function saveCommand(opts = {}) {
|
|
|
45584
45877
|
}
|
|
45585
45878
|
const path = opts.config ?? PATHS.configFile;
|
|
45586
45879
|
let config = {};
|
|
45587
|
-
if ((0,
|
|
45880
|
+
if ((0, import_node_fs43.existsSync)(path)) {
|
|
45588
45881
|
try {
|
|
45589
|
-
config = import_toml5.default.parse((0,
|
|
45882
|
+
config = import_toml5.default.parse((0, import_node_fs43.readFileSync)(path, "utf-8"));
|
|
45590
45883
|
} catch (err) {
|
|
45591
45884
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
45592
45885
|
`));
|
|
@@ -45699,8 +45992,8 @@ function welcomeCommand() {
|
|
|
45699
45992
|
}
|
|
45700
45993
|
|
|
45701
45994
|
// src/commands/properties.ts
|
|
45702
|
-
var
|
|
45703
|
-
var
|
|
45995
|
+
var import_node_fs44 = require("fs");
|
|
45996
|
+
var import_node_path32 = require("path");
|
|
45704
45997
|
var import_node_readline4 = __toESM(require("readline"));
|
|
45705
45998
|
init_cli_config();
|
|
45706
45999
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -46030,8 +46323,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
46030
46323
|
}
|
|
46031
46324
|
}
|
|
46032
46325
|
function parseImportFile(path) {
|
|
46033
|
-
const ext = (0,
|
|
46034
|
-
const raw = (0,
|
|
46326
|
+
const ext = (0, import_node_path32.extname)(path).toLowerCase();
|
|
46327
|
+
const raw = (0, import_node_fs44.readFileSync)(path, "utf-8");
|
|
46035
46328
|
if (ext === ".json") {
|
|
46036
46329
|
const parsed = JSON.parse(raw);
|
|
46037
46330
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -46226,19 +46519,19 @@ async function rulesCommand(opts) {
|
|
|
46226
46519
|
}
|
|
46227
46520
|
|
|
46228
46521
|
// src/commands/harden.ts
|
|
46229
|
-
var
|
|
46230
|
-
var
|
|
46522
|
+
var import_node_fs45 = require("fs");
|
|
46523
|
+
var import_node_child_process18 = require("child_process");
|
|
46231
46524
|
init_cli_config();
|
|
46232
46525
|
function tryExec(cmd) {
|
|
46233
46526
|
try {
|
|
46234
|
-
return (0,
|
|
46527
|
+
return (0, import_node_child_process18.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
46235
46528
|
} catch {
|
|
46236
46529
|
return null;
|
|
46237
46530
|
}
|
|
46238
46531
|
}
|
|
46239
46532
|
function tryRead(path) {
|
|
46240
46533
|
try {
|
|
46241
|
-
return (0,
|
|
46534
|
+
return (0, import_node_fs45.readFileSync)(path, "utf-8");
|
|
46242
46535
|
} catch {
|
|
46243
46536
|
return null;
|
|
46244
46537
|
}
|
|
@@ -46342,8 +46635,8 @@ function checkSshWeakConfig() {
|
|
|
46342
46635
|
};
|
|
46343
46636
|
}
|
|
46344
46637
|
function checkAutoUpdates() {
|
|
46345
|
-
const unattended = (0,
|
|
46346
|
-
const dnfAuto = (0,
|
|
46638
|
+
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");
|
|
46639
|
+
const dnfAuto = (0, import_node_fs45.existsSync)("/etc/dnf/automatic.conf");
|
|
46347
46640
|
if (unattended || dnfAuto) {
|
|
46348
46641
|
return {
|
|
46349
46642
|
key: "auto-updates",
|
|
@@ -46469,7 +46762,7 @@ function checkFail2ban() {
|
|
|
46469
46762
|
explanation: "fail2ban is installed and running."
|
|
46470
46763
|
};
|
|
46471
46764
|
}
|
|
46472
|
-
if ((0,
|
|
46765
|
+
if ((0, import_node_fs45.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
46473
46766
|
return {
|
|
46474
46767
|
key: checkKey,
|
|
46475
46768
|
status: "warn",
|
|
@@ -46655,9 +46948,9 @@ async function hardenCommand(opts) {
|
|
|
46655
46948
|
}
|
|
46656
46949
|
|
|
46657
46950
|
// src/core/patches/index.ts
|
|
46658
|
-
var
|
|
46659
|
-
var
|
|
46660
|
-
var
|
|
46951
|
+
var import_node_fs46 = require("fs");
|
|
46952
|
+
var import_node_path33 = require("path");
|
|
46953
|
+
var import_node_child_process19 = require("child_process");
|
|
46661
46954
|
var import_node_util2 = require("util");
|
|
46662
46955
|
|
|
46663
46956
|
// src/core/patches/dpkg-version.ts
|
|
@@ -46717,7 +47010,7 @@ var STALE_AFTER_MS = 2 * 864e5;
|
|
|
46717
47010
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
46718
47011
|
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
46719
47012
|
var defaultExec = async (file, args) => {
|
|
46720
|
-
const { stdout } = await (0, import_node_util2.promisify)(
|
|
47013
|
+
const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process19.execFile)(file, args, {
|
|
46721
47014
|
timeout: 12e4,
|
|
46722
47015
|
maxBuffer: 32 * 1024 * 1024,
|
|
46723
47016
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -46816,9 +47109,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
46816
47109
|
function newestReleaseMtime(dir) {
|
|
46817
47110
|
try {
|
|
46818
47111
|
let newest = 0;
|
|
46819
|
-
for (const name of (0,
|
|
47112
|
+
for (const name of (0, import_node_fs46.readdirSync)(dir)) {
|
|
46820
47113
|
if (!/Release$/.test(name)) continue;
|
|
46821
|
-
newest = Math.max(newest, (0,
|
|
47114
|
+
newest = Math.max(newest, (0, import_node_fs46.statSync)((0, import_node_path33.join)(dir, name)).mtimeMs);
|
|
46822
47115
|
}
|
|
46823
47116
|
return newest > 0 ? new Date(newest) : null;
|
|
46824
47117
|
} catch {
|
|
@@ -46835,7 +47128,7 @@ async function checkPatches(opts = {}) {
|
|
|
46835
47128
|
let osText = opts.osRelease;
|
|
46836
47129
|
if (osText === void 0) {
|
|
46837
47130
|
try {
|
|
46838
|
-
osText = (0,
|
|
47131
|
+
osText = (0, import_node_fs46.readFileSync)("/etc/os-release", "utf-8");
|
|
46839
47132
|
} catch {
|
|
46840
47133
|
osText = "";
|
|
46841
47134
|
}
|
|
@@ -47062,18 +47355,142 @@ async function patchesCommand(opts) {
|
|
|
47062
47355
|
|
|
47063
47356
|
// src/commands/feeds.ts
|
|
47064
47357
|
var import_node_net12 = require("net");
|
|
47065
|
-
var
|
|
47358
|
+
var import_node_path35 = require("path");
|
|
47066
47359
|
init_paths();
|
|
47360
|
+
|
|
47361
|
+
// src/commands/feeds-resolver.ts
|
|
47362
|
+
var import_node_child_process20 = require("child_process");
|
|
47363
|
+
var import_node_fs47 = require("fs");
|
|
47364
|
+
var import_node_path34 = require("path");
|
|
47365
|
+
var realIO = {
|
|
47366
|
+
exists: (p) => (0, import_node_fs47.existsSync)(p),
|
|
47367
|
+
read: (p) => {
|
|
47368
|
+
try {
|
|
47369
|
+
return (0, import_node_fs47.readFileSync)(p, "utf-8");
|
|
47370
|
+
} catch {
|
|
47371
|
+
return null;
|
|
47372
|
+
}
|
|
47373
|
+
},
|
|
47374
|
+
write: (p, c) => (0, import_node_fs47.writeFileSync)(p, c),
|
|
47375
|
+
remove: (p) => (0, import_node_fs47.rmSync)(p, { force: true }),
|
|
47376
|
+
run: (cmd, args) => {
|
|
47377
|
+
const r = (0, import_node_child_process20.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
47378
|
+
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
47379
|
+
}
|
|
47380
|
+
};
|
|
47381
|
+
var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
|
|
47382
|
+
var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
|
|
47383
|
+
function hookContent(resolver, stateDir) {
|
|
47384
|
+
const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
|
|
47385
|
+
return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts)}
|
|
47386
|
+
` : `${head}include: "${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)}"
|
|
47387
|
+
`;
|
|
47388
|
+
}
|
|
47389
|
+
function apparmorRule(stateDir) {
|
|
47390
|
+
return ` ${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
|
|
47391
|
+
}
|
|
47392
|
+
function detectResolvers(io = realIO) {
|
|
47393
|
+
const found = [];
|
|
47394
|
+
if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
|
|
47395
|
+
if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
|
|
47396
|
+
return found;
|
|
47397
|
+
}
|
|
47398
|
+
function check(resolver, io) {
|
|
47399
|
+
return resolver === "dnsmasq" ? io.run("dnsmasq", ["--test"]) : io.run("unbound-checkconf", []);
|
|
47400
|
+
}
|
|
47401
|
+
function restartIfActive(resolver, io) {
|
|
47402
|
+
if (io.run("systemctl", ["is-active", "--quiet", `${resolver}.service`]).code !== 0) return "not running; takes effect when it starts";
|
|
47403
|
+
const r = io.run("systemctl", ["restart", `${resolver}.service`]);
|
|
47404
|
+
return r.code === 0 ? "restarted" : `restart failed: ${r.out.split("\n")[0]}`;
|
|
47405
|
+
}
|
|
47406
|
+
function installHook(resolver, stateDir, io = realIO) {
|
|
47407
|
+
const hook = RESOLVER_HOOKS[resolver];
|
|
47408
|
+
const file = (0, import_node_path34.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
|
|
47409
|
+
if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
|
|
47410
|
+
io.write(hook, hookContent(resolver, stateDir));
|
|
47411
|
+
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
47412
|
+
const local = io.read(APPARMOR_LOCAL) ?? "";
|
|
47413
|
+
if (!local.includes(apparmorRule(stateDir))) io.write(APPARMOR_LOCAL, `${local.replace(/\n?$/, "\n")}${apparmorRule(stateDir)}
|
|
47414
|
+
`);
|
|
47415
|
+
if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
|
|
47416
|
+
}
|
|
47417
|
+
const checked = check(resolver, io);
|
|
47418
|
+
if (checked.code !== 0) {
|
|
47419
|
+
removeHook(resolver, stateDir, io, { restart: false });
|
|
47420
|
+
return { ok: false, message: `${resolver} rejected the config, so nothing was changed: ${checked.out.split("\n").slice(-2).join(" ")}` };
|
|
47421
|
+
}
|
|
47422
|
+
return { ok: true, message: `${hook} installed; ${resolver} ${restartIfActive(resolver, io)}` };
|
|
47423
|
+
}
|
|
47424
|
+
function removeHook(resolver, stateDir, io = realIO, opts = { restart: true }) {
|
|
47425
|
+
const hook = RESOLVER_HOOKS[resolver];
|
|
47426
|
+
const had = io.exists(hook);
|
|
47427
|
+
io.remove(hook);
|
|
47428
|
+
if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
|
|
47429
|
+
const local = io.read(APPARMOR_LOCAL) ?? "";
|
|
47430
|
+
const kept = local.split("\n").filter((l) => l !== apparmorRule(stateDir)).join("\n");
|
|
47431
|
+
if (kept !== local) {
|
|
47432
|
+
io.write(APPARMOR_LOCAL, kept);
|
|
47433
|
+
if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
|
|
47434
|
+
}
|
|
47435
|
+
}
|
|
47436
|
+
if (!had) return `${resolver}: no hook installed`;
|
|
47437
|
+
return `${hook} removed${opts.restart ? `; ${resolver} ${restartIfActive(resolver, io)}` : ""}`;
|
|
47438
|
+
}
|
|
47439
|
+
function countListed(text, pattern) {
|
|
47440
|
+
return text ? (text.match(pattern) ?? []).length : 0;
|
|
47441
|
+
}
|
|
47442
|
+
function resolverCommand(sub, stateDir, io = realIO) {
|
|
47443
|
+
const found = detectResolvers(io);
|
|
47444
|
+
const root = typeof process.getuid !== "function" || process.getuid() === 0;
|
|
47445
|
+
if (sub === "install" || sub === "remove") {
|
|
47446
|
+
if (!root) {
|
|
47447
|
+
console.error(`Run as root: sudo $(which threatcrush) feeds resolver ${sub}`);
|
|
47448
|
+
return 1;
|
|
47449
|
+
}
|
|
47450
|
+
if (sub === "install" && found.length === 0) {
|
|
47451
|
+
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.");
|
|
47452
|
+
return 1;
|
|
47453
|
+
}
|
|
47454
|
+
let failed = false;
|
|
47455
|
+
for (const resolver of sub === "install" ? found : ["dnsmasq", "unbound"]) {
|
|
47456
|
+
if (sub === "install") {
|
|
47457
|
+
const r = installHook(resolver, stateDir, io);
|
|
47458
|
+
failed ||= !r.ok;
|
|
47459
|
+
console.log(`${r.ok ? source_default.green("\u2713") : source_default.red("\u2717")} ${r.message}`);
|
|
47460
|
+
} else {
|
|
47461
|
+
console.log(` ${removeHook(resolver, stateDir, io)}`);
|
|
47462
|
+
}
|
|
47463
|
+
}
|
|
47464
|
+
if (sub === "install" && !failed) {
|
|
47465
|
+
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."));
|
|
47466
|
+
}
|
|
47467
|
+
return failed ? 1 : 0;
|
|
47468
|
+
}
|
|
47469
|
+
const hosts = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts));
|
|
47470
|
+
const unbound = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound));
|
|
47471
|
+
console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
|
|
47472
|
+
for (const r of ["dnsmasq", "unbound"]) {
|
|
47473
|
+
console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
|
|
47474
|
+
}
|
|
47475
|
+
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}`);
|
|
47476
|
+
return 0;
|
|
47477
|
+
}
|
|
47478
|
+
|
|
47479
|
+
// src/commands/feeds.ts
|
|
47067
47480
|
async function loadSet() {
|
|
47068
47481
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
47069
|
-
const path = (0,
|
|
47482
|
+
const path = (0, import_node_path35.join)(dir, "threat-feeds.json");
|
|
47070
47483
|
const set = readFeedCache(path);
|
|
47071
47484
|
if (set) return { set, from: path };
|
|
47072
47485
|
}
|
|
47073
|
-
const settings = threatFeedSettings(loadConfig((0,
|
|
47486
|
+
const settings = threatFeedSettings(loadConfig((0, import_node_path35.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
|
|
47074
47487
|
return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
|
|
47075
47488
|
}
|
|
47076
47489
|
async function feedsCommand(action, value, opts) {
|
|
47490
|
+
if (action === "resolver") {
|
|
47491
|
+
process.exitCode = resolverCommand(value, SYSTEM_PATHS.stateDir);
|
|
47492
|
+
return;
|
|
47493
|
+
}
|
|
47077
47494
|
const { set, from } = await loadSet();
|
|
47078
47495
|
if (action === "check") {
|
|
47079
47496
|
if (!value) {
|
|
@@ -47110,7 +47527,7 @@ async function feedsCommand(action, value, opts) {
|
|
|
47110
47527
|
}
|
|
47111
47528
|
|
|
47112
47529
|
// src/commands/privileged.ts
|
|
47113
|
-
var
|
|
47530
|
+
var import_node_fs48 = require("fs");
|
|
47114
47531
|
init_paths();
|
|
47115
47532
|
var SEV2 = {
|
|
47116
47533
|
critical: source_default.red.bold,
|
|
@@ -47123,19 +47540,19 @@ async function privilegedCommand(opts) {
|
|
|
47123
47540
|
const snapshot = takeSnapshot({
|
|
47124
47541
|
readFile: (p) => {
|
|
47125
47542
|
try {
|
|
47126
|
-
return (0,
|
|
47543
|
+
return (0, import_node_fs48.readFileSync)(p, "utf-8");
|
|
47127
47544
|
} catch {
|
|
47128
47545
|
return null;
|
|
47129
47546
|
}
|
|
47130
47547
|
},
|
|
47131
47548
|
readDir: (p) => {
|
|
47132
47549
|
try {
|
|
47133
|
-
return (0,
|
|
47550
|
+
return (0, import_node_fs48.readdirSync)(p);
|
|
47134
47551
|
} catch {
|
|
47135
47552
|
return null;
|
|
47136
47553
|
}
|
|
47137
47554
|
},
|
|
47138
|
-
exists: (p) => (0,
|
|
47555
|
+
exists: (p) => (0, import_node_fs48.existsSync)(p)
|
|
47139
47556
|
});
|
|
47140
47557
|
let events = [];
|
|
47141
47558
|
let ledgerNote = "";
|
|
@@ -47320,11 +47737,11 @@ async function allowlistCommand(opts) {
|
|
|
47320
47737
|
init_paths();
|
|
47321
47738
|
|
|
47322
47739
|
// src/upgrade.ts
|
|
47323
|
-
var
|
|
47740
|
+
var import_node_child_process21 = require("child_process");
|
|
47324
47741
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
47325
47742
|
var defaultRunner = (cmd) => {
|
|
47326
47743
|
try {
|
|
47327
|
-
return (0,
|
|
47744
|
+
return (0, import_node_child_process21.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
47328
47745
|
} catch {
|
|
47329
47746
|
return null;
|
|
47330
47747
|
}
|
|
@@ -47439,25 +47856,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
47439
47856
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
47440
47857
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
47441
47858
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
47442
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
47859
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
|
|
47443
47860
|
function detectPackageManager() {
|
|
47444
47861
|
try {
|
|
47445
|
-
const npmGlobal = (0,
|
|
47862
|
+
const npmGlobal = (0, import_node_child_process22.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
47446
47863
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
47447
47864
|
} catch {
|
|
47448
47865
|
}
|
|
47449
47866
|
try {
|
|
47450
|
-
(0,
|
|
47867
|
+
(0, import_node_child_process22.execSync)("pnpm --version", { stdio: "pipe" });
|
|
47451
47868
|
return "pnpm";
|
|
47452
47869
|
} catch {
|
|
47453
47870
|
}
|
|
47454
47871
|
try {
|
|
47455
|
-
(0,
|
|
47872
|
+
(0, import_node_child_process22.execSync)("yarn --version", { stdio: "pipe" });
|
|
47456
47873
|
return "yarn";
|
|
47457
47874
|
} catch {
|
|
47458
47875
|
}
|
|
47459
47876
|
try {
|
|
47460
|
-
(0,
|
|
47877
|
+
(0, import_node_child_process22.execSync)("bun --version", { stdio: "pipe" });
|
|
47461
47878
|
return "bun";
|
|
47462
47879
|
} catch {
|
|
47463
47880
|
}
|
|
@@ -47465,14 +47882,14 @@ function detectPackageManager() {
|
|
|
47465
47882
|
}
|
|
47466
47883
|
function readInstallConfig() {
|
|
47467
47884
|
try {
|
|
47468
|
-
return JSON.parse((0,
|
|
47885
|
+
return JSON.parse((0, import_node_fs49.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
47469
47886
|
} catch {
|
|
47470
47887
|
return {};
|
|
47471
47888
|
}
|
|
47472
47889
|
}
|
|
47473
47890
|
function packageLooksInstalled(pm, pkgName) {
|
|
47474
47891
|
try {
|
|
47475
|
-
const output = (0,
|
|
47892
|
+
const output = (0, import_node_child_process22.execSync)(globalListCommand(pm, pkgName), {
|
|
47476
47893
|
encoding: "utf-8",
|
|
47477
47894
|
stdio: ["pipe", "pipe", "pipe"]
|
|
47478
47895
|
});
|
|
@@ -47575,14 +47992,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
47575
47992
|
function restartSystemdDaemon() {
|
|
47576
47993
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
47577
47994
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
47578
|
-
if (!asRoot && (0,
|
|
47995
|
+
if (!asRoot && (0, import_node_child_process22.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
47579
47996
|
const [cmd, ...args] = argv;
|
|
47580
|
-
if ((0,
|
|
47581
|
-
return (0,
|
|
47997
|
+
if ((0, import_node_child_process22.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
47998
|
+
return (0, import_node_child_process22.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
47582
47999
|
}
|
|
47583
48000
|
function execQuiet(cmd) {
|
|
47584
48001
|
try {
|
|
47585
|
-
return (0,
|
|
48002
|
+
return (0, import_node_child_process22.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
47586
48003
|
} catch {
|
|
47587
48004
|
return null;
|
|
47588
48005
|
}
|
|
@@ -47735,7 +48152,7 @@ program2.command("harden").description("Run hardening security scan").option("--
|
|
|
47735
48152
|
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) => {
|
|
47736
48153
|
await patchesCommand(opts);
|
|
47737
48154
|
});
|
|
47738
|
-
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) => {
|
|
48155
|
+
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) => {
|
|
47739
48156
|
await feedsCommand(action, value, opts);
|
|
47740
48157
|
});
|
|
47741
48158
|
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) => {
|
|
@@ -47777,7 +48194,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
47777
48194
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
47778
48195
|
console.log(LOGO2);
|
|
47779
48196
|
const logPath = PATHS.logFile;
|
|
47780
|
-
if (!(0,
|
|
48197
|
+
if (!(0, import_node_fs49.existsSync)(logPath)) {
|
|
47781
48198
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
47782
48199
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
47783
48200
|
return;
|
|
@@ -47785,7 +48202,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
47785
48202
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
47786
48203
|
`));
|
|
47787
48204
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
47788
|
-
(0,
|
|
48205
|
+
(0, import_node_child_process22.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
47789
48206
|
});
|
|
47790
48207
|
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) => {
|
|
47791
48208
|
console.log(LOGO2);
|
|
@@ -47797,7 +48214,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
47797
48214
|
for (const cmd of commands2) {
|
|
47798
48215
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47799
48216
|
`));
|
|
47800
|
-
(0,
|
|
48217
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47801
48218
|
}
|
|
47802
48219
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
47803
48220
|
await reportIfStillStale();
|
|
@@ -47822,7 +48239,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
47822
48239
|
for (const cmd of commands) {
|
|
47823
48240
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47824
48241
|
`));
|
|
47825
|
-
(0,
|
|
48242
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47826
48243
|
}
|
|
47827
48244
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
47828
48245
|
if (installMode === "desktop") {
|
|
@@ -47873,7 +48290,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
47873
48290
|
for (const cmd of commands) {
|
|
47874
48291
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
47875
48292
|
`));
|
|
47876
|
-
(0,
|
|
48293
|
+
(0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
|
|
47877
48294
|
}
|
|
47878
48295
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
47879
48296
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -47950,10 +48367,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
47950
48367
|
});
|
|
47951
48368
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
47952
48369
|
console.log(LOGO2);
|
|
47953
|
-
const configPath = (0,
|
|
48370
|
+
const configPath = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
|
|
47954
48371
|
let email = "";
|
|
47955
48372
|
try {
|
|
47956
|
-
const config = JSON.parse((0,
|
|
48373
|
+
const config = JSON.parse((0, import_node_fs49.readFileSync)(configPath, "utf-8"));
|
|
47957
48374
|
email = config.email || "";
|
|
47958
48375
|
} catch {
|
|
47959
48376
|
}
|
|
@@ -47970,9 +48387,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
47970
48387
|
return;
|
|
47971
48388
|
}
|
|
47972
48389
|
try {
|
|
47973
|
-
const dir = (0,
|
|
47974
|
-
if (!(0,
|
|
47975
|
-
(0,
|
|
48390
|
+
const dir = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush");
|
|
48391
|
+
if (!(0, import_node_fs49.existsSync)(dir)) (0, import_node_fs49.mkdirSync)(dir, { recursive: true });
|
|
48392
|
+
(0, import_node_fs49.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
47976
48393
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
47977
48394
|
} catch {
|
|
47978
48395
|
}
|