@profullstack/threatcrush 0.12.8 → 0.13.0
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 +200 -75
- 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;
|
|
@@ -11048,14 +11072,17 @@ function tiles(ui, state, theme) {
|
|
|
11048
11072
|
});
|
|
11049
11073
|
});
|
|
11050
11074
|
}
|
|
11051
|
-
function modulesPanel(parent, state, theme) {
|
|
11075
|
+
function modulesPanel(parent, state, theme, options) {
|
|
11076
|
+
const focused = state.focus === "modules";
|
|
11052
11077
|
parent.panel(
|
|
11053
11078
|
{
|
|
11054
11079
|
title: " MODULES ",
|
|
11055
11080
|
size: "fill",
|
|
11056
11081
|
border: "rounded",
|
|
11057
|
-
borderColor: theme.border,
|
|
11082
|
+
borderColor: focused ? theme.borderFocused : theme.border,
|
|
11058
11083
|
titleColor: theme.primary,
|
|
11084
|
+
subtitle: focused ? "enter filters feed" : void 0,
|
|
11085
|
+
subtitleColor: theme.muted,
|
|
11059
11086
|
footer: state.modules.length > 0 ? `${state.modules.filter((m) => m.status === "running").length}/${state.modules.length} active` : void 0,
|
|
11060
11087
|
padding: [0, 1]
|
|
11061
11088
|
},
|
|
@@ -11067,7 +11094,17 @@ function modulesPanel(parent, state, theme) {
|
|
|
11067
11094
|
panel.table({
|
|
11068
11095
|
rows: state.modules,
|
|
11069
11096
|
header: false,
|
|
11097
|
+
selected: focused ? state.moduleIndex : -1,
|
|
11098
|
+
followSelection: true,
|
|
11099
|
+
onSelectRow: options.onModuleSelect,
|
|
11070
11100
|
columns: [
|
|
11101
|
+
{
|
|
11102
|
+
// Marks the module the feed is currently pinned to.
|
|
11103
|
+
key: "name",
|
|
11104
|
+
width: 2,
|
|
11105
|
+
render: (m) => state.moduleFilter === m.name ? "\u25B6" : " ",
|
|
11106
|
+
color: () => theme.primary
|
|
11107
|
+
},
|
|
11071
11108
|
{
|
|
11072
11109
|
key: "status",
|
|
11073
11110
|
width: 2,
|
|
@@ -11107,18 +11144,27 @@ function severityPanel(parent, state, theme) {
|
|
|
11107
11144
|
}
|
|
11108
11145
|
function feedPanel(parent, state, theme, options) {
|
|
11109
11146
|
const following = state.scrollBack === 0;
|
|
11147
|
+
const shown = visibleEvents(state);
|
|
11148
|
+
const filtered = state.moduleFilter !== null;
|
|
11110
11149
|
parent.panel(
|
|
11111
11150
|
{
|
|
11112
|
-
title: " LIVE EVENTS ",
|
|
11151
|
+
title: filtered ? ` LIVE EVENTS \xB7 ${state.moduleFilter} ` : " LIVE EVENTS ",
|
|
11113
11152
|
size: "2.4fr",
|
|
11114
11153
|
border: "rounded",
|
|
11115
11154
|
borderColor: state.connection === "live" ? theme.borderFocused : theme.border,
|
|
11116
11155
|
titleColor: theme.primary,
|
|
11117
|
-
subtitle: following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
|
|
11118
|
-
subtitleColor: severityColors.medium,
|
|
11156
|
+
subtitle: filtered ? `${shown.length}/${state.events.length} \xB7 esc clears filter` : following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
|
|
11157
|
+
subtitleColor: filtered ? theme.primary : severityColors.medium,
|
|
11119
11158
|
padding: [0, 1]
|
|
11120
11159
|
},
|
|
11121
11160
|
(panel) => {
|
|
11161
|
+
if (filtered && shown.length === 0 && state.events.length > 0) {
|
|
11162
|
+
panel.spacer(1);
|
|
11163
|
+
panel.text(`No events from ${state.moduleFilter} yet.`, { fg: theme.muted, align: "center" });
|
|
11164
|
+
panel.spacer(1);
|
|
11165
|
+
panel.label("esc shows everything again", { fg: theme.muted, align: "center" });
|
|
11166
|
+
return;
|
|
11167
|
+
}
|
|
11122
11168
|
if (state.events.length === 0) {
|
|
11123
11169
|
panel.spacer(1);
|
|
11124
11170
|
if (state.connection === "live") {
|
|
@@ -11139,7 +11185,7 @@ function feedPanel(parent, state, theme, options) {
|
|
|
11139
11185
|
return;
|
|
11140
11186
|
}
|
|
11141
11187
|
panel.log({
|
|
11142
|
-
entries:
|
|
11188
|
+
entries: shown.map(toLogEntry),
|
|
11143
11189
|
follow: following,
|
|
11144
11190
|
fromEnd: state.scrollBack,
|
|
11145
11191
|
scrollbar: true,
|
|
@@ -11320,8 +11366,7 @@ function footer(ui, state, theme) {
|
|
|
11320
11366
|
{ key: "q", label: "quit" },
|
|
11321
11367
|
{ key: "tab", label: state.focus },
|
|
11322
11368
|
{ key: "\u2191\u2193", label: onFeed ? "scroll" : "select" },
|
|
11323
|
-
{ key: "b", label: "ban" },
|
|
11324
|
-
{ key: "u", label: "unban" },
|
|
11369
|
+
...state.focus === "modules" ? [{ key: "\u23CE", label: state.moduleFilter ? "unfilter" : "filter" }] : [{ key: "b", label: "ban" }, { key: "u", label: "unban" }],
|
|
11325
11370
|
{ key: "p", label: state.paused ? "resume" : "pause" },
|
|
11326
11371
|
{ key: "r", label: "reset" }
|
|
11327
11372
|
],
|
|
@@ -11333,6 +11378,7 @@ function footer(ui, state, theme) {
|
|
|
11333
11378
|
label: state.paused && state.parked.length > 0 ? `${state.parked.length} held` : "",
|
|
11334
11379
|
color: severityColors.medium
|
|
11335
11380
|
},
|
|
11381
|
+
{ label: state.moduleFilter ? `filter: ${state.moduleFilter}` : "", color: theme.primary },
|
|
11336
11382
|
{
|
|
11337
11383
|
label: state.firewall ? `${state.bans.length} banned${state.firewall.dry_run ? " (dry-run)" : ""}` : "",
|
|
11338
11384
|
color: state.firewall?.dry_run ? severityColors.medium : theme.muted
|
|
@@ -11349,7 +11395,7 @@ function renderDashboard(ui, state, theme, options = {}) {
|
|
|
11349
11395
|
tiles(col, state, theme);
|
|
11350
11396
|
col.row({ size: "fill", gap: 0 }, (row) => {
|
|
11351
11397
|
row.column({ size: "1fr" }, (left) => {
|
|
11352
|
-
modulesPanel(left, state, theme);
|
|
11398
|
+
modulesPanel(left, state, theme, options);
|
|
11353
11399
|
severityPanel(left, state, theme);
|
|
11354
11400
|
});
|
|
11355
11401
|
feedPanel(row, state, theme, options);
|
|
@@ -11566,11 +11612,18 @@ async function startDashboard(options = {}) {
|
|
|
11566
11612
|
};
|
|
11567
11613
|
app.on("key", (event) => {
|
|
11568
11614
|
switch (event.key) {
|
|
11569
|
-
case "q":
|
|
11570
11615
|
case "escape":
|
|
11616
|
+
if (state.moduleFilter) dispatch({ type: "clear_module_filter" });
|
|
11617
|
+
else quit();
|
|
11618
|
+
break;
|
|
11619
|
+
case "q":
|
|
11571
11620
|
case "ctrl+c":
|
|
11572
11621
|
quit();
|
|
11573
11622
|
break;
|
|
11623
|
+
case "enter":
|
|
11624
|
+
case "return":
|
|
11625
|
+
dispatch({ type: "toggle_module_filter" });
|
|
11626
|
+
break;
|
|
11574
11627
|
case "p":
|
|
11575
11628
|
case "space":
|
|
11576
11629
|
dispatch({ type: "pause" });
|
|
@@ -11624,6 +11677,13 @@ async function startDashboard(options = {}) {
|
|
|
11624
11677
|
onBanSelect: (row) => {
|
|
11625
11678
|
dispatch({ type: "focus", focus: "bans" });
|
|
11626
11679
|
dispatch({ type: "select_at", index: row });
|
|
11680
|
+
},
|
|
11681
|
+
// One click on a module both selects it and pins the feed to it; a
|
|
11682
|
+
// second click on the same module releases the feed.
|
|
11683
|
+
onModuleSelect: (row) => {
|
|
11684
|
+
dispatch({ type: "focus", focus: "modules" });
|
|
11685
|
+
dispatch({ type: "select_at", index: row });
|
|
11686
|
+
dispatch({ type: "toggle_module_filter" });
|
|
11627
11687
|
}
|
|
11628
11688
|
});
|
|
11629
11689
|
});
|
|
@@ -15804,7 +15864,7 @@ var source_default = chalk;
|
|
|
15804
15864
|
|
|
15805
15865
|
// src/index.ts
|
|
15806
15866
|
var import_readline = __toESM(require("readline"));
|
|
15807
|
-
var
|
|
15867
|
+
var import_node_child_process13 = require("child_process");
|
|
15808
15868
|
var import_node_fs33 = require("fs");
|
|
15809
15869
|
var import_node_path23 = require("path");
|
|
15810
15870
|
var import_node_os8 = require("os");
|
|
@@ -23105,7 +23165,7 @@ async function sshConnect(options) {
|
|
|
23105
23165
|
}
|
|
23106
23166
|
|
|
23107
23167
|
// src/commands/daemon.ts
|
|
23108
|
-
var
|
|
23168
|
+
var import_node_child_process9 = require("child_process");
|
|
23109
23169
|
var import_node_fs28 = require("fs");
|
|
23110
23170
|
var import_node_path20 = require("path");
|
|
23111
23171
|
var import_node_fs29 = require("fs");
|
|
@@ -23851,6 +23911,7 @@ var NetworkMonitor = class {
|
|
|
23851
23911
|
|
|
23852
23912
|
// src/modules/dns-monitor/index.ts
|
|
23853
23913
|
var import_node_fs22 = require("fs");
|
|
23914
|
+
var import_node_child_process6 = require("child_process");
|
|
23854
23915
|
var import_node_readline5 = require("readline");
|
|
23855
23916
|
var DNS_LOG_SOURCES = [
|
|
23856
23917
|
"/var/log/syslog",
|
|
@@ -23862,10 +23923,30 @@ var DNS_LOG_SOURCES = [
|
|
|
23862
23923
|
"/var/log/pihole.log"
|
|
23863
23924
|
// Pi-hole
|
|
23864
23925
|
];
|
|
23926
|
+
function qtypeName(qtype) {
|
|
23927
|
+
const names = {
|
|
23928
|
+
1: "A",
|
|
23929
|
+
2: "NS",
|
|
23930
|
+
5: "CNAME",
|
|
23931
|
+
6: "SOA",
|
|
23932
|
+
12: "PTR",
|
|
23933
|
+
15: "MX",
|
|
23934
|
+
16: "TXT",
|
|
23935
|
+
28: "AAAA",
|
|
23936
|
+
33: "SRV",
|
|
23937
|
+
35: "NAPTR",
|
|
23938
|
+
43: "DS",
|
|
23939
|
+
48: "DNSKEY",
|
|
23940
|
+
65: "HTTPS",
|
|
23941
|
+
255: "ANY"
|
|
23942
|
+
};
|
|
23943
|
+
return names[qtype] ?? `TYPE${qtype}`;
|
|
23944
|
+
}
|
|
23865
23945
|
var DnsMonitor = class {
|
|
23866
|
-
|
|
23867
|
-
constructor(bus2) {
|
|
23946
|
+
constructor(bus2, options = {}) {
|
|
23868
23947
|
this.bus = bus2;
|
|
23948
|
+
this.extraPaths = options.log_paths ?? [];
|
|
23949
|
+
this.journalUnits = options.journal_units ?? [];
|
|
23869
23950
|
}
|
|
23870
23951
|
bus;
|
|
23871
23952
|
active = false;
|
|
@@ -23882,8 +23963,13 @@ var DnsMonitor = class {
|
|
|
23882
23963
|
// unique high-entropy domains per window
|
|
23883
23964
|
dgaWindowMs = 6e4;
|
|
23884
23965
|
entropyThreshold = 3.5;
|
|
23966
|
+
// Shannon entropy threshold for DGA
|
|
23967
|
+
/** Extra files and journal units from `[modules.dns-monitor]` in the config. */
|
|
23968
|
+
extraPaths = [];
|
|
23969
|
+
journalUnits = [];
|
|
23970
|
+
journalTails = [];
|
|
23885
23971
|
start() {
|
|
23886
|
-
const sources = DNS_LOG_SOURCES.filter((p) => {
|
|
23972
|
+
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
23887
23973
|
if (!(0, import_node_fs22.existsSync)(p)) return false;
|
|
23888
23974
|
try {
|
|
23889
23975
|
(0, import_node_fs22.accessSync)(p, import_node_fs22.constants.R_OK);
|
|
@@ -23892,7 +23978,8 @@ var DnsMonitor = class {
|
|
|
23892
23978
|
return false;
|
|
23893
23979
|
}
|
|
23894
23980
|
});
|
|
23895
|
-
|
|
23981
|
+
for (const unit of this.journalUnits) this.tailJournalUnit(unit);
|
|
23982
|
+
if (sources.length === 0 && this.journalTails.length === 0) return false;
|
|
23896
23983
|
this.active = true;
|
|
23897
23984
|
for (const src of sources) {
|
|
23898
23985
|
this.tailLog(src);
|
|
@@ -23903,8 +23990,30 @@ var DnsMonitor = class {
|
|
|
23903
23990
|
stop() {
|
|
23904
23991
|
for (const t of this.timers.values()) clearInterval(t);
|
|
23905
23992
|
this.timers.clear();
|
|
23993
|
+
for (const child of this.journalTails) {
|
|
23994
|
+
try {
|
|
23995
|
+
child.kill("SIGTERM");
|
|
23996
|
+
} catch {
|
|
23997
|
+
}
|
|
23998
|
+
}
|
|
23999
|
+
this.journalTails = [];
|
|
23906
24000
|
this.active = false;
|
|
23907
24001
|
}
|
|
24002
|
+
/** Follow one systemd unit's journal, feeding its lines to the same parser. */
|
|
24003
|
+
tailJournalUnit(unit) {
|
|
24004
|
+
try {
|
|
24005
|
+
const child = (0, import_node_child_process6.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
|
|
24006
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
24007
|
+
});
|
|
24008
|
+
if (!child.stdout) return;
|
|
24009
|
+
const rl = (0, import_node_readline5.createInterface)({ input: child.stdout });
|
|
24010
|
+
rl.on("line", (line) => this.parseDnsLine(line));
|
|
24011
|
+
child.on("error", () => {
|
|
24012
|
+
});
|
|
24013
|
+
this.journalTails.push(child);
|
|
24014
|
+
} catch {
|
|
24015
|
+
}
|
|
24016
|
+
}
|
|
23908
24017
|
isActive() {
|
|
23909
24018
|
return this.active;
|
|
23910
24019
|
}
|
|
@@ -23937,6 +24046,18 @@ var DnsMonitor = class {
|
|
|
23937
24046
|
rl.on("close", () => this.positions.set(path, stat.size));
|
|
23938
24047
|
}
|
|
23939
24048
|
parseDnsLine(line) {
|
|
24049
|
+
const moshpit = line.match(
|
|
24050
|
+
/\[dns\]\s+(?:udp|tcp|doh)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w+)/i
|
|
24051
|
+
);
|
|
24052
|
+
if (moshpit) {
|
|
24053
|
+
this.domainBuffer.push({
|
|
24054
|
+
type: qtypeName(Number.parseInt(moshpit[3], 10)),
|
|
24055
|
+
domain: moshpit[2],
|
|
24056
|
+
source_ip: moshpit[1],
|
|
24057
|
+
timestamp: Date.now()
|
|
24058
|
+
});
|
|
24059
|
+
return;
|
|
24060
|
+
}
|
|
23940
24061
|
const resolvedMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
|
|
23941
24062
|
if (resolvedMatch) {
|
|
23942
24063
|
this.domainBuffer.push({
|
|
@@ -24112,7 +24233,11 @@ var ModuleHost = class {
|
|
|
24112
24233
|
this.bus.announceModule("network-monitor", "running", nmod.detail);
|
|
24113
24234
|
}
|
|
24114
24235
|
}
|
|
24115
|
-
|
|
24236
|
+
const dnsConfig = loadModuleConfigs(PATHS.confD).get("dns-monitor") ?? {};
|
|
24237
|
+
this.dnsMonitor = new DnsMonitor(this.bus, {
|
|
24238
|
+
log_paths: Array.isArray(dnsConfig.log_paths) ? dnsConfig.log_paths : void 0,
|
|
24239
|
+
journal_units: Array.isArray(dnsConfig.journal_units) ? dnsConfig.journal_units : void 0
|
|
24240
|
+
});
|
|
24116
24241
|
if (this.dnsMonitor.start()) {
|
|
24117
24242
|
const dmod = this.modules.get("dns-monitor");
|
|
24118
24243
|
if (dmod) {
|
|
@@ -25087,7 +25212,7 @@ function loadAllRules(customDir) {
|
|
|
25087
25212
|
}
|
|
25088
25213
|
|
|
25089
25214
|
// src/daemon/firewall/adapters.ts
|
|
25090
|
-
var
|
|
25215
|
+
var import_node_child_process7 = require("child_process");
|
|
25091
25216
|
var import_node_fs25 = require("fs");
|
|
25092
25217
|
var import_node_path18 = require("path");
|
|
25093
25218
|
var import_node_net3 = require("net");
|
|
@@ -25123,11 +25248,11 @@ var Fail2banAdapter = class {
|
|
|
25123
25248
|
enforces = true;
|
|
25124
25249
|
jailReady = false;
|
|
25125
25250
|
isAvailable() {
|
|
25126
|
-
const result = (0,
|
|
25251
|
+
const result = (0, import_node_child_process7.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
25127
25252
|
return result.status === 0;
|
|
25128
25253
|
}
|
|
25129
25254
|
client(args) {
|
|
25130
|
-
return (0,
|
|
25255
|
+
return (0, import_node_child_process7.execFileSync)("fail2ban-client", args, {
|
|
25131
25256
|
encoding: "utf-8",
|
|
25132
25257
|
stdio: ["ignore", "pipe", "pipe"]
|
|
25133
25258
|
});
|
|
@@ -25219,35 +25344,35 @@ var NftablesAdapter = class {
|
|
|
25219
25344
|
table = "threatcrush";
|
|
25220
25345
|
set = "blocklist";
|
|
25221
25346
|
isAvailable() {
|
|
25222
|
-
const result = (0,
|
|
25347
|
+
const result = (0, import_node_child_process7.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
25223
25348
|
return result.status === 0;
|
|
25224
25349
|
}
|
|
25225
25350
|
ensureSetup() {
|
|
25226
25351
|
try {
|
|
25227
|
-
(0,
|
|
25352
|
+
(0, import_node_child_process7.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
25228
25353
|
} catch {
|
|
25229
|
-
(0,
|
|
25230
|
-
(0,
|
|
25231
|
-
(0,
|
|
25232
|
-
(0,
|
|
25354
|
+
(0, import_node_child_process7.execSync)(`nft add table inet ${this.table}`);
|
|
25355
|
+
(0, import_node_child_process7.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
25356
|
+
(0, import_node_child_process7.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
25357
|
+
(0, import_node_child_process7.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
25233
25358
|
}
|
|
25234
25359
|
}
|
|
25235
25360
|
async block(ip) {
|
|
25236
25361
|
assertValidFirewallIp(ip);
|
|
25237
25362
|
this.ensureSetup();
|
|
25238
|
-
(0,
|
|
25363
|
+
(0, import_node_child_process7.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
25239
25364
|
}
|
|
25240
25365
|
async unblock(ip) {
|
|
25241
25366
|
assertValidFirewallIp(ip);
|
|
25242
25367
|
try {
|
|
25243
|
-
(0,
|
|
25368
|
+
(0, import_node_child_process7.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
25244
25369
|
} catch {
|
|
25245
25370
|
}
|
|
25246
25371
|
}
|
|
25247
25372
|
async isBlocked(ip) {
|
|
25248
25373
|
assertValidFirewallIp(ip);
|
|
25249
25374
|
try {
|
|
25250
|
-
const output = (0,
|
|
25375
|
+
const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
25251
25376
|
return output.includes(ip);
|
|
25252
25377
|
} catch {
|
|
25253
25378
|
return false;
|
|
@@ -25255,7 +25380,7 @@ var NftablesAdapter = class {
|
|
|
25255
25380
|
}
|
|
25256
25381
|
async listBlocked() {
|
|
25257
25382
|
try {
|
|
25258
|
-
const output = (0,
|
|
25383
|
+
const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
25259
25384
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
25260
25385
|
if (!match) return [];
|
|
25261
25386
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -25268,34 +25393,34 @@ var IptablesAdapter = class {
|
|
|
25268
25393
|
name = "iptables";
|
|
25269
25394
|
chain = "THREATCRUSH";
|
|
25270
25395
|
isAvailable() {
|
|
25271
|
-
const result = (0,
|
|
25396
|
+
const result = (0, import_node_child_process7.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
25272
25397
|
return result.status === 0;
|
|
25273
25398
|
}
|
|
25274
25399
|
ensureChain() {
|
|
25275
25400
|
try {
|
|
25276
|
-
(0,
|
|
25401
|
+
(0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
25277
25402
|
} catch {
|
|
25278
|
-
(0,
|
|
25279
|
-
(0,
|
|
25403
|
+
(0, import_node_child_process7.execSync)(`iptables -N ${this.chain}`);
|
|
25404
|
+
(0, import_node_child_process7.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
25280
25405
|
}
|
|
25281
25406
|
}
|
|
25282
25407
|
async block(ip) {
|
|
25283
25408
|
assertValidFirewallIp(ip);
|
|
25284
25409
|
this.ensureChain();
|
|
25285
25410
|
if (await this.isBlocked(ip)) return;
|
|
25286
|
-
(0,
|
|
25411
|
+
(0, import_node_child_process7.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
25287
25412
|
}
|
|
25288
25413
|
async unblock(ip) {
|
|
25289
25414
|
assertValidFirewallIp(ip);
|
|
25290
25415
|
try {
|
|
25291
|
-
(0,
|
|
25416
|
+
(0, import_node_child_process7.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
25292
25417
|
} catch {
|
|
25293
25418
|
}
|
|
25294
25419
|
}
|
|
25295
25420
|
async isBlocked(ip) {
|
|
25296
25421
|
assertValidFirewallIp(ip);
|
|
25297
25422
|
try {
|
|
25298
|
-
const output = (0,
|
|
25423
|
+
const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
25299
25424
|
return output.includes(ip);
|
|
25300
25425
|
} catch {
|
|
25301
25426
|
return false;
|
|
@@ -25303,7 +25428,7 @@ var IptablesAdapter = class {
|
|
|
25303
25428
|
}
|
|
25304
25429
|
async listBlocked() {
|
|
25305
25430
|
try {
|
|
25306
|
-
const output = (0,
|
|
25431
|
+
const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
25307
25432
|
const ips = [];
|
|
25308
25433
|
for (const line of output.split("\n")) {
|
|
25309
25434
|
const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -25365,7 +25490,7 @@ init_paths();
|
|
|
25365
25490
|
init_backoff();
|
|
25366
25491
|
|
|
25367
25492
|
// src/daemon/firewall/protected.ts
|
|
25368
|
-
var
|
|
25493
|
+
var import_node_child_process8 = require("child_process");
|
|
25369
25494
|
var import_node_net4 = require("net");
|
|
25370
25495
|
var DEFAULT_PROTECTED = [
|
|
25371
25496
|
"127.0.0.0/8",
|
|
@@ -25461,7 +25586,7 @@ function currentSshClient(env2 = process.env) {
|
|
|
25461
25586
|
function establishedSshPeers() {
|
|
25462
25587
|
const peers = /* @__PURE__ */ new Set();
|
|
25463
25588
|
try {
|
|
25464
|
-
const out = (0,
|
|
25589
|
+
const out = (0, import_node_child_process8.execFileSync)("ss", ["-tnpH"], {
|
|
25465
25590
|
encoding: "utf-8",
|
|
25466
25591
|
stdio: ["ignore", "pipe", "ignore"],
|
|
25467
25592
|
timeout: 3e3
|
|
@@ -25482,7 +25607,7 @@ function defaultGateways() {
|
|
|
25482
25607
|
const found = /* @__PURE__ */ new Set();
|
|
25483
25608
|
for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
|
|
25484
25609
|
try {
|
|
25485
|
-
const out = (0,
|
|
25610
|
+
const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
25486
25611
|
for (const line of out.split("\n")) {
|
|
25487
25612
|
const match = line.match(/\bvia\s+(\S+)/);
|
|
25488
25613
|
if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
|
|
@@ -26087,7 +26212,7 @@ async function daemonStart() {
|
|
|
26087
26212
|
}
|
|
26088
26213
|
return;
|
|
26089
26214
|
}
|
|
26090
|
-
const child = (0,
|
|
26215
|
+
const child = (0, import_node_child_process9.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
26091
26216
|
detached: true,
|
|
26092
26217
|
stdio: ["ignore", out, err],
|
|
26093
26218
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -26172,7 +26297,7 @@ async function releaseStaleSocket() {
|
|
|
26172
26297
|
}
|
|
26173
26298
|
|
|
26174
26299
|
// src/commands/service.ts
|
|
26175
|
-
var
|
|
26300
|
+
var import_node_child_process10 = require("child_process");
|
|
26176
26301
|
var import_node_fs30 = require("fs");
|
|
26177
26302
|
var import_node_path21 = require("path");
|
|
26178
26303
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
@@ -26193,7 +26318,7 @@ function resolveBinPath() {
|
|
|
26193
26318
|
const arg = process.argv[1];
|
|
26194
26319
|
if (arg && (0, import_node_fs30.existsSync)(arg)) return stableBinPath(arg);
|
|
26195
26320
|
try {
|
|
26196
|
-
return (0,
|
|
26321
|
+
return (0, import_node_child_process10.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
26197
26322
|
} catch {
|
|
26198
26323
|
return "threatcrush";
|
|
26199
26324
|
}
|
|
@@ -26218,18 +26343,18 @@ function isRoot3() {
|
|
|
26218
26343
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
26219
26344
|
}
|
|
26220
26345
|
function reexecWithSudo(args) {
|
|
26221
|
-
if ((0,
|
|
26346
|
+
if ((0, import_node_child_process10.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
26222
26347
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
26223
26348
|
const bin = resolveBinPath();
|
|
26224
26349
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
26225
|
-
const result = (0,
|
|
26350
|
+
const result = (0, import_node_child_process10.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
26226
26351
|
return result.status === 0;
|
|
26227
26352
|
}
|
|
26228
26353
|
function callerHome() {
|
|
26229
26354
|
const user = process.env.SUDO_USER;
|
|
26230
26355
|
if (!user) return null;
|
|
26231
26356
|
try {
|
|
26232
|
-
const line = (0,
|
|
26357
|
+
const line = (0, import_node_child_process10.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
26233
26358
|
const home = line.split(":")[5];
|
|
26234
26359
|
return home && (0, import_node_fs30.existsSync)(home) ? home : null;
|
|
26235
26360
|
} catch {
|
|
@@ -26264,7 +26389,7 @@ function stopUserModeDaemon() {
|
|
|
26264
26389
|
}
|
|
26265
26390
|
}
|
|
26266
26391
|
function unitIsActive() {
|
|
26267
|
-
const result = (0,
|
|
26392
|
+
const result = (0, import_node_child_process10.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
26268
26393
|
return result.status === 0;
|
|
26269
26394
|
}
|
|
26270
26395
|
async function installServiceCommand() {
|
|
@@ -26292,8 +26417,8 @@ async function installServiceCommand() {
|
|
|
26292
26417
|
ensureSystemDirs();
|
|
26293
26418
|
stopUserModeDaemon();
|
|
26294
26419
|
try {
|
|
26295
|
-
(0,
|
|
26296
|
-
(0,
|
|
26420
|
+
(0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
26421
|
+
(0, import_node_child_process10.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
26297
26422
|
} catch (err) {
|
|
26298
26423
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
26299
26424
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -26333,7 +26458,7 @@ function ensureSystemDirs() {
|
|
|
26333
26458
|
try {
|
|
26334
26459
|
if (groupWritable && admGid !== null) {
|
|
26335
26460
|
(0, import_node_fs30.chmodSync)(path, sticky ? 1533 : 509);
|
|
26336
|
-
(0,
|
|
26461
|
+
(0, import_node_child_process10.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
26337
26462
|
} else {
|
|
26338
26463
|
(0, import_node_fs30.chmodSync)(path, 493);
|
|
26339
26464
|
}
|
|
@@ -26355,22 +26480,22 @@ async function uninstallServiceCommand() {
|
|
|
26355
26480
|
return;
|
|
26356
26481
|
}
|
|
26357
26482
|
try {
|
|
26358
|
-
(0,
|
|
26483
|
+
(0, import_node_child_process10.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
26359
26484
|
} catch {
|
|
26360
26485
|
}
|
|
26361
26486
|
try {
|
|
26362
|
-
(0,
|
|
26487
|
+
(0, import_node_child_process10.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
26363
26488
|
} catch {
|
|
26364
26489
|
}
|
|
26365
26490
|
try {
|
|
26366
26491
|
if ((0, import_node_fs30.existsSync)(UNIT_PATH)) {
|
|
26367
|
-
(0,
|
|
26492
|
+
(0, import_node_child_process10.execSync)(`rm -f ${UNIT_PATH}`);
|
|
26368
26493
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
26369
26494
|
}
|
|
26370
26495
|
} catch {
|
|
26371
26496
|
}
|
|
26372
26497
|
try {
|
|
26373
|
-
(0,
|
|
26498
|
+
(0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
26374
26499
|
} catch {
|
|
26375
26500
|
}
|
|
26376
26501
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
@@ -26983,10 +27108,10 @@ async function rulesCommand(opts) {
|
|
|
26983
27108
|
|
|
26984
27109
|
// src/commands/harden.ts
|
|
26985
27110
|
var import_node_fs32 = require("fs");
|
|
26986
|
-
var
|
|
27111
|
+
var import_node_child_process11 = require("child_process");
|
|
26987
27112
|
function tryExec(cmd) {
|
|
26988
27113
|
try {
|
|
26989
|
-
return (0,
|
|
27114
|
+
return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
26990
27115
|
} catch {
|
|
26991
27116
|
return null;
|
|
26992
27117
|
}
|
|
@@ -27518,11 +27643,11 @@ async function allowlistCommand(opts) {
|
|
|
27518
27643
|
init_paths();
|
|
27519
27644
|
|
|
27520
27645
|
// src/upgrade.ts
|
|
27521
|
-
var
|
|
27646
|
+
var import_node_child_process12 = require("child_process");
|
|
27522
27647
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
27523
27648
|
var defaultRunner = (cmd) => {
|
|
27524
27649
|
try {
|
|
27525
|
-
return (0,
|
|
27650
|
+
return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
27526
27651
|
} catch {
|
|
27527
27652
|
return null;
|
|
27528
27653
|
}
|
|
@@ -27640,22 +27765,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
|
27640
27765
|
var INSTALL_CONFIG_PATH = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
|
|
27641
27766
|
function detectPackageManager() {
|
|
27642
27767
|
try {
|
|
27643
|
-
const npmGlobal = (0,
|
|
27768
|
+
const npmGlobal = (0, import_node_child_process13.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
27644
27769
|
if (npmGlobal.includes(PKG_NAME)) return "npm";
|
|
27645
27770
|
} catch {
|
|
27646
27771
|
}
|
|
27647
27772
|
try {
|
|
27648
|
-
(0,
|
|
27773
|
+
(0, import_node_child_process13.execSync)("pnpm --version", { stdio: "pipe" });
|
|
27649
27774
|
return "pnpm";
|
|
27650
27775
|
} catch {
|
|
27651
27776
|
}
|
|
27652
27777
|
try {
|
|
27653
|
-
(0,
|
|
27778
|
+
(0, import_node_child_process13.execSync)("yarn --version", { stdio: "pipe" });
|
|
27654
27779
|
return "yarn";
|
|
27655
27780
|
} catch {
|
|
27656
27781
|
}
|
|
27657
27782
|
try {
|
|
27658
|
-
(0,
|
|
27783
|
+
(0, import_node_child_process13.execSync)("bun --version", { stdio: "pipe" });
|
|
27659
27784
|
return "bun";
|
|
27660
27785
|
} catch {
|
|
27661
27786
|
}
|
|
@@ -27670,7 +27795,7 @@ function readInstallConfig() {
|
|
|
27670
27795
|
}
|
|
27671
27796
|
function packageLooksInstalled(pm, pkgName) {
|
|
27672
27797
|
try {
|
|
27673
|
-
const output = (0,
|
|
27798
|
+
const output = (0, import_node_child_process13.execSync)(globalListCommand(pm, pkgName), {
|
|
27674
27799
|
encoding: "utf-8",
|
|
27675
27800
|
stdio: ["pipe", "pipe", "pipe"]
|
|
27676
27801
|
});
|
|
@@ -27773,14 +27898,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
27773
27898
|
function restartSystemdDaemon() {
|
|
27774
27899
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
27775
27900
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
27776
|
-
if (!asRoot && (0,
|
|
27901
|
+
if (!asRoot && (0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
27777
27902
|
const [cmd, ...args] = argv;
|
|
27778
|
-
if ((0,
|
|
27779
|
-
return (0,
|
|
27903
|
+
if ((0, import_node_child_process13.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
27904
|
+
return (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
27780
27905
|
}
|
|
27781
27906
|
function execQuiet(cmd) {
|
|
27782
27907
|
try {
|
|
27783
|
-
return (0,
|
|
27908
|
+
return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
27784
27909
|
} catch {
|
|
27785
27910
|
return null;
|
|
27786
27911
|
}
|
|
@@ -27936,7 +28061,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
27936
28061
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
27937
28062
|
`));
|
|
27938
28063
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
27939
|
-
(0,
|
|
28064
|
+
(0, import_node_child_process13.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
27940
28065
|
});
|
|
27941
28066
|
program2.command("activate").description("Activate your license key").action(async () => {
|
|
27942
28067
|
console.log(LOGO2);
|
|
@@ -27983,7 +28108,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
27983
28108
|
for (const cmd of commands2) {
|
|
27984
28109
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
27985
28110
|
`));
|
|
27986
|
-
(0,
|
|
28111
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
27987
28112
|
}
|
|
27988
28113
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
27989
28114
|
await reportIfStillStale();
|
|
@@ -28008,7 +28133,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
28008
28133
|
for (const cmd of commands) {
|
|
28009
28134
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
28010
28135
|
`));
|
|
28011
|
-
(0,
|
|
28136
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
28012
28137
|
}
|
|
28013
28138
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
28014
28139
|
if (installMode === "desktop") {
|
|
@@ -28059,7 +28184,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
28059
28184
|
for (const cmd of commands) {
|
|
28060
28185
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
28061
28186
|
`));
|
|
28062
|
-
(0,
|
|
28187
|
+
(0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
|
|
28063
28188
|
}
|
|
28064
28189
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
28065
28190
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|