@profullstack/threatcrush 0.12.8 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/daemon.js +94 -29
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +206 -76
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10675,9 +10675,15 @@ function initialState(now = Date.now()) {
|
|
|
10675
10675
|
threatIndex: 0,
|
|
10676
10676
|
banIndex: 0,
|
|
10677
10677
|
notice: null,
|
|
10678
|
-
busy: false
|
|
10678
|
+
busy: false,
|
|
10679
|
+
moduleIndex: 0,
|
|
10680
|
+
moduleFilter: null
|
|
10679
10681
|
};
|
|
10680
10682
|
}
|
|
10683
|
+
function visibleEvents(state) {
|
|
10684
|
+
if (!state.moduleFilter) return state.events;
|
|
10685
|
+
return state.events.filter((e) => e.module === state.moduleFilter);
|
|
10686
|
+
}
|
|
10681
10687
|
function isBanned(state, ip) {
|
|
10682
10688
|
return state.bans.some((b) => b.ip === ip);
|
|
10683
10689
|
}
|
|
@@ -10768,6 +10774,10 @@ function reducer(state, action) {
|
|
|
10768
10774
|
return { ...state, focus: next };
|
|
10769
10775
|
}
|
|
10770
10776
|
case "select": {
|
|
10777
|
+
if (state.focus === "modules") {
|
|
10778
|
+
const max = Math.max(0, state.modules.length - 1);
|
|
10779
|
+
return { ...state, moduleIndex: Math.min(max, Math.max(0, state.moduleIndex + action.delta)) };
|
|
10780
|
+
}
|
|
10771
10781
|
if (state.focus === "threats") {
|
|
10772
10782
|
const max = Math.max(0, state.topSources.length - 1);
|
|
10773
10783
|
return { ...state, threatIndex: Math.min(max, Math.max(0, state.threatIndex + action.delta)) };
|
|
@@ -10779,6 +10789,10 @@ function reducer(state, action) {
|
|
|
10779
10789
|
return state;
|
|
10780
10790
|
}
|
|
10781
10791
|
case "select_at": {
|
|
10792
|
+
if (state.focus === "modules") {
|
|
10793
|
+
const max2 = Math.max(0, state.modules.length - 1);
|
|
10794
|
+
return { ...state, moduleIndex: Math.min(max2, Math.max(0, action.index)) };
|
|
10795
|
+
}
|
|
10782
10796
|
if (state.focus === "bans") {
|
|
10783
10797
|
const max2 = Math.max(0, state.bans.length - 1);
|
|
10784
10798
|
return { ...state, banIndex: Math.min(max2, Math.max(0, action.index)) };
|
|
@@ -10797,6 +10811,14 @@ function reducer(state, action) {
|
|
|
10797
10811
|
};
|
|
10798
10812
|
case "busy":
|
|
10799
10813
|
return { ...state, busy: action.busy };
|
|
10814
|
+
case "toggle_module_filter": {
|
|
10815
|
+
const name = state.modules[state.moduleIndex]?.name;
|
|
10816
|
+
if (!name) return state;
|
|
10817
|
+
const moduleFilter = state.moduleFilter === name ? null : name;
|
|
10818
|
+
return { ...state, moduleFilter, scrollBack: 0 };
|
|
10819
|
+
}
|
|
10820
|
+
case "clear_module_filter":
|
|
10821
|
+
return { ...state, moduleFilter: null, scrollBack: 0 };
|
|
10800
10822
|
case "counters":
|
|
10801
10823
|
return {
|
|
10802
10824
|
...state,
|
|
@@ -10828,7 +10850,9 @@ function reducer(state, action) {
|
|
|
10828
10850
|
bans: state.bans,
|
|
10829
10851
|
protectedList: state.protectedList,
|
|
10830
10852
|
firewall: state.firewall,
|
|
10831
|
-
focus: state.focus
|
|
10853
|
+
focus: state.focus,
|
|
10854
|
+
moduleFilter: state.moduleFilter,
|
|
10855
|
+
moduleIndex: state.moduleIndex
|
|
10832
10856
|
};
|
|
10833
10857
|
}
|
|
10834
10858
|
}
|
|
@@ -10861,7 +10885,7 @@ var FOCUS_ORDER, NOTICE_MS, TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
|
|
|
10861
10885
|
var init_state = __esm({
|
|
10862
10886
|
"src/tui/state.ts"() {
|
|
10863
10887
|
"use strict";
|
|
10864
|
-
FOCUS_ORDER = ["feed", "threats", "bans"];
|
|
10888
|
+
FOCUS_ORDER = ["feed", "modules", "threats", "bans"];
|
|
10865
10889
|
NOTICE_MS = 6e3;
|
|
10866
10890
|
TIMELINE_SLOTS = 60;
|
|
10867
10891
|
FEED_LIMIT = 500;
|
|
@@ -10975,11 +10999,16 @@ function clock(d) {
|
|
|
10975
10999
|
const pad = (n) => String(n).padStart(2, "0");
|
|
10976
11000
|
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
10977
11001
|
}
|
|
11002
|
+
function withHost(event) {
|
|
11003
|
+
const host = event.details?.host;
|
|
11004
|
+
if (typeof host !== "string" || host === "" || host === "-") return event.message;
|
|
11005
|
+
return `${host} \xB7 ${event.message}`;
|
|
11006
|
+
}
|
|
10978
11007
|
function toLogEntry(event) {
|
|
10979
11008
|
return {
|
|
10980
11009
|
time: clock(event.timestamp),
|
|
10981
11010
|
level: event.severity.toUpperCase(),
|
|
10982
|
-
message: event
|
|
11011
|
+
message: withHost(event),
|
|
10983
11012
|
meta: event.source_ip ? `${event.module} \xB7 ${event.source_ip}` : event.module
|
|
10984
11013
|
};
|
|
10985
11014
|
}
|
|
@@ -11048,14 +11077,17 @@ function tiles(ui, state, theme) {
|
|
|
11048
11077
|
});
|
|
11049
11078
|
});
|
|
11050
11079
|
}
|
|
11051
|
-
function modulesPanel(parent, state, theme) {
|
|
11080
|
+
function modulesPanel(parent, state, theme, options) {
|
|
11081
|
+
const focused = state.focus === "modules";
|
|
11052
11082
|
parent.panel(
|
|
11053
11083
|
{
|
|
11054
11084
|
title: " MODULES ",
|
|
11055
11085
|
size: "fill",
|
|
11056
11086
|
border: "rounded",
|
|
11057
|
-
borderColor: theme.border,
|
|
11087
|
+
borderColor: focused ? theme.borderFocused : theme.border,
|
|
11058
11088
|
titleColor: theme.primary,
|
|
11089
|
+
subtitle: focused ? "enter filters feed" : void 0,
|
|
11090
|
+
subtitleColor: theme.muted,
|
|
11059
11091
|
footer: state.modules.length > 0 ? `${state.modules.filter((m) => m.status === "running").length}/${state.modules.length} active` : void 0,
|
|
11060
11092
|
padding: [0, 1]
|
|
11061
11093
|
},
|
|
@@ -11067,7 +11099,17 @@ function modulesPanel(parent, state, theme) {
|
|
|
11067
11099
|
panel.table({
|
|
11068
11100
|
rows: state.modules,
|
|
11069
11101
|
header: false,
|
|
11102
|
+
selected: focused ? state.moduleIndex : -1,
|
|
11103
|
+
followSelection: true,
|
|
11104
|
+
onSelectRow: options.onModuleSelect,
|
|
11070
11105
|
columns: [
|
|
11106
|
+
{
|
|
11107
|
+
// Marks the module the feed is currently pinned to.
|
|
11108
|
+
key: "name",
|
|
11109
|
+
width: 2,
|
|
11110
|
+
render: (m) => state.moduleFilter === m.name ? "\u25B6" : " ",
|
|
11111
|
+
color: () => theme.primary
|
|
11112
|
+
},
|
|
11071
11113
|
{
|
|
11072
11114
|
key: "status",
|
|
11073
11115
|
width: 2,
|
|
@@ -11107,18 +11149,27 @@ function severityPanel(parent, state, theme) {
|
|
|
11107
11149
|
}
|
|
11108
11150
|
function feedPanel(parent, state, theme, options) {
|
|
11109
11151
|
const following = state.scrollBack === 0;
|
|
11152
|
+
const shown = visibleEvents(state);
|
|
11153
|
+
const filtered = state.moduleFilter !== null;
|
|
11110
11154
|
parent.panel(
|
|
11111
11155
|
{
|
|
11112
|
-
title: " LIVE EVENTS ",
|
|
11156
|
+
title: filtered ? ` LIVE EVENTS \xB7 ${state.moduleFilter} ` : " LIVE EVENTS ",
|
|
11113
11157
|
size: "2.4fr",
|
|
11114
11158
|
border: "rounded",
|
|
11115
11159
|
borderColor: state.connection === "live" ? theme.borderFocused : theme.border,
|
|
11116
11160
|
titleColor: theme.primary,
|
|
11117
|
-
subtitle: following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
|
|
11118
|
-
subtitleColor: severityColors.medium,
|
|
11161
|
+
subtitle: filtered ? `${shown.length}/${state.events.length} \xB7 esc clears filter` : following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
|
|
11162
|
+
subtitleColor: filtered ? theme.primary : severityColors.medium,
|
|
11119
11163
|
padding: [0, 1]
|
|
11120
11164
|
},
|
|
11121
11165
|
(panel) => {
|
|
11166
|
+
if (filtered && shown.length === 0 && state.events.length > 0) {
|
|
11167
|
+
panel.spacer(1);
|
|
11168
|
+
panel.text(`No events from ${state.moduleFilter} yet.`, { fg: theme.muted, align: "center" });
|
|
11169
|
+
panel.spacer(1);
|
|
11170
|
+
panel.label("esc shows everything again", { fg: theme.muted, align: "center" });
|
|
11171
|
+
return;
|
|
11172
|
+
}
|
|
11122
11173
|
if (state.events.length === 0) {
|
|
11123
11174
|
panel.spacer(1);
|
|
11124
11175
|
if (state.connection === "live") {
|
|
@@ -11139,7 +11190,7 @@ function feedPanel(parent, state, theme, options) {
|
|
|
11139
11190
|
return;
|
|
11140
11191
|
}
|
|
11141
11192
|
panel.log({
|
|
11142
|
-
entries:
|
|
11193
|
+
entries: shown.map(toLogEntry),
|
|
11143
11194
|
follow: following,
|
|
11144
11195
|
fromEnd: state.scrollBack,
|
|
11145
11196
|
scrollbar: true,
|
|
@@ -11320,8 +11371,7 @@ function footer(ui, state, theme) {
|
|
|
11320
11371
|
{ key: "q", label: "quit" },
|
|
11321
11372
|
{ key: "tab", label: state.focus },
|
|
11322
11373
|
{ key: "\u2191\u2193", label: onFeed ? "scroll" : "select" },
|
|
11323
|
-
{ key: "b", label: "ban" },
|
|
11324
|
-
{ key: "u", label: "unban" },
|
|
11374
|
+
...state.focus === "modules" ? [{ key: "\u23CE", label: state.moduleFilter ? "unfilter" : "filter" }] : [{ key: "b", label: "ban" }, { key: "u", label: "unban" }],
|
|
11325
11375
|
{ key: "p", label: state.paused ? "resume" : "pause" },
|
|
11326
11376
|
{ key: "r", label: "reset" }
|
|
11327
11377
|
],
|
|
@@ -11333,6 +11383,7 @@ function footer(ui, state, theme) {
|
|
|
11333
11383
|
label: state.paused && state.parked.length > 0 ? `${state.parked.length} held` : "",
|
|
11334
11384
|
color: severityColors.medium
|
|
11335
11385
|
},
|
|
11386
|
+
{ label: state.moduleFilter ? `filter: ${state.moduleFilter}` : "", color: theme.primary },
|
|
11336
11387
|
{
|
|
11337
11388
|
label: state.firewall ? `${state.bans.length} banned${state.firewall.dry_run ? " (dry-run)" : ""}` : "",
|
|
11338
11389
|
color: state.firewall?.dry_run ? severityColors.medium : theme.muted
|
|
@@ -11349,7 +11400,7 @@ function renderDashboard(ui, state, theme, options = {}) {
|
|
|
11349
11400
|
tiles(col, state, theme);
|
|
11350
11401
|
col.row({ size: "fill", gap: 0 }, (row) => {
|
|
11351
11402
|
row.column({ size: "1fr" }, (left) => {
|
|
11352
|
-
modulesPanel(left, state, theme);
|
|
11403
|
+
modulesPanel(left, state, theme, options);
|
|
11353
11404
|
severityPanel(left, state, theme);
|
|
11354
11405
|
});
|
|
11355
11406
|
feedPanel(row, state, theme, options);
|
|
@@ -11566,11 +11617,18 @@ async function startDashboard(options = {}) {
|
|
|
11566
11617
|
};
|
|
11567
11618
|
app.on("key", (event) => {
|
|
11568
11619
|
switch (event.key) {
|
|
11569
|
-
case "q":
|
|
11570
11620
|
case "escape":
|
|
11621
|
+
if (state.moduleFilter) dispatch({ type: "clear_module_filter" });
|
|
11622
|
+
else quit();
|
|
11623
|
+
break;
|
|
11624
|
+
case "q":
|
|
11571
11625
|
case "ctrl+c":
|
|
11572
11626
|
quit();
|
|
11573
11627
|
break;
|
|
11628
|
+
case "enter":
|
|
11629
|
+
case "return":
|
|
11630
|
+
dispatch({ type: "toggle_module_filter" });
|
|
11631
|
+
break;
|
|
11574
11632
|
case "p":
|
|
11575
11633
|
case "space":
|
|
11576
11634
|
dispatch({ type: "pause" });
|
|
@@ -11624,6 +11682,13 @@ async function startDashboard(options = {}) {
|
|
|
11624
11682
|
onBanSelect: (row) => {
|
|
11625
11683
|
dispatch({ type: "focus", focus: "bans" });
|
|
11626
11684
|
dispatch({ type: "select_at", index: row });
|
|
11685
|
+
},
|
|
11686
|
+
// One click on a module both selects it and pins the feed to it; a
|
|
11687
|
+
// second click on the same module releases the feed.
|
|
11688
|
+
onModuleSelect: (row) => {
|
|
11689
|
+
dispatch({ type: "focus", focus: "modules" });
|
|
11690
|
+
dispatch({ type: "select_at", index: row });
|
|
11691
|
+
dispatch({ type: "toggle_module_filter" });
|
|
11627
11692
|
}
|
|
11628
11693
|
});
|
|
11629
11694
|
});
|
|
@@ -15804,7 +15869,7 @@ var source_default = chalk;
|
|
|
15804
15869
|
|
|
15805
15870
|
// src/index.ts
|
|
15806
15871
|
var import_readline = __toESM(require("readline"));
|
|
15807
|
-
var
|
|
15872
|
+
var import_node_child_process13 = require("child_process");
|
|
15808
15873
|
var import_node_fs33 = require("fs");
|
|
15809
15874
|
var import_node_path23 = require("path");
|
|
15810
15875
|
var import_node_os8 = require("os");
|
|
@@ -23105,7 +23170,7 @@ async function sshConnect(options) {
|
|
|
23105
23170
|
}
|
|
23106
23171
|
|
|
23107
23172
|
// src/commands/daemon.ts
|
|
23108
|
-
var
|
|
23173
|
+
var import_node_child_process9 = require("child_process");
|
|
23109
23174
|
var import_node_fs28 = require("fs");
|
|
23110
23175
|
var import_node_path20 = require("path");
|
|
23111
23176
|
var import_node_fs29 = require("fs");
|
|
@@ -23851,6 +23916,7 @@ var NetworkMonitor = class {
|
|
|
23851
23916
|
|
|
23852
23917
|
// src/modules/dns-monitor/index.ts
|
|
23853
23918
|
var import_node_fs22 = require("fs");
|
|
23919
|
+
var import_node_child_process6 = require("child_process");
|
|
23854
23920
|
var import_node_readline5 = require("readline");
|
|
23855
23921
|
var DNS_LOG_SOURCES = [
|
|
23856
23922
|
"/var/log/syslog",
|
|
@@ -23862,10 +23928,30 @@ var DNS_LOG_SOURCES = [
|
|
|
23862
23928
|
"/var/log/pihole.log"
|
|
23863
23929
|
// Pi-hole
|
|
23864
23930
|
];
|
|
23931
|
+
function qtypeName(qtype) {
|
|
23932
|
+
const names = {
|
|
23933
|
+
1: "A",
|
|
23934
|
+
2: "NS",
|
|
23935
|
+
5: "CNAME",
|
|
23936
|
+
6: "SOA",
|
|
23937
|
+
12: "PTR",
|
|
23938
|
+
15: "MX",
|
|
23939
|
+
16: "TXT",
|
|
23940
|
+
28: "AAAA",
|
|
23941
|
+
33: "SRV",
|
|
23942
|
+
35: "NAPTR",
|
|
23943
|
+
43: "DS",
|
|
23944
|
+
48: "DNSKEY",
|
|
23945
|
+
65: "HTTPS",
|
|
23946
|
+
255: "ANY"
|
|
23947
|
+
};
|
|
23948
|
+
return names[qtype] ?? `TYPE${qtype}`;
|
|
23949
|
+
}
|
|
23865
23950
|
var DnsMonitor = class {
|
|
23866
|
-
|
|
23867
|
-
constructor(bus2) {
|
|
23951
|
+
constructor(bus2, options = {}) {
|
|
23868
23952
|
this.bus = bus2;
|
|
23953
|
+
this.extraPaths = options.log_paths ?? [];
|
|
23954
|
+
this.journalUnits = options.journal_units ?? [];
|
|
23869
23955
|
}
|
|
23870
23956
|
bus;
|
|
23871
23957
|
active = false;
|
|
@@ -23882,8 +23968,13 @@ var DnsMonitor = class {
|
|
|
23882
23968
|
// unique high-entropy domains per window
|
|
23883
23969
|
dgaWindowMs = 6e4;
|
|
23884
23970
|
entropyThreshold = 3.5;
|
|
23971
|
+
// Shannon entropy threshold for DGA
|
|
23972
|
+
/** Extra files and journal units from `[modules.dns-monitor]` in the config. */
|
|
23973
|
+
extraPaths = [];
|
|
23974
|
+
journalUnits = [];
|
|
23975
|
+
journalTails = [];
|
|
23885
23976
|
start() {
|
|
23886
|
-
const sources = DNS_LOG_SOURCES.filter((p) => {
|
|
23977
|
+
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
23887
23978
|
if (!(0, import_node_fs22.existsSync)(p)) return false;
|
|
23888
23979
|
try {
|
|
23889
23980
|
(0, import_node_fs22.accessSync)(p, import_node_fs22.constants.R_OK);
|
|
@@ -23892,7 +23983,8 @@ var DnsMonitor = class {
|
|
|
23892
23983
|
return false;
|
|
23893
23984
|
}
|
|
23894
23985
|
});
|
|
23895
|
-
|
|
23986
|
+
for (const unit of this.journalUnits) this.tailJournalUnit(unit);
|
|
23987
|
+
if (sources.length === 0 && this.journalTails.length === 0) return false;
|
|
23896
23988
|
this.active = true;
|
|
23897
23989
|
for (const src of sources) {
|
|
23898
23990
|
this.tailLog(src);
|
|
@@ -23903,8 +23995,30 @@ var DnsMonitor = class {
|
|
|
23903
23995
|
stop() {
|
|
23904
23996
|
for (const t of this.timers.values()) clearInterval(t);
|
|
23905
23997
|
this.timers.clear();
|
|
23998
|
+
for (const child of this.journalTails) {
|
|
23999
|
+
try {
|
|
24000
|
+
child.kill("SIGTERM");
|
|
24001
|
+
} catch {
|
|
24002
|
+
}
|
|
24003
|
+
}
|
|
24004
|
+
this.journalTails = [];
|
|
23906
24005
|
this.active = false;
|
|
23907
24006
|
}
|
|
24007
|
+
/** Follow one systemd unit's journal, feeding its lines to the same parser. */
|
|
24008
|
+
tailJournalUnit(unit) {
|
|
24009
|
+
try {
|
|
24010
|
+
const child = (0, import_node_child_process6.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
|
|
24011
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
24012
|
+
});
|
|
24013
|
+
if (!child.stdout) return;
|
|
24014
|
+
const rl = (0, import_node_readline5.createInterface)({ input: child.stdout });
|
|
24015
|
+
rl.on("line", (line) => this.parseDnsLine(line));
|
|
24016
|
+
child.on("error", () => {
|
|
24017
|
+
});
|
|
24018
|
+
this.journalTails.push(child);
|
|
24019
|
+
} catch {
|
|
24020
|
+
}
|
|
24021
|
+
}
|
|
23908
24022
|
isActive() {
|
|
23909
24023
|
return this.active;
|
|
23910
24024
|
}
|
|
@@ -23937,6 +24051,18 @@ var DnsMonitor = class {
|
|
|
23937
24051
|
rl.on("close", () => this.positions.set(path, stat.size));
|
|
23938
24052
|
}
|
|
23939
24053
|
parseDnsLine(line) {
|
|
24054
|
+
const moshpit = line.match(
|
|
24055
|
+
/\[dns\]\s+(?:udp|tcp|doh)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w+)/i
|
|
24056
|
+
);
|
|
24057
|
+
if (moshpit) {
|
|
24058
|
+
this.domainBuffer.push({
|
|
24059
|
+
type: qtypeName(Number.parseInt(moshpit[3], 10)),
|
|
24060
|
+
domain: moshpit[2],
|
|
24061
|
+
source_ip: moshpit[1],
|
|
24062
|
+
timestamp: Date.now()
|
|
24063
|
+
});
|
|
24064
|
+
return;
|
|
24065
|
+
}
|
|
23940
24066
|
const resolvedMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
23941
24067
|
if (resolvedMatch) {
|
|
23942
24068
|
this.domainBuffer.push({
|
|
@@ -24112,7 +24238,11 @@ var ModuleHost = class {
|
|
|
24112
24238
|
this.bus.announceModule("network-monitor", "running", nmod.detail);
|
|
24113
24239
|
}
|
|
24114
24240
|
}
|
|
24115
|
-
|
|
24241
|
+
const dnsConfig = loadModuleConfigs(PATHS.confD).get("dns-monitor") ?? {};
|
|
24242
|
+
this.dnsMonitor = new DnsMonitor(this.bus, {
|
|
24243
|
+
log_paths: Array.isArray(dnsConfig.log_paths) ? dnsConfig.log_paths : void 0,
|
|
24244
|
+
journal_units: Array.isArray(dnsConfig.journal_units) ? dnsConfig.journal_units : void 0
|
|
24245
|
+
});
|
|
24116
24246
|
if (this.dnsMonitor.start()) {
|
|
24117
24247
|
const dmod = this.modules.get("dns-monitor");
|
|
24118
24248
|
if (dmod) {
|
|
@@ -25087,7 +25217,7 @@ function loadAllRules(customDir) {
|
|
|
25087
25217
|
}
|
|
25088
25218
|
|
|
25089
25219
|
// src/daemon/firewall/adapters.ts
|
|
25090
|
-
var
|
|
25220
|
+
var import_node_child_process7 = require("child_process");
|
|
25091
25221
|
var import_node_fs25 = require("fs");
|
|
25092
25222
|
var import_node_path18 = require("path");
|
|
25093
25223
|
var import_node_net3 = require("net");
|
|
@@ -25123,11 +25253,11 @@ var Fail2banAdapter = class {
|
|
|
25123
25253
|
enforces = true;
|
|
25124
25254
|
jailReady = false;
|
|
25125
25255
|
isAvailable() {
|
|
25126
|
-
const result = (0,
|
|
25256
|
+
const result = (0, import_node_child_process7.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
25127
25257
|
return result.status === 0;
|
|
25128
25258
|
}
|
|
25129
25259
|
client(args) {
|
|
25130
|
-
return (0,
|
|
25260
|
+
return (0, import_node_child_process7.execFileSync)("fail2ban-client", args, {
|
|
25131
25261
|
encoding: "utf-8",
|
|
25132
25262
|
stdio: ["ignore", "pipe", "pipe"]
|
|
25133
25263
|
});
|
|
@@ -25219,35 +25349,35 @@ var NftablesAdapter = class {
|
|
|
25219
25349
|
table = "threatcrush";
|
|
25220
25350
|
set = "blocklist";
|
|
25221
25351
|
isAvailable() {
|
|
25222
|
-
const result = (0,
|
|
25352
|
+
const result = (0, import_node_child_process7.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
25223
25353
|
return result.status === 0;
|
|
25224
25354
|
}
|
|
25225
25355
|
ensureSetup() {
|
|
25226
25356
|
try {
|
|
25227
|
-
(0,
|
|
25357
|
+
(0, import_node_child_process7.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
25228
25358
|
} catch {
|
|
25229
|
-
(0,
|
|
25230
|
-
(0,
|
|
25231
|
-
(0,
|
|
25232
|
-
(0,
|
|
25359
|
+
(0, import_node_child_process7.execSync)(`nft add table inet ${this.table}`);
|
|
25360
|
+
(0, import_node_child_process7.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
25361
|
+
(0, import_node_child_process7.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
25362
|
+
(0, import_node_child_process7.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
25233
25363
|
}
|
|
25234
25364
|
}
|
|
25235
25365
|
async block(ip) {
|
|
25236
25366
|
assertValidFirewallIp(ip);
|
|
25237
25367
|
this.ensureSetup();
|
|
25238
|
-
(0,
|
|
25368
|
+
(0, import_node_child_process7.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
25239
25369
|
}
|
|
25240
25370
|
async unblock(ip) {
|
|
25241
25371
|
assertValidFirewallIp(ip);
|
|
25242
25372
|
try {
|
|
25243
|
-
(0,
|
|
25373
|
+
(0, import_node_child_process7.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
25244
25374
|
} catch {
|
|
25245
25375
|
}
|
|
25246
25376
|
}
|
|
25247
25377
|
async isBlocked(ip) {
|
|
25248
25378
|
assertValidFirewallIp(ip);
|
|
25249
25379
|
try {
|
|
25250
|
-
const output = (0,
|
|
25380
|
+
const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
25251
25381
|
return output.includes(ip);
|
|
25252
25382
|
} catch {
|
|
25253
25383
|
return false;
|
|
@@ -25255,7 +25385,7 @@ var NftablesAdapter = class {
|
|
|
25255
25385
|
}
|
|
25256
25386
|
async listBlocked() {
|
|
25257
25387
|
try {
|
|
25258
|
-
const output = (0,
|
|
25388
|
+
const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
25259
25389
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
25260
25390
|
if (!match) return [];
|
|
25261
25391
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -25268,34 +25398,34 @@ var IptablesAdapter = class {
|
|
|
25268
25398
|
name = "iptables";
|
|
25269
25399
|
chain = "THREATCRUSH";
|
|
25270
25400
|
isAvailable() {
|
|
25271
|
-
const result = (0,
|
|
25401
|
+
const result = (0, import_node_child_process7.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
25272
25402
|
return result.status === 0;
|
|
25273
25403
|
}
|
|
25274
25404
|
ensureChain() {
|
|
25275
25405
|
try {
|
|
25276
|
-
(0,
|
|
25406
|
+
(0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
25277
25407
|
} catch {
|
|
25278
|
-
(0,
|
|
25279
|
-
(0,
|
|
25408
|
+
(0, import_node_child_process7.execSync)(`iptables -N ${this.chain}`);
|
|
25409
|
+
(0, import_node_child_process7.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
25280
25410
|
}
|
|
25281
25411
|
}
|
|
25282
25412
|
async block(ip) {
|
|
25283
25413
|
assertValidFirewallIp(ip);
|
|
25284
25414
|
this.ensureChain();
|
|
25285
25415
|
if (await this.isBlocked(ip)) return;
|
|
25286
|
-
(0,
|
|
25416
|
+
(0, import_node_child_process7.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
25287
25417
|
}
|
|
25288
25418
|
async unblock(ip) {
|
|
25289
25419
|
assertValidFirewallIp(ip);
|
|
25290
25420
|
try {
|
|
25291
|
-
(0,
|
|
25421
|
+
(0, import_node_child_process7.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
25292
25422
|
} catch {
|
|
25293
25423
|
}
|
|
25294
25424
|
}
|
|
25295
25425
|
async isBlocked(ip) {
|
|
25296
25426
|
assertValidFirewallIp(ip);
|
|
25297
25427
|
try {
|
|
25298
|
-
const output = (0,
|
|
25428
|
+
const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
25299
25429
|
return output.includes(ip);
|
|
25300
25430
|
} catch {
|
|
25301
25431
|
return false;
|
|
@@ -25303,7 +25433,7 @@ var IptablesAdapter = class {
|
|
|
25303
25433
|
}
|
|
25304
25434
|
async listBlocked() {
|
|
25305
25435
|
try {
|
|
25306
|
-
const output = (0,
|
|
25436
|
+
const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
25307
25437
|
const ips = [];
|
|
25308
25438
|
for (const line of output.split("\n")) {
|
|
25309
25439
|
const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -25365,7 +25495,7 @@ init_paths();
|
|
|
25365
25495
|
init_backoff();
|
|
25366
25496
|
|
|
25367
25497
|
// src/daemon/firewall/protected.ts
|
|
25368
|
-
var
|
|
25498
|
+
var import_node_child_process8 = require("child_process");
|
|
25369
25499
|
var import_node_net4 = require("net");
|
|
25370
25500
|
var DEFAULT_PROTECTED = [
|
|
25371
25501
|
"127.0.0.0/8",
|
|
@@ -25461,7 +25591,7 @@ function currentSshClient(env2 = process.env) {
|
|
|
25461
25591
|
function establishedSshPeers() {
|
|
25462
25592
|
const peers = /* @__PURE__ */ new Set();
|
|
25463
25593
|
try {
|
|
25464
|
-
const out = (0,
|
|
25594
|
+
const out = (0, import_node_child_process8.execFileSync)("ss", ["-tnpH"], {
|
|
25465
25595
|
encoding: "utf-8",
|
|
25466
25596
|
stdio: ["ignore", "pipe", "ignore"],
|
|
25467
25597
|
timeout: 3e3
|
|
@@ -25482,7 +25612,7 @@ function defaultGateways() {
|
|
|
25482
25612
|
const found = /* @__PURE__ */ new Set();
|
|
25483
25613
|
for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
|
|
25484
25614
|
try {
|
|
25485
|
-
const out = (0,
|
|
25615
|
+
const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
25486
25616
|
for (const line of out.split("\n")) {
|
|
25487
25617
|
const match = line.match(/\bvia\s+(\S+)/);
|
|
25488
25618
|
if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
|
|
@@ -26087,7 +26217,7 @@ async function daemonStart() {
|
|
|
26087
26217
|
}
|
|
26088
26218
|
return;
|
|
26089
26219
|
}
|
|
26090
|
-
const child = (0,
|
|
26220
|
+
const child = (0, import_node_child_process9.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
26091
26221
|
detached: true,
|
|
26092
26222
|
stdio: ["ignore", out, err],
|
|
26093
26223
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -26172,7 +26302,7 @@ async function releaseStaleSocket() {
|
|
|
26172
26302
|
}
|
|
26173
26303
|
|
|
26174
26304
|
// src/commands/service.ts
|
|
26175
|
-
var
|
|
26305
|
+
var import_node_child_process10 = require("child_process");
|
|
26176
26306
|
var import_node_fs30 = require("fs");
|
|
26177
26307
|
var import_node_path21 = require("path");
|
|
26178
26308
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
@@ -26193,7 +26323,7 @@ function resolveBinPath() {
|
|
|
26193
26323
|
const arg = process.argv[1];
|
|
26194
26324
|
if (arg && (0, import_node_fs30.existsSync)(arg)) return stableBinPath(arg);
|
|
26195
26325
|
try {
|
|
26196
|
-
return (0,
|
|
26326
|
+
return (0, import_node_child_process10.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
26197
26327
|
} catch {
|
|
26198
26328
|
return "threatcrush";
|
|
26199
26329
|
}
|
|
@@ -26218,18 +26348,18 @@ function isRoot3() {
|
|
|
26218
26348
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
26219
26349
|
}
|
|
26220
26350
|
function reexecWithSudo(args) {
|
|
26221
|
-
if ((0,
|
|
26351
|
+
if ((0, import_node_child_process10.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
26222
26352
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
26223
26353
|
const bin = resolveBinPath();
|
|
26224
26354
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
26225
|
-
const result = (0,
|
|
26355
|
+
const result = (0, import_node_child_process10.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
26226
26356
|
return result.status === 0;
|
|
26227
26357
|
}
|
|
26228
26358
|
function callerHome() {
|
|
26229
26359
|
const user = process.env.SUDO_USER;
|
|
26230
26360
|
if (!user) return null;
|
|
26231
26361
|
try {
|
|
26232
|
-
const line = (0,
|
|
26362
|
+
const line = (0, import_node_child_process10.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
26233
26363
|
const home = line.split(":")[5];
|
|
26234
26364
|
return home && (0, import_node_fs30.existsSync)(home) ? home : null;
|
|
26235
26365
|
} catch {
|
|
@@ -26264,7 +26394,7 @@ function stopUserModeDaemon() {
|
|
|
26264
26394
|
}
|
|
26265
26395
|
}
|
|
26266
26396
|
function unitIsActive() {
|
|
26267
|
-
const result = (0,
|
|
26397
|
+
const result = (0, import_node_child_process10.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
26268
26398
|
return result.status === 0;
|
|
26269
26399
|
}
|
|
26270
26400
|
async function installServiceCommand() {
|
|
@@ -26292,8 +26422,8 @@ async function installServiceCommand() {
|
|
|
26292
26422
|
ensureSystemDirs();
|
|
26293
26423
|
stopUserModeDaemon();
|
|
26294
26424
|
try {
|
|
26295
|
-
(0,
|
|
26296
|
-
(0,
|
|
26425
|
+
(0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
26426
|
+
(0, import_node_child_process10.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
26297
26427
|
} catch (err) {
|
|
26298
26428
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
26299
26429
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -26333,7 +26463,7 @@ function ensureSystemDirs() {
|
|
|
26333
26463
|
try {
|
|
26334
26464
|
if (groupWritable && admGid !== null) {
|
|
26335
26465
|
(0, import_node_fs30.chmodSync)(path, sticky ? 1533 : 509);
|
|
26336
|
-
(0,
|
|
26466
|
+
(0, import_node_child_process10.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
26337
26467
|
} else {
|
|
26338
26468
|
(0, import_node_fs30.chmodSync)(path, 493);
|
|
26339
26469
|
}
|
|
@@ -26355,22 +26485,22 @@ async function uninstallServiceCommand() {
|
|
|
26355
26485
|
return;
|
|
26356
26486
|
}
|
|
26357
26487
|
try {
|
|
26358
|
-
(0,
|
|
26488
|
+
(0, import_node_child_process10.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
26359
26489
|
} catch {
|
|
26360
26490
|
}
|
|
26361
26491
|
try {
|
|
26362
|
-
(0,
|
|
26492
|
+
(0, import_node_child_process10.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
26363
26493
|
} catch {
|
|
26364
26494
|
}
|
|
26365
26495
|
try {
|
|
26366
26496
|
if ((0, import_node_fs30.existsSync)(UNIT_PATH)) {
|
|
26367
|
-
(0,
|
|
26497
|
+
(0, import_node_child_process10.execSync)(`rm -f ${UNIT_PATH}`);
|
|
26368
26498
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
26369
26499
|
}
|
|
26370
26500
|
} catch {
|
|
26371
26501
|
}
|
|
26372
26502
|
try {
|
|
26373
|
-
(0,
|
|
26503
|
+
(0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
26374
26504
|
} catch {
|
|
26375
26505
|
}
|
|
26376
26506
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
@@ -26983,10 +27113,10 @@ async function rulesCommand(opts) {
|
|
|
26983
27113
|
|
|
26984
27114
|
// src/commands/harden.ts
|
|
26985
27115
|
var import_node_fs32 = require("fs");
|
|
26986
|
-
var
|
|
27116
|
+
var import_node_child_process11 = require("child_process");
|
|
26987
27117
|
function tryExec(cmd) {
|
|
26988
27118
|
try {
|
|
26989
|
-
return (0,
|
|
27119
|
+
return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
26990
27120
|
} catch {
|
|
26991
27121
|
return null;
|
|
26992
27122
|
}
|
|
@@ -27518,11 +27648,11 @@ async function allowlistCommand(opts) {
|
|
|
27518
27648
|
init_paths();
|
|
27519
27649
|
|
|
27520
27650
|
// src/upgrade.ts
|
|
27521
|
-
var
|
|
27651
|
+
var import_node_child_process12 = require("child_process");
|
|
27522
27652
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
27523
27653
|
var defaultRunner = (cmd) => {
|
|
27524
27654
|
try {
|
|
27525
|
-
return (0,
|
|
27655
|
+
return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
27526
27656
|
} catch {
|
|
27527
27657
|
return null;
|
|
27528
27658
|
}
|
|
@@ -27640,22 +27770,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
|
27640
27770
|
var INSTALL_CONFIG_PATH = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
|
|
27641
27771
|
function detectPackageManager() {
|
|
27642
27772
|
try {
|
|
27643
|
-
const npmGlobal = (0,
|
|
27773
|
+
const npmGlobal = (0, import_node_child_process13.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
27644
27774
|
if (npmGlobal.includes(PKG_NAME)) return "npm";
|
|
27645
27775
|
} catch {
|
|
27646
27776
|
}
|
|
27647
27777
|
try {
|
|
27648
|
-
(0,
|
|
27778
|
+
(0, import_node_child_process13.execSync)("pnpm --version", { stdio: "pipe" });
|
|
27649
27779
|
return "pnpm";
|
|
27650
27780
|
} catch {
|
|
27651
27781
|
}
|
|
27652
27782
|
try {
|
|
27653
|
-
(0,
|
|
27783
|
+
(0, import_node_child_process13.execSync)("yarn --version", { stdio: "pipe" });
|
|
27654
27784
|
return "yarn";
|
|
27655
27785
|
} catch {
|
|
27656
27786
|
}
|
|
27657
27787
|
try {
|
|
27658
|
-
(0,
|
|
27788
|
+
(0, import_node_child_process13.execSync)("bun --version", { stdio: "pipe" });
|
|
27659
27789
|
return "bun";
|
|
27660
27790
|
} catch {
|
|
27661
27791
|
}
|
|
@@ -27670,7 +27800,7 @@ function readInstallConfig() {
|
|
|
27670
27800
|
}
|
|
27671
27801
|
function packageLooksInstalled(pm, pkgName) {
|
|
27672
27802
|
try {
|
|
27673
|
-
const output = (0,
|
|
27803
|
+
const output = (0, import_node_child_process13.execSync)(globalListCommand(pm, pkgName), {
|
|
27674
27804
|
encoding: "utf-8",
|
|
27675
27805
|
stdio: ["pipe", "pipe", "pipe"]
|
|
27676
27806
|
});
|
|
@@ -27773,14 +27903,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
27773
27903
|
function restartSystemdDaemon() {
|
|
27774
27904
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
27775
27905
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
27776
|
-
if (!asRoot && (0,
|
|
27906
|
+
if (!asRoot && (0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
27777
27907
|
const [cmd, ...args] = argv;
|
|
27778
|
-
if ((0,
|
|
27779
|
-
return (0,
|
|
27908
|
+
if ((0, import_node_child_process13.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
27909
|
+
return (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
27780
27910
|
}
|
|
27781
27911
|
function execQuiet(cmd) {
|
|
27782
27912
|
try {
|
|
27783
|
-
return (0,
|
|
27913
|
+
return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
27784
27914
|
} catch {
|
|
27785
27915
|
return null;
|
|
27786
27916
|
}
|
|
@@ -27936,7 +28066,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
27936
28066
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
27937
28067
|
`));
|
|
27938
28068
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
27939
|
-
(0,
|
|
28069
|
+
(0, import_node_child_process13.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
27940
28070
|
});
|
|
27941
28071
|
program2.command("activate").description("Activate your license key").action(async () => {
|
|
27942
28072
|
console.log(LOGO2);
|
|
@@ -27983,7 +28113,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
27983
28113
|
for (const cmd of commands2) {
|
|
27984
28114
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
27985
28115
|
`));
|
|
27986
|
-
(0,
|
|
28116
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
27987
28117
|
}
|
|
27988
28118
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
27989
28119
|
await reportIfStillStale();
|
|
@@ -28008,7 +28138,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
28008
28138
|
for (const cmd of commands) {
|
|
28009
28139
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
28010
28140
|
`));
|
|
28011
|
-
(0,
|
|
28141
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
28012
28142
|
}
|
|
28013
28143
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
28014
28144
|
if (installMode === "desktop") {
|
|
@@ -28059,7 +28189,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
28059
28189
|
for (const cmd of commands) {
|
|
28060
28190
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
28061
28191
|
`));
|
|
28062
|
-
(0,
|
|
28192
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
28063
28193
|
}
|
|
28064
28194
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
28065
28195
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|