@profullstack/threatcrush 0.17.1 → 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 +15 -1
- package/dist/daemon.js +196 -69
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +203 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
@@ -27038,46 +27038,120 @@ var ThreatFeeds = class {
|
|
|
27038
27038
|
}
|
|
27039
27039
|
this.blocking = false;
|
|
27040
27040
|
}
|
|
27041
|
-
/**
|
|
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))
|
|
27050
|
-
|
|
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") {
|
|
@@ -28932,7 +29037,7 @@ var BpftraceSource = class {
|
|
|
28932
29037
|
this.stderrTail = "";
|
|
28933
29038
|
let child;
|
|
28934
29039
|
try {
|
|
28935
|
-
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 }), {
|
|
28936
29041
|
stdio: ["ignore", "pipe", "pipe"],
|
|
28937
29042
|
shell: false,
|
|
28938
29043
|
env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
|
|
@@ -29024,6 +29129,7 @@ function edrSettings(section) {
|
|
|
29024
29129
|
webServiceUsers: configuredUsers,
|
|
29025
29130
|
tempExecPaths: configuredPaths,
|
|
29026
29131
|
watchNetworkSyscalls: section?.watch_network_syscalls === true,
|
|
29132
|
+
matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
|
|
29027
29133
|
networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
|
|
29028
29134
|
watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
|
|
29029
29135
|
pollMs
|
|
@@ -29170,6 +29276,7 @@ var EdrWatch = class {
|
|
|
29170
29276
|
const options = {
|
|
29171
29277
|
bpftracePath,
|
|
29172
29278
|
network: this.opts.settings.watchNetworkSyscalls,
|
|
29279
|
+
peers: this.opts.settings.matchThreatFeeds,
|
|
29173
29280
|
onEvent: (event) => {
|
|
29174
29281
|
this.handleEbpfEvent(event);
|
|
29175
29282
|
},
|
|
@@ -29182,7 +29289,8 @@ var EdrWatch = class {
|
|
|
29182
29289
|
};
|
|
29183
29290
|
this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
|
|
29184
29291
|
this.setSource("ebpf", reason);
|
|
29185
|
-
|
|
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}`);
|
|
29186
29294
|
this.bpftrace.start();
|
|
29187
29295
|
}
|
|
29188
29296
|
startAuditd(reason) {
|
|
@@ -29242,6 +29350,19 @@ var EdrWatch = class {
|
|
|
29242
29350
|
if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
|
|
29243
29351
|
this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
|
|
29244
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
|
+
}
|
|
29245
29366
|
const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
|
|
29246
29367
|
for (const record of records) {
|
|
29247
29368
|
const threat = this.classify(record);
|
|
@@ -29456,7 +29577,7 @@ var import_node_child_process11 = require("child_process");
|
|
|
29456
29577
|
|
|
29457
29578
|
// src/core/asn.ts
|
|
29458
29579
|
var import_node_dns = require("dns");
|
|
29459
|
-
var
|
|
29580
|
+
var import_node_net12 = require("net");
|
|
29460
29581
|
var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
|
|
29461
29582
|
var HOSTING_ASNS = /* @__PURE__ */ new Set([
|
|
29462
29583
|
15169,
|
|
@@ -29575,7 +29696,7 @@ var AsnLookup = class {
|
|
|
29575
29696
|
now;
|
|
29576
29697
|
cache = /* @__PURE__ */ new Map();
|
|
29577
29698
|
async lookup(ip) {
|
|
29578
|
-
if ((0,
|
|
29699
|
+
if ((0, import_node_net12.isIP)(ip) === 0) return null;
|
|
29579
29700
|
const hit = this.cache.get(ip);
|
|
29580
29701
|
if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
|
|
29581
29702
|
let info = null;
|
|
@@ -30026,7 +30147,7 @@ var LightningWatch = class {
|
|
|
30026
30147
|
// src/daemon/workers/docker-logs.ts
|
|
30027
30148
|
var import_node_fs34 = require("fs");
|
|
30028
30149
|
var import_node_http = require("http");
|
|
30029
|
-
var
|
|
30150
|
+
var import_node_net13 = require("net");
|
|
30030
30151
|
|
|
30031
30152
|
// src/daemon/workers/postgres-shell.ts
|
|
30032
30153
|
var import_node_fs33 = require("fs");
|
|
@@ -30391,7 +30512,7 @@ function cleanPgHost(raw) {
|
|
|
30391
30512
|
if (!raw) return void 0;
|
|
30392
30513
|
let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
|
|
30393
30514
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
30394
|
-
return (0,
|
|
30515
|
+
return (0, import_node_net13.isIP)(host) ? host : void 0;
|
|
30395
30516
|
}
|
|
30396
30517
|
function prefixHost(line) {
|
|
30397
30518
|
const first = cleanPgHost(line.split(/\s/, 1)[0]);
|
|
@@ -30661,7 +30782,7 @@ var DockerLogsWatch = class {
|
|
|
30661
30782
|
// src/daemon/workers/login-watch.ts
|
|
30662
30783
|
var import_node_fs35 = require("fs");
|
|
30663
30784
|
var import_node_child_process12 = require("child_process");
|
|
30664
|
-
var
|
|
30785
|
+
var import_node_net14 = require("net");
|
|
30665
30786
|
var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
|
|
30666
30787
|
function stringList(value, fallback) {
|
|
30667
30788
|
if (!Array.isArray(value)) return fallback;
|
|
@@ -30706,7 +30827,7 @@ function networkOf(ip) {
|
|
|
30706
30827
|
}
|
|
30707
30828
|
function classifyLogin(login, ctx) {
|
|
30708
30829
|
const { user, ip } = login;
|
|
30709
|
-
if (!user || !(0,
|
|
30830
|
+
if (!user || !(0, import_node_net14.isIP)(ip)) return null;
|
|
30710
30831
|
if (isProtected(ip, DEFAULT_PROTECTED)) return null;
|
|
30711
30832
|
const network = networkOf(ip);
|
|
30712
30833
|
const reasons = [];
|
|
@@ -30744,7 +30865,7 @@ function parseAcceptedLogins2(text) {
|
|
|
30744
30865
|
const out = [];
|
|
30745
30866
|
for (const line of text.split("\n")) {
|
|
30746
30867
|
const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line);
|
|
30747
|
-
if (m && (0,
|
|
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) });
|
|
30748
30869
|
}
|
|
30749
30870
|
return out;
|
|
30750
30871
|
}
|
|
@@ -30755,7 +30876,7 @@ function ssPeerIp(field) {
|
|
|
30755
30876
|
else host = field.replace(/:\d+$/, "");
|
|
30756
30877
|
host = host.split("%")[0];
|
|
30757
30878
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
30758
|
-
return (0,
|
|
30879
|
+
return (0, import_node_net14.isIP)(host) ? host : null;
|
|
30759
30880
|
}
|
|
30760
30881
|
function sshdPidsForPeer(ssOutput, ip) {
|
|
30761
30882
|
const pids = /* @__PURE__ */ new Set();
|
|
@@ -31059,7 +31180,7 @@ var LoginWatch = class {
|
|
|
31059
31180
|
// src/core/tor-exits.ts
|
|
31060
31181
|
var import_node_fs36 = require("fs");
|
|
31061
31182
|
var import_node_path27 = require("path");
|
|
31062
|
-
var
|
|
31183
|
+
var import_node_net15 = require("net");
|
|
31063
31184
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
31064
31185
|
function parseTorExitList(text) {
|
|
31065
31186
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -31067,7 +31188,7 @@ function parseTorExitList(text) {
|
|
|
31067
31188
|
const line = raw.trim();
|
|
31068
31189
|
if (!line || line.startsWith("#")) continue;
|
|
31069
31190
|
const ip = line.split(/\s+/)[0];
|
|
31070
|
-
if ((0,
|
|
31191
|
+
if ((0, import_node_net15.isIP)(ip)) out.add(normalizeIp(ip));
|
|
31071
31192
|
}
|
|
31072
31193
|
return out;
|
|
31073
31194
|
}
|
|
@@ -31178,7 +31299,7 @@ var TorExitList = class _TorExitList {
|
|
|
31178
31299
|
|
|
31179
31300
|
// src/daemon/firewall/tor-block.ts
|
|
31180
31301
|
var import_node_child_process13 = require("child_process");
|
|
31181
|
-
var
|
|
31302
|
+
var import_node_net16 = require("net");
|
|
31182
31303
|
var TOR_NFT_TABLE = "threatcrush-tor";
|
|
31183
31304
|
function defaultNftRunner() {
|
|
31184
31305
|
return (args, stdin) => new Promise((resolve4, reject) => {
|
|
@@ -31225,7 +31346,7 @@ var TorExitBlockEnforcer = class {
|
|
|
31225
31346
|
await this.teardown();
|
|
31226
31347
|
return;
|
|
31227
31348
|
}
|
|
31228
|
-
const ipv4 = this.opts.exits.values().filter((ip) => (0,
|
|
31349
|
+
const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net16.isIP)(ip) === 4);
|
|
31229
31350
|
if (ipv4.length === 0) return;
|
|
31230
31351
|
try {
|
|
31231
31352
|
await this.apply(ipv4);
|
|
@@ -31872,12 +31993,12 @@ var AuthorizedKeysIndex = class {
|
|
|
31872
31993
|
};
|
|
31873
31994
|
|
|
31874
31995
|
// src/daemon/ssh-context/ip-intel.ts
|
|
31875
|
-
var
|
|
31996
|
+
var import_node_net17 = require("net");
|
|
31876
31997
|
var import_node_os6 = require("os");
|
|
31877
31998
|
var import_node_dns2 = require("dns");
|
|
31878
31999
|
var import_node_fs38 = require("fs");
|
|
31879
32000
|
function list(entries2) {
|
|
31880
|
-
const b = new
|
|
32001
|
+
const b = new import_node_net17.BlockList();
|
|
31881
32002
|
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
31882
32003
|
return b;
|
|
31883
32004
|
}
|
|
@@ -31892,7 +32013,7 @@ var PRIVATE = list([
|
|
|
31892
32013
|
["fe80::", 10, "ipv6"]
|
|
31893
32014
|
]);
|
|
31894
32015
|
function family(ip) {
|
|
31895
|
-
const f = (0,
|
|
32016
|
+
const f = (0, import_node_net17.isIP)(ip);
|
|
31896
32017
|
return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
|
|
31897
32018
|
}
|
|
31898
32019
|
function normalizeIp2(ip) {
|
|
@@ -31963,7 +32084,7 @@ var GitHubActionsRanges = class {
|
|
|
31963
32084
|
lastTry = 0;
|
|
31964
32085
|
inflight = null;
|
|
31965
32086
|
set(cidrs, at) {
|
|
31966
|
-
const b = new
|
|
32087
|
+
const b = new import_node_net17.BlockList();
|
|
31967
32088
|
let n = 0;
|
|
31968
32089
|
for (const c of cidrs) {
|
|
31969
32090
|
const [addr, bits] = c.split("/");
|
|
@@ -32022,7 +32143,7 @@ function withTimeout2(p, ms) {
|
|
|
32022
32143
|
}
|
|
32023
32144
|
function cymruOriginName2(raw) {
|
|
32024
32145
|
const ip = normalizeIp2(raw);
|
|
32025
|
-
const f = (0,
|
|
32146
|
+
const f = (0, import_node_net17.isIP)(ip);
|
|
32026
32147
|
if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
|
|
32027
32148
|
if (f !== 6) return null;
|
|
32028
32149
|
const parts = ip.split("::");
|
|
@@ -32950,14 +33071,14 @@ function loadAllRules(customDir) {
|
|
|
32950
33071
|
var import_node_child_process15 = require("child_process");
|
|
32951
33072
|
var import_node_fs40 = require("fs");
|
|
32952
33073
|
var import_node_path30 = require("path");
|
|
32953
|
-
var
|
|
33074
|
+
var import_node_net18 = require("net");
|
|
32954
33075
|
function assertValidFirewallIp(ip) {
|
|
32955
|
-
if ((0,
|
|
33076
|
+
if ((0, import_node_net18.isIP)(ip) !== 4) {
|
|
32956
33077
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
32957
33078
|
}
|
|
32958
33079
|
}
|
|
32959
33080
|
function assertBannableIp(ip) {
|
|
32960
|
-
if ((0,
|
|
33081
|
+
if ((0, import_node_net18.isIP)(ip) === 0) {
|
|
32961
33082
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
32962
33083
|
}
|
|
32963
33084
|
}
|
|
@@ -33063,7 +33184,7 @@ var Fail2banAdapter = class {
|
|
|
33063
33184
|
const status = this.client(["status", this.jail]);
|
|
33064
33185
|
const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
33065
33186
|
if (!line) return [];
|
|
33066
|
-
return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
33187
|
+
return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
|
|
33067
33188
|
} catch {
|
|
33068
33189
|
return [];
|
|
33069
33190
|
}
|
|
@@ -33073,10 +33194,10 @@ var Fail2banAdapter = class {
|
|
|
33073
33194
|
function parseBannedList(output) {
|
|
33074
33195
|
const found = [];
|
|
33075
33196
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
33076
|
-
if ((0,
|
|
33197
|
+
if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
33077
33198
|
}
|
|
33078
33199
|
if (found.length > 0) return found;
|
|
33079
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
33200
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
|
|
33080
33201
|
}
|
|
33081
33202
|
var NftablesAdapter = class {
|
|
33082
33203
|
name = "nftables";
|
|
@@ -33225,7 +33346,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
33225
33346
|
// src/daemon/firewall/remediation.ts
|
|
33226
33347
|
var import_node_fs41 = require("fs");
|
|
33227
33348
|
var import_node_child_process16 = require("child_process");
|
|
33228
|
-
var
|
|
33349
|
+
var import_node_net19 = require("net");
|
|
33229
33350
|
|
|
33230
33351
|
// src/daemon/firewall/crawlers.ts
|
|
33231
33352
|
var import_node_dns3 = require("dns");
|
|
@@ -33394,7 +33515,7 @@ var RemediationManager = class {
|
|
|
33394
33515
|
setTorExitCheck(check) {
|
|
33395
33516
|
this.isTorExit = check;
|
|
33396
33517
|
let dropped = 0;
|
|
33397
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
33518
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
33398
33519
|
for (const ip of Object.keys(this.operators)) {
|
|
33399
33520
|
if (!check(ip)) continue;
|
|
33400
33521
|
delete this.operators[ip];
|
|
@@ -33487,7 +33608,7 @@ var RemediationManager = class {
|
|
|
33487
33608
|
if (remediation?.action !== "block") return;
|
|
33488
33609
|
}
|
|
33489
33610
|
const ip = event.source_ip;
|
|
33490
|
-
if (!ip || (0,
|
|
33611
|
+
if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
|
|
33491
33612
|
const strict = remediation?.override_operator_protection === true;
|
|
33492
33613
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
33493
33614
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -33516,7 +33637,7 @@ var RemediationManager = class {
|
|
|
33516
33637
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
33517
33638
|
*/
|
|
33518
33639
|
async ban(ip, reason, opts = {}) {
|
|
33519
|
-
if ((0,
|
|
33640
|
+
if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
33520
33641
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
33521
33642
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
33522
33643
|
}
|
|
@@ -33793,7 +33914,7 @@ var RemediationManager = class {
|
|
|
33793
33914
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
33794
33915
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
33795
33916
|
for (const [ip, at] of Object.entries(saved)) {
|
|
33796
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
33917
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
|
|
33797
33918
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
33798
33919
|
this.operators[ip] = at;
|
|
33799
33920
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -34343,6 +34464,12 @@ async function runDaemon() {
|
|
|
34343
34464
|
settings: edrSettings(config.edr),
|
|
34344
34465
|
networkBaselinePath: (0, import_node_path33.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
34345
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
|
+
},
|
|
34346
34473
|
log: logLine
|
|
34347
34474
|
});
|
|
34348
34475
|
edr.start();
|