@profullstack/threatcrush 0.13.6 → 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 +765 -374
- 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();
|
|
@@ -12672,12 +12687,21 @@ function initialState(now = Date.now()) {
|
|
|
12672
12687
|
notice: null,
|
|
12673
12688
|
busy: false,
|
|
12674
12689
|
moduleIndex: 0,
|
|
12675
|
-
moduleFilter: null
|
|
12690
|
+
moduleFilter: null,
|
|
12691
|
+
showNoise: false
|
|
12676
12692
|
};
|
|
12677
12693
|
}
|
|
12694
|
+
function isNoise(event) {
|
|
12695
|
+
return (event.severity === "low" || event.severity === "info") && /^Client error 4\d\d:/.test(event.message);
|
|
12696
|
+
}
|
|
12678
12697
|
function visibleEvents(state) {
|
|
12679
|
-
|
|
12680
|
-
|
|
12698
|
+
return state.events.filter(
|
|
12699
|
+
(e) => (!state.moduleFilter || e.module === state.moduleFilter) && (state.showNoise || !isNoise(e))
|
|
12700
|
+
);
|
|
12701
|
+
}
|
|
12702
|
+
function hiddenNoise(state) {
|
|
12703
|
+
if (state.showNoise) return 0;
|
|
12704
|
+
return state.events.filter((e) => (!state.moduleFilter || e.module === state.moduleFilter) && isNoise(e)).length;
|
|
12681
12705
|
}
|
|
12682
12706
|
function isBanned(state, ip) {
|
|
12683
12707
|
return state.bans.some((b) => b.ip === ip);
|
|
@@ -12814,6 +12838,8 @@ function reducer(state, action) {
|
|
|
12814
12838
|
}
|
|
12815
12839
|
case "clear_module_filter":
|
|
12816
12840
|
return { ...state, moduleFilter: null, scrollBack: 0 };
|
|
12841
|
+
case "toggle_noise":
|
|
12842
|
+
return { ...state, showNoise: !state.showNoise, scrollBack: 0 };
|
|
12817
12843
|
case "counters":
|
|
12818
12844
|
return {
|
|
12819
12845
|
...state,
|
|
@@ -12847,7 +12873,8 @@ function reducer(state, action) {
|
|
|
12847
12873
|
firewall: state.firewall,
|
|
12848
12874
|
focus: state.focus,
|
|
12849
12875
|
moduleFilter: state.moduleFilter,
|
|
12850
|
-
moduleIndex: state.moduleIndex
|
|
12876
|
+
moduleIndex: state.moduleIndex,
|
|
12877
|
+
showNoise: state.showNoise
|
|
12851
12878
|
};
|
|
12852
12879
|
}
|
|
12853
12880
|
}
|
|
@@ -13142,6 +13169,10 @@ function severityPanel(parent, state, theme) {
|
|
|
13142
13169
|
}
|
|
13143
13170
|
);
|
|
13144
13171
|
}
|
|
13172
|
+
function noiseNote(state) {
|
|
13173
|
+
const hidden = hiddenNoise(state);
|
|
13174
|
+
return hidden > 0 ? `${hidden} routine 4xx hidden \xB7 n shows` : void 0;
|
|
13175
|
+
}
|
|
13145
13176
|
function feedPanel(parent, state, theme, options) {
|
|
13146
13177
|
const following = state.scrollBack === 0;
|
|
13147
13178
|
const shown = visibleEvents(state);
|
|
@@ -13153,7 +13184,7 @@ function feedPanel(parent, state, theme, options) {
|
|
|
13153
13184
|
border: "rounded",
|
|
13154
13185
|
borderColor: state.connection === "live" ? theme.borderFocused : theme.border,
|
|
13155
13186
|
titleColor: theme.primary,
|
|
13156
|
-
subtitle: filtered ? `${shown.length}/${state.events.length} \xB7 esc clears filter` : following ?
|
|
13187
|
+
subtitle: filtered ? `${shown.length}/${state.events.length} \xB7 esc clears filter` : following ? noiseNote(state) : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
|
|
13157
13188
|
subtitleColor: filtered ? theme.primary : severityColors.medium,
|
|
13158
13189
|
padding: [0, 1]
|
|
13159
13190
|
},
|
|
@@ -13165,6 +13196,13 @@ function feedPanel(parent, state, theme, options) {
|
|
|
13165
13196
|
panel.label("esc shows everything again", { fg: theme.muted, align: "center" });
|
|
13166
13197
|
return;
|
|
13167
13198
|
}
|
|
13199
|
+
if (!filtered && shown.length === 0 && state.events.length > 0) {
|
|
13200
|
+
panel.spacer(1);
|
|
13201
|
+
panel.text("Nothing but routine 4xx client errors so far.", { fg: theme.muted, align: "center" });
|
|
13202
|
+
panel.spacer(1);
|
|
13203
|
+
panel.label("n shows them", { fg: theme.muted, align: "center" });
|
|
13204
|
+
return;
|
|
13205
|
+
}
|
|
13168
13206
|
if (state.events.length === 0) {
|
|
13169
13207
|
panel.spacer(1);
|
|
13170
13208
|
if (state.connection === "live") {
|
|
@@ -13368,7 +13406,8 @@ function footer(ui, state, theme) {
|
|
|
13368
13406
|
{ key: "\u2191\u2193", label: onFeed ? "scroll" : "select" },
|
|
13369
13407
|
...state.focus === "modules" ? [{ key: "\u23CE", label: state.moduleFilter ? "unfilter" : "filter" }] : [{ key: "b", label: "ban" }, { key: "u", label: "unban" }],
|
|
13370
13408
|
{ key: "p", label: state.paused ? "resume" : "pause" },
|
|
13371
|
-
{ key: "r", label: "reset" }
|
|
13409
|
+
{ key: "r", label: "reset" },
|
|
13410
|
+
{ key: "n", label: state.showNoise ? "hide 4xx" : "show 4xx" }
|
|
13372
13411
|
],
|
|
13373
13412
|
right: [
|
|
13374
13413
|
// The notice is the answer to "did my keypress do anything", so it takes
|
|
@@ -13631,6 +13670,9 @@ async function startDashboard(options = {}) {
|
|
|
13631
13670
|
case "r":
|
|
13632
13671
|
dispatch({ type: "reset" });
|
|
13633
13672
|
break;
|
|
13673
|
+
case "n":
|
|
13674
|
+
dispatch({ type: "toggle_noise" });
|
|
13675
|
+
break;
|
|
13634
13676
|
case "tab":
|
|
13635
13677
|
dispatch({ type: "focus_next" });
|
|
13636
13678
|
break;
|
|
@@ -15870,12 +15912,12 @@ var source_default = chalk;
|
|
|
15870
15912
|
// src/index.ts
|
|
15871
15913
|
var import_readline = __toESM(require("readline"));
|
|
15872
15914
|
var import_node_child_process13 = require("child_process");
|
|
15873
|
-
var
|
|
15874
|
-
var
|
|
15915
|
+
var import_node_fs34 = require("fs");
|
|
15916
|
+
var import_node_path24 = require("path");
|
|
15875
15917
|
var import_node_os8 = require("os");
|
|
15876
15918
|
|
|
15877
15919
|
// src/commands/monitor.ts
|
|
15878
|
-
var
|
|
15920
|
+
var import_node_fs7 = require("fs");
|
|
15879
15921
|
var import_node_readline = require("readline");
|
|
15880
15922
|
|
|
15881
15923
|
// src/core/version.ts
|
|
@@ -20240,6 +20282,31 @@ var CRS_RULES = [
|
|
|
20240
20282
|
"negated": false
|
|
20241
20283
|
}
|
|
20242
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
|
+
},
|
|
20243
20310
|
{
|
|
20244
20311
|
"id": 941110,
|
|
20245
20312
|
"msg": "XSS Filter - Category 1: Script Tag Vector",
|
|
@@ -20926,6 +20993,30 @@ var CRS_RULES = [
|
|
|
20926
20993
|
"negated": false
|
|
20927
20994
|
}
|
|
20928
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
|
+
},
|
|
20929
21020
|
{
|
|
20930
21021
|
"id": 942140,
|
|
20931
21022
|
"msg": "SQL Injection Attack: Common DB Names Detected",
|
|
@@ -21546,6 +21637,31 @@ var CRS_RULES = [
|
|
|
21546
21637
|
}
|
|
21547
21638
|
}
|
|
21548
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
|
+
];
|
|
21549
21665
|
|
|
21550
21666
|
// src/core/crs/transforms.ts
|
|
21551
21667
|
var NBSP = 160;
|
|
@@ -22058,9 +22174,44 @@ var TRANSFORMS = {
|
|
|
22058
22174
|
base64Decode
|
|
22059
22175
|
};
|
|
22060
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
|
+
|
|
22061
22211
|
// src/core/crs/engine.ts
|
|
22062
22212
|
var SEVERITY_POINTS = { CRITICAL: 5, ERROR: 4, WARNING: 3, NOTICE: 2 };
|
|
22063
22213
|
var DEFAULT_ANOMALY_THRESHOLD = 5;
|
|
22214
|
+
var DEFAULT_EXCLUDED_RULE_IDS = [941130];
|
|
22064
22215
|
var ATTACK_TYPES = {
|
|
22065
22216
|
"attack-sqli": "sqli",
|
|
22066
22217
|
"attack-xss": "xss",
|
|
@@ -22073,6 +22224,9 @@ var ATTACK_TYPES = {
|
|
|
22073
22224
|
"attack-reputation-scanner": "scanner",
|
|
22074
22225
|
"attack-injection-generic": "injection"
|
|
22075
22226
|
};
|
|
22227
|
+
function crsAttackType(rule) {
|
|
22228
|
+
return rule.tags.map((t) => ATTACK_TYPES[t]).find((t) => t !== void 0) ?? null;
|
|
22229
|
+
}
|
|
22076
22230
|
var PhraseMatcher = class {
|
|
22077
22231
|
next = [/* @__PURE__ */ new Map()];
|
|
22078
22232
|
fail = [0];
|
|
@@ -22152,6 +22306,16 @@ function compileOperator(op) {
|
|
|
22152
22306
|
case "within":
|
|
22153
22307
|
test = (v) => op.arg.includes(v);
|
|
22154
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;
|
|
22155
22319
|
}
|
|
22156
22320
|
return op.negated ? (v) => !test(v) : test;
|
|
22157
22321
|
}
|
|
@@ -22270,6 +22434,8 @@ var MEMO_ENTRIES = 1e4;
|
|
|
22270
22434
|
var MEMO_MAX_VALUE = 512;
|
|
22271
22435
|
var CrsEngine = class {
|
|
22272
22436
|
threshold;
|
|
22437
|
+
/** How many rules are loaded, by origin: ported OWASP CRS, and ThreatCrush's own. */
|
|
22438
|
+
ruleCounts;
|
|
22273
22439
|
rules;
|
|
22274
22440
|
/** Unchained rules by the targets they read. */
|
|
22275
22441
|
byTarget = /* @__PURE__ */ new Map();
|
|
@@ -22279,14 +22445,17 @@ var CrsEngine = class {
|
|
|
22279
22445
|
memoSize = 0;
|
|
22280
22446
|
constructor(options = {}) {
|
|
22281
22447
|
this.threshold = options.threshold ?? DEFAULT_ANOMALY_THRESHOLD;
|
|
22282
|
-
const excluded = new Set(options.excludeRuleIds ??
|
|
22283
|
-
|
|
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) => ({
|
|
22284
22453
|
index,
|
|
22285
22454
|
rule,
|
|
22286
22455
|
test: compileOperator(rule.op),
|
|
22287
22456
|
stepKeys: rule.transforms.map((_, k) => rule.transforms.slice(0, k + 1).join(",")),
|
|
22288
22457
|
chain: (rule.chain ?? []).map((link) => ({ link, test: compileOperator(link.op) })),
|
|
22289
|
-
attackType: rule
|
|
22458
|
+
attackType: crsAttackType(rule)
|
|
22290
22459
|
}));
|
|
22291
22460
|
for (const compiled of this.rules) {
|
|
22292
22461
|
if (compiled.chain.length > 0) {
|
|
@@ -22300,9 +22469,6 @@ var CrsEngine = class {
|
|
|
22300
22469
|
}
|
|
22301
22470
|
}
|
|
22302
22471
|
}
|
|
22303
|
-
get ruleCount() {
|
|
22304
|
-
return this.rules.length;
|
|
22305
|
-
}
|
|
22306
22472
|
slotMatches(target, rules, slot) {
|
|
22307
22473
|
const memoize = slot.value.length <= MEMO_MAX_VALUE;
|
|
22308
22474
|
let memo = this.memo.get(target);
|
|
@@ -22403,20 +22569,36 @@ function parseNginxLog(line) {
|
|
|
22403
22569
|
function parseAuthLog(line) {
|
|
22404
22570
|
const match = line.match(AUTH_REGEX);
|
|
22405
22571
|
if (!match) return null;
|
|
22406
|
-
|
|
22407
|
-
|
|
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);
|
|
22408
22577
|
return {
|
|
22409
|
-
timestamp
|
|
22410
|
-
raw
|
|
22578
|
+
timestamp,
|
|
22579
|
+
raw,
|
|
22411
22580
|
source: "auth",
|
|
22412
22581
|
fields: {
|
|
22413
|
-
process:
|
|
22414
|
-
message
|
|
22582
|
+
process: process10,
|
|
22583
|
+
message,
|
|
22415
22584
|
ip: ipMatch?.[1],
|
|
22416
22585
|
user: userMatch?.[1]
|
|
22417
22586
|
}
|
|
22418
22587
|
};
|
|
22419
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
|
+
}
|
|
22420
22602
|
function parseSyslog(line) {
|
|
22421
22603
|
const match = line.match(SYSLOG_REGEX);
|
|
22422
22604
|
if (!match) return null;
|
|
@@ -22434,9 +22616,13 @@ function parseSyslog(line) {
|
|
|
22434
22616
|
var crsEngine;
|
|
22435
22617
|
function configureAttackDetection(section) {
|
|
22436
22618
|
const threshold = section?.anomaly_threshold;
|
|
22619
|
+
const included = Array.isArray(section?.include_rules) ? section.include_rules.map(Number) : [];
|
|
22437
22620
|
crsEngine = new CrsEngine({
|
|
22438
22621
|
threshold: typeof threshold === "number" && threshold > 0 ? threshold : void 0,
|
|
22439
|
-
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
|
+
]
|
|
22440
22626
|
});
|
|
22441
22627
|
}
|
|
22442
22628
|
function engine() {
|
|
@@ -22491,8 +22677,8 @@ function parseSyslogTimestamp(s) {
|
|
|
22491
22677
|
}
|
|
22492
22678
|
|
|
22493
22679
|
// src/core/config.ts
|
|
22494
|
-
var
|
|
22495
|
-
var
|
|
22680
|
+
var import_node_fs3 = require("fs");
|
|
22681
|
+
var import_node_path3 = require("path");
|
|
22496
22682
|
var import_toml = __toESM(require_toml());
|
|
22497
22683
|
var DEFAULT_CONFIG_PATH = "/etc/threatcrush/threatcrushd.conf";
|
|
22498
22684
|
var DEFAULT_CONFDIR = "/etc/threatcrush/threatcrushd.conf.d";
|
|
@@ -22518,11 +22704,11 @@ var DEFAULT_CONFIG = {
|
|
|
22518
22704
|
};
|
|
22519
22705
|
function loadConfig(configPath) {
|
|
22520
22706
|
const path = configPath || DEFAULT_CONFIG_PATH;
|
|
22521
|
-
if (!(0,
|
|
22707
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
22522
22708
|
return { ...DEFAULT_CONFIG };
|
|
22523
22709
|
}
|
|
22524
22710
|
try {
|
|
22525
|
-
const raw = (0,
|
|
22711
|
+
const raw = (0, import_node_fs3.readFileSync)(path, "utf-8");
|
|
22526
22712
|
const parsed = import_toml.default.parse(raw);
|
|
22527
22713
|
return {
|
|
22528
22714
|
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
@@ -22540,13 +22726,13 @@ function loadConfig(configPath) {
|
|
|
22540
22726
|
function loadModuleConfigs(confDir) {
|
|
22541
22727
|
const dir = confDir || DEFAULT_CONFDIR;
|
|
22542
22728
|
const configs = /* @__PURE__ */ new Map();
|
|
22543
|
-
if (!(0,
|
|
22729
|
+
if (!(0, import_node_fs3.existsSync)(dir)) {
|
|
22544
22730
|
return configs;
|
|
22545
22731
|
}
|
|
22546
|
-
const files = (0,
|
|
22732
|
+
const files = (0, import_node_fs3.readdirSync)(dir).filter((f) => f.endsWith(".conf"));
|
|
22547
22733
|
for (const file of files) {
|
|
22548
22734
|
try {
|
|
22549
|
-
const raw = (0,
|
|
22735
|
+
const raw = (0, import_node_fs3.readFileSync)((0, import_node_path3.join)(dir, file), "utf-8");
|
|
22550
22736
|
const parsed = import_toml.default.parse(raw);
|
|
22551
22737
|
for (const [name, config] of Object.entries(parsed)) {
|
|
22552
22738
|
configs.set(name, config);
|
|
@@ -22749,9 +22935,9 @@ async function monitorCommand(options) {
|
|
|
22749
22935
|
const unreadable = [];
|
|
22750
22936
|
for (const s of LOG_SOURCES) {
|
|
22751
22937
|
if (moduleFilter && !moduleFilter.includes(s.name)) continue;
|
|
22752
|
-
if (!(0,
|
|
22938
|
+
if (!(0, import_node_fs7.existsSync)(s.path)) continue;
|
|
22753
22939
|
try {
|
|
22754
|
-
(0,
|
|
22940
|
+
(0, import_node_fs7.accessSync)(s.path, import_node_fs7.constants.R_OK);
|
|
22755
22941
|
availableSources.push(s);
|
|
22756
22942
|
} catch {
|
|
22757
22943
|
unreadable.push(s);
|
|
@@ -22768,11 +22954,11 @@ async function monitorCommand(options) {
|
|
|
22768
22954
|
logger.warn("No readable log files found to monitor.");
|
|
22769
22955
|
logger.info("Available log paths checked:");
|
|
22770
22956
|
for (const s of LOG_SOURCES) {
|
|
22771
|
-
const exists = (0,
|
|
22957
|
+
const exists = (0, import_node_fs7.existsSync)(s.path);
|
|
22772
22958
|
let readable = false;
|
|
22773
22959
|
if (exists) {
|
|
22774
22960
|
try {
|
|
22775
|
-
(0,
|
|
22961
|
+
(0, import_node_fs7.accessSync)(s.path, import_node_fs7.constants.R_OK);
|
|
22776
22962
|
readable = true;
|
|
22777
22963
|
} catch {
|
|
22778
22964
|
readable = false;
|
|
@@ -22805,16 +22991,16 @@ async function monitorCommand(options) {
|
|
|
22805
22991
|
}
|
|
22806
22992
|
function tailLog(source) {
|
|
22807
22993
|
const { path, name, category } = source;
|
|
22808
|
-
const stat = (0,
|
|
22994
|
+
const stat = (0, import_node_fs7.statSync)(path);
|
|
22809
22995
|
let position = stat.size;
|
|
22810
22996
|
const checkForNewData = () => {
|
|
22811
22997
|
try {
|
|
22812
|
-
const currentStat = (0,
|
|
22998
|
+
const currentStat = (0, import_node_fs7.statSync)(path);
|
|
22813
22999
|
if (currentStat.size <= position) {
|
|
22814
23000
|
if (currentStat.size < position) position = 0;
|
|
22815
23001
|
return;
|
|
22816
23002
|
}
|
|
22817
|
-
const stream = (0,
|
|
23003
|
+
const stream = (0, import_node_fs7.createReadStream)(path, { start: position, encoding: "utf-8" });
|
|
22818
23004
|
stream.on("error", (err) => {
|
|
22819
23005
|
logger.warn(`stopped tailing ${path}: ${err.code || err.message}`);
|
|
22820
23006
|
position = currentStat.size;
|
|
@@ -22931,8 +23117,8 @@ async function runDemoMode() {
|
|
|
22931
23117
|
}
|
|
22932
23118
|
|
|
22933
23119
|
// src/commands/scan.ts
|
|
22934
|
-
var
|
|
22935
|
-
var
|
|
23120
|
+
var import_node_fs10 = require("fs");
|
|
23121
|
+
var import_node_path9 = require("path");
|
|
22936
23122
|
|
|
22937
23123
|
// ../../node_modules/.pnpm/ora@8.2.0/node_modules/ora/index.js
|
|
22938
23124
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
@@ -26846,8 +27032,8 @@ function meetsFailThreshold(findings, threshold) {
|
|
|
26846
27032
|
}
|
|
26847
27033
|
|
|
26848
27034
|
// ../../packages/scan/src/node/walk.ts
|
|
26849
|
-
var
|
|
26850
|
-
var
|
|
27035
|
+
var import_node_fs8 = require("fs");
|
|
27036
|
+
var import_node_path6 = require("path");
|
|
26851
27037
|
function compileExcludes(patterns) {
|
|
26852
27038
|
const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
|
|
26853
27039
|
if (matchers.length === 0) return () => false;
|
|
@@ -26918,7 +27104,7 @@ function matchPrefix(parts, segs) {
|
|
|
26918
27104
|
}
|
|
26919
27105
|
function readIgnoreFile(root) {
|
|
26920
27106
|
try {
|
|
26921
|
-
return (0,
|
|
27107
|
+
return (0, import_node_fs8.readFileSync)((0, import_node_path6.join)(root, ".threatcrushignore"), "utf-8").split("\n");
|
|
26922
27108
|
} catch {
|
|
26923
27109
|
return [];
|
|
26924
27110
|
}
|
|
@@ -26934,16 +27120,16 @@ function scanPath(targetPath, options = {}) {
|
|
|
26934
27120
|
let excluded = 0;
|
|
26935
27121
|
const rootIsDirectory = (() => {
|
|
26936
27122
|
try {
|
|
26937
|
-
return (0,
|
|
27123
|
+
return (0, import_node_fs8.statSync)(targetPath).isDirectory();
|
|
26938
27124
|
} catch {
|
|
26939
27125
|
return true;
|
|
26940
27126
|
}
|
|
26941
27127
|
})();
|
|
26942
|
-
const walkRoot = rootIsDirectory ? targetPath : (0,
|
|
27128
|
+
const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path6.dirname)(targetPath);
|
|
26943
27129
|
const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
|
|
26944
27130
|
const scanFile = (fullPath, filename) => {
|
|
26945
27131
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
26946
|
-
const extension = (0,
|
|
27132
|
+
const extension = (0, import_node_path6.extname)(filename).toLowerCase();
|
|
26947
27133
|
const isManifest = filename === "package.json" || filename === "requirements.txt";
|
|
26948
27134
|
const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
|
|
26949
27135
|
const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
|
|
@@ -26955,26 +27141,26 @@ function scanPath(targetPath, options = {}) {
|
|
|
26955
27141
|
let handle;
|
|
26956
27142
|
let declared = null;
|
|
26957
27143
|
try {
|
|
26958
|
-
handle = (0,
|
|
27144
|
+
handle = (0, import_node_fs8.openSync)(fullPath, "r");
|
|
26959
27145
|
} catch {
|
|
26960
27146
|
unreadable.push(relativePath);
|
|
26961
27147
|
return;
|
|
26962
27148
|
}
|
|
26963
27149
|
try {
|
|
26964
|
-
if ((0,
|
|
27150
|
+
if ((0, import_node_fs8.fstatSync)(handle).size > maxFileBytes) return;
|
|
26965
27151
|
if (mayDeclareInterpreter) {
|
|
26966
27152
|
const prefix = Buffer.alloc(128);
|
|
26967
|
-
const read = (0,
|
|
27153
|
+
const read = (0, import_node_fs8.readSync)(handle, prefix, 0, prefix.length, 0);
|
|
26968
27154
|
declared = languageOfShebang(prefix.subarray(0, read).toString("utf-8").split("\n", 1)[0] ?? "");
|
|
26969
27155
|
if (!declared) return;
|
|
26970
27156
|
}
|
|
26971
|
-
text = (0,
|
|
27157
|
+
text = (0, import_node_fs8.readFileSync)(handle, "utf-8");
|
|
26972
27158
|
} catch {
|
|
26973
27159
|
unreadable.push(relativePath);
|
|
26974
27160
|
return;
|
|
26975
27161
|
} finally {
|
|
26976
27162
|
try {
|
|
26977
|
-
(0,
|
|
27163
|
+
(0, import_node_fs8.closeSync)(handle);
|
|
26978
27164
|
} catch {
|
|
26979
27165
|
}
|
|
26980
27166
|
}
|
|
@@ -26992,13 +27178,13 @@ function scanPath(targetPath, options = {}) {
|
|
|
26992
27178
|
const walk = (currentPath) => {
|
|
26993
27179
|
let entries;
|
|
26994
27180
|
try {
|
|
26995
|
-
entries = (0,
|
|
27181
|
+
entries = (0, import_node_fs8.readdirSync)(currentPath, { withFileTypes: true });
|
|
26996
27182
|
} catch {
|
|
26997
27183
|
unreadable.push(toRelative(walkRoot, currentPath));
|
|
26998
27184
|
return;
|
|
26999
27185
|
}
|
|
27000
27186
|
for (const entry of entries) {
|
|
27001
|
-
const fullPath = (0,
|
|
27187
|
+
const fullPath = (0, import_node_path6.join)(currentPath, entry.name);
|
|
27002
27188
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
27003
27189
|
if (entry.isDirectory()) {
|
|
27004
27190
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
@@ -27022,7 +27208,7 @@ function scanPath(targetPath, options = {}) {
|
|
|
27022
27208
|
} else if (isExcluded(toRelative(walkRoot, targetPath))) {
|
|
27023
27209
|
excluded += 1;
|
|
27024
27210
|
} else {
|
|
27025
|
-
scanFile(targetPath, (0,
|
|
27211
|
+
scanFile(targetPath, (0, import_node_path6.basename)(targetPath));
|
|
27026
27212
|
}
|
|
27027
27213
|
if (options.missingControls) findings.push(...controls.findings());
|
|
27028
27214
|
const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
|
|
@@ -27054,22 +27240,22 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
|
|
|
27054
27240
|
}
|
|
27055
27241
|
}
|
|
27056
27242
|
function toRelative(base, target) {
|
|
27057
|
-
const rel = (0,
|
|
27058
|
-
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("/");
|
|
27059
27245
|
}
|
|
27060
27246
|
|
|
27061
27247
|
// ../../packages/scan/src/node/dependencies.ts
|
|
27062
|
-
var
|
|
27063
|
-
var
|
|
27248
|
+
var import_node_fs9 = require("fs");
|
|
27249
|
+
var import_node_path7 = require("path");
|
|
27064
27250
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
27065
27251
|
async function scanDependencies(targetPath) {
|
|
27066
27252
|
const findings = [];
|
|
27067
27253
|
for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
|
|
27068
|
-
const lockPath = (0,
|
|
27069
|
-
if (!(0,
|
|
27254
|
+
const lockPath = (0, import_node_path7.join)(targetPath, file);
|
|
27255
|
+
if (!(0, import_node_fs9.existsSync)(lockPath)) continue;
|
|
27070
27256
|
let deps;
|
|
27071
27257
|
try {
|
|
27072
|
-
deps = dedupe(parse2((0,
|
|
27258
|
+
deps = dedupe(parse2((0, import_node_fs9.readFileSync)(lockPath, "utf-8")));
|
|
27073
27259
|
} catch {
|
|
27074
27260
|
continue;
|
|
27075
27261
|
}
|
|
@@ -27284,7 +27470,7 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
27284
27470
|
|
|
27285
27471
|
// ../../packages/scan/src/node/sarif.ts
|
|
27286
27472
|
var import_node_crypto2 = require("crypto");
|
|
27287
|
-
var
|
|
27473
|
+
var import_node_path8 = require("path");
|
|
27288
27474
|
var FINGERPRINT_KEY = "threatcrush/contentHash/v1";
|
|
27289
27475
|
function fingerprintOf(finding) {
|
|
27290
27476
|
const content = finding.excerpt.replace(/\s+/g, " ").trim();
|
|
@@ -27322,11 +27508,11 @@ function securitySeverity(severity) {
|
|
|
27322
27508
|
}
|
|
27323
27509
|
}
|
|
27324
27510
|
function toArtifactUri(filePath, base, prefix = "", root = base) {
|
|
27325
|
-
const absolute = (0,
|
|
27326
|
-
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);
|
|
27327
27513
|
const escapedOut = relativePath.startsWith("..") || relativePath === "";
|
|
27328
27514
|
const chosen = escapedOut ? absolute : relativePath;
|
|
27329
|
-
const posix = chosen.split(
|
|
27515
|
+
const posix = chosen.split(import_node_path8.sep).join("/").replace(/^\.\//, "");
|
|
27330
27516
|
if (!prefix || escapedOut) return posix;
|
|
27331
27517
|
const trimmed = prefix.replace(/^\/+|\/+$/g, "");
|
|
27332
27518
|
return trimmed ? `${trimmed}/${posix}` : posix;
|
|
@@ -27416,11 +27602,11 @@ ${finding.consequence}` : `**${finding.title}**`
|
|
|
27416
27602
|
// src/commands/scan.ts
|
|
27417
27603
|
function readVersion() {
|
|
27418
27604
|
for (const candidate of [
|
|
27419
|
-
(0,
|
|
27420
|
-
(0,
|
|
27605
|
+
(0, import_node_path9.join)(__dirname, "..", "package.json"),
|
|
27606
|
+
(0, import_node_path9.join)(__dirname, "..", "..", "package.json")
|
|
27421
27607
|
]) {
|
|
27422
27608
|
try {
|
|
27423
|
-
return JSON.parse((0,
|
|
27609
|
+
return JSON.parse((0, import_node_fs10.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
|
|
27424
27610
|
} catch {
|
|
27425
27611
|
}
|
|
27426
27612
|
}
|
|
@@ -27487,7 +27673,7 @@ async function scanCommand(targetPath, options = {}) {
|
|
|
27487
27673
|
const say = machineReadable ? (line) => process.stderr.write(`${line}
|
|
27488
27674
|
`) : (line) => process.stdout.write(`${line}
|
|
27489
27675
|
`);
|
|
27490
|
-
if (!(0,
|
|
27676
|
+
if (!(0, import_node_fs10.existsSync)(targetPath)) {
|
|
27491
27677
|
say(source_default.red(`Scan target does not exist: ${targetPath}`));
|
|
27492
27678
|
process.exitCode = 2;
|
|
27493
27679
|
return failedResult(targetPath, `no such path: ${targetPath}`);
|
|
@@ -27583,7 +27769,7 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
27583
27769
|
// and it fails silently. `--path-prefix` covers the remaining case:
|
|
27584
27770
|
// a scan run from inside the subdirectory it is scanning.
|
|
27585
27771
|
base: process.cwd(),
|
|
27586
|
-
root: (0,
|
|
27772
|
+
root: (0, import_node_path9.resolve)(outcome.root)
|
|
27587
27773
|
}) : {
|
|
27588
27774
|
tool: "threatcrush",
|
|
27589
27775
|
version: PKG_VERSION2,
|
|
@@ -27597,8 +27783,8 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
27597
27783
|
const serialized = `${JSON.stringify(payload, null, 2)}
|
|
27598
27784
|
`;
|
|
27599
27785
|
if (options.output) {
|
|
27600
|
-
(0,
|
|
27601
|
-
(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");
|
|
27602
27788
|
say(
|
|
27603
27789
|
source_default.gray(
|
|
27604
27790
|
` ${format.toUpperCase()} written to ${options.output} (${outcome.findings.length} finding(s))`
|
|
@@ -27650,28 +27836,28 @@ function printHuman(outcome) {
|
|
|
27650
27836
|
}
|
|
27651
27837
|
|
|
27652
27838
|
// src/commands/init.ts
|
|
27653
|
-
var
|
|
27839
|
+
var import_node_fs12 = require("fs");
|
|
27654
27840
|
var import_node_child_process = require("child_process");
|
|
27655
27841
|
var import_node_readline3 = __toESM(require("readline"));
|
|
27656
27842
|
|
|
27657
27843
|
// src/core/cli-config.ts
|
|
27658
|
-
var
|
|
27659
|
-
var
|
|
27844
|
+
var import_node_fs11 = require("fs");
|
|
27845
|
+
var import_node_path10 = require("path");
|
|
27660
27846
|
var import_node_os4 = require("os");
|
|
27661
|
-
var CLI_CONFIG_DIR = (0,
|
|
27662
|
-
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");
|
|
27663
27849
|
function readCliConfig() {
|
|
27664
27850
|
try {
|
|
27665
|
-
return JSON.parse((0,
|
|
27851
|
+
return JSON.parse((0, import_node_fs11.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
|
|
27666
27852
|
} catch {
|
|
27667
27853
|
return {};
|
|
27668
27854
|
}
|
|
27669
27855
|
}
|
|
27670
27856
|
function writeCliConfig(config) {
|
|
27671
|
-
if (!(0,
|
|
27672
|
-
(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");
|
|
27673
27859
|
try {
|
|
27674
|
-
(0,
|
|
27860
|
+
(0, import_node_fs11.chmodSync)(CLI_CONFIG_PATH, 384);
|
|
27675
27861
|
} catch {
|
|
27676
27862
|
}
|
|
27677
27863
|
}
|
|
@@ -27916,7 +28102,7 @@ function binaryExists(name) {
|
|
|
27916
28102
|
}
|
|
27917
28103
|
}
|
|
27918
28104
|
function findLogPath(paths) {
|
|
27919
|
-
return paths.find((p) => (0,
|
|
28105
|
+
return paths.find((p) => (0, import_node_fs12.existsSync)(p));
|
|
27920
28106
|
}
|
|
27921
28107
|
async function promptYesNo(question, fallback2) {
|
|
27922
28108
|
const rl = import_node_readline3.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -28032,11 +28218,11 @@ async function initCommand() {
|
|
|
28032
28218
|
}
|
|
28033
28219
|
} else {
|
|
28034
28220
|
const spinner2 = ora({ text: "Writing configuration files...", color: "green" }).start();
|
|
28035
|
-
(0,
|
|
28036
|
-
(0,
|
|
28037
|
-
(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 });
|
|
28038
28224
|
const mainConfig = generateDefaultConfig(detected.map((d) => d.name));
|
|
28039
|
-
(0,
|
|
28225
|
+
(0, import_node_fs12.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
|
|
28040
28226
|
for (const svc of detected) {
|
|
28041
28227
|
const svcDef = SERVICES_TO_DETECT.find((s) => s.name === svc.name);
|
|
28042
28228
|
if (!svcDef) continue;
|
|
@@ -28045,7 +28231,7 @@ async function initCommand() {
|
|
|
28045
28231
|
...svcDef.moduleConfig,
|
|
28046
28232
|
log_path: svc.logPath || svcDef.logPaths[0]
|
|
28047
28233
|
});
|
|
28048
|
-
(0,
|
|
28234
|
+
(0, import_node_fs12.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
|
|
28049
28235
|
}
|
|
28050
28236
|
spinner2.succeed("Configuration written successfully");
|
|
28051
28237
|
console.log();
|
|
@@ -28063,8 +28249,8 @@ async function initCommand() {
|
|
|
28063
28249
|
}
|
|
28064
28250
|
function checkWriteAccess(dir) {
|
|
28065
28251
|
try {
|
|
28066
|
-
if (!(0,
|
|
28067
|
-
(0,
|
|
28252
|
+
if (!(0, import_node_fs12.existsSync)(dir)) {
|
|
28253
|
+
(0, import_node_fs12.mkdirSync)(dir, { recursive: true });
|
|
28068
28254
|
}
|
|
28069
28255
|
return true;
|
|
28070
28256
|
} catch {
|
|
@@ -28073,8 +28259,8 @@ function checkWriteAccess(dir) {
|
|
|
28073
28259
|
}
|
|
28074
28260
|
|
|
28075
28261
|
// src/core/module-loader.ts
|
|
28076
|
-
var
|
|
28077
|
-
var
|
|
28262
|
+
var import_node_fs13 = require("fs");
|
|
28263
|
+
var import_node_path11 = require("path");
|
|
28078
28264
|
var import_toml2 = __toESM(require_toml());
|
|
28079
28265
|
init_paths();
|
|
28080
28266
|
function discoverModules(moduleDir, confDir) {
|
|
@@ -28082,22 +28268,22 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28082
28268
|
const configs = loadModuleConfigs(confDir || PATHS.confD);
|
|
28083
28269
|
const searchPaths = [
|
|
28084
28270
|
moduleDir || PATHS.moduleDir,
|
|
28085
|
-
(0,
|
|
28271
|
+
(0, import_node_path11.resolve)(process.cwd(), "modules")
|
|
28086
28272
|
];
|
|
28087
|
-
const builtinDir = (0,
|
|
28088
|
-
if ((0,
|
|
28273
|
+
const builtinDir = (0, import_node_path11.resolve)(__dirname || ".", "..", "modules");
|
|
28274
|
+
if ((0, import_node_fs13.existsSync)(builtinDir)) {
|
|
28089
28275
|
searchPaths.push(builtinDir);
|
|
28090
28276
|
}
|
|
28091
28277
|
for (const basePath of searchPaths) {
|
|
28092
|
-
if (!(0,
|
|
28093
|
-
const entries = (0,
|
|
28278
|
+
if (!(0, import_node_fs13.existsSync)(basePath)) continue;
|
|
28279
|
+
const entries = (0, import_node_fs13.readdirSync)(basePath, { withFileTypes: true });
|
|
28094
28280
|
for (const entry of entries) {
|
|
28095
28281
|
if (!entry.isDirectory()) continue;
|
|
28096
|
-
const modPath = (0,
|
|
28097
|
-
const manifestPath = (0,
|
|
28098
|
-
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;
|
|
28099
28285
|
try {
|
|
28100
|
-
const raw = (0,
|
|
28286
|
+
const raw = (0, import_node_fs13.readFileSync)(manifestPath, "utf-8");
|
|
28101
28287
|
const manifest = import_toml2.default.parse(raw);
|
|
28102
28288
|
const config = configs.get(manifest.module.name) || { enabled: true };
|
|
28103
28289
|
modules.push({
|
|
@@ -28123,21 +28309,21 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28123
28309
|
init_ipc_client();
|
|
28124
28310
|
|
|
28125
28311
|
// src/daemon/pidfile.ts
|
|
28126
|
-
var
|
|
28312
|
+
var import_node_fs14 = require("fs");
|
|
28127
28313
|
init_paths();
|
|
28128
28314
|
function writePidFile() {
|
|
28129
28315
|
ensureRuntimeDirs();
|
|
28130
|
-
(0,
|
|
28316
|
+
(0, import_node_fs14.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
|
|
28131
28317
|
}
|
|
28132
28318
|
function readPidFile() {
|
|
28133
|
-
if (!(0,
|
|
28134
|
-
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();
|
|
28135
28321
|
const pid = parseInt(raw, 10);
|
|
28136
28322
|
return Number.isFinite(pid) ? pid : null;
|
|
28137
28323
|
}
|
|
28138
28324
|
function removePidFile() {
|
|
28139
28325
|
try {
|
|
28140
|
-
if ((0,
|
|
28326
|
+
if ((0, import_node_fs14.existsSync)(PATHS.pidFile)) (0, import_node_fs14.unlinkSync)(PATHS.pidFile);
|
|
28141
28327
|
} catch {
|
|
28142
28328
|
}
|
|
28143
28329
|
}
|
|
@@ -28249,24 +28435,24 @@ function formatUptime2(seconds) {
|
|
|
28249
28435
|
|
|
28250
28436
|
// src/commands/modules.ts
|
|
28251
28437
|
var import_node_child_process2 = require("child_process");
|
|
28252
|
-
var
|
|
28253
|
-
var
|
|
28438
|
+
var import_node_fs16 = require("fs");
|
|
28439
|
+
var import_node_path13 = require("path");
|
|
28254
28440
|
var import_toml3 = __toESM(require_toml());
|
|
28255
28441
|
init_paths();
|
|
28256
28442
|
|
|
28257
28443
|
// src/daemon/module-trust.ts
|
|
28258
28444
|
var import_node_crypto3 = require("crypto");
|
|
28259
|
-
var
|
|
28260
|
-
var
|
|
28445
|
+
var import_node_fs15 = require("fs");
|
|
28446
|
+
var import_node_path12 = require("path");
|
|
28261
28447
|
init_paths();
|
|
28262
|
-
var TRUST_FILE = (0,
|
|
28263
|
-
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");
|
|
28264
28450
|
var DIGEST_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".git"]);
|
|
28265
28451
|
function collectFiles(root, dir = root, out = []) {
|
|
28266
|
-
for (const entry of (0,
|
|
28452
|
+
for (const entry of (0, import_node_fs15.readdirSync)(dir, { withFileTypes: true }).sort(
|
|
28267
28453
|
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
28268
28454
|
)) {
|
|
28269
|
-
const full = (0,
|
|
28455
|
+
const full = (0, import_node_path12.join)(dir, entry.name);
|
|
28270
28456
|
if (entry.isSymbolicLink()) {
|
|
28271
28457
|
out.push({ path: full, isSymlink: true });
|
|
28272
28458
|
} else if (entry.isDirectory()) {
|
|
@@ -28281,24 +28467,24 @@ function collectFiles(root, dir = root, out = []) {
|
|
|
28281
28467
|
function computeModuleDigest(modulePath) {
|
|
28282
28468
|
const hash = (0, import_node_crypto3.createHash)("sha256");
|
|
28283
28469
|
for (const entry of collectFiles(modulePath)) {
|
|
28284
|
-
const relPath = (0,
|
|
28470
|
+
const relPath = (0, import_node_path12.relative)(modulePath, entry.path).split(import_node_path12.sep).join("/");
|
|
28285
28471
|
hash.update(relPath);
|
|
28286
28472
|
hash.update("\0");
|
|
28287
28473
|
if (entry.isSymlink) {
|
|
28288
28474
|
hash.update("symlink:");
|
|
28289
|
-
hash.update((0,
|
|
28475
|
+
hash.update((0, import_node_fs15.readlinkSync)(entry.path));
|
|
28290
28476
|
} else {
|
|
28291
28477
|
hash.update("file:");
|
|
28292
|
-
hash.update((0,
|
|
28478
|
+
hash.update((0, import_node_fs15.readFileSync)(entry.path));
|
|
28293
28479
|
}
|
|
28294
28480
|
hash.update("\0");
|
|
28295
28481
|
}
|
|
28296
28482
|
return hash.digest("hex");
|
|
28297
28483
|
}
|
|
28298
28484
|
function readTrustFile() {
|
|
28299
|
-
if (!(0,
|
|
28485
|
+
if (!(0, import_node_fs15.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
|
|
28300
28486
|
try {
|
|
28301
|
-
const parsed = JSON.parse((0,
|
|
28487
|
+
const parsed = JSON.parse((0, import_node_fs15.readFileSync)(TRUST_FILE, "utf-8"));
|
|
28302
28488
|
if (parsed.version !== 1 || typeof parsed.modules !== "object" || !parsed.modules) {
|
|
28303
28489
|
return { version: 1, modules: {} };
|
|
28304
28490
|
}
|
|
@@ -28308,9 +28494,9 @@ function readTrustFile() {
|
|
|
28308
28494
|
}
|
|
28309
28495
|
}
|
|
28310
28496
|
function writeTrustFile(file) {
|
|
28311
|
-
(0,
|
|
28497
|
+
(0, import_node_fs15.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
|
|
28312
28498
|
try {
|
|
28313
|
-
(0,
|
|
28499
|
+
(0, import_node_fs15.chmodSync)(TRUST_FILE, 384);
|
|
28314
28500
|
} catch {
|
|
28315
28501
|
}
|
|
28316
28502
|
}
|
|
@@ -28336,9 +28522,9 @@ function listTrustedModules() {
|
|
|
28336
28522
|
return readTrustFile().modules;
|
|
28337
28523
|
}
|
|
28338
28524
|
function readPublisherKeys() {
|
|
28339
|
-
if (!(0,
|
|
28525
|
+
if (!(0, import_node_fs15.existsSync)(PUBLISHER_KEYS_FILE)) return {};
|
|
28340
28526
|
try {
|
|
28341
|
-
const parsed = JSON.parse((0,
|
|
28527
|
+
const parsed = JSON.parse((0, import_node_fs15.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
|
|
28342
28528
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
28343
28529
|
} catch {
|
|
28344
28530
|
return {};
|
|
@@ -28347,16 +28533,16 @@ function readPublisherKeys() {
|
|
|
28347
28533
|
function verifyModuleSignature(modulePath, digest) {
|
|
28348
28534
|
const keys = readPublisherKeys();
|
|
28349
28535
|
const pinnedKeyIds = Object.keys(keys);
|
|
28350
|
-
const sigPath = (0,
|
|
28536
|
+
const sigPath = (0, import_node_path12.join)(modulePath, "mod.sig");
|
|
28351
28537
|
if (pinnedKeyIds.length === 0) {
|
|
28352
28538
|
return { ok: true };
|
|
28353
28539
|
}
|
|
28354
|
-
if (!(0,
|
|
28540
|
+
if (!(0, import_node_fs15.existsSync)(sigPath)) {
|
|
28355
28541
|
return { ok: false, reason: "publisher keys are pinned but the module ships no mod.sig" };
|
|
28356
28542
|
}
|
|
28357
28543
|
let parsed;
|
|
28358
28544
|
try {
|
|
28359
|
-
parsed = JSON.parse((0,
|
|
28545
|
+
parsed = JSON.parse((0, import_node_fs15.readFileSync)(sigPath, "utf-8"));
|
|
28360
28546
|
} catch {
|
|
28361
28547
|
return { ok: false, reason: "mod.sig is not valid JSON" };
|
|
28362
28548
|
}
|
|
@@ -28417,7 +28603,7 @@ function safeModuleDirName(name, label = "module name") {
|
|
|
28417
28603
|
return name;
|
|
28418
28604
|
}
|
|
28419
28605
|
function moduleDestination(dir, name, label) {
|
|
28420
|
-
return (0,
|
|
28606
|
+
return (0, import_node_path13.join)(dir, safeModuleDirName(name, label));
|
|
28421
28607
|
}
|
|
28422
28608
|
function assertSafeTarballEntries(tarPath) {
|
|
28423
28609
|
const listing = (0, import_node_child_process2.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
|
|
@@ -28430,12 +28616,12 @@ function assertSafeTarballEntries(tarPath) {
|
|
|
28430
28616
|
}
|
|
28431
28617
|
}
|
|
28432
28618
|
function validateManifest(modPath) {
|
|
28433
|
-
const manifestPath = (0,
|
|
28434
|
-
if (!(0,
|
|
28619
|
+
const manifestPath = (0, import_node_path13.join)(modPath, "mod.toml");
|
|
28620
|
+
if (!(0, import_node_fs16.existsSync)(manifestPath)) {
|
|
28435
28621
|
return { ok: false, error: `mod.toml not found at ${manifestPath}` };
|
|
28436
28622
|
}
|
|
28437
28623
|
try {
|
|
28438
|
-
const raw = (0,
|
|
28624
|
+
const raw = (0, import_node_fs16.readFileSync)(manifestPath, "utf-8");
|
|
28439
28625
|
const parsed = import_toml3.default.parse(raw);
|
|
28440
28626
|
const name = parsed.module?.name;
|
|
28441
28627
|
const version = parsed.module?.version;
|
|
@@ -28495,8 +28681,8 @@ async function modulesInstallCommand(source) {
|
|
|
28495
28681
|
console.log();
|
|
28496
28682
|
const dir = modulesDir();
|
|
28497
28683
|
if (source.startsWith("./") || source.startsWith("/") || source.startsWith("~")) {
|
|
28498
|
-
const absPath = (0,
|
|
28499
|
-
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)) {
|
|
28500
28686
|
console.log(source_default.red(` \u2717 Path not found: ${absPath}
|
|
28501
28687
|
`));
|
|
28502
28688
|
return;
|
|
@@ -28515,7 +28701,7 @@ async function modulesInstallCommand(source) {
|
|
|
28515
28701
|
`));
|
|
28516
28702
|
return;
|
|
28517
28703
|
}
|
|
28518
|
-
if ((0,
|
|
28704
|
+
if ((0, import_node_fs16.existsSync)(dest2)) {
|
|
28519
28705
|
console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
|
|
28520
28706
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
|
|
28521
28707
|
`));
|
|
@@ -28523,7 +28709,7 @@ async function modulesInstallCommand(source) {
|
|
|
28523
28709
|
}
|
|
28524
28710
|
const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
|
|
28525
28711
|
try {
|
|
28526
|
-
(0,
|
|
28712
|
+
(0, import_node_fs16.cpSync)(absPath, dest2, { recursive: true, dereference: true });
|
|
28527
28713
|
spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
|
|
28528
28714
|
} catch (err) {
|
|
28529
28715
|
spinner2.fail(`Copy failed: ${err.message}`);
|
|
@@ -28539,14 +28725,14 @@ async function modulesInstallCommand(source) {
|
|
|
28539
28725
|
let name;
|
|
28540
28726
|
let dest2;
|
|
28541
28727
|
try {
|
|
28542
|
-
name = safeModuleDirName((0,
|
|
28728
|
+
name = safeModuleDirName((0, import_node_path13.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
|
|
28543
28729
|
dest2 = moduleDestination(dir, name);
|
|
28544
28730
|
} catch (err) {
|
|
28545
28731
|
console.log(source_default.red(` x ${err.message}
|
|
28546
28732
|
`));
|
|
28547
28733
|
return;
|
|
28548
28734
|
}
|
|
28549
|
-
if ((0,
|
|
28735
|
+
if ((0, import_node_fs16.existsSync)(dest2)) {
|
|
28550
28736
|
console.log(source_default.yellow(` ! ${name} is already installed at ${dest2}`));
|
|
28551
28737
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${name}`)} first.
|
|
28552
28738
|
`));
|
|
@@ -28563,7 +28749,7 @@ async function modulesInstallCommand(source) {
|
|
|
28563
28749
|
if (!check.ok) {
|
|
28564
28750
|
spinner2.fail(check.error);
|
|
28565
28751
|
try {
|
|
28566
|
-
(0,
|
|
28752
|
+
(0, import_node_fs16.rmSync)(dest2, { recursive: true, force: true });
|
|
28567
28753
|
} catch {
|
|
28568
28754
|
}
|
|
28569
28755
|
return;
|
|
@@ -28609,7 +28795,7 @@ async function modulesInstallCommand(source) {
|
|
|
28609
28795
|
`));
|
|
28610
28796
|
return;
|
|
28611
28797
|
}
|
|
28612
|
-
if ((0,
|
|
28798
|
+
if ((0, import_node_fs16.existsSync)(dest)) {
|
|
28613
28799
|
console.log(source_default.yellow(` ! ${mod.slug} is already installed at ${dest}
|
|
28614
28800
|
`));
|
|
28615
28801
|
return;
|
|
@@ -28635,7 +28821,7 @@ async function modulesInstallCommand(source) {
|
|
|
28635
28821
|
if (!check.ok) {
|
|
28636
28822
|
cloneSpinner.fail(check.error);
|
|
28637
28823
|
try {
|
|
28638
|
-
(0,
|
|
28824
|
+
(0, import_node_fs16.rmSync)(dest, { recursive: true, force: true });
|
|
28639
28825
|
} catch {
|
|
28640
28826
|
}
|
|
28641
28827
|
return;
|
|
@@ -28649,11 +28835,11 @@ async function modulesInstallCommand(source) {
|
|
|
28649
28835
|
dlSpinner.fail(`HTTP ${res.status}`);
|
|
28650
28836
|
return;
|
|
28651
28837
|
}
|
|
28652
|
-
const tar = (0,
|
|
28653
|
-
(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()));
|
|
28654
28840
|
assertSafeTarballEntries(tar);
|
|
28655
28841
|
(0, import_node_child_process2.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
|
|
28656
|
-
(0,
|
|
28842
|
+
(0, import_node_fs16.rmSync)(tar, { force: true });
|
|
28657
28843
|
const check = validateManifest(dest);
|
|
28658
28844
|
if (!check.ok) {
|
|
28659
28845
|
dlSpinner.fail(check.error);
|
|
@@ -28685,7 +28871,7 @@ async function modulesRemoveCommand(name) {
|
|
|
28685
28871
|
`));
|
|
28686
28872
|
return;
|
|
28687
28873
|
}
|
|
28688
|
-
if (!(0,
|
|
28874
|
+
if (!(0, import_node_fs16.existsSync)(target)) {
|
|
28689
28875
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
28690
28876
|
`));
|
|
28691
28877
|
return;
|
|
@@ -28695,7 +28881,7 @@ async function modulesRemoveCommand(name) {
|
|
|
28695
28881
|
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
|
|
28696
28882
|
}
|
|
28697
28883
|
try {
|
|
28698
|
-
(0,
|
|
28884
|
+
(0, import_node_fs16.rmSync)(target, { recursive: true, force: true });
|
|
28699
28885
|
untrustModule(name);
|
|
28700
28886
|
console.log(source_default.green(` \u2713 Removed ${name} from ${dir}
|
|
28701
28887
|
`));
|
|
@@ -28720,7 +28906,7 @@ async function modulesTrustCommand(name) {
|
|
|
28720
28906
|
`));
|
|
28721
28907
|
return;
|
|
28722
28908
|
}
|
|
28723
|
-
if (!(0,
|
|
28909
|
+
if (!(0, import_node_fs16.existsSync)(target)) {
|
|
28724
28910
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
28725
28911
|
`));
|
|
28726
28912
|
return;
|
|
@@ -29156,21 +29342,21 @@ async function pentestCommand(targetUrl) {
|
|
|
29156
29342
|
|
|
29157
29343
|
// src/commands/orgs.ts
|
|
29158
29344
|
var import_node_os5 = require("os");
|
|
29159
|
-
var
|
|
29160
|
-
var
|
|
29345
|
+
var import_node_fs17 = require("fs");
|
|
29346
|
+
var import_node_path14 = require("path");
|
|
29161
29347
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29162
|
-
var CONFIG_PATH = (0,
|
|
29348
|
+
var CONFIG_PATH = (0, import_node_path14.join)((0, import_node_os5.homedir)(), ".threatcrush", "config.json");
|
|
29163
29349
|
function readConfig() {
|
|
29164
29350
|
try {
|
|
29165
|
-
return JSON.parse((0,
|
|
29351
|
+
return JSON.parse((0, import_node_fs17.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
29166
29352
|
} catch {
|
|
29167
29353
|
return {};
|
|
29168
29354
|
}
|
|
29169
29355
|
}
|
|
29170
29356
|
function writeConfig(config) {
|
|
29171
|
-
const dir = (0,
|
|
29172
|
-
if (!(0,
|
|
29173
|
-
(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));
|
|
29174
29360
|
}
|
|
29175
29361
|
function getAuthHeaders() {
|
|
29176
29362
|
const config = readConfig();
|
|
@@ -29306,13 +29492,13 @@ async function useOrganization(slug) {
|
|
|
29306
29492
|
|
|
29307
29493
|
// src/commands/servers.ts
|
|
29308
29494
|
var import_node_os6 = require("os");
|
|
29309
|
-
var
|
|
29310
|
-
var
|
|
29495
|
+
var import_node_fs18 = require("fs");
|
|
29496
|
+
var import_node_path15 = require("path");
|
|
29311
29497
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29312
|
-
var CONFIG_PATH2 = (0,
|
|
29498
|
+
var CONFIG_PATH2 = (0, import_node_path15.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
|
|
29313
29499
|
function readConfig2() {
|
|
29314
29500
|
try {
|
|
29315
|
-
return JSON.parse((0,
|
|
29501
|
+
return JSON.parse((0, import_node_fs18.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
29316
29502
|
} catch {
|
|
29317
29503
|
return {};
|
|
29318
29504
|
}
|
|
@@ -29415,14 +29601,14 @@ function timeAgo(dateStr) {
|
|
|
29415
29601
|
|
|
29416
29602
|
// src/commands/connect.ts
|
|
29417
29603
|
var import_node_os7 = require("os");
|
|
29418
|
-
var
|
|
29419
|
-
var
|
|
29604
|
+
var import_node_fs19 = require("fs");
|
|
29605
|
+
var import_node_path16 = require("path");
|
|
29420
29606
|
var import_node_child_process3 = require("child_process");
|
|
29421
29607
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29422
|
-
var CONFIG_PATH3 = (0,
|
|
29608
|
+
var CONFIG_PATH3 = (0, import_node_path16.join)((0, import_node_os7.homedir)(), ".threatcrush", "config.json");
|
|
29423
29609
|
function readConfig3() {
|
|
29424
29610
|
try {
|
|
29425
|
-
return JSON.parse((0,
|
|
29611
|
+
return JSON.parse((0, import_node_fs19.readFileSync)(CONFIG_PATH3, "utf-8"));
|
|
29426
29612
|
} catch {
|
|
29427
29613
|
return {};
|
|
29428
29614
|
}
|
|
@@ -29577,18 +29763,18 @@ async function sshConnect(options) {
|
|
|
29577
29763
|
|
|
29578
29764
|
// src/commands/daemon.ts
|
|
29579
29765
|
var import_node_child_process9 = require("child_process");
|
|
29580
|
-
var import_node_fs28 = require("fs");
|
|
29581
|
-
var import_node_path20 = require("path");
|
|
29582
29766
|
var import_node_fs29 = require("fs");
|
|
29767
|
+
var import_node_path21 = require("path");
|
|
29768
|
+
var import_node_fs30 = require("fs");
|
|
29583
29769
|
|
|
29584
29770
|
// src/daemon/index.ts
|
|
29585
|
-
var
|
|
29586
|
-
var
|
|
29771
|
+
var import_node_fs28 = require("fs");
|
|
29772
|
+
var import_node_path20 = require("path");
|
|
29587
29773
|
init_paths();
|
|
29588
29774
|
|
|
29589
29775
|
// src/daemon/ipc-server.ts
|
|
29590
29776
|
var import_node_net2 = require("net");
|
|
29591
|
-
var
|
|
29777
|
+
var import_node_fs20 = require("fs");
|
|
29592
29778
|
init_paths();
|
|
29593
29779
|
init_control_token();
|
|
29594
29780
|
|
|
@@ -29640,9 +29826,9 @@ var IpcServer = class {
|
|
|
29640
29826
|
controlToken = "";
|
|
29641
29827
|
async start() {
|
|
29642
29828
|
this.controlToken = issueControlToken();
|
|
29643
|
-
if ((0,
|
|
29829
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) {
|
|
29644
29830
|
try {
|
|
29645
|
-
(0,
|
|
29831
|
+
(0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29646
29832
|
} catch {
|
|
29647
29833
|
}
|
|
29648
29834
|
}
|
|
@@ -29678,14 +29864,14 @@ var IpcServer = class {
|
|
|
29678
29864
|
return new Promise((resolve5) => {
|
|
29679
29865
|
if (!this.server) {
|
|
29680
29866
|
try {
|
|
29681
|
-
if ((0,
|
|
29867
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) (0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29682
29868
|
} catch {
|
|
29683
29869
|
}
|
|
29684
29870
|
return resolve5();
|
|
29685
29871
|
}
|
|
29686
29872
|
this.server.close(() => {
|
|
29687
29873
|
try {
|
|
29688
|
-
if ((0,
|
|
29874
|
+
if ((0, import_node_fs20.existsSync)(PATHS.socket)) (0, import_node_fs20.unlinkSync)(PATHS.socket);
|
|
29689
29875
|
} catch {
|
|
29690
29876
|
}
|
|
29691
29877
|
resolve5();
|
|
@@ -29717,12 +29903,27 @@ var IpcServer = class {
|
|
|
29717
29903
|
});
|
|
29718
29904
|
}
|
|
29719
29905
|
async handleLine(client, line) {
|
|
29720
|
-
let
|
|
29906
|
+
let frame;
|
|
29721
29907
|
try {
|
|
29722
|
-
|
|
29908
|
+
frame = JSON.parse(line);
|
|
29723
29909
|
} catch {
|
|
29724
29910
|
return this.send(client, { id: 0, ok: false, error: "invalid json" });
|
|
29725
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) {
|
|
29726
29927
|
switch (req.method) {
|
|
29727
29928
|
case "ping":
|
|
29728
29929
|
return this.send(client, { id: req.id, ok: true, result: "pong" });
|
|
@@ -29830,6 +30031,10 @@ var IpcServer = class {
|
|
|
29830
30031
|
this.send(client, { id: req.id, ok: true, result: "shutting down" });
|
|
29831
30032
|
setTimeout(() => process.emit("SIGTERM"), 50);
|
|
29832
30033
|
return;
|
|
30034
|
+
default: {
|
|
30035
|
+
const unknown = req;
|
|
30036
|
+
return this.send(client, { id: unknown.id, ok: false, error: `unknown method: ${unknown.method}` });
|
|
30037
|
+
}
|
|
29833
30038
|
}
|
|
29834
30039
|
}
|
|
29835
30040
|
send(client, msg) {
|
|
@@ -29847,14 +30052,14 @@ var IpcServer = class {
|
|
|
29847
30052
|
};
|
|
29848
30053
|
|
|
29849
30054
|
// src/daemon/module-host.ts
|
|
29850
|
-
var
|
|
29851
|
-
var
|
|
30055
|
+
var import_node_fs24 = require("fs");
|
|
30056
|
+
var import_node_path17 = require("path");
|
|
29852
30057
|
var import_node_url = require("url");
|
|
29853
30058
|
var import_toml4 = __toESM(require_toml());
|
|
29854
30059
|
init_paths();
|
|
29855
30060
|
|
|
29856
30061
|
// src/daemon/watchers/log-watcher.ts
|
|
29857
|
-
var
|
|
30062
|
+
var import_node_fs21 = require("fs");
|
|
29858
30063
|
var import_node_readline4 = require("readline");
|
|
29859
30064
|
var DEFAULT_SOURCES = [
|
|
29860
30065
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
@@ -29875,9 +30080,9 @@ var LogWatcher = class {
|
|
|
29875
30080
|
start() {
|
|
29876
30081
|
const started = [];
|
|
29877
30082
|
for (const src of this.sources) {
|
|
29878
|
-
if (!(0,
|
|
30083
|
+
if (!(0, import_node_fs21.existsSync)(src.path)) continue;
|
|
29879
30084
|
try {
|
|
29880
|
-
(0,
|
|
30085
|
+
(0, import_node_fs21.accessSync)(src.path, import_node_fs21.constants.R_OK);
|
|
29881
30086
|
} catch {
|
|
29882
30087
|
continue;
|
|
29883
30088
|
}
|
|
@@ -29895,9 +30100,17 @@ var LogWatcher = class {
|
|
|
29895
30100
|
activeModules() {
|
|
29896
30101
|
return [...this.active];
|
|
29897
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
|
+
}
|
|
29898
30111
|
tail(src) {
|
|
29899
30112
|
try {
|
|
29900
|
-
this.positions.set(src.path, (0,
|
|
30113
|
+
this.positions.set(src.path, (0, import_node_fs21.statSync)(src.path).size);
|
|
29901
30114
|
} catch {
|
|
29902
30115
|
this.positions.set(src.path, 0);
|
|
29903
30116
|
}
|
|
@@ -29908,7 +30121,7 @@ var LogWatcher = class {
|
|
|
29908
30121
|
poll(src) {
|
|
29909
30122
|
let stat;
|
|
29910
30123
|
try {
|
|
29911
|
-
stat = (0,
|
|
30124
|
+
stat = (0, import_node_fs21.statSync)(src.path);
|
|
29912
30125
|
} catch {
|
|
29913
30126
|
return;
|
|
29914
30127
|
}
|
|
@@ -29918,7 +30131,7 @@ var LogWatcher = class {
|
|
|
29918
30131
|
return;
|
|
29919
30132
|
}
|
|
29920
30133
|
if (stat.size === prev) return;
|
|
29921
|
-
const stream = (0,
|
|
30134
|
+
const stream = (0, import_node_fs21.createReadStream)(src.path, { start: prev, encoding: "utf-8" });
|
|
29922
30135
|
stream.on("error", () => this.positions.set(src.path, stat.size));
|
|
29923
30136
|
const rl = (0, import_node_readline4.createInterface)({ input: stream });
|
|
29924
30137
|
rl.on("error", () => {
|
|
@@ -29939,20 +30152,9 @@ var LogWatcher = class {
|
|
|
29939
30152
|
if (parsed.source === "auth") {
|
|
29940
30153
|
const entry = parseAuthLog(line);
|
|
29941
30154
|
if (!entry) return;
|
|
29942
|
-
|
|
29943
|
-
|
|
29944
|
-
|
|
29945
|
-
severity = "high";
|
|
29946
|
-
message = `Failed SSH login for ${entry.fields.user || "unknown"} from ${entry.fields.ip || "unknown"}`;
|
|
29947
|
-
} else if (/invalid user/i.test(msg)) {
|
|
29948
|
-
severity = "high";
|
|
29949
|
-
message = `Invalid SSH user: ${entry.fields.user || "unknown"} from ${entry.fields.ip || "unknown"}`;
|
|
29950
|
-
} else if (/accepted/i.test(msg)) {
|
|
29951
|
-
severity = "info";
|
|
29952
|
-
message = `SSH login accepted for ${entry.fields.user || "unknown"}`;
|
|
29953
|
-
} else {
|
|
29954
|
-
return;
|
|
29955
|
-
}
|
|
30155
|
+
const verdict = classifySshAuth(entry);
|
|
30156
|
+
if (!verdict) return;
|
|
30157
|
+
({ severity, message, source_ip: sourceIp } = verdict);
|
|
29956
30158
|
} else if (parsed.source === "nginx") {
|
|
29957
30159
|
const entry = parseNginxLog(line);
|
|
29958
30160
|
if (!entry) return;
|
|
@@ -30010,13 +30212,33 @@ var LogWatcher = class {
|
|
|
30010
30212
|
|
|
30011
30213
|
// src/daemon/watchers/journal-watcher.ts
|
|
30012
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
|
+
}
|
|
30013
30233
|
var JournalWatcher = class _JournalWatcher {
|
|
30014
30234
|
constructor(bus2) {
|
|
30015
30235
|
this.bus = bus2;
|
|
30016
30236
|
}
|
|
30017
30237
|
bus;
|
|
30018
30238
|
proc = null;
|
|
30239
|
+
sshdProc = null;
|
|
30019
30240
|
buffer = "";
|
|
30241
|
+
sshdBuffer = "";
|
|
30020
30242
|
moduleName = "user-journal";
|
|
30021
30243
|
active = false;
|
|
30022
30244
|
// When the daemon runs as root (system mode), tail the SYSTEM journal so
|
|
@@ -30042,7 +30264,9 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30042
30264
|
);
|
|
30043
30265
|
if (!child.stdout) return false;
|
|
30044
30266
|
child.stdout.setEncoding("utf-8");
|
|
30045
|
-
child.stdout.on("data", (chunk) =>
|
|
30267
|
+
child.stdout.on("data", (chunk) => {
|
|
30268
|
+
this.buffer = this.drain(this.buffer + chunk, (entry) => this.handleEntry(entry));
|
|
30269
|
+
});
|
|
30046
30270
|
child.on("exit", () => {
|
|
30047
30271
|
this.proc = null;
|
|
30048
30272
|
this.active = false;
|
|
@@ -30051,14 +30275,49 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30051
30275
|
this.active = true;
|
|
30052
30276
|
return true;
|
|
30053
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
|
+
}
|
|
30054
30312
|
stop() {
|
|
30055
|
-
|
|
30313
|
+
for (const child of [this.proc, this.sshdProc]) {
|
|
30056
30314
|
try {
|
|
30057
|
-
|
|
30315
|
+
child?.kill("SIGTERM");
|
|
30058
30316
|
} catch {
|
|
30059
30317
|
}
|
|
30060
|
-
this.proc = null;
|
|
30061
30318
|
}
|
|
30319
|
+
this.proc = null;
|
|
30320
|
+
this.sshdProc = null;
|
|
30062
30321
|
this.active = false;
|
|
30063
30322
|
}
|
|
30064
30323
|
isActive() {
|
|
@@ -30067,36 +30326,40 @@ var JournalWatcher = class _JournalWatcher {
|
|
|
30067
30326
|
moduleNameValue() {
|
|
30068
30327
|
return this.moduleName;
|
|
30069
30328
|
}
|
|
30070
|
-
|
|
30071
|
-
|
|
30329
|
+
/** Hands each complete JSON line to `onEntry`; returns the unterminated rest. */
|
|
30330
|
+
drain(buffer, onEntry) {
|
|
30072
30331
|
let idx;
|
|
30073
|
-
while ((idx =
|
|
30074
|
-
const line =
|
|
30075
|
-
|
|
30332
|
+
while ((idx = buffer.indexOf("\n")) >= 0) {
|
|
30333
|
+
const line = buffer.slice(0, idx);
|
|
30334
|
+
buffer = buffer.slice(idx + 1);
|
|
30076
30335
|
if (!line.trim()) continue;
|
|
30077
|
-
|
|
30336
|
+
let entry;
|
|
30337
|
+
try {
|
|
30338
|
+
entry = JSON.parse(line);
|
|
30339
|
+
} catch {
|
|
30340
|
+
continue;
|
|
30341
|
+
}
|
|
30342
|
+
onEntry(entry);
|
|
30078
30343
|
}
|
|
30344
|
+
return buffer;
|
|
30079
30345
|
}
|
|
30080
|
-
|
|
30081
|
-
|
|
30082
|
-
try {
|
|
30083
|
-
entry = JSON.parse(line);
|
|
30084
|
-
} catch {
|
|
30085
|
-
return;
|
|
30086
|
-
}
|
|
30346
|
+
handleEntry(entry) {
|
|
30347
|
+
if (this.sshdProc && isSshdRecord(entry)) return;
|
|
30087
30348
|
const message = entry.MESSAGE;
|
|
30088
30349
|
if (!message) return;
|
|
30089
30350
|
const priority = parseInt(entry.PRIORITY ?? "6", 10);
|
|
30090
30351
|
const severity = priorityToSeverity(priority);
|
|
30091
30352
|
const ident = entry.SYSLOG_IDENTIFIER || entry._COMM || "journal";
|
|
30092
30353
|
const bumpedSeverity = bumpForIdent(ident, message, severity);
|
|
30093
|
-
|
|
30354
|
+
this.emit({
|
|
30094
30355
|
timestamp: realtimeToDate(entry.__REALTIME_TIMESTAMP) || /* @__PURE__ */ new Date(),
|
|
30095
30356
|
module: this.moduleName,
|
|
30096
30357
|
category: "system",
|
|
30097
30358
|
severity: bumpedSeverity,
|
|
30098
30359
|
message: `[${ident}] ${message}`.slice(0, 500)
|
|
30099
|
-
};
|
|
30360
|
+
});
|
|
30361
|
+
}
|
|
30362
|
+
emit(event) {
|
|
30100
30363
|
try {
|
|
30101
30364
|
insertEvent(event);
|
|
30102
30365
|
} catch {
|
|
@@ -30129,7 +30392,7 @@ function realtimeToDate(rt) {
|
|
|
30129
30392
|
|
|
30130
30393
|
// src/modules/network-monitor/index.ts
|
|
30131
30394
|
var import_node_child_process5 = require("child_process");
|
|
30132
|
-
var
|
|
30395
|
+
var import_node_fs22 = require("fs");
|
|
30133
30396
|
var NetworkMonitor = class {
|
|
30134
30397
|
constructor(bus2) {
|
|
30135
30398
|
this.bus = bus2;
|
|
@@ -30137,13 +30400,22 @@ var NetworkMonitor = class {
|
|
|
30137
30400
|
bus;
|
|
30138
30401
|
active = false;
|
|
30139
30402
|
pollTimer = null;
|
|
30403
|
+
heartbeatTimer = null;
|
|
30140
30404
|
scanTrackers = /* @__PURE__ */ new Map();
|
|
30141
30405
|
halfOpenTrackers = /* @__PURE__ */ new Map();
|
|
30142
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();
|
|
30143
30411
|
// Config
|
|
30144
30412
|
pollIntervalMs = 5e3;
|
|
30413
|
+
heartbeatMs = 9e5;
|
|
30414
|
+
// 15 min: proof of life, low volume
|
|
30145
30415
|
portScanThreshold = 10;
|
|
30146
|
-
// unique ports
|
|
30416
|
+
// unique listening ports -> high (bannable)
|
|
30417
|
+
portScanNoticeThreshold = 5;
|
|
30418
|
+
// 5-9 -> medium notice (never bans)
|
|
30147
30419
|
portScanWindowMs = 3e4;
|
|
30148
30420
|
synFloodThreshold = 50;
|
|
30149
30421
|
// half-open connections
|
|
@@ -30154,20 +30426,37 @@ var NetworkMonitor = class {
|
|
|
30154
30426
|
}
|
|
30155
30427
|
this.active = true;
|
|
30156
30428
|
this.pollTimer = setInterval(() => this.poll(), this.pollIntervalMs);
|
|
30429
|
+
this.heartbeatTimer = setInterval(() => this.heartbeat(), this.heartbeatMs);
|
|
30157
30430
|
return true;
|
|
30158
30431
|
}
|
|
30159
30432
|
stop() {
|
|
30160
30433
|
if (this.pollTimer) clearInterval(this.pollTimer);
|
|
30434
|
+
if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
|
|
30161
30435
|
this.pollTimer = null;
|
|
30436
|
+
this.heartbeatTimer = null;
|
|
30162
30437
|
this.active = false;
|
|
30163
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
|
+
}
|
|
30164
30453
|
isActive() {
|
|
30165
30454
|
return this.active;
|
|
30166
30455
|
}
|
|
30167
30456
|
hasConntrackOrSs() {
|
|
30168
30457
|
const ss = (0, import_node_child_process5.spawnSync)("ss", ["--version"], { stdio: "pipe" });
|
|
30169
30458
|
if (ss.status === 0) return true;
|
|
30170
|
-
return (0,
|
|
30459
|
+
return (0, import_node_fs22.existsSync)("/proc/net/tcp");
|
|
30171
30460
|
}
|
|
30172
30461
|
/**
|
|
30173
30462
|
* The TCP ports this host actually listens on.
|
|
@@ -30199,6 +30488,8 @@ var NetworkMonitor = class {
|
|
|
30199
30488
|
poll() {
|
|
30200
30489
|
try {
|
|
30201
30490
|
const connections = this.getConnections();
|
|
30491
|
+
this.obsConnections += connections.length;
|
|
30492
|
+
for (const c of connections) this.obsSources.add(c.source_ip);
|
|
30202
30493
|
this.analyzePortScans(connections);
|
|
30203
30494
|
this.analyzeSynFlood(connections);
|
|
30204
30495
|
this.cleanupTrackers();
|
|
@@ -30267,7 +30558,8 @@ var NetworkMonitor = class {
|
|
|
30267
30558
|
tracker.ports.add(conn.dest_port);
|
|
30268
30559
|
tracker.lastSeen = now;
|
|
30269
30560
|
tracker.count++;
|
|
30270
|
-
|
|
30561
|
+
const withinWindow = now - tracker.firstSeen <= this.portScanWindowMs;
|
|
30562
|
+
if (tracker.ports.size >= this.portScanThreshold && withinWindow) {
|
|
30271
30563
|
this.emitEvent(
|
|
30272
30564
|
"high",
|
|
30273
30565
|
`Port scan detected: ${conn.source_ip} probed ${tracker.ports.size} ports in ${Math.round((now - tracker.firstSeen) / 1e3)}s`,
|
|
@@ -30275,6 +30567,20 @@ var NetworkMonitor = class {
|
|
|
30275
30567
|
{ ports_scanned: tracker.ports.size, window_seconds: Math.round((now - tracker.firstSeen) / 1e3) }
|
|
30276
30568
|
);
|
|
30277
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
|
+
);
|
|
30278
30584
|
}
|
|
30279
30585
|
}
|
|
30280
30586
|
}
|
|
@@ -30337,7 +30643,7 @@ var NetworkMonitor = class {
|
|
|
30337
30643
|
};
|
|
30338
30644
|
|
|
30339
30645
|
// src/modules/dns-monitor/index.ts
|
|
30340
|
-
var
|
|
30646
|
+
var import_node_fs23 = require("fs");
|
|
30341
30647
|
var import_node_child_process6 = require("child_process");
|
|
30342
30648
|
var import_node_readline5 = require("readline");
|
|
30343
30649
|
var DNS_LOG_SOURCES = [
|
|
@@ -30350,6 +30656,7 @@ var DNS_LOG_SOURCES = [
|
|
|
30350
30656
|
"/var/log/pihole.log"
|
|
30351
30657
|
// Pi-hole
|
|
30352
30658
|
];
|
|
30659
|
+
var DEFAULT_DNS_JOURNAL_UNITS = ["moshpit-dns", "dnsmasq", "named", "unbound", "pdns-recursor"];
|
|
30353
30660
|
function qtypeName(qtype) {
|
|
30354
30661
|
const names = {
|
|
30355
30662
|
1: "A",
|
|
@@ -30370,10 +30677,11 @@ function qtypeName(qtype) {
|
|
|
30370
30677
|
return names[qtype] ?? `TYPE${qtype}`;
|
|
30371
30678
|
}
|
|
30372
30679
|
var DnsMonitor = class {
|
|
30680
|
+
// 15 min: enough to prove life, low volume
|
|
30373
30681
|
constructor(bus2, options = {}) {
|
|
30374
30682
|
this.bus = bus2;
|
|
30375
30683
|
this.extraPaths = options.log_paths ?? [];
|
|
30376
|
-
this.journalUnits = options.journal_units ??
|
|
30684
|
+
this.journalUnits = options.journal_units ?? DEFAULT_DNS_JOURNAL_UNITS;
|
|
30377
30685
|
}
|
|
30378
30686
|
bus;
|
|
30379
30687
|
active = false;
|
|
@@ -30395,28 +30703,77 @@ var DnsMonitor = class {
|
|
|
30395
30703
|
extraPaths = [];
|
|
30396
30704
|
journalUnits = [];
|
|
30397
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
|
+
}
|
|
30398
30726
|
start() {
|
|
30399
30727
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
30400
|
-
if (!(0,
|
|
30728
|
+
if (!(0, import_node_fs23.existsSync)(p)) return false;
|
|
30401
30729
|
try {
|
|
30402
|
-
(0,
|
|
30730
|
+
(0, import_node_fs23.accessSync)(p, import_node_fs23.constants.R_OK);
|
|
30403
30731
|
return true;
|
|
30404
30732
|
} catch {
|
|
30405
30733
|
return false;
|
|
30406
30734
|
}
|
|
30407
30735
|
});
|
|
30408
|
-
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);
|
|
30409
30743
|
if (sources.length === 0 && this.journalTails.length === 0) return false;
|
|
30410
30744
|
this.active = true;
|
|
30411
30745
|
for (const src of sources) {
|
|
30412
30746
|
this.tailLog(src);
|
|
30413
30747
|
}
|
|
30414
|
-
setInterval(() => this.analyzeBuffer(), 1e4);
|
|
30748
|
+
this.analyzeTimer = setInterval(() => this.analyzeBuffer(), 1e4);
|
|
30749
|
+
this.heartbeatTimer = setInterval(() => this.heartbeat(), this.heartbeatMs);
|
|
30415
30750
|
return true;
|
|
30416
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
|
+
}
|
|
30417
30766
|
stop() {
|
|
30418
30767
|
for (const t of this.timers.values()) clearInterval(t);
|
|
30419
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
|
+
}
|
|
30420
30777
|
for (const child of this.journalTails) {
|
|
30421
30778
|
try {
|
|
30422
30779
|
child.kill("SIGTERM");
|
|
@@ -30446,7 +30803,7 @@ var DnsMonitor = class {
|
|
|
30446
30803
|
}
|
|
30447
30804
|
tailLog(path) {
|
|
30448
30805
|
try {
|
|
30449
|
-
this.positions.set(path, (0,
|
|
30806
|
+
this.positions.set(path, (0, import_node_fs23.statSync)(path).size);
|
|
30450
30807
|
} catch {
|
|
30451
30808
|
this.positions.set(path, 0);
|
|
30452
30809
|
}
|
|
@@ -30456,7 +30813,7 @@ var DnsMonitor = class {
|
|
|
30456
30813
|
pollLog(path) {
|
|
30457
30814
|
let stat;
|
|
30458
30815
|
try {
|
|
30459
|
-
stat = (0,
|
|
30816
|
+
stat = (0, import_node_fs23.statSync)(path);
|
|
30460
30817
|
} catch {
|
|
30461
30818
|
return;
|
|
30462
30819
|
}
|
|
@@ -30466,7 +30823,7 @@ var DnsMonitor = class {
|
|
|
30466
30823
|
return;
|
|
30467
30824
|
}
|
|
30468
30825
|
if (stat.size === prev) return;
|
|
30469
|
-
const stream = (0,
|
|
30826
|
+
const stream = (0, import_node_fs23.createReadStream)(path, { start: prev, encoding: "utf-8" });
|
|
30470
30827
|
stream.on("error", () => this.positions.set(path, stat.size));
|
|
30471
30828
|
const rl = (0, import_node_readline5.createInterface)({ input: stream });
|
|
30472
30829
|
rl.on("line", (line) => this.parseDnsLine(line));
|
|
@@ -30477,7 +30834,7 @@ var DnsMonitor = class {
|
|
|
30477
30834
|
/\[dns\]\s+(?:udp|tcp|doh)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w+)/i
|
|
30478
30835
|
);
|
|
30479
30836
|
if (moshpit) {
|
|
30480
|
-
this.
|
|
30837
|
+
this.record({
|
|
30481
30838
|
type: qtypeName(Number.parseInt(moshpit[3], 10)),
|
|
30482
30839
|
domain: moshpit[2],
|
|
30483
30840
|
source_ip: moshpit[1],
|
|
@@ -30487,7 +30844,7 @@ var DnsMonitor = class {
|
|
|
30487
30844
|
}
|
|
30488
30845
|
const resolvedMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
30489
30846
|
if (resolvedMatch) {
|
|
30490
|
-
this.
|
|
30847
|
+
this.record({
|
|
30491
30848
|
type: resolvedMatch[1],
|
|
30492
30849
|
domain: resolvedMatch[2],
|
|
30493
30850
|
source_ip: resolvedMatch[3],
|
|
@@ -30497,7 +30854,7 @@ var DnsMonitor = class {
|
|
|
30497
30854
|
}
|
|
30498
30855
|
const dnsmasqMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
30499
30856
|
if (dnsmasqMatch) {
|
|
30500
|
-
this.
|
|
30857
|
+
this.record({
|
|
30501
30858
|
type: dnsmasqMatch[1],
|
|
30502
30859
|
domain: dnsmasqMatch[2],
|
|
30503
30860
|
source_ip: dnsmasqMatch[3],
|
|
@@ -30508,7 +30865,7 @@ var DnsMonitor = class {
|
|
|
30508
30865
|
const genericMatch = line.match(/(?:query|lookup|resolve)[:\s]+(\S+)/i);
|
|
30509
30866
|
if (genericMatch) {
|
|
30510
30867
|
const typeMatch = line.match(/type[:\s]+(\w+)/i);
|
|
30511
|
-
this.
|
|
30868
|
+
this.record({
|
|
30512
30869
|
type: typeMatch?.[1] || "A",
|
|
30513
30870
|
domain: genericMatch[1],
|
|
30514
30871
|
timestamp: Date.now()
|
|
@@ -30588,6 +30945,11 @@ var DnsMonitor = class {
|
|
|
30588
30945
|
}
|
|
30589
30946
|
return entropy;
|
|
30590
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
|
+
}
|
|
30591
30953
|
emitEvent(severity, message, sourceIp, details) {
|
|
30592
30954
|
const event = {
|
|
30593
30955
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -30651,6 +31013,18 @@ var ModuleHost = class {
|
|
|
30651
31013
|
this.bus.announceModule("user-journal", "running", mod.detail);
|
|
30652
31014
|
}
|
|
30653
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
|
+
}
|
|
30654
31028
|
this.networkMonitor = new NetworkMonitor(this.bus);
|
|
30655
31029
|
if (this.networkMonitor.start()) {
|
|
30656
31030
|
const nmod = this.modules.get("network-monitor");
|
|
@@ -30669,7 +31043,7 @@ var ModuleHost = class {
|
|
|
30669
31043
|
const dmod = this.modules.get("dns-monitor");
|
|
30670
31044
|
if (dmod) {
|
|
30671
31045
|
dmod.status = "running";
|
|
30672
|
-
dmod.detail =
|
|
31046
|
+
dmod.detail = `monitoring DNS: ${this.dnsMonitor.sources().join(", ") || "no source"}`;
|
|
30673
31047
|
this.bus.announceModule("dns-monitor", "running", dmod.detail);
|
|
30674
31048
|
}
|
|
30675
31049
|
}
|
|
@@ -30713,15 +31087,15 @@ var ModuleHost = class {
|
|
|
30713
31087
|
for (const m of builtins) this.modules.set(m.name, m);
|
|
30714
31088
|
}
|
|
30715
31089
|
async discoverAndStartInstalled() {
|
|
30716
|
-
if (!(0,
|
|
31090
|
+
if (!(0, import_node_fs24.existsSync)(PATHS.moduleDir)) return;
|
|
30717
31091
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
30718
|
-
const entries = (0,
|
|
31092
|
+
const entries = (0, import_node_fs24.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
30719
31093
|
for (const entry of entries) {
|
|
30720
31094
|
if (!entry.isDirectory()) continue;
|
|
30721
|
-
const manifestPath = (0,
|
|
30722
|
-
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;
|
|
30723
31097
|
try {
|
|
30724
|
-
const manifest = import_toml4.default.parse((0,
|
|
31098
|
+
const manifest = import_toml4.default.parse((0, import_node_fs24.readFileSync)(manifestPath, "utf-8"));
|
|
30725
31099
|
const name = manifest.module?.name || entry.name;
|
|
30726
31100
|
const defaults = manifest.module?.config?.defaults || {};
|
|
30727
31101
|
const config = {
|
|
@@ -30735,7 +31109,7 @@ var ModuleHost = class {
|
|
|
30735
31109
|
source: "installed",
|
|
30736
31110
|
status: config.enabled === false ? "disabled" : "loaded",
|
|
30737
31111
|
events: 0,
|
|
30738
|
-
path: (0,
|
|
31112
|
+
path: (0, import_node_path17.join)(PATHS.moduleDir, entry.name),
|
|
30739
31113
|
config
|
|
30740
31114
|
};
|
|
30741
31115
|
this.modules.set(name, hosted);
|
|
@@ -30750,7 +31124,7 @@ var ModuleHost = class {
|
|
|
30750
31124
|
status: "error",
|
|
30751
31125
|
events: 0,
|
|
30752
31126
|
detail: `manifest load failed: ${String(err.message || err)}`,
|
|
30753
|
-
path: (0,
|
|
31127
|
+
path: (0, import_node_path17.join)(PATHS.moduleDir, entry.name)
|
|
30754
31128
|
});
|
|
30755
31129
|
}
|
|
30756
31130
|
}
|
|
@@ -30789,17 +31163,17 @@ var ModuleHost = class {
|
|
|
30789
31163
|
}
|
|
30790
31164
|
}
|
|
30791
31165
|
installedEntrypoint(modulePath) {
|
|
30792
|
-
const packageJson = (0,
|
|
31166
|
+
const packageJson = (0, import_node_path17.join)(modulePath, "package.json");
|
|
30793
31167
|
const candidates = [];
|
|
30794
|
-
if ((0,
|
|
31168
|
+
if ((0, import_node_fs24.existsSync)(packageJson)) {
|
|
30795
31169
|
try {
|
|
30796
|
-
const pkg = JSON.parse((0,
|
|
30797
|
-
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));
|
|
30798
31172
|
} catch {
|
|
30799
31173
|
}
|
|
30800
31174
|
}
|
|
30801
|
-
candidates.push((0,
|
|
30802
|
-
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;
|
|
30803
31177
|
}
|
|
30804
31178
|
isThreatCrushModule(value) {
|
|
30805
31179
|
return Boolean(
|
|
@@ -31329,10 +31703,11 @@ var RuleEngine = class {
|
|
|
31329
31703
|
};
|
|
31330
31704
|
|
|
31331
31705
|
// src/daemon/rules/loader.ts
|
|
31332
|
-
var
|
|
31333
|
-
var
|
|
31706
|
+
var import_node_fs25 = require("fs");
|
|
31707
|
+
var import_node_path18 = require("path");
|
|
31334
31708
|
|
|
31335
31709
|
// src/daemon/rules/default-rules.ts
|
|
31710
|
+
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
31336
31711
|
var DEFAULT_RULES = [
|
|
31337
31712
|
{
|
|
31338
31713
|
id: "ssh-brute-force",
|
|
@@ -31353,8 +31728,7 @@ var DEFAULT_RULES = [
|
|
|
31353
31728
|
tags: ["ssh", "brute-force", "credential-stuffing"],
|
|
31354
31729
|
remediation: {
|
|
31355
31730
|
action: "block",
|
|
31356
|
-
|
|
31357
|
-
description: "Block source IP for 1 hour"
|
|
31731
|
+
description: "Block source IP"
|
|
31358
31732
|
},
|
|
31359
31733
|
enabled: true
|
|
31360
31734
|
},
|
|
@@ -31402,7 +31776,6 @@ var DEFAULT_RULES = [
|
|
|
31402
31776
|
tags: ["ssh", "root-access"],
|
|
31403
31777
|
remediation: {
|
|
31404
31778
|
action: "block",
|
|
31405
|
-
ttl_seconds: 7200,
|
|
31406
31779
|
description: "Block source IP attempting root login"
|
|
31407
31780
|
},
|
|
31408
31781
|
enabled: true
|
|
@@ -31426,7 +31799,6 @@ var DEFAULT_RULES = [
|
|
|
31426
31799
|
tags: ["ssh", "enumeration", "reconnaissance"],
|
|
31427
31800
|
remediation: {
|
|
31428
31801
|
action: "block",
|
|
31429
|
-
ttl_seconds: 3600,
|
|
31430
31802
|
description: "Block source IP performing user enumeration"
|
|
31431
31803
|
},
|
|
31432
31804
|
enabled: true
|
|
@@ -31456,20 +31828,15 @@ var DEFAULT_RULES = [
|
|
|
31456
31828
|
description: "HTTP request with SQL injection patterns",
|
|
31457
31829
|
version: "1.0.0",
|
|
31458
31830
|
category: "web",
|
|
31459
|
-
severity: "
|
|
31831
|
+
severity: "high",
|
|
31460
31832
|
source_types: ["log-watcher", "web"],
|
|
31461
|
-
match: {
|
|
31462
|
-
field: "message",
|
|
31463
|
-
operator: "contains",
|
|
31464
|
-
value: "Attack detected [SQLI]"
|
|
31465
|
-
},
|
|
31833
|
+
match: { field: "attack_type", operator: "equals", value: "sqli", and: [AT_CRS_THRESHOLD] },
|
|
31466
31834
|
threshold: 1,
|
|
31467
31835
|
window_seconds: 60,
|
|
31468
31836
|
cooldown_seconds: 300,
|
|
31469
31837
|
tags: ["web", "sqli", "injection"],
|
|
31470
31838
|
remediation: {
|
|
31471
31839
|
action: "block",
|
|
31472
|
-
ttl_seconds: 3600,
|
|
31473
31840
|
description: "Block source IP performing SQL injection"
|
|
31474
31841
|
},
|
|
31475
31842
|
enabled: true
|
|
@@ -31480,20 +31847,15 @@ var DEFAULT_RULES = [
|
|
|
31480
31847
|
description: "HTTP request with path traversal patterns",
|
|
31481
31848
|
version: "1.0.0",
|
|
31482
31849
|
category: "web",
|
|
31483
|
-
severity: "
|
|
31850
|
+
severity: "high",
|
|
31484
31851
|
source_types: ["log-watcher", "web"],
|
|
31485
|
-
match: {
|
|
31486
|
-
field: "message",
|
|
31487
|
-
operator: "contains",
|
|
31488
|
-
value: "Attack detected [PATH_TRAVERSAL]"
|
|
31489
|
-
},
|
|
31852
|
+
match: { field: "attack_type", operator: "equals", value: "path_traversal", and: [AT_CRS_THRESHOLD] },
|
|
31490
31853
|
threshold: 1,
|
|
31491
31854
|
window_seconds: 60,
|
|
31492
31855
|
cooldown_seconds: 300,
|
|
31493
31856
|
tags: ["web", "path-traversal", "lfi"],
|
|
31494
31857
|
remediation: {
|
|
31495
31858
|
action: "block",
|
|
31496
|
-
ttl_seconds: 3600,
|
|
31497
31859
|
description: "Block source IP performing path traversal"
|
|
31498
31860
|
},
|
|
31499
31861
|
enabled: true
|
|
@@ -31506,22 +31868,39 @@ var DEFAULT_RULES = [
|
|
|
31506
31868
|
category: "web",
|
|
31507
31869
|
severity: "high",
|
|
31508
31870
|
source_types: ["log-watcher", "web"],
|
|
31509
|
-
match: {
|
|
31510
|
-
field: "message",
|
|
31511
|
-
operator: "regex",
|
|
31512
|
-
value: "Attack detected \\[XSS\\]"
|
|
31513
|
-
},
|
|
31871
|
+
match: { field: "attack_type", operator: "equals", value: "xss", and: [AT_CRS_THRESHOLD] },
|
|
31514
31872
|
threshold: 1,
|
|
31515
31873
|
window_seconds: 60,
|
|
31516
31874
|
cooldown_seconds: 300,
|
|
31517
31875
|
tags: ["web", "xss", "injection"],
|
|
31518
31876
|
remediation: {
|
|
31519
31877
|
action: "block",
|
|
31520
|
-
ttl_seconds: 3600,
|
|
31521
31878
|
description: "Block source IP performing XSS attack"
|
|
31522
31879
|
},
|
|
31523
31880
|
enabled: true
|
|
31524
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
|
+
},
|
|
31525
31904
|
{
|
|
31526
31905
|
id: "web-scanner-detection",
|
|
31527
31906
|
title: "Web Vulnerability Scanner Detected",
|
|
@@ -31541,7 +31920,6 @@ var DEFAULT_RULES = [
|
|
|
31541
31920
|
tags: ["web", "scanner", "reconnaissance"],
|
|
31542
31921
|
remediation: {
|
|
31543
31922
|
action: "block",
|
|
31544
|
-
ttl_seconds: 1800,
|
|
31545
31923
|
description: "Block automated scanner"
|
|
31546
31924
|
},
|
|
31547
31925
|
enabled: true
|
|
@@ -31631,7 +32009,6 @@ var DEFAULT_RULES = [
|
|
|
31631
32009
|
tags: ["network", "port-scan", "reconnaissance"],
|
|
31632
32010
|
remediation: {
|
|
31633
32011
|
action: "block",
|
|
31634
|
-
ttl_seconds: 3600,
|
|
31635
32012
|
description: "Block port scanner"
|
|
31636
32013
|
},
|
|
31637
32014
|
enabled: true
|
|
@@ -31663,10 +32040,13 @@ var DEFAULT_RULES = [
|
|
|
31663
32040
|
category: "web",
|
|
31664
32041
|
severity: "high",
|
|
31665
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.
|
|
31666
32045
|
match: {
|
|
31667
|
-
field: "
|
|
32046
|
+
field: "attack_type",
|
|
31668
32047
|
operator: "regex",
|
|
31669
|
-
value: "
|
|
32048
|
+
value: "^(rce|ssrf|rfi|php_injection|ssti)$",
|
|
32049
|
+
and: [AT_CRS_THRESHOLD]
|
|
31670
32050
|
},
|
|
31671
32051
|
threshold: 1,
|
|
31672
32052
|
window_seconds: 60,
|
|
@@ -31674,7 +32054,6 @@ var DEFAULT_RULES = [
|
|
|
31674
32054
|
tags: ["web", "exploit", "probe"],
|
|
31675
32055
|
remediation: {
|
|
31676
32056
|
action: "block",
|
|
31677
|
-
ttl_seconds: 7200,
|
|
31678
32057
|
description: "Block source IP performing exploit probes"
|
|
31679
32058
|
},
|
|
31680
32059
|
enabled: true
|
|
@@ -31686,11 +32065,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
31686
32065
|
function loadAllRules(customDir) {
|
|
31687
32066
|
const rules = [...DEFAULT_RULES];
|
|
31688
32067
|
const dir = customDir || RULES_DIR;
|
|
31689
|
-
if ((0,
|
|
31690
|
-
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"));
|
|
31691
32070
|
for (const file of files) {
|
|
31692
32071
|
try {
|
|
31693
|
-
const raw = (0,
|
|
32072
|
+
const raw = (0, import_node_fs25.readFileSync)((0, import_node_path18.join)(dir, file), "utf-8");
|
|
31694
32073
|
const parsed = JSON.parse(raw);
|
|
31695
32074
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
31696
32075
|
for (const rule of customRules) {
|
|
@@ -31698,6 +32077,13 @@ function loadAllRules(customDir) {
|
|
|
31698
32077
|
console.warn(`[rules] skipping invalid rule in ${file}: missing required fields`);
|
|
31699
32078
|
continue;
|
|
31700
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
|
+
}
|
|
31701
32087
|
const existingIdx = rules.findIndex((r) => r.id === rule.id);
|
|
31702
32088
|
if (existingIdx >= 0) {
|
|
31703
32089
|
rules[existingIdx] = { ...rules[existingIdx], ...rule };
|
|
@@ -31715,8 +32101,8 @@ function loadAllRules(customDir) {
|
|
|
31715
32101
|
|
|
31716
32102
|
// src/daemon/firewall/adapters.ts
|
|
31717
32103
|
var import_node_child_process7 = require("child_process");
|
|
31718
|
-
var
|
|
31719
|
-
var
|
|
32104
|
+
var import_node_fs26 = require("fs");
|
|
32105
|
+
var import_node_path19 = require("path");
|
|
31720
32106
|
var import_node_net3 = require("net");
|
|
31721
32107
|
function assertValidFirewallIp(ip) {
|
|
31722
32108
|
if ((0, import_node_net3.isIP)(ip) !== 4) {
|
|
@@ -31729,9 +32115,9 @@ function assertBannableIp(ip) {
|
|
|
31729
32115
|
}
|
|
31730
32116
|
}
|
|
31731
32117
|
function writeIfAbsent(path, contents) {
|
|
31732
|
-
(0,
|
|
32118
|
+
(0, import_node_fs26.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
|
|
31733
32119
|
try {
|
|
31734
|
-
(0,
|
|
32120
|
+
(0, import_node_fs26.writeFileSync)(path, contents, { flag: "wx" });
|
|
31735
32121
|
} catch (err) {
|
|
31736
32122
|
if (err.code !== "EEXIST") throw err;
|
|
31737
32123
|
}
|
|
@@ -31986,7 +32372,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
31986
32372
|
}
|
|
31987
32373
|
|
|
31988
32374
|
// src/daemon/firewall/remediation.ts
|
|
31989
|
-
var
|
|
32375
|
+
var import_node_fs27 = require("fs");
|
|
31990
32376
|
var import_node_net5 = require("net");
|
|
31991
32377
|
init_paths();
|
|
31992
32378
|
init_backoff();
|
|
@@ -32504,7 +32890,7 @@ var RemediationManager = class {
|
|
|
32504
32890
|
}
|
|
32505
32891
|
logLine(line) {
|
|
32506
32892
|
try {
|
|
32507
|
-
(0,
|
|
32893
|
+
(0, import_node_fs27.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
32508
32894
|
`);
|
|
32509
32895
|
} catch {
|
|
32510
32896
|
}
|
|
@@ -32585,7 +32971,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
32585
32971
|
// src/daemon/index.ts
|
|
32586
32972
|
function readVersion2() {
|
|
32587
32973
|
try {
|
|
32588
|
-
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"));
|
|
32589
32975
|
return pkg.version || "0.0.0";
|
|
32590
32976
|
} catch {
|
|
32591
32977
|
return "0.0.0";
|
|
@@ -32593,7 +32979,7 @@ function readVersion2() {
|
|
|
32593
32979
|
}
|
|
32594
32980
|
function logLine(line) {
|
|
32595
32981
|
try {
|
|
32596
|
-
(0,
|
|
32982
|
+
(0, import_node_fs28.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
32597
32983
|
`);
|
|
32598
32984
|
} catch {
|
|
32599
32985
|
}
|
|
@@ -32621,7 +33007,7 @@ async function runDaemon() {
|
|
|
32621
33007
|
} catch (err) {
|
|
32622
33008
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
32623
33009
|
}
|
|
32624
|
-
const config = loadConfig((0,
|
|
33010
|
+
const config = loadConfig((0, import_node_fs28.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
32625
33011
|
configureAttackDetection(config.detection);
|
|
32626
33012
|
bus.on("event", (event) => {
|
|
32627
33013
|
logLine(`[event] ${event.severity} ${event.module} ${event.message}`);
|
|
@@ -32727,7 +33113,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
32727
33113
|
function isRoot2() {
|
|
32728
33114
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
32729
33115
|
}
|
|
32730
|
-
var DAEMON_ENTRY = (0,
|
|
33116
|
+
var DAEMON_ENTRY = (0, import_node_path21.join)(__dirname, "daemon.js");
|
|
32731
33117
|
async function daemonForeground() {
|
|
32732
33118
|
await runDaemon();
|
|
32733
33119
|
}
|
|
@@ -32748,7 +33134,7 @@ async function daemonStart() {
|
|
|
32748
33134
|
return;
|
|
32749
33135
|
}
|
|
32750
33136
|
ensureRuntimeDirs();
|
|
32751
|
-
if (!(0,
|
|
33137
|
+
if (!(0, import_node_fs29.existsSync)(DAEMON_ENTRY)) {
|
|
32752
33138
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
32753
33139
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
32754
33140
|
return;
|
|
@@ -32756,8 +33142,8 @@ async function daemonStart() {
|
|
|
32756
33142
|
let out;
|
|
32757
33143
|
let err;
|
|
32758
33144
|
try {
|
|
32759
|
-
out = (0,
|
|
32760
|
-
err = (0,
|
|
33145
|
+
out = (0, import_node_fs30.openSync)(PATHS.logFile, "a");
|
|
33146
|
+
err = (0, import_node_fs30.openSync)(PATHS.logFile, "a");
|
|
32761
33147
|
} catch (e) {
|
|
32762
33148
|
const code = e.code;
|
|
32763
33149
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -32843,12 +33229,12 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
32843
33229
|
}
|
|
32844
33230
|
async function releaseStaleSocket() {
|
|
32845
33231
|
const deadline = Date.now() + 2e3;
|
|
32846
|
-
while ((0,
|
|
33232
|
+
while ((0, import_node_fs29.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
32847
33233
|
await new Promise((r) => setTimeout(r, 50));
|
|
32848
33234
|
}
|
|
32849
|
-
if ((0,
|
|
33235
|
+
if ((0, import_node_fs29.existsSync)(PATHS.socket)) {
|
|
32850
33236
|
try {
|
|
32851
|
-
(0,
|
|
33237
|
+
(0, import_node_fs29.unlinkSync)(PATHS.socket);
|
|
32852
33238
|
} catch {
|
|
32853
33239
|
}
|
|
32854
33240
|
}
|
|
@@ -32856,25 +33242,25 @@ async function releaseStaleSocket() {
|
|
|
32856
33242
|
|
|
32857
33243
|
// src/commands/service.ts
|
|
32858
33244
|
var import_node_child_process10 = require("child_process");
|
|
32859
|
-
var
|
|
32860
|
-
var
|
|
33245
|
+
var import_node_fs31 = require("fs");
|
|
33246
|
+
var import_node_path22 = require("path");
|
|
32861
33247
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
32862
33248
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
32863
33249
|
function resolveTemplate() {
|
|
32864
|
-
const templatePath = (0,
|
|
32865
|
-
if (!(0,
|
|
33250
|
+
const templatePath = (0, import_node_path22.join)(__dirname, "systemd", "threatcrushd.service");
|
|
33251
|
+
if (!(0, import_node_fs31.existsSync)(templatePath)) {
|
|
32866
33252
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
32867
33253
|
}
|
|
32868
|
-
return (0,
|
|
33254
|
+
return (0, import_node_fs31.readFileSync)(templatePath, "utf-8");
|
|
32869
33255
|
}
|
|
32870
33256
|
function stableBinPath(binPath) {
|
|
32871
33257
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
32872
33258
|
if (stable === binPath) return binPath;
|
|
32873
|
-
return (0,
|
|
33259
|
+
return (0, import_node_fs31.existsSync)(stable) ? stable : binPath;
|
|
32874
33260
|
}
|
|
32875
33261
|
function resolveBinPath() {
|
|
32876
33262
|
const arg = process.argv[1];
|
|
32877
|
-
if (arg && (0,
|
|
33263
|
+
if (arg && (0, import_node_fs31.existsSync)(arg)) return stableBinPath(arg);
|
|
32878
33264
|
try {
|
|
32879
33265
|
return (0, import_node_child_process10.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
32880
33266
|
} catch {
|
|
@@ -32884,11 +33270,11 @@ function resolveBinPath() {
|
|
|
32884
33270
|
function stableNodePath(execPath) {
|
|
32885
33271
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
32886
33272
|
if (stable === execPath) return execPath;
|
|
32887
|
-
return (0,
|
|
33273
|
+
return (0, import_node_fs31.existsSync)(stable) ? stable : execPath;
|
|
32888
33274
|
}
|
|
32889
33275
|
function looksLikeNodeScript(path) {
|
|
32890
33276
|
try {
|
|
32891
|
-
const head = (0,
|
|
33277
|
+
const head = (0, import_node_fs31.readFileSync)(path, "utf-8").slice(0, 120);
|
|
32892
33278
|
return /^#!.*\bnode\b/.test(head);
|
|
32893
33279
|
} catch {
|
|
32894
33280
|
return false;
|
|
@@ -32914,7 +33300,7 @@ function callerHome() {
|
|
|
32914
33300
|
try {
|
|
32915
33301
|
const line = (0, import_node_child_process10.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
32916
33302
|
const home = line.split(":")[5];
|
|
32917
|
-
return home && (0,
|
|
33303
|
+
return home && (0, import_node_fs31.existsSync)(home) ? home : null;
|
|
32918
33304
|
} catch {
|
|
32919
33305
|
return null;
|
|
32920
33306
|
}
|
|
@@ -32922,13 +33308,13 @@ function callerHome() {
|
|
|
32922
33308
|
function stopUserModeDaemon() {
|
|
32923
33309
|
const home = callerHome();
|
|
32924
33310
|
if (!home) return;
|
|
32925
|
-
const runDir = (0,
|
|
32926
|
-
const pidFile = (0,
|
|
32927
|
-
const socket = (0,
|
|
32928
|
-
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;
|
|
32929
33315
|
let pid = null;
|
|
32930
33316
|
try {
|
|
32931
|
-
pid = Number.parseInt((0,
|
|
33317
|
+
pid = Number.parseInt((0, import_node_fs31.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
32932
33318
|
} catch {
|
|
32933
33319
|
pid = null;
|
|
32934
33320
|
}
|
|
@@ -32941,7 +33327,7 @@ function stopUserModeDaemon() {
|
|
|
32941
33327
|
}
|
|
32942
33328
|
for (const path of [socket, pidFile]) {
|
|
32943
33329
|
try {
|
|
32944
|
-
if ((0,
|
|
33330
|
+
if ((0, import_node_fs31.existsSync)(path)) (0, import_node_fs31.rmSync)(path);
|
|
32945
33331
|
} catch {
|
|
32946
33332
|
}
|
|
32947
33333
|
}
|
|
@@ -32969,7 +33355,7 @@ async function installServiceCommand() {
|
|
|
32969
33355
|
looksLikeNodeScript(binPath)
|
|
32970
33356
|
);
|
|
32971
33357
|
const unit = resolveTemplate().replace("{{BIN_PATH}} daemon", exec).replace("{{BIN_PATH}}", binPath);
|
|
32972
|
-
(0,
|
|
33358
|
+
(0, import_node_fs31.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
32973
33359
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
32974
33360
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
32975
33361
|
ensureSystemDirs();
|
|
@@ -33005,20 +33391,20 @@ function ensureSystemDirs() {
|
|
|
33005
33391
|
];
|
|
33006
33392
|
let admGid = null;
|
|
33007
33393
|
try {
|
|
33008
|
-
admGid = (0,
|
|
33394
|
+
admGid = (0, import_node_fs31.statSync)("/var/log/auth.log").gid;
|
|
33009
33395
|
} catch {
|
|
33010
33396
|
}
|
|
33011
33397
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
33012
33398
|
try {
|
|
33013
|
-
(0,
|
|
33399
|
+
(0, import_node_fs31.mkdirSync)(path, { recursive: true });
|
|
33014
33400
|
} catch {
|
|
33015
33401
|
}
|
|
33016
33402
|
try {
|
|
33017
33403
|
if (groupWritable && admGid !== null) {
|
|
33018
|
-
(0,
|
|
33404
|
+
(0, import_node_fs31.chmodSync)(path, sticky ? 1533 : 509);
|
|
33019
33405
|
(0, import_node_child_process10.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
33020
33406
|
} else {
|
|
33021
|
-
(0,
|
|
33407
|
+
(0, import_node_fs31.chmodSync)(path, 493);
|
|
33022
33408
|
}
|
|
33023
33409
|
} catch {
|
|
33024
33410
|
}
|
|
@@ -33046,7 +33432,7 @@ async function uninstallServiceCommand() {
|
|
|
33046
33432
|
} catch {
|
|
33047
33433
|
}
|
|
33048
33434
|
try {
|
|
33049
|
-
if ((0,
|
|
33435
|
+
if ((0, import_node_fs31.existsSync)(UNIT_PATH)) {
|
|
33050
33436
|
(0, import_node_child_process10.execSync)(`rm -f ${UNIT_PATH}`);
|
|
33051
33437
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
33052
33438
|
}
|
|
@@ -33144,8 +33530,8 @@ function welcomeCommand() {
|
|
|
33144
33530
|
}
|
|
33145
33531
|
|
|
33146
33532
|
// src/commands/properties.ts
|
|
33147
|
-
var
|
|
33148
|
-
var
|
|
33533
|
+
var import_node_fs32 = require("fs");
|
|
33534
|
+
var import_node_path23 = require("path");
|
|
33149
33535
|
var import_node_readline6 = __toESM(require("readline"));
|
|
33150
33536
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
33151
33537
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
@@ -33474,8 +33860,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
33474
33860
|
}
|
|
33475
33861
|
}
|
|
33476
33862
|
function parseImportFile(path) {
|
|
33477
|
-
const ext = (0,
|
|
33478
|
-
const raw = (0,
|
|
33863
|
+
const ext = (0, import_node_path23.extname)(path).toLowerCase();
|
|
33864
|
+
const raw = (0, import_node_fs32.readFileSync)(path, "utf-8");
|
|
33479
33865
|
if (ext === ".json") {
|
|
33480
33866
|
const parsed = JSON.parse(raw);
|
|
33481
33867
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -33633,13 +34019,18 @@ async function rulesShowCommand(ruleId) {
|
|
|
33633
34019
|
console.log(` Enabled: ${rule.enabled ? source_default.green("yes") : source_default.red("no")}`);
|
|
33634
34020
|
if (rule.remediation) {
|
|
33635
34021
|
console.log(` Remediation: ${source_default.gray(rule.remediation.description || rule.remediation.action || "none")}`);
|
|
33636
|
-
if (rule.remediation.
|
|
33637
|
-
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")}`);
|
|
33638
34024
|
}
|
|
33639
34025
|
}
|
|
33640
34026
|
console.log();
|
|
33641
34027
|
console.log(source_default.gray(" Match condition:"));
|
|
33642
|
-
|
|
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);
|
|
33643
34034
|
console.log();
|
|
33644
34035
|
}
|
|
33645
34036
|
async function rulesCommand(opts) {
|
|
@@ -33665,7 +34056,7 @@ async function rulesCommand(opts) {
|
|
|
33665
34056
|
}
|
|
33666
34057
|
|
|
33667
34058
|
// src/commands/harden.ts
|
|
33668
|
-
var
|
|
34059
|
+
var import_node_fs33 = require("fs");
|
|
33669
34060
|
var import_node_child_process11 = require("child_process");
|
|
33670
34061
|
function tryExec(cmd) {
|
|
33671
34062
|
try {
|
|
@@ -33676,7 +34067,7 @@ function tryExec(cmd) {
|
|
|
33676
34067
|
}
|
|
33677
34068
|
function tryRead(path) {
|
|
33678
34069
|
try {
|
|
33679
|
-
return (0,
|
|
34070
|
+
return (0, import_node_fs33.readFileSync)(path, "utf-8");
|
|
33680
34071
|
} catch {
|
|
33681
34072
|
return null;
|
|
33682
34073
|
}
|
|
@@ -33780,8 +34171,8 @@ function checkSshWeakConfig() {
|
|
|
33780
34171
|
};
|
|
33781
34172
|
}
|
|
33782
34173
|
function checkAutoUpdates() {
|
|
33783
|
-
const unattended = (0,
|
|
33784
|
-
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");
|
|
33785
34176
|
if (unattended || dnfAuto) {
|
|
33786
34177
|
return {
|
|
33787
34178
|
key: "auto-updates",
|
|
@@ -33907,7 +34298,7 @@ function checkFail2ban() {
|
|
|
33907
34298
|
explanation: "fail2ban is installed and running."
|
|
33908
34299
|
};
|
|
33909
34300
|
}
|
|
33910
|
-
if ((0,
|
|
34301
|
+
if ((0, import_node_fs33.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
33911
34302
|
return {
|
|
33912
34303
|
key: checkKey,
|
|
33913
34304
|
status: "warn",
|
|
@@ -34320,7 +34711,7 @@ ${source_default.dim(" C R U S H")}
|
|
|
34320
34711
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
34321
34712
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
34322
34713
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
34323
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
34714
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
|
|
34324
34715
|
function detectPackageManager() {
|
|
34325
34716
|
try {
|
|
34326
34717
|
const npmGlobal = (0, import_node_child_process13.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
@@ -34346,7 +34737,7 @@ function detectPackageManager() {
|
|
|
34346
34737
|
}
|
|
34347
34738
|
function readInstallConfig() {
|
|
34348
34739
|
try {
|
|
34349
|
-
return JSON.parse((0,
|
|
34740
|
+
return JSON.parse((0, import_node_fs34.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
34350
34741
|
} catch {
|
|
34351
34742
|
return {};
|
|
34352
34743
|
}
|
|
@@ -34610,7 +35001,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
34610
35001
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
34611
35002
|
console.log(LOGO2);
|
|
34612
35003
|
const logPath = PATHS.logFile;
|
|
34613
|
-
if (!(0,
|
|
35004
|
+
if (!(0, import_node_fs34.existsSync)(logPath)) {
|
|
34614
35005
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
34615
35006
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
34616
35007
|
return;
|
|
@@ -34818,10 +35209,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
34818
35209
|
});
|
|
34819
35210
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
34820
35211
|
console.log(LOGO2);
|
|
34821
|
-
const configPath = (0,
|
|
35212
|
+
const configPath = (0, import_node_path24.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
|
|
34822
35213
|
let email = "";
|
|
34823
35214
|
try {
|
|
34824
|
-
const config = JSON.parse((0,
|
|
35215
|
+
const config = JSON.parse((0, import_node_fs34.readFileSync)(configPath, "utf-8"));
|
|
34825
35216
|
email = config.email || "";
|
|
34826
35217
|
} catch {
|
|
34827
35218
|
}
|
|
@@ -34838,9 +35229,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
34838
35229
|
return;
|
|
34839
35230
|
}
|
|
34840
35231
|
try {
|
|
34841
|
-
const dir = (0,
|
|
34842
|
-
if (!(0,
|
|
34843
|
-
(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));
|
|
34844
35235
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
34845
35236
|
} catch {
|
|
34846
35237
|
}
|