@profullstack/threatcrush 0.17.1 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -670,10 +670,27 @@ that traces successful `exec` (pid, ppid, effective uid, file name) and, when
670
670
  transitions. Each event becomes the same normalized record the auditd parser
671
671
  produces, so reverse-shell, web-service shell, writable-path execution, miner,
672
672
  new-outbound and listener detections behave identically on either source.
673
- Command arguments and remote addresses are not traced.
673
+ Command arguments are not traced.
674
+
675
+ With `watch_network_syscalls = true` the eBPF source also reads the remote
676
+ address and port of every outbound TCP connect and looks it up in the
677
+ `[threat_feeds]` lists. A hit raises a critical `threat-feed-outbound` event
678
+ naming the process and its binary. This is the path that sees a one-second
679
+ download or a connection made inside a container: the threat-feeds socket
680
+ snapshot runs every 15 seconds in the host's own network namespace and misses
681
+ both. An address that is not listed is dropped at once and never stored or
682
+ sent anywhere. Set `match_threat_feeds = false` under `[edr]` to trace no
683
+ remote addresses at all. The auditd source does not do this matching.
684
+
685
+ Inbound is covered by the snapshot: a listed host connected to one of this
686
+ box's listening ports raises a high `threat-feed-inbound` event that carries
687
+ the source address, so auto-defence can ban it.
674
688
 
675
689
  It needs root, `bpftrace` (`apt install bpftrace`) and kernel BTF
676
- (`/sys/kernel/btf/vmlinux`). `source = "auto"` picks eBPF when all three are
690
+ (`/sys/kernel/btf/vmlinux`). Under systemd the unit must also grant `CAP_BPF`
691
+ and `CAP_PERFMON`: enable `[edr]` first, then run `threatcrush install-service`
692
+ again, which adds them when the eBPF source is configured. A unit installed
693
+ before that makes bpftrace exit with "Missing CAP_BPF capability". `source = "auto"` picks eBPF when all three are
677
694
  present and auditd otherwise; `source = "ebpf"` logs why and uses auditd when
678
695
  they are not. If bpftrace exits it is restarted with exponential backoff (1s
679
696
  up to 60s); if it fails to start three times in a row, the daemon falls back
package/dist/daemon.js CHANGED
@@ -27038,46 +27038,120 @@ var ThreatFeeds = class {
27038
27038
  }
27039
27039
  this.blocking = false;
27040
27040
  }
27041
- /** Outbound connections to listed IPs, one alert per IP and process per hour. */
27041
+ /**
27042
+ * Listed IPs among the open sockets, one alert per IP and process per hour.
27043
+ * A socket on one of our listening ports is the listed host connecting in;
27044
+ * any other is this box calling out. This is a 15 s snapshot of the host's
27045
+ * own network namespace: a short connection, or one made inside a container,
27046
+ * is only seen by the `[edr]` eBPF source, which reports through
27047
+ * `observeOutbound`.
27048
+ */
27042
27049
  pollConnections() {
27043
27050
  if (!this.set || Object.keys(this.set.ips).length === 0) return;
27044
27051
  const conns = this.run("ss", ["-tnpH"]);
27045
27052
  if (conns === null) return;
27046
27053
  const listening = parseListeningPorts(this.run("ss", ["-ltnH"]) ?? "");
27047
- const now = this.now();
27048
27054
  for (const c of parseSs(conns)) {
27049
- if (listening.has(c.localPort)) continue;
27050
- const ind = matchIp(c.peerIp, this.set);
27051
- if (!ind) continue;
27052
- const key = `${c.peerIp}|${c.process ?? "?"}`;
27053
- if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) continue;
27054
- this.alerted.set(key, now);
27055
- const who = c.process ? `${c.process} (pid ${c.pid})` : "an unknown process";
27056
- const blocked = this.blocking ? " \u2014 blocked" : "";
27057
- this.opts.bus.publish({
27058
- timestamp: new Date(now),
27059
- module: "threat-feeds",
27060
- category: "network",
27061
- severity: "critical",
27062
- message: `Outbound connection to known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp}:${c.peerPort} by ${who}${blocked}`,
27063
- // No source_ip on purpose: the remote end is not an attacker to ban
27064
- // inbound, so remediation has nothing to act on and the egress table
27065
- // stays the only enforcement.
27066
- details: {
27067
- rule_id: "threat-feed-outbound",
27068
- destination_ip: c.peerIp,
27069
- destination_port: c.peerPort,
27070
- local_port: c.localPort,
27071
- state: c.state,
27072
- process: c.process,
27073
- pid: c.pid,
27074
- malware: ind.malware,
27075
- threat: ind.threat,
27076
- feed: ind.feed,
27077
- blocked: this.blocking
27078
- }
27079
- });
27055
+ if (listening.has(c.localPort)) this.reportInbound(c);
27056
+ else this.reportOutbound({ ...c, seenBy: "ss" });
27080
27057
  }
27058
+ this.forgetOldAlerts();
27059
+ }
27060
+ /**
27061
+ * One outbound connect traced by the `[edr]` eBPF source: every namespace,
27062
+ * however short-lived, with the process that made it. The address is looked
27063
+ * up and dropped unless it is listed. Returns whether an event was raised.
27064
+ */
27065
+ observeOutbound(conn) {
27066
+ if (!this.set || !matchIp(conn.peerIp, this.set)) return false;
27067
+ let executable = null;
27068
+ try {
27069
+ executable = conn.resolveExecutable?.() ?? null;
27070
+ } catch {
27071
+ }
27072
+ const process3 = executable ? executable.slice(executable.lastIndexOf("/") + 1) : conn.comm;
27073
+ return this.reportOutbound({
27074
+ state: "SYN-SENT",
27075
+ localPort: 0,
27076
+ peerIp: conn.peerIp,
27077
+ peerPort: conn.peerPort,
27078
+ process: process3 || conn.comm || null,
27079
+ pid: conn.pid,
27080
+ executable,
27081
+ seenBy: "ebpf"
27082
+ });
27083
+ }
27084
+ reportOutbound(c) {
27085
+ const ind = matchIp(c.peerIp, this.set);
27086
+ if (!ind) return false;
27087
+ const now = this.now();
27088
+ const key = `${c.peerIp}|${c.process ?? "?"}`;
27089
+ if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) return false;
27090
+ this.alerted.set(key, now);
27091
+ const who = c.process ? `${c.process} (pid ${c.pid})` : "an unknown process";
27092
+ const blocked = this.blocking ? " \u2014 blocked" : "";
27093
+ this.opts.bus.publish({
27094
+ timestamp: new Date(now),
27095
+ module: "threat-feeds",
27096
+ category: "network",
27097
+ severity: "critical",
27098
+ message: `Outbound connection to known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp}:${c.peerPort} by ${who}${blocked}`,
27099
+ // No source_ip on purpose: the remote end is not an attacker to ban
27100
+ // inbound, so remediation has nothing to act on and the egress table
27101
+ // stays the only enforcement.
27102
+ details: {
27103
+ rule_id: "threat-feed-outbound",
27104
+ destination_ip: c.peerIp,
27105
+ destination_port: c.peerPort,
27106
+ ...c.seenBy === "ss" ? { local_port: c.localPort } : {},
27107
+ state: c.state,
27108
+ process: c.process,
27109
+ pid: c.pid,
27110
+ ...c.executable ? { executable: c.executable } : {},
27111
+ seen_by: c.seenBy,
27112
+ malware: ind.malware,
27113
+ threat: ind.threat,
27114
+ feed: ind.feed,
27115
+ blocked: this.blocking
27116
+ }
27117
+ });
27118
+ return true;
27119
+ }
27120
+ /**
27121
+ * A listed malware host connecting in to one of our services. It is the
27122
+ * remote end reaching us, not a sign that this box is compromised, so it is
27123
+ * `high`, not `critical`; it carries source_ip so auto-defence can ban it.
27124
+ */
27125
+ reportInbound(c) {
27126
+ const ind = matchIp(c.peerIp, this.set);
27127
+ if (!ind) return false;
27128
+ const now = this.now();
27129
+ const key = `in|${c.peerIp}|${c.localPort}`;
27130
+ if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) return false;
27131
+ this.alerted.set(key, now);
27132
+ this.opts.bus.publish({
27133
+ timestamp: new Date(now),
27134
+ module: "threat-feeds",
27135
+ category: "network",
27136
+ severity: "high",
27137
+ message: `Inbound connection from known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp} to port ${c.localPort}`,
27138
+ source_ip: c.peerIp,
27139
+ details: {
27140
+ rule_id: "threat-feed-inbound",
27141
+ local_port: c.localPort,
27142
+ remote_port: c.peerPort,
27143
+ state: c.state,
27144
+ process: c.process,
27145
+ pid: c.pid,
27146
+ malware: ind.malware,
27147
+ threat: ind.threat,
27148
+ feed: ind.feed
27149
+ }
27150
+ });
27151
+ return true;
27152
+ }
27153
+ forgetOldAlerts() {
27154
+ const now = this.now();
27081
27155
  for (const [key, at] of this.alerted) if (now - at > REALERT_MS) this.alerted.delete(key);
27082
27156
  }
27083
27157
  };
@@ -28694,14 +28768,18 @@ var import_node_child_process10 = require("child_process");
28694
28768
  // src/daemon/workers/edr-ebpf.ts
28695
28769
  var import_node_child_process9 = require("child_process");
28696
28770
  var import_node_fs28 = require("fs");
28771
+ var import_node_net11 = require("net");
28697
28772
  var import_node_path24 = require("path");
28698
28773
  var BPFTRACE_RECORD_TAG = "TC1";
28699
28774
  var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
28700
28775
  var TCP_SYN_SENT = 2;
28701
28776
  var TCP_LISTEN = 10;
28702
28777
  var IPPROTO_TCP = 6;
28778
+ var AF_INET = 2;
28779
+ var AF_INET6 = 10;
28703
28780
  function bpftraceScript(opts) {
28704
28781
  const prefix = `"${BPFTRACE_RECORD_TAG}\\t%s\\t%d\\t%d\\t%d\\t%s\\n"`;
28782
+ const peerPrefix = `"${BPFTRACE_RECORD_TAG}\\t%s\\t%d\\t%d\\t%d\\t%s\\t%d\\t%s\\n"`;
28705
28783
  const lines = [
28706
28784
  "tracepoint:sched:sched_process_exec",
28707
28785
  "{",
@@ -28709,12 +28787,29 @@ function bpftraceScript(opts) {
28709
28787
  "}"
28710
28788
  ];
28711
28789
  if (opts.network) {
28790
+ if (opts.peers) {
28791
+ lines.push(
28792
+ "tracepoint:sock:inet_sock_set_state",
28793
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT} && args.family == ${AF_INET}/`,
28794
+ "{",
28795
+ ` printf(${peerPrefix}, "connectp", pid, curtask->real_parent->tgid, curtask->cred->euid.val, ntop(args.daddr), args.dport, comm);`,
28796
+ "}",
28797
+ "tracepoint:sock:inet_sock_set_state",
28798
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT} && args.family == ${AF_INET6}/`,
28799
+ "{",
28800
+ ` printf(${peerPrefix}, "connectp", pid, curtask->real_parent->tgid, curtask->cred->euid.val, ntop(args.daddr_v6), args.dport, comm);`,
28801
+ "}"
28802
+ );
28803
+ } else {
28804
+ lines.push(
28805
+ "tracepoint:sock:inet_sock_set_state",
28806
+ `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
28807
+ "{",
28808
+ ` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
28809
+ "}"
28810
+ );
28811
+ }
28712
28812
  lines.push(
28713
- "tracepoint:sock:inet_sock_set_state",
28714
- `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
28715
- "{",
28716
- ` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
28717
- "}",
28718
28813
  "tracepoint:sock:inet_sock_set_state",
28719
28814
  `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_LISTEN}/`,
28720
28815
  "{",
@@ -28741,12 +28836,22 @@ function parseRecordText(text) {
28741
28836
  }
28742
28837
  const [tag, kind, pidText, ppidText, euidText] = parts;
28743
28838
  if (tag !== BPFTRACE_RECORD_TAG) return null;
28744
- if (kind !== "exec" && kind !== "connect" && kind !== "listen") return null;
28839
+ if (kind !== "exec" && kind !== "connect" && kind !== "connectp" && kind !== "listen") return null;
28745
28840
  const pid = Number(pidText);
28746
28841
  const ppid = Number(ppidText);
28747
28842
  const euid = Number(euidText);
28748
28843
  if (!/^\d+$/.test(pidText) || !/^\d+$/.test(ppidText) || !/^\d+$/.test(euidText)) return null;
28749
28844
  if (!Number.isSafeInteger(pid) || pid <= 0 || !Number.isSafeInteger(ppid) || !Number.isSafeInteger(euid)) return null;
28845
+ if (kind === "connectp") {
28846
+ const addrEnd = rest.indexOf(" ");
28847
+ const portEnd = addrEnd < 0 ? -1 : rest.indexOf(" ", addrEnd + 1);
28848
+ if (portEnd < 0) return null;
28849
+ const peerIp = rest.slice(0, addrEnd).replace(/^::ffff:(?=\d+\.\d+\.\d+\.\d+$)/i, "");
28850
+ const portText = rest.slice(addrEnd + 1, portEnd);
28851
+ const comm = rest.slice(portEnd + 1, portEnd + 1 + MAX_FIELD);
28852
+ if (!(0, import_node_net11.isIP)(peerIp) || !/^\d{1,5}$/.test(portText) || Number(portText) > 65535 || !comm) return null;
28853
+ return { kind: "connect", pid, ppid, euid, comm: comm.slice(0, 64), peerIp, peerPort: Number(portText) };
28854
+ }
28750
28855
  const value = rest.slice(0, MAX_FIELD);
28751
28856
  if (!value) return null;
28752
28857
  if (kind === "exec") {
@@ -28825,6 +28930,7 @@ function probeHost(configured) {
28825
28930
  platform: process.platform
28826
28931
  };
28827
28932
  }
28933
+ var BPFTRACE_ENV = { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" };
28828
28934
  var STDERR_TAIL = 2048;
28829
28935
  var HEALTHY_AFTER_MS = 3e4;
28830
28936
  var KILL_GRACE_MS = 3e3;
@@ -28932,10 +29038,10 @@ var BpftraceSource = class {
28932
29038
  this.stderrTail = "";
28933
29039
  let child;
28934
29040
  try {
28935
- child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network }), {
29041
+ child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network, peers: this.opts.peers }), {
28936
29042
  stdio: ["ignore", "pipe", "pipe"],
28937
29043
  shell: false,
28938
- env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
29044
+ env: BPFTRACE_ENV
28939
29045
  });
28940
29046
  } catch (error) {
28941
29047
  this.onExit(null, null, error.message);
@@ -29024,6 +29130,7 @@ function edrSettings(section) {
29024
29130
  webServiceUsers: configuredUsers,
29025
29131
  tempExecPaths: configuredPaths,
29026
29132
  watchNetworkSyscalls: section?.watch_network_syscalls === true,
29133
+ matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
29027
29134
  networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
29028
29135
  watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
29029
29136
  pollMs
@@ -29170,19 +29277,24 @@ var EdrWatch = class {
29170
29277
  const options = {
29171
29278
  bpftracePath,
29172
29279
  network: this.opts.settings.watchNetworkSyscalls,
29280
+ peers: this.opts.settings.matchThreatFeeds,
29173
29281
  onEvent: (event) => {
29174
29282
  this.handleEbpfEvent(event);
29175
29283
  },
29176
29284
  onFatal: (failure) => {
29177
29285
  this.bpftrace = null;
29178
29286
  this.opts.log(`[edr] ${failure}; falling back to auditd`);
29287
+ if (/Missing CAP_(BPF|PERFMON)/.test(failure)) {
29288
+ this.opts.log("[edr] the service unit does not grant CAP_BPF and CAP_PERFMON: re-run `threatcrush install-service` with [edr] enabled, then restart the daemon");
29289
+ }
29179
29290
  this.startAuditd(`eBPF failed: ${failure}`);
29180
29291
  },
29181
29292
  log: this.opts.log
29182
29293
  };
29183
29294
  this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
29184
29295
  this.setSource("ebpf", reason);
29185
- 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`);
29296
+ 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";
29297
+ this.opts.log(`[edr] event source: eBPF via ${bpftracePath} (exec${this.opts.settings.watchNetworkSyscalls ? ", tcp connect/listen" : ""}); ${addresses}`);
29186
29298
  this.bpftrace.start();
29187
29299
  }
29188
29300
  startAuditd(reason) {
@@ -29242,6 +29354,19 @@ var EdrWatch = class {
29242
29354
  if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
29243
29355
  this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
29244
29356
  const resolver = resolveExe ?? (() => this.resolveEbpfExe(event));
29357
+ if (event.kind === "connect" && event.peerIp && event.peerPort !== void 0 && this.opts.settings.matchThreatFeeds && this.opts.onConnection) {
29358
+ try {
29359
+ this.opts.onConnection({
29360
+ peerIp: event.peerIp,
29361
+ peerPort: event.peerPort,
29362
+ pid: event.pid,
29363
+ comm: event.comm,
29364
+ euid: event.euid,
29365
+ resolveExecutable: () => resolver(event.pid)
29366
+ });
29367
+ } catch {
29368
+ }
29369
+ }
29245
29370
  const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
29246
29371
  for (const record of records) {
29247
29372
  const threat = this.classify(record);
@@ -29456,7 +29581,7 @@ var import_node_child_process11 = require("child_process");
29456
29581
 
29457
29582
  // src/core/asn.ts
29458
29583
  var import_node_dns = require("dns");
29459
- var import_node_net11 = require("net");
29584
+ var import_node_net12 = require("net");
29460
29585
  var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
29461
29586
  var HOSTING_ASNS = /* @__PURE__ */ new Set([
29462
29587
  15169,
@@ -29575,7 +29700,7 @@ var AsnLookup = class {
29575
29700
  now;
29576
29701
  cache = /* @__PURE__ */ new Map();
29577
29702
  async lookup(ip) {
29578
- if ((0, import_node_net11.isIP)(ip) === 0) return null;
29703
+ if ((0, import_node_net12.isIP)(ip) === 0) return null;
29579
29704
  const hit = this.cache.get(ip);
29580
29705
  if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
29581
29706
  let info = null;
@@ -30026,7 +30151,7 @@ var LightningWatch = class {
30026
30151
  // src/daemon/workers/docker-logs.ts
30027
30152
  var import_node_fs34 = require("fs");
30028
30153
  var import_node_http = require("http");
30029
- var import_node_net12 = require("net");
30154
+ var import_node_net13 = require("net");
30030
30155
 
30031
30156
  // src/daemon/workers/postgres-shell.ts
30032
30157
  var import_node_fs33 = require("fs");
@@ -30391,7 +30516,7 @@ function cleanPgHost(raw) {
30391
30516
  if (!raw) return void 0;
30392
30517
  let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
30393
30518
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
30394
- return (0, import_node_net12.isIP)(host) ? host : void 0;
30519
+ return (0, import_node_net13.isIP)(host) ? host : void 0;
30395
30520
  }
30396
30521
  function prefixHost(line) {
30397
30522
  const first = cleanPgHost(line.split(/\s/, 1)[0]);
@@ -30661,7 +30786,7 @@ var DockerLogsWatch = class {
30661
30786
  // src/daemon/workers/login-watch.ts
30662
30787
  var import_node_fs35 = require("fs");
30663
30788
  var import_node_child_process12 = require("child_process");
30664
- var import_node_net13 = require("net");
30789
+ var import_node_net14 = require("net");
30665
30790
  var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
30666
30791
  function stringList(value, fallback) {
30667
30792
  if (!Array.isArray(value)) return fallback;
@@ -30706,7 +30831,7 @@ function networkOf(ip) {
30706
30831
  }
30707
30832
  function classifyLogin(login, ctx) {
30708
30833
  const { user, ip } = login;
30709
- if (!user || !(0, import_node_net13.isIP)(ip)) return null;
30834
+ if (!user || !(0, import_node_net14.isIP)(ip)) return null;
30710
30835
  if (isProtected(ip, DEFAULT_PROTECTED)) return null;
30711
30836
  const network = networkOf(ip);
30712
30837
  const reasons = [];
@@ -30744,7 +30869,7 @@ function parseAcceptedLogins2(text) {
30744
30869
  const out = [];
30745
30870
  for (const line of text.split("\n")) {
30746
30871
  const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line);
30747
- if (m && (0, import_node_net13.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
30872
+ if (m && (0, import_node_net14.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
30748
30873
  }
30749
30874
  return out;
30750
30875
  }
@@ -30755,7 +30880,7 @@ function ssPeerIp(field) {
30755
30880
  else host = field.replace(/:\d+$/, "");
30756
30881
  host = host.split("%")[0];
30757
30882
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
30758
- return (0, import_node_net13.isIP)(host) ? host : null;
30883
+ return (0, import_node_net14.isIP)(host) ? host : null;
30759
30884
  }
30760
30885
  function sshdPidsForPeer(ssOutput, ip) {
30761
30886
  const pids = /* @__PURE__ */ new Set();
@@ -31059,7 +31184,7 @@ var LoginWatch = class {
31059
31184
  // src/core/tor-exits.ts
31060
31185
  var import_node_fs36 = require("fs");
31061
31186
  var import_node_path27 = require("path");
31062
- var import_node_net14 = require("net");
31187
+ var import_node_net15 = require("net");
31063
31188
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
31064
31189
  function parseTorExitList(text) {
31065
31190
  const out = /* @__PURE__ */ new Set();
@@ -31067,7 +31192,7 @@ function parseTorExitList(text) {
31067
31192
  const line = raw.trim();
31068
31193
  if (!line || line.startsWith("#")) continue;
31069
31194
  const ip = line.split(/\s+/)[0];
31070
- if ((0, import_node_net14.isIP)(ip)) out.add(normalizeIp(ip));
31195
+ if ((0, import_node_net15.isIP)(ip)) out.add(normalizeIp(ip));
31071
31196
  }
31072
31197
  return out;
31073
31198
  }
@@ -31178,7 +31303,7 @@ var TorExitList = class _TorExitList {
31178
31303
 
31179
31304
  // src/daemon/firewall/tor-block.ts
31180
31305
  var import_node_child_process13 = require("child_process");
31181
- var import_node_net15 = require("net");
31306
+ var import_node_net16 = require("net");
31182
31307
  var TOR_NFT_TABLE = "threatcrush-tor";
31183
31308
  function defaultNftRunner() {
31184
31309
  return (args, stdin) => new Promise((resolve4, reject) => {
@@ -31225,7 +31350,7 @@ var TorExitBlockEnforcer = class {
31225
31350
  await this.teardown();
31226
31351
  return;
31227
31352
  }
31228
- const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net15.isIP)(ip) === 4);
31353
+ const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net16.isIP)(ip) === 4);
31229
31354
  if (ipv4.length === 0) return;
31230
31355
  try {
31231
31356
  await this.apply(ipv4);
@@ -31872,12 +31997,12 @@ var AuthorizedKeysIndex = class {
31872
31997
  };
31873
31998
 
31874
31999
  // src/daemon/ssh-context/ip-intel.ts
31875
- var import_node_net16 = require("net");
32000
+ var import_node_net17 = require("net");
31876
32001
  var import_node_os6 = require("os");
31877
32002
  var import_node_dns2 = require("dns");
31878
32003
  var import_node_fs38 = require("fs");
31879
32004
  function list(entries2) {
31880
- const b = new import_node_net16.BlockList();
32005
+ const b = new import_node_net17.BlockList();
31881
32006
  for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
31882
32007
  return b;
31883
32008
  }
@@ -31892,7 +32017,7 @@ var PRIVATE = list([
31892
32017
  ["fe80::", 10, "ipv6"]
31893
32018
  ]);
31894
32019
  function family(ip) {
31895
- const f = (0, import_node_net16.isIP)(ip);
32020
+ const f = (0, import_node_net17.isIP)(ip);
31896
32021
  return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
31897
32022
  }
31898
32023
  function normalizeIp2(ip) {
@@ -31963,7 +32088,7 @@ var GitHubActionsRanges = class {
31963
32088
  lastTry = 0;
31964
32089
  inflight = null;
31965
32090
  set(cidrs, at) {
31966
- const b = new import_node_net16.BlockList();
32091
+ const b = new import_node_net17.BlockList();
31967
32092
  let n = 0;
31968
32093
  for (const c of cidrs) {
31969
32094
  const [addr, bits] = c.split("/");
@@ -32022,7 +32147,7 @@ function withTimeout2(p, ms) {
32022
32147
  }
32023
32148
  function cymruOriginName2(raw) {
32024
32149
  const ip = normalizeIp2(raw);
32025
- const f = (0, import_node_net16.isIP)(ip);
32150
+ const f = (0, import_node_net17.isIP)(ip);
32026
32151
  if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
32027
32152
  if (f !== 6) return null;
32028
32153
  const parts = ip.split("::");
@@ -32950,14 +33075,14 @@ function loadAllRules(customDir) {
32950
33075
  var import_node_child_process15 = require("child_process");
32951
33076
  var import_node_fs40 = require("fs");
32952
33077
  var import_node_path30 = require("path");
32953
- var import_node_net17 = require("net");
33078
+ var import_node_net18 = require("net");
32954
33079
  function assertValidFirewallIp(ip) {
32955
- if ((0, import_node_net17.isIP)(ip) !== 4) {
33080
+ if ((0, import_node_net18.isIP)(ip) !== 4) {
32956
33081
  throw new Error(`Invalid IPv4 address: ${ip}`);
32957
33082
  }
32958
33083
  }
32959
33084
  function assertBannableIp(ip) {
32960
- if ((0, import_node_net17.isIP)(ip) === 0) {
33085
+ if ((0, import_node_net18.isIP)(ip) === 0) {
32961
33086
  throw new Error(`Invalid IP address: ${ip}`);
32962
33087
  }
32963
33088
  }
@@ -33063,7 +33188,7 @@ var Fail2banAdapter = class {
33063
33188
  const status = this.client(["status", this.jail]);
33064
33189
  const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
33065
33190
  if (!line) return [];
33066
- return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
33191
+ return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
33067
33192
  } catch {
33068
33193
  return [];
33069
33194
  }
@@ -33073,10 +33198,10 @@ var Fail2banAdapter = class {
33073
33198
  function parseBannedList(output) {
33074
33199
  const found = [];
33075
33200
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
33076
- if ((0, import_node_net17.isIP)(match[1]) !== 0) found.push(match[1]);
33201
+ if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
33077
33202
  }
33078
33203
  if (found.length > 0) return found;
33079
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
33204
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
33080
33205
  }
33081
33206
  var NftablesAdapter = class {
33082
33207
  name = "nftables";
@@ -33225,7 +33350,7 @@ function detectFirewallAdapter(backend = "auto") {
33225
33350
  // src/daemon/firewall/remediation.ts
33226
33351
  var import_node_fs41 = require("fs");
33227
33352
  var import_node_child_process16 = require("child_process");
33228
- var import_node_net18 = require("net");
33353
+ var import_node_net19 = require("net");
33229
33354
 
33230
33355
  // src/daemon/firewall/crawlers.ts
33231
33356
  var import_node_dns3 = require("dns");
@@ -33394,7 +33519,7 @@ var RemediationManager = class {
33394
33519
  setTorExitCheck(check) {
33395
33520
  this.isTorExit = check;
33396
33521
  let dropped = 0;
33397
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net18.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
33522
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
33398
33523
  for (const ip of Object.keys(this.operators)) {
33399
33524
  if (!check(ip)) continue;
33400
33525
  delete this.operators[ip];
@@ -33487,7 +33612,7 @@ var RemediationManager = class {
33487
33612
  if (remediation?.action !== "block") return;
33488
33613
  }
33489
33614
  const ip = event.source_ip;
33490
- if (!ip || (0, import_node_net18.isIP)(ip) === 0) return;
33615
+ if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
33491
33616
  const strict = remediation?.override_operator_protection === true;
33492
33617
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
33493
33618
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -33516,7 +33641,7 @@ var RemediationManager = class {
33516
33641
  * 4th offence and so on, clamped to `max_ban_seconds`.
33517
33642
  */
33518
33643
  async ban(ip, reason, opts = {}) {
33519
- if ((0, import_node_net18.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
33644
+ if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
33520
33645
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
33521
33646
  return { ok: false, error: `${ip} is protected and can never be blocked` };
33522
33647
  }
@@ -33793,7 +33918,7 @@ var RemediationManager = class {
33793
33918
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
33794
33919
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
33795
33920
  for (const [ip, at] of Object.entries(saved)) {
33796
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net18.isIP)(ip)) continue;
33921
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
33797
33922
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
33798
33923
  this.operators[ip] = at;
33799
33924
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -34343,6 +34468,12 @@ async function runDaemon() {
34343
34468
  settings: edrSettings(config.edr),
34344
34469
  networkBaselinePath: (0, import_node_path33.join)(PATHS.stateDir, "edr-outbound-executables.json"),
34345
34470
  sourceStatusPath: (0, import_node_path33.join)(PATHS.stateDir, "edr-source.json"),
34471
+ // Every traced connect is checked against the abuse.ch lists: this is what
34472
+ // sees a one-second download or a container calling out, which the
34473
+ // threat-feeds socket snapshot cannot.
34474
+ onConnection: (conn) => {
34475
+ threatFeeds.observeOutbound(conn);
34476
+ },
34346
34477
  log: logLine
34347
34478
  });
34348
34479
  edr.start();