@profullstack/threatcrush 0.11.11 → 0.12.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 +627 -88
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +1124 -222
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10594,6 +10594,24 @@ var init_ipc_client = __esm({
|
|
|
10594
10594
|
async subscribe(channels) {
|
|
10595
10595
|
await this.request("subscribe", { channels });
|
|
10596
10596
|
}
|
|
10597
|
+
async blocklist() {
|
|
10598
|
+
return this.request("blocklist");
|
|
10599
|
+
}
|
|
10600
|
+
/**
|
|
10601
|
+
* Ban an address. The control token is read from disk here rather than by
|
|
10602
|
+
* the caller, so the dashboard and the CLI go through the same gate.
|
|
10603
|
+
*/
|
|
10604
|
+
async block(ip, reason, ttl) {
|
|
10605
|
+
return this.request("block", {
|
|
10606
|
+
ip,
|
|
10607
|
+
reason,
|
|
10608
|
+
ttl,
|
|
10609
|
+
token: readControlToken()
|
|
10610
|
+
});
|
|
10611
|
+
}
|
|
10612
|
+
async unblock(ip, forget = true) {
|
|
10613
|
+
return this.request("unblock", { ip, forget, token: readControlToken() });
|
|
10614
|
+
}
|
|
10597
10615
|
async shutdown() {
|
|
10598
10616
|
await this.request("shutdown", { token: readControlToken() });
|
|
10599
10617
|
}
|
|
@@ -10651,9 +10669,25 @@ function initialState(now = Date.now()) {
|
|
|
10651
10669
|
paused: false,
|
|
10652
10670
|
parked: [],
|
|
10653
10671
|
scrollBack: 0,
|
|
10654
|
-
startedAt: now
|
|
10672
|
+
startedAt: now,
|
|
10673
|
+
bans: [],
|
|
10674
|
+
protectedList: [],
|
|
10675
|
+
firewall: null,
|
|
10676
|
+
focus: "feed",
|
|
10677
|
+
threatIndex: 0,
|
|
10678
|
+
banIndex: 0,
|
|
10679
|
+
notice: null,
|
|
10680
|
+
busy: false
|
|
10655
10681
|
};
|
|
10656
10682
|
}
|
|
10683
|
+
function isBanned(state, ip) {
|
|
10684
|
+
return state.bans.some((b) => b.ip === ip);
|
|
10685
|
+
}
|
|
10686
|
+
function selectedIp(state) {
|
|
10687
|
+
if (state.focus === "threats") return state.topSources[state.threatIndex]?.ip ?? null;
|
|
10688
|
+
if (state.focus === "bans") return state.bans[state.banIndex]?.ip ?? null;
|
|
10689
|
+
return null;
|
|
10690
|
+
}
|
|
10657
10691
|
function accept(state, event) {
|
|
10658
10692
|
const events = [...state.events, event].slice(-FEED_LIMIT);
|
|
10659
10693
|
return {
|
|
@@ -10696,7 +10730,8 @@ function reducer(state, action) {
|
|
|
10696
10730
|
}
|
|
10697
10731
|
case "tick": {
|
|
10698
10732
|
const timeline = [...state.timeline.slice(1), state.pending];
|
|
10699
|
-
|
|
10733
|
+
const notice = state.notice && state.notice.until <= Date.now() ? null : state.notice;
|
|
10734
|
+
return { ...state, timeline, pending: 0, notice };
|
|
10700
10735
|
}
|
|
10701
10736
|
case "modules":
|
|
10702
10737
|
return {
|
|
@@ -10704,8 +10739,65 @@ function reducer(state, action) {
|
|
|
10704
10739
|
modules: action.modules,
|
|
10705
10740
|
counters: { ...state.counters, modules: action.modules.length }
|
|
10706
10741
|
};
|
|
10707
|
-
case "top":
|
|
10708
|
-
|
|
10742
|
+
case "top": {
|
|
10743
|
+
const previous = state.topSources[state.threatIndex]?.ip;
|
|
10744
|
+
const moved = previous ? action.top.findIndex((s) => s.ip === previous) : -1;
|
|
10745
|
+
const threatIndex = moved >= 0 ? moved : Math.min(state.threatIndex, Math.max(0, action.top.length - 1));
|
|
10746
|
+
return { ...state, topSources: action.top, threatIndex };
|
|
10747
|
+
}
|
|
10748
|
+
case "blocklist": {
|
|
10749
|
+
const previous = state.bans[state.banIndex]?.ip;
|
|
10750
|
+
const moved = previous ? action.reply.entries.findIndex((b) => b.ip === previous) : -1;
|
|
10751
|
+
const banIndex = moved >= 0 ? moved : Math.min(state.banIndex, Math.max(0, action.reply.entries.length - 1));
|
|
10752
|
+
return {
|
|
10753
|
+
...state,
|
|
10754
|
+
bans: action.reply.entries,
|
|
10755
|
+
protectedList: action.reply.protected,
|
|
10756
|
+
firewall: {
|
|
10757
|
+
enabled: action.reply.enabled,
|
|
10758
|
+
dry_run: action.reply.dry_run,
|
|
10759
|
+
backend: action.reply.backend,
|
|
10760
|
+
min_severity: action.reply.min_severity
|
|
10761
|
+
},
|
|
10762
|
+
banIndex
|
|
10763
|
+
};
|
|
10764
|
+
}
|
|
10765
|
+
case "focus":
|
|
10766
|
+
return { ...state, focus: action.focus };
|
|
10767
|
+
case "focus_next": {
|
|
10768
|
+
const next = FOCUS_ORDER[(FOCUS_ORDER.indexOf(state.focus) + 1) % FOCUS_ORDER.length];
|
|
10769
|
+
return { ...state, focus: next };
|
|
10770
|
+
}
|
|
10771
|
+
case "select": {
|
|
10772
|
+
if (state.focus === "threats") {
|
|
10773
|
+
const max = Math.max(0, state.topSources.length - 1);
|
|
10774
|
+
return { ...state, threatIndex: Math.min(max, Math.max(0, state.threatIndex + action.delta)) };
|
|
10775
|
+
}
|
|
10776
|
+
if (state.focus === "bans") {
|
|
10777
|
+
const max = Math.max(0, state.bans.length - 1);
|
|
10778
|
+
return { ...state, banIndex: Math.min(max, Math.max(0, state.banIndex + action.delta)) };
|
|
10779
|
+
}
|
|
10780
|
+
return state;
|
|
10781
|
+
}
|
|
10782
|
+
case "select_at": {
|
|
10783
|
+
if (state.focus === "bans") {
|
|
10784
|
+
const max2 = Math.max(0, state.bans.length - 1);
|
|
10785
|
+
return { ...state, banIndex: Math.min(max2, Math.max(0, action.index)) };
|
|
10786
|
+
}
|
|
10787
|
+
const max = Math.max(0, state.topSources.length - 1);
|
|
10788
|
+
return { ...state, threatIndex: Math.min(max, Math.max(0, action.index)) };
|
|
10789
|
+
}
|
|
10790
|
+
case "notice":
|
|
10791
|
+
return {
|
|
10792
|
+
...state,
|
|
10793
|
+
notice: {
|
|
10794
|
+
text: action.text,
|
|
10795
|
+
tone: action.tone,
|
|
10796
|
+
until: (action.now ?? Date.now()) + NOTICE_MS
|
|
10797
|
+
}
|
|
10798
|
+
};
|
|
10799
|
+
case "busy":
|
|
10800
|
+
return { ...state, busy: action.busy };
|
|
10709
10801
|
case "counters":
|
|
10710
10802
|
return {
|
|
10711
10803
|
...state,
|
|
@@ -10730,7 +10822,14 @@ function reducer(state, action) {
|
|
|
10730
10822
|
connectionLabel: state.connectionLabel,
|
|
10731
10823
|
daemon: state.daemon,
|
|
10732
10824
|
modules: state.modules,
|
|
10733
|
-
counters: { ...state.counters, events: 0, threats: 0 }
|
|
10825
|
+
counters: { ...state.counters, events: 0, threats: 0 },
|
|
10826
|
+
// Reset clears the *view*, never the firewall. Bans are the daemon's
|
|
10827
|
+
// state, and wiping them from the screen would make the dashboard
|
|
10828
|
+
// disagree with the host it is describing.
|
|
10829
|
+
bans: state.bans,
|
|
10830
|
+
protectedList: state.protectedList,
|
|
10831
|
+
firewall: state.firewall,
|
|
10832
|
+
focus: state.focus
|
|
10734
10833
|
};
|
|
10735
10834
|
}
|
|
10736
10835
|
}
|
|
@@ -10759,16 +10858,73 @@ function formatCount(n) {
|
|
|
10759
10858
|
if (n < 1e6) return `${(n / 1e3).toFixed(n < 1e4 ? 1 : 0)}k`;
|
|
10760
10859
|
return `${(n / 1e6).toFixed(1)}M`;
|
|
10761
10860
|
}
|
|
10762
|
-
var TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
|
|
10861
|
+
var FOCUS_ORDER, NOTICE_MS, TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
|
|
10763
10862
|
var init_state = __esm({
|
|
10764
10863
|
"src/tui/state.ts"() {
|
|
10765
10864
|
"use strict";
|
|
10865
|
+
FOCUS_ORDER = ["feed", "threats", "bans"];
|
|
10866
|
+
NOTICE_MS = 6e3;
|
|
10766
10867
|
TIMELINE_SLOTS = 60;
|
|
10767
10868
|
FEED_LIMIT = 500;
|
|
10768
10869
|
SEVERITIES = ["info", "low", "medium", "high", "critical"];
|
|
10769
10870
|
}
|
|
10770
10871
|
});
|
|
10771
10872
|
|
|
10873
|
+
// src/daemon/firewall/backoff.ts
|
|
10874
|
+
function fibonacciMinutes(strike) {
|
|
10875
|
+
const n = Math.max(1, Math.floor(strike));
|
|
10876
|
+
let prev = 1;
|
|
10877
|
+
let curr = 1;
|
|
10878
|
+
for (let i = 1; i < n; i++) {
|
|
10879
|
+
const next = prev + curr;
|
|
10880
|
+
prev = curr;
|
|
10881
|
+
curr = next;
|
|
10882
|
+
}
|
|
10883
|
+
return curr;
|
|
10884
|
+
}
|
|
10885
|
+
function banSeconds(strike, maxSeconds) {
|
|
10886
|
+
const seconds = fibonacciMinutes(strike) * 60;
|
|
10887
|
+
return Math.min(seconds, Math.max(60, maxSeconds));
|
|
10888
|
+
}
|
|
10889
|
+
function recordStrike(strikes, ip, now, memorySeconds) {
|
|
10890
|
+
const existing = strikes[ip];
|
|
10891
|
+
const expired = !existing || now - existing.last > memorySeconds * 1e3;
|
|
10892
|
+
const count = expired ? 1 : existing.count + 1;
|
|
10893
|
+
strikes[ip] = { count, last: now };
|
|
10894
|
+
return count;
|
|
10895
|
+
}
|
|
10896
|
+
function pruneStrikes(strikes, now, memorySeconds) {
|
|
10897
|
+
const kept = {};
|
|
10898
|
+
for (const [ip, strike] of Object.entries(strikes)) {
|
|
10899
|
+
if (now - strike.last <= memorySeconds * 1e3) kept[ip] = strike;
|
|
10900
|
+
}
|
|
10901
|
+
return kept;
|
|
10902
|
+
}
|
|
10903
|
+
function parseDuration(value) {
|
|
10904
|
+
if (typeof value === "number") return Number.isFinite(value) && value > 0 ? value : null;
|
|
10905
|
+
if (!value) return null;
|
|
10906
|
+
const match = String(value).trim().match(/^(\d+)\s*(s|m|h|d)?$/i);
|
|
10907
|
+
if (!match) return null;
|
|
10908
|
+
const units = { s: 1, m: 60, h: 3600, d: 86400 };
|
|
10909
|
+
return Number(match[1]) * (units[(match[2] || "s").toLowerCase()] ?? 1);
|
|
10910
|
+
}
|
|
10911
|
+
function formatDuration(seconds) {
|
|
10912
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return "0s";
|
|
10913
|
+
const d = Math.floor(seconds / 86400);
|
|
10914
|
+
const h = Math.floor(seconds % 86400 / 3600);
|
|
10915
|
+
const m = Math.floor(seconds % 3600 / 60);
|
|
10916
|
+
const s = Math.floor(seconds % 60);
|
|
10917
|
+
if (d > 0) return h > 0 ? `${d}d ${h}h` : `${d}d`;
|
|
10918
|
+
if (h > 0) return m > 0 ? `${h}h ${m}m` : `${h}h`;
|
|
10919
|
+
if (m > 0) return s > 0 && m < 10 ? `${m}m ${s}s` : `${m}m`;
|
|
10920
|
+
return `${s}s`;
|
|
10921
|
+
}
|
|
10922
|
+
var init_backoff = __esm({
|
|
10923
|
+
"src/daemon/firewall/backoff.ts"() {
|
|
10924
|
+
"use strict";
|
|
10925
|
+
}
|
|
10926
|
+
});
|
|
10927
|
+
|
|
10772
10928
|
// src/tui/theme.ts
|
|
10773
10929
|
var threatcrushTheme, severityColors, levelColors;
|
|
10774
10930
|
var init_theme2 = __esm({
|
|
@@ -10996,9 +11152,19 @@ function feedPanel(parent, state, theme, options) {
|
|
|
10996
11152
|
}
|
|
10997
11153
|
);
|
|
10998
11154
|
}
|
|
10999
|
-
function threatsPanel(parent, state, theme) {
|
|
11155
|
+
function threatsPanel(parent, state, theme, options) {
|
|
11156
|
+
const focused = state.focus === "threats";
|
|
11000
11157
|
parent.panel(
|
|
11001
|
-
{
|
|
11158
|
+
{
|
|
11159
|
+
title: " TOP THREATS ",
|
|
11160
|
+
size: "fill",
|
|
11161
|
+
border: "rounded",
|
|
11162
|
+
borderColor: focused ? theme.borderFocused : theme.border,
|
|
11163
|
+
titleColor: theme.primary,
|
|
11164
|
+
subtitle: focused ? "b ban \xB7 u unban" : void 0,
|
|
11165
|
+
subtitleColor: theme.muted,
|
|
11166
|
+
padding: [0, 1]
|
|
11167
|
+
},
|
|
11002
11168
|
(panel) => {
|
|
11003
11169
|
if (state.topSources.length === 0) {
|
|
11004
11170
|
if (state.daemon?.stateDb === false) {
|
|
@@ -11014,7 +11180,19 @@ function threatsPanel(parent, state, theme) {
|
|
|
11014
11180
|
panel.table({
|
|
11015
11181
|
rows: state.topSources,
|
|
11016
11182
|
header: false,
|
|
11183
|
+
selected: focused ? state.threatIndex : -1,
|
|
11184
|
+
followSelection: true,
|
|
11185
|
+
scrollbar: true,
|
|
11186
|
+
onSelectRow: options.onThreatSelect,
|
|
11017
11187
|
columns: [
|
|
11188
|
+
{
|
|
11189
|
+
// A source is either banned, protected, or neither — and which one
|
|
11190
|
+
// it is decides what the b key will do to it.
|
|
11191
|
+
key: "ip",
|
|
11192
|
+
width: 2,
|
|
11193
|
+
render: (s) => isBanned(state, s.ip) ? "\u2716" : isProtectedRow(state, s.ip) ? "\u26CA" : " ",
|
|
11194
|
+
color: (s) => isBanned(state, s.ip) ? severityColors.critical : isProtectedRow(state, s.ip) ? theme.success : theme.muted
|
|
11195
|
+
},
|
|
11018
11196
|
{ key: "ip", width: "fill", color: () => theme.foreground },
|
|
11019
11197
|
{
|
|
11020
11198
|
key: "count",
|
|
@@ -11029,6 +11207,91 @@ function threatsPanel(parent, state, theme) {
|
|
|
11029
11207
|
}
|
|
11030
11208
|
);
|
|
11031
11209
|
}
|
|
11210
|
+
function isProtectedRow(state, ip) {
|
|
11211
|
+
return state.protectedList.some((entry) => entry === ip || ipInCidrLabel(ip, entry));
|
|
11212
|
+
}
|
|
11213
|
+
function ipInCidrLabel(ip, entry) {
|
|
11214
|
+
const slash = entry.indexOf("/");
|
|
11215
|
+
if (slash < 0) return false;
|
|
11216
|
+
const network = entry.slice(0, slash);
|
|
11217
|
+
const prefix = Number(entry.slice(slash + 1));
|
|
11218
|
+
if (!Number.isFinite(prefix)) return false;
|
|
11219
|
+
if (network.includes(":") !== ip.includes(":")) return false;
|
|
11220
|
+
if (ip.includes(":")) return ip.toLowerCase().startsWith(network.toLowerCase().replace(/:+$/, ""));
|
|
11221
|
+
const octets = Math.floor(prefix / 8);
|
|
11222
|
+
if (octets === 0) return false;
|
|
11223
|
+
return ip.split(".").slice(0, octets).join(".") === network.split(".").slice(0, octets).join(".");
|
|
11224
|
+
}
|
|
11225
|
+
function bansPanel(parent, state, theme, options) {
|
|
11226
|
+
const focused = state.focus === "bans";
|
|
11227
|
+
const fw = state.firewall;
|
|
11228
|
+
const footer2 = fw ? `${fw.backend}${fw.dry_run ? " \xB7 DRY-RUN" : ""} \xB7 \u2265${fw.min_severity}` : void 0;
|
|
11229
|
+
parent.panel(
|
|
11230
|
+
{
|
|
11231
|
+
title: " BANNED ",
|
|
11232
|
+
size: "fill",
|
|
11233
|
+
border: "rounded",
|
|
11234
|
+
borderColor: focused ? theme.borderFocused : theme.border,
|
|
11235
|
+
titleColor: theme.primary,
|
|
11236
|
+
subtitle: focused ? "u unban" : void 0,
|
|
11237
|
+
subtitleColor: theme.muted,
|
|
11238
|
+
footer: footer2,
|
|
11239
|
+
padding: [0, 1]
|
|
11240
|
+
},
|
|
11241
|
+
(panel) => {
|
|
11242
|
+
if (!fw) {
|
|
11243
|
+
panel.label("firewall state unknown", { fg: theme.muted });
|
|
11244
|
+
return;
|
|
11245
|
+
}
|
|
11246
|
+
if (!fw.enabled) {
|
|
11247
|
+
panel.text("auto-defence OFF", { fg: severityColors.high, bold: true });
|
|
11248
|
+
panel.label("[remediation] enabled = false", { fg: theme.muted });
|
|
11249
|
+
return;
|
|
11250
|
+
}
|
|
11251
|
+
if (state.bans.length === 0) {
|
|
11252
|
+
panel.label("nothing banned", { fg: theme.muted });
|
|
11253
|
+
panel.label(fw.dry_run ? "dry-run: bans are simulated" : "bans: 1m \u2192 2m \u2192 3m \u2192 5m \u2192 8m", {
|
|
11254
|
+
fg: fw.dry_run ? severityColors.medium : theme.muted
|
|
11255
|
+
});
|
|
11256
|
+
return;
|
|
11257
|
+
}
|
|
11258
|
+
const now = Date.now();
|
|
11259
|
+
panel.table({
|
|
11260
|
+
rows: state.bans,
|
|
11261
|
+
header: false,
|
|
11262
|
+
selected: focused ? state.banIndex : -1,
|
|
11263
|
+
followSelection: true,
|
|
11264
|
+
scrollbar: true,
|
|
11265
|
+
onSelectRow: options.onBanSelect,
|
|
11266
|
+
columns: [
|
|
11267
|
+
{
|
|
11268
|
+
key: "ip",
|
|
11269
|
+
width: 2,
|
|
11270
|
+
// A manual ban reads differently from one the daemon decided on.
|
|
11271
|
+
render: (b) => b.source === "manual" ? "\u2298" : "\u2716",
|
|
11272
|
+
color: (b) => b.dry_run ? theme.muted : severityColors.critical
|
|
11273
|
+
},
|
|
11274
|
+
{ key: "ip", width: "fill", color: () => theme.foreground },
|
|
11275
|
+
{
|
|
11276
|
+
key: "strikes",
|
|
11277
|
+
width: 3,
|
|
11278
|
+
align: "right",
|
|
11279
|
+
// Which rung of the ladder produced this ban's length.
|
|
11280
|
+
render: (b) => `#${b.strikes}`,
|
|
11281
|
+
color: (b) => b.strikes > 1 ? severityColors.high : theme.muted
|
|
11282
|
+
},
|
|
11283
|
+
{
|
|
11284
|
+
key: "expires_at",
|
|
11285
|
+
width: 7,
|
|
11286
|
+
align: "right",
|
|
11287
|
+
render: (b) => formatDuration(Math.round((b.expires_at - now) / 1e3)),
|
|
11288
|
+
color: () => severityColors.medium
|
|
11289
|
+
}
|
|
11290
|
+
]
|
|
11291
|
+
});
|
|
11292
|
+
}
|
|
11293
|
+
);
|
|
11294
|
+
}
|
|
11032
11295
|
function throughputPanel(parent, state, theme) {
|
|
11033
11296
|
parent.panel(
|
|
11034
11297
|
{ title: " THROUGHPUT ", size: 9, border: "rounded", borderColor: theme.border, titleColor: theme.primary, padding: [0, 1] },
|
|
@@ -11045,20 +11308,30 @@ function throughputPanel(parent, state, theme) {
|
|
|
11045
11308
|
);
|
|
11046
11309
|
}
|
|
11047
11310
|
function footer(ui, state, theme) {
|
|
11311
|
+
const onFeed = state.focus === "feed";
|
|
11048
11312
|
ui.statusBar({
|
|
11049
11313
|
size: 1,
|
|
11050
11314
|
items: [
|
|
11051
11315
|
{ key: "q", label: "quit" },
|
|
11316
|
+
{ key: "tab", label: state.focus },
|
|
11317
|
+
{ key: "\u2191\u2193", label: onFeed ? "scroll" : "select" },
|
|
11318
|
+
{ key: "b", label: "ban" },
|
|
11319
|
+
{ key: "u", label: "unban" },
|
|
11052
11320
|
{ key: "p", label: state.paused ? "resume" : "pause" },
|
|
11053
|
-
{ key: "r", label: "reset" }
|
|
11054
|
-
{ key: "\u2191\u2193", label: "scroll" },
|
|
11055
|
-
{ key: "end", label: "follow" }
|
|
11321
|
+
{ key: "r", label: "reset" }
|
|
11056
11322
|
],
|
|
11057
11323
|
right: [
|
|
11324
|
+
// The notice is the answer to "did my keypress do anything", so it takes
|
|
11325
|
+
// the slot for as long as it lives.
|
|
11326
|
+
{ label: state.notice?.text ?? "", color: state.notice?.tone === "error" ? severityColors.high : theme.success },
|
|
11058
11327
|
{
|
|
11059
11328
|
label: state.paused && state.parked.length > 0 ? `${state.parked.length} held` : "",
|
|
11060
11329
|
color: severityColors.medium
|
|
11061
11330
|
},
|
|
11331
|
+
{
|
|
11332
|
+
label: state.firewall ? `${state.bans.length} banned${state.firewall.dry_run ? " (dry-run)" : ""}` : "",
|
|
11333
|
+
color: state.firewall?.dry_run ? severityColors.medium : theme.muted
|
|
11334
|
+
},
|
|
11062
11335
|
{ label: state.daemon ? `v${state.daemon.version} \xB7 ${state.daemon.mode}` : "no daemon", color: theme.muted }
|
|
11063
11336
|
].filter((item) => item.label !== ""),
|
|
11064
11337
|
background: theme.surface
|
|
@@ -11076,7 +11349,8 @@ function renderDashboard(ui, state, theme, options = {}) {
|
|
|
11076
11349
|
});
|
|
11077
11350
|
feedPanel(row, state, theme, options);
|
|
11078
11351
|
row.column({ size: "1fr" }, (right) => {
|
|
11079
|
-
threatsPanel(right, state, theme);
|
|
11352
|
+
threatsPanel(right, state, theme, options);
|
|
11353
|
+
bansPanel(right, state, theme, options);
|
|
11080
11354
|
throughputPanel(right, state, theme);
|
|
11081
11355
|
});
|
|
11082
11356
|
});
|
|
@@ -11088,6 +11362,7 @@ var init_view = __esm({
|
|
|
11088
11362
|
"use strict";
|
|
11089
11363
|
init_theme2();
|
|
11090
11364
|
init_state();
|
|
11365
|
+
init_backoff();
|
|
11091
11366
|
}
|
|
11092
11367
|
});
|
|
11093
11368
|
|
|
@@ -11138,6 +11413,8 @@ async function startDashboard(options = {}) {
|
|
|
11138
11413
|
let client = null;
|
|
11139
11414
|
let stopped = false;
|
|
11140
11415
|
const timers = [];
|
|
11416
|
+
let refreshBans = async () => {
|
|
11417
|
+
};
|
|
11141
11418
|
const every = (ms, fn) => {
|
|
11142
11419
|
const t = setInterval(fn, ms);
|
|
11143
11420
|
t.unref?.();
|
|
@@ -11160,6 +11437,15 @@ async function startDashboard(options = {}) {
|
|
|
11160
11437
|
} else {
|
|
11161
11438
|
const onEvent = (event) => {
|
|
11162
11439
|
if (!stopped) dispatch({ type: "event", event });
|
|
11440
|
+
if (!stopped && event.module === "firewall-rules") void refreshBans();
|
|
11441
|
+
};
|
|
11442
|
+
refreshBans = async () => {
|
|
11443
|
+
if (!client || stopped) return;
|
|
11444
|
+
try {
|
|
11445
|
+
const reply = await client.blocklist();
|
|
11446
|
+
dispatch({ type: "blocklist", reply });
|
|
11447
|
+
} catch {
|
|
11448
|
+
}
|
|
11163
11449
|
};
|
|
11164
11450
|
const poll = async () => {
|
|
11165
11451
|
if (!client || stopped) return;
|
|
@@ -11168,6 +11454,7 @@ async function startDashboard(options = {}) {
|
|
|
11168
11454
|
dispatch({ type: "connected", label: `daemon pid ${status.pid}`, status });
|
|
11169
11455
|
const top = await client.topSources(8).catch(() => []);
|
|
11170
11456
|
dispatch({ type: "top", top });
|
|
11457
|
+
await refreshBans();
|
|
11171
11458
|
} catch {
|
|
11172
11459
|
try {
|
|
11173
11460
|
client?.close();
|
|
@@ -11177,7 +11464,7 @@ async function startDashboard(options = {}) {
|
|
|
11177
11464
|
dispatch({ type: "connection_lost", label: "daemon went away \u2014 retrying" });
|
|
11178
11465
|
}
|
|
11179
11466
|
};
|
|
11180
|
-
const
|
|
11467
|
+
const connect2 = async () => {
|
|
11181
11468
|
if (client || stopped) return;
|
|
11182
11469
|
if (!IpcClient.isDaemonRunning()) {
|
|
11183
11470
|
if (state.connection !== "lost") {
|
|
@@ -11210,9 +11497,9 @@ async function startDashboard(options = {}) {
|
|
|
11210
11497
|
dispatch({ type: "connection_lost", label: `daemon unreachable: ${err.message}` });
|
|
11211
11498
|
}
|
|
11212
11499
|
};
|
|
11213
|
-
void
|
|
11500
|
+
void connect2();
|
|
11214
11501
|
every(RECONNECT_MS, () => {
|
|
11215
|
-
if (!client) void
|
|
11502
|
+
if (!client) void connect2();
|
|
11216
11503
|
});
|
|
11217
11504
|
every(POLL_MS, () => {
|
|
11218
11505
|
void poll();
|
|
@@ -11223,6 +11510,55 @@ async function startDashboard(options = {}) {
|
|
|
11223
11510
|
teardown();
|
|
11224
11511
|
app.stop();
|
|
11225
11512
|
};
|
|
11513
|
+
const banSelected = async () => {
|
|
11514
|
+
const ip = selectedIp(state);
|
|
11515
|
+
if (state.busy) return;
|
|
11516
|
+
if (!ip) {
|
|
11517
|
+
dispatch({ type: "notice", text: "select a source first (tab)", tone: "error" });
|
|
11518
|
+
return;
|
|
11519
|
+
}
|
|
11520
|
+
if (!client) {
|
|
11521
|
+
dispatch({ type: "notice", text: "no daemon \u2014 cannot ban", tone: "error" });
|
|
11522
|
+
return;
|
|
11523
|
+
}
|
|
11524
|
+
if (isBanned(state, ip)) {
|
|
11525
|
+
dispatch({ type: "notice", text: `${ip} is already banned`, tone: "error" });
|
|
11526
|
+
return;
|
|
11527
|
+
}
|
|
11528
|
+
dispatch({ type: "busy", busy: true });
|
|
11529
|
+
try {
|
|
11530
|
+
const entry = await client.block(ip, "banned from dashboard");
|
|
11531
|
+
const ttl = formatDuration(Math.round((entry.expires_at - Date.now()) / 1e3));
|
|
11532
|
+
dispatch({ type: "notice", text: `banned ${ip} for ${ttl} (#${entry.strikes})`, tone: "ok" });
|
|
11533
|
+
} catch (err) {
|
|
11534
|
+
dispatch({ type: "notice", text: `ban failed: ${err.message}`, tone: "error" });
|
|
11535
|
+
} finally {
|
|
11536
|
+
dispatch({ type: "busy", busy: false });
|
|
11537
|
+
await refreshBans();
|
|
11538
|
+
}
|
|
11539
|
+
};
|
|
11540
|
+
const unbanSelected = async () => {
|
|
11541
|
+
const ip = selectedIp(state);
|
|
11542
|
+
if (state.busy) return;
|
|
11543
|
+
if (!ip) {
|
|
11544
|
+
dispatch({ type: "notice", text: "select a source first (tab)", tone: "error" });
|
|
11545
|
+
return;
|
|
11546
|
+
}
|
|
11547
|
+
if (!client) {
|
|
11548
|
+
dispatch({ type: "notice", text: "no daemon \u2014 cannot unban", tone: "error" });
|
|
11549
|
+
return;
|
|
11550
|
+
}
|
|
11551
|
+
dispatch({ type: "busy", busy: true });
|
|
11552
|
+
try {
|
|
11553
|
+
await client.unblock(ip);
|
|
11554
|
+
dispatch({ type: "notice", text: `unbanned ${ip}`, tone: "ok" });
|
|
11555
|
+
} catch (err) {
|
|
11556
|
+
dispatch({ type: "notice", text: `unban failed: ${err.message}`, tone: "error" });
|
|
11557
|
+
} finally {
|
|
11558
|
+
dispatch({ type: "busy", busy: false });
|
|
11559
|
+
await refreshBans();
|
|
11560
|
+
}
|
|
11561
|
+
};
|
|
11226
11562
|
app.on("key", (event) => {
|
|
11227
11563
|
switch (event.key) {
|
|
11228
11564
|
case "q":
|
|
@@ -11237,13 +11573,24 @@ async function startDashboard(options = {}) {
|
|
|
11237
11573
|
case "r":
|
|
11238
11574
|
dispatch({ type: "reset" });
|
|
11239
11575
|
break;
|
|
11576
|
+
case "tab":
|
|
11577
|
+
dispatch({ type: "focus_next" });
|
|
11578
|
+
break;
|
|
11579
|
+
case "b":
|
|
11580
|
+
void banSelected();
|
|
11581
|
+
break;
|
|
11582
|
+
case "u":
|
|
11583
|
+
void unbanSelected();
|
|
11584
|
+
break;
|
|
11240
11585
|
case "up":
|
|
11241
11586
|
case "k":
|
|
11242
|
-
dispatch({ type: "scroll", delta: 1 });
|
|
11587
|
+
if (state.focus === "feed") dispatch({ type: "scroll", delta: 1 });
|
|
11588
|
+
else dispatch({ type: "select", delta: -1 });
|
|
11243
11589
|
break;
|
|
11244
11590
|
case "down":
|
|
11245
11591
|
case "j":
|
|
11246
|
-
dispatch({ type: "scroll", delta: -1 });
|
|
11592
|
+
if (state.focus === "feed") dispatch({ type: "scroll", delta: -1 });
|
|
11593
|
+
else dispatch({ type: "select", delta: 1 });
|
|
11247
11594
|
break;
|
|
11248
11595
|
case "pageup":
|
|
11249
11596
|
dispatch({ type: "scroll", delta: 10 });
|
|
@@ -11262,7 +11609,17 @@ async function startDashboard(options = {}) {
|
|
|
11262
11609
|
app.render(({ ui, theme }) => {
|
|
11263
11610
|
renderDashboard(ui, state, theme, {
|
|
11264
11611
|
demo: options.demo,
|
|
11265
|
-
onFeedScroll: (delta) => dispatch({ type: "scroll", delta: -delta })
|
|
11612
|
+
onFeedScroll: (delta) => dispatch({ type: "scroll", delta: -delta }),
|
|
11613
|
+
// One click both focuses the panel and picks the row — the operator
|
|
11614
|
+
// should not have to click to focus and click again to select.
|
|
11615
|
+
onThreatSelect: (row) => {
|
|
11616
|
+
dispatch({ type: "focus", focus: "threats" });
|
|
11617
|
+
dispatch({ type: "select_at", index: row });
|
|
11618
|
+
},
|
|
11619
|
+
onBanSelect: (row) => {
|
|
11620
|
+
dispatch({ type: "focus", focus: "bans" });
|
|
11621
|
+
dispatch({ type: "select_at", index: row });
|
|
11622
|
+
}
|
|
11266
11623
|
});
|
|
11267
11624
|
});
|
|
11268
11625
|
try {
|
|
@@ -11279,6 +11636,7 @@ var init_dashboard = __esm({
|
|
|
11279
11636
|
init_ipc_client();
|
|
11280
11637
|
init_paths();
|
|
11281
11638
|
init_state();
|
|
11639
|
+
init_backoff();
|
|
11282
11640
|
init_theme2();
|
|
11283
11641
|
init_view();
|
|
11284
11642
|
init_demo();
|
|
@@ -15441,9 +15799,9 @@ var source_default = chalk;
|
|
|
15441
15799
|
|
|
15442
15800
|
// src/index.ts
|
|
15443
15801
|
var import_readline = __toESM(require("readline"));
|
|
15444
|
-
var
|
|
15445
|
-
var
|
|
15446
|
-
var
|
|
15802
|
+
var import_node_child_process12 = require("child_process");
|
|
15803
|
+
var import_node_fs33 = require("fs");
|
|
15804
|
+
var import_node_path23 = require("path");
|
|
15447
15805
|
var import_node_os8 = require("os");
|
|
15448
15806
|
|
|
15449
15807
|
// src/commands/monitor.ts
|
|
@@ -15518,9 +15876,10 @@ function banner() {
|
|
|
15518
15876
|
}
|
|
15519
15877
|
|
|
15520
15878
|
// src/core/log-parser.ts
|
|
15521
|
-
var NGINX_REGEX = /^(\S+) \S+ \S+ \[([^\]]+)\] "(\S+) (\S+) \S+" (\d{3}) (\d+) "[^"]*" "([^"]*)"/;
|
|
15522
|
-
var
|
|
15523
|
-
var
|
|
15879
|
+
var NGINX_REGEX = /^(?:(\S+) )?(\S+) \S+ \S+ \[([^\]]+)\] "(\S+) (\S+) \S+" (\d{3}) (\d+) "[^"]*" "([^"]*)"/;
|
|
15880
|
+
var TIMESTAMP = String.raw`(\w{3}\s+\d+\s+[\d:]+|\d{4}-\d{2}-\d{2}T[\d:.]+(?:Z|[+-]\d{2}:?\d{2})?)`;
|
|
15881
|
+
var AUTH_REGEX = new RegExp(`^${TIMESTAMP}\\s+\\S+\\s+(\\S+?)(?:\\[\\d+\\])?:\\s+(.*)`);
|
|
15882
|
+
var SYSLOG_REGEX = new RegExp(`^${TIMESTAMP}\\s+\\S+\\s+(\\S+?)(?:\\[\\d+\\])?:\\s+(.*)`);
|
|
15524
15883
|
var IP_REGEX = /(?:from|FROM)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
|
|
15525
15884
|
var INVALID_USER_REGEX = /(?:for\s+invalid\s+user)\s+(\S+?)(?:\s+from|\s*$)/;
|
|
15526
15885
|
var USER_REGEX = /(?:for|user)\s+(\S+?)(?:\s+from|\s*$)/;
|
|
@@ -15550,26 +15909,37 @@ var ATTACK_PATTERNS = {
|
|
|
15550
15909
|
/windows\/system32/i
|
|
15551
15910
|
],
|
|
15552
15911
|
rfi: [
|
|
15553
|
-
|
|
15912
|
+
// A remote URL pointing at something executable — the actual shape of a
|
|
15913
|
+
// remote file include (`?page=http://evil.tld/shell.txt`).
|
|
15914
|
+
//
|
|
15915
|
+
// This used to be `(?:https?|ftp):\/\/.*\?`, i.e. *any* URL carrying a
|
|
15916
|
+
// query string. A URL inside a query parameter is ordinary web design —
|
|
15917
|
+
// readers, share links, oembed, feed proxies — so on rssamplifier.com every
|
|
15918
|
+
// `/<feed>/read?p=https://…` hit was logged as a CRITICAL attack. With
|
|
15919
|
+
// auto-defence enforcing, that pattern bans readers, which is precisely the
|
|
15920
|
+
// failure PRD 0010 is written to prevent.
|
|
15921
|
+
/(?:https?|ftp):\/\/\S+\.(?:php|phtml|phar|asp|aspx|jsp|txt|sh|pl|py|cgi)(?:[?#%\s]|$)/i,
|
|
15554
15922
|
/php:\/\/(?:input|filter)/i,
|
|
15555
|
-
/data:\/\//i
|
|
15923
|
+
/(?:data|expect|zip|phar):\/\//i
|
|
15556
15924
|
]
|
|
15557
15925
|
};
|
|
15558
15926
|
function parseNginxLog(line) {
|
|
15559
15927
|
const match = line.match(NGINX_REGEX);
|
|
15560
15928
|
if (!match) return null;
|
|
15929
|
+
const fields = {
|
|
15930
|
+
ip: match[2],
|
|
15931
|
+
method: match[4],
|
|
15932
|
+
path: match[5],
|
|
15933
|
+
status: match[6],
|
|
15934
|
+
size: match[7],
|
|
15935
|
+
user_agent: match[8]
|
|
15936
|
+
};
|
|
15937
|
+
if (match[1]) fields.host = match[1];
|
|
15561
15938
|
return {
|
|
15562
|
-
timestamp: parseNginxTimestamp(match[
|
|
15939
|
+
timestamp: parseNginxTimestamp(match[3]),
|
|
15563
15940
|
raw: line,
|
|
15564
15941
|
source: "nginx",
|
|
15565
|
-
fields
|
|
15566
|
-
ip: match[1],
|
|
15567
|
-
method: match[3],
|
|
15568
|
-
path: match[4],
|
|
15569
|
-
status: match[5],
|
|
15570
|
-
size: match[6],
|
|
15571
|
-
user_agent: match[7]
|
|
15572
|
-
}
|
|
15942
|
+
fields
|
|
15573
15943
|
};
|
|
15574
15944
|
}
|
|
15575
15945
|
function parseAuthLog(line) {
|
|
@@ -15605,17 +15975,23 @@ function parseSyslog(line) {
|
|
|
15605
15975
|
}
|
|
15606
15976
|
function detectAttackPattern(path) {
|
|
15607
15977
|
const candidates = /* @__PURE__ */ new Set([path]);
|
|
15608
|
-
|
|
15609
|
-
|
|
15610
|
-
|
|
15611
|
-
|
|
15612
|
-
|
|
15613
|
-
|
|
15614
|
-
|
|
15978
|
+
const seeds = [path, path.includes("+") ? path.replace(/\+/g, " ") : null].filter(
|
|
15979
|
+
(s) => s !== null
|
|
15980
|
+
);
|
|
15981
|
+
for (const seed of seeds) {
|
|
15982
|
+
candidates.add(seed);
|
|
15983
|
+
let current = seed;
|
|
15984
|
+
for (let i = 0; i < 2; i++) {
|
|
15985
|
+
let decoded = null;
|
|
15986
|
+
try {
|
|
15987
|
+
decoded = decodeURIComponent(current);
|
|
15988
|
+
} catch {
|
|
15989
|
+
decoded = null;
|
|
15990
|
+
}
|
|
15991
|
+
if (decoded === null || decoded === current) break;
|
|
15992
|
+
candidates.add(decoded);
|
|
15993
|
+
current = decoded;
|
|
15615
15994
|
}
|
|
15616
|
-
if (decoded === null || decoded === current) break;
|
|
15617
|
-
candidates.add(decoded);
|
|
15618
|
-
current = decoded;
|
|
15619
15995
|
}
|
|
15620
15996
|
for (const [type, patterns] of Object.entries(ATTACK_PATTERNS)) {
|
|
15621
15997
|
for (const pattern of patterns) {
|
|
@@ -15641,6 +16017,10 @@ function parseNginxTimestamp(s) {
|
|
|
15641
16017
|
return Number.isNaN(d.getTime()) ? /* @__PURE__ */ new Date() : d;
|
|
15642
16018
|
}
|
|
15643
16019
|
function parseSyslogTimestamp(s) {
|
|
16020
|
+
if (/^\d{4}-\d{2}-\d{2}T/.test(s)) {
|
|
16021
|
+
const iso = new Date(s);
|
|
16022
|
+
return Number.isNaN(iso.getTime()) ? /* @__PURE__ */ new Date() : iso;
|
|
16023
|
+
}
|
|
15644
16024
|
const now = /* @__PURE__ */ new Date();
|
|
15645
16025
|
let d = /* @__PURE__ */ new Date(`${s} ${now.getFullYear()}`);
|
|
15646
16026
|
if (Number.isNaN(d.getTime())) return now;
|
|
@@ -20731,6 +21111,7 @@ function loadConfig(configPath) {
|
|
|
20731
21111
|
api: { ...DEFAULT_CONFIG.api, ...parsed.api },
|
|
20732
21112
|
alerts: parsed.alerts || {},
|
|
20733
21113
|
modules: { ...DEFAULT_CONFIG.modules, ...parsed.modules },
|
|
21114
|
+
remediation: parsed.remediation,
|
|
20734
21115
|
license: parsed.license
|
|
20735
21116
|
};
|
|
20736
21117
|
} catch {
|
|
@@ -22698,14 +23079,14 @@ async function sshConnect(options) {
|
|
|
22698
23079
|
}
|
|
22699
23080
|
|
|
22700
23081
|
// src/commands/daemon.ts
|
|
22701
|
-
var
|
|
22702
|
-
var import_node_fs27 = require("fs");
|
|
22703
|
-
var import_node_path19 = require("path");
|
|
23082
|
+
var import_node_child_process8 = require("child_process");
|
|
22704
23083
|
var import_node_fs28 = require("fs");
|
|
23084
|
+
var import_node_path20 = require("path");
|
|
23085
|
+
var import_node_fs29 = require("fs");
|
|
22705
23086
|
|
|
22706
23087
|
// src/daemon/index.ts
|
|
22707
|
-
var
|
|
22708
|
-
var
|
|
23088
|
+
var import_node_fs27 = require("fs");
|
|
23089
|
+
var import_node_path19 = require("path");
|
|
22709
23090
|
init_paths();
|
|
22710
23091
|
|
|
22711
23092
|
// src/daemon/ipc-server.ts
|
|
@@ -22731,10 +23112,12 @@ var bus = new EventBus();
|
|
|
22731
23112
|
bus.setMaxListeners(50);
|
|
22732
23113
|
|
|
22733
23114
|
// src/daemon/ipc-server.ts
|
|
23115
|
+
init_backoff();
|
|
22734
23116
|
var IpcServer = class {
|
|
22735
|
-
constructor(version, moduleHost) {
|
|
23117
|
+
constructor(version, moduleHost, remediation) {
|
|
22736
23118
|
this.version = version;
|
|
22737
23119
|
this.moduleHost = moduleHost;
|
|
23120
|
+
this.remediation = remediation;
|
|
22738
23121
|
bus.on("event", (event) => {
|
|
22739
23122
|
this.counters.events++;
|
|
22740
23123
|
if (event.severity === "medium" || event.severity === "high" || event.severity === "critical") {
|
|
@@ -22751,6 +23134,7 @@ var IpcServer = class {
|
|
|
22751
23134
|
}
|
|
22752
23135
|
version;
|
|
22753
23136
|
moduleHost;
|
|
23137
|
+
remediation;
|
|
22754
23138
|
server = null;
|
|
22755
23139
|
clients = /* @__PURE__ */ new Map();
|
|
22756
23140
|
nextClientId = 1;
|
|
@@ -22890,6 +23274,67 @@ var IpcServer = class {
|
|
|
22890
23274
|
case "subscribe":
|
|
22891
23275
|
for (const ch of req.params.channels) client.subscriptions.add(ch);
|
|
22892
23276
|
return this.send(client, { id: req.id, ok: true, result: { subscribed: [...client.subscriptions] } });
|
|
23277
|
+
case "blocklist": {
|
|
23278
|
+
if (!this.remediation) {
|
|
23279
|
+
return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
|
|
23280
|
+
}
|
|
23281
|
+
const status = this.remediation.status();
|
|
23282
|
+
const reply = {
|
|
23283
|
+
entries: this.remediation.getBlocklist().map((entry) => ({
|
|
23284
|
+
ip: entry.ip,
|
|
23285
|
+
reason: entry.reason,
|
|
23286
|
+
blocked_at: entry.blocked_at,
|
|
23287
|
+
expires_at: entry.expires_at,
|
|
23288
|
+
strikes: entry.strikes,
|
|
23289
|
+
source: entry.source,
|
|
23290
|
+
dry_run: entry.dry_run
|
|
23291
|
+
})),
|
|
23292
|
+
protected: this.remediation.getProtected(),
|
|
23293
|
+
enabled: status.enabled,
|
|
23294
|
+
dry_run: status.dry_run,
|
|
23295
|
+
backend: status.backend,
|
|
23296
|
+
min_severity: status.min_severity
|
|
23297
|
+
};
|
|
23298
|
+
return this.send(client, { id: req.id, ok: true, result: reply });
|
|
23299
|
+
}
|
|
23300
|
+
case "block": {
|
|
23301
|
+
if (!tokensMatch(this.controlToken, req.params?.token)) {
|
|
23302
|
+
return this.send(client, {
|
|
23303
|
+
id: req.id,
|
|
23304
|
+
ok: false,
|
|
23305
|
+
error: "banning requires the daemon control token (run as root, or as the user running threatcrushd)"
|
|
23306
|
+
});
|
|
23307
|
+
}
|
|
23308
|
+
if (!this.remediation) {
|
|
23309
|
+
return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
|
|
23310
|
+
}
|
|
23311
|
+
const ttl = parseDuration(req.params?.ttl) ?? void 0;
|
|
23312
|
+
const result = await this.remediation.ban(req.params.ip, req.params.reason || "banned by operator", {
|
|
23313
|
+
ttlSeconds: ttl,
|
|
23314
|
+
source: "manual"
|
|
23315
|
+
});
|
|
23316
|
+
if (!result.ok) {
|
|
23317
|
+
return this.send(client, { id: req.id, ok: false, error: result.error || "ban failed" });
|
|
23318
|
+
}
|
|
23319
|
+
return this.send(client, { id: req.id, ok: true, result: result.entry });
|
|
23320
|
+
}
|
|
23321
|
+
case "unblock": {
|
|
23322
|
+
if (!tokensMatch(this.controlToken, req.params?.token)) {
|
|
23323
|
+
return this.send(client, {
|
|
23324
|
+
id: req.id,
|
|
23325
|
+
ok: false,
|
|
23326
|
+
error: "unbanning requires the daemon control token (run as root, or as the user running threatcrushd)"
|
|
23327
|
+
});
|
|
23328
|
+
}
|
|
23329
|
+
if (!this.remediation) {
|
|
23330
|
+
return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
|
|
23331
|
+
}
|
|
23332
|
+
const result = await this.remediation.unban(req.params.ip, { forget: req.params.forget !== false });
|
|
23333
|
+
if (!result.ok) {
|
|
23334
|
+
return this.send(client, { id: req.id, ok: false, error: result.error || "unban failed" });
|
|
23335
|
+
}
|
|
23336
|
+
return this.send(client, { id: req.id, ok: true, result: { ip: req.params.ip } });
|
|
23337
|
+
}
|
|
22893
23338
|
case "shutdown":
|
|
22894
23339
|
if (!tokensMatch(this.controlToken, req.params?.token)) {
|
|
22895
23340
|
return this.send(client, {
|
|
@@ -23006,6 +23451,7 @@ var LogWatcher = class {
|
|
|
23006
23451
|
let severity = "info";
|
|
23007
23452
|
let message = line;
|
|
23008
23453
|
let sourceIp;
|
|
23454
|
+
let host;
|
|
23009
23455
|
if (parsed.source === "auth") {
|
|
23010
23456
|
const entry = parseAuthLog(line);
|
|
23011
23457
|
if (!entry) return;
|
|
@@ -23029,6 +23475,7 @@ var LogWatcher = class {
|
|
|
23029
23475
|
sourceIp = entry.fields.ip;
|
|
23030
23476
|
const status = parseInt(entry.fields.status, 10);
|
|
23031
23477
|
const attack = detectAttackPattern(entry.fields.path);
|
|
23478
|
+
host = entry.fields.host;
|
|
23032
23479
|
if (attack) {
|
|
23033
23480
|
severity = "critical";
|
|
23034
23481
|
message = `Attack [${attack.toUpperCase()}]: ${entry.fields.method} ${entry.fields.path}`;
|
|
@@ -23050,7 +23497,8 @@ var LogWatcher = class {
|
|
|
23050
23497
|
category: src.category,
|
|
23051
23498
|
severity,
|
|
23052
23499
|
message,
|
|
23053
|
-
source_ip: sourceIp
|
|
23500
|
+
source_ip: sourceIp,
|
|
23501
|
+
...host ? { details: { host } } : {}
|
|
23054
23502
|
};
|
|
23055
23503
|
try {
|
|
23056
23504
|
insertEvent(event);
|
|
@@ -24590,12 +25038,132 @@ function loadAllRules(customDir) {
|
|
|
24590
25038
|
|
|
24591
25039
|
// src/daemon/firewall/adapters.ts
|
|
24592
25040
|
var import_node_child_process6 = require("child_process");
|
|
25041
|
+
var import_node_fs25 = require("fs");
|
|
25042
|
+
var import_node_path18 = require("path");
|
|
24593
25043
|
var import_node_net3 = require("net");
|
|
24594
25044
|
function assertValidFirewallIp(ip) {
|
|
24595
25045
|
if ((0, import_node_net3.isIP)(ip) !== 4) {
|
|
24596
25046
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
24597
25047
|
}
|
|
24598
25048
|
}
|
|
25049
|
+
function assertBannableIp(ip) {
|
|
25050
|
+
if ((0, import_node_net3.isIP)(ip) === 0) {
|
|
25051
|
+
throw new Error(`Invalid IP address: ${ip}`);
|
|
25052
|
+
}
|
|
25053
|
+
}
|
|
25054
|
+
function writeIfAbsent(path, contents) {
|
|
25055
|
+
(0, import_node_fs25.mkdirSync)((0, import_node_path18.dirname)(path), { recursive: true });
|
|
25056
|
+
try {
|
|
25057
|
+
(0, import_node_fs25.writeFileSync)(path, contents, { flag: "wx" });
|
|
25058
|
+
} catch (err) {
|
|
25059
|
+
if (err.code !== "EEXIST") throw err;
|
|
25060
|
+
}
|
|
25061
|
+
}
|
|
25062
|
+
var FAIL2BAN_JAIL = "threatcrush";
|
|
25063
|
+
var FAIL2BAN_FILTER_FILE = "/etc/fail2ban/filter.d/threatcrush.conf";
|
|
25064
|
+
var FAIL2BAN_JAIL_FILE = "/etc/fail2ban/jail.d/threatcrush.conf";
|
|
25065
|
+
var Fail2banAdapter = class {
|
|
25066
|
+
constructor(jail = FAIL2BAN_JAIL, backstopSeconds = 86400) {
|
|
25067
|
+
this.jail = jail;
|
|
25068
|
+
this.backstopSeconds = backstopSeconds;
|
|
25069
|
+
}
|
|
25070
|
+
jail;
|
|
25071
|
+
backstopSeconds;
|
|
25072
|
+
name = "fail2ban";
|
|
25073
|
+
enforces = true;
|
|
25074
|
+
jailReady = false;
|
|
25075
|
+
isAvailable() {
|
|
25076
|
+
const result = (0, import_node_child_process6.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
25077
|
+
return result.status === 0;
|
|
25078
|
+
}
|
|
25079
|
+
client(args) {
|
|
25080
|
+
return (0, import_node_child_process6.execFileSync)("fail2ban-client", args, {
|
|
25081
|
+
encoding: "utf-8",
|
|
25082
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
25083
|
+
});
|
|
25084
|
+
}
|
|
25085
|
+
/**
|
|
25086
|
+
* Create the jail if it is missing. Writing to /etc/fail2ban needs root; when
|
|
25087
|
+
* we cannot, the error surfaces to the caller instead of a ban that silently
|
|
25088
|
+
* goes nowhere.
|
|
25089
|
+
*/
|
|
25090
|
+
ensureJail() {
|
|
25091
|
+
if (this.jailReady) return;
|
|
25092
|
+
try {
|
|
25093
|
+
this.client(["status", this.jail]);
|
|
25094
|
+
this.jailReady = true;
|
|
25095
|
+
return;
|
|
25096
|
+
} catch {
|
|
25097
|
+
}
|
|
25098
|
+
writeIfAbsent(
|
|
25099
|
+
FAIL2BAN_FILTER_FILE,
|
|
25100
|
+
[
|
|
25101
|
+
"# Installed by ThreatCrush. Intentionally matches nothing:",
|
|
25102
|
+
"# detection happens in threatcrushd, this jail only executes bans.",
|
|
25103
|
+
"[Definition]",
|
|
25104
|
+
"failregex = ^threatcrush-never-matches <HOST>$",
|
|
25105
|
+
"ignoreregex =",
|
|
25106
|
+
""
|
|
25107
|
+
].join("\n")
|
|
25108
|
+
);
|
|
25109
|
+
writeIfAbsent(
|
|
25110
|
+
FAIL2BAN_JAIL_FILE,
|
|
25111
|
+
[
|
|
25112
|
+
"# Installed by ThreatCrush \u2014 bans arrive via `fail2ban-client set threatcrush banip`.",
|
|
25113
|
+
"# bantime is only a backstop; threatcrushd unbans on its own schedule.",
|
|
25114
|
+
`[${this.jail}]`,
|
|
25115
|
+
"enabled = true",
|
|
25116
|
+
"filter = threatcrush",
|
|
25117
|
+
"backend = polling",
|
|
25118
|
+
"logpath = /var/log/threatcrush/threatcrushd.log",
|
|
25119
|
+
"maxretry = 1000000",
|
|
25120
|
+
"findtime = 1",
|
|
25121
|
+
`bantime = ${this.backstopSeconds}`,
|
|
25122
|
+
""
|
|
25123
|
+
].join("\n")
|
|
25124
|
+
);
|
|
25125
|
+
this.client(["reload", this.jail]);
|
|
25126
|
+
this.jailReady = true;
|
|
25127
|
+
}
|
|
25128
|
+
async block(ip) {
|
|
25129
|
+
assertBannableIp(ip);
|
|
25130
|
+
this.ensureJail();
|
|
25131
|
+
this.client(["set", this.jail, "banip", ip]);
|
|
25132
|
+
}
|
|
25133
|
+
async unblock(ip) {
|
|
25134
|
+
assertBannableIp(ip);
|
|
25135
|
+
try {
|
|
25136
|
+
this.client(["set", this.jail, "unbanip", ip]);
|
|
25137
|
+
} catch {
|
|
25138
|
+
}
|
|
25139
|
+
}
|
|
25140
|
+
async isBlocked(ip) {
|
|
25141
|
+
assertBannableIp(ip);
|
|
25142
|
+
return (await this.listBlocked()).includes(ip);
|
|
25143
|
+
}
|
|
25144
|
+
async listBlocked() {
|
|
25145
|
+
try {
|
|
25146
|
+
return parseBannedList(this.client(["get", this.jail, "banned"]));
|
|
25147
|
+
} catch {
|
|
25148
|
+
try {
|
|
25149
|
+
const status = this.client(["status", this.jail]);
|
|
25150
|
+
const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
25151
|
+
if (!line) return [];
|
|
25152
|
+
return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net3.isIP)(s) !== 0);
|
|
25153
|
+
} catch {
|
|
25154
|
+
return [];
|
|
25155
|
+
}
|
|
25156
|
+
}
|
|
25157
|
+
}
|
|
25158
|
+
};
|
|
25159
|
+
function parseBannedList(output) {
|
|
25160
|
+
const found = [];
|
|
25161
|
+
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
25162
|
+
if ((0, import_node_net3.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
25163
|
+
}
|
|
25164
|
+
if (found.length > 0) return found;
|
|
25165
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net3.isIP)(s) !== 0);
|
|
25166
|
+
}
|
|
24599
25167
|
var NftablesAdapter = class {
|
|
24600
25168
|
name = "nftables";
|
|
24601
25169
|
table = "threatcrush";
|
|
@@ -24699,6 +25267,7 @@ var IptablesAdapter = class {
|
|
|
24699
25267
|
};
|
|
24700
25268
|
var DryRunAdapter = class {
|
|
24701
25269
|
name = "dry-run";
|
|
25270
|
+
enforces = false;
|
|
24702
25271
|
blocked = /* @__PURE__ */ new Set();
|
|
24703
25272
|
isAvailable() {
|
|
24704
25273
|
return true;
|
|
@@ -24719,7 +25288,19 @@ var DryRunAdapter = class {
|
|
|
24719
25288
|
return [...this.blocked];
|
|
24720
25289
|
}
|
|
24721
25290
|
};
|
|
24722
|
-
function detectFirewallAdapter() {
|
|
25291
|
+
function detectFirewallAdapter(backend = "auto") {
|
|
25292
|
+
const byName = {
|
|
25293
|
+
fail2ban: () => new Fail2banAdapter(),
|
|
25294
|
+
nftables: () => new NftablesAdapter(),
|
|
25295
|
+
iptables: () => new IptablesAdapter(),
|
|
25296
|
+
"dry-run": () => new DryRunAdapter()
|
|
25297
|
+
};
|
|
25298
|
+
if (backend !== "auto") {
|
|
25299
|
+
const chosen = byName[backend]?.();
|
|
25300
|
+
if (chosen?.isAvailable()) return chosen;
|
|
25301
|
+
}
|
|
25302
|
+
const f2b = new Fail2banAdapter();
|
|
25303
|
+
if (f2b.isAvailable()) return f2b;
|
|
24723
25304
|
const nft = new NftablesAdapter();
|
|
24724
25305
|
if (nft.isAvailable()) return nft;
|
|
24725
25306
|
const ipt = new IptablesAdapter();
|
|
@@ -24728,14 +25309,129 @@ function detectFirewallAdapter() {
|
|
|
24728
25309
|
}
|
|
24729
25310
|
|
|
24730
25311
|
// src/daemon/firewall/remediation.ts
|
|
24731
|
-
var
|
|
25312
|
+
var import_node_fs26 = require("fs");
|
|
25313
|
+
var import_node_net5 = require("net");
|
|
24732
25314
|
init_paths();
|
|
25315
|
+
init_backoff();
|
|
25316
|
+
|
|
25317
|
+
// src/daemon/firewall/protected.ts
|
|
25318
|
+
var import_node_child_process7 = require("child_process");
|
|
25319
|
+
var import_node_net4 = require("net");
|
|
25320
|
+
var DEFAULT_PROTECTED = [
|
|
25321
|
+
"127.0.0.0/8",
|
|
25322
|
+
"::1/128",
|
|
25323
|
+
"10.0.0.0/8",
|
|
25324
|
+
"172.16.0.0/12",
|
|
25325
|
+
"192.168.0.0/16",
|
|
25326
|
+
"169.254.0.0/16",
|
|
25327
|
+
"fc00::/7",
|
|
25328
|
+
"fe80::/10"
|
|
25329
|
+
];
|
|
25330
|
+
function ipToBytes(ip) {
|
|
25331
|
+
const version = (0, import_node_net4.isIP)(ip);
|
|
25332
|
+
if (version === 4) return v4ToBytes(ip);
|
|
25333
|
+
if (version === 6) return v6ToBytes(ip);
|
|
25334
|
+
return null;
|
|
25335
|
+
}
|
|
25336
|
+
function v4ToBytes(ip) {
|
|
25337
|
+
const parts = ip.split(".");
|
|
25338
|
+
if (parts.length !== 4) return null;
|
|
25339
|
+
const bytes = new Uint8Array(4);
|
|
25340
|
+
for (let i = 0; i < 4; i++) {
|
|
25341
|
+
const n = Number(parts[i]);
|
|
25342
|
+
if (!Number.isInteger(n) || n < 0 || n > 255) return null;
|
|
25343
|
+
bytes[i] = n;
|
|
25344
|
+
}
|
|
25345
|
+
return bytes;
|
|
25346
|
+
}
|
|
25347
|
+
function v6ToBytes(ip) {
|
|
25348
|
+
const bare = ip.split("%")[0];
|
|
25349
|
+
const [headText, tailText] = bare.split("::", 2);
|
|
25350
|
+
const head = headText ? headText.split(":") : [];
|
|
25351
|
+
const tail = tailText !== void 0 ? tailText ? tailText.split(":") : [] : null;
|
|
25352
|
+
const groups = [];
|
|
25353
|
+
const pushGroup = (group) => {
|
|
25354
|
+
if (group.includes(".")) {
|
|
25355
|
+
const v4 = v4ToBytes(group);
|
|
25356
|
+
if (!v4) return false;
|
|
25357
|
+
groups.push(v4[0] << 8 | v4[1], v4[2] << 8 | v4[3]);
|
|
25358
|
+
return true;
|
|
25359
|
+
}
|
|
25360
|
+
if (!/^[0-9a-fA-F]{1,4}$/.test(group)) return false;
|
|
25361
|
+
groups.push(parseInt(group, 16));
|
|
25362
|
+
return true;
|
|
25363
|
+
};
|
|
25364
|
+
for (const group of head) if (!pushGroup(group)) return null;
|
|
25365
|
+
const headCount = groups.length;
|
|
25366
|
+
if (tail === null) {
|
|
25367
|
+
if (headCount !== 8) return null;
|
|
25368
|
+
} else {
|
|
25369
|
+
const tailGroups = [];
|
|
25370
|
+
const saved = groups.length;
|
|
25371
|
+
for (const group of tail) if (!pushGroup(group)) return null;
|
|
25372
|
+
tailGroups.push(...groups.splice(saved));
|
|
25373
|
+
const zeros = 8 - headCount - tailGroups.length;
|
|
25374
|
+
if (zeros < 0) return null;
|
|
25375
|
+
for (let i = 0; i < zeros; i++) groups.push(0);
|
|
25376
|
+
groups.push(...tailGroups);
|
|
25377
|
+
}
|
|
25378
|
+
if (groups.length !== 8) return null;
|
|
25379
|
+
const bytes = new Uint8Array(16);
|
|
25380
|
+
for (let i = 0; i < 8; i++) {
|
|
25381
|
+
bytes[i * 2] = groups[i] >> 8 & 255;
|
|
25382
|
+
bytes[i * 2 + 1] = groups[i] & 255;
|
|
25383
|
+
}
|
|
25384
|
+
return bytes;
|
|
25385
|
+
}
|
|
25386
|
+
function ipMatches(ip, entry) {
|
|
25387
|
+
const [network, prefixText] = entry.trim().split("/");
|
|
25388
|
+
const target = ipToBytes(ip);
|
|
25389
|
+
const base = ipToBytes(network);
|
|
25390
|
+
if (!target || !base || target.length !== base.length) return false;
|
|
25391
|
+
const bits = prefixText === void 0 ? base.length * 8 : Number(prefixText);
|
|
25392
|
+
if (!Number.isInteger(bits) || bits < 0 || bits > base.length * 8) return false;
|
|
25393
|
+
const wholeBytes = Math.floor(bits / 8);
|
|
25394
|
+
for (let i = 0; i < wholeBytes; i++) {
|
|
25395
|
+
if (target[i] !== base[i]) return false;
|
|
25396
|
+
}
|
|
25397
|
+
const remainder = bits % 8;
|
|
25398
|
+
if (remainder === 0) return true;
|
|
25399
|
+
const mask = 255 << 8 - remainder & 255;
|
|
25400
|
+
return (target[wholeBytes] & mask) === (base[wholeBytes] & mask);
|
|
25401
|
+
}
|
|
25402
|
+
function isProtected(ip, list) {
|
|
25403
|
+
return list.some((entry) => ipMatches(ip, entry));
|
|
25404
|
+
}
|
|
25405
|
+
function currentSshClient(env2 = process.env) {
|
|
25406
|
+
const source = env2.SSH_CLIENT || env2.SSH_CONNECTION;
|
|
25407
|
+
if (!source) return null;
|
|
25408
|
+
const ip = source.trim().split(/\s+/)[0];
|
|
25409
|
+
return ip && (0, import_node_net4.isIP)(ip) ? ip : null;
|
|
25410
|
+
}
|
|
25411
|
+
function defaultGateways() {
|
|
25412
|
+
const found = /* @__PURE__ */ new Set();
|
|
25413
|
+
for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
|
|
25414
|
+
try {
|
|
25415
|
+
const out = (0, import_node_child_process7.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
25416
|
+
for (const line of out.split("\n")) {
|
|
25417
|
+
const match = line.match(/\bvia\s+(\S+)/);
|
|
25418
|
+
if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
|
|
25419
|
+
}
|
|
25420
|
+
} catch {
|
|
25421
|
+
}
|
|
25422
|
+
}
|
|
25423
|
+
return [...found];
|
|
25424
|
+
}
|
|
25425
|
+
|
|
25426
|
+
// src/daemon/firewall/remediation.ts
|
|
24733
25427
|
var DEFAULT_CONFIG2 = {
|
|
24734
25428
|
enabled: true,
|
|
24735
|
-
dry_run:
|
|
24736
|
-
default_ttl_seconds: 3600,
|
|
25429
|
+
dry_run: false,
|
|
24737
25430
|
min_severity: "high",
|
|
24738
|
-
|
|
25431
|
+
max_ban_seconds: 86400,
|
|
25432
|
+
strike_memory_seconds: 86400,
|
|
25433
|
+
allowlist: [],
|
|
25434
|
+
protect_current_ssh_client: true
|
|
24739
25435
|
};
|
|
24740
25436
|
var SEVERITY_RANK4 = {
|
|
24741
25437
|
info: 0,
|
|
@@ -24749,130 +25445,248 @@ var RemediationManager = class {
|
|
|
24749
25445
|
this.adapter = adapter;
|
|
24750
25446
|
this.bus = bus2;
|
|
24751
25447
|
this.config = { ...DEFAULT_CONFIG2, ...config };
|
|
25448
|
+
this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
|
|
25449
|
+
if (this.config.protect_current_ssh_client) {
|
|
25450
|
+
const ssh = currentSshClient();
|
|
25451
|
+
if (ssh) this.protectedList.push(ssh);
|
|
25452
|
+
}
|
|
25453
|
+
for (const gateway of defaultGateways()) this.protectedList.push(gateway);
|
|
25454
|
+
if (this.adapter.enforces === false) this.config.dry_run = true;
|
|
24752
25455
|
this.loadState();
|
|
25456
|
+
void this.reconcile();
|
|
24753
25457
|
this.startExpiryWorker();
|
|
24754
25458
|
}
|
|
24755
25459
|
adapter;
|
|
24756
25460
|
bus;
|
|
24757
25461
|
config;
|
|
24758
25462
|
blocklist = [];
|
|
25463
|
+
strikes = {};
|
|
25464
|
+
protectedList = [];
|
|
24759
25465
|
expiryTimer = null;
|
|
25466
|
+
/** Every address that can never be blocked, built-ins included. */
|
|
25467
|
+
getProtected() {
|
|
25468
|
+
return [...this.protectedList];
|
|
25469
|
+
}
|
|
25470
|
+
isAllowlisted(ip) {
|
|
25471
|
+
return isProtected(ip, this.protectedList);
|
|
25472
|
+
}
|
|
24760
25473
|
async handleDetection(event) {
|
|
24761
25474
|
if (!this.config.enabled) return;
|
|
24762
25475
|
const eventRank = SEVERITY_RANK4[event.severity] ?? 0;
|
|
24763
25476
|
const minRank = SEVERITY_RANK4[this.config.min_severity] ?? 3;
|
|
24764
25477
|
if (eventRank < minRank) return;
|
|
24765
25478
|
const ip = event.source_ip;
|
|
24766
|
-
if (!ip) return;
|
|
25479
|
+
if (!ip || (0, import_node_net5.isIP)(ip) === 0) return;
|
|
24767
25480
|
if (this.isAllowlisted(ip)) return;
|
|
24768
25481
|
if (this.blocklist.some((b) => b.ip === ip)) return;
|
|
24769
|
-
const ruleRemediation = event.details?.remediation;
|
|
24770
|
-
const ttl = ruleRemediation?.ttl_seconds || this.config.default_ttl_seconds;
|
|
24771
25482
|
const ruleId = event.details?.rule_id;
|
|
24772
|
-
await this.
|
|
25483
|
+
await this.ban(ip, event.message, { ruleId, source: "auto" });
|
|
24773
25484
|
}
|
|
24774
|
-
|
|
24775
|
-
|
|
25485
|
+
/**
|
|
25486
|
+
* Ban `ip`. With no explicit TTL the length comes from the Fibonacci ladder:
|
|
25487
|
+
* 1m, 2m, 3m, 5m, 8m, 13m … for the 1st, 2nd, 3rd offence and so on, clamped
|
|
25488
|
+
* to `max_ban_seconds`.
|
|
25489
|
+
*/
|
|
25490
|
+
async ban(ip, reason, opts = {}) {
|
|
25491
|
+
if ((0, import_node_net5.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
25492
|
+
if (this.isAllowlisted(ip)) {
|
|
25493
|
+
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
25494
|
+
}
|
|
25495
|
+
const now = Date.now();
|
|
25496
|
+
const existing = this.blocklist.find((b) => b.ip === ip);
|
|
25497
|
+
if (existing && !opts.ttlSeconds) {
|
|
25498
|
+
return { ok: false, error: `${ip} is already banned` };
|
|
25499
|
+
}
|
|
25500
|
+
const strike = recordStrike(this.strikes, ip, now, this.config.strike_memory_seconds);
|
|
25501
|
+
const ttl = opts.ttlSeconds ?? banSeconds(strike, this.config.max_ban_seconds);
|
|
24776
25502
|
const entry = {
|
|
24777
25503
|
ip,
|
|
24778
25504
|
reason,
|
|
24779
|
-
rule_id: ruleId,
|
|
24780
|
-
blocked_at:
|
|
24781
|
-
expires_at:
|
|
24782
|
-
dry_run: this.config.dry_run
|
|
25505
|
+
rule_id: opts.ruleId,
|
|
25506
|
+
blocked_at: now,
|
|
25507
|
+
expires_at: now + ttl * 1e3,
|
|
25508
|
+
dry_run: this.config.dry_run,
|
|
25509
|
+
strikes: strike,
|
|
25510
|
+
source: opts.source ?? "manual"
|
|
24783
25511
|
};
|
|
24784
25512
|
if (!this.config.dry_run) {
|
|
24785
25513
|
try {
|
|
24786
25514
|
await this.adapter.block(ip);
|
|
24787
25515
|
} catch (err) {
|
|
24788
|
-
|
|
25516
|
+
const message = err.message;
|
|
25517
|
+
this.logLine(`[firewall] error blocking ${ip}: ${message}`);
|
|
24789
25518
|
this.bus.publish({
|
|
24790
25519
|
timestamp: /* @__PURE__ */ new Date(),
|
|
24791
25520
|
module: "firewall-rules",
|
|
24792
25521
|
category: "system",
|
|
24793
25522
|
severity: "medium",
|
|
24794
|
-
message: `Failed to block ${ip}: ${
|
|
25523
|
+
message: `Failed to block ${ip}: ${message}. Ensure the daemon can manage ${this.adapter.name}.`,
|
|
25524
|
+
source_ip: ip
|
|
24795
25525
|
});
|
|
24796
|
-
return false;
|
|
25526
|
+
return { ok: false, error: message };
|
|
24797
25527
|
}
|
|
24798
25528
|
}
|
|
25529
|
+
this.blocklist = this.blocklist.filter((b) => b.ip !== ip);
|
|
24799
25530
|
this.blocklist.push(entry);
|
|
24800
25531
|
this.saveState();
|
|
24801
25532
|
const mode = this.config.dry_run ? "[DRY-RUN] " : "";
|
|
24802
|
-
const
|
|
24803
|
-
this.logLine(`[firewall] ${
|
|
25533
|
+
const label = `${mode}Banned ${ip} for ${formatDuration(ttl)} (offence #${strike}): ${reason}`;
|
|
25534
|
+
this.logLine(`[firewall] ${label}`);
|
|
24804
25535
|
this.bus.publish({
|
|
24805
25536
|
timestamp: /* @__PURE__ */ new Date(),
|
|
24806
25537
|
module: "firewall-rules",
|
|
24807
25538
|
category: "system",
|
|
24808
25539
|
severity: "info",
|
|
24809
|
-
message:
|
|
25540
|
+
message: label,
|
|
24810
25541
|
source_ip: ip,
|
|
24811
|
-
details: {
|
|
25542
|
+
details: {
|
|
25543
|
+
action: "block",
|
|
25544
|
+
rule_id: opts.ruleId,
|
|
25545
|
+
dry_run: this.config.dry_run,
|
|
25546
|
+
ttl_seconds: ttl,
|
|
25547
|
+
strikes: strike,
|
|
25548
|
+
source: entry.source,
|
|
25549
|
+
backend: this.adapter.name
|
|
25550
|
+
}
|
|
24812
25551
|
});
|
|
24813
|
-
return true;
|
|
25552
|
+
return { ok: true, entry };
|
|
24814
25553
|
}
|
|
24815
|
-
|
|
25554
|
+
/**
|
|
25555
|
+
* Lift a ban. `forget` also drops the strike ledger entry — an operator
|
|
25556
|
+
* unbanning by hand is overruling the detection, so the next offence should
|
|
25557
|
+
* start at one minute again rather than resuming the ladder.
|
|
25558
|
+
*/
|
|
25559
|
+
async unban(ip, opts = {}) {
|
|
24816
25560
|
const idx = this.blocklist.findIndex((b) => b.ip === ip);
|
|
24817
|
-
|
|
24818
|
-
|
|
24819
|
-
if (!entry.dry_run) {
|
|
25561
|
+
const entry = idx >= 0 ? this.blocklist[idx] : null;
|
|
25562
|
+
if (!entry?.dry_run) {
|
|
24820
25563
|
try {
|
|
24821
25564
|
await this.adapter.unblock(ip);
|
|
24822
25565
|
} catch (err) {
|
|
24823
|
-
|
|
24824
|
-
|
|
25566
|
+
const message = err.message;
|
|
25567
|
+
this.logLine(`[firewall] error unblocking ${ip}: ${message}`);
|
|
25568
|
+
return { ok: false, error: message };
|
|
24825
25569
|
}
|
|
24826
25570
|
}
|
|
24827
|
-
this.blocklist.splice(idx, 1);
|
|
25571
|
+
if (idx >= 0) this.blocklist.splice(idx, 1);
|
|
25572
|
+
if (opts.forget) delete this.strikes[ip];
|
|
24828
25573
|
this.saveState();
|
|
24829
|
-
|
|
25574
|
+
if (idx < 0) return { ok: false, error: `${ip} is not banned` };
|
|
25575
|
+
this.logLine(`[firewall] Unbanned ${ip}${opts.forget ? " (strikes cleared)" : ""}`);
|
|
24830
25576
|
this.bus.publish({
|
|
24831
25577
|
timestamp: /* @__PURE__ */ new Date(),
|
|
24832
25578
|
module: "firewall-rules",
|
|
24833
25579
|
category: "system",
|
|
24834
25580
|
severity: "info",
|
|
24835
|
-
message: `
|
|
25581
|
+
message: `Unbanned ${ip}`,
|
|
24836
25582
|
source_ip: ip,
|
|
24837
|
-
details: { action: "unblock" }
|
|
25583
|
+
details: { action: "unblock", forget: opts.forget === true }
|
|
24838
25584
|
});
|
|
24839
|
-
return true;
|
|
25585
|
+
return { ok: true };
|
|
24840
25586
|
}
|
|
24841
|
-
|
|
24842
|
-
|
|
25587
|
+
/** Lifts every ban this module placed. The "undo it all" of R12. */
|
|
25588
|
+
async flush() {
|
|
25589
|
+
const entries = [...this.blocklist];
|
|
25590
|
+
for (const entry of entries) await this.unban(entry.ip);
|
|
25591
|
+
return entries.length;
|
|
25592
|
+
}
|
|
25593
|
+
getBlocklist() {
|
|
25594
|
+
return [...this.blocklist].sort((a, b) => b.blocked_at - a.blocked_at);
|
|
25595
|
+
}
|
|
25596
|
+
getAllowlist() {
|
|
25597
|
+
return [...this.protectedList];
|
|
25598
|
+
}
|
|
25599
|
+
/** Offence count per address, so the dashboard can show why a ban is long. */
|
|
25600
|
+
getStrikes() {
|
|
25601
|
+
return { ...this.strikes };
|
|
25602
|
+
}
|
|
25603
|
+
status() {
|
|
25604
|
+
return {
|
|
25605
|
+
enabled: this.config.enabled,
|
|
25606
|
+
dry_run: this.config.dry_run,
|
|
25607
|
+
backend: this.adapter.name,
|
|
25608
|
+
min_severity: this.config.min_severity,
|
|
25609
|
+
banned: this.blocklist.length,
|
|
25610
|
+
max_ban_seconds: this.config.max_ban_seconds
|
|
25611
|
+
};
|
|
24843
25612
|
}
|
|
24844
25613
|
addToAllowlist(ip) {
|
|
24845
|
-
if (!this.
|
|
24846
|
-
|
|
24847
|
-
}
|
|
25614
|
+
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
25615
|
+
if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
|
|
24848
25616
|
}
|
|
24849
25617
|
removeFromAllowlist(ip) {
|
|
25618
|
+
if (DEFAULT_PROTECTED.includes(ip)) return;
|
|
25619
|
+
this.protectedList = this.protectedList.filter((a) => a !== ip);
|
|
24850
25620
|
this.config.allowlist = this.config.allowlist.filter((a) => a !== ip);
|
|
24851
25621
|
}
|
|
24852
|
-
getBlocklist() {
|
|
24853
|
-
return [...this.blocklist];
|
|
24854
|
-
}
|
|
24855
|
-
getAllowlist() {
|
|
24856
|
-
return [...this.config.allowlist];
|
|
24857
|
-
}
|
|
24858
25622
|
stop() {
|
|
24859
25623
|
if (this.expiryTimer) clearInterval(this.expiryTimer);
|
|
24860
25624
|
this.expiryTimer = null;
|
|
24861
25625
|
}
|
|
25626
|
+
/**
|
|
25627
|
+
* R5: bans survive a restart, their TTLs do not. Anything that expired while
|
|
25628
|
+
* the daemon was down is dropped, and anything still live is re-applied —
|
|
25629
|
+
* the firewall may have been flushed by a reboot underneath us.
|
|
25630
|
+
*/
|
|
25631
|
+
async reconcile() {
|
|
25632
|
+
const now = Date.now();
|
|
25633
|
+
const live = this.blocklist.filter((b) => b.expires_at > now);
|
|
25634
|
+
const stale = this.blocklist.filter((b) => b.expires_at <= now);
|
|
25635
|
+
for (const entry of stale) {
|
|
25636
|
+
if (!entry.dry_run) {
|
|
25637
|
+
try {
|
|
25638
|
+
await this.adapter.unblock(entry.ip);
|
|
25639
|
+
} catch {
|
|
25640
|
+
}
|
|
25641
|
+
}
|
|
25642
|
+
}
|
|
25643
|
+
this.blocklist = live;
|
|
25644
|
+
this.saveState();
|
|
25645
|
+
if (this.config.dry_run) return;
|
|
25646
|
+
let applied = [];
|
|
25647
|
+
try {
|
|
25648
|
+
applied = await this.adapter.listBlocked();
|
|
25649
|
+
} catch {
|
|
25650
|
+
}
|
|
25651
|
+
for (const entry of live) {
|
|
25652
|
+
if (applied.includes(entry.ip)) continue;
|
|
25653
|
+
try {
|
|
25654
|
+
await this.adapter.block(entry.ip);
|
|
25655
|
+
} catch {
|
|
25656
|
+
}
|
|
25657
|
+
}
|
|
25658
|
+
}
|
|
24862
25659
|
startExpiryWorker() {
|
|
24863
|
-
this.expiryTimer = setInterval(() => void this.processExpiries(),
|
|
25660
|
+
this.expiryTimer = setInterval(() => void this.processExpiries(), 1e4);
|
|
25661
|
+
this.expiryTimer.unref?.();
|
|
24864
25662
|
}
|
|
24865
25663
|
async processExpiries() {
|
|
24866
25664
|
const now = Date.now();
|
|
24867
|
-
const
|
|
24868
|
-
|
|
24869
|
-
|
|
25665
|
+
for (const entry of this.blocklist.filter((b) => b.expires_at <= now)) {
|
|
25666
|
+
await this.unban(entry.ip);
|
|
25667
|
+
}
|
|
25668
|
+
const pruned = pruneStrikes(this.strikes, now, this.config.strike_memory_seconds);
|
|
25669
|
+
if (Object.keys(pruned).length !== Object.keys(this.strikes).length) {
|
|
25670
|
+
this.strikes = pruned;
|
|
25671
|
+
this.saveState();
|
|
24870
25672
|
}
|
|
24871
25673
|
}
|
|
24872
25674
|
loadState() {
|
|
24873
25675
|
try {
|
|
24874
25676
|
const saved = getModuleState("firewall-rules", "blocklist");
|
|
24875
|
-
if (Array.isArray(saved))
|
|
25677
|
+
if (Array.isArray(saved)) {
|
|
25678
|
+
this.blocklist = saved.map((entry) => ({
|
|
25679
|
+
...entry,
|
|
25680
|
+
strikes: entry.strikes ?? 1,
|
|
25681
|
+
source: entry.source ?? "auto",
|
|
25682
|
+
expires_at: entry.expires_at ?? entry.blocked_at + this.config.max_ban_seconds * 1e3
|
|
25683
|
+
}));
|
|
25684
|
+
}
|
|
25685
|
+
} catch {
|
|
25686
|
+
}
|
|
25687
|
+
try {
|
|
25688
|
+
const saved = getModuleState("firewall-rules", "strikes");
|
|
25689
|
+
if (saved && typeof saved === "object") this.strikes = saved;
|
|
24876
25690
|
} catch {
|
|
24877
25691
|
}
|
|
24878
25692
|
}
|
|
@@ -24881,16 +25695,42 @@ var RemediationManager = class {
|
|
|
24881
25695
|
setModuleState("firewall-rules", "blocklist", this.blocklist);
|
|
24882
25696
|
} catch {
|
|
24883
25697
|
}
|
|
25698
|
+
try {
|
|
25699
|
+
setModuleState("firewall-rules", "strikes", this.strikes);
|
|
25700
|
+
} catch {
|
|
25701
|
+
}
|
|
24884
25702
|
}
|
|
24885
25703
|
logLine(line) {
|
|
24886
25704
|
try {
|
|
24887
|
-
(0,
|
|
25705
|
+
(0, import_node_fs26.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
24888
25706
|
`);
|
|
24889
25707
|
} catch {
|
|
24890
25708
|
}
|
|
24891
25709
|
}
|
|
24892
25710
|
};
|
|
24893
25711
|
|
|
25712
|
+
// src/daemon/firewall/settings.ts
|
|
25713
|
+
init_backoff();
|
|
25714
|
+
function remediationSettings(section) {
|
|
25715
|
+
if (!section) return {};
|
|
25716
|
+
const settings = {};
|
|
25717
|
+
if (typeof section.enabled === "boolean") settings.enabled = section.enabled;
|
|
25718
|
+
if (section.mode === "dry_run") settings.dry_run = true;
|
|
25719
|
+
else if (section.mode === "enforce") settings.dry_run = false;
|
|
25720
|
+
else if (typeof section.dry_run === "boolean") settings.dry_run = section.dry_run;
|
|
25721
|
+
if (section.min_severity) settings.min_severity = section.min_severity;
|
|
25722
|
+
const maxBan = parseDuration(section.max_ban);
|
|
25723
|
+
if (maxBan) settings.max_ban_seconds = maxBan;
|
|
25724
|
+
const memory = parseDuration(section.strike_memory);
|
|
25725
|
+
if (memory) settings.strike_memory_seconds = memory;
|
|
25726
|
+
const allow = [...section.protected ?? [], ...section.allowlist ?? []];
|
|
25727
|
+
if (allow.length > 0) settings.allowlist = allow;
|
|
25728
|
+
if (typeof section.protect_current_ssh_client === "boolean") {
|
|
25729
|
+
settings.protect_current_ssh_client = section.protect_current_ssh_client;
|
|
25730
|
+
}
|
|
25731
|
+
return settings;
|
|
25732
|
+
}
|
|
25733
|
+
|
|
24894
25734
|
// src/core/telemetry.ts
|
|
24895
25735
|
var ready = false;
|
|
24896
25736
|
var sentry = null;
|
|
@@ -24940,7 +25780,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
24940
25780
|
// src/daemon/index.ts
|
|
24941
25781
|
function readVersion2() {
|
|
24942
25782
|
try {
|
|
24943
|
-
const pkg = JSON.parse((0,
|
|
25783
|
+
const pkg = JSON.parse((0, import_node_fs27.readFileSync)((0, import_node_path19.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
24944
25784
|
return pkg.version || "0.0.0";
|
|
24945
25785
|
} catch {
|
|
24946
25786
|
return "0.0.0";
|
|
@@ -24948,7 +25788,7 @@ function readVersion2() {
|
|
|
24948
25788
|
}
|
|
24949
25789
|
function logLine(line) {
|
|
24950
25790
|
try {
|
|
24951
|
-
(0,
|
|
25791
|
+
(0, import_node_fs27.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
24952
25792
|
`);
|
|
24953
25793
|
} catch {
|
|
24954
25794
|
}
|
|
@@ -24976,7 +25816,7 @@ async function runDaemon() {
|
|
|
24976
25816
|
} catch (err) {
|
|
24977
25817
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
24978
25818
|
}
|
|
24979
|
-
const config = loadConfig((0,
|
|
25819
|
+
const config = loadConfig((0, import_node_fs27.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
24980
25820
|
bus.on("event", (event) => {
|
|
24981
25821
|
logLine(`[event] ${event.severity} ${event.module} ${event.message}`);
|
|
24982
25822
|
});
|
|
@@ -25004,14 +25844,24 @@ async function runDaemon() {
|
|
|
25004
25844
|
});
|
|
25005
25845
|
logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
|
|
25006
25846
|
setInterval(() => ruleEngine.cleanup(), 3e5);
|
|
25007
|
-
const
|
|
25008
|
-
const
|
|
25847
|
+
const settings = remediationSettings(config.remediation);
|
|
25848
|
+
const firewallAdapter = detectFirewallAdapter(config.remediation?.backend ?? "auto");
|
|
25849
|
+
const remediation = new RemediationManager(firewallAdapter, bus, settings);
|
|
25009
25850
|
bus.on("event", (event) => {
|
|
25010
25851
|
if (event.module !== "firewall-rules") {
|
|
25011
25852
|
void remediation.handleDetection(event);
|
|
25012
25853
|
}
|
|
25013
25854
|
});
|
|
25014
|
-
|
|
25855
|
+
const remediationStatus = remediation.status();
|
|
25856
|
+
logLine(
|
|
25857
|
+
`[daemon] auto-defence ${remediationStatus.enabled ? "ON" : "OFF"} (backend=${remediationStatus.backend}, mode=${remediationStatus.dry_run ? "dry_run" : "enforce"}, min_severity=${remediationStatus.min_severity}, bans escalate 1m\u21922m\u21923m\u21925m\u21928m\u2026)`
|
|
25858
|
+
);
|
|
25859
|
+
if (remediationStatus.dry_run && firewallAdapter.enforces !== false) {
|
|
25860
|
+
logLine("[daemon] dry_run is set in [remediation] \u2014 detections will be logged, not blocked");
|
|
25861
|
+
}
|
|
25862
|
+
if (firewallAdapter.enforces === false) {
|
|
25863
|
+
logLine("[daemon] no manageable firewall found (need fail2ban, nftables or iptables) \u2014 bans are simulated");
|
|
25864
|
+
}
|
|
25015
25865
|
new AlertDispatcher(bus, config);
|
|
25016
25866
|
const runsWorker = new RunsWorker(bus);
|
|
25017
25867
|
try {
|
|
@@ -25019,7 +25869,7 @@ async function runDaemon() {
|
|
|
25019
25869
|
} catch (err) {
|
|
25020
25870
|
logLine(`[daemon] runs-worker failed to start: ${err.message}`);
|
|
25021
25871
|
}
|
|
25022
|
-
const ipc = new IpcServer(version, moduleHost);
|
|
25872
|
+
const ipc = new IpcServer(version, moduleHost, remediation);
|
|
25023
25873
|
await ipc.start();
|
|
25024
25874
|
logLine(`[daemon] ipc listening on ${PATHS.socket}`);
|
|
25025
25875
|
const shutdown = async (signal) => {
|
|
@@ -25067,7 +25917,7 @@ async function runDaemon() {
|
|
|
25067
25917
|
// src/commands/daemon.ts
|
|
25068
25918
|
init_paths();
|
|
25069
25919
|
init_ipc_client();
|
|
25070
|
-
var DAEMON_ENTRY = (0,
|
|
25920
|
+
var DAEMON_ENTRY = (0, import_node_path20.join)(__dirname, "daemon.js");
|
|
25071
25921
|
async function daemonForeground() {
|
|
25072
25922
|
await runDaemon();
|
|
25073
25923
|
}
|
|
@@ -25078,7 +25928,7 @@ async function daemonStart() {
|
|
|
25078
25928
|
return;
|
|
25079
25929
|
}
|
|
25080
25930
|
ensureRuntimeDirs();
|
|
25081
|
-
if (!(0,
|
|
25931
|
+
if (!(0, import_node_fs28.existsSync)(DAEMON_ENTRY)) {
|
|
25082
25932
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
25083
25933
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
25084
25934
|
return;
|
|
@@ -25086,8 +25936,8 @@ async function daemonStart() {
|
|
|
25086
25936
|
let out;
|
|
25087
25937
|
let err;
|
|
25088
25938
|
try {
|
|
25089
|
-
out = (0,
|
|
25090
|
-
err = (0,
|
|
25939
|
+
out = (0, import_node_fs29.openSync)(PATHS.logFile, "a");
|
|
25940
|
+
err = (0, import_node_fs29.openSync)(PATHS.logFile, "a");
|
|
25091
25941
|
} catch (e) {
|
|
25092
25942
|
const code = e.code;
|
|
25093
25943
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -25100,7 +25950,7 @@ async function daemonStart() {
|
|
|
25100
25950
|
}
|
|
25101
25951
|
return;
|
|
25102
25952
|
}
|
|
25103
|
-
const child = (0,
|
|
25953
|
+
const child = (0, import_node_child_process8.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
25104
25954
|
detached: true,
|
|
25105
25955
|
stdio: ["ignore", out, err],
|
|
25106
25956
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -25173,39 +26023,39 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
25173
26023
|
}
|
|
25174
26024
|
async function releaseStaleSocket() {
|
|
25175
26025
|
const deadline = Date.now() + 2e3;
|
|
25176
|
-
while ((0,
|
|
26026
|
+
while ((0, import_node_fs28.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
25177
26027
|
await new Promise((r) => setTimeout(r, 50));
|
|
25178
26028
|
}
|
|
25179
|
-
if ((0,
|
|
26029
|
+
if ((0, import_node_fs28.existsSync)(PATHS.socket)) {
|
|
25180
26030
|
try {
|
|
25181
|
-
(0,
|
|
26031
|
+
(0, import_node_fs28.unlinkSync)(PATHS.socket);
|
|
25182
26032
|
} catch {
|
|
25183
26033
|
}
|
|
25184
26034
|
}
|
|
25185
26035
|
}
|
|
25186
26036
|
|
|
25187
26037
|
// src/commands/service.ts
|
|
25188
|
-
var
|
|
25189
|
-
var
|
|
25190
|
-
var
|
|
26038
|
+
var import_node_child_process9 = require("child_process");
|
|
26039
|
+
var import_node_fs30 = require("fs");
|
|
26040
|
+
var import_node_path21 = require("path");
|
|
25191
26041
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
25192
26042
|
function resolveTemplate() {
|
|
25193
|
-
const templatePath = (0,
|
|
25194
|
-
if (!(0,
|
|
26043
|
+
const templatePath = (0, import_node_path21.join)(__dirname, "systemd", "threatcrushd.service");
|
|
26044
|
+
if (!(0, import_node_fs30.existsSync)(templatePath)) {
|
|
25195
26045
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
25196
26046
|
}
|
|
25197
|
-
return (0,
|
|
26047
|
+
return (0, import_node_fs30.readFileSync)(templatePath, "utf-8");
|
|
25198
26048
|
}
|
|
25199
26049
|
function stableBinPath(binPath) {
|
|
25200
26050
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
25201
26051
|
if (stable === binPath) return binPath;
|
|
25202
|
-
return (0,
|
|
26052
|
+
return (0, import_node_fs30.existsSync)(stable) ? stable : binPath;
|
|
25203
26053
|
}
|
|
25204
26054
|
function resolveBinPath() {
|
|
25205
26055
|
const arg = process.argv[1];
|
|
25206
|
-
if (arg && (0,
|
|
26056
|
+
if (arg && (0, import_node_fs30.existsSync)(arg)) return stableBinPath(arg);
|
|
25207
26057
|
try {
|
|
25208
|
-
return (0,
|
|
26058
|
+
return (0, import_node_child_process9.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
25209
26059
|
} catch {
|
|
25210
26060
|
return "threatcrush";
|
|
25211
26061
|
}
|
|
@@ -25224,12 +26074,12 @@ async function installServiceCommand() {
|
|
|
25224
26074
|
return;
|
|
25225
26075
|
}
|
|
25226
26076
|
const unit = resolveTemplate().replace("{{BIN_PATH}}", resolveBinPath());
|
|
25227
|
-
(0,
|
|
26077
|
+
(0, import_node_fs30.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
25228
26078
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
25229
26079
|
ensureSystemDirs();
|
|
25230
26080
|
try {
|
|
25231
|
-
(0,
|
|
25232
|
-
(0,
|
|
26081
|
+
(0, import_node_child_process9.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
26082
|
+
(0, import_node_child_process9.execSync)("systemctl enable threatcrushd.service", { stdio: "inherit" });
|
|
25233
26083
|
console.log(source_default.green(" \u2713 Service enabled on boot."));
|
|
25234
26084
|
console.log(source_default.dim(" Start now with: systemctl start threatcrushd"));
|
|
25235
26085
|
console.log(source_default.dim(" View logs with: journalctl -u threatcrushd -f"));
|
|
@@ -25250,20 +26100,20 @@ function ensureSystemDirs() {
|
|
|
25250
26100
|
];
|
|
25251
26101
|
let admGid = null;
|
|
25252
26102
|
try {
|
|
25253
|
-
admGid = (0,
|
|
26103
|
+
admGid = (0, import_node_fs30.statSync)("/var/log/auth.log").gid;
|
|
25254
26104
|
} catch {
|
|
25255
26105
|
}
|
|
25256
26106
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
25257
26107
|
try {
|
|
25258
|
-
(0,
|
|
26108
|
+
(0, import_node_fs30.mkdirSync)(path, { recursive: true });
|
|
25259
26109
|
} catch {
|
|
25260
26110
|
}
|
|
25261
26111
|
try {
|
|
25262
26112
|
if (groupWritable && admGid !== null) {
|
|
25263
|
-
(0,
|
|
25264
|
-
(0,
|
|
26113
|
+
(0, import_node_fs30.chmodSync)(path, sticky ? 1533 : 509);
|
|
26114
|
+
(0, import_node_child_process9.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
25265
26115
|
} else {
|
|
25266
|
-
(0,
|
|
26116
|
+
(0, import_node_fs30.chmodSync)(path, 493);
|
|
25267
26117
|
}
|
|
25268
26118
|
} catch {
|
|
25269
26119
|
}
|
|
@@ -25281,22 +26131,22 @@ async function uninstallServiceCommand() {
|
|
|
25281
26131
|
return;
|
|
25282
26132
|
}
|
|
25283
26133
|
try {
|
|
25284
|
-
(0,
|
|
26134
|
+
(0, import_node_child_process9.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
25285
26135
|
} catch {
|
|
25286
26136
|
}
|
|
25287
26137
|
try {
|
|
25288
|
-
(0,
|
|
26138
|
+
(0, import_node_child_process9.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
25289
26139
|
} catch {
|
|
25290
26140
|
}
|
|
25291
26141
|
try {
|
|
25292
|
-
if ((0,
|
|
25293
|
-
(0,
|
|
26142
|
+
if ((0, import_node_fs30.existsSync)(UNIT_PATH)) {
|
|
26143
|
+
(0, import_node_child_process9.execSync)(`rm -f ${UNIT_PATH}`);
|
|
25294
26144
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
25295
26145
|
}
|
|
25296
26146
|
} catch {
|
|
25297
26147
|
}
|
|
25298
26148
|
try {
|
|
25299
|
-
(0,
|
|
26149
|
+
(0, import_node_child_process9.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
25300
26150
|
} catch {
|
|
25301
26151
|
}
|
|
25302
26152
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
@@ -25387,8 +26237,8 @@ function welcomeCommand() {
|
|
|
25387
26237
|
}
|
|
25388
26238
|
|
|
25389
26239
|
// src/commands/properties.ts
|
|
25390
|
-
var
|
|
25391
|
-
var
|
|
26240
|
+
var import_node_fs31 = require("fs");
|
|
26241
|
+
var import_node_path22 = require("path");
|
|
25392
26242
|
var import_node_readline6 = __toESM(require("readline"));
|
|
25393
26243
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
25394
26244
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
@@ -25717,8 +26567,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
25717
26567
|
}
|
|
25718
26568
|
}
|
|
25719
26569
|
function parseImportFile(path) {
|
|
25720
|
-
const ext = (0,
|
|
25721
|
-
const raw = (0,
|
|
26570
|
+
const ext = (0, import_node_path22.extname)(path).toLowerCase();
|
|
26571
|
+
const raw = (0, import_node_fs31.readFileSync)(path, "utf-8");
|
|
25722
26572
|
if (ext === ".json") {
|
|
25723
26573
|
const parsed = JSON.parse(raw);
|
|
25724
26574
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -25908,18 +26758,18 @@ async function rulesCommand(opts) {
|
|
|
25908
26758
|
}
|
|
25909
26759
|
|
|
25910
26760
|
// src/commands/harden.ts
|
|
25911
|
-
var
|
|
25912
|
-
var
|
|
26761
|
+
var import_node_fs32 = require("fs");
|
|
26762
|
+
var import_node_child_process10 = require("child_process");
|
|
25913
26763
|
function tryExec(cmd) {
|
|
25914
26764
|
try {
|
|
25915
|
-
return (0,
|
|
26765
|
+
return (0, import_node_child_process10.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
25916
26766
|
} catch {
|
|
25917
26767
|
return null;
|
|
25918
26768
|
}
|
|
25919
26769
|
}
|
|
25920
26770
|
function tryRead(path) {
|
|
25921
26771
|
try {
|
|
25922
|
-
return (0,
|
|
26772
|
+
return (0, import_node_fs32.readFileSync)(path, "utf-8");
|
|
25923
26773
|
} catch {
|
|
25924
26774
|
return null;
|
|
25925
26775
|
}
|
|
@@ -26023,8 +26873,8 @@ function checkSshWeakConfig() {
|
|
|
26023
26873
|
};
|
|
26024
26874
|
}
|
|
26025
26875
|
function checkAutoUpdates() {
|
|
26026
|
-
const unattended = (0,
|
|
26027
|
-
const dnfAuto = (0,
|
|
26876
|
+
const unattended = (0, import_node_fs32.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs32.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
26877
|
+
const dnfAuto = (0, import_node_fs32.existsSync)("/etc/dnf/automatic.conf");
|
|
26028
26878
|
if (unattended || dnfAuto) {
|
|
26029
26879
|
return {
|
|
26030
26880
|
key: "auto-updates",
|
|
@@ -26150,7 +27000,7 @@ function checkFail2ban() {
|
|
|
26150
27000
|
explanation: "fail2ban is installed and running."
|
|
26151
27001
|
};
|
|
26152
27002
|
}
|
|
26153
|
-
if ((0,
|
|
27003
|
+
if ((0, import_node_fs32.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
26154
27004
|
return {
|
|
26155
27005
|
key: checkKey,
|
|
26156
27006
|
status: "warn",
|
|
@@ -26301,79 +27151,131 @@ async function hardenCommand(opts) {
|
|
|
26301
27151
|
}
|
|
26302
27152
|
|
|
26303
27153
|
// src/commands/firewall.ts
|
|
27154
|
+
init_ipc_client();
|
|
27155
|
+
init_paths();
|
|
27156
|
+
init_backoff();
|
|
27157
|
+
async function connect() {
|
|
27158
|
+
if (!IpcClient.isDaemonRunning()) {
|
|
27159
|
+
console.log(source_default.red(` No daemon at ${PATHS.socket}.`));
|
|
27160
|
+
console.log(source_default.gray(" Start it first: threatcrush start"));
|
|
27161
|
+
console.log();
|
|
27162
|
+
return null;
|
|
27163
|
+
}
|
|
27164
|
+
const client = new IpcClient();
|
|
27165
|
+
try {
|
|
27166
|
+
await client.connect();
|
|
27167
|
+
return client;
|
|
27168
|
+
} catch (err) {
|
|
27169
|
+
console.log(source_default.red(` Cannot reach threatcrushd: ${err.message}`));
|
|
27170
|
+
console.log();
|
|
27171
|
+
return null;
|
|
27172
|
+
}
|
|
27173
|
+
}
|
|
26304
27174
|
async function blockCommand(ip, opts) {
|
|
26305
27175
|
banner();
|
|
26306
27176
|
console.log(source_default.green.bold(" Firewall Block"));
|
|
26307
27177
|
console.log(source_default.gray(" " + "\u2500".repeat(50)));
|
|
26308
|
-
|
|
26309
|
-
if (
|
|
26310
|
-
|
|
26311
|
-
|
|
26312
|
-
|
|
26313
|
-
|
|
26314
|
-
|
|
26315
|
-
|
|
26316
|
-
|
|
26317
|
-
}
|
|
26318
|
-
|
|
26319
|
-
|
|
26320
|
-
|
|
26321
|
-
|
|
27178
|
+
const client = await connect();
|
|
27179
|
+
if (!client) return;
|
|
27180
|
+
try {
|
|
27181
|
+
const entry = await client.block(ip, "banned from CLI", opts.ttl);
|
|
27182
|
+
const ttl = formatDuration(Math.round((entry.expires_at - Date.now()) / 1e3));
|
|
27183
|
+
const mode = entry.dry_run ? source_default.yellow(" [DRY-RUN]") : "";
|
|
27184
|
+
console.log(` ${source_default.red("\u2716")} Banned ${source_default.white(ip)} for ${source_default.white(ttl)}${mode}`);
|
|
27185
|
+
console.log(source_default.gray(` Offence #${entry.strikes} \u2014 repeat offences escalate 1m \u2192 2m \u2192 3m \u2192 5m \u2192 8m \u2026`));
|
|
27186
|
+
} catch (err) {
|
|
27187
|
+
console.log(` ${source_default.red("\u2717")} ${err.message}`);
|
|
27188
|
+
} finally {
|
|
27189
|
+
client.close();
|
|
27190
|
+
console.log();
|
|
27191
|
+
}
|
|
26322
27192
|
}
|
|
26323
27193
|
async function unblockCommand(ip) {
|
|
26324
27194
|
banner();
|
|
26325
27195
|
console.log(source_default.green.bold(" Firewall Unblock"));
|
|
26326
27196
|
console.log(source_default.gray(" " + "\u2500".repeat(50)));
|
|
26327
|
-
|
|
26328
|
-
|
|
26329
|
-
|
|
27197
|
+
const client = await connect();
|
|
27198
|
+
if (!client) return;
|
|
27199
|
+
try {
|
|
27200
|
+
await client.unblock(ip);
|
|
27201
|
+
console.log(` ${source_default.green("\u2713")} Unbanned ${source_default.white(ip)} ${source_default.gray("(strike history cleared)")}`);
|
|
27202
|
+
} catch (err) {
|
|
27203
|
+
console.log(` ${source_default.red("\u2717")} ${err.message}`);
|
|
27204
|
+
} finally {
|
|
27205
|
+
client.close();
|
|
27206
|
+
console.log();
|
|
27207
|
+
}
|
|
26330
27208
|
}
|
|
26331
27209
|
async function blocklistCommand() {
|
|
26332
27210
|
banner();
|
|
26333
27211
|
console.log(source_default.green.bold(" Active Blocklist"));
|
|
26334
|
-
console.log(source_default.gray(" " + "\u2500".repeat(
|
|
26335
|
-
|
|
26336
|
-
|
|
27212
|
+
console.log(source_default.gray(" " + "\u2500".repeat(70)));
|
|
27213
|
+
const client = await connect();
|
|
27214
|
+
if (!client) return;
|
|
27215
|
+
let reply;
|
|
27216
|
+
try {
|
|
27217
|
+
reply = await client.blocklist();
|
|
27218
|
+
} catch (err) {
|
|
27219
|
+
console.log(` ${source_default.red("\u2717")} ${err.message}`);
|
|
27220
|
+
client.close();
|
|
27221
|
+
console.log();
|
|
27222
|
+
return;
|
|
27223
|
+
}
|
|
27224
|
+
client.close();
|
|
27225
|
+
const mode = reply.dry_run ? source_default.yellow("dry-run") : source_default.green("enforcing");
|
|
27226
|
+
console.log(` Auto-defence: ${reply.enabled ? mode : source_default.red("disabled")}`);
|
|
27227
|
+
console.log(` Backend: ${source_default.white(reply.backend)}`);
|
|
27228
|
+
console.log(` Bans at: ${source_default.white(reply.min_severity)} severity and above`);
|
|
26337
27229
|
console.log();
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
27230
|
+
if (reply.entries.length === 0) {
|
|
27231
|
+
console.log(source_default.gray(" Nothing is banned."));
|
|
27232
|
+
console.log();
|
|
27233
|
+
return;
|
|
27234
|
+
}
|
|
27235
|
+
const now = Date.now();
|
|
27236
|
+
console.log(
|
|
27237
|
+
source_default.gray(" ") + source_default.gray("IP".padEnd(40)) + source_default.gray("#".padEnd(5)) + source_default.gray("LEFT".padEnd(9)) + source_default.gray("SOURCE")
|
|
27238
|
+
);
|
|
27239
|
+
for (const entry of reply.entries) {
|
|
27240
|
+
const left = formatDuration(Math.round((entry.expires_at - now) / 1e3));
|
|
27241
|
+
console.log(
|
|
27242
|
+
" " + source_default.white(entry.ip.padEnd(40)) + source_default.gray(String(entry.strikes).padEnd(5)) + source_default.yellow(left.padEnd(9)) + source_default.gray(entry.source + (entry.dry_run ? " (dry-run)" : ""))
|
|
27243
|
+
);
|
|
27244
|
+
console.log(source_default.gray(` ${entry.reason}`));
|
|
27245
|
+
}
|
|
26343
27246
|
console.log();
|
|
26344
27247
|
}
|
|
26345
27248
|
async function allowlistCommand(opts) {
|
|
26346
27249
|
banner();
|
|
26347
27250
|
const action = opts.action || "list";
|
|
26348
|
-
console.log(source_default.green.bold(" Allowlist"));
|
|
27251
|
+
console.log(source_default.green.bold(" Allowlist (never banned)"));
|
|
26349
27252
|
console.log(source_default.gray(" " + "\u2500".repeat(50)));
|
|
26350
|
-
|
|
26351
|
-
|
|
26352
|
-
|
|
26353
|
-
|
|
26354
|
-
|
|
26355
|
-
|
|
26356
|
-
|
|
26357
|
-
console.log(source_default.gray(" Add more via /etc/threatcrush/threatcrushd.conf [remediation] allowlist"));
|
|
26358
|
-
break;
|
|
26359
|
-
case "add":
|
|
26360
|
-
if (!opts.value) {
|
|
26361
|
-
console.log(source_default.red(" IP/CIDR required. Usage: threatcrush allowlist add <ip>"));
|
|
26362
|
-
break;
|
|
26363
|
-
}
|
|
26364
|
-
console.log(source_default.green(` Added ${opts.value} to allowlist`));
|
|
26365
|
-
break;
|
|
26366
|
-
case "remove":
|
|
26367
|
-
if (!opts.value) {
|
|
26368
|
-
console.log(source_default.red(" IP/CIDR required. Usage: threatcrush allowlist remove <ip>"));
|
|
26369
|
-
break;
|
|
27253
|
+
if (action === "list" || action === "ls") {
|
|
27254
|
+
const client = await connect();
|
|
27255
|
+
if (!client) return;
|
|
27256
|
+
try {
|
|
27257
|
+
const reply = await client.blocklist();
|
|
27258
|
+
for (const entry of reply.protected) {
|
|
27259
|
+
console.log(` ${source_default.green("\u26CA")} ${source_default.white(entry)}`);
|
|
26370
27260
|
}
|
|
26371
|
-
console.log(
|
|
26372
|
-
|
|
26373
|
-
|
|
26374
|
-
console.log(source_default.
|
|
26375
|
-
|
|
27261
|
+
console.log();
|
|
27262
|
+
console.log(source_default.gray(" Loopback, private ranges, the default gateway and the SSH client"));
|
|
27263
|
+
console.log(source_default.gray(" that started the daemon are always protected. Add more under"));
|
|
27264
|
+
console.log(source_default.gray(` [remediation] protected = [...] in ${PATHS.configFile}`));
|
|
27265
|
+
} catch (err) {
|
|
27266
|
+
console.log(` ${source_default.red("\u2717")} ${err.message}`);
|
|
27267
|
+
} finally {
|
|
27268
|
+
client.close();
|
|
27269
|
+
console.log();
|
|
27270
|
+
}
|
|
27271
|
+
return;
|
|
26376
27272
|
}
|
|
27273
|
+
console.log(source_default.gray(` Edit ${PATHS.configFile}:`));
|
|
27274
|
+
console.log();
|
|
27275
|
+
console.log(source_default.gray(" [remediation]"));
|
|
27276
|
+
console.log(source_default.gray(` protected = ["${opts.value || "203.0.113.7/32"}"]`));
|
|
27277
|
+
console.log();
|
|
27278
|
+
console.log(source_default.gray(" then: threatcrush restart"));
|
|
26377
27279
|
console.log();
|
|
26378
27280
|
}
|
|
26379
27281
|
|
|
@@ -26381,11 +27283,11 @@ async function allowlistCommand(opts) {
|
|
|
26381
27283
|
init_paths();
|
|
26382
27284
|
|
|
26383
27285
|
// src/upgrade.ts
|
|
26384
|
-
var
|
|
27286
|
+
var import_node_child_process11 = require("child_process");
|
|
26385
27287
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
26386
27288
|
var defaultRunner = (cmd) => {
|
|
26387
27289
|
try {
|
|
26388
|
-
return (0,
|
|
27290
|
+
return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
26389
27291
|
} catch {
|
|
26390
27292
|
return null;
|
|
26391
27293
|
}
|
|
@@ -26500,25 +27402,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
26500
27402
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
26501
27403
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
26502
27404
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
26503
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
27405
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
|
|
26504
27406
|
function detectPackageManager() {
|
|
26505
27407
|
try {
|
|
26506
|
-
const npmGlobal = (0,
|
|
27408
|
+
const npmGlobal = (0, import_node_child_process12.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
26507
27409
|
if (npmGlobal.includes(PKG_NAME)) return "npm";
|
|
26508
27410
|
} catch {
|
|
26509
27411
|
}
|
|
26510
27412
|
try {
|
|
26511
|
-
(0,
|
|
27413
|
+
(0, import_node_child_process12.execSync)("pnpm --version", { stdio: "pipe" });
|
|
26512
27414
|
return "pnpm";
|
|
26513
27415
|
} catch {
|
|
26514
27416
|
}
|
|
26515
27417
|
try {
|
|
26516
|
-
(0,
|
|
27418
|
+
(0, import_node_child_process12.execSync)("yarn --version", { stdio: "pipe" });
|
|
26517
27419
|
return "yarn";
|
|
26518
27420
|
} catch {
|
|
26519
27421
|
}
|
|
26520
27422
|
try {
|
|
26521
|
-
(0,
|
|
27423
|
+
(0, import_node_child_process12.execSync)("bun --version", { stdio: "pipe" });
|
|
26522
27424
|
return "bun";
|
|
26523
27425
|
} catch {
|
|
26524
27426
|
}
|
|
@@ -26526,14 +27428,14 @@ function detectPackageManager() {
|
|
|
26526
27428
|
}
|
|
26527
27429
|
function readInstallConfig() {
|
|
26528
27430
|
try {
|
|
26529
|
-
return JSON.parse((0,
|
|
27431
|
+
return JSON.parse((0, import_node_fs33.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
26530
27432
|
} catch {
|
|
26531
27433
|
return {};
|
|
26532
27434
|
}
|
|
26533
27435
|
}
|
|
26534
27436
|
function packageLooksInstalled(pm, pkgName) {
|
|
26535
27437
|
try {
|
|
26536
|
-
const output = (0,
|
|
27438
|
+
const output = (0, import_node_child_process12.execSync)(globalListCommand(pm, pkgName), {
|
|
26537
27439
|
encoding: "utf-8",
|
|
26538
27440
|
stdio: ["pipe", "pipe", "pipe"]
|
|
26539
27441
|
});
|
|
@@ -26604,7 +27506,7 @@ async function refreshDaemonAfterUpgrade() {
|
|
|
26604
27506
|
}
|
|
26605
27507
|
function execQuiet(cmd) {
|
|
26606
27508
|
try {
|
|
26607
|
-
return (0,
|
|
27509
|
+
return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
26608
27510
|
} catch {
|
|
26609
27511
|
return null;
|
|
26610
27512
|
}
|
|
@@ -26752,7 +27654,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
26752
27654
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
26753
27655
|
console.log(LOGO2);
|
|
26754
27656
|
const logPath = PATHS.logFile;
|
|
26755
|
-
if (!(0,
|
|
27657
|
+
if (!(0, import_node_fs33.existsSync)(logPath)) {
|
|
26756
27658
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
26757
27659
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
26758
27660
|
return;
|
|
@@ -26760,7 +27662,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
26760
27662
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
26761
27663
|
`));
|
|
26762
27664
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
26763
|
-
(0,
|
|
27665
|
+
(0, import_node_child_process12.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
26764
27666
|
});
|
|
26765
27667
|
program2.command("activate").description("Activate your license key").action(async () => {
|
|
26766
27668
|
console.log(LOGO2);
|
|
@@ -26807,7 +27709,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
26807
27709
|
for (const cmd of commands2) {
|
|
26808
27710
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
26809
27711
|
`));
|
|
26810
|
-
(0,
|
|
27712
|
+
(0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
|
|
26811
27713
|
}
|
|
26812
27714
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
26813
27715
|
await reportIfStillStale();
|
|
@@ -26832,7 +27734,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
26832
27734
|
for (const cmd of commands) {
|
|
26833
27735
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
26834
27736
|
`));
|
|
26835
|
-
(0,
|
|
27737
|
+
(0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
|
|
26836
27738
|
}
|
|
26837
27739
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
26838
27740
|
if (installMode === "desktop") {
|
|
@@ -26882,7 +27784,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
26882
27784
|
for (const cmd of commands) {
|
|
26883
27785
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
26884
27786
|
`));
|
|
26885
|
-
(0,
|
|
27787
|
+
(0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
|
|
26886
27788
|
}
|
|
26887
27789
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
26888
27790
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -26959,10 +27861,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
26959
27861
|
});
|
|
26960
27862
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
26961
27863
|
console.log(LOGO2);
|
|
26962
|
-
const configPath = (0,
|
|
27864
|
+
const configPath = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
|
|
26963
27865
|
let email = "";
|
|
26964
27866
|
try {
|
|
26965
|
-
const config = JSON.parse((0,
|
|
27867
|
+
const config = JSON.parse((0, import_node_fs33.readFileSync)(configPath, "utf-8"));
|
|
26966
27868
|
email = config.email || "";
|
|
26967
27869
|
} catch {
|
|
26968
27870
|
}
|
|
@@ -26979,9 +27881,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
26979
27881
|
return;
|
|
26980
27882
|
}
|
|
26981
27883
|
try {
|
|
26982
|
-
const dir = (0,
|
|
26983
|
-
if (!(0,
|
|
26984
|
-
(0,
|
|
27884
|
+
const dir = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush");
|
|
27885
|
+
if (!(0, import_node_fs33.existsSync)(dir)) (0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
27886
|
+
(0, import_node_fs33.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
26985
27887
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
26986
27888
|
} catch {
|
|
26987
27889
|
}
|