@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/README.md CHANGED
@@ -670,7 +670,21 @@ 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
690
  (`/sys/kernel/btf/vmlinux`). `source = "auto"` picks eBPF when all three are
package/dist/daemon.js CHANGED
@@ -26897,8 +26897,8 @@ function parseListeningPorts(text) {
26897
26897
  const ports = /* @__PURE__ */ new Set();
26898
26898
  for (const line of text.split("\n")) {
26899
26899
  const cols = line.trim().split(/\s+/);
26900
- const local = cols.length >= 4 ? splitAddr(cols[3]) : null;
26901
- if (local) ports.add(local.port);
26900
+ const m = cols.length >= 4 ? /:(\d+)$/.exec(cols[3]) : null;
26901
+ if (m) ports.add(Number(m[1]));
26902
26902
  }
26903
26903
  return ports;
26904
26904
  }
@@ -27038,45 +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
- state: c.state,
27071
- process: c.process,
27072
- pid: c.pid,
27073
- malware: ind.malware,
27074
- threat: ind.threat,
27075
- feed: ind.feed,
27076
- blocked: this.blocking
27077
- }
27078
- });
27055
+ if (listening.has(c.localPort)) this.reportInbound(c);
27056
+ else this.reportOutbound({ ...c, seenBy: "ss" });
27079
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();
27080
27155
  for (const [key, at] of this.alerted) if (now - at > REALERT_MS) this.alerted.delete(key);
27081
27156
  }
27082
27157
  };
@@ -28693,14 +28768,18 @@ var import_node_child_process10 = require("child_process");
28693
28768
  // src/daemon/workers/edr-ebpf.ts
28694
28769
  var import_node_child_process9 = require("child_process");
28695
28770
  var import_node_fs28 = require("fs");
28771
+ var import_node_net11 = require("net");
28696
28772
  var import_node_path24 = require("path");
28697
28773
  var BPFTRACE_RECORD_TAG = "TC1";
28698
28774
  var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
28699
28775
  var TCP_SYN_SENT = 2;
28700
28776
  var TCP_LISTEN = 10;
28701
28777
  var IPPROTO_TCP = 6;
28778
+ var AF_INET = 2;
28779
+ var AF_INET6 = 10;
28702
28780
  function bpftraceScript(opts) {
28703
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"`;
28704
28783
  const lines = [
28705
28784
  "tracepoint:sched:sched_process_exec",
28706
28785
  "{",
@@ -28708,12 +28787,29 @@ function bpftraceScript(opts) {
28708
28787
  "}"
28709
28788
  ];
28710
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
+ }
28711
28812
  lines.push(
28712
- "tracepoint:sock:inet_sock_set_state",
28713
- `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
28714
- "{",
28715
- ` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
28716
- "}",
28717
28813
  "tracepoint:sock:inet_sock_set_state",
28718
28814
  `/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_LISTEN}/`,
28719
28815
  "{",
@@ -28740,12 +28836,22 @@ function parseRecordText(text) {
28740
28836
  }
28741
28837
  const [tag, kind, pidText, ppidText, euidText] = parts;
28742
28838
  if (tag !== BPFTRACE_RECORD_TAG) return null;
28743
- if (kind !== "exec" && kind !== "connect" && kind !== "listen") return null;
28839
+ if (kind !== "exec" && kind !== "connect" && kind !== "connectp" && kind !== "listen") return null;
28744
28840
  const pid = Number(pidText);
28745
28841
  const ppid = Number(ppidText);
28746
28842
  const euid = Number(euidText);
28747
28843
  if (!/^\d+$/.test(pidText) || !/^\d+$/.test(ppidText) || !/^\d+$/.test(euidText)) return null;
28748
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
+ }
28749
28855
  const value = rest.slice(0, MAX_FIELD);
28750
28856
  if (!value) return null;
28751
28857
  if (kind === "exec") {
@@ -28931,7 +29037,7 @@ var BpftraceSource = class {
28931
29037
  this.stderrTail = "";
28932
29038
  let child;
28933
29039
  try {
28934
- child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network }), {
29040
+ child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network, peers: this.opts.peers }), {
28935
29041
  stdio: ["ignore", "pipe", "pipe"],
28936
29042
  shell: false,
28937
29043
  env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
@@ -29023,6 +29129,7 @@ function edrSettings(section) {
29023
29129
  webServiceUsers: configuredUsers,
29024
29130
  tempExecPaths: configuredPaths,
29025
29131
  watchNetworkSyscalls: section?.watch_network_syscalls === true,
29132
+ matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
29026
29133
  networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
29027
29134
  watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
29028
29135
  pollMs
@@ -29169,6 +29276,7 @@ var EdrWatch = class {
29169
29276
  const options = {
29170
29277
  bpftracePath,
29171
29278
  network: this.opts.settings.watchNetworkSyscalls,
29279
+ peers: this.opts.settings.matchThreatFeeds,
29172
29280
  onEvent: (event) => {
29173
29281
  this.handleEbpfEvent(event);
29174
29282
  },
@@ -29181,7 +29289,8 @@ var EdrWatch = class {
29181
29289
  };
29182
29290
  this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
29183
29291
  this.setSource("ebpf", reason);
29184
- 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`);
29292
+ 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";
29293
+ this.opts.log(`[edr] event source: eBPF via ${bpftracePath} (exec${this.opts.settings.watchNetworkSyscalls ? ", tcp connect/listen" : ""}); ${addresses}`);
29185
29294
  this.bpftrace.start();
29186
29295
  }
29187
29296
  startAuditd(reason) {
@@ -29241,6 +29350,19 @@ var EdrWatch = class {
29241
29350
  if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
29242
29351
  this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
29243
29352
  const resolver = resolveExe ?? (() => this.resolveEbpfExe(event));
29353
+ if (event.kind === "connect" && event.peerIp && event.peerPort !== void 0 && this.opts.settings.matchThreatFeeds && this.opts.onConnection) {
29354
+ try {
29355
+ this.opts.onConnection({
29356
+ peerIp: event.peerIp,
29357
+ peerPort: event.peerPort,
29358
+ pid: event.pid,
29359
+ comm: event.comm,
29360
+ euid: event.euid,
29361
+ resolveExecutable: () => resolver(event.pid)
29362
+ });
29363
+ } catch {
29364
+ }
29365
+ }
29244
29366
  const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
29245
29367
  for (const record of records) {
29246
29368
  const threat = this.classify(record);
@@ -29455,7 +29577,7 @@ var import_node_child_process11 = require("child_process");
29455
29577
 
29456
29578
  // src/core/asn.ts
29457
29579
  var import_node_dns = require("dns");
29458
- var import_node_net11 = require("net");
29580
+ var import_node_net12 = require("net");
29459
29581
  var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
29460
29582
  var HOSTING_ASNS = /* @__PURE__ */ new Set([
29461
29583
  15169,
@@ -29574,7 +29696,7 @@ var AsnLookup = class {
29574
29696
  now;
29575
29697
  cache = /* @__PURE__ */ new Map();
29576
29698
  async lookup(ip) {
29577
- if ((0, import_node_net11.isIP)(ip) === 0) return null;
29699
+ if ((0, import_node_net12.isIP)(ip) === 0) return null;
29578
29700
  const hit = this.cache.get(ip);
29579
29701
  if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
29580
29702
  let info = null;
@@ -30025,7 +30147,7 @@ var LightningWatch = class {
30025
30147
  // src/daemon/workers/docker-logs.ts
30026
30148
  var import_node_fs34 = require("fs");
30027
30149
  var import_node_http = require("http");
30028
- var import_node_net12 = require("net");
30150
+ var import_node_net13 = require("net");
30029
30151
 
30030
30152
  // src/daemon/workers/postgres-shell.ts
30031
30153
  var import_node_fs33 = require("fs");
@@ -30390,7 +30512,7 @@ function cleanPgHost(raw) {
30390
30512
  if (!raw) return void 0;
30391
30513
  let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
30392
30514
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
30393
- return (0, import_node_net12.isIP)(host) ? host : void 0;
30515
+ return (0, import_node_net13.isIP)(host) ? host : void 0;
30394
30516
  }
30395
30517
  function prefixHost(line) {
30396
30518
  const first = cleanPgHost(line.split(/\s/, 1)[0]);
@@ -30660,7 +30782,7 @@ var DockerLogsWatch = class {
30660
30782
  // src/daemon/workers/login-watch.ts
30661
30783
  var import_node_fs35 = require("fs");
30662
30784
  var import_node_child_process12 = require("child_process");
30663
- var import_node_net13 = require("net");
30785
+ var import_node_net14 = require("net");
30664
30786
  var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
30665
30787
  function stringList(value, fallback) {
30666
30788
  if (!Array.isArray(value)) return fallback;
@@ -30705,7 +30827,7 @@ function networkOf(ip) {
30705
30827
  }
30706
30828
  function classifyLogin(login, ctx) {
30707
30829
  const { user, ip } = login;
30708
- if (!user || !(0, import_node_net13.isIP)(ip)) return null;
30830
+ if (!user || !(0, import_node_net14.isIP)(ip)) return null;
30709
30831
  if (isProtected(ip, DEFAULT_PROTECTED)) return null;
30710
30832
  const network = networkOf(ip);
30711
30833
  const reasons = [];
@@ -30743,7 +30865,7 @@ function parseAcceptedLogins2(text) {
30743
30865
  const out = [];
30744
30866
  for (const line of text.split("\n")) {
30745
30867
  const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line);
30746
- if (m && (0, import_node_net13.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
30868
+ if (m && (0, import_node_net14.isIP)(m[3])) out.push({ user: m[2], ip: m[3], at: Math.round(Number(m[1]) * 1e3) });
30747
30869
  }
30748
30870
  return out;
30749
30871
  }
@@ -30754,7 +30876,7 @@ function ssPeerIp(field) {
30754
30876
  else host = field.replace(/:\d+$/, "");
30755
30877
  host = host.split("%")[0];
30756
30878
  if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
30757
- return (0, import_node_net13.isIP)(host) ? host : null;
30879
+ return (0, import_node_net14.isIP)(host) ? host : null;
30758
30880
  }
30759
30881
  function sshdPidsForPeer(ssOutput, ip) {
30760
30882
  const pids = /* @__PURE__ */ new Set();
@@ -31058,7 +31180,7 @@ var LoginWatch = class {
31058
31180
  // src/core/tor-exits.ts
31059
31181
  var import_node_fs36 = require("fs");
31060
31182
  var import_node_path27 = require("path");
31061
- var import_node_net14 = require("net");
31183
+ var import_node_net15 = require("net");
31062
31184
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
31063
31185
  function parseTorExitList(text) {
31064
31186
  const out = /* @__PURE__ */ new Set();
@@ -31066,7 +31188,7 @@ function parseTorExitList(text) {
31066
31188
  const line = raw.trim();
31067
31189
  if (!line || line.startsWith("#")) continue;
31068
31190
  const ip = line.split(/\s+/)[0];
31069
- if ((0, import_node_net14.isIP)(ip)) out.add(normalizeIp(ip));
31191
+ if ((0, import_node_net15.isIP)(ip)) out.add(normalizeIp(ip));
31070
31192
  }
31071
31193
  return out;
31072
31194
  }
@@ -31177,7 +31299,7 @@ var TorExitList = class _TorExitList {
31177
31299
 
31178
31300
  // src/daemon/firewall/tor-block.ts
31179
31301
  var import_node_child_process13 = require("child_process");
31180
- var import_node_net15 = require("net");
31302
+ var import_node_net16 = require("net");
31181
31303
  var TOR_NFT_TABLE = "threatcrush-tor";
31182
31304
  function defaultNftRunner() {
31183
31305
  return (args, stdin) => new Promise((resolve4, reject) => {
@@ -31224,7 +31346,7 @@ var TorExitBlockEnforcer = class {
31224
31346
  await this.teardown();
31225
31347
  return;
31226
31348
  }
31227
- const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net15.isIP)(ip) === 4);
31349
+ const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net16.isIP)(ip) === 4);
31228
31350
  if (ipv4.length === 0) return;
31229
31351
  try {
31230
31352
  await this.apply(ipv4);
@@ -31871,12 +31993,12 @@ var AuthorizedKeysIndex = class {
31871
31993
  };
31872
31994
 
31873
31995
  // src/daemon/ssh-context/ip-intel.ts
31874
- var import_node_net16 = require("net");
31996
+ var import_node_net17 = require("net");
31875
31997
  var import_node_os6 = require("os");
31876
31998
  var import_node_dns2 = require("dns");
31877
31999
  var import_node_fs38 = require("fs");
31878
32000
  function list(entries2) {
31879
- const b = new import_node_net16.BlockList();
32001
+ const b = new import_node_net17.BlockList();
31880
32002
  for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
31881
32003
  return b;
31882
32004
  }
@@ -31891,7 +32013,7 @@ var PRIVATE = list([
31891
32013
  ["fe80::", 10, "ipv6"]
31892
32014
  ]);
31893
32015
  function family(ip) {
31894
- const f = (0, import_node_net16.isIP)(ip);
32016
+ const f = (0, import_node_net17.isIP)(ip);
31895
32017
  return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
31896
32018
  }
31897
32019
  function normalizeIp2(ip) {
@@ -31962,7 +32084,7 @@ var GitHubActionsRanges = class {
31962
32084
  lastTry = 0;
31963
32085
  inflight = null;
31964
32086
  set(cidrs, at) {
31965
- const b = new import_node_net16.BlockList();
32087
+ const b = new import_node_net17.BlockList();
31966
32088
  let n = 0;
31967
32089
  for (const c of cidrs) {
31968
32090
  const [addr, bits] = c.split("/");
@@ -32021,7 +32143,7 @@ function withTimeout2(p, ms) {
32021
32143
  }
32022
32144
  function cymruOriginName2(raw) {
32023
32145
  const ip = normalizeIp2(raw);
32024
- const f = (0, import_node_net16.isIP)(ip);
32146
+ const f = (0, import_node_net17.isIP)(ip);
32025
32147
  if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
32026
32148
  if (f !== 6) return null;
32027
32149
  const parts = ip.split("::");
@@ -32949,14 +33071,14 @@ function loadAllRules(customDir) {
32949
33071
  var import_node_child_process15 = require("child_process");
32950
33072
  var import_node_fs40 = require("fs");
32951
33073
  var import_node_path30 = require("path");
32952
- var import_node_net17 = require("net");
33074
+ var import_node_net18 = require("net");
32953
33075
  function assertValidFirewallIp(ip) {
32954
- if ((0, import_node_net17.isIP)(ip) !== 4) {
33076
+ if ((0, import_node_net18.isIP)(ip) !== 4) {
32955
33077
  throw new Error(`Invalid IPv4 address: ${ip}`);
32956
33078
  }
32957
33079
  }
32958
33080
  function assertBannableIp(ip) {
32959
- if ((0, import_node_net17.isIP)(ip) === 0) {
33081
+ if ((0, import_node_net18.isIP)(ip) === 0) {
32960
33082
  throw new Error(`Invalid IP address: ${ip}`);
32961
33083
  }
32962
33084
  }
@@ -33062,7 +33184,7 @@ var Fail2banAdapter = class {
33062
33184
  const status = this.client(["status", this.jail]);
33063
33185
  const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
33064
33186
  if (!line) return [];
33065
- return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
33187
+ return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
33066
33188
  } catch {
33067
33189
  return [];
33068
33190
  }
@@ -33072,10 +33194,10 @@ var Fail2banAdapter = class {
33072
33194
  function parseBannedList(output) {
33073
33195
  const found = [];
33074
33196
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
33075
- if ((0, import_node_net17.isIP)(match[1]) !== 0) found.push(match[1]);
33197
+ if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
33076
33198
  }
33077
33199
  if (found.length > 0) return found;
33078
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
33200
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
33079
33201
  }
33080
33202
  var NftablesAdapter = class {
33081
33203
  name = "nftables";
@@ -33224,7 +33346,7 @@ function detectFirewallAdapter(backend = "auto") {
33224
33346
  // src/daemon/firewall/remediation.ts
33225
33347
  var import_node_fs41 = require("fs");
33226
33348
  var import_node_child_process16 = require("child_process");
33227
- var import_node_net18 = require("net");
33349
+ var import_node_net19 = require("net");
33228
33350
 
33229
33351
  // src/daemon/firewall/crawlers.ts
33230
33352
  var import_node_dns3 = require("dns");
@@ -33393,7 +33515,7 @@ var RemediationManager = class {
33393
33515
  setTorExitCheck(check) {
33394
33516
  this.isTorExit = check;
33395
33517
  let dropped = 0;
33396
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net18.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
33518
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
33397
33519
  for (const ip of Object.keys(this.operators)) {
33398
33520
  if (!check(ip)) continue;
33399
33521
  delete this.operators[ip];
@@ -33486,7 +33608,7 @@ var RemediationManager = class {
33486
33608
  if (remediation?.action !== "block") return;
33487
33609
  }
33488
33610
  const ip = event.source_ip;
33489
- if (!ip || (0, import_node_net18.isIP)(ip) === 0) return;
33611
+ if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
33490
33612
  const strict = remediation?.override_operator_protection === true;
33491
33613
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
33492
33614
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -33515,7 +33637,7 @@ var RemediationManager = class {
33515
33637
  * 4th offence and so on, clamped to `max_ban_seconds`.
33516
33638
  */
33517
33639
  async ban(ip, reason, opts = {}) {
33518
- if ((0, import_node_net18.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
33640
+ if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
33519
33641
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
33520
33642
  return { ok: false, error: `${ip} is protected and can never be blocked` };
33521
33643
  }
@@ -33792,7 +33914,7 @@ var RemediationManager = class {
33792
33914
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
33793
33915
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
33794
33916
  for (const [ip, at] of Object.entries(saved)) {
33795
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net18.isIP)(ip)) continue;
33917
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
33796
33918
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
33797
33919
  this.operators[ip] = at;
33798
33920
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -34342,6 +34464,12 @@ async function runDaemon() {
34342
34464
  settings: edrSettings(config.edr),
34343
34465
  networkBaselinePath: (0, import_node_path33.join)(PATHS.stateDir, "edr-outbound-executables.json"),
34344
34466
  sourceStatusPath: (0, import_node_path33.join)(PATHS.stateDir, "edr-source.json"),
34467
+ // Every traced connect is checked against the abuse.ch lists: this is what
34468
+ // sees a one-second download or a container calling out, which the
34469
+ // threat-feeds socket snapshot cannot.
34470
+ onConnection: (conn) => {
34471
+ threatFeeds.observeOutbound(conn);
34472
+ },
34345
34473
  log: logLine
34346
34474
  });
34347
34475
  edr.start();