@profullstack/threatcrush 0.13.7 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/crs/NOTICE +13 -3
- package/dist/daemon.js +518 -174
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +732 -368
- package/dist/index.js.map +1 -1
- package/dist/libinjection/COPYING +33 -0
- package/dist/libinjection/libinjection.wasm +0 -0
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -7881,14 +7881,14 @@ var init_surface = __esm({
|
|
|
7881
7881
|
const w = this.width;
|
|
7882
7882
|
const h = this.height;
|
|
7883
7883
|
const borderStyle = { fg, bg };
|
|
7884
|
-
const
|
|
7884
|
+
const put2 = options.collapse ? (x, y, ch) => this.mergeBorder(x, y, ch, style, borderStyle) : (x, y, ch) => this.char(x, y, ch, borderStyle);
|
|
7885
7885
|
const putH = (x, y, length, ch) => {
|
|
7886
7886
|
for (let i = 0; i < length; i++)
|
|
7887
|
-
|
|
7887
|
+
put2(x + i, y, ch);
|
|
7888
7888
|
};
|
|
7889
7889
|
const putV = (x, y, length, ch) => {
|
|
7890
7890
|
for (let i = 0; i < length; i++)
|
|
7891
|
-
|
|
7891
|
+
put2(x, y + i, ch);
|
|
7892
7892
|
};
|
|
7893
7893
|
const corner = (a, aBit, c, cBit) => junction(style, (a ? aBit : 0) | (c ? cBit : 0));
|
|
7894
7894
|
const tl = corner(sides.top, EDGE_RIGHT, sides.left, EDGE_DOWN);
|
|
@@ -7896,18 +7896,18 @@ var init_surface = __esm({
|
|
|
7896
7896
|
if (sides.top)
|
|
7897
7897
|
putH(1, 0, w - 2, b.h);
|
|
7898
7898
|
if (tl !== null)
|
|
7899
|
-
|
|
7899
|
+
put2(0, 0, tl);
|
|
7900
7900
|
if (tr !== null)
|
|
7901
|
-
|
|
7901
|
+
put2(w - 1, 0, tr);
|
|
7902
7902
|
if (h > 1) {
|
|
7903
7903
|
const bl = corner(sides.bottom, EDGE_RIGHT, sides.left, EDGE_UP);
|
|
7904
7904
|
const br = corner(sides.bottom, EDGE_LEFT, sides.right, EDGE_UP);
|
|
7905
7905
|
if (sides.bottom)
|
|
7906
7906
|
putH(1, h - 1, w - 2, b.h);
|
|
7907
7907
|
if (bl !== null)
|
|
7908
|
-
|
|
7908
|
+
put2(0, h - 1, bl);
|
|
7909
7909
|
if (br !== null)
|
|
7910
|
-
|
|
7910
|
+
put2(w - 1, h - 1, br);
|
|
7911
7911
|
if (sides.left)
|
|
7912
7912
|
putV(0, 1, h - 2, b.v);
|
|
7913
7913
|
if (sides.right)
|
|
@@ -12417,29 +12417,29 @@ function isRoot() {
|
|
|
12417
12417
|
function resolveClientSocket() {
|
|
12418
12418
|
const override = process.env.THREATCRUSH_SOCKET;
|
|
12419
12419
|
if (override) return override;
|
|
12420
|
-
if ((0,
|
|
12421
|
-
if ((0,
|
|
12420
|
+
if ((0, import_node_fs4.existsSync)(SYSTEM_PATHS.socket)) return SYSTEM_PATHS.socket;
|
|
12421
|
+
if ((0, import_node_fs4.existsSync)(USER_PATHS.socket)) return USER_PATHS.socket;
|
|
12422
12422
|
return PATHS.socket;
|
|
12423
12423
|
}
|
|
12424
12424
|
function systemDaemonPresent() {
|
|
12425
|
-
return (0,
|
|
12425
|
+
return (0, import_node_fs4.existsSync)(SYSTEM_PATHS.socket) || (0, import_node_fs4.existsSync)(SYSTEM_PATHS.pidFile);
|
|
12426
12426
|
}
|
|
12427
12427
|
function ensureRuntimeDirs() {
|
|
12428
12428
|
for (const dir of [PATHS.configDir, PATHS.confD, PATHS.moduleDir, PATHS.logDir, PATHS.stateDir, PATHS.runDir]) {
|
|
12429
12429
|
try {
|
|
12430
|
-
(0,
|
|
12430
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
12431
12431
|
} catch {
|
|
12432
12432
|
}
|
|
12433
12433
|
}
|
|
12434
12434
|
}
|
|
12435
|
-
var
|
|
12435
|
+
var import_node_fs4, import_node_os2, import_node_path4, userBase, SYSTEM_PATHS, USER_PATHS, PATHS;
|
|
12436
12436
|
var init_paths = __esm({
|
|
12437
12437
|
"src/daemon/paths.ts"() {
|
|
12438
12438
|
"use strict";
|
|
12439
|
-
|
|
12439
|
+
import_node_fs4 = require("fs");
|
|
12440
12440
|
import_node_os2 = require("os");
|
|
12441
|
-
|
|
12442
|
-
userBase = (0,
|
|
12441
|
+
import_node_path4 = require("path");
|
|
12442
|
+
userBase = (0, import_node_path4.join)((0, import_node_os2.homedir)(), ".threatcrush");
|
|
12443
12443
|
SYSTEM_PATHS = {
|
|
12444
12444
|
mode: "system",
|
|
12445
12445
|
configDir: "/etc/threatcrush",
|
|
@@ -12457,16 +12457,16 @@ var init_paths = __esm({
|
|
|
12457
12457
|
USER_PATHS = {
|
|
12458
12458
|
mode: "user",
|
|
12459
12459
|
configDir: userBase,
|
|
12460
|
-
configFile: (0,
|
|
12461
|
-
confD: (0,
|
|
12462
|
-
moduleDir: (0,
|
|
12463
|
-
logDir: (0,
|
|
12464
|
-
logFile: (0,
|
|
12465
|
-
stateDir: (0,
|
|
12466
|
-
stateDb: (0,
|
|
12467
|
-
runDir: (0,
|
|
12468
|
-
pidFile: (0,
|
|
12469
|
-
socket: (0,
|
|
12460
|
+
configFile: (0, import_node_path4.join)(userBase, "threatcrushd.conf"),
|
|
12461
|
+
confD: (0, import_node_path4.join)(userBase, "threatcrushd.conf.d"),
|
|
12462
|
+
moduleDir: (0, import_node_path4.join)(userBase, "modules"),
|
|
12463
|
+
logDir: (0, import_node_path4.join)(userBase, "logs"),
|
|
12464
|
+
logFile: (0, import_node_path4.join)(userBase, "logs", "threatcrushd.log"),
|
|
12465
|
+
stateDir: (0, import_node_path4.join)(userBase, "state"),
|
|
12466
|
+
stateDb: (0, import_node_path4.join)(userBase, "state", "state.db"),
|
|
12467
|
+
runDir: (0, import_node_path4.join)(userBase, "run"),
|
|
12468
|
+
pidFile: (0, import_node_path4.join)(userBase, "run", "threatcrushd.pid"),
|
|
12469
|
+
socket: (0, import_node_path4.join)(userBase, "run", "threatcrushd.sock")
|
|
12470
12470
|
};
|
|
12471
12471
|
PATHS = isRoot() ? SYSTEM_PATHS : USER_PATHS;
|
|
12472
12472
|
}
|
|
@@ -12475,17 +12475,17 @@ var init_paths = __esm({
|
|
|
12475
12475
|
// src/daemon/control-token.ts
|
|
12476
12476
|
function issueControlToken() {
|
|
12477
12477
|
const token = (0, import_node_crypto.randomBytes)(32).toString("hex");
|
|
12478
|
-
(0,
|
|
12478
|
+
(0, import_node_fs5.writeFileSync)(CONTROL_TOKEN_FILE, token, { mode: 384 });
|
|
12479
12479
|
try {
|
|
12480
|
-
(0,
|
|
12480
|
+
(0, import_node_fs5.chmodSync)(CONTROL_TOKEN_FILE, 384);
|
|
12481
12481
|
} catch {
|
|
12482
12482
|
}
|
|
12483
12483
|
return token;
|
|
12484
12484
|
}
|
|
12485
12485
|
function readControlToken() {
|
|
12486
|
-
if (!(0,
|
|
12486
|
+
if (!(0, import_node_fs5.existsSync)(CONTROL_TOKEN_FILE)) return null;
|
|
12487
12487
|
try {
|
|
12488
|
-
const token = (0,
|
|
12488
|
+
const token = (0, import_node_fs5.readFileSync)(CONTROL_TOKEN_FILE, "utf-8").trim();
|
|
12489
12489
|
return token || null;
|
|
12490
12490
|
} catch {
|
|
12491
12491
|
return null;
|
|
@@ -12497,27 +12497,34 @@ function tokensMatch(expected, provided) {
|
|
|
12497
12497
|
const b = Buffer.from(provided);
|
|
12498
12498
|
return a.length === b.length && (0, import_node_crypto.timingSafeEqual)(a, b);
|
|
12499
12499
|
}
|
|
12500
|
-
var import_node_crypto,
|
|
12500
|
+
var import_node_crypto, import_node_fs5, import_node_path5, CONTROL_TOKEN_FILE;
|
|
12501
12501
|
var init_control_token = __esm({
|
|
12502
12502
|
"src/daemon/control-token.ts"() {
|
|
12503
12503
|
"use strict";
|
|
12504
12504
|
import_node_crypto = require("crypto");
|
|
12505
|
-
|
|
12506
|
-
|
|
12505
|
+
import_node_fs5 = require("fs");
|
|
12506
|
+
import_node_path5 = require("path");
|
|
12507
12507
|
init_paths();
|
|
12508
|
-
CONTROL_TOKEN_FILE = (0,
|
|
12508
|
+
CONTROL_TOKEN_FILE = (0, import_node_path5.join)(PATHS.runDir, "control.token");
|
|
12509
12509
|
}
|
|
12510
12510
|
});
|
|
12511
12511
|
|
|
12512
12512
|
// src/core/ipc-client.ts
|
|
12513
|
-
|
|
12513
|
+
function daemonError(error) {
|
|
12514
|
+
if (error?.startsWith("unknown method")) {
|
|
12515
|
+
return new Error(`threatcrushd is older than this CLI (${error}); update it`);
|
|
12516
|
+
}
|
|
12517
|
+
return new Error(error || "ipc error");
|
|
12518
|
+
}
|
|
12519
|
+
var import_node_net, import_node_fs6, REQUEST_TIMEOUT_MS, IpcClient;
|
|
12514
12520
|
var init_ipc_client = __esm({
|
|
12515
12521
|
"src/core/ipc-client.ts"() {
|
|
12516
12522
|
"use strict";
|
|
12517
12523
|
import_node_net = require("net");
|
|
12518
|
-
|
|
12524
|
+
import_node_fs6 = require("fs");
|
|
12519
12525
|
init_paths();
|
|
12520
12526
|
init_control_token();
|
|
12527
|
+
REQUEST_TIMEOUT_MS = 1e4;
|
|
12521
12528
|
IpcClient = class {
|
|
12522
12529
|
constructor(opts = {}) {
|
|
12523
12530
|
this.opts = opts;
|
|
@@ -12530,10 +12537,10 @@ var init_ipc_client = __esm({
|
|
|
12530
12537
|
pending = /* @__PURE__ */ new Map();
|
|
12531
12538
|
socketPath;
|
|
12532
12539
|
static isDaemonRunning(socketPath = resolveClientSocket()) {
|
|
12533
|
-
return (0,
|
|
12540
|
+
return (0, import_node_fs6.existsSync)(socketPath);
|
|
12534
12541
|
}
|
|
12535
12542
|
async connect(timeoutMs = 2e3) {
|
|
12536
|
-
if (!(0,
|
|
12543
|
+
if (!(0, import_node_fs6.existsSync)(this.socketPath)) {
|
|
12537
12544
|
throw new Error(`threatcrushd socket not found at ${this.socketPath}`);
|
|
12538
12545
|
}
|
|
12539
12546
|
return new Promise((resolve5, reject) => {
|
|
@@ -12566,10 +12573,16 @@ var init_ipc_client = __esm({
|
|
|
12566
12573
|
const id = this.nextId++;
|
|
12567
12574
|
const frame = params ? { id, method, params } : { id, method };
|
|
12568
12575
|
return new Promise((resolve5, reject) => {
|
|
12569
|
-
|
|
12576
|
+
const timer = setTimeout(() => {
|
|
12577
|
+
this.pending.delete(id);
|
|
12578
|
+
reject(new Error(
|
|
12579
|
+
`threatcrushd did not answer "${method}" within ${REQUEST_TIMEOUT_MS / 1e3}s; if it is older than this CLI, update it`
|
|
12580
|
+
));
|
|
12581
|
+
}, REQUEST_TIMEOUT_MS);
|
|
12582
|
+
this.pending.set(id, { resolve: resolve5, reject, timer });
|
|
12570
12583
|
this.socket.write(JSON.stringify(frame) + "\n", (err) => {
|
|
12571
|
-
if (err) {
|
|
12572
|
-
|
|
12584
|
+
if (err && this.pending.delete(id)) {
|
|
12585
|
+
clearTimeout(timer);
|
|
12573
12586
|
reject(err);
|
|
12574
12587
|
}
|
|
12575
12588
|
});
|
|
@@ -12629,14 +12642,16 @@ var init_ipc_client = __esm({
|
|
|
12629
12642
|
const pending = this.pending.get(msg.id);
|
|
12630
12643
|
if (!pending) continue;
|
|
12631
12644
|
this.pending.delete(msg.id);
|
|
12645
|
+
clearTimeout(pending.timer);
|
|
12632
12646
|
if (msg.ok) pending.resolve(msg.result);
|
|
12633
|
-
else pending.reject(
|
|
12647
|
+
else pending.reject(daemonError(msg.error));
|
|
12634
12648
|
} catch {
|
|
12635
12649
|
}
|
|
12636
12650
|
}
|
|
12637
12651
|
}
|
|
12638
12652
|
onClose() {
|
|
12639
|
-
for (const { reject } of this.pending.values()) {
|
|
12653
|
+
for (const { reject, timer } of this.pending.values()) {
|
|
12654
|
+
clearTimeout(timer);
|
|
12640
12655
|
reject(new Error("daemon connection closed"));
|
|
12641
12656
|
}
|
|
12642
12657
|
this.pending.clear();
|
|
@@ -15897,12 +15912,12 @@ var source_default = chalk;
|
|
|
15897
15912
|
// src/index.ts
|
|
15898
15913
|
var import_readline = __toESM(require("readline"));
|
|
15899
15914
|
var import_node_child_process13 = require("child_process");
|
|
15900
|
-
var
|
|
15901
|
-
var
|
|
15915
|
+
var import_node_fs34 = require("fs");
|
|
15916
|
+
var import_node_path24 = require("path");
|
|
15902
15917
|
var import_node_os8 = require("os");
|
|
15903
15918
|
|
|
15904
15919
|
// src/commands/monitor.ts
|
|
15905
|
-
var
|
|
15920
|
+
var import_node_fs7 = require("fs");
|
|
15906
15921
|
var import_node_readline = require("readline");
|
|
15907
15922
|
|
|
15908
15923
|
// src/core/version.ts
|
|
@@ -20267,6 +20282,31 @@ var CRS_RULES = [
|
|
|
20267
20282
|
"negated": false
|
|
20268
20283
|
}
|
|
20269
20284
|
},
|
|
20285
|
+
{
|
|
20286
|
+
"id": 941100,
|
|
20287
|
+
"msg": "XSS Attack Detected via libinjection",
|
|
20288
|
+
"severity": "CRITICAL",
|
|
20289
|
+
"tags": [
|
|
20290
|
+
"attack-xss"
|
|
20291
|
+
],
|
|
20292
|
+
"targets": [
|
|
20293
|
+
"REQUEST_HEADERS:User-Agent",
|
|
20294
|
+
"ARGS_NAMES",
|
|
20295
|
+
"ARGS"
|
|
20296
|
+
],
|
|
20297
|
+
"transforms": [
|
|
20298
|
+
"utf8toUnicode",
|
|
20299
|
+
"urlDecodeUni",
|
|
20300
|
+
"htmlEntityDecode",
|
|
20301
|
+
"jsDecode",
|
|
20302
|
+
"cssDecode",
|
|
20303
|
+
"removeNulls"
|
|
20304
|
+
],
|
|
20305
|
+
"op": {
|
|
20306
|
+
"type": "detectXSS",
|
|
20307
|
+
"negated": false
|
|
20308
|
+
}
|
|
20309
|
+
},
|
|
20270
20310
|
{
|
|
20271
20311
|
"id": 941110,
|
|
20272
20312
|
"msg": "XSS Filter - Category 1: Script Tag Vector",
|
|
@@ -20953,6 +20993,30 @@ var CRS_RULES = [
|
|
|
20953
20993
|
"negated": false
|
|
20954
20994
|
}
|
|
20955
20995
|
},
|
|
20996
|
+
{
|
|
20997
|
+
"id": 942100,
|
|
20998
|
+
"msg": "SQL Injection Attack Detected via libinjection",
|
|
20999
|
+
"severity": "CRITICAL",
|
|
21000
|
+
"tags": [
|
|
21001
|
+
"attack-sqli"
|
|
21002
|
+
],
|
|
21003
|
+
"targets": [
|
|
21004
|
+
"REQUEST_HEADERS:User-Agent",
|
|
21005
|
+
"REQUEST_HEADERS:Referer",
|
|
21006
|
+
"ARGS_NAMES",
|
|
21007
|
+
"ARGS"
|
|
21008
|
+
],
|
|
21009
|
+
"transforms": [
|
|
21010
|
+
"utf8toUnicode",
|
|
21011
|
+
"urlDecodeUni",
|
|
21012
|
+
"removeNulls"
|
|
21013
|
+
],
|
|
21014
|
+
"multiMatch": true,
|
|
21015
|
+
"op": {
|
|
21016
|
+
"type": "detectSQLi",
|
|
21017
|
+
"negated": false
|
|
21018
|
+
}
|
|
21019
|
+
},
|
|
20956
21020
|
{
|
|
20957
21021
|
"id": 942140,
|
|
20958
21022
|
"msg": "SQL Injection Attack: Common DB Names Detected",
|
|
@@ -21573,6 +21637,31 @@ var CRS_RULES = [
|
|
|
21573
21637
|
}
|
|
21574
21638
|
}
|
|
21575
21639
|
];
|
|
21640
|
+
var THREATCRUSH_RULES = [
|
|
21641
|
+
{
|
|
21642
|
+
"id": 10001,
|
|
21643
|
+
"msg": "OS File Access Attempt in the request path",
|
|
21644
|
+
"severity": "CRITICAL",
|
|
21645
|
+
"tags": [
|
|
21646
|
+
"attack-lfi",
|
|
21647
|
+
"threatcrush"
|
|
21648
|
+
],
|
|
21649
|
+
"targets": [
|
|
21650
|
+
"REQUEST_FILENAME"
|
|
21651
|
+
],
|
|
21652
|
+
"transforms": [
|
|
21653
|
+
"utf8toUnicode",
|
|
21654
|
+
"urlDecodeUni",
|
|
21655
|
+
"normalizePathWin"
|
|
21656
|
+
],
|
|
21657
|
+
"op": {
|
|
21658
|
+
"type": "rx",
|
|
21659
|
+
"source": "^/?(?:[a-z]:/)?(?:\\.history(?![0-9a-z])|apache/access\\.conf(?![0-9a-z])|apache/apache\\.conf(?![0-9a-z])|apache/apache2\\.conf(?![0-9a-z])|apache/audit_log(?![0-9a-z])|apache/conf(?![0-9a-z])|apache/default-server\\.conf(?![0-9a-z])|apache/error_log(?![0-9a-z])|apache/httpd\\.conf(?![0-9a-z])|apache/log(?![0-9a-z])|apache2/apache\\.conf(?![0-9a-z])|apache2/apache2\\.conf(?![0-9a-z])|apache2/conf(?![0-9a-z])|apache2/default-server\\.conf(?![0-9a-z])|apache2/envvars(?![0-9a-z])|apache2/httpd\\.conf(?![0-9a-z])|apache2/httpd2\\.conf(?![0-9a-z])|apache2/logs(?![0-9a-z])|apache2/mods(?![0-9a-z])|apache2/ports\\.conf(?![0-9a-z])|apache2/sites(?![0-9a-z])|apache2/ssl-global\\.conf(?![0-9a-z])|apache2/vhosts\\.d(?![0-9a-z])|apache22/conf(?![0-9a-z])|apache22/httpd\\.conf(?![0-9a-z])|apache22/logs(?![0-9a-z])|apache24/conf(?![0-9a-z])|apache24/httpd\\.conf(?![0-9a-z])|apache24/logs(?![0-9a-z])|boot/grub/grub\\.cfg(?![0-9a-z])|boot/grub/menu\\.lst(?![0-9a-z])|config/app\\.php(?![0-9a-z])|config/custom\\.php(?![0-9a-z])|config/database\\.php(?![0-9a-z])|configuration\\.php(?![0-9a-z])|cpanel/logs(?![0-9a-z])|data/elasticsearch(?![0-9a-z])|data/kafka(?![0-9a-z])|etc/\\.java(?![0-9a-z])|etc/acpi(?![0-9a-z])|etc/adduser\\.conf(?![0-9a-z])|etc/alias(?![0-9a-z])|etc/alsa(?![0-9a-z])|etc/alternatives(?![0-9a-z])|etc/amavis(?![0-9a-z])|etc/anacrontab(?![0-9a-z])|etc/ansible(?![0-9a-z])|etc/apache/access\\.conf(?![0-9a-z])|etc/apache/apache\\.conf(?![0-9a-z])|etc/apache/default-server\\.conf(?![0-9a-z])|etc/apache/httpd\\.conf(?![0-9a-z])|etc/apache/vhosts\\.conf(?![0-9a-z])|etc/apache2(?![0-9a-z])|etc/apm(?![0-9a-z])|etc/apparmor(?![0-9a-z])|etc/apport(?![0-9a-z])|etc/apt(?![0-9a-z])|etc/asciidoc(?![0-9a-z])|etc/at\\.allow(?![0-9a-z])|etc/at\\.deny(?![0-9a-z])|etc/audit(?![0-9a-z])|etc/avahi(?![0-9a-z])|etc/bash_completion\\.d(?![0-9a-z])|etc/bashrc(?![0-9a-z])|etc/bind(?![0-9a-z])|etc/binfmt\\.d(?![0-9a-z])|etc/bluetooth(?![0-9a-z])|etc/bonobo-activation(?![0-9a-z])|etc/bootptab(?![0-9a-z])|etc/brltty(?![0-9a-z])|etc/byobu(?![0-9a-z])|etc/ca-certificates(?![0-9a-z])|etc/calendar(?![0-9a-z])|etc/casper\\.conf(?![0-9a-z])|etc/centos-release(?![0-9a-z])|etc/chatscripts(?![0-9a-z])|etc/chkrootkit\\.conf(?![0-9a-z])|etc/chromium-browser(?![0-9a-z])|etc/chrootusers(?![0-9a-z])|etc/chttp\\.conf(?![0-9a-z])|etc/clam\\.d(?![0-9a-z])|etc/clamav(?![0-9a-z])|etc/cni(?![0-9a-z])|etc/console-setup(?![0-9a-z])|etc/coraza-waf(?![0-9a-z])|etc/cracklib(?![0-9a-z])|etc/cron\\.allow(?![0-9a-z])|etc/cron\\.d(?![0-9a-z])|etc/cron\\.hourly(?![0-9a-z])|etc/cron\\.monthly(?![0-9a-z])|etc/cron\\.weekly(?![0-9a-z])|etc/cron\\.yearly(?![0-9a-z])|etc/crontab(?![0-9a-z])|etc/crowdsec(?![0-9a-z])|etc/crypttab(?![0-9a-z])|etc/cups(?![0-9a-z])|etc/cvs-cron\\.conf(?![0-9a-z])|etc/cvs-pserver\\.conf(?![0-9a-z])|etc/dbus-1(?![0-9a-z])|etc/dconf(?![0-9a-z])|etc/debconf\\.conf(?![0-9a-z])|etc/debian_version(?![0-9a-z])|etc/default(?![0-9a-z])|etc/deluser\\.conf(?![0-9a-z])|etc/depmod\\.d(?![0-9a-z])|etc/dhcp(?![0-9a-z])|etc/dictionaries-common(?![0-9a-z])|etc/dkms(?![0-9a-z])|etc/dns2tcpd\\.conf(?![0-9a-z])|etc/dnsmasq\\.d(?![0-9a-z])|etc/docker(?![0-9a-z])|etc/dockeretc/dpkg(?![0-9a-z])|etc/dovecot(?![0-9a-z])|etc/e2fsck\\.conf(?![0-9a-z])|etc/elasticsearch(?![0-9a-z])|etc/emacs(?![0-9a-z])|etc/environment\\.d(?![0-9a-z])|etc/esound/esd\\.conf(?![0-9a-z])|etc/etter\\.conf(?![0-9a-z])|etc/exports(?![0-9a-z])|etc/fail2ban(?![0-9a-z])|etc/fedora-release(?![0-9a-z])|etc/firebird(?![0-9a-z])|etc/firefox(?![0-9a-z])|etc/firewall(?![0-9a-z])|etc/fonts(?![0-9a-z])|etc/foremost\\.conf(?![0-9a-z])|etc/freshclam\\.conf(?![0-9a-z])|etc/fstab(?![0-9a-z])|etc/ftpaccess(?![0-9a-z])|etc/ftpchroot(?![0-9a-z])|etc/ftphosts(?![0-9a-z])|etc/ftpusers(?![0-9a-z])|etc/fuse\\.conf(?![0-9a-z])|etc/fwupd(?![0-9a-z])|etc/gconf(?![0-9a-z])|etc/gdb(?![0-9a-z])|etc/gdm3(?![0-9a-z])|etc/geoclue(?![0-9a-z])|etc/ghostscript(?![0-9a-z])|etc/gimp(?![0-9a-z])|etc/gitlab(?![0-9a-z])|etc/glvnd(?![0-9a-z])|etc/gnome(?![0-9a-z])|etc/gnucash(?![0-9a-z])|etc/gnustep(?![0-9a-z])|etc/groff(?![0-9a-z])|etc/group(?![0-9a-z])|etc/grub\\.conf(?![0-9a-z])|etc/grub\\.d(?![0-9a-z])|etc/gshadow(?![0-9a-z])|etc/gss(?![0-9a-z])|etc/gtk-2\\.0(?![0-9a-z])|etc/gtk-3\\.0(?![0-9a-z])|etc/hdparm\\.conf(?![0-9a-z])|etc/host\\.conf(?![0-9a-z])|etc/hostname(?![0-9a-z])|etc/hosts(?![0-9a-z])|etc/hp(?![0-9a-z])|etc/http/conf(?![0-9a-z])|etc/http/httpd\\.conf(?![0-9a-z])|etc/httpd(?![0-9a-z])|etc/ifplugd(?![0-9a-z])|etc/imagemagick-6(?![0-9a-z])|etc/inetd\\.conf(?![0-9a-z])|etc/init(?![0-9a-z])|etc/insserv\\.conf\\.d(?![0-9a-z])|etc/ipfw(?![0-9a-z])|etc/iproute2(?![0-9a-z])|etc/iptables(?![0-9a-z])|etc/issue(?![0-9a-z])|etc/java(?![0-9a-z])|etc/kafka(?![0-9a-z])|etc/kbd/config(?![0-9a-z])|etc/kernel(?![0-9a-z])|etc/kibana(?![0-9a-z])|etc/ld\\.so\\.conf(?![0-9a-z])|etc/ldap(?![0-9a-z])|etc/letsencrypt(?![0-9a-z])|etc/libblockdev(?![0-9a-z])|etc/libibverbs\\.d(?![0-9a-z])|etc/libnl-3(?![0-9a-z])|etc/libpaper\\.d(?![0-9a-z])|etc/libreoffice(?![0-9a-z])|etc/lighttpd(?![0-9a-z])|etc/lilo\\.conf(?![0-9a-z])|etc/logcheck(?![0-9a-z])|etc/login\\.defs(?![0-9a-z])|etc/logrotate\\.conf(?![0-9a-z])|etc/logrotate\\.d(?![0-9a-z])|etc/logstash(?![0-9a-z])|etc/logwatch(?![0-9a-z])|etc/lsb-release(?![0-9a-z])|etc/ltrace\\.conf(?![0-9a-z])|etc/lvm(?![0-9a-z])|etc/lynx(?![0-9a-z])|etc/mail(?![0-9a-z])|etc/mandrake-release(?![0-9a-z])|etc/manpath\\.config(?![0-9a-z])|etc/mc(?![0-9a-z])|etc/menu(?![0-9a-z])|etc/miredo-server\\.conf(?![0-9a-z])|etc/miredo\\.conf(?![0-9a-z])|etc/miredo/miredo-server\\.conf(?![0-9a-z])|etc/miredo/miredo\\.conf(?![0-9a-z])|etc/modprobe\\.d(?![0-9a-z])|etc/modsecurity(?![0-9a-z])|etc/modulesf(?![0-9a-z])|etc/mongod\\.conf(?![0-9a-z])|etc/monit(?![0-9a-z])|etc/mono(?![0-9a-z])|etc/motd(?![0-9a-z])|etc/mplayer(?![0-9a-z])|etc/mpv(?![0-9a-z])|etc/mtab(?![0-9a-z])|etc/mtools\\.conf(?![0-9a-z])|etc/muddleftpd(?![0-9a-z])|etc/muddleftpd\\.com(?![0-9a-z])|etc/muttrc\\.d(?![0-9a-z])|etc/my\\.conf(?![0-9a-z])|etc/mysql(?![0-9a-z])|etc/netplan(?![0-9a-z])|etc/network(?![0-9a-z])|etc/networkmanager(?![0-9a-z])|etc/newsyslog\\.conf(?![0-9a-z])|etc/newt(?![0-9a-z])|etc/nghttpx(?![0-9a-z])|etc/nginx(?![0-9a-z])|etc/nikto(?![0-9a-z])|etc/npasswd(?![0-9a-z])|etc/nsswitch\\.conf(?![0-9a-z])|etc/nuxeo\\.conf(?![0-9a-z])|etc/odbcdatasources(?![0-9a-z])|etc/openal(?![0-9a-z])|etc/opendkim(?![0-9a-z])|etc/opendmarc(?![0-9a-z])|etc/openldap/ldap\\.conf(?![0-9a-z])|etc/openmpi(?![0-9a-z])|etc/opt(?![0-9a-z])|etc/os-release(?![0-9a-z])|etc/osxhttpd(?![0-9a-z])|etc/osync(?![0-9a-z])|etc/packagekit(?![0-9a-z])|etc/pam\\.conf(?![0-9a-z])|etc/pam\\.d(?![0-9a-z])|etc/pam\\.d/proftpd(?![0-9a-z])|etc/passwd(?![0-9a-z])|etc/password(?![0-9a-z])|etc/pcmcia(?![0-9a-z])|etc/perl(?![0-9a-z])|etc/php(?![0-9a-z])|etc/pki(?![0-9a-z])|etc/pm(?![0-9a-z])|etc/polkit-1(?![0-9a-z])|etc/postfix(?![0-9a-z])|etc/postgresql(?![0-9a-z])|etc/ppp(?![0-9a-z])|etc/printcap(?![0-9a-z])|etc/profile(?![0-9a-z])|etc/proftp\\.conf(?![0-9a-z])|etc/proftpd(?![0-9a-z])|etc/pulse(?![0-9a-z])|etc/pure-ftpd(?![0-9a-z])|etc/pureftpd(?![0-9a-z])|etc/python(?![0-9a-z])|etc/qemu(?![0-9a-z])|etc/rc\\.conf(?![0-9a-z])|etc/rc\\.d/rc\\.httpd(?![0-9a-z])|etc/rc0\\.d(?![0-9a-z])|etc/rc1\\.d(?![0-9a-z])|etc/rc2\\.d(?![0-9a-z])|etc/rc3\\.d(?![0-9a-z])|etc/rc4\\.d(?![0-9a-z])|etc/rc5\\.d(?![0-9a-z])|etc/rc6\\.d(?![0-9a-z])|etc/rcs\\.d(?![0-9a-z])|etc/redhat-release(?![0-9a-z])|etc/redis-sentinel\\.conf(?![0-9a-z])|etc/redis\\.conf(?![0-9a-z])|etc/resolv\\.conf(?![0-9a-z])|etc/resolvconf(?![0-9a-z])|etc/rsyslog\\.d(?![0-9a-z])|etc/samba(?![0-9a-z])|etc/sane\\.d(?![0-9a-z])|etc/scw-release(?![0-9a-z])|etc/security(?![0-9a-z])|etc/selinux(?![0-9a-z])|etc/sensors\\.conf(?![0-9a-z])|etc/sensors\\.d(?![0-9a-z])|etc/sensors3\\.conf(?![0-9a-z])|etc/sgml(?![0-9a-z])|etc/shadow(?![0-9a-z])|etc/signon-ui(?![0-9a-z])|etc/skel(?![0-9a-z])|etc/slackware-release(?![0-9a-z])|etc/smb\\.conf(?![0-9a-z])|etc/smbpasswd(?![0-9a-z])|etc/smi\\.conf(?![0-9a-z])|etc/snmp(?![0-9a-z])|etc/sogo(?![0-9a-z])|etc/sound(?![0-9a-z])|etc/spamassassin(?![0-9a-z])|etc/speech-dispatcher(?![0-9a-z])|etc/squid(?![0-9a-z])|etc/squirrelmail(?![0-9a-z])|etc/ssh(?![0-9a-z])|etc/ssl(?![0-9a-z])|etc/sso(?![0-9a-z])|etc/stunnel(?![0-9a-z])|etc/subgid(?![0-9a-z])|etc/subuid(?![0-9a-z])|etc/subversion(?![0-9a-z])|etc/sudoers(?![0-9a-z])|etc/suse-release(?![0-9a-z])|etc/sw-cp-server/applications\\.d(?![0-9a-z])|etc/sysconfig(?![0-9a-z])|etc/sysctl\\.conf(?![0-9a-z])|etc/sysctl\\.d(?![0-9a-z])|etc/syslog\\.conf(?![0-9a-z])|etc/sysstat(?![0-9a-z])|etc/system-release-cpe(?![0-9a-z])|etc/systemd(?![0-9a-z])|etc/termcap(?![0-9a-z])|etc/terminfo(?![0-9a-z])|etc/texmf(?![0-9a-z])|etc/thermald(?![0-9a-z])|etc/thnuclnt(?![0-9a-z])|etc/thunderbird(?![0-9a-z])|etc/timezone(?![0-9a-z])|etc/timidity(?![0-9a-z])|etc/tinyproxy(?![0-9a-z])|etc/tmpfiles\\.d(?![0-9a-z])|etc/tor/tor-tsocks\\.conf(?![0-9a-z])|etc/tsocks\\.conf(?![0-9a-z])|etc/ubuntu-advantage(?![0-9a-z])|etc/udev(?![0-9a-z])|etc/udisks2(?![0-9a-z])|etc/ufw(?![0-9a-z])|etc/unbound(?![0-9a-z])|etc/update-manager(?![0-9a-z])|etc/update-motd\\.d(?![0-9a-z])|etc/update-notifier(?![0-9a-z])|etc/updatedb\\.conf(?![0-9a-z])|etc/upower(?![0-9a-z])|etc/urlview(?![0-9a-z])|etc/usb_modeswitch\\.d(?![0-9a-z])|etc/utmp(?![0-9a-z])|etc/vhcs2/proftpd/proftpd\\.conf(?![0-9a-z])|etc/vim(?![0-9a-z])|etc/vmware(?![0-9a-z])|etc/vsftpd\\.chroot_list(?![0-9a-z])|etc/vsftpd\\.conf(?![0-9a-z])|etc/vsftpd/vsftpd\\.conf(?![0-9a-z])|etc/vulkan(?![0-9a-z])|etc/w3m(?![0-9a-z])|etc/webmin(?![0-9a-z])|etc/wicd(?![0-9a-z])|etc/wireshark(?![0-9a-z])|etc/wpa_supplicant(?![0-9a-z])|etc/wu-ftpd(?![0-9a-z])|etc/x11(?![0-9a-z])|etc/xdg(?![0-9a-z])|etc/xml(?![0-9a-z])|home/postgres(?![0-9a-z])|http/httpd\\.conf(?![0-9a-z])|httpd/conf/httpd\\.conf(?![0-9a-z])|includes/configure\\.php(?![0-9a-z])|inetpub/wwwroot/global\\.asa(?![0-9a-z])|jakarta/dist/tomcat(?![0-9a-z])|jakarta/tomcat/conf(?![0-9a-z])|jakarta/tomcat/logs(?![0-9a-z])|library/webserver/documents(?![0-9a-z])|lighttpd/conf(?![0-9a-z])|lighttpd/lighttpd\\.conf(?![0-9a-z])|lighttpd/log(?![0-9a-z])|localsettings\\.php(?![0-9a-z])|logs/access\\.log(?![0-9a-z])|logs/access_log(?![0-9a-z])|logs/error_log(?![0-9a-z])|logs/pure-ftpd\\.log(?![0-9a-z])|logs/samba\\.log(?![0-9a-z])|logs/security_debug_log(?![0-9a-z])|logs/security_log(?![0-9a-z])|lsws/conf(?![0-9a-z])|lsws/logs(?![0-9a-z])|mysql/bin/my\\.ini(?![0-9a-z])|mysql/data(?![0-9a-z])|mysql/my\\.ini(?![0-9a-z])|nginx/conf/nginx\\.conf(?![0-9a-z])|opt/apache(?![0-9a-z])|opt/apache2(?![0-9a-z])|opt/httpd/apache\\.conf(?![0-9a-z])|opt/httpd/apache2\\.conf(?![0-9a-z])|opt/httpd/conf/|opt/jboss(?![0-9a-z])|opt/lampp(?![0-9a-z])|opt/nuxeo(?![0-9a-z])|opt/tomcat(?![0-9a-z])|opt/xampp(?![0-9a-z])|pgsql/bin/pg_passwd(?![0-9a-z])|pgsql/data(?![0-9a-z])|php/apache\\.conf(?![0-9a-z])|php/apache2\\.conf(?![0-9a-z])|php/httpd\\.conf(?![0-9a-z])|php5/apache\\.conf(?![0-9a-z])|php5/apache2\\.conf(?![0-9a-z])|php5/httpd\\.conf(?![0-9a-z])|postgresql/log/|program files(?![0-9a-z])|psa/admin(?![0-9a-z])|pureftpd/etc(?![0-9a-z])|root/anaconda-ks\\.cfg(?![0-9a-z])|samba/lib(?![0-9a-z])|sb/config(?![0-9a-z])|server/default/conf(?![0-9a-z])|server/default/deploy(?![0-9a-z])|server/default/log(?![0-9a-z])|squirrelmail/www(?![0-9a-z])|system/library/webobjects/adaptors(?![0-9a-z])|system32/config(?![0-9a-z])|system32/inetsrv/config(?![0-9a-z])|tmp/|tmp/access\\.log(?![0-9a-z])|tmp/kafka-logs(?![0-9a-z])|typo3conf/localconf\\.php(?![0-9a-z])|usr/etc/pure-ftpd\\.conf(?![0-9a-z])|usr/home/user/lighttpd(?![0-9a-z])|usr/lib/cron/log(?![0-9a-z])|usr/lib/php(?![0-9a-z])|usr/lib/rpm/rpm\\.log(?![0-9a-z])|usr/lib/security(?![0-9a-z])|usr/local/zeus/web(?![0-9a-z])|usr/pkg/etc/httpd(?![0-9a-z])|usr/pkgsrc/net/pureftpd(?![0-9a-z])|usr/ports/contrib/pure-ftpd(?![0-9a-z])|usr/ports/ftp/pure-ftpd(?![0-9a-z])|usr/sbin/mudlogd(?![0-9a-z])|usr/sbin/mudpasswd(?![0-9a-z])|usr/share/adduser(?![0-9a-z])|usr/share/logs(?![0-9a-z])|usr/share/squirrelmail(?![0-9a-z])|usr/share/tomcat(?![0-9a-z])|usr/spool/lp(?![0-9a-z])|usr/spool/mqueue(?![0-9a-z])|var/adm(?![0-9a-z])|var/apache/logs(?![0-9a-z])|var/apache2/config\\.inc(?![0-9a-z])|var/cpanel(?![0-9a-z])|var/cron/log(?![0-9a-z])|var/data/elasticsearch(?![0-9a-z])|var/data/mysql-bin(?![0-9a-z])|var/htmp(?![0-9a-z])|var/lib/elasticsearch(?![0-9a-z])|var/lib/mysql(?![0-9a-z])|var/lib/pgsql(?![0-9a-z])|var/lib/squirrelmail(?![0-9a-z])|var/lighttpd(?![0-9a-z])|var/local/www/conf(?![0-9a-z])|var/log(?![0-9a-z])|var/lp/logs(?![0-9a-z])|var/mail(?![0-9a-z])|var/mysql-bin(?![0-9a-z])|var/mysql\\.log(?![0-9a-z])|var/nm2/postgresql\\.conf(?![0-9a-z])|var/postgresql(?![0-9a-z])|var/run/utmp(?![0-9a-z])|var/saf/_log(?![0-9a-z])|var/saf/port/log(?![0-9a-z])|var/spool(?![0-9a-z])|var/webmin(?![0-9a-z])|var/www(?![0-9a-z])|volumes/macintosh_hd(?![0-9a-z])|volumes/webbackup(?![0-9a-z])|wamp/bin/apache(?![0-9a-z])|wamp/bin/mysql(?![0-9a-z])|wamp/bin/php(?![0-9a-z])|wamp/logs(?![0-9a-z])|windows/comsetup\\.log(?![0-9a-z])|windows/debug/netsetup\\.log(?![0-9a-z])|windows/odbc\\.ini(?![0-9a-z])|windows/repair/setup\\.log(?![0-9a-z])|windows/setupact\\.log(?![0-9a-z])|windows/setupapi\\.log(?![0-9a-z])|windows/setuperr\\.log(?![0-9a-z])|windows/system32(?![0-9a-z])|windows/syswow64(?![0-9a-z])|windows/updspapi\\.log(?![0-9a-z])|windows/windowsupdate\\.log(?![0-9a-z])|windows/wmsetup\\.log(?![0-9a-z])|winnt/repair(?![0-9a-z])|winnt/system32/logfiles(?![0-9a-z])|wp-cli\\.|www/conf/httpd\\.conf(?![0-9a-z])|www/logs(?![0-9a-z])|xampp/apache/logs(?![0-9a-z])|xampp/filezillaftp(?![0-9a-z])|xampp/htdocs(?![0-9a-z])|xampp/mercurymail(?![0-9a-z])|xampp/mysql/data(?![0-9a-z])|xampp/php(?![0-9a-z])|xampp/sendmail(?![0-9a-z])|xampp/webalizer/webalizer\\.conf(?![0-9a-z]))",
|
|
21660
|
+
"flags": "i",
|
|
21661
|
+
"negated": false
|
|
21662
|
+
}
|
|
21663
|
+
}
|
|
21664
|
+
];
|
|
21576
21665
|
|
|
21577
21666
|
// src/core/crs/transforms.ts
|
|
21578
21667
|
var NBSP = 160;
|
|
@@ -22085,9 +22174,44 @@ var TRANSFORMS = {
|
|
|
22085
22174
|
base64Decode
|
|
22086
22175
|
};
|
|
22087
22176
|
|
|
22177
|
+
// src/core/crs/libinjection.ts
|
|
22178
|
+
var import_node_fs2 = require("fs");
|
|
22179
|
+
var import_node_path2 = require("path");
|
|
22180
|
+
var wasm;
|
|
22181
|
+
function loadLibinjection() {
|
|
22182
|
+
if (!wasm) {
|
|
22183
|
+
const bytes = (0, import_node_fs2.readFileSync)((0, import_node_path2.join)(__dirname, "libinjection", "libinjection.wasm"));
|
|
22184
|
+
wasm = new WebAssembly.Instance(new WebAssembly.Module(bytes), {}).exports;
|
|
22185
|
+
wasm._initialize();
|
|
22186
|
+
}
|
|
22187
|
+
return wasm;
|
|
22188
|
+
}
|
|
22189
|
+
var view;
|
|
22190
|
+
function put(w, bytes) {
|
|
22191
|
+
const ptr = w.tc_input(bytes.length);
|
|
22192
|
+
if (ptr === 0) throw new Error(`libinjection: cannot allocate ${bytes.length} bytes`);
|
|
22193
|
+
if (view?.buffer !== w.memory.buffer) view = Buffer.from(w.memory.buffer);
|
|
22194
|
+
view.write(bytes, ptr, bytes.length, "latin1");
|
|
22195
|
+
}
|
|
22196
|
+
function detectSQLi(bytes) {
|
|
22197
|
+
const w = loadLibinjection();
|
|
22198
|
+
put(w, bytes);
|
|
22199
|
+
const result = w.tc_sqli(bytes.length);
|
|
22200
|
+
if (result !== 1) return { result, fingerprint: "" };
|
|
22201
|
+
const start = w.tc_fingerprint();
|
|
22202
|
+
if (view?.buffer !== w.memory.buffer) view = Buffer.from(w.memory.buffer);
|
|
22203
|
+
return { result, fingerprint: view.toString("latin1", start, view.indexOf(0, start)) };
|
|
22204
|
+
}
|
|
22205
|
+
function detectXSS(bytes) {
|
|
22206
|
+
const w = loadLibinjection();
|
|
22207
|
+
put(w, bytes);
|
|
22208
|
+
return w.tc_xss(bytes.length);
|
|
22209
|
+
}
|
|
22210
|
+
|
|
22088
22211
|
// src/core/crs/engine.ts
|
|
22089
22212
|
var SEVERITY_POINTS = { CRITICAL: 5, ERROR: 4, WARNING: 3, NOTICE: 2 };
|
|
22090
22213
|
var DEFAULT_ANOMALY_THRESHOLD = 5;
|
|
22214
|
+
var DEFAULT_EXCLUDED_RULE_IDS = [941130];
|
|
22091
22215
|
var ATTACK_TYPES = {
|
|
22092
22216
|
"attack-sqli": "sqli",
|
|
22093
22217
|
"attack-xss": "xss",
|
|
@@ -22100,6 +22224,9 @@ var ATTACK_TYPES = {
|
|
|
22100
22224
|
"attack-reputation-scanner": "scanner",
|
|
22101
22225
|
"attack-injection-generic": "injection"
|
|
22102
22226
|
};
|
|
22227
|
+
function crsAttackType(rule) {
|
|
22228
|
+
return rule.tags.map((t) => ATTACK_TYPES[t]).find((t) => t !== void 0) ?? null;
|
|
22229
|
+
}
|
|
22103
22230
|
var PhraseMatcher = class {
|
|
22104
22231
|
next = [/* @__PURE__ */ new Map()];
|
|
22105
22232
|
fail = [0];
|
|
@@ -22179,6 +22306,16 @@ function compileOperator(op) {
|
|
|
22179
22306
|
case "within":
|
|
22180
22307
|
test = (v) => op.arg.includes(v);
|
|
22181
22308
|
break;
|
|
22309
|
+
// ModSecurity v3 counts libinjection's ERROR (parser in an invalid state) as
|
|
22310
|
+
// a match, fail-safe, like TRUE.
|
|
22311
|
+
case "detectSQLi":
|
|
22312
|
+
loadLibinjection();
|
|
22313
|
+
test = (v) => detectSQLi(v).result !== 0;
|
|
22314
|
+
break;
|
|
22315
|
+
case "detectXSS":
|
|
22316
|
+
loadLibinjection();
|
|
22317
|
+
test = (v) => detectXSS(v) !== 0;
|
|
22318
|
+
break;
|
|
22182
22319
|
}
|
|
22183
22320
|
return op.negated ? (v) => !test(v) : test;
|
|
22184
22321
|
}
|
|
@@ -22297,6 +22434,8 @@ var MEMO_ENTRIES = 1e4;
|
|
|
22297
22434
|
var MEMO_MAX_VALUE = 512;
|
|
22298
22435
|
var CrsEngine = class {
|
|
22299
22436
|
threshold;
|
|
22437
|
+
/** How many rules are loaded, by origin: ported OWASP CRS, and ThreatCrush's own. */
|
|
22438
|
+
ruleCounts;
|
|
22300
22439
|
rules;
|
|
22301
22440
|
/** Unchained rules by the targets they read. */
|
|
22302
22441
|
byTarget = /* @__PURE__ */ new Map();
|
|
@@ -22306,14 +22445,17 @@ var CrsEngine = class {
|
|
|
22306
22445
|
memoSize = 0;
|
|
22307
22446
|
constructor(options = {}) {
|
|
22308
22447
|
this.threshold = options.threshold ?? DEFAULT_ANOMALY_THRESHOLD;
|
|
22309
|
-
const excluded = new Set(options.excludeRuleIds ??
|
|
22310
|
-
|
|
22448
|
+
const excluded = new Set(options.excludeRuleIds ?? DEFAULT_EXCLUDED_RULE_IDS);
|
|
22449
|
+
const crs = CRS_RULES.filter((r) => !excluded.has(r.id));
|
|
22450
|
+
const threatcrush = THREATCRUSH_RULES.filter((r) => !excluded.has(r.id));
|
|
22451
|
+
this.ruleCounts = { crs: crs.length, threatcrush: threatcrush.length };
|
|
22452
|
+
this.rules = [...crs, ...threatcrush].map((rule, index) => ({
|
|
22311
22453
|
index,
|
|
22312
22454
|
rule,
|
|
22313
22455
|
test: compileOperator(rule.op),
|
|
22314
22456
|
stepKeys: rule.transforms.map((_, k) => rule.transforms.slice(0, k + 1).join(",")),
|
|
22315
22457
|
chain: (rule.chain ?? []).map((link) => ({ link, test: compileOperator(link.op) })),
|
|
22316
|
-
attackType: rule
|
|
22458
|
+
attackType: crsAttackType(rule)
|
|
22317
22459
|
}));
|
|
22318
22460
|
for (const compiled of this.rules) {
|
|
22319
22461
|
if (compiled.chain.length > 0) {
|
|
@@ -22327,9 +22469,6 @@ var CrsEngine = class {
|
|
|
22327
22469
|
}
|
|
22328
22470
|
}
|
|
22329
22471
|
}
|
|
22330
|
-
get ruleCount() {
|
|
22331
|
-
return this.rules.length;
|
|
22332
|
-
}
|
|
22333
22472
|
slotMatches(target, rules, slot) {
|
|
22334
22473
|
const memoize = slot.value.length <= MEMO_MAX_VALUE;
|
|
22335
22474
|
let memo = this.memo.get(target);
|
|
@@ -22430,20 +22569,36 @@ function parseNginxLog(line) {
|
|
|
22430
22569
|
function parseAuthLog(line) {
|
|
22431
22570
|
const match = line.match(AUTH_REGEX);
|
|
22432
22571
|
if (!match) return null;
|
|
22433
|
-
|
|
22434
|
-
|
|
22572
|
+
return parseAuthMessage(match[2], match[3], parseSyslogTimestamp(match[1]), line);
|
|
22573
|
+
}
|
|
22574
|
+
function parseAuthMessage(process10, message, timestamp, raw = message) {
|
|
22575
|
+
const ipMatch = message.match(IP_REGEX);
|
|
22576
|
+
const userMatch = message.match(INVALID_USER_REGEX) || message.match(USER_REGEX);
|
|
22435
22577
|
return {
|
|
22436
|
-
timestamp
|
|
22437
|
-
raw
|
|
22578
|
+
timestamp,
|
|
22579
|
+
raw,
|
|
22438
22580
|
source: "auth",
|
|
22439
22581
|
fields: {
|
|
22440
|
-
process:
|
|
22441
|
-
message
|
|
22582
|
+
process: process10,
|
|
22583
|
+
message,
|
|
22442
22584
|
ip: ipMatch?.[1],
|
|
22443
22585
|
user: userMatch?.[1]
|
|
22444
22586
|
}
|
|
22445
22587
|
};
|
|
22446
22588
|
}
|
|
22589
|
+
function classifySshAuth(entry) {
|
|
22590
|
+
const { ip, user, message } = entry.fields;
|
|
22591
|
+
if (/failed password/i.test(message)) {
|
|
22592
|
+
return { severity: "high", message: `Failed SSH login for ${user || "unknown"} from ${ip || "unknown"}`, source_ip: ip };
|
|
22593
|
+
}
|
|
22594
|
+
if (/invalid user/i.test(message)) {
|
|
22595
|
+
return { severity: "high", message: `Invalid SSH user: ${user || "unknown"} from ${ip || "unknown"}`, source_ip: ip };
|
|
22596
|
+
}
|
|
22597
|
+
if (/accepted/i.test(message)) {
|
|
22598
|
+
return { severity: "info", message: `SSH login accepted for ${user || "unknown"}`, source_ip: ip };
|
|
22599
|
+
}
|
|
22600
|
+
return null;
|
|
22601
|
+
}
|
|
22447
22602
|
function parseSyslog(line) {
|
|
22448
22603
|
const match = line.match(SYSLOG_REGEX);
|
|
22449
22604
|
if (!match) return null;
|
|
@@ -22461,9 +22616,13 @@ function parseSyslog(line) {
|
|
|
22461
22616
|
var crsEngine;
|
|
22462
22617
|
function configureAttackDetection(section) {
|
|
22463
22618
|
const threshold = section?.anomaly_threshold;
|
|
22619
|
+
const included = Array.isArray(section?.include_rules) ? section.include_rules.map(Number) : [];
|
|
22464
22620
|
crsEngine = new CrsEngine({
|
|
22465
22621
|
threshold: typeof threshold === "number" && threshold > 0 ? threshold : void 0,
|
|
22466
|
-
excludeRuleIds:
|
|
22622
|
+
excludeRuleIds: [
|
|
22623
|
+
...DEFAULT_EXCLUDED_RULE_IDS.filter((id) => !included.includes(id)),
|
|
22624
|
+
...Array.isArray(section?.exclude_rules) ? section.exclude_rules.map(Number) : []
|
|
22625
|
+
]
|
|
22467
22626
|
});
|
|
22468
22627
|
}
|
|
22469
22628
|
function engine() {
|
|
@@ -22518,8 +22677,8 @@ function parseSyslogTimestamp(s) {
|
|
|
22518
22677
|
}
|
|
22519
22678
|
|
|
22520
22679
|
// src/core/config.ts
|
|
22521
|
-
var
|
|
22522
|
-
var
|
|
22680
|
+
var import_node_fs3 = require("fs");
|
|
22681
|
+
var import_node_path3 = require("path");
|
|
22523
22682
|
var import_toml = __toESM(require_toml());
|
|
22524
22683
|
var DEFAULT_CONFIG_PATH = "/etc/threatcrush/threatcrushd.conf";
|
|
22525
22684
|
var DEFAULT_CONFDIR = "/etc/threatcrush/threatcrushd.conf.d";
|
|
@@ -22545,11 +22704,11 @@ var DEFAULT_CONFIG = {
|
|
|
22545
22704
|
};
|
|
22546
22705
|
function loadConfig(configPath) {
|
|
22547
22706
|
const path = configPath || DEFAULT_CONFIG_PATH;
|
|
22548
|
-
if (!(0,
|
|
22707
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
22549
22708
|
return { ...DEFAULT_CONFIG };
|
|
22550
22709
|
}
|
|
22551
22710
|
try {
|
|
22552
|
-
const raw = (0,
|
|
22711
|
+
const raw = (0, import_node_fs3.readFileSync)(path, "utf-8");
|
|
22553
22712
|
const parsed = import_toml.default.parse(raw);
|
|
22554
22713
|
return {
|
|
22555
22714
|
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
@@ -22567,13 +22726,13 @@ function loadConfig(configPath) {
|
|
|
22567
22726
|
function loadModuleConfigs(confDir) {
|
|
22568
22727
|
const dir = confDir || DEFAULT_CONFDIR;
|
|
22569
22728
|
const configs = /* @__PURE__ */ new Map();
|
|
22570
|
-
if (!(0,
|
|
22729
|
+
if (!(0, import_node_fs3.existsSync)(dir)) {
|
|
22571
22730
|
return configs;
|
|
22572
22731
|
}
|
|
22573
|
-
const files = (0,
|
|
22732
|
+
const files = (0, import_node_fs3.readdirSync)(dir).filter((f) => f.endsWith(".conf"));
|
|
22574
22733
|
for (const file of files) {
|
|
22575
22734
|
try {
|
|
22576
|
-
const raw = (0,
|
|
22735
|
+
const raw = (0, import_node_fs3.readFileSync)((0, import_node_path3.join)(dir, file), "utf-8");
|
|
22577
22736
|
const parsed = import_toml.default.parse(raw);
|
|
22578
22737
|
for (const [name, config] of Object.entries(parsed)) {
|
|
22579
22738
|
configs.set(name, config);
|
|
@@ -22776,9 +22935,9 @@ async function monitorCommand(options) {
|
|
|
22776
22935
|
const unreadable = [];
|
|
22777
22936
|
for (const s of LOG_SOURCES) {
|
|
22778
22937
|
if (moduleFilter && !moduleFilter.includes(s.name)) continue;
|
|
22779
|
-
if (!(0,
|
|
22938
|
+
if (!(0, import_node_fs7.existsSync)(s.path)) continue;
|
|
22780
22939
|
try {
|
|
22781
|
-
(0,
|
|
22940
|
+
(0, import_node_fs7.accessSync)(s.path, import_node_fs7.constants.R_OK);
|
|
22782
22941
|
availableSources.push(s);
|
|
22783
22942
|
} catch {
|
|
22784
22943
|
unreadable.push(s);
|
|
@@ -22795,11 +22954,11 @@ async function monitorCommand(options) {
|
|
|
22795
22954
|
logger.warn("No readable log files found to monitor.");
|
|
22796
22955
|
logger.info("Available log paths checked:");
|
|
22797
22956
|
for (const s of LOG_SOURCES) {
|
|
22798
|
-
const exists = (0,
|
|
22957
|
+
const exists = (0, import_node_fs7.existsSync)(s.path);
|
|
22799
22958
|
let readable = false;
|
|
22800
22959
|
if (exists) {
|
|
22801
22960
|
try {
|
|
22802
|
-
(0,
|
|
22961
|
+
(0, import_node_fs7.accessSync)(s.path, import_node_fs7.constants.R_OK);
|
|
22803
22962
|
readable = true;
|
|
22804
22963
|
} catch {
|
|
22805
22964
|
readable = false;
|
|
@@ -22832,16 +22991,16 @@ async function monitorCommand(options) {
|
|
|
22832
22991
|
}
|
|
22833
22992
|
function tailLog(source) {
|
|
22834
22993
|
const { path, name, category } = source;
|
|
22835
|
-
const stat = (0,
|
|
22994
|
+
const stat = (0, import_node_fs7.statSync)(path);
|
|
22836
22995
|
let position = stat.size;
|
|
22837
22996
|
const checkForNewData = () => {
|
|
22838
22997
|
try {
|
|
22839
|
-
const currentStat = (0,
|
|
22998
|
+
const currentStat = (0, import_node_fs7.statSync)(path);
|
|
22840
22999
|
if (currentStat.size <= position) {
|
|
22841
23000
|
if (currentStat.size < position) position = 0;
|
|
22842
23001
|
return;
|
|
22843
23002
|
}
|
|
22844
|
-
const stream = (0,
|
|
23003
|
+
const stream = (0, import_node_fs7.createReadStream)(path, { start: position, encoding: "utf-8" });
|
|
22845
23004
|
stream.on("error", (err) => {
|
|
22846
23005
|
logger.warn(`stopped tailing ${path}: ${err.code || err.message}`);
|
|
22847
23006
|
position = currentStat.size;
|
|
@@ -22958,8 +23117,8 @@ async function runDemoMode() {
|
|
|
22958
23117
|
}
|
|
22959
23118
|
|
|
22960
23119
|
// src/commands/scan.ts
|
|
22961
|
-
var
|
|
22962
|
-
var
|
|
23120
|
+
var import_node_fs10 = require("fs");
|
|
23121
|
+
var import_node_path9 = require("path");
|
|
22963
23122
|
|
|
22964
23123
|
// ../../node_modules/.pnpm/ora@8.2.0/node_modules/ora/index.js
|
|
22965
23124
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
@@ -26873,8 +27032,8 @@ function meetsFailThreshold(findings, threshold) {
|
|
|
26873
27032
|
}
|
|
26874
27033
|
|
|
26875
27034
|
// ../../packages/scan/src/node/walk.ts
|
|
26876
|
-
var
|
|
26877
|
-
var
|
|
27035
|
+
var import_node_fs8 = require("fs");
|
|
27036
|
+
var import_node_path6 = require("path");
|
|
26878
27037
|
function compileExcludes(patterns) {
|
|
26879
27038
|
const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
|
|
26880
27039
|
if (matchers.length === 0) return () => false;
|
|
@@ -26945,7 +27104,7 @@ function matchPrefix(parts, segs) {
|
|
|
26945
27104
|
}
|
|
26946
27105
|
function readIgnoreFile(root) {
|
|
26947
27106
|
try {
|
|
26948
|
-
return (0,
|
|
27107
|
+
return (0, import_node_fs8.readFileSync)((0, import_node_path6.join)(root, ".threatcrushignore"), "utf-8").split("\n");
|
|
26949
27108
|
} catch {
|
|
26950
27109
|
return [];
|
|
26951
27110
|
}
|
|
@@ -26961,16 +27120,16 @@ function scanPath(targetPath, options = {}) {
|
|
|
26961
27120
|
let excluded = 0;
|
|
26962
27121
|
const rootIsDirectory = (() => {
|
|
26963
27122
|
try {
|
|
26964
|
-
return (0,
|
|
27123
|
+
return (0, import_node_fs8.statSync)(targetPath).isDirectory();
|
|
26965
27124
|
} catch {
|
|
26966
27125
|
return true;
|
|
26967
27126
|
}
|
|
26968
27127
|
})();
|
|
26969
|
-
const walkRoot = rootIsDirectory ? targetPath : (0,
|
|
27128
|
+
const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path6.dirname)(targetPath);
|
|
26970
27129
|
const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
|
|
26971
27130
|
const scanFile = (fullPath, filename) => {
|
|
26972
27131
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
26973
|
-
const extension = (0,
|
|
27132
|
+
const extension = (0, import_node_path6.extname)(filename).toLowerCase();
|
|
26974
27133
|
const isManifest = filename === "package.json" || filename === "requirements.txt";
|
|
26975
27134
|
const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
|
|
26976
27135
|
const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
|
|
@@ -26982,26 +27141,26 @@ function scanPath(targetPath, options = {}) {
|
|
|
26982
27141
|
let handle;
|
|
26983
27142
|
let declared = null;
|
|
26984
27143
|
try {
|
|
26985
|
-
handle = (0,
|
|
27144
|
+
handle = (0, import_node_fs8.openSync)(fullPath, "r");
|
|
26986
27145
|
} catch {
|
|
26987
27146
|
unreadable.push(relativePath);
|
|
26988
27147
|
return;
|
|
26989
27148
|
}
|
|
26990
27149
|
try {
|
|
26991
|
-
if ((0,
|
|
27150
|
+
if ((0, import_node_fs8.fstatSync)(handle).size > maxFileBytes) return;
|
|
26992
27151
|
if (mayDeclareInterpreter) {
|
|
26993
27152
|
const prefix = Buffer.alloc(128);
|
|
26994
|
-
const read = (0,
|
|
27153
|
+
const read = (0, import_node_fs8.readSync)(handle, prefix, 0, prefix.length, 0);
|
|
26995
27154
|
declared = languageOfShebang(prefix.subarray(0, read).toString("utf-8").split("\n", 1)[0] ?? "");
|
|
26996
27155
|
if (!declared) return;
|
|
26997
27156
|
}
|
|
26998
|
-
text = (0,
|
|
27157
|
+
text = (0, import_node_fs8.readFileSync)(handle, "utf-8");
|
|
26999
27158
|
} catch {
|
|
27000
27159
|
unreadable.push(relativePath);
|
|
27001
27160
|
return;
|
|
27002
27161
|
} finally {
|
|
27003
27162
|
try {
|
|
27004
|
-
(0,
|
|
27163
|
+
(0, import_node_fs8.closeSync)(handle);
|
|
27005
27164
|
} catch {
|
|
27006
27165
|
}
|
|
27007
27166
|
}
|
|
@@ -27019,13 +27178,13 @@ function scanPath(targetPath, options = {}) {
|
|
|
27019
27178
|
const walk = (currentPath) => {
|
|
27020
27179
|
let entries;
|
|
27021
27180
|
try {
|
|
27022
|
-
entries = (0,
|
|
27181
|
+
entries = (0, import_node_fs8.readdirSync)(currentPath, { withFileTypes: true });
|
|
27023
27182
|
} catch {
|
|
27024
27183
|
unreadable.push(toRelative(walkRoot, currentPath));
|
|
27025
27184
|
return;
|
|
27026
27185
|
}
|
|
27027
27186
|
for (const entry of entries) {
|
|
27028
|
-
const fullPath = (0,
|
|
27187
|
+
const fullPath = (0, import_node_path6.join)(currentPath, entry.name);
|
|
27029
27188
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
27030
27189
|
if (entry.isDirectory()) {
|
|
27031
27190
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
@@ -27049,7 +27208,7 @@ function scanPath(targetPath, options = {}) {
|
|
|
27049
27208
|
} else if (isExcluded(toRelative(walkRoot, targetPath))) {
|
|
27050
27209
|
excluded += 1;
|
|
27051
27210
|
} else {
|
|
27052
|
-
scanFile(targetPath, (0,
|
|
27211
|
+
scanFile(targetPath, (0, import_node_path6.basename)(targetPath));
|
|
27053
27212
|
}
|
|
27054
27213
|
if (options.missingControls) findings.push(...controls.findings());
|
|
27055
27214
|
const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
|
|
@@ -27081,22 +27240,22 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
|
|
|
27081
27240
|
}
|
|
27082
27241
|
}
|
|
27083
27242
|
function toRelative(base, target) {
|
|
27084
|
-
const rel = (0,
|
|
27085
|
-
return (rel === "" ? target : rel).split(
|
|
27243
|
+
const rel = (0, import_node_path6.relative)(base, target);
|
|
27244
|
+
return (rel === "" ? target : rel).split(import_node_path6.sep).join("/");
|
|
27086
27245
|
}
|
|
27087
27246
|
|
|
27088
27247
|
// ../../packages/scan/src/node/dependencies.ts
|
|
27089
|
-
var
|
|
27090
|
-
var
|
|
27248
|
+
var import_node_fs9 = require("fs");
|
|
27249
|
+
var import_node_path7 = require("path");
|
|
27091
27250
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
27092
27251
|
async function scanDependencies(targetPath) {
|
|
27093
27252
|
const findings = [];
|
|
27094
27253
|
for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
|
|
27095
|
-
const lockPath = (0,
|
|
27096
|
-
if (!(0,
|
|
27254
|
+
const lockPath = (0, import_node_path7.join)(targetPath, file);
|
|
27255
|
+
if (!(0, import_node_fs9.existsSync)(lockPath)) continue;
|
|
27097
27256
|
let deps;
|
|
27098
27257
|
try {
|
|
27099
|
-
deps = dedupe(parse2((0,
|
|
27258
|
+
deps = dedupe(parse2((0, import_node_fs9.readFileSync)(lockPath, "utf-8")));
|
|
27100
27259
|
} catch {
|
|
27101
27260
|
continue;
|
|
27102
27261
|
}
|
|
@@ -27311,7 +27470,7 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
27311
27470
|
|
|
27312
27471
|
// ../../packages/scan/src/node/sarif.ts
|
|
27313
27472
|
var import_node_crypto2 = require("crypto");
|
|
27314
|
-
var
|
|
27473
|
+
var import_node_path8 = require("path");
|
|
27315
27474
|
var FINGERPRINT_KEY = "threatcrush/contentHash/v1";
|
|
27316
27475
|
function fingerprintOf(finding) {
|
|
27317
27476
|
const content = finding.excerpt.replace(/\s+/g, " ").trim();
|
|
@@ -27349,11 +27508,11 @@ function securitySeverity(severity) {
|
|
|
27349
27508
|
}
|
|
27350
27509
|
}
|
|
27351
27510
|
function toArtifactUri(filePath, base, prefix = "", root = base) {
|
|
27352
|
-
const absolute = (0,
|
|
27353
|
-
const relativePath = (0,
|
|
27511
|
+
const absolute = (0, import_node_path8.isAbsolute)(filePath) ? filePath : (0, import_node_path8.resolve)(root, filePath);
|
|
27512
|
+
const relativePath = (0, import_node_path8.relative)(base, absolute);
|
|
27354
27513
|
const escapedOut = relativePath.startsWith("..") || relativePath === "";
|
|
27355
27514
|
const chosen = escapedOut ? absolute : relativePath;
|
|
27356
|
-
const posix = chosen.split(
|
|
27515
|
+
const posix = chosen.split(import_node_path8.sep).join("/").replace(/^\.\//, "");
|
|
27357
27516
|
if (!prefix || escapedOut) return posix;
|
|
27358
27517
|
const trimmed = prefix.replace(/^\/+|\/+$/g, "");
|
|
27359
27518
|
return trimmed ? `${trimmed}/${posix}` : posix;
|
|
@@ -27443,11 +27602,11 @@ ${finding.consequence}` : `**${finding.title}**`
|
|
|
27443
27602
|
// src/commands/scan.ts
|
|
27444
27603
|
function readVersion() {
|
|
27445
27604
|
for (const candidate of [
|
|
27446
|
-
(0,
|
|
27447
|
-
(0,
|
|
27605
|
+
(0, import_node_path9.join)(__dirname, "..", "package.json"),
|
|
27606
|
+
(0, import_node_path9.join)(__dirname, "..", "..", "package.json")
|
|
27448
27607
|
]) {
|
|
27449
27608
|
try {
|
|
27450
|
-
return JSON.parse((0,
|
|
27609
|
+
return JSON.parse((0, import_node_fs10.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
|
|
27451
27610
|
} catch {
|
|
27452
27611
|
}
|
|
27453
27612
|
}
|
|
@@ -27514,7 +27673,7 @@ async function scanCommand(targetPath, options = {}) {
|
|
|
27514
27673
|
const say = machineReadable ? (line) => process.stderr.write(`${line}
|
|
27515
27674
|
`) : (line) => process.stdout.write(`${line}
|
|
27516
27675
|
`);
|
|
27517
|
-
if (!(0,
|
|
27676
|
+
if (!(0, import_node_fs10.existsSync)(targetPath)) {
|
|
27518
27677
|
say(source_default.red(`Scan target does not exist: ${targetPath}`));
|
|
27519
27678
|
process.exitCode = 2;
|
|
27520
27679
|
return failedResult(targetPath, `no such path: ${targetPath}`);
|
|
@@ -27610,7 +27769,7 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
27610
27769
|
// and it fails silently. `--path-prefix` covers the remaining case:
|
|
27611
27770
|
// a scan run from inside the subdirectory it is scanning.
|
|
27612
27771
|
base: process.cwd(),
|
|
27613
|
-
root: (0,
|
|
27772
|
+
root: (0, import_node_path9.resolve)(outcome.root)
|
|
27614
27773
|
}) : {
|
|
27615
27774
|
tool: "threatcrush",
|
|
27616
27775
|
version: PKG_VERSION2,
|
|
@@ -27624,8 +27783,8 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
27624
27783
|
const serialized = `${JSON.stringify(payload, null, 2)}
|
|
27625
27784
|
`;
|
|
27626
27785
|
if (options.output) {
|
|
27627
|
-
(0,
|
|
27628
|
-
(0,
|
|
27786
|
+
(0, import_node_fs10.mkdirSync)((0, import_node_path9.dirname)((0, import_node_path9.resolve)(options.output)), { recursive: true });
|
|
27787
|
+
(0, import_node_fs10.writeFileSync)(options.output, serialized, "utf-8");
|
|
27629
27788
|
say(
|
|
27630
27789
|
source_default.gray(
|
|
27631
27790
|
` ${format.toUpperCase()} written to ${options.output} (${outcome.findings.length} finding(s))`
|
|
@@ -27677,28 +27836,28 @@ function printHuman(outcome) {
|
|
|
27677
27836
|
}
|
|
27678
27837
|
|
|
27679
27838
|
// src/commands/init.ts
|
|
27680
|
-
var
|
|
27839
|
+
var import_node_fs12 = require("fs");
|
|
27681
27840
|
var import_node_child_process = require("child_process");
|
|
27682
27841
|
var import_node_readline3 = __toESM(require("readline"));
|
|
27683
27842
|
|
|
27684
27843
|
// src/core/cli-config.ts
|
|
27685
|
-
var
|
|
27686
|
-
var
|
|
27844
|
+
var import_node_fs11 = require("fs");
|
|
27845
|
+
var import_node_path10 = require("path");
|
|
27687
27846
|
var import_node_os4 = require("os");
|
|
27688
|
-
var CLI_CONFIG_DIR = (0,
|
|
27689
|
-
var CLI_CONFIG_PATH = (0,
|
|
27847
|
+
var CLI_CONFIG_DIR = (0, import_node_path10.join)((0, import_node_os4.homedir)(), ".threatcrush");
|
|
27848
|
+
var CLI_CONFIG_PATH = (0, import_node_path10.join)(CLI_CONFIG_DIR, "config.json");
|
|
27690
27849
|
function readCliConfig() {
|
|
27691
27850
|
try {
|
|
27692
|
-
return JSON.parse((0,
|
|
27851
|
+
return JSON.parse((0, import_node_fs11.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
|
|
27693
27852
|
} catch {
|
|
27694
27853
|
return {};
|
|
27695
27854
|
}
|
|
27696
27855
|
}
|
|
27697
27856
|
function writeCliConfig(config) {
|
|
27698
|
-
if (!(0,
|
|
27699
|
-
(0,
|
|
27857
|
+
if (!(0, import_node_fs11.existsSync)(CLI_CONFIG_DIR)) (0, import_node_fs11.mkdirSync)(CLI_CONFIG_DIR, { recursive: true });
|
|
27858
|
+
(0, import_node_fs11.writeFileSync)(CLI_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
27700
27859
|
try {
|
|
27701
|
-
(0,
|
|
27860
|
+
(0, import_node_fs11.chmodSync)(CLI_CONFIG_PATH, 384);
|
|
27702
27861
|
} catch {
|
|
27703
27862
|
}
|
|
27704
27863
|
}
|
|
@@ -27943,7 +28102,7 @@ function binaryExists(name) {
|
|
|
27943
28102
|
}
|
|
27944
28103
|
}
|
|
27945
28104
|
function findLogPath(paths) {
|
|
27946
|
-
return paths.find((p) => (0,
|
|
28105
|
+
return paths.find((p) => (0, import_node_fs12.existsSync)(p));
|
|
27947
28106
|
}
|
|
27948
28107
|
async function promptYesNo(question, fallback2) {
|
|
27949
28108
|
const rl = import_node_readline3.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -28059,11 +28218,11 @@ async function initCommand() {
|
|
|
28059
28218
|
}
|
|
28060
28219
|
} else {
|
|
28061
28220
|
const spinner2 = ora({ text: "Writing configuration files...", color: "green" }).start();
|
|
28062
|
-
(0,
|
|
28063
|
-
(0,
|
|
28064
|
-
(0,
|
|
28221
|
+
(0, import_node_fs12.mkdirSync)(confDDir, { recursive: true });
|
|
28222
|
+
(0, import_node_fs12.mkdirSync)("/var/log/threatcrush", { recursive: true });
|
|
28223
|
+
(0, import_node_fs12.mkdirSync)("/var/lib/threatcrush", { recursive: true });
|
|
28065
28224
|
const mainConfig = generateDefaultConfig(detected.map((d) => d.name));
|
|
28066
|
-
(0,
|
|
28225
|
+
(0, import_node_fs12.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
|
|
28067
28226
|
for (const svc of detected) {
|
|
28068
28227
|
const svcDef = SERVICES_TO_DETECT.find((s) => s.name === svc.name);
|
|
28069
28228
|
if (!svcDef) continue;
|
|
@@ -28072,7 +28231,7 @@ async function initCommand() {
|
|
|
28072
28231
|
...svcDef.moduleConfig,
|
|
28073
28232
|
log_path: svc.logPath || svcDef.logPaths[0]
|
|
28074
28233
|
});
|
|
28075
|
-
(0,
|
|
28234
|
+
(0, import_node_fs12.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
|
|
28076
28235
|
}
|
|
28077
28236
|
spinner2.succeed("Configuration written successfully");
|
|
28078
28237
|
console.log();
|
|
@@ -28090,8 +28249,8 @@ async function initCommand() {
|
|
|
28090
28249
|
}
|
|
28091
28250
|
function checkWriteAccess(dir) {
|
|
28092
28251
|
try {
|
|
28093
|
-
if (!(0,
|
|
28094
|
-
(0,
|
|
28252
|
+
if (!(0, import_node_fs12.existsSync)(dir)) {
|
|
28253
|
+
(0, import_node_fs12.mkdirSync)(dir, { recursive: true });
|
|
28095
28254
|
}
|
|
28096
28255
|
return true;
|
|
28097
28256
|
} catch {
|
|
@@ -28100,8 +28259,8 @@ function checkWriteAccess(dir) {
|
|
|
28100
28259
|
}
|
|
28101
28260
|
|
|
28102
28261
|
// src/core/module-loader.ts
|
|
28103
|
-
var
|
|
28104
|
-
var
|
|
28262
|
+
var import_node_fs13 = require("fs");
|
|
28263
|
+
var import_node_path11 = require("path");
|
|
28105
28264
|
var import_toml2 = __toESM(require_toml());
|
|
28106
28265
|
init_paths();
|
|
28107
28266
|
function discoverModules(moduleDir, confDir) {
|
|
@@ -28109,22 +28268,22 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28109
28268
|
const configs = loadModuleConfigs(confDir || PATHS.confD);
|
|
28110
28269
|
const searchPaths = [
|
|
28111
28270
|
moduleDir || PATHS.moduleDir,
|
|
28112
|
-
(0,
|
|
28271
|
+
(0, import_node_path11.resolve)(process.cwd(), "modules")
|
|
28113
28272
|
];
|
|
28114
|
-
const builtinDir = (0,
|
|
28115
|
-
if ((0,
|
|
28273
|
+
const builtinDir = (0, import_node_path11.resolve)(__dirname || ".", "..", "modules");
|
|
28274
|
+
if ((0, import_node_fs13.existsSync)(builtinDir)) {
|
|
28116
28275
|
searchPaths.push(builtinDir);
|
|
28117
28276
|
}
|
|
28118
28277
|
for (const basePath of searchPaths) {
|
|
28119
|
-
if (!(0,
|
|
28120
|
-
const entries = (0,
|
|
28278
|
+
if (!(0, import_node_fs13.existsSync)(basePath)) continue;
|
|
28279
|
+
const entries = (0, import_node_fs13.readdirSync)(basePath, { withFileTypes: true });
|
|
28121
28280
|
for (const entry of entries) {
|
|
28122
28281
|
if (!entry.isDirectory()) continue;
|
|
28123
|
-
const modPath = (0,
|
|
28124
|
-
const manifestPath = (0,
|
|
28125
|
-
if (!(0,
|
|
28282
|
+
const modPath = (0, import_node_path11.join)(basePath, entry.name);
|
|
28283
|
+
const manifestPath = (0, import_node_path11.join)(modPath, "mod.toml");
|
|
28284
|
+
if (!(0, import_node_fs13.existsSync)(manifestPath)) continue;
|
|
28126
28285
|
try {
|
|
28127
|
-
const raw = (0,
|
|
28286
|
+
const raw = (0, import_node_fs13.readFileSync)(manifestPath, "utf-8");
|
|
28128
28287
|
const manifest = import_toml2.default.parse(raw);
|
|
28129
28288
|
const config = configs.get(manifest.module.name) || { enabled: true };
|
|
28130
28289
|
modules.push({
|
|
@@ -28150,21 +28309,21 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28150
28309
|
init_ipc_client();
|
|
28151
28310
|
|
|
28152
28311
|
// src/daemon/pidfile.ts
|
|
28153
|
-
var
|
|
28312
|
+
var import_node_fs14 = require("fs");
|
|
28154
28313
|
init_paths();
|
|
28155
28314
|
function writePidFile() {
|
|
28156
28315
|
ensureRuntimeDirs();
|
|
28157
|
-
(0,
|
|
28316
|
+
(0, import_node_fs14.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
|
|
28158
28317
|
}
|
|
28159
28318
|
function readPidFile() {
|
|
28160
|
-
if (!(0,
|
|
28161
|
-
const raw = (0,
|
|
28319
|
+
if (!(0, import_node_fs14.existsSync)(PATHS.pidFile)) return null;
|
|
28320
|
+
const raw = (0, import_node_fs14.readFileSync)(PATHS.pidFile, "utf-8").trim();
|
|
28162
28321
|
const pid = parseInt(raw, 10);
|
|
28163
28322
|
return Number.isFinite(pid) ? pid : null;
|
|
28164
28323
|
}
|
|
28165
28324
|
function removePidFile() {
|
|
28166
28325
|
try {
|
|
28167
|
-
if ((0,
|
|
28326
|
+
if ((0, import_node_fs14.existsSync)(PATHS.pidFile)) (0, import_node_fs14.unlinkSync)(PATHS.pidFile);
|
|
28168
28327
|
} catch {
|
|
28169
28328
|
}
|
|
28170
28329
|
}
|
|
@@ -28276,24 +28435,24 @@ function formatUptime2(seconds) {
|
|
|
28276
28435
|
|
|
28277
28436
|
// src/commands/modules.ts
|
|
28278
28437
|
var import_node_child_process2 = require("child_process");
|
|
28279
|
-
var
|
|
28280
|
-
var
|
|
28438
|
+
var import_node_fs16 = require("fs");
|
|
28439
|
+
var import_node_path13 = require("path");
|
|
28281
28440
|
var import_toml3 = __toESM(require_toml());
|
|
28282
28441
|
init_paths();
|
|
28283
28442
|
|
|
28284
28443
|
// src/daemon/module-trust.ts
|
|
28285
28444
|
var import_node_crypto3 = require("crypto");
|
|
28286
|
-
var
|
|
28287
|
-
var
|
|
28445
|
+
var import_node_fs15 = require("fs");
|
|
28446
|
+
var import_node_path12 = require("path");
|
|
28288
28447
|
init_paths();
|
|
28289
|
-
var TRUST_FILE = (0,
|
|
28290
|
-
var PUBLISHER_KEYS_FILE = (0,
|
|
28448
|
+
var TRUST_FILE = (0, import_node_path12.join)(PATHS.configDir, "trusted-modules.json");
|
|
28449
|
+
var PUBLISHER_KEYS_FILE = (0, import_node_path12.join)(PATHS.configDir, "publisher-keys.json");
|
|
28291
28450
|
var DIGEST_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".git"]);
|
|
28292
28451
|
function collectFiles(root, dir = root, out = []) {
|
|
28293
|
-
for (const entry of (0,
|
|
28452
|
+
for (const entry of (0, import_node_fs15.readdirSync)(dir, { withFileTypes: true }).sort(
|
|
28294
28453
|
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
28295
28454
|
)) {
|
|
28296
|
-
const full = (0,
|
|
28455
|
+
const full = (0, import_node_path12.join)(dir, entry.name);
|
|
28297
28456
|
if (entry.isSymbolicLink()) {
|
|
28298
28457
|
out.push({ path: full, isSymlink: true });
|
|
28299
28458
|
} else if (entry.isDirectory()) {
|
|
@@ -28308,24 +28467,24 @@ function collectFiles(root, dir = root, out = []) {
|
|
|
28308
28467
|
function computeModuleDigest(modulePath) {
|
|
28309
28468
|
const hash = (0, import_node_crypto3.createHash)("sha256");
|
|
28310
28469
|
for (const entry of collectFiles(modulePath)) {
|
|
28311
|
-
const relPath = (0,
|
|
28470
|
+
const relPath = (0, import_node_path12.relative)(modulePath, entry.path).split(import_node_path12.sep).join("/");
|
|
28312
28471
|
hash.update(relPath);
|
|
28313
28472
|
hash.update("\0");
|
|
28314
28473
|
if (entry.isSymlink) {
|
|
28315
28474
|
hash.update("symlink:");
|
|
28316
|
-
hash.update((0,
|
|
28475
|
+
hash.update((0, import_node_fs15.readlinkSync)(entry.path));
|
|
28317
28476
|
} else {
|
|
28318
28477
|
hash.update("file:");
|
|
28319
|
-
hash.update((0,
|
|
28478
|
+
hash.update((0, import_node_fs15.readFileSync)(entry.path));
|
|
28320
28479
|
}
|
|
28321
28480
|
hash.update("\0");
|
|
28322
28481
|
}
|
|
28323
28482
|
return hash.digest("hex");
|
|
28324
28483
|
}
|
|
28325
28484
|
function readTrustFile() {
|
|
28326
|
-
if (!(0,
|
|
28485
|
+
if (!(0, import_node_fs15.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
|
|
28327
28486
|
try {
|
|
28328
|
-
const parsed = JSON.parse((0,
|
|
28487
|
+
const parsed = JSON.parse((0, import_node_fs15.readFileSync)(TRUST_FILE, "utf-8"));
|
|
28329
28488
|
if (parsed.version !== 1 || typeof parsed.modules !== "object" || !parsed.modules) {
|
|
28330
28489
|
return { version: 1, modules: {} };
|
|
28331
28490
|
}
|
|
@@ -28335,9 +28494,9 @@ function readTrustFile() {
|
|
|
28335
28494
|
}
|
|
28336
28495
|
}
|
|
28337
28496
|
function writeTrustFile(file) {
|
|
28338
|
-
(0,
|
|
28497
|
+
(0, import_node_fs15.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
|
|
28339
28498
|
try {
|
|
28340
|
-
(0,
|
|
28499
|
+
(0, import_node_fs15.chmodSync)(TRUST_FILE, 384);
|
|
28341
28500
|
} catch {
|
|
28342
28501
|
}
|
|
28343
28502
|
}
|
|
@@ -28363,9 +28522,9 @@ function listTrustedModules() {
|
|
|
28363
28522
|
return readTrustFile().modules;
|
|
28364
28523
|
}
|
|
28365
28524
|
function readPublisherKeys() {
|
|
28366
|
-
if (!(0,
|
|
28525
|
+
if (!(0, import_node_fs15.existsSync)(PUBLISHER_KEYS_FILE)) return {};
|
|
28367
28526
|
try {
|
|
28368
|
-
const parsed = JSON.parse((0,
|
|
28527
|
+
const parsed = JSON.parse((0, import_node_fs15.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
|
|
28369
28528
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
28370
28529
|
} catch {
|
|
28371
28530
|
return {};
|
|
@@ -28374,16 +28533,16 @@ function readPublisherKeys() {
|
|
|
28374
28533
|
function verifyModuleSignature(modulePath, digest) {
|
|
28375
28534
|
const keys = readPublisherKeys();
|
|
28376
28535
|
const pinnedKeyIds = Object.keys(keys);
|
|
28377
|
-
const sigPath = (0,
|
|
28536
|
+
const sigPath = (0, import_node_path12.join)(modulePath, "mod.sig");
|
|
28378
28537
|
if (pinnedKeyIds.length === 0) {
|
|
28379
28538
|
return { ok: true };
|
|
28380
28539
|
}
|
|
28381
|
-
if (!(0,
|
|
28540
|
+
if (!(0, import_node_fs15.existsSync)(sigPath)) {
|
|
28382
28541
|
return { ok: false, reason: "publisher keys are pinned but the module ships no mod.sig" };
|
|
28383
28542
|
}
|
|
28384
28543
|
let parsed;
|
|
28385
28544
|
try {
|
|
28386
|
-
parsed = JSON.parse((0,
|
|
28545
|
+
parsed = JSON.parse((0, import_node_fs15.readFileSync)(sigPath, "utf-8"));
|
|
28387
28546
|
} catch {
|
|
28388
28547
|
return { ok: false, reason: "mod.sig is not valid JSON" };
|
|
28389
28548
|
}
|
|
@@ -28444,7 +28603,7 @@ function safeModuleDirName(name, label = "module name") {
|
|
|
28444
28603
|
return name;
|
|
28445
28604
|
}
|
|
28446
28605
|
function moduleDestination(dir, name, label) {
|
|
28447
|
-
return (0,
|
|
28606
|
+
return (0, import_node_path13.join)(dir, safeModuleDirName(name, label));
|
|
28448
28607
|
}
|
|
28449
28608
|
function assertSafeTarballEntries(tarPath) {
|
|
28450
28609
|
const listing = (0, import_node_child_process2.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
|
|
@@ -28457,12 +28616,12 @@ function assertSafeTarballEntries(tarPath) {
|
|
|
28457
28616
|
}
|
|
28458
28617
|
}
|
|
28459
28618
|
function validateManifest(modPath) {
|
|
28460
|
-
const manifestPath = (0,
|
|
28461
|
-
if (!(0,
|
|
28619
|
+
const manifestPath = (0, import_node_path13.join)(modPath, "mod.toml");
|
|
28620
|
+
if (!(0, import_node_fs16.existsSync)(manifestPath)) {
|
|
28462
28621
|
return { ok: false, error: `mod.toml not found at ${manifestPath}` };
|
|
28463
28622
|
}
|
|
28464
28623
|
try {
|
|
28465
|
-
const raw = (0,
|
|
28624
|
+
const raw = (0, import_node_fs16.readFileSync)(manifestPath, "utf-8");
|
|
28466
28625
|
const parsed = import_toml3.default.parse(raw);
|
|
28467
28626
|
const name = parsed.module?.name;
|
|
28468
28627
|
const version = parsed.module?.version;
|
|
@@ -28522,8 +28681,8 @@ async function modulesInstallCommand(source) {
|
|
|
28522
28681
|
console.log();
|
|
28523
28682
|
const dir = modulesDir();
|
|
28524
28683
|
if (source.startsWith("./") || source.startsWith("/") || source.startsWith("~")) {
|
|
28525
|
-
const absPath = (0,
|
|
28526
|
-
if (!(0,
|
|
28684
|
+
const absPath = (0, import_node_path13.resolve)(source.startsWith("~") ? source.replace("~", process.env.HOME || "") : source);
|
|
28685
|
+
if (!(0, import_node_fs16.existsSync)(absPath)) {
|
|
28527
28686
|
console.log(source_default.red(` \u2717 Path not found: ${absPath}
|
|
28528
28687
|
`));
|
|
28529
28688
|
return;
|
|
@@ -28542,7 +28701,7 @@ async function modulesInstallCommand(source) {
|
|
|
28542
28701
|
`));
|
|
28543
28702
|
return;
|
|
28544
28703
|
}
|
|
28545
|
-
if ((0,
|
|
28704
|
+
if ((0, import_node_fs16.existsSync)(dest2)) {
|
|
28546
28705
|
console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
|
|
28547
28706
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
|
|
28548
28707
|
`));
|
|
@@ -28550,7 +28709,7 @@ async function modulesInstallCommand(source) {
|
|
|
28550
28709
|
}
|
|
28551
28710
|
const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
|
|
28552
28711
|
try {
|
|
28553
|
-
(0,
|
|
28712
|
+
(0, import_node_fs16.cpSync)(absPath, dest2, { recursive: true, dereference: true });
|
|
28554
28713
|
spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
|
|
28555
28714
|
} catch (err) {
|
|
28556
28715
|
spinner2.fail(`Copy failed: ${err.message}`);
|
|
@@ -28566,14 +28725,14 @@ async function modulesInstallCommand(source) {
|
|
|
28566
28725
|
let name;
|
|
28567
28726
|
let dest2;
|
|
28568
28727
|
try {
|
|
28569
|
-
name = safeModuleDirName((0,
|
|
28728
|
+
name = safeModuleDirName((0, import_node_path13.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
|
|
28570
28729
|
dest2 = moduleDestination(dir, name);
|
|
28571
28730
|
} catch (err) {
|
|
28572
28731
|
console.log(source_default.red(` x ${err.message}
|
|
28573
28732
|
`));
|
|
28574
28733
|
return;
|
|
28575
28734
|
}
|
|
28576
|
-
if ((0,
|
|
28735
|
+
if ((0, import_node_fs16.existsSync)(dest2)) {
|
|
28577
28736
|
console.log(source_default.yellow(` ! ${name} is already installed at ${dest2}`));
|
|
28578
28737
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${name}`)} first.
|
|
28579
28738
|
`));
|
|
@@ -28590,7 +28749,7 @@ async function modulesInstallCommand(source) {
|
|
|
28590
28749
|
if (!check.ok) {
|
|
28591
28750
|
spinner2.fail(check.error);
|
|
28592
28751
|
try {
|
|
28593
|
-
(0,
|
|
28752
|
+
(0, import_node_fs16.rmSync)(dest2, { recursive: true, force: true });
|
|
28594
28753
|
} catch {
|
|
28595
28754
|
}
|
|
28596
28755
|
return;
|
|
@@ -28636,7 +28795,7 @@ async function modulesInstallCommand(source) {
|
|
|
28636
28795
|
`));
|
|
28637
28796
|
return;
|
|
28638
28797
|
}
|
|
28639
|
-
if ((0,
|
|
28798
|
+
if ((0, import_node_fs16.existsSync)(dest)) {
|
|
28640
28799
|
console.log(source_default.yellow(` ! ${mod.slug} is already installed at ${dest}
|
|
28641
28800
|
`));
|
|
28642
28801
|
return;
|
|
@@ -28662,7 +28821,7 @@ async function modulesInstallCommand(source) {
|
|
|
28662
28821
|
if (!check.ok) {
|
|
28663
28822
|
cloneSpinner.fail(check.error);
|
|
28664
28823
|
try {
|
|
28665
|
-
(0,
|
|
28824
|
+
(0, import_node_fs16.rmSync)(dest, { recursive: true, force: true });
|
|
28666
28825
|
} catch {
|
|
28667
28826
|
}
|
|
28668
28827
|
return;
|
|
@@ -28676,11 +28835,11 @@ async function modulesInstallCommand(source) {
|
|
|
28676
28835
|
dlSpinner.fail(`HTTP ${res.status}`);
|
|
28677
28836
|
return;
|
|
28678
28837
|
}
|
|
28679
|
-
const tar = (0,
|
|
28680
|
-
(0,
|
|
28838
|
+
const tar = (0, import_node_path13.join)(dir, `${mod.slug}.tar.gz`);
|
|
28839
|
+
(0, import_node_fs16.writeFileSync)(tar, Buffer.from(await res.arrayBuffer()));
|
|
28681
28840
|
assertSafeTarballEntries(tar);
|
|
28682
28841
|
(0, import_node_child_process2.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
|
|
28683
|
-
(0,
|
|
28842
|
+
(0, import_node_fs16.rmSync)(tar, { force: true });
|
|
28684
28843
|
const check = validateManifest(dest);
|
|
28685
28844
|
if (!check.ok) {
|
|
28686
28845
|
dlSpinner.fail(check.error);
|
|
@@ -28712,7 +28871,7 @@ async function modulesRemoveCommand(name) {
|
|
|
28712
28871
|
`));
|
|
28713
28872
|
return;
|
|
28714
28873
|
}
|
|
28715
|
-
if (!(0,
|
|
28874
|
+
if (!(0, import_node_fs16.existsSync)(target)) {
|
|
28716
28875
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
28717
28876
|
`));
|
|
28718
28877
|
return;
|
|
@@ -28722,7 +28881,7 @@ async function modulesRemoveCommand(name) {
|
|
|
28722
28881
|
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
|
|
28723
28882
|
}
|
|
28724
28883
|
try {
|
|
28725
|
-
(0,
|
|
28884
|
+
(0, import_node_fs16.rmSync)(target, { recursive: true, force: true });
|
|
28726
28885
|
untrustModule(name);
|
|
28727
28886
|
console.log(source_default.green(` \u2713 Removed ${name} from ${dir}
|
|
28728
28887
|
`));
|
|
@@ -28747,7 +28906,7 @@ async function modulesTrustCommand(name) {
|
|
|
28747
28906
|
`));
|
|
28748
28907
|
return;
|
|
28749
28908
|
}
|
|
28750
|
-
if (!(0,
|
|
28909
|
+
if (!(0, import_node_fs16.existsSync)(target)) {
|
|
28751
28910
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
28752
28911
|
`));
|
|
28753
28912
|
return;
|
|
@@ -29183,21 +29342,21 @@ async function pentestCommand(targetUrl) {
|
|
|
29183
29342
|
|
|
29184
29343
|
// src/commands/orgs.ts
|
|
29185
29344
|
var import_node_os5 = require("os");
|
|
29186
|
-
var
|
|
29187
|
-
var
|
|
29345
|
+
var import_node_fs17 = require("fs");
|
|
29346
|
+
var import_node_path14 = require("path");
|
|
29188
29347
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29189
|
-
var CONFIG_PATH = (0,
|
|
29348
|
+
var CONFIG_PATH = (0, import_node_path14.join)((0, import_node_os5.homedir)(), ".threatcrush", "config.json");
|
|
29190
29349
|
function readConfig() {
|
|
29191
29350
|
try {
|
|
29192
|
-
return JSON.parse((0,
|
|
29351
|
+
return JSON.parse((0, import_node_fs17.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
29193
29352
|
} catch {
|
|
29194
29353
|
return {};
|
|
29195
29354
|
}
|
|
29196
29355
|
}
|
|
29197
29356
|
function writeConfig(config) {
|
|
29198
|
-
const dir = (0,
|
|
29199
|
-
if (!(0,
|
|
29200
|
-
(0,
|
|
29357
|
+
const dir = (0, import_node_path14.join)((0, import_node_os5.homedir)(), ".threatcrush");
|
|
29358
|
+
if (!(0, import_node_fs17.existsSync)(dir)) (0, import_node_fs17.mkdirSync)(dir, { recursive: true });
|
|
29359
|
+
(0, import_node_fs17.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
29201
29360
|
}
|
|
29202
29361
|
function getAuthHeaders() {
|
|
29203
29362
|
const config = readConfig();
|
|
@@ -29333,13 +29492,13 @@ async function useOrganization(slug) {
|
|
|
29333
29492
|
|
|
29334
29493
|
// src/commands/servers.ts
|
|
29335
29494
|
var import_node_os6 = require("os");
|
|
29336
|
-
var
|
|
29337
|
-
var
|
|
29495
|
+
var import_node_fs18 = require("fs");
|
|
29496
|
+
var import_node_path15 = require("path");
|
|
29338
29497
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29339
|
-
var CONFIG_PATH2 = (0,
|
|
29498
|
+
var CONFIG_PATH2 = (0, import_node_path15.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
|
|
29340
29499
|
function readConfig2() {
|
|
29341
29500
|
try {
|
|
29342
|
-
return JSON.parse((0,
|
|
29501
|
+
return JSON.parse((0, import_node_fs18.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
29343
29502
|
} catch {
|
|
29344
29503
|
return {};
|
|
29345
29504
|
}
|
|
@@ -29442,14 +29601,14 @@ function timeAgo(dateStr) {
|
|
|
29442
29601
|
|
|
29443
29602
|
// src/commands/connect.ts
|
|
29444
29603
|
var import_node_os7 = require("os");
|
|
29445
|
-
var
|
|
29446
|
-
var
|
|
29604
|
+
var import_node_fs19 = require("fs");
|
|
29605
|
+
var import_node_path16 = require("path");
|
|
29447
29606
|
var import_node_child_process3 = require("child_process");
|
|
29448
29607
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29449
|
-
var CONFIG_PATH3 = (0,
|
|
29608
|
+
var CONFIG_PATH3 = (0, import_node_path16.join)((0, import_node_os7.homedir)(), ".threatcrush", "config.json");
|
|
29450
29609
|
function readConfig3() {
|
|
29451
29610
|
try {
|
|
29452
|
-
return JSON.parse((0,
|
|
29611
|
+
return JSON.parse((0, import_node_fs19.readFileSync)(CONFIG_PATH3, "utf-8"));
|
|
29453
29612
|
} catch {
|
|
29454
29613
|
return {};
|
|
29455
29614
|
}
|
|
@@ -29604,18 +29763,18 @@ async function sshConnect(options) {
|
|
|
29604
29763
|
|
|
29605
29764
|
// src/commands/daemon.ts
|
|
29606
29765
|
var import_node_child_process9 = require("child_process");
|
|
29607
|
-
var import_node_fs28 = require("fs");
|
|
29608
|
-
var import_node_path20 = require("path");
|
|
29609
29766
|
var import_node_fs29 = require("fs");
|
|
29767
|
+
var import_node_path21 = require("path");
|
|
29768
|
+
var import_node_fs30 = require("fs");
|
|
29610
29769
|
|
|
29611
29770
|
// src/daemon/index.ts
|
|
29612
|
-
var
|
|
29613
|
-
var
|
|
29771
|
+
var import_node_fs28 = require("fs");
|
|
29772
|
+
var import_node_path20 = require("path");
|
|
29614
29773
|
init_paths();
|
|
29615
29774
|
|
|
29616
29775
|
// src/daemon/ipc-server.ts
|
|
29617
29776
|
var import_node_net2 = require("net");
|
|
29618
|
-
var
|
|
29777
|
+
var import_node_fs20 = require("fs");
|
|
29619
29778
|
init_paths();
|
|
29620
29779
|
init_control_token();
|
|
29621
29780
|
|
|
@@ -29667,9 +29826,9 @@ var IpcServer = class {
|
|
|
29667
29826
|
controlToken = "";
|
|
29668
29827
|
async start() {
|
|
29669
29828
|
this.controlToken = issueControlToken();
|
|
29670
|
-
if ((0,
|
|
29829
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) {
|
|
29671
29830
|
try {
|
|
29672
|
-
(0,
|
|
29831
|
+
(0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29673
29832
|
} catch {
|
|
29674
29833
|
}
|
|
29675
29834
|
}
|
|
@@ -29705,14 +29864,14 @@ var IpcServer = class {
|
|
|
29705
29864
|
return new Promise((resolve5) => {
|
|
29706
29865
|
if (!this.server) {
|
|
29707
29866
|
try {
|
|
29708
|
-
if ((0,
|
|
29867
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) (0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29709
29868
|
} catch {
|
|
29710
29869
|
}
|
|
29711
29870
|
return resolve5();
|
|
29712
29871
|
}
|
|
29713
29872
|
this.server.close(() => {
|
|
29714
29873
|
try {
|
|
29715
|
-
if ((0,
|
|
29874
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) (0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29716
29875
|
} catch {
|
|
29717
29876
|
}
|
|
29718
29877
|
resolve5();
|
|
@@ -29744,12 +29903,27 @@ var IpcServer = class {
|
|
|
29744
29903
|
});
|
|
29745
29904
|
}
|
|
29746
29905
|
async handleLine(client, line) {
|
|
29747
|
-
let
|
|
29906
|
+
let frame;
|
|
29748
29907
|
try {
|
|
29749
|
-
|
|
29908
|
+
frame = JSON.parse(line);
|
|
29750
29909
|
} catch {
|
|
29751
29910
|
return this.send(client, { id: 0, ok: false, error: "invalid json" });
|
|
29752
29911
|
}
|
|
29912
|
+
const { id, method } = frame ?? {};
|
|
29913
|
+
if (typeof id !== "number" || typeof method !== "string") {
|
|
29914
|
+
return this.send(client, {
|
|
29915
|
+
id: typeof id === "number" ? id : 0,
|
|
29916
|
+
ok: false,
|
|
29917
|
+
error: 'invalid request: expected {"id": number, "method": string}'
|
|
29918
|
+
});
|
|
29919
|
+
}
|
|
29920
|
+
try {
|
|
29921
|
+
await this.dispatch(client, frame);
|
|
29922
|
+
} catch (err) {
|
|
29923
|
+
this.send(client, { id, ok: false, error: String(err?.message || err) });
|
|
29924
|
+
}
|
|
29925
|
+
}
|
|
29926
|
+
async dispatch(client, req) {
|
|
29753
29927
|
switch (req.method) {
|
|
29754
29928
|
case "ping":
|
|
29755
29929
|
return this.send(client, { id: req.id, ok: true, result: "pong" });
|
|
@@ -29857,6 +30031,10 @@ var IpcServer = class {
|
|
|
29857
30031
|
this.send(client, { id: req.id, ok: true, result: "shutting down" });
|
|
29858
30032
|
setTimeout(() => process.emit("SIGTERM"), 50);
|
|
29859
30033
|
return;
|
|
30034
|
+
default: {
|
|
30035
|
+
const unknown = req;
|
|
30036
|
+
return this.send(client, { id: unknown.id, ok: false, error: `unknown method: ${unknown.method}` });
|
|
30037
|
+
}
|
|
29860
30038
|
}
|
|
29861
30039
|
}
|
|
29862
30040
|
send(client, msg) {
|
|
@@ -29874,14 +30052,14 @@ var IpcServer = class {
|
|
|
29874
30052
|
};
|
|
29875
30053
|
|
|
29876
30054
|
// src/daemon/module-host.ts
|
|
29877
|
-
var
|
|
29878
|
-
var
|
|
30055
|
+
var import_node_fs24 = require("fs");
|
|
30056
|
+
var import_node_path17 = require("path");
|
|
29879
30057
|
var import_node_url = require("url");
|
|
29880
30058
|
var import_toml4 = __toESM(require_toml());
|
|
29881
30059
|
init_paths();
|
|
29882
30060
|
|
|
29883
30061
|
// src/daemon/watchers/log-watcher.ts
|
|
29884
|
-
var
|
|
30062
|
+
var import_node_fs21 = require("fs");
|
|
29885
30063
|
var import_node_readline4 = require("readline");
|
|
29886
30064
|
var DEFAULT_SOURCES = [
|
|
29887
30065
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
@@ -29902,9 +30080,9 @@ var LogWatcher = class {
|
|
|
29902
30080
|
start() {
|
|
29903
30081
|
const started = [];
|
|
29904
30082
|
for (const src of this.sources) {
|
|
29905
|
-
if (!(0,
|
|
30083
|
+
if (!(0, import_node_fs21.existsSync)(src.path)) continue;
|
|
29906
30084
|
try {
|
|
29907
|
-
(0,
|
|
30085
|
+
(0, import_node_fs21.accessSync)(src.path, import_node_fs21.constants.R_OK);
|
|
29908
30086
|
} catch {
|
|
29909
30087
|
continue;
|
|
29910
30088
|
}
|
|
@@ -29922,9 +30100,17 @@ var LogWatcher = class {
|
|
|
29922
30100
|
activeModules() {
|
|
29923
30101
|
return [...this.active];
|
|
29924
30102
|
}
|
|
30103
|
+
/**
|
|
30104
|
+
* The auth logs being tailed. While there is one, it is the only source of
|
|
30105
|
+
* SSH events: sshd's journald records carry the same lines, and counting
|
|
30106
|
+
* both would halve every SSH threshold.
|
|
30107
|
+
*/
|
|
30108
|
+
authLogs() {
|
|
30109
|
+
return this.sources.filter((s) => s.category === "auth" && this.timers.has(s.path)).map((s) => s.path);
|
|
30110
|
+
}
|
|
29925
30111
|
tail(src) {
|
|
29926
30112
|
try {
|
|
29927
|
-
this.positions.set(src.path, (0,
|
|
30113
|
+
this.positions.set(src.path, (0, import_node_fs21.statSync)(src.path).size);
|
|
29928
30114
|
} catch {
|
|
29929
30115
|
this.positions.set(src.path, 0);
|
|
29930
30116
|
}
|
|
@@ -29935,7 +30121,7 @@ var LogWatcher = class {
|
|
|
29935
30121
|
poll(src) {
|
|
29936
30122
|
let stat;
|
|
29937
30123
|
try {
|
|
29938
|
-
stat = (0,
|
|
30124
|
+
stat = (0, import_node_fs21.statSync)(src.path);
|
|
29939
30125
|
} catch {
|
|
29940
30126
|
return;
|
|
29941
30127
|
}
|
|
@@ -29945,7 +30131,7 @@ var LogWatcher = class {
|
|
|
29945
30131
|
return;
|
|
29946
30132
|
}
|
|
29947
30133
|
if (stat.size === prev) return;
|
|
29948
|
-
const stream = (0,
|
|
30134
|
+
const stream = (0, import_node_fs21.createReadStream)(src.path, { start: prev, encoding: "utf-8" });
|
|
29949
30135
|
stream.on("error", () => this.positions.set(src.path, stat.size));
|
|
29950
30136
|
const rl = (0, import_node_readline4.createInterface)({ input: stream });
|
|
29951
30137
|
rl.on("error", () => {
|
|
@@ -29966,20 +30152,9 @@ var LogWatcher = class {
|
|
|
29966
30152
|
if (parsed.source === "auth") {
|
|
29967
30153
|
const entry = parseAuthLog(line);
|
|
29968
30154
|
if (!entry) return;
|
|
29969
|
-
|
|
29970
|
-
|
|
29971
|
-
|
|
29972
|
-
severity = "high";
|
|
29973
|
-
message = `Failed SSH login for ${entry.fields.user || "unknown"} from ${entry.fields.ip || "unknown"}`;
|
|
29974
|
-
} else if (/invalid user/i.test(msg)) {
|
|
29975
|
-
severity = "high";
|
|
29976
|
-
message = `Invalid SSH user: ${entry.fields.user || "unknown"} from ${entry.fields.ip || "unknown"}`;
|
|
29977
|
-
} else if (/accepted/i.test(msg)) {
|
|
29978
|
-
severity = "info";
|
|
29979
|
-
message = `SSH login accepted for ${entry.fields.user || "unknown"}`;
|
|
29980
|
-
} else {
|
|
29981
|
-
return;
|
|
29982
|
-
}
|
|
30155
|
+
const verdict = classifySshAuth(entry);
|
|
30156
|
+
if (!verdict) return;
|
|
30157
|
+
({ severity, message, source_ip: sourceIp } = verdict);
|
|
29983
30158
|
} else if (parsed.source === "nginx") {
|
|
29984
30159
|
const entry = parseNginxLog(line);
|
|
29985
30160
|
if (!entry) return;
|
|
@@ -30037,13 +30212,33 @@ var LogWatcher = class {
|
|
|
30037
30212
|
|
|
30038
30213
|
// src/daemon/watchers/journal-watcher.ts
|
|
30039
30214
|
var import_node_child_process4 = require("child_process");
|
|
30215
|
+
var SSHD_COMMS = ["sshd", "sshd-session"];
|
|
30216
|
+
function isSshdRecord(entry) {
|
|
30217
|
+
return entry._UID === "0" && SSHD_COMMS.includes(entry._COMM);
|
|
30218
|
+
}
|
|
30219
|
+
function sshEventFromJournal(entry) {
|
|
30220
|
+
if (!isSshdRecord(entry) || typeof entry.MESSAGE !== "string") return null;
|
|
30221
|
+
const timestamp = realtimeToDate(entry.__REALTIME_TIMESTAMP) || /* @__PURE__ */ new Date();
|
|
30222
|
+
const verdict = classifySshAuth(parseAuthMessage(entry._COMM, entry.MESSAGE, timestamp));
|
|
30223
|
+
if (!verdict) return null;
|
|
30224
|
+
return {
|
|
30225
|
+
timestamp,
|
|
30226
|
+
module: "ssh-guard",
|
|
30227
|
+
category: "auth",
|
|
30228
|
+
severity: verdict.severity,
|
|
30229
|
+
message: verdict.message,
|
|
30230
|
+
source_ip: verdict.source_ip
|
|
30231
|
+
};
|
|
30232
|
+
}
|
|
30040
30233
|
var JournalWatcher = class _JournalWatcher {
|
|
30041
30234
|
constructor(bus2) {
|
|
30042
30235
|
this.bus = bus2;
|
|
30043
30236
|
}
|
|
30044
30237
|
bus;
|
|
30045
30238
|
proc = null;
|
|
30239
|
+
sshdProc = null;
|
|
30046
30240
|
buffer = "";
|
|
30241
|
+
sshdBuffer = "";
|
|
30047
30242
|
moduleName = "user-journal";
|
|
30048
30243
|
active = false;
|
|
30049
30244
|
// When the daemon runs as root (system mode), tail the SYSTEM journal so
|
|
@@ -30069,7 +30264,9 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30069
30264
|
);
|
|
30070
30265
|
if (!child.stdout) return false;
|
|
30071
30266
|
child.stdout.setEncoding("utf-8");
|
|
30072
|
-
child.stdout.on("data", (chunk) =>
|
|
30267
|
+
child.stdout.on("data", (chunk) => {
|
|
30268
|
+
this.buffer = this.drain(this.buffer + chunk, (entry) => this.handleEntry(entry));
|
|
30269
|
+
});
|
|
30073
30270
|
child.on("exit", () => {
|
|
30074
30271
|
this.proc = null;
|
|
30075
30272
|
this.active = false;
|
|
@@ -30078,14 +30275,49 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30078
30275
|
this.active = true;
|
|
30079
30276
|
return true;
|
|
30080
30277
|
}
|
|
30278
|
+
/**
|
|
30279
|
+
* Follows sshd in the system journal. Unprivileged, that needs the adm,
|
|
30280
|
+
* systemd-journal or wheel group; without it journalctl shows only the
|
|
30281
|
+
* user's own records, so this reports `unreadable` rather than tailing
|
|
30282
|
+
* nothing and looking like protection.
|
|
30283
|
+
*/
|
|
30284
|
+
startSshd() {
|
|
30285
|
+
const probe = (0, import_node_child_process4.spawnSync)("journalctl", ["-q", "-n", "1", "-o", "cat", "--no-pager", "_UID=0"], {
|
|
30286
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
30287
|
+
encoding: "utf-8"
|
|
30288
|
+
});
|
|
30289
|
+
if (probe.error || probe.status !== 0) return "unavailable";
|
|
30290
|
+
if (!probe.stdout.trim()) return "unreadable";
|
|
30291
|
+
const matches2 = ["_UID=0", ...SSHD_COMMS.map((comm) => `_COMM=${comm}`)];
|
|
30292
|
+
const child = (0, import_node_child_process4.spawn)("journalctl", ["-o", "json", "-f", "--since", "now", ...matches2], {
|
|
30293
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
30294
|
+
});
|
|
30295
|
+
if (!child.stdout) return "unavailable";
|
|
30296
|
+
child.stdout.setEncoding("utf-8");
|
|
30297
|
+
child.stdout.on("data", (chunk) => {
|
|
30298
|
+
this.sshdBuffer = this.drain(this.sshdBuffer + chunk, (entry) => {
|
|
30299
|
+
const event = sshEventFromJournal(entry);
|
|
30300
|
+
if (event) this.emit(event);
|
|
30301
|
+
});
|
|
30302
|
+
});
|
|
30303
|
+
child.on("error", () => {
|
|
30304
|
+
this.sshdProc = null;
|
|
30305
|
+
});
|
|
30306
|
+
child.on("exit", () => {
|
|
30307
|
+
this.sshdProc = null;
|
|
30308
|
+
});
|
|
30309
|
+
this.sshdProc = child;
|
|
30310
|
+
return "running";
|
|
30311
|
+
}
|
|
30081
30312
|
stop() {
|
|
30082
|
-
|
|
30313
|
+
for (const child of [this.proc, this.sshdProc]) {
|
|
30083
30314
|
try {
|
|
30084
|
-
|
|
30315
|
+
child?.kill("SIGTERM");
|
|
30085
30316
|
} catch {
|
|
30086
30317
|
}
|
|
30087
|
-
this.proc = null;
|
|
30088
30318
|
}
|
|
30319
|
+
this.proc = null;
|
|
30320
|
+
this.sshdProc = null;
|
|
30089
30321
|
this.active = false;
|
|
30090
30322
|
}
|
|
30091
30323
|
isActive() {
|
|
@@ -30094,36 +30326,40 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30094
30326
|
moduleNameValue() {
|
|
30095
30327
|
return this.moduleName;
|
|
30096
30328
|
}
|
|
30097
|
-
|
|
30098
|
-
|
|
30329
|
+
/** Hands each complete JSON line to `onEntry`; returns the unterminated rest. */
|
|
30330
|
+
drain(buffer, onEntry) {
|
|
30099
30331
|
let idx;
|
|
30100
|
-
while ((idx =
|
|
30101
|
-
const line =
|
|
30102
|
-
|
|
30332
|
+
while ((idx = buffer.indexOf("\n")) >= 0) {
|
|
30333
|
+
const line = buffer.slice(0, idx);
|
|
30334
|
+
buffer = buffer.slice(idx + 1);
|
|
30103
30335
|
if (!line.trim()) continue;
|
|
30104
|
-
|
|
30336
|
+
let entry;
|
|
30337
|
+
try {
|
|
30338
|
+
entry = JSON.parse(line);
|
|
30339
|
+
} catch {
|
|
30340
|
+
continue;
|
|
30341
|
+
}
|
|
30342
|
+
onEntry(entry);
|
|
30105
30343
|
}
|
|
30344
|
+
return buffer;
|
|
30106
30345
|
}
|
|
30107
|
-
|
|
30108
|
-
|
|
30109
|
-
try {
|
|
30110
|
-
entry = JSON.parse(line);
|
|
30111
|
-
} catch {
|
|
30112
|
-
return;
|
|
30113
|
-
}
|
|
30346
|
+
handleEntry(entry) {
|
|
30347
|
+
if (this.sshdProc && isSshdRecord(entry)) return;
|
|
30114
30348
|
const message = entry.MESSAGE;
|
|
30115
30349
|
if (!message) return;
|
|
30116
30350
|
const priority = parseInt(entry.PRIORITY ?? "6", 10);
|
|
30117
30351
|
const severity = priorityToSeverity(priority);
|
|
30118
30352
|
const ident = entry.SYSLOG_IDENTIFIER || entry._COMM || "journal";
|
|
30119
30353
|
const bumpedSeverity = bumpForIdent(ident, message, severity);
|
|
30120
|
-
|
|
30354
|
+
this.emit({
|
|
30121
30355
|
timestamp: realtimeToDate(entry.__REALTIME_TIMESTAMP) || /* @__PURE__ */ new Date(),
|
|
30122
30356
|
module: this.moduleName,
|
|
30123
30357
|
category: "system",
|
|
30124
30358
|
severity: bumpedSeverity,
|
|
30125
30359
|
message: `[${ident}] ${message}`.slice(0, 500)
|
|
30126
|
-
};
|
|
30360
|
+
});
|
|
30361
|
+
}
|
|
30362
|
+
emit(event) {
|
|
30127
30363
|
try {
|
|
30128
30364
|
insertEvent(event);
|
|
30129
30365
|
} catch {
|
|
@@ -30156,7 +30392,7 @@ function realtimeToDate(rt) {
|
|
|
30156
30392
|
|
|
30157
30393
|
// src/modules/network-monitor/index.ts
|
|
30158
30394
|
var import_node_child_process5 = require("child_process");
|
|
30159
|
-
var
|
|
30395
|
+
var import_node_fs22 = require("fs");
|
|
30160
30396
|
var NetworkMonitor = class {
|
|
30161
30397
|
constructor(bus2) {
|
|
30162
30398
|
this.bus = bus2;
|
|
@@ -30164,13 +30400,22 @@ var NetworkMonitor = class {
|
|
|
30164
30400
|
bus;
|
|
30165
30401
|
active = false;
|
|
30166
30402
|
pollTimer = null;
|
|
30403
|
+
heartbeatTimer = null;
|
|
30167
30404
|
scanTrackers = /* @__PURE__ */ new Map();
|
|
30168
30405
|
halfOpenTrackers = /* @__PURE__ */ new Map();
|
|
30169
30406
|
lastConnections = /* @__PURE__ */ new Set();
|
|
30407
|
+
// Proof-of-life accounting, reset each heartbeat.
|
|
30408
|
+
obsConnections = 0;
|
|
30409
|
+
obsSources = /* @__PURE__ */ new Set();
|
|
30410
|
+
noticed = /* @__PURE__ */ new Set();
|
|
30170
30411
|
// Config
|
|
30171
30412
|
pollIntervalMs = 5e3;
|
|
30413
|
+
heartbeatMs = 9e5;
|
|
30414
|
+
// 15 min: proof of life, low volume
|
|
30172
30415
|
portScanThreshold = 10;
|
|
30173
|
-
// unique ports
|
|
30416
|
+
// unique listening ports -> high (bannable)
|
|
30417
|
+
portScanNoticeThreshold = 5;
|
|
30418
|
+
// 5-9 -> medium notice (never bans)
|
|
30174
30419
|
portScanWindowMs = 3e4;
|
|
30175
30420
|
synFloodThreshold = 50;
|
|
30176
30421
|
// half-open connections
|
|
@@ -30181,20 +30426,37 @@ var NetworkMonitor = class {
|
|
|
30181
30426
|
}
|
|
30182
30427
|
this.active = true;
|
|
30183
30428
|
this.pollTimer = setInterval(() => this.poll(), this.pollIntervalMs);
|
|
30429
|
+
this.heartbeatTimer = setInterval(() => this.heartbeat(), this.heartbeatMs);
|
|
30184
30430
|
return true;
|
|
30185
30431
|
}
|
|
30186
30432
|
stop() {
|
|
30187
30433
|
if (this.pollTimer) clearInterval(this.pollTimer);
|
|
30434
|
+
if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
|
|
30188
30435
|
this.pollTimer = null;
|
|
30436
|
+
this.heartbeatTimer = null;
|
|
30189
30437
|
this.active = false;
|
|
30190
30438
|
}
|
|
30439
|
+
heartbeat() {
|
|
30440
|
+
const conns = this.obsConnections;
|
|
30441
|
+
const srcs = this.obsSources.size;
|
|
30442
|
+
this.obsConnections = 0;
|
|
30443
|
+
this.obsSources.clear();
|
|
30444
|
+
this.noticed.clear();
|
|
30445
|
+
const listening = this.listeningPorts().size;
|
|
30446
|
+
this.emitEvent(
|
|
30447
|
+
"info",
|
|
30448
|
+
`network-monitor alive: ${conns} inbound connection(s) from ${srcs} source(s) across ${listening} listening port(s) in the last ${Math.round(this.heartbeatMs / 6e4)}m`,
|
|
30449
|
+
void 0,
|
|
30450
|
+
{ heartbeat: true, inbound: conns, sources: srcs, listening_ports: listening }
|
|
30451
|
+
);
|
|
30452
|
+
}
|
|
30191
30453
|
isActive() {
|
|
30192
30454
|
return this.active;
|
|
30193
30455
|
}
|
|
30194
30456
|
hasConntrackOrSs() {
|
|
30195
30457
|
const ss = (0, import_node_child_process5.spawnSync)("ss", ["--version"], { stdio: "pipe" });
|
|
30196
30458
|
if (ss.status === 0) return true;
|
|
30197
|
-
return (0,
|
|
30459
|
+
return (0, import_node_fs22.existsSync)("/proc/net/tcp");
|
|
30198
30460
|
}
|
|
30199
30461
|
/**
|
|
30200
30462
|
* The TCP ports this host actually listens on.
|
|
@@ -30226,6 +30488,8 @@ var NetworkMonitor = class {
|
|
|
30226
30488
|
poll() {
|
|
30227
30489
|
try {
|
|
30228
30490
|
const connections = this.getConnections();
|
|
30491
|
+
this.obsConnections += connections.length;
|
|
30492
|
+
for (const c of connections) this.obsSources.add(c.source_ip);
|
|
30229
30493
|
this.analyzePortScans(connections);
|
|
30230
30494
|
this.analyzeSynFlood(connections);
|
|
30231
30495
|
this.cleanupTrackers();
|
|
@@ -30294,7 +30558,8 @@ var NetworkMonitor = class {
|
|
|
30294
30558
|
tracker.ports.add(conn.dest_port);
|
|
30295
30559
|
tracker.lastSeen = now;
|
|
30296
30560
|
tracker.count++;
|
|
30297
|
-
|
|
30561
|
+
const withinWindow = now - tracker.firstSeen <= this.portScanWindowMs;
|
|
30562
|
+
if (tracker.ports.size >= this.portScanThreshold && withinWindow) {
|
|
30298
30563
|
this.emitEvent(
|
|
30299
30564
|
"high",
|
|
30300
30565
|
`Port scan detected: ${conn.source_ip} probed ${tracker.ports.size} ports in ${Math.round((now - tracker.firstSeen) / 1e3)}s`,
|
|
@@ -30302,6 +30567,20 @@ var NetworkMonitor = class {
|
|
|
30302
30567
|
{ ports_scanned: tracker.ports.size, window_seconds: Math.round((now - tracker.firstSeen) / 1e3) }
|
|
30303
30568
|
);
|
|
30304
30569
|
this.scanTrackers.delete(key);
|
|
30570
|
+
} else if (
|
|
30571
|
+
// A smaller spread across our listening ports is worth surfacing, but
|
|
30572
|
+
// at `medium` so it is logged and never banned (auto-defence bans at
|
|
30573
|
+
// `high`). These are inbound-to-listening only, so the ephemeral
|
|
30574
|
+
// outbound-port bug that once banned our upstreams cannot recur here.
|
|
30575
|
+
tracker.ports.size >= this.portScanNoticeThreshold && withinWindow && !this.noticed.has(key)
|
|
30576
|
+
) {
|
|
30577
|
+
this.noticed.add(key);
|
|
30578
|
+
this.emitEvent(
|
|
30579
|
+
"medium",
|
|
30580
|
+
`Possible port scan: ${conn.source_ip} touched ${tracker.ports.size} listening ports in ${Math.round((now - tracker.firstSeen) / 1e3)}s`,
|
|
30581
|
+
conn.source_ip,
|
|
30582
|
+
{ ports_scanned: tracker.ports.size, window_seconds: Math.round((now - tracker.firstSeen) / 1e3), notice: true }
|
|
30583
|
+
);
|
|
30305
30584
|
}
|
|
30306
30585
|
}
|
|
30307
30586
|
}
|
|
@@ -30364,7 +30643,7 @@ var NetworkMonitor = class {
|
|
|
30364
30643
|
};
|
|
30365
30644
|
|
|
30366
30645
|
// src/modules/dns-monitor/index.ts
|
|
30367
|
-
var
|
|
30646
|
+
var import_node_fs23 = require("fs");
|
|
30368
30647
|
var import_node_child_process6 = require("child_process");
|
|
30369
30648
|
var import_node_readline5 = require("readline");
|
|
30370
30649
|
var DNS_LOG_SOURCES = [
|
|
@@ -30377,6 +30656,7 @@ var DNS_LOG_SOURCES = [
|
|
|
30377
30656
|
"/var/log/pihole.log"
|
|
30378
30657
|
// Pi-hole
|
|
30379
30658
|
];
|
|
30659
|
+
var DEFAULT_DNS_JOURNAL_UNITS = ["moshpit-dns", "dnsmasq", "named", "unbound", "pdns-recursor"];
|
|
30380
30660
|
function qtypeName(qtype) {
|
|
30381
30661
|
const names = {
|
|
30382
30662
|
1: "A",
|
|
@@ -30397,10 +30677,11 @@ function qtypeName(qtype) {
|
|
|
30397
30677
|
return names[qtype] ?? `TYPE${qtype}`;
|
|
30398
30678
|
}
|
|
30399
30679
|
var DnsMonitor = class {
|
|
30680
|
+
// 15 min: enough to prove life, low volume
|
|
30400
30681
|
constructor(bus2, options = {}) {
|
|
30401
30682
|
this.bus = bus2;
|
|
30402
30683
|
this.extraPaths = options.log_paths ?? [];
|
|
30403
|
-
this.journalUnits = options.journal_units ??
|
|
30684
|
+
this.journalUnits = options.journal_units ?? DEFAULT_DNS_JOURNAL_UNITS;
|
|
30404
30685
|
}
|
|
30405
30686
|
bus;
|
|
30406
30687
|
active = false;
|
|
@@ -30422,28 +30703,77 @@ var DnsMonitor = class {
|
|
|
30422
30703
|
extraPaths = [];
|
|
30423
30704
|
journalUnits = [];
|
|
30424
30705
|
journalTails = [];
|
|
30706
|
+
/** What we ended up tailing, for an honest status line. */
|
|
30707
|
+
activeSources = [];
|
|
30708
|
+
/** Queries seen since the last heartbeat, for a proof-of-life event. */
|
|
30709
|
+
observed = 0;
|
|
30710
|
+
analyzeTimer = null;
|
|
30711
|
+
heartbeatTimer = null;
|
|
30712
|
+
heartbeatMs = 9e5;
|
|
30713
|
+
/** True if a systemd unit is loaded on this host (so we do not tail nothing). */
|
|
30714
|
+
unitExists(unit) {
|
|
30715
|
+
try {
|
|
30716
|
+
const r = (0, import_node_child_process6.spawnSync)("systemctl", ["show", unit, "--property=LoadState", "--value"], {
|
|
30717
|
+
encoding: "utf-8",
|
|
30718
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
30719
|
+
timeout: 3e3
|
|
30720
|
+
});
|
|
30721
|
+
return r.status === 0 && (r.stdout || "").trim() === "loaded";
|
|
30722
|
+
} catch {
|
|
30723
|
+
return false;
|
|
30724
|
+
}
|
|
30725
|
+
}
|
|
30425
30726
|
start() {
|
|
30426
30727
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
30427
|
-
if (!(0,
|
|
30728
|
+
if (!(0, import_node_fs23.existsSync)(p)) return false;
|
|
30428
30729
|
try {
|
|
30429
|
-
(0,
|
|
30730
|
+
(0, import_node_fs23.accessSync)(p, import_node_fs23.constants.R_OK);
|
|
30430
30731
|
return true;
|
|
30431
30732
|
} catch {
|
|
30432
30733
|
return false;
|
|
30433
30734
|
}
|
|
30434
30735
|
});
|
|
30435
|
-
for (const unit of this.journalUnits)
|
|
30736
|
+
for (const unit of this.journalUnits) {
|
|
30737
|
+
if (this.unitExists(unit)) {
|
|
30738
|
+
this.tailJournalUnit(unit);
|
|
30739
|
+
this.activeSources.push(`journal:${unit}`);
|
|
30740
|
+
}
|
|
30741
|
+
}
|
|
30742
|
+
this.activeSources.push(...sources);
|
|
30436
30743
|
if (sources.length === 0 && this.journalTails.length === 0) return false;
|
|
30437
30744
|
this.active = true;
|
|
30438
30745
|
for (const src of sources) {
|
|
30439
30746
|
this.tailLog(src);
|
|
30440
30747
|
}
|
|
30441
|
-
setInterval(() => this.analyzeBuffer(), 1e4);
|
|
30748
|
+
this.analyzeTimer = setInterval(() => this.analyzeBuffer(), 1e4);
|
|
30749
|
+
this.heartbeatTimer = setInterval(() => this.heartbeat(), this.heartbeatMs);
|
|
30442
30750
|
return true;
|
|
30443
30751
|
}
|
|
30752
|
+
/** What the module is tailing, for the host's status line. */
|
|
30753
|
+
sources() {
|
|
30754
|
+
return [...this.activeSources];
|
|
30755
|
+
}
|
|
30756
|
+
heartbeat() {
|
|
30757
|
+
const seen = this.observed;
|
|
30758
|
+
this.observed = 0;
|
|
30759
|
+
this.emitEvent(
|
|
30760
|
+
"info",
|
|
30761
|
+
`dns-monitor alive: ${seen} DNS quer${seen === 1 ? "y" : "ies"} in the last ${Math.round(this.heartbeatMs / 6e4)}m (sources: ${this.activeSources.join(", ") || "none"})`,
|
|
30762
|
+
void 0,
|
|
30763
|
+
{ heartbeat: true, observed: seen, sources: this.activeSources }
|
|
30764
|
+
);
|
|
30765
|
+
}
|
|
30444
30766
|
stop() {
|
|
30445
30767
|
for (const t of this.timers.values()) clearInterval(t);
|
|
30446
30768
|
this.timers.clear();
|
|
30769
|
+
if (this.analyzeTimer) {
|
|
30770
|
+
clearInterval(this.analyzeTimer);
|
|
30771
|
+
this.analyzeTimer = null;
|
|
30772
|
+
}
|
|
30773
|
+
if (this.heartbeatTimer) {
|
|
30774
|
+
clearInterval(this.heartbeatTimer);
|
|
30775
|
+
this.heartbeatTimer = null;
|
|
30776
|
+
}
|
|
30447
30777
|
for (const child of this.journalTails) {
|
|
30448
30778
|
try {
|
|
30449
30779
|
child.kill("SIGTERM");
|
|
@@ -30473,7 +30803,7 @@ var DnsMonitor = class {
|
|
|
30473
30803
|
}
|
|
30474
30804
|
tailLog(path) {
|
|
30475
30805
|
try {
|
|
30476
|
-
this.positions.set(path, (0,
|
|
30806
|
+
this.positions.set(path, (0, import_node_fs23.statSync)(path).size);
|
|
30477
30807
|
} catch {
|
|
30478
30808
|
this.positions.set(path, 0);
|
|
30479
30809
|
}
|
|
@@ -30483,7 +30813,7 @@ var DnsMonitor = class {
|
|
|
30483
30813
|
pollLog(path) {
|
|
30484
30814
|
let stat;
|
|
30485
30815
|
try {
|
|
30486
|
-
stat = (0,
|
|
30816
|
+
stat = (0, import_node_fs23.statSync)(path);
|
|
30487
30817
|
} catch {
|
|
30488
30818
|
return;
|
|
30489
30819
|
}
|
|
@@ -30493,7 +30823,7 @@ var DnsMonitor = class {
|
|
|
30493
30823
|
return;
|
|
30494
30824
|
}
|
|
30495
30825
|
if (stat.size === prev) return;
|
|
30496
|
-
const stream = (0,
|
|
30826
|
+
const stream = (0, import_node_fs23.createReadStream)(path, { start: prev, encoding: "utf-8" });
|
|
30497
30827
|
stream.on("error", () => this.positions.set(path, stat.size));
|
|
30498
30828
|
const rl = (0, import_node_readline5.createInterface)({ input: stream });
|
|
30499
30829
|
rl.on("line", (line) => this.parseDnsLine(line));
|
|
@@ -30504,7 +30834,7 @@ var DnsMonitor = class {
|
|
|
30504
30834
|
/\[dns\]\s+(?:udp|tcp|doh)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w+)/i
|
|
30505
30835
|
);
|
|
30506
30836
|
if (moshpit) {
|
|
30507
|
-
this.
|
|
30837
|
+
this.record({
|
|
30508
30838
|
type: qtypeName(Number.parseInt(moshpit[3], 10)),
|
|
30509
30839
|
domain: moshpit[2],
|
|
30510
30840
|
source_ip: moshpit[1],
|
|
@@ -30514,7 +30844,7 @@ var DnsMonitor = class {
|
|
|
30514
30844
|
}
|
|
30515
30845
|
const resolvedMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
30516
30846
|
if (resolvedMatch) {
|
|
30517
|
-
this.
|
|
30847
|
+
this.record({
|
|
30518
30848
|
type: resolvedMatch[1],
|
|
30519
30849
|
domain: resolvedMatch[2],
|
|
30520
30850
|
source_ip: resolvedMatch[3],
|
|
@@ -30524,7 +30854,7 @@ var DnsMonitor = class {
|
|
|
30524
30854
|
}
|
|
30525
30855
|
const dnsmasqMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
30526
30856
|
if (dnsmasqMatch) {
|
|
30527
|
-
this.
|
|
30857
|
+
this.record({
|
|
30528
30858
|
type: dnsmasqMatch[1],
|
|
30529
30859
|
domain: dnsmasqMatch[2],
|
|
30530
30860
|
source_ip: dnsmasqMatch[3],
|
|
@@ -30535,7 +30865,7 @@ var DnsMonitor = class {
|
|
|
30535
30865
|
const genericMatch = line.match(/(?:query|lookup|resolve)[:\s]+(\S+)/i);
|
|
30536
30866
|
if (genericMatch) {
|
|
30537
30867
|
const typeMatch = line.match(/type[:\s]+(\w+)/i);
|
|
30538
|
-
this.
|
|
30868
|
+
this.record({
|
|
30539
30869
|
type: typeMatch?.[1] || "A",
|
|
30540
30870
|
domain: genericMatch[1],
|
|
30541
30871
|
timestamp: Date.now()
|
|
@@ -30615,6 +30945,11 @@ var DnsMonitor = class {
|
|
|
30615
30945
|
}
|
|
30616
30946
|
return entropy;
|
|
30617
30947
|
}
|
|
30948
|
+
/** Buffer a parsed query and count it toward the proof-of-life heartbeat. */
|
|
30949
|
+
record(q) {
|
|
30950
|
+
this.domainBuffer.push(q);
|
|
30951
|
+
this.observed++;
|
|
30952
|
+
}
|
|
30618
30953
|
emitEvent(severity, message, sourceIp, details) {
|
|
30619
30954
|
const event = {
|
|
30620
30955
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -30678,6 +31013,18 @@ var ModuleHost = class {
|
|
|
30678
31013
|
this.bus.announceModule("user-journal", "running", mod.detail);
|
|
30679
31014
|
}
|
|
30680
31015
|
}
|
|
31016
|
+
if (this.logWatcher.authLogs().length === 0) {
|
|
31017
|
+
const sshd = this.journalWatcher.startSshd();
|
|
31018
|
+
const mod = this.modules.get("ssh-guard");
|
|
31019
|
+
if (mod && sshd === "running") {
|
|
31020
|
+
mod.status = "running";
|
|
31021
|
+
mod.detail = "no auth log; following sshd in the system journal";
|
|
31022
|
+
this.bus.announceModule("ssh-guard", "running", mod.detail);
|
|
31023
|
+
} else if (mod && sshd === "unreadable") {
|
|
31024
|
+
mod.detail = "no auth log, and the system journal is unreadable: add this user to the adm, systemd-journal or wheel group";
|
|
31025
|
+
this.bus.announceModule("ssh-guard", mod.status, mod.detail);
|
|
31026
|
+
}
|
|
31027
|
+
}
|
|
30681
31028
|
this.networkMonitor = new NetworkMonitor(this.bus);
|
|
30682
31029
|
if (this.networkMonitor.start()) {
|
|
30683
31030
|
const nmod = this.modules.get("network-monitor");
|
|
@@ -30696,7 +31043,7 @@ var ModuleHost = class {
|
|
|
30696
31043
|
const dmod = this.modules.get("dns-monitor");
|
|
30697
31044
|
if (dmod) {
|
|
30698
31045
|
dmod.status = "running";
|
|
30699
|
-
dmod.detail =
|
|
31046
|
+
dmod.detail = `monitoring DNS: ${this.dnsMonitor.sources().join(", ") || "no source"}`;
|
|
30700
31047
|
this.bus.announceModule("dns-monitor", "running", dmod.detail);
|
|
30701
31048
|
}
|
|
30702
31049
|
}
|
|
@@ -30740,15 +31087,15 @@ var ModuleHost = class {
|
|
|
30740
31087
|
for (const m of builtins) this.modules.set(m.name, m);
|
|
30741
31088
|
}
|
|
30742
31089
|
async discoverAndStartInstalled() {
|
|
30743
|
-
if (!(0,
|
|
31090
|
+
if (!(0, import_node_fs24.existsSync)(PATHS.moduleDir)) return;
|
|
30744
31091
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
30745
|
-
const entries = (0,
|
|
31092
|
+
const entries = (0, import_node_fs24.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
30746
31093
|
for (const entry of entries) {
|
|
30747
31094
|
if (!entry.isDirectory()) continue;
|
|
30748
|
-
const manifestPath = (0,
|
|
30749
|
-
if (!(0,
|
|
31095
|
+
const manifestPath = (0, import_node_path17.join)(PATHS.moduleDir, entry.name, "mod.toml");
|
|
31096
|
+
if (!(0, import_node_fs24.existsSync)(manifestPath)) continue;
|
|
30750
31097
|
try {
|
|
30751
|
-
const manifest = import_toml4.default.parse((0,
|
|
31098
|
+
const manifest = import_toml4.default.parse((0, import_node_fs24.readFileSync)(manifestPath, "utf-8"));
|
|
30752
31099
|
const name = manifest.module?.name || entry.name;
|
|
30753
31100
|
const defaults = manifest.module?.config?.defaults || {};
|
|
30754
31101
|
const config = {
|
|
@@ -30762,7 +31109,7 @@ var ModuleHost = class {
|
|
|
30762
31109
|
source: "installed",
|
|
30763
31110
|
status: config.enabled === false ? "disabled" : "loaded",
|
|
30764
31111
|
events: 0,
|
|
30765
|
-
path: (0,
|
|
31112
|
+
path: (0, import_node_path17.join)(PATHS.moduleDir, entry.name),
|
|
30766
31113
|
config
|
|
30767
31114
|
};
|
|
30768
31115
|
this.modules.set(name, hosted);
|
|
@@ -30777,7 +31124,7 @@ var ModuleHost = class {
|
|
|
30777
31124
|
status: "error",
|
|
30778
31125
|
events: 0,
|
|
30779
31126
|
detail: `manifest load failed: ${String(err.message || err)}`,
|
|
30780
|
-
path: (0,
|
|
31127
|
+
path: (0, import_node_path17.join)(PATHS.moduleDir, entry.name)
|
|
30781
31128
|
});
|
|
30782
31129
|
}
|
|
30783
31130
|
}
|
|
@@ -30816,17 +31163,17 @@ var ModuleHost = class {
|
|
|
30816
31163
|
}
|
|
30817
31164
|
}
|
|
30818
31165
|
installedEntrypoint(modulePath) {
|
|
30819
|
-
const packageJson = (0,
|
|
31166
|
+
const packageJson = (0, import_node_path17.join)(modulePath, "package.json");
|
|
30820
31167
|
const candidates = [];
|
|
30821
|
-
if ((0,
|
|
31168
|
+
if ((0, import_node_fs24.existsSync)(packageJson)) {
|
|
30822
31169
|
try {
|
|
30823
|
-
const pkg = JSON.parse((0,
|
|
30824
|
-
if (pkg.main) candidates.push((0,
|
|
31170
|
+
const pkg = JSON.parse((0, import_node_fs24.readFileSync)(packageJson, "utf-8"));
|
|
31171
|
+
if (pkg.main) candidates.push((0, import_node_path17.join)(modulePath, pkg.main));
|
|
30825
31172
|
} catch {
|
|
30826
31173
|
}
|
|
30827
31174
|
}
|
|
30828
|
-
candidates.push((0,
|
|
30829
|
-
return candidates.find((candidate) => (0,
|
|
31175
|
+
candidates.push((0, import_node_path17.join)(modulePath, "dist", "index.js"), (0, import_node_path17.join)(modulePath, "index.js"));
|
|
31176
|
+
return candidates.find((candidate) => (0, import_node_fs24.existsSync)(candidate)) || null;
|
|
30830
31177
|
}
|
|
30831
31178
|
isThreatCrushModule(value) {
|
|
30832
31179
|
return Boolean(
|
|
@@ -31356,10 +31703,11 @@ var RuleEngine = class {
|
|
|
31356
31703
|
};
|
|
31357
31704
|
|
|
31358
31705
|
// src/daemon/rules/loader.ts
|
|
31359
|
-
var
|
|
31360
|
-
var
|
|
31706
|
+
var import_node_fs25 = require("fs");
|
|
31707
|
+
var import_node_path18 = require("path");
|
|
31361
31708
|
|
|
31362
31709
|
// src/daemon/rules/default-rules.ts
|
|
31710
|
+
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
31363
31711
|
var DEFAULT_RULES = [
|
|
31364
31712
|
{
|
|
31365
31713
|
id: "ssh-brute-force",
|
|
@@ -31380,8 +31728,7 @@ var DEFAULT_RULES = [
|
|
|
31380
31728
|
tags: ["ssh", "brute-force", "credential-stuffing"],
|
|
31381
31729
|
remediation: {
|
|
31382
31730
|
action: "block",
|
|
31383
|
-
|
|
31384
|
-
description: "Block source IP for 1 hour"
|
|
31731
|
+
description: "Block source IP"
|
|
31385
31732
|
},
|
|
31386
31733
|
enabled: true
|
|
31387
31734
|
},
|
|
@@ -31429,7 +31776,6 @@ var DEFAULT_RULES = [
|
|
|
31429
31776
|
tags: ["ssh", "root-access"],
|
|
31430
31777
|
remediation: {
|
|
31431
31778
|
action: "block",
|
|
31432
|
-
ttl_seconds: 7200,
|
|
31433
31779
|
description: "Block source IP attempting root login"
|
|
31434
31780
|
},
|
|
31435
31781
|
enabled: true
|
|
@@ -31453,7 +31799,6 @@ var DEFAULT_RULES = [
|
|
|
31453
31799
|
tags: ["ssh", "enumeration", "reconnaissance"],
|
|
31454
31800
|
remediation: {
|
|
31455
31801
|
action: "block",
|
|
31456
|
-
ttl_seconds: 3600,
|
|
31457
31802
|
description: "Block source IP performing user enumeration"
|
|
31458
31803
|
},
|
|
31459
31804
|
enabled: true
|
|
@@ -31483,20 +31828,15 @@ var DEFAULT_RULES = [
|
|
|
31483
31828
|
description: "HTTP request with SQL injection patterns",
|
|
31484
31829
|
version: "1.0.0",
|
|
31485
31830
|
category: "web",
|
|
31486
|
-
severity: "
|
|
31831
|
+
severity: "high",
|
|
31487
31832
|
source_types: ["log-watcher", "web"],
|
|
31488
|
-
match: {
|
|
31489
|
-
field: "message",
|
|
31490
|
-
operator: "contains",
|
|
31491
|
-
value: "Attack detected [SQLI]"
|
|
31492
|
-
},
|
|
31833
|
+
match: { field: "attack_type", operator: "equals", value: "sqli", and: [AT_CRS_THRESHOLD] },
|
|
31493
31834
|
threshold: 1,
|
|
31494
31835
|
window_seconds: 60,
|
|
31495
31836
|
cooldown_seconds: 300,
|
|
31496
31837
|
tags: ["web", "sqli", "injection"],
|
|
31497
31838
|
remediation: {
|
|
31498
31839
|
action: "block",
|
|
31499
|
-
ttl_seconds: 3600,
|
|
31500
31840
|
description: "Block source IP performing SQL injection"
|
|
31501
31841
|
},
|
|
31502
31842
|
enabled: true
|
|
@@ -31507,20 +31847,15 @@ var DEFAULT_RULES = [
|
|
|
31507
31847
|
description: "HTTP request with path traversal patterns",
|
|
31508
31848
|
version: "1.0.0",
|
|
31509
31849
|
category: "web",
|
|
31510
|
-
severity: "
|
|
31850
|
+
severity: "high",
|
|
31511
31851
|
source_types: ["log-watcher", "web"],
|
|
31512
|
-
match: {
|
|
31513
|
-
field: "message",
|
|
31514
|
-
operator: "contains",
|
|
31515
|
-
value: "Attack detected [PATH_TRAVERSAL]"
|
|
31516
|
-
},
|
|
31852
|
+
match: { field: "attack_type", operator: "equals", value: "path_traversal", and: [AT_CRS_THRESHOLD] },
|
|
31517
31853
|
threshold: 1,
|
|
31518
31854
|
window_seconds: 60,
|
|
31519
31855
|
cooldown_seconds: 300,
|
|
31520
31856
|
tags: ["web", "path-traversal", "lfi"],
|
|
31521
31857
|
remediation: {
|
|
31522
31858
|
action: "block",
|
|
31523
|
-
ttl_seconds: 3600,
|
|
31524
31859
|
description: "Block source IP performing path traversal"
|
|
31525
31860
|
},
|
|
31526
31861
|
enabled: true
|
|
@@ -31533,22 +31868,39 @@ var DEFAULT_RULES = [
|
|
|
31533
31868
|
category: "web",
|
|
31534
31869
|
severity: "high",
|
|
31535
31870
|
source_types: ["log-watcher", "web"],
|
|
31536
|
-
match: {
|
|
31537
|
-
field: "message",
|
|
31538
|
-
operator: "regex",
|
|
31539
|
-
value: "Attack detected \\[XSS\\]"
|
|
31540
|
-
},
|
|
31871
|
+
match: { field: "attack_type", operator: "equals", value: "xss", and: [AT_CRS_THRESHOLD] },
|
|
31541
31872
|
threshold: 1,
|
|
31542
31873
|
window_seconds: 60,
|
|
31543
31874
|
cooldown_seconds: 300,
|
|
31544
31875
|
tags: ["web", "xss", "injection"],
|
|
31545
31876
|
remediation: {
|
|
31546
31877
|
action: "block",
|
|
31547
|
-
ttl_seconds: 3600,
|
|
31548
31878
|
description: "Block source IP performing XSS attack"
|
|
31549
31879
|
},
|
|
31550
31880
|
enabled: true
|
|
31551
31881
|
},
|
|
31882
|
+
{
|
|
31883
|
+
// CRS 913100: the User-Agent names a security scanner or attack tool
|
|
31884
|
+
// (sqlmap, nikto, nuclei, …). One request is enough, like the rules above;
|
|
31885
|
+
// `web-scanner-detection` is the volume rule for scanners that hide theirs.
|
|
31886
|
+
id: "web-scanner-user-agent",
|
|
31887
|
+
title: "Attack Tool User-Agent Detected",
|
|
31888
|
+
description: "HTTP request from a known vulnerability scanner or attack tool",
|
|
31889
|
+
version: "1.0.0",
|
|
31890
|
+
category: "web",
|
|
31891
|
+
severity: "high",
|
|
31892
|
+
source_types: ["log-watcher", "web"],
|
|
31893
|
+
match: { field: "attack_type", operator: "equals", value: "scanner", and: [AT_CRS_THRESHOLD] },
|
|
31894
|
+
threshold: 1,
|
|
31895
|
+
window_seconds: 60,
|
|
31896
|
+
cooldown_seconds: 300,
|
|
31897
|
+
tags: ["web", "scanner", "reconnaissance"],
|
|
31898
|
+
remediation: {
|
|
31899
|
+
action: "block",
|
|
31900
|
+
description: "Block source IP running a known attack tool"
|
|
31901
|
+
},
|
|
31902
|
+
enabled: true
|
|
31903
|
+
},
|
|
31552
31904
|
{
|
|
31553
31905
|
id: "web-scanner-detection",
|
|
31554
31906
|
title: "Web Vulnerability Scanner Detected",
|
|
@@ -31568,7 +31920,6 @@ var DEFAULT_RULES = [
|
|
|
31568
31920
|
tags: ["web", "scanner", "reconnaissance"],
|
|
31569
31921
|
remediation: {
|
|
31570
31922
|
action: "block",
|
|
31571
|
-
ttl_seconds: 1800,
|
|
31572
31923
|
description: "Block automated scanner"
|
|
31573
31924
|
},
|
|
31574
31925
|
enabled: true
|
|
@@ -31658,7 +32009,6 @@ var DEFAULT_RULES = [
|
|
|
31658
32009
|
tags: ["network", "port-scan", "reconnaissance"],
|
|
31659
32010
|
remediation: {
|
|
31660
32011
|
action: "block",
|
|
31661
|
-
ttl_seconds: 3600,
|
|
31662
32012
|
description: "Block port scanner"
|
|
31663
32013
|
},
|
|
31664
32014
|
enabled: true
|
|
@@ -31690,10 +32040,13 @@ var DEFAULT_RULES = [
|
|
|
31690
32040
|
category: "web",
|
|
31691
32041
|
severity: "high",
|
|
31692
32042
|
source_types: ["log-watcher", "web"],
|
|
32043
|
+
// CRS files command injection under `rce`. There is no XXE type: an
|
|
32044
|
+
// access log never shows the request body an XXE payload lives in.
|
|
31693
32045
|
match: {
|
|
31694
|
-
field: "
|
|
32046
|
+
field: "attack_type",
|
|
31695
32047
|
operator: "regex",
|
|
31696
|
-
value: "
|
|
32048
|
+
value: "^(rce|ssrf|rfi|php_injection|ssti)$",
|
|
32049
|
+
and: [AT_CRS_THRESHOLD]
|
|
31697
32050
|
},
|
|
31698
32051
|
threshold: 1,
|
|
31699
32052
|
window_seconds: 60,
|
|
@@ -31701,7 +32054,6 @@ var DEFAULT_RULES = [
|
|
|
31701
32054
|
tags: ["web", "exploit", "probe"],
|
|
31702
32055
|
remediation: {
|
|
31703
32056
|
action: "block",
|
|
31704
|
-
ttl_seconds: 7200,
|
|
31705
32057
|
description: "Block source IP performing exploit probes"
|
|
31706
32058
|
},
|
|
31707
32059
|
enabled: true
|
|
@@ -31713,11 +32065,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
31713
32065
|
function loadAllRules(customDir) {
|
|
31714
32066
|
const rules = [...DEFAULT_RULES];
|
|
31715
32067
|
const dir = customDir || RULES_DIR;
|
|
31716
|
-
if ((0,
|
|
31717
|
-
const files = (0,
|
|
32068
|
+
if ((0, import_node_fs25.existsSync)(dir)) {
|
|
32069
|
+
const files = (0, import_node_fs25.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
31718
32070
|
for (const file of files) {
|
|
31719
32071
|
try {
|
|
31720
|
-
const raw = (0,
|
|
32072
|
+
const raw = (0, import_node_fs25.readFileSync)((0, import_node_path18.join)(dir, file), "utf-8");
|
|
31721
32073
|
const parsed = JSON.parse(raw);
|
|
31722
32074
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
31723
32075
|
for (const rule of customRules) {
|
|
@@ -31725,6 +32077,13 @@ function loadAllRules(customDir) {
|
|
|
31725
32077
|
console.warn(`[rules] skipping invalid rule in ${file}: missing required fields`);
|
|
31726
32078
|
continue;
|
|
31727
32079
|
}
|
|
32080
|
+
if (rule.remediation && typeof rule.remediation === "object" && "ttl_seconds" in rule.remediation) {
|
|
32081
|
+
console.warn(
|
|
32082
|
+
`[rules] ${rule.id} (${file}): remediation.ttl_seconds is ignored; ban length follows the escalation ladder, see auto-defence.md`
|
|
32083
|
+
);
|
|
32084
|
+
const { ttl_seconds: _ignored, ...remediation } = rule.remediation;
|
|
32085
|
+
rule.remediation = remediation;
|
|
32086
|
+
}
|
|
31728
32087
|
const existingIdx = rules.findIndex((r) => r.id === rule.id);
|
|
31729
32088
|
if (existingIdx >= 0) {
|
|
31730
32089
|
rules[existingIdx] = { ...rules[existingIdx], ...rule };
|
|
@@ -31742,8 +32101,8 @@ function loadAllRules(customDir) {
|
|
|
31742
32101
|
|
|
31743
32102
|
// src/daemon/firewall/adapters.ts
|
|
31744
32103
|
var import_node_child_process7 = require("child_process");
|
|
31745
|
-
var
|
|
31746
|
-
var
|
|
32104
|
+
var import_node_fs26 = require("fs");
|
|
32105
|
+
var import_node_path19 = require("path");
|
|
31747
32106
|
var import_node_net3 = require("net");
|
|
31748
32107
|
function assertValidFirewallIp(ip) {
|
|
31749
32108
|
if ((0, import_node_net3.isIP)(ip) !== 4) {
|
|
@@ -31756,9 +32115,9 @@ function assertBannableIp(ip) {
|
|
|
31756
32115
|
}
|
|
31757
32116
|
}
|
|
31758
32117
|
function writeIfAbsent(path, contents) {
|
|
31759
|
-
(0,
|
|
32118
|
+
(0, import_node_fs26.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
|
|
31760
32119
|
try {
|
|
31761
|
-
(0,
|
|
32120
|
+
(0, import_node_fs26.writeFileSync)(path, contents, { flag: "wx" });
|
|
31762
32121
|
} catch (err) {
|
|
31763
32122
|
if (err.code !== "EEXIST") throw err;
|
|
31764
32123
|
}
|
|
@@ -32013,7 +32372,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
32013
32372
|
}
|
|
32014
32373
|
|
|
32015
32374
|
// src/daemon/firewall/remediation.ts
|
|
32016
|
-
var
|
|
32375
|
+
var import_node_fs27 = require("fs");
|
|
32017
32376
|
var import_node_net5 = require("net");
|
|
32018
32377
|
init_paths();
|
|
32019
32378
|
init_backoff();
|
|
@@ -32531,7 +32890,7 @@ var RemediationManager = class {
|
|
|
32531
32890
|
}
|
|
32532
32891
|
logLine(line) {
|
|
32533
32892
|
try {
|
|
32534
|
-
(0,
|
|
32893
|
+
(0, import_node_fs27.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
32535
32894
|
`);
|
|
32536
32895
|
} catch {
|
|
32537
32896
|
}
|
|
@@ -32612,7 +32971,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
32612
32971
|
// src/daemon/index.ts
|
|
32613
32972
|
function readVersion2() {
|
|
32614
32973
|
try {
|
|
32615
|
-
const pkg = JSON.parse((0,
|
|
32974
|
+
const pkg = JSON.parse((0, import_node_fs28.readFileSync)((0, import_node_path20.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
32616
32975
|
return pkg.version || "0.0.0";
|
|
32617
32976
|
} catch {
|
|
32618
32977
|
return "0.0.0";
|
|
@@ -32620,7 +32979,7 @@ function readVersion2() {
|
|
|
32620
32979
|
}
|
|
32621
32980
|
function logLine(line) {
|
|
32622
32981
|
try {
|
|
32623
|
-
(0,
|
|
32982
|
+
(0, import_node_fs28.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
32624
32983
|
`);
|
|
32625
32984
|
} catch {
|
|
32626
32985
|
}
|
|
@@ -32648,7 +33007,7 @@ async function runDaemon() {
|
|
|
32648
33007
|
} catch (err) {
|
|
32649
33008
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
32650
33009
|
}
|
|
32651
|
-
const config = loadConfig((0,
|
|
33010
|
+
const config = loadConfig((0, import_node_fs28.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
32652
33011
|
configureAttackDetection(config.detection);
|
|
32653
33012
|
bus.on("event", (event) => {
|
|
32654
33013
|
logLine(`[event] ${event.severity} ${event.module} ${event.message}`);
|
|
@@ -32754,7 +33113,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
32754
33113
|
function isRoot2() {
|
|
32755
33114
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
32756
33115
|
}
|
|
32757
|
-
var DAEMON_ENTRY = (0,
|
|
33116
|
+
var DAEMON_ENTRY = (0, import_node_path21.join)(__dirname, "daemon.js");
|
|
32758
33117
|
async function daemonForeground() {
|
|
32759
33118
|
await runDaemon();
|
|
32760
33119
|
}
|
|
@@ -32775,7 +33134,7 @@ async function daemonStart() {
|
|
|
32775
33134
|
return;
|
|
32776
33135
|
}
|
|
32777
33136
|
ensureRuntimeDirs();
|
|
32778
|
-
if (!(0,
|
|
33137
|
+
if (!(0, import_node_fs29.existsSync)(DAEMON_ENTRY)) {
|
|
32779
33138
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
32780
33139
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
32781
33140
|
return;
|
|
@@ -32783,8 +33142,8 @@ async function daemonStart() {
|
|
|
32783
33142
|
let out;
|
|
32784
33143
|
let err;
|
|
32785
33144
|
try {
|
|
32786
|
-
out = (0,
|
|
32787
|
-
err = (0,
|
|
33145
|
+
out = (0, import_node_fs30.openSync)(PATHS.logFile, "a");
|
|
33146
|
+
err = (0, import_node_fs30.openSync)(PATHS.logFile, "a");
|
|
32788
33147
|
} catch (e) {
|
|
32789
33148
|
const code = e.code;
|
|
32790
33149
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -32870,12 +33229,12 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
32870
33229
|
}
|
|
32871
33230
|
async function releaseStaleSocket() {
|
|
32872
33231
|
const deadline = Date.now() + 2e3;
|
|
32873
|
-
while ((0,
|
|
33232
|
+
while ((0, import_node_fs29.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
32874
33233
|
await new Promise((r) => setTimeout(r, 50));
|
|
32875
33234
|
}
|
|
32876
|
-
if ((0,
|
|
33235
|
+
if ((0, import_node_fs29.existsSync)(PATHS.socket)) {
|
|
32877
33236
|
try {
|
|
32878
|
-
(0,
|
|
33237
|
+
(0, import_node_fs29.unlinkSync)(PATHS.socket);
|
|
32879
33238
|
} catch {
|
|
32880
33239
|
}
|
|
32881
33240
|
}
|
|
@@ -32883,25 +33242,25 @@ async function releaseStaleSocket() {
|
|
|
32883
33242
|
|
|
32884
33243
|
// src/commands/service.ts
|
|
32885
33244
|
var import_node_child_process10 = require("child_process");
|
|
32886
|
-
var
|
|
32887
|
-
var
|
|
33245
|
+
var import_node_fs31 = require("fs");
|
|
33246
|
+
var import_node_path22 = require("path");
|
|
32888
33247
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
32889
33248
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
32890
33249
|
function resolveTemplate() {
|
|
32891
|
-
const templatePath = (0,
|
|
32892
|
-
if (!(0,
|
|
33250
|
+
const templatePath = (0, import_node_path22.join)(__dirname, "systemd", "threatcrushd.service");
|
|
33251
|
+
if (!(0, import_node_fs31.existsSync)(templatePath)) {
|
|
32893
33252
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
32894
33253
|
}
|
|
32895
|
-
return (0,
|
|
33254
|
+
return (0, import_node_fs31.readFileSync)(templatePath, "utf-8");
|
|
32896
33255
|
}
|
|
32897
33256
|
function stableBinPath(binPath) {
|
|
32898
33257
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
32899
33258
|
if (stable === binPath) return binPath;
|
|
32900
|
-
return (0,
|
|
33259
|
+
return (0, import_node_fs31.existsSync)(stable) ? stable : binPath;
|
|
32901
33260
|
}
|
|
32902
33261
|
function resolveBinPath() {
|
|
32903
33262
|
const arg = process.argv[1];
|
|
32904
|
-
if (arg && (0,
|
|
33263
|
+
if (arg && (0, import_node_fs31.existsSync)(arg)) return stableBinPath(arg);
|
|
32905
33264
|
try {
|
|
32906
33265
|
return (0, import_node_child_process10.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
32907
33266
|
} catch {
|
|
@@ -32911,11 +33270,11 @@ function resolveBinPath() {
|
|
|
32911
33270
|
function stableNodePath(execPath) {
|
|
32912
33271
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
32913
33272
|
if (stable === execPath) return execPath;
|
|
32914
|
-
return (0,
|
|
33273
|
+
return (0, import_node_fs31.existsSync)(stable) ? stable : execPath;
|
|
32915
33274
|
}
|
|
32916
33275
|
function looksLikeNodeScript(path) {
|
|
32917
33276
|
try {
|
|
32918
|
-
const head = (0,
|
|
33277
|
+
const head = (0, import_node_fs31.readFileSync)(path, "utf-8").slice(0, 120);
|
|
32919
33278
|
return /^#!.*\bnode\b/.test(head);
|
|
32920
33279
|
} catch {
|
|
32921
33280
|
return false;
|
|
@@ -32941,7 +33300,7 @@ function callerHome() {
|
|
|
32941
33300
|
try {
|
|
32942
33301
|
const line = (0, import_node_child_process10.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
32943
33302
|
const home = line.split(":")[5];
|
|
32944
|
-
return home && (0,
|
|
33303
|
+
return home && (0, import_node_fs31.existsSync)(home) ? home : null;
|
|
32945
33304
|
} catch {
|
|
32946
33305
|
return null;
|
|
32947
33306
|
}
|
|
@@ -32949,13 +33308,13 @@ function callerHome() {
|
|
|
32949
33308
|
function stopUserModeDaemon() {
|
|
32950
33309
|
const home = callerHome();
|
|
32951
33310
|
if (!home) return;
|
|
32952
|
-
const runDir = (0,
|
|
32953
|
-
const pidFile = (0,
|
|
32954
|
-
const socket = (0,
|
|
32955
|
-
if (!(0,
|
|
33311
|
+
const runDir = (0, import_node_path22.join)(home, ".threatcrush", "run");
|
|
33312
|
+
const pidFile = (0, import_node_path22.join)(runDir, "threatcrushd.pid");
|
|
33313
|
+
const socket = (0, import_node_path22.join)(runDir, "threatcrushd.sock");
|
|
33314
|
+
if (!(0, import_node_fs31.existsSync)(pidFile) && !(0, import_node_fs31.existsSync)(socket)) return;
|
|
32956
33315
|
let pid = null;
|
|
32957
33316
|
try {
|
|
32958
|
-
pid = Number.parseInt((0,
|
|
33317
|
+
pid = Number.parseInt((0, import_node_fs31.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
32959
33318
|
} catch {
|
|
32960
33319
|
pid = null;
|
|
32961
33320
|
}
|
|
@@ -32968,7 +33327,7 @@ function stopUserModeDaemon() {
|
|
|
32968
33327
|
}
|
|
32969
33328
|
for (const path of [socket, pidFile]) {
|
|
32970
33329
|
try {
|
|
32971
|
-
if ((0,
|
|
33330
|
+
if ((0, import_node_fs31.existsSync)(path)) (0, import_node_fs31.rmSync)(path);
|
|
32972
33331
|
} catch {
|
|
32973
33332
|
}
|
|
32974
33333
|
}
|
|
@@ -32996,7 +33355,7 @@ async function installServiceCommand() {
|
|
|
32996
33355
|
looksLikeNodeScript(binPath)
|
|
32997
33356
|
);
|
|
32998
33357
|
const unit = resolveTemplate().replace("{{BIN_PATH}} daemon", exec).replace("{{BIN_PATH}}", binPath);
|
|
32999
|
-
(0,
|
|
33358
|
+
(0, import_node_fs31.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
33000
33359
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
33001
33360
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
33002
33361
|
ensureSystemDirs();
|
|
@@ -33032,20 +33391,20 @@ function ensureSystemDirs() {
|
|
|
33032
33391
|
];
|
|
33033
33392
|
let admGid = null;
|
|
33034
33393
|
try {
|
|
33035
|
-
admGid = (0,
|
|
33394
|
+
admGid = (0, import_node_fs31.statSync)("/var/log/auth.log").gid;
|
|
33036
33395
|
} catch {
|
|
33037
33396
|
}
|
|
33038
33397
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
33039
33398
|
try {
|
|
33040
|
-
(0,
|
|
33399
|
+
(0, import_node_fs31.mkdirSync)(path, { recursive: true });
|
|
33041
33400
|
} catch {
|
|
33042
33401
|
}
|
|
33043
33402
|
try {
|
|
33044
33403
|
if (groupWritable && admGid !== null) {
|
|
33045
|
-
(0,
|
|
33404
|
+
(0, import_node_fs31.chmodSync)(path, sticky ? 1533 : 509);
|
|
33046
33405
|
(0, import_node_child_process10.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
33047
33406
|
} else {
|
|
33048
|
-
(0,
|
|
33407
|
+
(0, import_node_fs31.chmodSync)(path, 493);
|
|
33049
33408
|
}
|
|
33050
33409
|
} catch {
|
|
33051
33410
|
}
|
|
@@ -33073,7 +33432,7 @@ async function uninstallServiceCommand() {
|
|
|
33073
33432
|
} catch {
|
|
33074
33433
|
}
|
|
33075
33434
|
try {
|
|
33076
|
-
if ((0,
|
|
33435
|
+
if ((0, import_node_fs31.existsSync)(UNIT_PATH)) {
|
|
33077
33436
|
(0, import_node_child_process10.execSync)(`rm -f ${UNIT_PATH}`);
|
|
33078
33437
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
33079
33438
|
}
|
|
@@ -33171,8 +33530,8 @@ function welcomeCommand() {
|
|
|
33171
33530
|
}
|
|
33172
33531
|
|
|
33173
33532
|
// src/commands/properties.ts
|
|
33174
|
-
var
|
|
33175
|
-
var
|
|
33533
|
+
var import_node_fs32 = require("fs");
|
|
33534
|
+
var import_node_path23 = require("path");
|
|
33176
33535
|
var import_node_readline6 = __toESM(require("readline"));
|
|
33177
33536
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
33178
33537
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
@@ -33501,8 +33860,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
33501
33860
|
}
|
|
33502
33861
|
}
|
|
33503
33862
|
function parseImportFile(path) {
|
|
33504
|
-
const ext = (0,
|
|
33505
|
-
const raw = (0,
|
|
33863
|
+
const ext = (0, import_node_path23.extname)(path).toLowerCase();
|
|
33864
|
+
const raw = (0, import_node_fs32.readFileSync)(path, "utf-8");
|
|
33506
33865
|
if (ext === ".json") {
|
|
33507
33866
|
const parsed = JSON.parse(raw);
|
|
33508
33867
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -33660,13 +34019,18 @@ async function rulesShowCommand(ruleId) {
|
|
|
33660
34019
|
console.log(` Enabled: ${rule.enabled ? source_default.green("yes") : source_default.red("no")}`);
|
|
33661
34020
|
if (rule.remediation) {
|
|
33662
34021
|
console.log(` Remediation: ${source_default.gray(rule.remediation.description || rule.remediation.action || "none")}`);
|
|
33663
|
-
if (rule.remediation.
|
|
33664
|
-
console.log(`
|
|
34022
|
+
if (rule.remediation.action === "block") {
|
|
34023
|
+
console.log(` Ban length: ${source_default.gray("escalation ladder, 1m \u2192 2m \u2192 3m \u2192 5m \u2192 8m \u2026 up to max_ban")}`);
|
|
33665
34024
|
}
|
|
33666
34025
|
}
|
|
33667
34026
|
console.log();
|
|
33668
34027
|
console.log(source_default.gray(" Match condition:"));
|
|
33669
|
-
|
|
34028
|
+
const show = (m, prefix, depth) => {
|
|
34029
|
+
console.log(source_default.gray(`${" ".repeat(depth + 2)}${prefix}${m.field} ${m.operator} "${m.value}"`));
|
|
34030
|
+
for (const sub of m.and ?? []) show(sub, "and ", depth + 1);
|
|
34031
|
+
for (const sub of m.or ?? []) show(sub, "or ", depth + 1);
|
|
34032
|
+
};
|
|
34033
|
+
show(rule.match, "", 0);
|
|
33670
34034
|
console.log();
|
|
33671
34035
|
}
|
|
33672
34036
|
async function rulesCommand(opts) {
|
|
@@ -33692,7 +34056,7 @@ async function rulesCommand(opts) {
|
|
|
33692
34056
|
}
|
|
33693
34057
|
|
|
33694
34058
|
// src/commands/harden.ts
|
|
33695
|
-
var
|
|
34059
|
+
var import_node_fs33 = require("fs");
|
|
33696
34060
|
var import_node_child_process11 = require("child_process");
|
|
33697
34061
|
function tryExec(cmd) {
|
|
33698
34062
|
try {
|
|
@@ -33703,7 +34067,7 @@ function tryExec(cmd) {
|
|
|
33703
34067
|
}
|
|
33704
34068
|
function tryRead(path) {
|
|
33705
34069
|
try {
|
|
33706
|
-
return (0,
|
|
34070
|
+
return (0, import_node_fs33.readFileSync)(path, "utf-8");
|
|
33707
34071
|
} catch {
|
|
33708
34072
|
return null;
|
|
33709
34073
|
}
|
|
@@ -33807,8 +34171,8 @@ function checkSshWeakConfig() {
|
|
|
33807
34171
|
};
|
|
33808
34172
|
}
|
|
33809
34173
|
function checkAutoUpdates() {
|
|
33810
|
-
const unattended = (0,
|
|
33811
|
-
const dnfAuto = (0,
|
|
34174
|
+
const unattended = (0, import_node_fs33.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs33.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
34175
|
+
const dnfAuto = (0, import_node_fs33.existsSync)("/etc/dnf/automatic.conf");
|
|
33812
34176
|
if (unattended || dnfAuto) {
|
|
33813
34177
|
return {
|
|
33814
34178
|
key: "auto-updates",
|
|
@@ -33934,7 +34298,7 @@ function checkFail2ban() {
|
|
|
33934
34298
|
explanation: "fail2ban is installed and running."
|
|
33935
34299
|
};
|
|
33936
34300
|
}
|
|
33937
|
-
if ((0,
|
|
34301
|
+
if ((0, import_node_fs33.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
33938
34302
|
return {
|
|
33939
34303
|
key: checkKey,
|
|
33940
34304
|
status: "warn",
|
|
@@ -34347,7 +34711,7 @@ ${source_default.dim(" C R U S H")}
|
|
|
34347
34711
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
34348
34712
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
34349
34713
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
34350
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
34714
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
|
|
34351
34715
|
function detectPackageManager() {
|
|
34352
34716
|
try {
|
|
34353
34717
|
const npmGlobal = (0, import_node_child_process13.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
@@ -34373,7 +34737,7 @@ function detectPackageManager() {
|
|
|
34373
34737
|
}
|
|
34374
34738
|
function readInstallConfig() {
|
|
34375
34739
|
try {
|
|
34376
|
-
return JSON.parse((0,
|
|
34740
|
+
return JSON.parse((0, import_node_fs34.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
34377
34741
|
} catch {
|
|
34378
34742
|
return {};
|
|
34379
34743
|
}
|
|
@@ -34637,7 +35001,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
34637
35001
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
34638
35002
|
console.log(LOGO2);
|
|
34639
35003
|
const logPath = PATHS.logFile;
|
|
34640
|
-
if (!(0,
|
|
35004
|
+
if (!(0, import_node_fs34.existsSync)(logPath)) {
|
|
34641
35005
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
34642
35006
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
34643
35007
|
return;
|
|
@@ -34845,10 +35209,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
34845
35209
|
});
|
|
34846
35210
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
34847
35211
|
console.log(LOGO2);
|
|
34848
|
-
const configPath = (0,
|
|
35212
|
+
const configPath = (0, import_node_path24.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
|
|
34849
35213
|
let email = "";
|
|
34850
35214
|
try {
|
|
34851
|
-
const config = JSON.parse((0,
|
|
35215
|
+
const config = JSON.parse((0, import_node_fs34.readFileSync)(configPath, "utf-8"));
|
|
34852
35216
|
email = config.email || "";
|
|
34853
35217
|
} catch {
|
|
34854
35218
|
}
|
|
@@ -34865,9 +35229,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
34865
35229
|
return;
|
|
34866
35230
|
}
|
|
34867
35231
|
try {
|
|
34868
|
-
const dir = (0,
|
|
34869
|
-
if (!(0,
|
|
34870
|
-
(0,
|
|
35232
|
+
const dir = (0, import_node_path24.join)((0, import_node_os8.homedir)(), ".threatcrush");
|
|
35233
|
+
if (!(0, import_node_fs34.existsSync)(dir)) (0, import_node_fs34.mkdirSync)(dir, { recursive: true });
|
|
35234
|
+
(0, import_node_fs34.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
34871
35235
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
34872
35236
|
} catch {
|
|
34873
35237
|
}
|