@profullstack/threatcrush 0.12.7 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10675,9 +10675,15 @@ function initialState(now = Date.now()) {
10675
10675
  threatIndex: 0,
10676
10676
  banIndex: 0,
10677
10677
  notice: null,
10678
- busy: false
10678
+ busy: false,
10679
+ moduleIndex: 0,
10680
+ moduleFilter: null
10679
10681
  };
10680
10682
  }
10683
+ function visibleEvents(state) {
10684
+ if (!state.moduleFilter) return state.events;
10685
+ return state.events.filter((e) => e.module === state.moduleFilter);
10686
+ }
10681
10687
  function isBanned(state, ip) {
10682
10688
  return state.bans.some((b) => b.ip === ip);
10683
10689
  }
@@ -10768,6 +10774,10 @@ function reducer(state, action) {
10768
10774
  return { ...state, focus: next };
10769
10775
  }
10770
10776
  case "select": {
10777
+ if (state.focus === "modules") {
10778
+ const max = Math.max(0, state.modules.length - 1);
10779
+ return { ...state, moduleIndex: Math.min(max, Math.max(0, state.moduleIndex + action.delta)) };
10780
+ }
10771
10781
  if (state.focus === "threats") {
10772
10782
  const max = Math.max(0, state.topSources.length - 1);
10773
10783
  return { ...state, threatIndex: Math.min(max, Math.max(0, state.threatIndex + action.delta)) };
@@ -10779,6 +10789,10 @@ function reducer(state, action) {
10779
10789
  return state;
10780
10790
  }
10781
10791
  case "select_at": {
10792
+ if (state.focus === "modules") {
10793
+ const max2 = Math.max(0, state.modules.length - 1);
10794
+ return { ...state, moduleIndex: Math.min(max2, Math.max(0, action.index)) };
10795
+ }
10782
10796
  if (state.focus === "bans") {
10783
10797
  const max2 = Math.max(0, state.bans.length - 1);
10784
10798
  return { ...state, banIndex: Math.min(max2, Math.max(0, action.index)) };
@@ -10797,6 +10811,14 @@ function reducer(state, action) {
10797
10811
  };
10798
10812
  case "busy":
10799
10813
  return { ...state, busy: action.busy };
10814
+ case "toggle_module_filter": {
10815
+ const name = state.modules[state.moduleIndex]?.name;
10816
+ if (!name) return state;
10817
+ const moduleFilter = state.moduleFilter === name ? null : name;
10818
+ return { ...state, moduleFilter, scrollBack: 0 };
10819
+ }
10820
+ case "clear_module_filter":
10821
+ return { ...state, moduleFilter: null, scrollBack: 0 };
10800
10822
  case "counters":
10801
10823
  return {
10802
10824
  ...state,
@@ -10828,7 +10850,9 @@ function reducer(state, action) {
10828
10850
  bans: state.bans,
10829
10851
  protectedList: state.protectedList,
10830
10852
  firewall: state.firewall,
10831
- focus: state.focus
10853
+ focus: state.focus,
10854
+ moduleFilter: state.moduleFilter,
10855
+ moduleIndex: state.moduleIndex
10832
10856
  };
10833
10857
  }
10834
10858
  }
@@ -10861,7 +10885,7 @@ var FOCUS_ORDER, NOTICE_MS, TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
10861
10885
  var init_state = __esm({
10862
10886
  "src/tui/state.ts"() {
10863
10887
  "use strict";
10864
- FOCUS_ORDER = ["feed", "threats", "bans"];
10888
+ FOCUS_ORDER = ["feed", "modules", "threats", "bans"];
10865
10889
  NOTICE_MS = 6e3;
10866
10890
  TIMELINE_SLOTS = 60;
10867
10891
  FEED_LIMIT = 500;
@@ -11048,14 +11072,17 @@ function tiles(ui, state, theme) {
11048
11072
  });
11049
11073
  });
11050
11074
  }
11051
- function modulesPanel(parent, state, theme) {
11075
+ function modulesPanel(parent, state, theme, options) {
11076
+ const focused = state.focus === "modules";
11052
11077
  parent.panel(
11053
11078
  {
11054
11079
  title: " MODULES ",
11055
11080
  size: "fill",
11056
11081
  border: "rounded",
11057
- borderColor: theme.border,
11082
+ borderColor: focused ? theme.borderFocused : theme.border,
11058
11083
  titleColor: theme.primary,
11084
+ subtitle: focused ? "enter filters feed" : void 0,
11085
+ subtitleColor: theme.muted,
11059
11086
  footer: state.modules.length > 0 ? `${state.modules.filter((m) => m.status === "running").length}/${state.modules.length} active` : void 0,
11060
11087
  padding: [0, 1]
11061
11088
  },
@@ -11067,7 +11094,17 @@ function modulesPanel(parent, state, theme) {
11067
11094
  panel.table({
11068
11095
  rows: state.modules,
11069
11096
  header: false,
11097
+ selected: focused ? state.moduleIndex : -1,
11098
+ followSelection: true,
11099
+ onSelectRow: options.onModuleSelect,
11070
11100
  columns: [
11101
+ {
11102
+ // Marks the module the feed is currently pinned to.
11103
+ key: "name",
11104
+ width: 2,
11105
+ render: (m) => state.moduleFilter === m.name ? "\u25B6" : " ",
11106
+ color: () => theme.primary
11107
+ },
11071
11108
  {
11072
11109
  key: "status",
11073
11110
  width: 2,
@@ -11107,18 +11144,27 @@ function severityPanel(parent, state, theme) {
11107
11144
  }
11108
11145
  function feedPanel(parent, state, theme, options) {
11109
11146
  const following = state.scrollBack === 0;
11147
+ const shown = visibleEvents(state);
11148
+ const filtered = state.moduleFilter !== null;
11110
11149
  parent.panel(
11111
11150
  {
11112
- title: " LIVE EVENTS ",
11151
+ title: filtered ? ` LIVE EVENTS \xB7 ${state.moduleFilter} ` : " LIVE EVENTS ",
11113
11152
  size: "2.4fr",
11114
11153
  border: "rounded",
11115
11154
  borderColor: state.connection === "live" ? theme.borderFocused : theme.border,
11116
11155
  titleColor: theme.primary,
11117
- subtitle: following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
11118
- subtitleColor: severityColors.medium,
11156
+ subtitle: filtered ? `${shown.length}/${state.events.length} \xB7 esc clears filter` : following ? void 0 : `\u2191 ${state.scrollBack} back \xB7 end to follow`,
11157
+ subtitleColor: filtered ? theme.primary : severityColors.medium,
11119
11158
  padding: [0, 1]
11120
11159
  },
11121
11160
  (panel) => {
11161
+ if (filtered && shown.length === 0 && state.events.length > 0) {
11162
+ panel.spacer(1);
11163
+ panel.text(`No events from ${state.moduleFilter} yet.`, { fg: theme.muted, align: "center" });
11164
+ panel.spacer(1);
11165
+ panel.label("esc shows everything again", { fg: theme.muted, align: "center" });
11166
+ return;
11167
+ }
11122
11168
  if (state.events.length === 0) {
11123
11169
  panel.spacer(1);
11124
11170
  if (state.connection === "live") {
@@ -11139,7 +11185,7 @@ function feedPanel(parent, state, theme, options) {
11139
11185
  return;
11140
11186
  }
11141
11187
  panel.log({
11142
- entries: state.events.map(toLogEntry),
11188
+ entries: shown.map(toLogEntry),
11143
11189
  follow: following,
11144
11190
  fromEnd: state.scrollBack,
11145
11191
  scrollbar: true,
@@ -11320,8 +11366,7 @@ function footer(ui, state, theme) {
11320
11366
  { key: "q", label: "quit" },
11321
11367
  { key: "tab", label: state.focus },
11322
11368
  { key: "\u2191\u2193", label: onFeed ? "scroll" : "select" },
11323
- { key: "b", label: "ban" },
11324
- { key: "u", label: "unban" },
11369
+ ...state.focus === "modules" ? [{ key: "\u23CE", label: state.moduleFilter ? "unfilter" : "filter" }] : [{ key: "b", label: "ban" }, { key: "u", label: "unban" }],
11325
11370
  { key: "p", label: state.paused ? "resume" : "pause" },
11326
11371
  { key: "r", label: "reset" }
11327
11372
  ],
@@ -11333,6 +11378,7 @@ function footer(ui, state, theme) {
11333
11378
  label: state.paused && state.parked.length > 0 ? `${state.parked.length} held` : "",
11334
11379
  color: severityColors.medium
11335
11380
  },
11381
+ { label: state.moduleFilter ? `filter: ${state.moduleFilter}` : "", color: theme.primary },
11336
11382
  {
11337
11383
  label: state.firewall ? `${state.bans.length} banned${state.firewall.dry_run ? " (dry-run)" : ""}` : "",
11338
11384
  color: state.firewall?.dry_run ? severityColors.medium : theme.muted
@@ -11349,7 +11395,7 @@ function renderDashboard(ui, state, theme, options = {}) {
11349
11395
  tiles(col, state, theme);
11350
11396
  col.row({ size: "fill", gap: 0 }, (row) => {
11351
11397
  row.column({ size: "1fr" }, (left) => {
11352
- modulesPanel(left, state, theme);
11398
+ modulesPanel(left, state, theme, options);
11353
11399
  severityPanel(left, state, theme);
11354
11400
  });
11355
11401
  feedPanel(row, state, theme, options);
@@ -11566,11 +11612,18 @@ async function startDashboard(options = {}) {
11566
11612
  };
11567
11613
  app.on("key", (event) => {
11568
11614
  switch (event.key) {
11569
- case "q":
11570
11615
  case "escape":
11616
+ if (state.moduleFilter) dispatch({ type: "clear_module_filter" });
11617
+ else quit();
11618
+ break;
11619
+ case "q":
11571
11620
  case "ctrl+c":
11572
11621
  quit();
11573
11622
  break;
11623
+ case "enter":
11624
+ case "return":
11625
+ dispatch({ type: "toggle_module_filter" });
11626
+ break;
11574
11627
  case "p":
11575
11628
  case "space":
11576
11629
  dispatch({ type: "pause" });
@@ -11624,6 +11677,13 @@ async function startDashboard(options = {}) {
11624
11677
  onBanSelect: (row) => {
11625
11678
  dispatch({ type: "focus", focus: "bans" });
11626
11679
  dispatch({ type: "select_at", index: row });
11680
+ },
11681
+ // One click on a module both selects it and pins the feed to it; a
11682
+ // second click on the same module releases the feed.
11683
+ onModuleSelect: (row) => {
11684
+ dispatch({ type: "focus", focus: "modules" });
11685
+ dispatch({ type: "select_at", index: row });
11686
+ dispatch({ type: "toggle_module_filter" });
11627
11687
  }
11628
11688
  });
11629
11689
  });
@@ -15804,7 +15864,7 @@ var source_default = chalk;
15804
15864
 
15805
15865
  // src/index.ts
15806
15866
  var import_readline = __toESM(require("readline"));
15807
- var import_node_child_process12 = require("child_process");
15867
+ var import_node_child_process13 = require("child_process");
15808
15868
  var import_node_fs33 = require("fs");
15809
15869
  var import_node_path23 = require("path");
15810
15870
  var import_node_os8 = require("os");
@@ -18032,7 +18092,8 @@ var CODE_RULES = [
18032
18092
  severity: "high",
18033
18093
  languages: ["python"],
18034
18094
  pattern: /\brequests\.(?:get|request|head)\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\burlopen\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\bhttpx\.get\s*\(\s*[a-zA-Z_]\w*\s*[,)]/,
18035
- needsContext: true
18095
+ needsContext: true,
18096
+ constantRequestHostGuard: true
18036
18097
  },
18037
18098
  {
18038
18099
  id: "go-ssrf-outbound-request",
@@ -18947,6 +19008,21 @@ function identifierAfter(text, start) {
18947
19008
  while (isIdentifierPart(text[index])) index += 1;
18948
19009
  return text.slice(from, index);
18949
19010
  }
19011
+ function urlAuthority(text) {
19012
+ const found = /['"]\s*https?:\/\/([^'"/?#\s]*)/.exec(text);
19013
+ return found ? found[1] : null;
19014
+ }
19015
+ function requestHostIsConstant(line, fileText) {
19016
+ const call = /(?:urlopen|requests\.(?:get|request|head)|httpx\.get)\s*\(\s*([A-Za-z_]\w*)\s*[,)]/.exec(line);
19017
+ if (!call) return false;
19018
+ const assignment = new RegExp(String.raw`^[ \t]*${call[1]}[ \t]*=[ \t]*(.+)$`, "gm");
19019
+ const values = [...fileText.matchAll(assignment)].map((m) => m[1]);
19020
+ if (!values.length) return false;
19021
+ return values.every((value) => {
19022
+ const authority = urlAuthority(value);
19023
+ return authority !== null && /^[A-Za-z0-9.-]+(?::\d+)?$/.test(authority);
19024
+ });
19025
+ }
18950
19026
  function hasSafeRedirectValue(line, fileText) {
18951
19027
  const location = line.indexOf("window.location");
18952
19028
  const redirect = line.indexOf(".redirect");
@@ -19056,6 +19132,9 @@ function evaluateRule(rule, ctx) {
19056
19132
  if (rule.safeRedirectGuard && hasSafeRedirectValue(line, fileTextOf(ctx.lines))) {
19057
19133
  return null;
19058
19134
  }
19135
+ if (rule.constantRequestHostGuard && requestHostIsConstant(line, fileTextOf(ctx.lines))) {
19136
+ return null;
19137
+ }
19059
19138
  if (rule.filledBeforeUseGuard && bufferFilledBeforeUse(ctx)) return null;
19060
19139
  const guard = rule.guard === void 0 ? GENERIC_GUARD : rule.guard;
19061
19140
  if (guard && (guard.test(line) || guard.test(context))) return null;
@@ -23086,7 +23165,7 @@ async function sshConnect(options) {
23086
23165
  }
23087
23166
 
23088
23167
  // src/commands/daemon.ts
23089
- var import_node_child_process8 = require("child_process");
23168
+ var import_node_child_process9 = require("child_process");
23090
23169
  var import_node_fs28 = require("fs");
23091
23170
  var import_node_path20 = require("path");
23092
23171
  var import_node_fs29 = require("fs");
@@ -23832,6 +23911,7 @@ var NetworkMonitor = class {
23832
23911
 
23833
23912
  // src/modules/dns-monitor/index.ts
23834
23913
  var import_node_fs22 = require("fs");
23914
+ var import_node_child_process6 = require("child_process");
23835
23915
  var import_node_readline5 = require("readline");
23836
23916
  var DNS_LOG_SOURCES = [
23837
23917
  "/var/log/syslog",
@@ -23843,10 +23923,30 @@ var DNS_LOG_SOURCES = [
23843
23923
  "/var/log/pihole.log"
23844
23924
  // Pi-hole
23845
23925
  ];
23926
+ function qtypeName(qtype) {
23927
+ const names = {
23928
+ 1: "A",
23929
+ 2: "NS",
23930
+ 5: "CNAME",
23931
+ 6: "SOA",
23932
+ 12: "PTR",
23933
+ 15: "MX",
23934
+ 16: "TXT",
23935
+ 28: "AAAA",
23936
+ 33: "SRV",
23937
+ 35: "NAPTR",
23938
+ 43: "DS",
23939
+ 48: "DNSKEY",
23940
+ 65: "HTTPS",
23941
+ 255: "ANY"
23942
+ };
23943
+ return names[qtype] ?? `TYPE${qtype}`;
23944
+ }
23846
23945
  var DnsMonitor = class {
23847
- // Shannon entropy threshold for DGA
23848
- constructor(bus2) {
23946
+ constructor(bus2, options = {}) {
23849
23947
  this.bus = bus2;
23948
+ this.extraPaths = options.log_paths ?? [];
23949
+ this.journalUnits = options.journal_units ?? [];
23850
23950
  }
23851
23951
  bus;
23852
23952
  active = false;
@@ -23863,8 +23963,13 @@ var DnsMonitor = class {
23863
23963
  // unique high-entropy domains per window
23864
23964
  dgaWindowMs = 6e4;
23865
23965
  entropyThreshold = 3.5;
23966
+ // Shannon entropy threshold for DGA
23967
+ /** Extra files and journal units from `[modules.dns-monitor]` in the config. */
23968
+ extraPaths = [];
23969
+ journalUnits = [];
23970
+ journalTails = [];
23866
23971
  start() {
23867
- const sources = DNS_LOG_SOURCES.filter((p) => {
23972
+ const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
23868
23973
  if (!(0, import_node_fs22.existsSync)(p)) return false;
23869
23974
  try {
23870
23975
  (0, import_node_fs22.accessSync)(p, import_node_fs22.constants.R_OK);
@@ -23873,7 +23978,8 @@ var DnsMonitor = class {
23873
23978
  return false;
23874
23979
  }
23875
23980
  });
23876
- if (sources.length === 0) return false;
23981
+ for (const unit of this.journalUnits) this.tailJournalUnit(unit);
23982
+ if (sources.length === 0 && this.journalTails.length === 0) return false;
23877
23983
  this.active = true;
23878
23984
  for (const src of sources) {
23879
23985
  this.tailLog(src);
@@ -23884,8 +23990,30 @@ var DnsMonitor = class {
23884
23990
  stop() {
23885
23991
  for (const t of this.timers.values()) clearInterval(t);
23886
23992
  this.timers.clear();
23993
+ for (const child of this.journalTails) {
23994
+ try {
23995
+ child.kill("SIGTERM");
23996
+ } catch {
23997
+ }
23998
+ }
23999
+ this.journalTails = [];
23887
24000
  this.active = false;
23888
24001
  }
24002
+ /** Follow one systemd unit's journal, feeding its lines to the same parser. */
24003
+ tailJournalUnit(unit) {
24004
+ try {
24005
+ const child = (0, import_node_child_process6.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
24006
+ stdio: ["ignore", "pipe", "ignore"]
24007
+ });
24008
+ if (!child.stdout) return;
24009
+ const rl = (0, import_node_readline5.createInterface)({ input: child.stdout });
24010
+ rl.on("line", (line) => this.parseDnsLine(line));
24011
+ child.on("error", () => {
24012
+ });
24013
+ this.journalTails.push(child);
24014
+ } catch {
24015
+ }
24016
+ }
23889
24017
  isActive() {
23890
24018
  return this.active;
23891
24019
  }
@@ -23918,6 +24046,18 @@ var DnsMonitor = class {
23918
24046
  rl.on("close", () => this.positions.set(path, stat.size));
23919
24047
  }
23920
24048
  parseDnsLine(line) {
24049
+ const moshpit = line.match(
24050
+ /\[dns\]\s+(?:udp|tcp|doh)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w+)/i
24051
+ );
24052
+ if (moshpit) {
24053
+ this.domainBuffer.push({
24054
+ type: qtypeName(Number.parseInt(moshpit[3], 10)),
24055
+ domain: moshpit[2],
24056
+ source_ip: moshpit[1],
24057
+ timestamp: Date.now()
24058
+ });
24059
+ return;
24060
+ }
23921
24061
  const resolvedMatch = line.match(/query\[(\w+)\]\s+(\S+)\s+from\s+(\S+)/i);
23922
24062
  if (resolvedMatch) {
23923
24063
  this.domainBuffer.push({
@@ -24093,7 +24233,11 @@ var ModuleHost = class {
24093
24233
  this.bus.announceModule("network-monitor", "running", nmod.detail);
24094
24234
  }
24095
24235
  }
24096
- this.dnsMonitor = new DnsMonitor(this.bus);
24236
+ const dnsConfig = loadModuleConfigs(PATHS.confD).get("dns-monitor") ?? {};
24237
+ this.dnsMonitor = new DnsMonitor(this.bus, {
24238
+ log_paths: Array.isArray(dnsConfig.log_paths) ? dnsConfig.log_paths : void 0,
24239
+ journal_units: Array.isArray(dnsConfig.journal_units) ? dnsConfig.journal_units : void 0
24240
+ });
24097
24241
  if (this.dnsMonitor.start()) {
24098
24242
  const dmod = this.modules.get("dns-monitor");
24099
24243
  if (dmod) {
@@ -25068,7 +25212,7 @@ function loadAllRules(customDir) {
25068
25212
  }
25069
25213
 
25070
25214
  // src/daemon/firewall/adapters.ts
25071
- var import_node_child_process6 = require("child_process");
25215
+ var import_node_child_process7 = require("child_process");
25072
25216
  var import_node_fs25 = require("fs");
25073
25217
  var import_node_path18 = require("path");
25074
25218
  var import_node_net3 = require("net");
@@ -25104,11 +25248,11 @@ var Fail2banAdapter = class {
25104
25248
  enforces = true;
25105
25249
  jailReady = false;
25106
25250
  isAvailable() {
25107
- const result = (0, import_node_child_process6.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
25251
+ const result = (0, import_node_child_process7.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
25108
25252
  return result.status === 0;
25109
25253
  }
25110
25254
  client(args) {
25111
- return (0, import_node_child_process6.execFileSync)("fail2ban-client", args, {
25255
+ return (0, import_node_child_process7.execFileSync)("fail2ban-client", args, {
25112
25256
  encoding: "utf-8",
25113
25257
  stdio: ["ignore", "pipe", "pipe"]
25114
25258
  });
@@ -25200,35 +25344,35 @@ var NftablesAdapter = class {
25200
25344
  table = "threatcrush";
25201
25345
  set = "blocklist";
25202
25346
  isAvailable() {
25203
- const result = (0, import_node_child_process6.spawnSync)("nft", ["--version"], { stdio: "pipe" });
25347
+ const result = (0, import_node_child_process7.spawnSync)("nft", ["--version"], { stdio: "pipe" });
25204
25348
  return result.status === 0;
25205
25349
  }
25206
25350
  ensureSetup() {
25207
25351
  try {
25208
- (0, import_node_child_process6.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
25352
+ (0, import_node_child_process7.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
25209
25353
  } catch {
25210
- (0, import_node_child_process6.execSync)(`nft add table inet ${this.table}`);
25211
- (0, import_node_child_process6.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
25212
- (0, import_node_child_process6.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
25213
- (0, import_node_child_process6.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
25354
+ (0, import_node_child_process7.execSync)(`nft add table inet ${this.table}`);
25355
+ (0, import_node_child_process7.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
25356
+ (0, import_node_child_process7.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
25357
+ (0, import_node_child_process7.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
25214
25358
  }
25215
25359
  }
25216
25360
  async block(ip) {
25217
25361
  assertValidFirewallIp(ip);
25218
25362
  this.ensureSetup();
25219
- (0, import_node_child_process6.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
25363
+ (0, import_node_child_process7.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
25220
25364
  }
25221
25365
  async unblock(ip) {
25222
25366
  assertValidFirewallIp(ip);
25223
25367
  try {
25224
- (0, import_node_child_process6.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
25368
+ (0, import_node_child_process7.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
25225
25369
  } catch {
25226
25370
  }
25227
25371
  }
25228
25372
  async isBlocked(ip) {
25229
25373
  assertValidFirewallIp(ip);
25230
25374
  try {
25231
- const output = (0, import_node_child_process6.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
25375
+ const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
25232
25376
  return output.includes(ip);
25233
25377
  } catch {
25234
25378
  return false;
@@ -25236,7 +25380,7 @@ var NftablesAdapter = class {
25236
25380
  }
25237
25381
  async listBlocked() {
25238
25382
  try {
25239
- const output = (0, import_node_child_process6.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
25383
+ const output = (0, import_node_child_process7.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
25240
25384
  const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
25241
25385
  if (!match) return [];
25242
25386
  return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
@@ -25249,34 +25393,34 @@ var IptablesAdapter = class {
25249
25393
  name = "iptables";
25250
25394
  chain = "THREATCRUSH";
25251
25395
  isAvailable() {
25252
- const result = (0, import_node_child_process6.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
25396
+ const result = (0, import_node_child_process7.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
25253
25397
  return result.status === 0;
25254
25398
  }
25255
25399
  ensureChain() {
25256
25400
  try {
25257
- (0, import_node_child_process6.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
25401
+ (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
25258
25402
  } catch {
25259
- (0, import_node_child_process6.execSync)(`iptables -N ${this.chain}`);
25260
- (0, import_node_child_process6.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
25403
+ (0, import_node_child_process7.execSync)(`iptables -N ${this.chain}`);
25404
+ (0, import_node_child_process7.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
25261
25405
  }
25262
25406
  }
25263
25407
  async block(ip) {
25264
25408
  assertValidFirewallIp(ip);
25265
25409
  this.ensureChain();
25266
25410
  if (await this.isBlocked(ip)) return;
25267
- (0, import_node_child_process6.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
25411
+ (0, import_node_child_process7.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
25268
25412
  }
25269
25413
  async unblock(ip) {
25270
25414
  assertValidFirewallIp(ip);
25271
25415
  try {
25272
- (0, import_node_child_process6.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
25416
+ (0, import_node_child_process7.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
25273
25417
  } catch {
25274
25418
  }
25275
25419
  }
25276
25420
  async isBlocked(ip) {
25277
25421
  assertValidFirewallIp(ip);
25278
25422
  try {
25279
- const output = (0, import_node_child_process6.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
25423
+ const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
25280
25424
  return output.includes(ip);
25281
25425
  } catch {
25282
25426
  return false;
@@ -25284,7 +25428,7 @@ var IptablesAdapter = class {
25284
25428
  }
25285
25429
  async listBlocked() {
25286
25430
  try {
25287
- const output = (0, import_node_child_process6.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
25431
+ const output = (0, import_node_child_process7.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
25288
25432
  const ips = [];
25289
25433
  for (const line of output.split("\n")) {
25290
25434
  const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
@@ -25346,7 +25490,7 @@ init_paths();
25346
25490
  init_backoff();
25347
25491
 
25348
25492
  // src/daemon/firewall/protected.ts
25349
- var import_node_child_process7 = require("child_process");
25493
+ var import_node_child_process8 = require("child_process");
25350
25494
  var import_node_net4 = require("net");
25351
25495
  var DEFAULT_PROTECTED = [
25352
25496
  "127.0.0.0/8",
@@ -25442,7 +25586,7 @@ function currentSshClient(env2 = process.env) {
25442
25586
  function establishedSshPeers() {
25443
25587
  const peers = /* @__PURE__ */ new Set();
25444
25588
  try {
25445
- const out = (0, import_node_child_process7.execFileSync)("ss", ["-tnpH"], {
25589
+ const out = (0, import_node_child_process8.execFileSync)("ss", ["-tnpH"], {
25446
25590
  encoding: "utf-8",
25447
25591
  stdio: ["ignore", "pipe", "ignore"],
25448
25592
  timeout: 3e3
@@ -25463,7 +25607,7 @@ function defaultGateways() {
25463
25607
  const found = /* @__PURE__ */ new Set();
25464
25608
  for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
25465
25609
  try {
25466
- const out = (0, import_node_child_process7.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
25610
+ const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
25467
25611
  for (const line of out.split("\n")) {
25468
25612
  const match = line.match(/\bvia\s+(\S+)/);
25469
25613
  if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
@@ -26068,7 +26212,7 @@ async function daemonStart() {
26068
26212
  }
26069
26213
  return;
26070
26214
  }
26071
- const child = (0, import_node_child_process8.spawn)(process.execPath, [DAEMON_ENTRY], {
26215
+ const child = (0, import_node_child_process9.spawn)(process.execPath, [DAEMON_ENTRY], {
26072
26216
  detached: true,
26073
26217
  stdio: ["ignore", out, err],
26074
26218
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -26153,7 +26297,7 @@ async function releaseStaleSocket() {
26153
26297
  }
26154
26298
 
26155
26299
  // src/commands/service.ts
26156
- var import_node_child_process9 = require("child_process");
26300
+ var import_node_child_process10 = require("child_process");
26157
26301
  var import_node_fs30 = require("fs");
26158
26302
  var import_node_path21 = require("path");
26159
26303
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
@@ -26174,7 +26318,7 @@ function resolveBinPath() {
26174
26318
  const arg = process.argv[1];
26175
26319
  if (arg && (0, import_node_fs30.existsSync)(arg)) return stableBinPath(arg);
26176
26320
  try {
26177
- return (0, import_node_child_process9.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
26321
+ return (0, import_node_child_process10.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
26178
26322
  } catch {
26179
26323
  return "threatcrush";
26180
26324
  }
@@ -26199,18 +26343,18 @@ function isRoot3() {
26199
26343
  return typeof process.getuid === "function" && process.getuid() === 0;
26200
26344
  }
26201
26345
  function reexecWithSudo(args) {
26202
- if ((0, import_node_child_process9.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
26346
+ if ((0, import_node_child_process10.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
26203
26347
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
26204
26348
  const bin = resolveBinPath();
26205
26349
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
26206
- const result = (0, import_node_child_process9.spawnSync)("sudo", argv, { stdio: "inherit" });
26350
+ const result = (0, import_node_child_process10.spawnSync)("sudo", argv, { stdio: "inherit" });
26207
26351
  return result.status === 0;
26208
26352
  }
26209
26353
  function callerHome() {
26210
26354
  const user = process.env.SUDO_USER;
26211
26355
  if (!user) return null;
26212
26356
  try {
26213
- const line = (0, import_node_child_process9.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
26357
+ const line = (0, import_node_child_process10.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
26214
26358
  const home = line.split(":")[5];
26215
26359
  return home && (0, import_node_fs30.existsSync)(home) ? home : null;
26216
26360
  } catch {
@@ -26245,7 +26389,7 @@ function stopUserModeDaemon() {
26245
26389
  }
26246
26390
  }
26247
26391
  function unitIsActive() {
26248
- const result = (0, import_node_child_process9.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
26392
+ const result = (0, import_node_child_process10.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
26249
26393
  return result.status === 0;
26250
26394
  }
26251
26395
  async function installServiceCommand() {
@@ -26273,8 +26417,8 @@ async function installServiceCommand() {
26273
26417
  ensureSystemDirs();
26274
26418
  stopUserModeDaemon();
26275
26419
  try {
26276
- (0, import_node_child_process9.execSync)("systemctl daemon-reload", { stdio: "inherit" });
26277
- (0, import_node_child_process9.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
26420
+ (0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
26421
+ (0, import_node_child_process10.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
26278
26422
  } catch (err) {
26279
26423
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
26280
26424
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -26314,7 +26458,7 @@ function ensureSystemDirs() {
26314
26458
  try {
26315
26459
  if (groupWritable && admGid !== null) {
26316
26460
  (0, import_node_fs30.chmodSync)(path, sticky ? 1533 : 509);
26317
- (0, import_node_child_process9.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
26461
+ (0, import_node_child_process10.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
26318
26462
  } else {
26319
26463
  (0, import_node_fs30.chmodSync)(path, 493);
26320
26464
  }
@@ -26336,22 +26480,22 @@ async function uninstallServiceCommand() {
26336
26480
  return;
26337
26481
  }
26338
26482
  try {
26339
- (0, import_node_child_process9.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
26483
+ (0, import_node_child_process10.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
26340
26484
  } catch {
26341
26485
  }
26342
26486
  try {
26343
- (0, import_node_child_process9.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
26487
+ (0, import_node_child_process10.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
26344
26488
  } catch {
26345
26489
  }
26346
26490
  try {
26347
26491
  if ((0, import_node_fs30.existsSync)(UNIT_PATH)) {
26348
- (0, import_node_child_process9.execSync)(`rm -f ${UNIT_PATH}`);
26492
+ (0, import_node_child_process10.execSync)(`rm -f ${UNIT_PATH}`);
26349
26493
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
26350
26494
  }
26351
26495
  } catch {
26352
26496
  }
26353
26497
  try {
26354
- (0, import_node_child_process9.execSync)("systemctl daemon-reload", { stdio: "inherit" });
26498
+ (0, import_node_child_process10.execSync)("systemctl daemon-reload", { stdio: "inherit" });
26355
26499
  } catch {
26356
26500
  }
26357
26501
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
@@ -26964,10 +27108,10 @@ async function rulesCommand(opts) {
26964
27108
 
26965
27109
  // src/commands/harden.ts
26966
27110
  var import_node_fs32 = require("fs");
26967
- var import_node_child_process10 = require("child_process");
27111
+ var import_node_child_process11 = require("child_process");
26968
27112
  function tryExec(cmd) {
26969
27113
  try {
26970
- return (0, import_node_child_process10.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
27114
+ return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
26971
27115
  } catch {
26972
27116
  return null;
26973
27117
  }
@@ -27499,11 +27643,11 @@ async function allowlistCommand(opts) {
27499
27643
  init_paths();
27500
27644
 
27501
27645
  // src/upgrade.ts
27502
- var import_node_child_process11 = require("child_process");
27646
+ var import_node_child_process12 = require("child_process");
27503
27647
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
27504
27648
  var defaultRunner = (cmd) => {
27505
27649
  try {
27506
- return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
27650
+ return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
27507
27651
  } catch {
27508
27652
  return null;
27509
27653
  }
@@ -27621,22 +27765,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
27621
27765
  var INSTALL_CONFIG_PATH = (0, import_node_path23.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
27622
27766
  function detectPackageManager() {
27623
27767
  try {
27624
- const npmGlobal = (0, import_node_child_process12.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
27768
+ const npmGlobal = (0, import_node_child_process13.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
27625
27769
  if (npmGlobal.includes(PKG_NAME)) return "npm";
27626
27770
  } catch {
27627
27771
  }
27628
27772
  try {
27629
- (0, import_node_child_process12.execSync)("pnpm --version", { stdio: "pipe" });
27773
+ (0, import_node_child_process13.execSync)("pnpm --version", { stdio: "pipe" });
27630
27774
  return "pnpm";
27631
27775
  } catch {
27632
27776
  }
27633
27777
  try {
27634
- (0, import_node_child_process12.execSync)("yarn --version", { stdio: "pipe" });
27778
+ (0, import_node_child_process13.execSync)("yarn --version", { stdio: "pipe" });
27635
27779
  return "yarn";
27636
27780
  } catch {
27637
27781
  }
27638
27782
  try {
27639
- (0, import_node_child_process12.execSync)("bun --version", { stdio: "pipe" });
27783
+ (0, import_node_child_process13.execSync)("bun --version", { stdio: "pipe" });
27640
27784
  return "bun";
27641
27785
  } catch {
27642
27786
  }
@@ -27651,7 +27795,7 @@ function readInstallConfig() {
27651
27795
  }
27652
27796
  function packageLooksInstalled(pm, pkgName) {
27653
27797
  try {
27654
- const output = (0, import_node_child_process12.execSync)(globalListCommand(pm, pkgName), {
27798
+ const output = (0, import_node_child_process13.execSync)(globalListCommand(pm, pkgName), {
27655
27799
  encoding: "utf-8",
27656
27800
  stdio: ["pipe", "pipe", "pipe"]
27657
27801
  });
@@ -27754,14 +27898,14 @@ async function promoteUnprivilegedDaemon() {
27754
27898
  function restartSystemdDaemon() {
27755
27899
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
27756
27900
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
27757
- if (!asRoot && (0, import_node_child_process12.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
27901
+ if (!asRoot && (0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
27758
27902
  const [cmd, ...args] = argv;
27759
- if ((0, import_node_child_process12.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
27760
- return (0, import_node_child_process12.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
27903
+ if ((0, import_node_child_process13.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
27904
+ return (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
27761
27905
  }
27762
27906
  function execQuiet(cmd) {
27763
27907
  try {
27764
- return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
27908
+ return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
27765
27909
  } catch {
27766
27910
  return null;
27767
27911
  }
@@ -27917,7 +28061,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
27917
28061
  console.log(source_default.green(` Tailing ${logPath}...
27918
28062
  `));
27919
28063
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
27920
- (0, import_node_child_process12.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
28064
+ (0, import_node_child_process13.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
27921
28065
  });
27922
28066
  program2.command("activate").description("Activate your license key").action(async () => {
27923
28067
  console.log(LOGO2);
@@ -27964,7 +28108,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
27964
28108
  for (const cmd of commands2) {
27965
28109
  console.log(source_default.green(` \u2192 ${cmd}
27966
28110
  `));
27967
- (0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
28111
+ (0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
27968
28112
  }
27969
28113
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
27970
28114
  await reportIfStillStale();
@@ -27989,7 +28133,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
27989
28133
  for (const cmd of commands) {
27990
28134
  console.log(source_default.green(` \u2192 ${cmd}
27991
28135
  `));
27992
- (0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
28136
+ (0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
27993
28137
  }
27994
28138
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
27995
28139
  if (installMode === "desktop") {
@@ -28040,7 +28184,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
28040
28184
  for (const cmd of commands) {
28041
28185
  console.log(source_default.green(` \u2192 ${cmd}
28042
28186
  `));
28043
- (0, import_node_child_process12.execSync)(cmd, { stdio: "inherit" });
28187
+ (0, import_node_child_process13.execSync)(cmd, { stdio: "inherit" });
28044
28188
  }
28045
28189
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
28046
28190
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));