@profullstack/threatcrush 0.17.0 → 0.18.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
@@ -59988,8 +59988,8 @@ function parseListeningPorts(text) {
59988
59988
  const ports = /* @__PURE__ */ new Set();
59989
59989
  for (const line2 of text.split("\n")) {
59990
59990
  const cols = line2.trim().split(/\s+/);
59991
- const local = cols.length >= 4 ? splitAddr(cols[3]) : null;
59992
- if (local) ports.add(local.port);
59991
+ const m = cols.length >= 4 ? /:(\d+)$/.exec(cols[3]) : null;
59992
+ if (m) ports.add(Number(m[1]));
59993
59993
  }
59994
59994
  return ports;
59995
59995
  }
@@ -60129,45 +60129,120 @@ var ThreatFeeds = class {
60129
60129
  }
60130
60130
  this.blocking = false;
60131
60131
  }
60132
- /** Outbound connections to listed IPs, one alert per IP and process per hour. */
60132
+ /**
60133
+ * Listed IPs among the open sockets, one alert per IP and process per hour.
60134
+ * A socket on one of our listening ports is the listed host connecting in;
60135
+ * any other is this box calling out. This is a 15 s snapshot of the host's
60136
+ * own network namespace: a short connection, or one made inside a container,
60137
+ * is only seen by the `[edr]` eBPF source, which reports through
60138
+ * `observeOutbound`.
60139
+ */
60133
60140
  pollConnections() {
60134
60141
  if (!this.set || Object.keys(this.set.ips).length === 0) return;
60135
60142
  const conns = this.run("ss", ["-tnpH"]);
60136
60143
  if (conns === null) return;
60137
60144
  const listening = parseListeningPorts(this.run("ss", ["-ltnH"]) ?? "");
60138
- const now = this.now();
60139
60145
  for (const c of parseSs2(conns)) {
60140
- if (listening.has(c.localPort)) continue;
60141
- const ind = matchIp(c.peerIp, this.set);
60142
- if (!ind) continue;
60143
- const key = `${c.peerIp}|${c.process ?? "?"}`;
60144
- if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) continue;
60145
- this.alerted.set(key, now);
60146
- const who = c.process ? `${c.process} (pid ${c.pid})` : "an unknown process";
60147
- const blocked = this.blocking ? " \u2014 blocked" : "";
60148
- this.opts.bus.publish({
60149
- timestamp: new Date(now),
60150
- module: "threat-feeds",
60151
- category: "network",
60152
- severity: "critical",
60153
- message: `Outbound connection to known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp}:${c.peerPort} by ${who}${blocked}`,
60154
- // No source_ip on purpose: the remote end is not an attacker to ban
60155
- // inbound, so remediation has nothing to act on and the egress table
60156
- // stays the only enforcement.
60157
- details: {
60158
- rule_id: "threat-feed-outbound",
60159
- destination_ip: c.peerIp,
60160
- destination_port: c.peerPort,
60161
- state: c.state,
60162
- process: c.process,
60163
- pid: c.pid,
60164
- malware: ind.malware,
60165
- threat: ind.threat,
60166
- feed: ind.feed,
60167
- blocked: this.blocking
60168
- }
60169
- });
60146
+ if (listening.has(c.localPort)) this.reportInbound(c);
60147
+ else this.reportOutbound({ ...c, seenBy: "ss" });
60148
+ }
60149
+ this.forgetOldAlerts();
60150
+ }
60151
+ /**
60152
+ * One outbound connect traced by the `[edr]` eBPF source: every namespace,
60153
+ * however short-lived, with the process that made it. The address is looked
60154
+ * up and dropped unless it is listed. Returns whether an event was raised.
60155
+ */
60156
+ observeOutbound(conn) {
60157
+ if (!this.set || !matchIp(conn.peerIp, this.set)) return false;
60158
+ let executable = null;
60159
+ try {
60160
+ executable = conn.resolveExecutable?.() ?? null;
60161
+ } catch {
60170
60162
  }
60163
+ const process11 = executable ? executable.slice(executable.lastIndexOf("/") + 1) : conn.comm;
60164
+ return this.reportOutbound({
60165
+ state: "SYN-SENT",
60166
+ localPort: 0,
60167
+ peerIp: conn.peerIp,
60168
+ peerPort: conn.peerPort,
60169
+ process: process11 || conn.comm || null,
60170
+ pid: conn.pid,
60171
+ executable,
60172
+ seenBy: "ebpf"
60173
+ });
60174
+ }
60175
+ reportOutbound(c) {
60176
+ const ind = matchIp(c.peerIp, this.set);
60177
+ if (!ind) return false;
60178
+ const now = this.now();
60179
+ const key = `${c.peerIp}|${c.process ?? "?"}`;
60180
+ if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) return false;
60181
+ this.alerted.set(key, now);
60182
+ const who = c.process ? `${c.process} (pid ${c.pid})` : "an unknown process";
60183
+ const blocked = this.blocking ? " \u2014 blocked" : "";
60184
+ this.opts.bus.publish({
60185
+ timestamp: new Date(now),
60186
+ module: "threat-feeds",
60187
+ category: "network",
60188
+ severity: "critical",
60189
+ message: `Outbound connection to known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp}:${c.peerPort} by ${who}${blocked}`,
60190
+ // No source_ip on purpose: the remote end is not an attacker to ban
60191
+ // inbound, so remediation has nothing to act on and the egress table
60192
+ // stays the only enforcement.
60193
+ details: {
60194
+ rule_id: "threat-feed-outbound",
60195
+ destination_ip: c.peerIp,
60196
+ destination_port: c.peerPort,
60197
+ ...c.seenBy === "ss" ? { local_port: c.localPort } : {},
60198
+ state: c.state,
60199
+ process: c.process,
60200
+ pid: c.pid,
60201
+ ...c.executable ? { executable: c.executable } : {},
60202
+ seen_by: c.seenBy,
60203
+ malware: ind.malware,
60204
+ threat: ind.threat,
60205
+ feed: ind.feed,
60206
+ blocked: this.blocking
60207
+ }
60208
+ });
60209
+ return true;
60210
+ }
60211
+ /**
60212
+ * A listed malware host connecting in to one of our services. It is the
60213
+ * remote end reaching us, not a sign that this box is compromised, so it is
60214
+ * `high`, not `critical`; it carries source_ip so auto-defence can ban it.
60215
+ */
60216
+ reportInbound(c) {
60217
+ const ind = matchIp(c.peerIp, this.set);
60218
+ if (!ind) return false;
60219
+ const now = this.now();
60220
+ const key = `in|${c.peerIp}|${c.localPort}`;
60221
+ if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) return false;
60222
+ this.alerted.set(key, now);
60223
+ this.opts.bus.publish({
60224
+ timestamp: new Date(now),
60225
+ module: "threat-feeds",
60226
+ category: "network",
60227
+ severity: "high",
60228
+ message: `Inbound connection from known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp} to port ${c.localPort}`,
60229
+ source_ip: c.peerIp,
60230
+ details: {
60231
+ rule_id: "threat-feed-inbound",
60232
+ local_port: c.localPort,
60233
+ remote_port: c.peerPort,
60234
+ state: c.state,
60235
+ process: c.process,
60236
+ pid: c.pid,
60237
+ malware: ind.malware,
60238
+ threat: ind.threat,
60239
+ feed: ind.feed
60240
+ }
60241
+ });
60242
+ return true;
60243
+ }
60244
+ forgetOldAlerts() {
60245
+ const now = this.now();
60171
60246
  for (const [key, at] of this.alerted) if (now - at > REALERT_MS) this.alerted.delete(key);
60172
60247
  }
60173
60248
  };
@@ -61787,14 +61862,18 @@ var import_node_child_process20 = require("child_process");
61787
61862
  // src/daemon/workers/edr-ebpf.ts
61788
61863
  var import_node_child_process19 = require("child_process");
61789
61864
  var import_node_fs55 = require("fs");
61865
+ var import_node_net17 = require("net");
61790
61866
  var import_node_path41 = require("path");
61791
61867
  var BPFTRACE_RECORD_TAG = "TC1";
61792
61868
  var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
61793
61869
  var TCP_SYN_SENT = 2;
61794
61870
  var TCP_LISTEN = 10;
61795
61871
  var IPPROTO_TCP = 6;
61872
+ var AF_INET = 2;
61873
+ var AF_INET6 = 10;
61796
61874
  function bpftraceScript(opts) {
61797
61875
  const prefix = `"${BPFTRACE_RECORD_TAG}\\t%s\\t%d\\t%d\\t%d\\t%s\\n"`;
61876
+ const peerPrefix = `"${BPFTRACE_RECORD_TAG}\\t%s\\t%d\\t%d\\t%d\\t%s\\t%d\\t%s\\n"`;
61798
61877
  const lines = [
61799
61878
  "tracepoint:sched:sched_process_exec",
61800
61879
  "{",
@@ -61802,12 +61881,29 @@ function bpftraceScript(opts) {
61802
61881
  "}"
61803
61882
  ];
61804
61883
  if (opts.network) {
61884
+ if (opts.peers) {
61885
+ lines.push(
61886
+ "tracepoint:sock:inet_sock_set_state",
61887
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT} && args.family == ${AF_INET}/`,
61888
+ "{",
61889
+ ` printf(${peerPrefix}, "connectp", pid, curtask->real_parent->tgid, curtask->cred->euid.val, ntop(args.daddr), args.dport, comm);`,
61890
+ "}",
61891
+ "tracepoint:sock:inet_sock_set_state",
61892
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT} && args.family == ${AF_INET6}/`,
61893
+ "{",
61894
+ ` printf(${peerPrefix}, "connectp", pid, curtask->real_parent->tgid, curtask->cred->euid.val, ntop(args.daddr_v6), args.dport, comm);`,
61895
+ "}"
61896
+ );
61897
+ } else {
61898
+ lines.push(
61899
+ "tracepoint:sock:inet_sock_set_state",
61900
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
61901
+ "{",
61902
+ ` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
61903
+ "}"
61904
+ );
61905
+ }
61805
61906
  lines.push(
61806
- "tracepoint:sock:inet_sock_set_state",
61807
- `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
61808
- "{",
61809
- ` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
61810
- "}",
61811
61907
  "tracepoint:sock:inet_sock_set_state",
61812
61908
  `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_LISTEN}/`,
61813
61909
  "{",
@@ -61834,12 +61930,22 @@ function parseRecordText(text) {
61834
61930
  }
61835
61931
  const [tag, kind, pidText, ppidText, euidText] = parts;
61836
61932
  if (tag !== BPFTRACE_RECORD_TAG) return null;
61837
- if (kind !== "exec" && kind !== "connect" && kind !== "listen") return null;
61933
+ if (kind !== "exec" && kind !== "connect" && kind !== "connectp" && kind !== "listen") return null;
61838
61934
  const pid = Number(pidText);
61839
61935
  const ppid = Number(ppidText);
61840
61936
  const euid = Number(euidText);
61841
61937
  if (!/^\d+$/.test(pidText) || !/^\d+$/.test(ppidText) || !/^\d+$/.test(euidText)) return null;
61842
61938
  if (!Number.isSafeInteger(pid) || pid <= 0 || !Number.isSafeInteger(ppid) || !Number.isSafeInteger(euid)) return null;
61939
+ if (kind === "connectp") {
61940
+ const addrEnd = rest.indexOf(" ");
61941
+ const portEnd = addrEnd < 0 ? -1 : rest.indexOf(" ", addrEnd + 1);
61942
+ if (portEnd < 0) return null;
61943
+ const peerIp2 = rest.slice(0, addrEnd).replace(/^::ffff:(?=\d+\.\d+\.\d+\.\d+$)/i, "");
61944
+ const portText = rest.slice(addrEnd + 1, portEnd);
61945
+ const comm = rest.slice(portEnd + 1, portEnd + 1 + MAX_FIELD);
61946
+ if (!(0, import_node_net17.isIP)(peerIp2) || !/^\d{1,5}$/.test(portText) || Number(portText) > 65535 || !comm) return null;
61947
+ return { kind: "connect", pid, ppid, euid, comm: comm.slice(0, 64), peerIp: peerIp2, peerPort: Number(portText) };
61948
+ }
61843
61949
  const value = rest.slice(0, MAX_FIELD);
61844
61950
  if (!value) return null;
61845
61951
  if (kind === "exec") {
@@ -62025,7 +62131,7 @@ var BpftraceSource = class {
62025
62131
  this.stderrTail = "";
62026
62132
  let child;
62027
62133
  try {
62028
- child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network }), {
62134
+ child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network, peers: this.opts.peers }), {
62029
62135
  stdio: ["ignore", "pipe", "pipe"],
62030
62136
  shell: false,
62031
62137
  env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
@@ -62117,6 +62223,7 @@ function edrSettings(section) {
62117
62223
  webServiceUsers: configuredUsers,
62118
62224
  tempExecPaths: configuredPaths,
62119
62225
  watchNetworkSyscalls: section?.watch_network_syscalls === true,
62226
+ matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
62120
62227
  networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
62121
62228
  watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
62122
62229
  pollMs
@@ -62272,6 +62379,7 @@ var EdrWatch = class {
62272
62379
  const options = {
62273
62380
  bpftracePath,
62274
62381
  network: this.opts.settings.watchNetworkSyscalls,
62382
+ peers: this.opts.settings.matchThreatFeeds,
62275
62383
  onEvent: (event) => {
62276
62384
  this.handleEbpfEvent(event);
62277
62385
  },
@@ -62284,7 +62392,8 @@ var EdrWatch = class {
62284
62392
  };
62285
62393
  this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
62286
62394
  this.setSource("ebpf", reason);
62287
- this.opts.log(`[edr] event source: eBPF via ${bpftracePath} (exec${this.opts.settings.watchNetworkSyscalls ? ", tcp connect/listen" : ""}); command arguments and remote addresses are not collected`);
62395
+ const addresses = this.opts.settings.matchThreatFeeds ? "command arguments are not collected; remote addresses are matched against the threat feeds and kept only on a hit" : "command arguments and remote addresses are not collected";
62396
+ this.opts.log(`[edr] event source: eBPF via ${bpftracePath} (exec${this.opts.settings.watchNetworkSyscalls ? ", tcp connect/listen" : ""}); ${addresses}`);
62288
62397
  this.bpftrace.start();
62289
62398
  }
62290
62399
  startAuditd(reason) {
@@ -62344,6 +62453,19 @@ var EdrWatch = class {
62344
62453
  if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
62345
62454
  this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
62346
62455
  const resolver = resolveExe ?? (() => this.resolveEbpfExe(event));
62456
+ if (event.kind === "connect" && event.peerIp && event.peerPort !== void 0 && this.opts.settings.matchThreatFeeds && this.opts.onConnection) {
62457
+ try {
62458
+ this.opts.onConnection({
62459
+ peerIp: event.peerIp,
62460
+ peerPort: event.peerPort,
62461
+ pid: event.pid,
62462
+ comm: event.comm,
62463
+ euid: event.euid,
62464
+ resolveExecutable: () => resolver(event.pid)
62465
+ });
62466
+ } catch {
62467
+ }
62468
+ }
62347
62469
  const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
62348
62470
  for (const record of records) {
62349
62471
  const threat = this.classify(record);
@@ -62558,7 +62680,7 @@ var import_node_child_process21 = require("child_process");
62558
62680
 
62559
62681
  // src/core/asn.ts
62560
62682
  var import_node_dns = require("dns");
62561
- var import_node_net17 = require("net");
62683
+ var import_node_net18 = require("net");
62562
62684
  var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
62563
62685
  var HOSTING_ASNS = /* @__PURE__ */ new Set([
62564
62686
  15169,
@@ -62677,7 +62799,7 @@ var AsnLookup = class {
62677
62799
  now;
62678
62800
  cache = /* @__PURE__ */ new Map();
62679
62801
  async lookup(ip) {
62680
- if ((0, import_node_net17.isIP)(ip) === 0) return null;
62802
+ if ((0, import_node_net18.isIP)(ip) === 0) return null;
62681
62803
  const hit = this.cache.get(ip);
62682
62804
  if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
62683
62805
  let info2 = null;
@@ -63128,7 +63250,7 @@ var LightningWatch = class {
63128
63250
  // src/daemon/workers/docker-logs.ts
63129
63251
  var import_node_fs61 = require("fs");
63130
63252
  var import_node_http = require("http");
63131
- var import_node_net18 = require("net");
63253
+ var import_node_net19 = require("net");
63132
63254
 
63133
63255
  // src/daemon/workers/postgres-shell.ts
63134
63256
  var import_node_fs60 = require("fs");
@@ -63493,7 +63615,7 @@ function cleanPgHost(raw) {
63493
63615
  if (!raw) return void 0;
63494
63616
  let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
63495
63617
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
63496
- return (0, import_node_net18.isIP)(host) ? host : void 0;
63618
+ return (0, import_node_net19.isIP)(host) ? host : void 0;
63497
63619
  }
63498
63620
  function prefixHost(line2) {
63499
63621
  const first = cleanPgHost(line2.split(/\s/, 1)[0]);
@@ -63763,7 +63885,7 @@ var DockerLogsWatch = class {
63763
63885
  // src/daemon/workers/login-watch.ts
63764
63886
  var import_node_fs62 = require("fs");
63765
63887
  var import_node_child_process22 = require("child_process");
63766
- var import_node_net19 = require("net");
63888
+ var import_node_net20 = require("net");
63767
63889
  var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
63768
63890
  function stringList(value, fallback) {
63769
63891
  if (!Array.isArray(value)) return fallback;
@@ -63808,7 +63930,7 @@ function networkOf(ip) {
63808
63930
  }
63809
63931
  function classifyLogin(login2, ctx) {
63810
63932
  const { user, ip } = login2;
63811
- if (!user || !(0, import_node_net19.isIP)(ip)) return null;
63933
+ if (!user || !(0, import_node_net20.isIP)(ip)) return null;
63812
63934
  if (isProtected(ip, DEFAULT_PROTECTED)) return null;
63813
63935
  const network = networkOf(ip);
63814
63936
  const reasons = [];
@@ -63846,7 +63968,7 @@ function parseAcceptedLogins3(text) {
63846
63968
  const out = [];
63847
63969
  for (const line2 of text.split("\n")) {
63848
63970
  const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line2);
63849
- if (m && (0, import_node_net19.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
63971
+ if (m && (0, import_node_net20.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
63850
63972
  }
63851
63973
  return out;
63852
63974
  }
@@ -63857,7 +63979,7 @@ function ssPeerIp(field) {
63857
63979
  else host = field.replace(/:\d+$/, "");
63858
63980
  host = host.split("%")[0];
63859
63981
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
63860
- return (0, import_node_net19.isIP)(host) ? host : null;
63982
+ return (0, import_node_net20.isIP)(host) ? host : null;
63861
63983
  }
63862
63984
  function sshdPidsForPeer(ssOutput, ip) {
63863
63985
  const pids = /* @__PURE__ */ new Set();
@@ -64161,7 +64283,7 @@ var LoginWatch = class {
64161
64283
  // src/core/tor-exits.ts
64162
64284
  var import_node_fs63 = require("fs");
64163
64285
  var import_node_path44 = require("path");
64164
- var import_node_net20 = require("net");
64286
+ var import_node_net21 = require("net");
64165
64287
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
64166
64288
  function parseTorExitList(text) {
64167
64289
  const out = /* @__PURE__ */ new Set();
@@ -64169,7 +64291,7 @@ function parseTorExitList(text) {
64169
64291
  const line2 = raw.trim();
64170
64292
  if (!line2 || line2.startsWith("#")) continue;
64171
64293
  const ip = line2.split(/\s+/)[0];
64172
- if ((0, import_node_net20.isIP)(ip)) out.add(normalizeIp(ip));
64294
+ if ((0, import_node_net21.isIP)(ip)) out.add(normalizeIp(ip));
64173
64295
  }
64174
64296
  return out;
64175
64297
  }
@@ -64280,7 +64402,7 @@ var TorExitList = class _TorExitList {
64280
64402
 
64281
64403
  // src/daemon/firewall/tor-block.ts
64282
64404
  var import_node_child_process23 = require("child_process");
64283
- var import_node_net21 = require("net");
64405
+ var import_node_net22 = require("net");
64284
64406
  var TOR_NFT_TABLE = "threatcrush-tor";
64285
64407
  function defaultNftRunner() {
64286
64408
  return (args, stdin) => new Promise((resolve9, reject) => {
@@ -64327,7 +64449,7 @@ var TorExitBlockEnforcer = class {
64327
64449
  await this.teardown();
64328
64450
  return;
64329
64451
  }
64330
- const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net21.isIP)(ip) === 4);
64452
+ const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net22.isIP)(ip) === 4);
64331
64453
  if (ipv4.length === 0) return;
64332
64454
  try {
64333
64455
  await this.apply(ipv4);
@@ -64869,12 +64991,12 @@ var AuthorizedKeysIndex = class {
64869
64991
  };
64870
64992
 
64871
64993
  // src/daemon/ssh-context/ip-intel.ts
64872
- var import_node_net22 = require("net");
64994
+ var import_node_net23 = require("net");
64873
64995
  var import_node_os20 = require("os");
64874
64996
  var import_node_dns2 = require("dns");
64875
64997
  var import_node_fs65 = require("fs");
64876
64998
  function list2(entries2) {
64877
- const b = new import_node_net22.BlockList();
64999
+ const b = new import_node_net23.BlockList();
64878
65000
  for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
64879
65001
  return b;
64880
65002
  }
@@ -64889,7 +65011,7 @@ var PRIVATE = list2([
64889
65011
  ["fe80::", 10, "ipv6"]
64890
65012
  ]);
64891
65013
  function family(ip) {
64892
- const f = (0, import_node_net22.isIP)(ip);
65014
+ const f = (0, import_node_net23.isIP)(ip);
64893
65015
  return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
64894
65016
  }
64895
65017
  function normalizeIp2(ip) {
@@ -64960,7 +65082,7 @@ var GitHubActionsRanges = class {
64960
65082
  lastTry = 0;
64961
65083
  inflight = null;
64962
65084
  set(cidrs, at) {
64963
- const b = new import_node_net22.BlockList();
65085
+ const b = new import_node_net23.BlockList();
64964
65086
  let n = 0;
64965
65087
  for (const c of cidrs) {
64966
65088
  const [addr, bits2] = c.split("/");
@@ -65019,7 +65141,7 @@ function withTimeout2(p, ms) {
65019
65141
  }
65020
65142
  function cymruOriginName2(raw) {
65021
65143
  const ip = normalizeIp2(raw);
65022
- const f = (0, import_node_net22.isIP)(ip);
65144
+ const f = (0, import_node_net23.isIP)(ip);
65023
65145
  if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
65024
65146
  if (f !== 6) return null;
65025
65147
  const parts = ip.split("::");
@@ -65947,14 +66069,14 @@ function loadAllRules(customDir) {
65947
66069
  var import_node_child_process25 = require("child_process");
65948
66070
  var import_node_fs67 = require("fs");
65949
66071
  var import_node_path47 = require("path");
65950
- var import_node_net23 = require("net");
66072
+ var import_node_net24 = require("net");
65951
66073
  function assertValidFirewallIp(ip) {
65952
- if ((0, import_node_net23.isIP)(ip) !== 4) {
66074
+ if ((0, import_node_net24.isIP)(ip) !== 4) {
65953
66075
  throw new Error(`Invalid IPv4 address: ${ip}`);
65954
66076
  }
65955
66077
  }
65956
66078
  function assertBannableIp(ip) {
65957
- if ((0, import_node_net23.isIP)(ip) === 0) {
66079
+ if ((0, import_node_net24.isIP)(ip) === 0) {
65958
66080
  throw new Error(`Invalid IP address: ${ip}`);
65959
66081
  }
65960
66082
  }
@@ -66060,7 +66182,7 @@ var Fail2banAdapter = class {
66060
66182
  const status = this.client(["status", this.jail]);
66061
66183
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
66062
66184
  if (!line2) return [];
66063
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
66185
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
66064
66186
  } catch {
66065
66187
  return [];
66066
66188
  }
@@ -66070,10 +66192,10 @@ var Fail2banAdapter = class {
66070
66192
  function parseBannedList(output) {
66071
66193
  const found = [];
66072
66194
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
66073
- if ((0, import_node_net23.isIP)(match[1]) !== 0) found.push(match[1]);
66195
+ if ((0, import_node_net24.isIP)(match[1]) !== 0) found.push(match[1]);
66074
66196
  }
66075
66197
  if (found.length > 0) return found;
66076
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net23.isIP)(s) !== 0);
66198
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
66077
66199
  }
66078
66200
  var NftablesAdapter = class {
66079
66201
  name = "nftables";
@@ -66222,7 +66344,7 @@ function detectFirewallAdapter(backend = "auto") {
66222
66344
  // src/daemon/firewall/remediation.ts
66223
66345
  var import_node_fs68 = require("fs");
66224
66346
  var import_node_child_process26 = require("child_process");
66225
- var import_node_net24 = require("net");
66347
+ var import_node_net25 = require("net");
66226
66348
  init_paths();
66227
66349
  init_backoff();
66228
66350
 
@@ -66393,7 +66515,7 @@ var RemediationManager = class {
66393
66515
  setTorExitCheck(check2) {
66394
66516
  this.isTorExit = check2;
66395
66517
  let dropped = 0;
66396
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net24.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
66518
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net25.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
66397
66519
  for (const ip of Object.keys(this.operators)) {
66398
66520
  if (!check2(ip)) continue;
66399
66521
  delete this.operators[ip];
@@ -66486,7 +66608,7 @@ var RemediationManager = class {
66486
66608
  if (remediation?.action !== "block") return;
66487
66609
  }
66488
66610
  const ip = event.source_ip;
66489
- if (!ip || (0, import_node_net24.isIP)(ip) === 0) return;
66611
+ if (!ip || (0, import_node_net25.isIP)(ip) === 0) return;
66490
66612
  const strict = remediation?.override_operator_protection === true;
66491
66613
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
66492
66614
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -66515,7 +66637,7 @@ var RemediationManager = class {
66515
66637
  * 4th offence and so on, clamped to `max_ban_seconds`.
66516
66638
  */
66517
66639
  async ban(ip, reason, opts = {}) {
66518
- if ((0, import_node_net24.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
66640
+ if ((0, import_node_net25.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
66519
66641
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
66520
66642
  return { ok: false, error: `${ip} is protected and can never be blocked` };
66521
66643
  }
@@ -66792,7 +66914,7 @@ var RemediationManager = class {
66792
66914
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
66793
66915
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
66794
66916
  for (const [ip, at] of Object.entries(saved)) {
66795
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net24.isIP)(ip)) continue;
66917
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net25.isIP)(ip)) continue;
66796
66918
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
66797
66919
  this.operators[ip] = at;
66798
66920
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -67178,6 +67300,12 @@ async function runDaemon() {
67178
67300
  settings: edrSettings(config.edr),
67179
67301
  networkBaselinePath: (0, import_node_path49.join)(PATHS.stateDir, "edr-outbound-executables.json"),
67180
67302
  sourceStatusPath: (0, import_node_path49.join)(PATHS.stateDir, "edr-source.json"),
67303
+ // Every traced connect is checked against the abuse.ch lists: this is what
67304
+ // sees a one-second download or a container calling out, which the
67305
+ // threat-feeds socket snapshot cannot.
67306
+ onConnection: (conn) => {
67307
+ threatFeeds.observeOutbound(conn);
67308
+ },
67181
67309
  log: logLine
67182
67310
  });
67183
67311
  edr.start();
@@ -69919,7 +70047,7 @@ async function patchesCommand(opts) {
69919
70047
  }
69920
70048
 
69921
70049
  // src/commands/feeds.ts
69922
- var import_node_net25 = require("net");
70050
+ var import_node_net26 = require("net");
69923
70051
  var import_node_path55 = require("path");
69924
70052
  init_paths();
69925
70053
 
@@ -70063,8 +70191,8 @@ async function feedsCommand(action, value, opts) {
70063
70191
  process.exitCode = 2;
70064
70192
  return;
70065
70193
  }
70066
- const ipHit = (0, import_node_net25.isIP)(value) ? matchIp(value, set) : null;
70067
- const domainHit = (0, import_node_net25.isIP)(value) ? null : matchDomain(value, set);
70194
+ const ipHit = (0, import_node_net26.isIP)(value) ? matchIp(value, set) : null;
70195
+ const domainHit = (0, import_node_net26.isIP)(value) ? null : matchDomain(value, set);
70068
70196
  const listed = ipHit ?? domainHit?.indicator ?? null;
70069
70197
  if (opts.json) {
70070
70198
  console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
@@ -70103,7 +70231,7 @@ async function feedsCommand(action, value, opts) {
70103
70231
 
70104
70232
  // src/commands/tor.ts
70105
70233
  var import_node_fs80 = require("fs");
70106
- var import_node_net26 = require("net");
70234
+ var import_node_net27 = require("net");
70107
70235
  var import_node_path56 = require("path");
70108
70236
  init_paths();
70109
70237
  async function torCommand(action, value, opts) {
@@ -70135,7 +70263,7 @@ async function torCommand(action, value, opts) {
70135
70263
  const remediation = loadConfig((0, import_node_path56.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
70136
70264
  const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
70137
70265
  if (action === "check") {
70138
- if (!value || !(0, import_node_net26.isIP)(value)) {
70266
+ if (!value || !(0, import_node_net27.isIP)(value)) {
70139
70267
  console.error("Usage: threatcrush tor check <ip>");
70140
70268
  process.exitCode = 2;
70141
70269
  return;
@@ -70628,7 +70756,7 @@ async function edrCommand(action = "status", opts = {}) {
70628
70756
  if (action === "bpftrace") {
70629
70757
  console.log("// Generated by threatcrush edr bpftrace: the program the eBPF source runs");
70630
70758
  console.log("// as `bpftrace -q -B line -f json -e <program>` when [edr] source selects ebpf.");
70631
- process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls }));
70759
+ process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls, peers: settings.matchThreatFeeds }));
70632
70760
  return;
70633
70761
  }
70634
70762
  if (action !== "status") {
@@ -70665,6 +70793,7 @@ async function edrCommand(action = "status", opts = {}) {
70665
70793
  web_service_users: settings.webServiceUsers,
70666
70794
  temp_exec_paths: settings.tempExecPaths,
70667
70795
  watch_network_syscalls: settings.watchNetworkSyscalls,
70796
+ match_threat_feeds: settings.matchThreatFeeds,
70668
70797
  network_baseline_seconds: settings.networkBaselineMs / 1e3,
70669
70798
  watch_unknown_temp_cpu: settings.watchUnknownTempCpu,
70670
70799
  poll_interval_seconds: settings.pollMs / 1e3,