@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/dist/index.js
CHANGED
|
@@ -60129,46 +60129,120 @@ var ThreatFeeds = class {
|
|
|
60129
60129
|
}
|
|
60130
60130
|
this.blocking = false;
|
|
60131
60131
|
}
|
|
60132
|
-
/**
|
|
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))
|
|
60141
|
-
|
|
60142
|
-
|
|
60143
|
-
|
|
60144
|
-
|
|
60145
|
-
|
|
60146
|
-
|
|
60147
|
-
|
|
60148
|
-
|
|
60149
|
-
|
|
60150
|
-
|
|
60151
|
-
|
|
60152
|
-
|
|
60153
|
-
|
|
60154
|
-
|
|
60155
|
-
|
|
60156
|
-
// stays the only enforcement.
|
|
60157
|
-
details: {
|
|
60158
|
-
rule_id: "threat-feed-outbound",
|
|
60159
|
-
destination_ip: c.peerIp,
|
|
60160
|
-
destination_port: c.peerPort,
|
|
60161
|
-
local_port: c.localPort,
|
|
60162
|
-
state: c.state,
|
|
60163
|
-
process: c.process,
|
|
60164
|
-
pid: c.pid,
|
|
60165
|
-
malware: ind.malware,
|
|
60166
|
-
threat: ind.threat,
|
|
60167
|
-
feed: ind.feed,
|
|
60168
|
-
blocked: this.blocking
|
|
60169
|
-
}
|
|
60170
|
-
});
|
|
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 {
|
|
60171
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();
|
|
60172
60246
|
for (const [key, at] of this.alerted) if (now - at > REALERT_MS) this.alerted.delete(key);
|
|
60173
60247
|
}
|
|
60174
60248
|
};
|
|
@@ -61788,14 +61862,18 @@ var import_node_child_process20 = require("child_process");
|
|
|
61788
61862
|
// src/daemon/workers/edr-ebpf.ts
|
|
61789
61863
|
var import_node_child_process19 = require("child_process");
|
|
61790
61864
|
var import_node_fs55 = require("fs");
|
|
61865
|
+
var import_node_net17 = require("net");
|
|
61791
61866
|
var import_node_path41 = require("path");
|
|
61792
61867
|
var BPFTRACE_RECORD_TAG = "TC1";
|
|
61793
61868
|
var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
|
|
61794
61869
|
var TCP_SYN_SENT = 2;
|
|
61795
61870
|
var TCP_LISTEN = 10;
|
|
61796
61871
|
var IPPROTO_TCP = 6;
|
|
61872
|
+
var AF_INET = 2;
|
|
61873
|
+
var AF_INET6 = 10;
|
|
61797
61874
|
function bpftraceScript(opts) {
|
|
61798
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"`;
|
|
61799
61877
|
const lines = [
|
|
61800
61878
|
"tracepoint:sched:sched_process_exec",
|
|
61801
61879
|
"{",
|
|
@@ -61803,12 +61881,29 @@ function bpftraceScript(opts) {
|
|
|
61803
61881
|
"}"
|
|
61804
61882
|
];
|
|
61805
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
|
+
}
|
|
61806
61906
|
lines.push(
|
|
61807
|
-
"tracepoint:sock:inet_sock_set_state",
|
|
61808
|
-
`/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_SYN_SENT}/`,
|
|
61809
|
-
"{",
|
|
61810
|
-
` printf(${prefix}, "connect", pid, curtask->real_parent->tgid, curtask->cred->euid.val, comm);`,
|
|
61811
|
-
"}",
|
|
61812
61907
|
"tracepoint:sock:inet_sock_set_state",
|
|
61813
61908
|
`/args.protocol == ${IPPROTO_TCP} && args.newstate == ${TCP_LISTEN}/`,
|
|
61814
61909
|
"{",
|
|
@@ -61835,12 +61930,22 @@ function parseRecordText(text) {
|
|
|
61835
61930
|
}
|
|
61836
61931
|
const [tag, kind, pidText, ppidText, euidText] = parts;
|
|
61837
61932
|
if (tag !== BPFTRACE_RECORD_TAG) return null;
|
|
61838
|
-
if (kind !== "exec" && kind !== "connect" && kind !== "listen") return null;
|
|
61933
|
+
if (kind !== "exec" && kind !== "connect" && kind !== "connectp" && kind !== "listen") return null;
|
|
61839
61934
|
const pid = Number(pidText);
|
|
61840
61935
|
const ppid = Number(ppidText);
|
|
61841
61936
|
const euid = Number(euidText);
|
|
61842
61937
|
if (!/^\d+$/.test(pidText) || !/^\d+$/.test(ppidText) || !/^\d+$/.test(euidText)) return null;
|
|
61843
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
|
+
}
|
|
61844
61949
|
const value = rest.slice(0, MAX_FIELD);
|
|
61845
61950
|
if (!value) return null;
|
|
61846
61951
|
if (kind === "exec") {
|
|
@@ -62026,7 +62131,7 @@ var BpftraceSource = class {
|
|
|
62026
62131
|
this.stderrTail = "";
|
|
62027
62132
|
let child;
|
|
62028
62133
|
try {
|
|
62029
|
-
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 }), {
|
|
62030
62135
|
stdio: ["ignore", "pipe", "pipe"],
|
|
62031
62136
|
shell: false,
|
|
62032
62137
|
env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
|
|
@@ -62118,6 +62223,7 @@ function edrSettings(section) {
|
|
|
62118
62223
|
webServiceUsers: configuredUsers,
|
|
62119
62224
|
tempExecPaths: configuredPaths,
|
|
62120
62225
|
watchNetworkSyscalls: section?.watch_network_syscalls === true,
|
|
62226
|
+
matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
|
|
62121
62227
|
networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
|
|
62122
62228
|
watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
|
|
62123
62229
|
pollMs
|
|
@@ -62273,6 +62379,7 @@ var EdrWatch = class {
|
|
|
62273
62379
|
const options = {
|
|
62274
62380
|
bpftracePath,
|
|
62275
62381
|
network: this.opts.settings.watchNetworkSyscalls,
|
|
62382
|
+
peers: this.opts.settings.matchThreatFeeds,
|
|
62276
62383
|
onEvent: (event) => {
|
|
62277
62384
|
this.handleEbpfEvent(event);
|
|
62278
62385
|
},
|
|
@@ -62285,7 +62392,8 @@ var EdrWatch = class {
|
|
|
62285
62392
|
};
|
|
62286
62393
|
this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
|
|
62287
62394
|
this.setSource("ebpf", reason);
|
|
62288
|
-
|
|
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}`);
|
|
62289
62397
|
this.bpftrace.start();
|
|
62290
62398
|
}
|
|
62291
62399
|
startAuditd(reason) {
|
|
@@ -62345,6 +62453,19 @@ var EdrWatch = class {
|
|
|
62345
62453
|
if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
|
|
62346
62454
|
this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
|
|
62347
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
|
+
}
|
|
62348
62469
|
const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
|
|
62349
62470
|
for (const record of records) {
|
|
62350
62471
|
const threat = this.classify(record);
|
|
@@ -62559,7 +62680,7 @@ var import_node_child_process21 = require("child_process");
|
|
|
62559
62680
|
|
|
62560
62681
|
// src/core/asn.ts
|
|
62561
62682
|
var import_node_dns = require("dns");
|
|
62562
|
-
var
|
|
62683
|
+
var import_node_net18 = require("net");
|
|
62563
62684
|
var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
|
|
62564
62685
|
var HOSTING_ASNS = /* @__PURE__ */ new Set([
|
|
62565
62686
|
15169,
|
|
@@ -62678,7 +62799,7 @@ var AsnLookup = class {
|
|
|
62678
62799
|
now;
|
|
62679
62800
|
cache = /* @__PURE__ */ new Map();
|
|
62680
62801
|
async lookup(ip) {
|
|
62681
|
-
if ((0,
|
|
62802
|
+
if ((0, import_node_net18.isIP)(ip) === 0) return null;
|
|
62682
62803
|
const hit = this.cache.get(ip);
|
|
62683
62804
|
if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
|
|
62684
62805
|
let info2 = null;
|
|
@@ -63129,7 +63250,7 @@ var LightningWatch = class {
|
|
|
63129
63250
|
// src/daemon/workers/docker-logs.ts
|
|
63130
63251
|
var import_node_fs61 = require("fs");
|
|
63131
63252
|
var import_node_http = require("http");
|
|
63132
|
-
var
|
|
63253
|
+
var import_node_net19 = require("net");
|
|
63133
63254
|
|
|
63134
63255
|
// src/daemon/workers/postgres-shell.ts
|
|
63135
63256
|
var import_node_fs60 = require("fs");
|
|
@@ -63494,7 +63615,7 @@ function cleanPgHost(raw) {
|
|
|
63494
63615
|
if (!raw) return void 0;
|
|
63495
63616
|
let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
|
|
63496
63617
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
63497
|
-
return (0,
|
|
63618
|
+
return (0, import_node_net19.isIP)(host) ? host : void 0;
|
|
63498
63619
|
}
|
|
63499
63620
|
function prefixHost(line2) {
|
|
63500
63621
|
const first = cleanPgHost(line2.split(/\s/, 1)[0]);
|
|
@@ -63764,7 +63885,7 @@ var DockerLogsWatch = class {
|
|
|
63764
63885
|
// src/daemon/workers/login-watch.ts
|
|
63765
63886
|
var import_node_fs62 = require("fs");
|
|
63766
63887
|
var import_node_child_process22 = require("child_process");
|
|
63767
|
-
var
|
|
63888
|
+
var import_node_net20 = require("net");
|
|
63768
63889
|
var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
|
|
63769
63890
|
function stringList(value, fallback) {
|
|
63770
63891
|
if (!Array.isArray(value)) return fallback;
|
|
@@ -63809,7 +63930,7 @@ function networkOf(ip) {
|
|
|
63809
63930
|
}
|
|
63810
63931
|
function classifyLogin(login2, ctx) {
|
|
63811
63932
|
const { user, ip } = login2;
|
|
63812
|
-
if (!user || !(0,
|
|
63933
|
+
if (!user || !(0, import_node_net20.isIP)(ip)) return null;
|
|
63813
63934
|
if (isProtected(ip, DEFAULT_PROTECTED)) return null;
|
|
63814
63935
|
const network = networkOf(ip);
|
|
63815
63936
|
const reasons = [];
|
|
@@ -63847,7 +63968,7 @@ function parseAcceptedLogins3(text) {
|
|
|
63847
63968
|
const out = [];
|
|
63848
63969
|
for (const line2 of text.split("\n")) {
|
|
63849
63970
|
const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line2);
|
|
63850
|
-
if (m && (0,
|
|
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) });
|
|
63851
63972
|
}
|
|
63852
63973
|
return out;
|
|
63853
63974
|
}
|
|
@@ -63858,7 +63979,7 @@ function ssPeerIp(field) {
|
|
|
63858
63979
|
else host = field.replace(/:\d+$/, "");
|
|
63859
63980
|
host = host.split("%")[0];
|
|
63860
63981
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
63861
|
-
return (0,
|
|
63982
|
+
return (0, import_node_net20.isIP)(host) ? host : null;
|
|
63862
63983
|
}
|
|
63863
63984
|
function sshdPidsForPeer(ssOutput, ip) {
|
|
63864
63985
|
const pids = /* @__PURE__ */ new Set();
|
|
@@ -64162,7 +64283,7 @@ var LoginWatch = class {
|
|
|
64162
64283
|
// src/core/tor-exits.ts
|
|
64163
64284
|
var import_node_fs63 = require("fs");
|
|
64164
64285
|
var import_node_path44 = require("path");
|
|
64165
|
-
var
|
|
64286
|
+
var import_node_net21 = require("net");
|
|
64166
64287
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
64167
64288
|
function parseTorExitList(text) {
|
|
64168
64289
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -64170,7 +64291,7 @@ function parseTorExitList(text) {
|
|
|
64170
64291
|
const line2 = raw.trim();
|
|
64171
64292
|
if (!line2 || line2.startsWith("#")) continue;
|
|
64172
64293
|
const ip = line2.split(/\s+/)[0];
|
|
64173
|
-
if ((0,
|
|
64294
|
+
if ((0, import_node_net21.isIP)(ip)) out.add(normalizeIp(ip));
|
|
64174
64295
|
}
|
|
64175
64296
|
return out;
|
|
64176
64297
|
}
|
|
@@ -64281,7 +64402,7 @@ var TorExitList = class _TorExitList {
|
|
|
64281
64402
|
|
|
64282
64403
|
// src/daemon/firewall/tor-block.ts
|
|
64283
64404
|
var import_node_child_process23 = require("child_process");
|
|
64284
|
-
var
|
|
64405
|
+
var import_node_net22 = require("net");
|
|
64285
64406
|
var TOR_NFT_TABLE = "threatcrush-tor";
|
|
64286
64407
|
function defaultNftRunner() {
|
|
64287
64408
|
return (args, stdin) => new Promise((resolve9, reject) => {
|
|
@@ -64328,7 +64449,7 @@ var TorExitBlockEnforcer = class {
|
|
|
64328
64449
|
await this.teardown();
|
|
64329
64450
|
return;
|
|
64330
64451
|
}
|
|
64331
|
-
const ipv4 = this.opts.exits.values().filter((ip) => (0,
|
|
64452
|
+
const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net22.isIP)(ip) === 4);
|
|
64332
64453
|
if (ipv4.length === 0) return;
|
|
64333
64454
|
try {
|
|
64334
64455
|
await this.apply(ipv4);
|
|
@@ -64870,12 +64991,12 @@ var AuthorizedKeysIndex = class {
|
|
|
64870
64991
|
};
|
|
64871
64992
|
|
|
64872
64993
|
// src/daemon/ssh-context/ip-intel.ts
|
|
64873
|
-
var
|
|
64994
|
+
var import_node_net23 = require("net");
|
|
64874
64995
|
var import_node_os20 = require("os");
|
|
64875
64996
|
var import_node_dns2 = require("dns");
|
|
64876
64997
|
var import_node_fs65 = require("fs");
|
|
64877
64998
|
function list2(entries2) {
|
|
64878
|
-
const b = new
|
|
64999
|
+
const b = new import_node_net23.BlockList();
|
|
64879
65000
|
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
64880
65001
|
return b;
|
|
64881
65002
|
}
|
|
@@ -64890,7 +65011,7 @@ var PRIVATE = list2([
|
|
|
64890
65011
|
["fe80::", 10, "ipv6"]
|
|
64891
65012
|
]);
|
|
64892
65013
|
function family(ip) {
|
|
64893
|
-
const f = (0,
|
|
65014
|
+
const f = (0, import_node_net23.isIP)(ip);
|
|
64894
65015
|
return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
|
|
64895
65016
|
}
|
|
64896
65017
|
function normalizeIp2(ip) {
|
|
@@ -64961,7 +65082,7 @@ var GitHubActionsRanges = class {
|
|
|
64961
65082
|
lastTry = 0;
|
|
64962
65083
|
inflight = null;
|
|
64963
65084
|
set(cidrs, at) {
|
|
64964
|
-
const b = new
|
|
65085
|
+
const b = new import_node_net23.BlockList();
|
|
64965
65086
|
let n = 0;
|
|
64966
65087
|
for (const c of cidrs) {
|
|
64967
65088
|
const [addr, bits2] = c.split("/");
|
|
@@ -65020,7 +65141,7 @@ function withTimeout2(p, ms) {
|
|
|
65020
65141
|
}
|
|
65021
65142
|
function cymruOriginName2(raw) {
|
|
65022
65143
|
const ip = normalizeIp2(raw);
|
|
65023
|
-
const f = (0,
|
|
65144
|
+
const f = (0, import_node_net23.isIP)(ip);
|
|
65024
65145
|
if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
|
|
65025
65146
|
if (f !== 6) return null;
|
|
65026
65147
|
const parts = ip.split("::");
|
|
@@ -65948,14 +66069,14 @@ function loadAllRules(customDir) {
|
|
|
65948
66069
|
var import_node_child_process25 = require("child_process");
|
|
65949
66070
|
var import_node_fs67 = require("fs");
|
|
65950
66071
|
var import_node_path47 = require("path");
|
|
65951
|
-
var
|
|
66072
|
+
var import_node_net24 = require("net");
|
|
65952
66073
|
function assertValidFirewallIp(ip) {
|
|
65953
|
-
if ((0,
|
|
66074
|
+
if ((0, import_node_net24.isIP)(ip) !== 4) {
|
|
65954
66075
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
65955
66076
|
}
|
|
65956
66077
|
}
|
|
65957
66078
|
function assertBannableIp(ip) {
|
|
65958
|
-
if ((0,
|
|
66079
|
+
if ((0, import_node_net24.isIP)(ip) === 0) {
|
|
65959
66080
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
65960
66081
|
}
|
|
65961
66082
|
}
|
|
@@ -66061,7 +66182,7 @@ var Fail2banAdapter = class {
|
|
|
66061
66182
|
const status = this.client(["status", this.jail]);
|
|
66062
66183
|
const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
66063
66184
|
if (!line2) return [];
|
|
66064
|
-
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
66185
|
+
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
|
|
66065
66186
|
} catch {
|
|
66066
66187
|
return [];
|
|
66067
66188
|
}
|
|
@@ -66071,10 +66192,10 @@ var Fail2banAdapter = class {
|
|
|
66071
66192
|
function parseBannedList(output) {
|
|
66072
66193
|
const found = [];
|
|
66073
66194
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
66074
|
-
if ((0,
|
|
66195
|
+
if ((0, import_node_net24.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
66075
66196
|
}
|
|
66076
66197
|
if (found.length > 0) return found;
|
|
66077
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
66198
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
|
|
66078
66199
|
}
|
|
66079
66200
|
var NftablesAdapter = class {
|
|
66080
66201
|
name = "nftables";
|
|
@@ -66223,7 +66344,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
66223
66344
|
// src/daemon/firewall/remediation.ts
|
|
66224
66345
|
var import_node_fs68 = require("fs");
|
|
66225
66346
|
var import_node_child_process26 = require("child_process");
|
|
66226
|
-
var
|
|
66347
|
+
var import_node_net25 = require("net");
|
|
66227
66348
|
init_paths();
|
|
66228
66349
|
init_backoff();
|
|
66229
66350
|
|
|
@@ -66394,7 +66515,7 @@ var RemediationManager = class {
|
|
|
66394
66515
|
setTorExitCheck(check2) {
|
|
66395
66516
|
this.isTorExit = check2;
|
|
66396
66517
|
let dropped = 0;
|
|
66397
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
66518
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net25.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
66398
66519
|
for (const ip of Object.keys(this.operators)) {
|
|
66399
66520
|
if (!check2(ip)) continue;
|
|
66400
66521
|
delete this.operators[ip];
|
|
@@ -66487,7 +66608,7 @@ var RemediationManager = class {
|
|
|
66487
66608
|
if (remediation?.action !== "block") return;
|
|
66488
66609
|
}
|
|
66489
66610
|
const ip = event.source_ip;
|
|
66490
|
-
if (!ip || (0,
|
|
66611
|
+
if (!ip || (0, import_node_net25.isIP)(ip) === 0) return;
|
|
66491
66612
|
const strict = remediation?.override_operator_protection === true;
|
|
66492
66613
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
66493
66614
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -66516,7 +66637,7 @@ var RemediationManager = class {
|
|
|
66516
66637
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
66517
66638
|
*/
|
|
66518
66639
|
async ban(ip, reason, opts = {}) {
|
|
66519
|
-
if ((0,
|
|
66640
|
+
if ((0, import_node_net25.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
66520
66641
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
66521
66642
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
66522
66643
|
}
|
|
@@ -66793,7 +66914,7 @@ var RemediationManager = class {
|
|
|
66793
66914
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
66794
66915
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
66795
66916
|
for (const [ip, at] of Object.entries(saved)) {
|
|
66796
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
66917
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net25.isIP)(ip)) continue;
|
|
66797
66918
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
66798
66919
|
this.operators[ip] = at;
|
|
66799
66920
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -67179,6 +67300,12 @@ async function runDaemon() {
|
|
|
67179
67300
|
settings: edrSettings(config.edr),
|
|
67180
67301
|
networkBaselinePath: (0, import_node_path49.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
67181
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
|
+
},
|
|
67182
67309
|
log: logLine
|
|
67183
67310
|
});
|
|
67184
67311
|
edr.start();
|
|
@@ -69920,7 +70047,7 @@ async function patchesCommand(opts) {
|
|
|
69920
70047
|
}
|
|
69921
70048
|
|
|
69922
70049
|
// src/commands/feeds.ts
|
|
69923
|
-
var
|
|
70050
|
+
var import_node_net26 = require("net");
|
|
69924
70051
|
var import_node_path55 = require("path");
|
|
69925
70052
|
init_paths();
|
|
69926
70053
|
|
|
@@ -70064,8 +70191,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
70064
70191
|
process.exitCode = 2;
|
|
70065
70192
|
return;
|
|
70066
70193
|
}
|
|
70067
|
-
const ipHit = (0,
|
|
70068
|
-
const domainHit = (0,
|
|
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);
|
|
70069
70196
|
const listed = ipHit ?? domainHit?.indicator ?? null;
|
|
70070
70197
|
if (opts.json) {
|
|
70071
70198
|
console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
|
|
@@ -70104,7 +70231,7 @@ async function feedsCommand(action, value, opts) {
|
|
|
70104
70231
|
|
|
70105
70232
|
// src/commands/tor.ts
|
|
70106
70233
|
var import_node_fs80 = require("fs");
|
|
70107
|
-
var
|
|
70234
|
+
var import_node_net27 = require("net");
|
|
70108
70235
|
var import_node_path56 = require("path");
|
|
70109
70236
|
init_paths();
|
|
70110
70237
|
async function torCommand(action, value, opts) {
|
|
@@ -70136,7 +70263,7 @@ async function torCommand(action, value, opts) {
|
|
|
70136
70263
|
const remediation = loadConfig((0, import_node_path56.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
70137
70264
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
70138
70265
|
if (action === "check") {
|
|
70139
|
-
if (!value || !(0,
|
|
70266
|
+
if (!value || !(0, import_node_net27.isIP)(value)) {
|
|
70140
70267
|
console.error("Usage: threatcrush tor check <ip>");
|
|
70141
70268
|
process.exitCode = 2;
|
|
70142
70269
|
return;
|
|
@@ -70629,7 +70756,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
70629
70756
|
if (action === "bpftrace") {
|
|
70630
70757
|
console.log("// Generated by threatcrush edr bpftrace: the program the eBPF source runs");
|
|
70631
70758
|
console.log("// as `bpftrace -q -B line -f json -e <program>` when [edr] source selects ebpf.");
|
|
70632
|
-
process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls }));
|
|
70759
|
+
process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls, peers: settings.matchThreatFeeds }));
|
|
70633
70760
|
return;
|
|
70634
70761
|
}
|
|
70635
70762
|
if (action !== "status") {
|
|
@@ -70666,6 +70793,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
70666
70793
|
web_service_users: settings.webServiceUsers,
|
|
70667
70794
|
temp_exec_paths: settings.tempExecPaths,
|
|
70668
70795
|
watch_network_syscalls: settings.watchNetworkSyscalls,
|
|
70796
|
+
match_threat_feeds: settings.matchThreatFeeds,
|
|
70669
70797
|
network_baseline_seconds: settings.networkBaselineMs / 1e3,
|
|
70670
70798
|
watch_unknown_temp_cpu: settings.watchUnknownTempCpu,
|
|
70671
70799
|
poll_interval_seconds: settings.pollMs / 1e3,
|