@profullstack/threatcrush 0.12.5 → 0.12.7
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 +21 -6
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +73 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10420,11 +10420,15 @@ function isRoot() {
|
|
|
10420
10420
|
return process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
10421
10421
|
}
|
|
10422
10422
|
function resolveClientSocket() {
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
if ((0, import_node_fs2.existsSync)(
|
|
10423
|
+
const override = process.env.THREATCRUSH_SOCKET;
|
|
10424
|
+
if (override) return override;
|
|
10425
|
+
if ((0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket)) return SYSTEM_PATHS.socket;
|
|
10426
|
+
if ((0, import_node_fs2.existsSync)(USER_PATHS.socket)) return USER_PATHS.socket;
|
|
10426
10427
|
return PATHS.socket;
|
|
10427
10428
|
}
|
|
10429
|
+
function systemDaemonPresent() {
|
|
10430
|
+
return (0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket) || (0, import_node_fs2.existsSync)(SYSTEM_PATHS.pidFile);
|
|
10431
|
+
}
|
|
10428
10432
|
function ensureRuntimeDirs() {
|
|
10429
10433
|
for (const dir of [PATHS.configDir, PATHS.confD, PATHS.moduleDir, PATHS.logDir, PATHS.stateDir, PATHS.runDir]) {
|
|
10430
10434
|
try {
|
|
@@ -17732,6 +17736,7 @@ var GENERIC_GUARD = (
|
|
|
17732
17736
|
);
|
|
17733
17737
|
var XXE_GUARD = /FEATURE_SECURE_PROCESSING|setExpandEntityReferences|disallow-doctype-decl|external-general-entities|external-parameter-entities|setXIncludeAware\s*\(\s*false/;
|
|
17734
17738
|
var XML_PARSING_FILE = /\b(?:javax\.xml|org\.xml\.sax|org\.w3c\.dom|org\.jdom2?|org\.dom4j|XmlPullParser|DocumentBuilderFactory|DocumentBuilder|SAXParserFactory|SAXParser|XMLInputFactory|XMLReaderFactory|XMLReader|SAXBuilder|SAXReader)\b/;
|
|
17739
|
+
var PY_XPATH_FILE = /\b(?:lxml|xml\.etree|ElementTree|etree|defusedxml|xpath)\b/i;
|
|
17735
17740
|
var CODE_SINK = /\bglobalThis\s*\[|\bconstructor\b|\beval\b|\bFunction\b|\brun\s*\(|\bvm\s*\.\s*run/;
|
|
17736
17741
|
var EXFIL_SINK = /\bconsole\s*\.\s*(?:log|debug|info|warn|error)\s*\(|\bfetch\s*\(|\baxios\b|\brequest\s*\(|\.\s*send\s*\(/;
|
|
17737
17742
|
var SQL_KEYWORDS = "SELECT\\b(?=[^`'\"\\n]*\\bFROM\\b)|INSERT\\s+INTO|UPDATE\\b(?=[^`'\"\\n]*\\bSET\\b)|DELETE\\s+FROM|DROP\\s+(?:TABLE|DATABASE|INDEX|VIEW|SCHEMA)|TRUNCATE\\s+TABLE|UNION\\s+SELECT";
|
|
@@ -18692,8 +18697,11 @@ var CODE_RULES = [
|
|
|
18692
18697
|
severity: "high",
|
|
18693
18698
|
languages: ["python"],
|
|
18694
18699
|
// Per-quote, so an inner `'` in a `"`-delimited f-string (`text()='{x}'`)
|
|
18695
|
-
// does not truncate the match before the interpolation.
|
|
18696
|
-
|
|
18700
|
+
// does not truncate the match before the interpolation. `(?<!:)` keeps the
|
|
18701
|
+
// `//` of a URL scheme out of it: `f"https://{host}/v1"` is a URL, not a
|
|
18702
|
+
// descendant-or-self step, and it was by far the commonest match here.
|
|
18703
|
+
pattern: /\bf"[^"\n]*(?:(?<!:)\/\/|\/\w+\[)[^"\n]*\{[^}\n]+\}|\bf'[^'\n]*(?:(?<!:)\/\/|\/\w+\[)[^'\n]*\{[^}\n]+\}/,
|
|
18704
|
+
fileRequires: PY_XPATH_FILE
|
|
18697
18705
|
},
|
|
18698
18706
|
{
|
|
18699
18707
|
id: "py-fast-password-hash",
|
|
@@ -19673,7 +19681,7 @@ var SECRET_RULES = [
|
|
|
19673
19681
|
keywordShaped: true
|
|
19674
19682
|
}
|
|
19675
19683
|
];
|
|
19676
|
-
var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv])`;
|
|
19684
|
+
var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv]|\{[^{}\s'"@/]+\}|<[A-Za-z_][\w.-]*>)`;
|
|
19677
19685
|
var KNOWN_PLACEHOLDERS = [
|
|
19678
19686
|
// Deliberately NOT here: AWS's published documentation key/secret pair
|
|
19679
19687
|
// (`AKIAIOSFODNN7EXAMPLE`, `wJalrXUtnFEMI/…`). GitHub allow-lists them, and
|
|
@@ -21666,14 +21674,12 @@ async function statusCommand() {
|
|
|
21666
21674
|
const pid = findRunningDaemon();
|
|
21667
21675
|
const client = new IpcClient();
|
|
21668
21676
|
let live = null;
|
|
21669
|
-
|
|
21670
|
-
|
|
21671
|
-
|
|
21672
|
-
|
|
21673
|
-
|
|
21674
|
-
|
|
21675
|
-
client.close();
|
|
21676
|
-
}
|
|
21677
|
+
try {
|
|
21678
|
+
await client.connect();
|
|
21679
|
+
live = await client.status();
|
|
21680
|
+
} catch {
|
|
21681
|
+
} finally {
|
|
21682
|
+
client.close();
|
|
21677
21683
|
}
|
|
21678
21684
|
console.log(source_default.green.bold(" Daemon Status"));
|
|
21679
21685
|
console.log(source_default.gray(" " + "\u2500".repeat(60)));
|
|
@@ -23159,8 +23165,8 @@ var IpcServer = class {
|
|
|
23159
23165
|
nodeFs.chmodSync(PATHS.socket, 432);
|
|
23160
23166
|
} catch {
|
|
23161
23167
|
}
|
|
23162
|
-
const
|
|
23163
|
-
if (
|
|
23168
|
+
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
23169
|
+
if (isRoot4) {
|
|
23164
23170
|
try {
|
|
23165
23171
|
const { gid } = nodeFs.statSync("/var/log/auth.log");
|
|
23166
23172
|
nodeFs.chownSync(PATHS.socket, 0, gid);
|
|
@@ -23512,8 +23518,8 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
23512
23518
|
// would give us root's mostly-empty per-user journal. Otherwise we use
|
|
23513
23519
|
// --user so the daemon can run unprivileged on a workstation.
|
|
23514
23520
|
static scopeArgs() {
|
|
23515
|
-
const
|
|
23516
|
-
return
|
|
23521
|
+
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
23522
|
+
return isRoot4 ? [] : ["--user"];
|
|
23517
23523
|
}
|
|
23518
23524
|
static isAvailable() {
|
|
23519
23525
|
const probe = (0, import_node_child_process4.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
|
|
@@ -25728,14 +25734,25 @@ var RemediationManager = class {
|
|
|
25728
25734
|
}
|
|
25729
25735
|
this.blocklist = live;
|
|
25730
25736
|
this.saveState();
|
|
25731
|
-
|
|
25732
|
-
let applied = [];
|
|
25737
|
+
let applied = null;
|
|
25733
25738
|
try {
|
|
25734
25739
|
applied = await this.adapter.listBlocked();
|
|
25735
25740
|
} catch {
|
|
25736
25741
|
}
|
|
25742
|
+
if (applied) {
|
|
25743
|
+
const known = new Set(live.filter((b) => !b.dry_run).map((b) => b.ip));
|
|
25744
|
+
for (const ip of applied) {
|
|
25745
|
+
if (known.has(ip)) continue;
|
|
25746
|
+
this.logLine(`[firewall] reconcile: dropping stale rule for ${ip} (no record of why)`);
|
|
25747
|
+
try {
|
|
25748
|
+
await this.adapter.unblock(ip);
|
|
25749
|
+
} catch {
|
|
25750
|
+
}
|
|
25751
|
+
}
|
|
25752
|
+
}
|
|
25753
|
+
if (this.config.dry_run) return;
|
|
25737
25754
|
for (const entry of live) {
|
|
25738
|
-
if (applied
|
|
25755
|
+
if (applied?.includes(entry.ip)) continue;
|
|
25739
25756
|
try {
|
|
25740
25757
|
await this.adapter.block(entry.ip);
|
|
25741
25758
|
} catch {
|
|
@@ -26004,6 +26021,10 @@ async function runDaemon() {
|
|
|
26004
26021
|
// src/commands/daemon.ts
|
|
26005
26022
|
init_paths();
|
|
26006
26023
|
init_ipc_client();
|
|
26024
|
+
var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
26025
|
+
function isRoot2() {
|
|
26026
|
+
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
26027
|
+
}
|
|
26007
26028
|
var DAEMON_ENTRY = (0, import_node_path20.join)(__dirname, "daemon.js");
|
|
26008
26029
|
async function daemonForeground() {
|
|
26009
26030
|
await runDaemon();
|
|
@@ -26014,6 +26035,16 @@ async function daemonStart() {
|
|
|
26014
26035
|
console.log(source_default.yellow(` threatcrushd already running (pid ${pid}).`));
|
|
26015
26036
|
return;
|
|
26016
26037
|
}
|
|
26038
|
+
if (!isRoot2() && systemDaemonPresent()) {
|
|
26039
|
+
console.log(source_default.yellow(" A system threatcrushd is already installed on this host."));
|
|
26040
|
+
console.log(source_default.dim(" Starting a second, user-mode daemon would shadow it: the CLI would"));
|
|
26041
|
+
console.log(source_default.dim(" talk to yours while the root one keeps enforcing the firewall."));
|
|
26042
|
+
console.log();
|
|
26043
|
+
console.log(source_default.dim(" Manage that one instead: sudo systemctl restart threatcrushd"));
|
|
26044
|
+
console.log(source_default.dim(` Or address it directly: THREATCRUSH_SOCKET=${SYSTEM_SOCKET} threatcrush status`));
|
|
26045
|
+
console.log();
|
|
26046
|
+
return;
|
|
26047
|
+
}
|
|
26017
26048
|
ensureRuntimeDirs();
|
|
26018
26049
|
if (!(0, import_node_fs28.existsSync)(DAEMON_ENTRY)) {
|
|
26019
26050
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
@@ -26164,7 +26195,7 @@ function looksLikeNodeScript(path) {
|
|
|
26164
26195
|
function execStartCommand(binPath, nodePath, isNodeScript) {
|
|
26165
26196
|
return isNodeScript ? `${nodePath} ${binPath} daemon` : `${binPath} daemon`;
|
|
26166
26197
|
}
|
|
26167
|
-
function
|
|
26198
|
+
function isRoot3() {
|
|
26168
26199
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
26169
26200
|
}
|
|
26170
26201
|
function reexecWithSudo(args) {
|
|
@@ -26223,7 +26254,7 @@ async function installServiceCommand() {
|
|
|
26223
26254
|
console.log(source_default.yellow(" systemd install is only supported on Linux."));
|
|
26224
26255
|
return;
|
|
26225
26256
|
}
|
|
26226
|
-
if (!
|
|
26257
|
+
if (!isRoot3()) {
|
|
26227
26258
|
if (reexecWithSudo(["install-service"])) return;
|
|
26228
26259
|
console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
|
|
26229
26260
|
console.log(source_default.dim(" Run this as root: threatcrush install-service"));
|
|
@@ -26298,7 +26329,7 @@ async function uninstallServiceCommand() {
|
|
|
26298
26329
|
console.log(source_default.yellow(" systemd uninstall is only supported on Linux."));
|
|
26299
26330
|
return;
|
|
26300
26331
|
}
|
|
26301
|
-
if (!
|
|
26332
|
+
if (!isRoot3()) {
|
|
26302
26333
|
if (reexecWithSudo(["uninstall-service"])) return;
|
|
26303
26334
|
console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
|
|
26304
26335
|
console.log(source_default.dim(" Run this as root: threatcrush uninstall-service"));
|
|
@@ -27424,18 +27455,26 @@ async function allowlistCommand(opts) {
|
|
|
27424
27455
|
const action = opts.action || "list";
|
|
27425
27456
|
console.log(source_default.green.bold(" Allowlist (never banned)"));
|
|
27426
27457
|
console.log(source_default.gray(" " + "\u2500".repeat(50)));
|
|
27458
|
+
const client = await connect();
|
|
27459
|
+
if (!client) return;
|
|
27460
|
+
let configPath = PATHS.configFile;
|
|
27461
|
+
let mode = null;
|
|
27462
|
+
try {
|
|
27463
|
+
const status = await client.status();
|
|
27464
|
+
configPath = status.paths.config;
|
|
27465
|
+
mode = status.mode;
|
|
27466
|
+
} catch {
|
|
27467
|
+
}
|
|
27427
27468
|
if (action === "list" || action === "ls") {
|
|
27428
|
-
const client = await connect();
|
|
27429
|
-
if (!client) return;
|
|
27430
27469
|
try {
|
|
27431
27470
|
const reply = await client.blocklist();
|
|
27432
27471
|
for (const entry of reply.protected) {
|
|
27433
27472
|
console.log(` ${source_default.green("\u26CA")} ${source_default.white(entry)}`);
|
|
27434
27473
|
}
|
|
27435
27474
|
console.log();
|
|
27436
|
-
console.log(source_default.gray(" Loopback, private ranges, the default gateway and
|
|
27437
|
-
console.log(source_default.gray("
|
|
27438
|
-
console.log(source_default.gray(` [remediation] protected = [...] in ${
|
|
27475
|
+
console.log(source_default.gray(" Loopback, private ranges, the default gateway and every live SSH"));
|
|
27476
|
+
console.log(source_default.gray(" peer are always protected. Add more under"));
|
|
27477
|
+
console.log(source_default.gray(` [remediation] protected = [...] in ${configPath}`));
|
|
27439
27478
|
} catch (err) {
|
|
27440
27479
|
console.log(` ${source_default.red("\u2717")} ${err.message}`);
|
|
27441
27480
|
} finally {
|
|
@@ -27444,12 +27483,15 @@ async function allowlistCommand(opts) {
|
|
|
27444
27483
|
}
|
|
27445
27484
|
return;
|
|
27446
27485
|
}
|
|
27447
|
-
|
|
27486
|
+
client.close();
|
|
27487
|
+
console.log(source_default.gray(` Edit ${configPath}:`));
|
|
27448
27488
|
console.log();
|
|
27449
27489
|
console.log(source_default.gray(" [remediation]"));
|
|
27450
27490
|
console.log(source_default.gray(` protected = ["${opts.value || "203.0.113.7/32"}"]`));
|
|
27451
27491
|
console.log();
|
|
27452
|
-
console.log(source_default.gray(
|
|
27492
|
+
console.log(source_default.gray(
|
|
27493
|
+
mode === "system" ? " then: sudo systemctl restart threatcrushd" : " then: threatcrush restart"
|
|
27494
|
+
));
|
|
27453
27495
|
console.log();
|
|
27454
27496
|
}
|
|
27455
27497
|
|