@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 +19 -2
- package/dist/daemon.js +201 -70
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +218 -77
- package/dist/index.js.map +1 -1
- package/dist/systemd/threatcrushd.service +4 -0
- 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
|
-
if (!ind) continue;
|
|
60143
|
-
const key = `${c.peerIp}|${c.process ?? "?"}`;
|
|
60144
|
-
if (now - (this.alerted.get(key) ?? 0) < REALERT_MS) continue;
|
|
60145
|
-
this.alerted.set(key, now);
|
|
60146
|
-
const who = c.process ? `${c.process} (pid ${c.pid})` : "an unknown process";
|
|
60147
|
-
const blocked = this.blocking ? " \u2014 blocked" : "";
|
|
60148
|
-
this.opts.bus.publish({
|
|
60149
|
-
timestamp: new Date(now),
|
|
60150
|
-
module: "threat-feeds",
|
|
60151
|
-
category: "network",
|
|
60152
|
-
severity: "critical",
|
|
60153
|
-
message: `Outbound connection to known ${ind.malware} ${ind.threat === "botnet_cc" ? "C2" : "malware host"} ${c.peerIp}:${c.peerPort} by ${who}${blocked}`,
|
|
60154
|
-
// No source_ip on purpose: the remote end is not an attacker to ban
|
|
60155
|
-
// inbound, so remediation has nothing to act on and the egress table
|
|
60156
|
-
// stays the only enforcement.
|
|
60157
|
-
details: {
|
|
60158
|
-
rule_id: "threat-feed-outbound",
|
|
60159
|
-
destination_ip: c.peerIp,
|
|
60160
|
-
destination_port: c.peerPort,
|
|
60161
|
-
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" });
|
|
60171
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 {
|
|
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") {
|
|
@@ -61919,6 +62024,7 @@ function probeHost(configured) {
|
|
|
61919
62024
|
platform: process.platform
|
|
61920
62025
|
};
|
|
61921
62026
|
}
|
|
62027
|
+
var BPFTRACE_ENV = { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" };
|
|
61922
62028
|
var STDERR_TAIL = 2048;
|
|
61923
62029
|
var HEALTHY_AFTER_MS = 3e4;
|
|
61924
62030
|
var KILL_GRACE_MS = 3e3;
|
|
@@ -62026,10 +62132,10 @@ var BpftraceSource = class {
|
|
|
62026
62132
|
this.stderrTail = "";
|
|
62027
62133
|
let child;
|
|
62028
62134
|
try {
|
|
62029
|
-
child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network }), {
|
|
62135
|
+
child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network, peers: this.opts.peers }), {
|
|
62030
62136
|
stdio: ["ignore", "pipe", "pipe"],
|
|
62031
62137
|
shell: false,
|
|
62032
|
-
env:
|
|
62138
|
+
env: BPFTRACE_ENV
|
|
62033
62139
|
});
|
|
62034
62140
|
} catch (error2) {
|
|
62035
62141
|
this.onExit(null, null, error2.message);
|
|
@@ -62118,6 +62224,7 @@ function edrSettings(section) {
|
|
|
62118
62224
|
webServiceUsers: configuredUsers,
|
|
62119
62225
|
tempExecPaths: configuredPaths,
|
|
62120
62226
|
watchNetworkSyscalls: section?.watch_network_syscalls === true,
|
|
62227
|
+
matchThreatFeeds: section?.watch_network_syscalls === true && section?.match_threat_feeds !== false,
|
|
62121
62228
|
networkBaselineMs: typeof baselineSeconds === "number" && Number.isFinite(baselineSeconds) ? Math.max(0, Math.min(3600, Math.floor(baselineSeconds))) * 1e3 : 6e4,
|
|
62122
62229
|
watchUnknownTempCpu: section?.watch_unknown_temp_cpu !== false,
|
|
62123
62230
|
pollMs
|
|
@@ -62273,19 +62380,24 @@ var EdrWatch = class {
|
|
|
62273
62380
|
const options = {
|
|
62274
62381
|
bpftracePath,
|
|
62275
62382
|
network: this.opts.settings.watchNetworkSyscalls,
|
|
62383
|
+
peers: this.opts.settings.matchThreatFeeds,
|
|
62276
62384
|
onEvent: (event) => {
|
|
62277
62385
|
this.handleEbpfEvent(event);
|
|
62278
62386
|
},
|
|
62279
62387
|
onFatal: (failure) => {
|
|
62280
62388
|
this.bpftrace = null;
|
|
62281
62389
|
this.opts.log(`[edr] ${failure}; falling back to auditd`);
|
|
62390
|
+
if (/Missing CAP_(BPF|PERFMON)/.test(failure)) {
|
|
62391
|
+
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");
|
|
62392
|
+
}
|
|
62282
62393
|
this.startAuditd(`eBPF failed: ${failure}`);
|
|
62283
62394
|
},
|
|
62284
62395
|
log: this.opts.log
|
|
62285
62396
|
};
|
|
62286
62397
|
this.bpftrace = this.opts.createBpftrace ? this.opts.createBpftrace(options) : new BpftraceSource(options);
|
|
62287
62398
|
this.setSource("ebpf", reason);
|
|
62288
|
-
|
|
62399
|
+
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";
|
|
62400
|
+
this.opts.log(`[edr] event source: eBPF via ${bpftracePath} (exec${this.opts.settings.watchNetworkSyscalls ? ", tcp connect/listen" : ""}); ${addresses}`);
|
|
62289
62401
|
this.bpftrace.start();
|
|
62290
62402
|
}
|
|
62291
62403
|
startAuditd(reason) {
|
|
@@ -62345,6 +62457,19 @@ var EdrWatch = class {
|
|
|
62345
62457
|
if ((event.kind === "connect" || event.kind === "listen") && !this.opts.settings.watchNetworkSyscalls) return null;
|
|
62346
62458
|
this.ebpfSerial = (this.ebpfSerial + 1) % Number.MAX_SAFE_INTEGER;
|
|
62347
62459
|
const resolver = resolveExe ?? (() => this.resolveEbpfExe(event));
|
|
62460
|
+
if (event.kind === "connect" && event.peerIp && event.peerPort !== void 0 && this.opts.settings.matchThreatFeeds && this.opts.onConnection) {
|
|
62461
|
+
try {
|
|
62462
|
+
this.opts.onConnection({
|
|
62463
|
+
peerIp: event.peerIp,
|
|
62464
|
+
peerPort: event.peerPort,
|
|
62465
|
+
pid: event.pid,
|
|
62466
|
+
comm: event.comm,
|
|
62467
|
+
euid: event.euid,
|
|
62468
|
+
resolveExecutable: () => resolver(event.pid)
|
|
62469
|
+
});
|
|
62470
|
+
} catch {
|
|
62471
|
+
}
|
|
62472
|
+
}
|
|
62348
62473
|
const records = ebpfEventToRecords(event, resolver, /* @__PURE__ */ new Date(), `ebpf-${this.ebpfSerial}`);
|
|
62349
62474
|
for (const record of records) {
|
|
62350
62475
|
const threat = this.classify(record);
|
|
@@ -62559,7 +62684,7 @@ var import_node_child_process21 = require("child_process");
|
|
|
62559
62684
|
|
|
62560
62685
|
// src/core/asn.ts
|
|
62561
62686
|
var import_node_dns = require("dns");
|
|
62562
|
-
var
|
|
62687
|
+
var import_node_net18 = require("net");
|
|
62563
62688
|
var CI_ASNS = /* @__PURE__ */ new Set([8075, 36459, 8068, 8069, 12076]);
|
|
62564
62689
|
var HOSTING_ASNS = /* @__PURE__ */ new Set([
|
|
62565
62690
|
15169,
|
|
@@ -62678,7 +62803,7 @@ var AsnLookup = class {
|
|
|
62678
62803
|
now;
|
|
62679
62804
|
cache = /* @__PURE__ */ new Map();
|
|
62680
62805
|
async lookup(ip) {
|
|
62681
|
-
if ((0,
|
|
62806
|
+
if ((0, import_node_net18.isIP)(ip) === 0) return null;
|
|
62682
62807
|
const hit = this.cache.get(ip);
|
|
62683
62808
|
if (hit && this.now() - hit.at < this.ttlMs) return hit.info;
|
|
62684
62809
|
let info2 = null;
|
|
@@ -63129,7 +63254,7 @@ var LightningWatch = class {
|
|
|
63129
63254
|
// src/daemon/workers/docker-logs.ts
|
|
63130
63255
|
var import_node_fs61 = require("fs");
|
|
63131
63256
|
var import_node_http = require("http");
|
|
63132
|
-
var
|
|
63257
|
+
var import_node_net19 = require("net");
|
|
63133
63258
|
|
|
63134
63259
|
// src/daemon/workers/postgres-shell.ts
|
|
63135
63260
|
var import_node_fs60 = require("fs");
|
|
@@ -63494,7 +63619,7 @@ function cleanPgHost(raw) {
|
|
|
63494
63619
|
if (!raw) return void 0;
|
|
63495
63620
|
let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
|
|
63496
63621
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
63497
|
-
return (0,
|
|
63622
|
+
return (0, import_node_net19.isIP)(host) ? host : void 0;
|
|
63498
63623
|
}
|
|
63499
63624
|
function prefixHost(line2) {
|
|
63500
63625
|
const first = cleanPgHost(line2.split(/\s/, 1)[0]);
|
|
@@ -63764,7 +63889,7 @@ var DockerLogsWatch = class {
|
|
|
63764
63889
|
// src/daemon/workers/login-watch.ts
|
|
63765
63890
|
var import_node_fs62 = require("fs");
|
|
63766
63891
|
var import_node_child_process22 = require("child_process");
|
|
63767
|
-
var
|
|
63892
|
+
var import_node_net20 = require("net");
|
|
63768
63893
|
var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
|
|
63769
63894
|
function stringList(value, fallback) {
|
|
63770
63895
|
if (!Array.isArray(value)) return fallback;
|
|
@@ -63809,7 +63934,7 @@ function networkOf(ip) {
|
|
|
63809
63934
|
}
|
|
63810
63935
|
function classifyLogin(login2, ctx) {
|
|
63811
63936
|
const { user, ip } = login2;
|
|
63812
|
-
if (!user || !(0,
|
|
63937
|
+
if (!user || !(0, import_node_net20.isIP)(ip)) return null;
|
|
63813
63938
|
if (isProtected(ip, DEFAULT_PROTECTED)) return null;
|
|
63814
63939
|
const network = networkOf(ip);
|
|
63815
63940
|
const reasons = [];
|
|
@@ -63847,7 +63972,7 @@ function parseAcceptedLogins3(text) {
|
|
|
63847
63972
|
const out = [];
|
|
63848
63973
|
for (const line2 of text.split("\n")) {
|
|
63849
63974
|
const m = /^(\d+(?:\.\d+)?)\s.*Accepted \S+ for (\S+) from (\S+) port \d+/.exec(line2);
|
|
63850
|
-
if (m && (0,
|
|
63975
|
+
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
63976
|
}
|
|
63852
63977
|
return out;
|
|
63853
63978
|
}
|
|
@@ -63858,7 +63983,7 @@ function ssPeerIp(field) {
|
|
|
63858
63983
|
else host = field.replace(/:\d+$/, "");
|
|
63859
63984
|
host = host.split("%")[0];
|
|
63860
63985
|
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
63861
|
-
return (0,
|
|
63986
|
+
return (0, import_node_net20.isIP)(host) ? host : null;
|
|
63862
63987
|
}
|
|
63863
63988
|
function sshdPidsForPeer(ssOutput, ip) {
|
|
63864
63989
|
const pids = /* @__PURE__ */ new Set();
|
|
@@ -64162,7 +64287,7 @@ var LoginWatch = class {
|
|
|
64162
64287
|
// src/core/tor-exits.ts
|
|
64163
64288
|
var import_node_fs63 = require("fs");
|
|
64164
64289
|
var import_node_path44 = require("path");
|
|
64165
|
-
var
|
|
64290
|
+
var import_node_net21 = require("net");
|
|
64166
64291
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
64167
64292
|
function parseTorExitList(text) {
|
|
64168
64293
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -64170,7 +64295,7 @@ function parseTorExitList(text) {
|
|
|
64170
64295
|
const line2 = raw.trim();
|
|
64171
64296
|
if (!line2 || line2.startsWith("#")) continue;
|
|
64172
64297
|
const ip = line2.split(/\s+/)[0];
|
|
64173
|
-
if ((0,
|
|
64298
|
+
if ((0, import_node_net21.isIP)(ip)) out.add(normalizeIp(ip));
|
|
64174
64299
|
}
|
|
64175
64300
|
return out;
|
|
64176
64301
|
}
|
|
@@ -64281,7 +64406,7 @@ var TorExitList = class _TorExitList {
|
|
|
64281
64406
|
|
|
64282
64407
|
// src/daemon/firewall/tor-block.ts
|
|
64283
64408
|
var import_node_child_process23 = require("child_process");
|
|
64284
|
-
var
|
|
64409
|
+
var import_node_net22 = require("net");
|
|
64285
64410
|
var TOR_NFT_TABLE = "threatcrush-tor";
|
|
64286
64411
|
function defaultNftRunner() {
|
|
64287
64412
|
return (args, stdin) => new Promise((resolve9, reject) => {
|
|
@@ -64328,7 +64453,7 @@ var TorExitBlockEnforcer = class {
|
|
|
64328
64453
|
await this.teardown();
|
|
64329
64454
|
return;
|
|
64330
64455
|
}
|
|
64331
|
-
const ipv4 = this.opts.exits.values().filter((ip) => (0,
|
|
64456
|
+
const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net22.isIP)(ip) === 4);
|
|
64332
64457
|
if (ipv4.length === 0) return;
|
|
64333
64458
|
try {
|
|
64334
64459
|
await this.apply(ipv4);
|
|
@@ -64870,12 +64995,12 @@ var AuthorizedKeysIndex = class {
|
|
|
64870
64995
|
};
|
|
64871
64996
|
|
|
64872
64997
|
// src/daemon/ssh-context/ip-intel.ts
|
|
64873
|
-
var
|
|
64998
|
+
var import_node_net23 = require("net");
|
|
64874
64999
|
var import_node_os20 = require("os");
|
|
64875
65000
|
var import_node_dns2 = require("dns");
|
|
64876
65001
|
var import_node_fs65 = require("fs");
|
|
64877
65002
|
function list2(entries2) {
|
|
64878
|
-
const b = new
|
|
65003
|
+
const b = new import_node_net23.BlockList();
|
|
64879
65004
|
for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
|
|
64880
65005
|
return b;
|
|
64881
65006
|
}
|
|
@@ -64890,7 +65015,7 @@ var PRIVATE = list2([
|
|
|
64890
65015
|
["fe80::", 10, "ipv6"]
|
|
64891
65016
|
]);
|
|
64892
65017
|
function family(ip) {
|
|
64893
|
-
const f = (0,
|
|
65018
|
+
const f = (0, import_node_net23.isIP)(ip);
|
|
64894
65019
|
return f === 4 ? "ipv4" : f === 6 ? "ipv6" : null;
|
|
64895
65020
|
}
|
|
64896
65021
|
function normalizeIp2(ip) {
|
|
@@ -64961,7 +65086,7 @@ var GitHubActionsRanges = class {
|
|
|
64961
65086
|
lastTry = 0;
|
|
64962
65087
|
inflight = null;
|
|
64963
65088
|
set(cidrs, at) {
|
|
64964
|
-
const b = new
|
|
65089
|
+
const b = new import_node_net23.BlockList();
|
|
64965
65090
|
let n = 0;
|
|
64966
65091
|
for (const c of cidrs) {
|
|
64967
65092
|
const [addr, bits2] = c.split("/");
|
|
@@ -65020,7 +65145,7 @@ function withTimeout2(p, ms) {
|
|
|
65020
65145
|
}
|
|
65021
65146
|
function cymruOriginName2(raw) {
|
|
65022
65147
|
const ip = normalizeIp2(raw);
|
|
65023
|
-
const f = (0,
|
|
65148
|
+
const f = (0, import_node_net23.isIP)(ip);
|
|
65024
65149
|
if (f === 4) return `${ip.split(".").reverse().join(".")}.origin.asn.cymru.com`;
|
|
65025
65150
|
if (f !== 6) return null;
|
|
65026
65151
|
const parts = ip.split("::");
|
|
@@ -65948,14 +66073,14 @@ function loadAllRules(customDir) {
|
|
|
65948
66073
|
var import_node_child_process25 = require("child_process");
|
|
65949
66074
|
var import_node_fs67 = require("fs");
|
|
65950
66075
|
var import_node_path47 = require("path");
|
|
65951
|
-
var
|
|
66076
|
+
var import_node_net24 = require("net");
|
|
65952
66077
|
function assertValidFirewallIp(ip) {
|
|
65953
|
-
if ((0,
|
|
66078
|
+
if ((0, import_node_net24.isIP)(ip) !== 4) {
|
|
65954
66079
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
65955
66080
|
}
|
|
65956
66081
|
}
|
|
65957
66082
|
function assertBannableIp(ip) {
|
|
65958
|
-
if ((0,
|
|
66083
|
+
if ((0, import_node_net24.isIP)(ip) === 0) {
|
|
65959
66084
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
65960
66085
|
}
|
|
65961
66086
|
}
|
|
@@ -66061,7 +66186,7 @@ var Fail2banAdapter = class {
|
|
|
66061
66186
|
const status = this.client(["status", this.jail]);
|
|
66062
66187
|
const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
66063
66188
|
if (!line2) return [];
|
|
66064
|
-
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
66189
|
+
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
|
|
66065
66190
|
} catch {
|
|
66066
66191
|
return [];
|
|
66067
66192
|
}
|
|
@@ -66071,10 +66196,10 @@ var Fail2banAdapter = class {
|
|
|
66071
66196
|
function parseBannedList(output) {
|
|
66072
66197
|
const found = [];
|
|
66073
66198
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
66074
|
-
if ((0,
|
|
66199
|
+
if ((0, import_node_net24.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
66075
66200
|
}
|
|
66076
66201
|
if (found.length > 0) return found;
|
|
66077
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
66202
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net24.isIP)(s) !== 0);
|
|
66078
66203
|
}
|
|
66079
66204
|
var NftablesAdapter = class {
|
|
66080
66205
|
name = "nftables";
|
|
@@ -66223,7 +66348,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
66223
66348
|
// src/daemon/firewall/remediation.ts
|
|
66224
66349
|
var import_node_fs68 = require("fs");
|
|
66225
66350
|
var import_node_child_process26 = require("child_process");
|
|
66226
|
-
var
|
|
66351
|
+
var import_node_net25 = require("net");
|
|
66227
66352
|
init_paths();
|
|
66228
66353
|
init_backoff();
|
|
66229
66354
|
|
|
@@ -66394,7 +66519,7 @@ var RemediationManager = class {
|
|
|
66394
66519
|
setTorExitCheck(check2) {
|
|
66395
66520
|
this.isTorExit = check2;
|
|
66396
66521
|
let dropped = 0;
|
|
66397
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
66522
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net25.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
66398
66523
|
for (const ip of Object.keys(this.operators)) {
|
|
66399
66524
|
if (!check2(ip)) continue;
|
|
66400
66525
|
delete this.operators[ip];
|
|
@@ -66487,7 +66612,7 @@ var RemediationManager = class {
|
|
|
66487
66612
|
if (remediation?.action !== "block") return;
|
|
66488
66613
|
}
|
|
66489
66614
|
const ip = event.source_ip;
|
|
66490
|
-
if (!ip || (0,
|
|
66615
|
+
if (!ip || (0, import_node_net25.isIP)(ip) === 0) return;
|
|
66491
66616
|
const strict = remediation?.override_operator_protection === true;
|
|
66492
66617
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
66493
66618
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -66516,7 +66641,7 @@ var RemediationManager = class {
|
|
|
66516
66641
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
66517
66642
|
*/
|
|
66518
66643
|
async ban(ip, reason, opts = {}) {
|
|
66519
|
-
if ((0,
|
|
66644
|
+
if ((0, import_node_net25.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
66520
66645
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
66521
66646
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
66522
66647
|
}
|
|
@@ -66793,7 +66918,7 @@ var RemediationManager = class {
|
|
|
66793
66918
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
66794
66919
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
66795
66920
|
for (const [ip, at] of Object.entries(saved)) {
|
|
66796
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
66921
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net25.isIP)(ip)) continue;
|
|
66797
66922
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
66798
66923
|
this.operators[ip] = at;
|
|
66799
66924
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -67179,6 +67304,12 @@ async function runDaemon() {
|
|
|
67179
67304
|
settings: edrSettings(config.edr),
|
|
67180
67305
|
networkBaselinePath: (0, import_node_path49.join)(PATHS.stateDir, "edr-outbound-executables.json"),
|
|
67181
67306
|
sourceStatusPath: (0, import_node_path49.join)(PATHS.stateDir, "edr-source.json"),
|
|
67307
|
+
// Every traced connect is checked against the abuse.ch lists: this is what
|
|
67308
|
+
// sees a one-second download or a container calling out, which the
|
|
67309
|
+
// threat-feeds socket snapshot cannot.
|
|
67310
|
+
onConnection: (conn) => {
|
|
67311
|
+
threatFeeds.observeOutbound(conn);
|
|
67312
|
+
},
|
|
67182
67313
|
log: logLine
|
|
67183
67314
|
});
|
|
67184
67315
|
edr.start();
|
|
@@ -67600,6 +67731,12 @@ function renderUnit(template, opts) {
|
|
|
67600
67731
|
const extraCaps = (opts.extraCapabilities ?? []).filter((cap) => /^CAP_[A-Z_]+$/.test(cap));
|
|
67601
67732
|
return template.replaceAll("{{EXTRA_CAPS}}", extraCaps.map((cap) => ` ${cap}`).join("")).replaceAll("{{BIN_PATH}} daemon", opts.exec).replaceAll("{{BIN_PATH}}", opts.binPath).replaceAll("{{CONFIG_DIR}}", opts.configDir).replaceAll("{{HISTORY_PATHS}}", (opts.historyPaths ?? []).map((path2) => `-${path2}`).join(" ")).replace(/ReadWritePaths=([^\n]*)/, (_line, paths) => `ReadWritePaths=${paths.split(/\s+/).filter(Boolean).join(" ")}`);
|
|
67602
67733
|
}
|
|
67734
|
+
function unitExtraCapabilities(opts) {
|
|
67735
|
+
return [
|
|
67736
|
+
...opts.containWriter ? ["CAP_SYS_PTRACE"] : [],
|
|
67737
|
+
...opts.edrEbpf ? ["CAP_BPF", "CAP_PERFMON"] : []
|
|
67738
|
+
];
|
|
67739
|
+
}
|
|
67603
67740
|
function nodeVersionDir(path2) {
|
|
67604
67741
|
const m = path2.match(
|
|
67605
67742
|
/^(.*?\/(?:installs\/node(?:js)?|\.nvm\/versions\/node|node-versions|tools\/image\/node|n\/versions\/node)\/[^/]+)\//
|
|
@@ -67712,12 +67849,15 @@ async function installServiceCommand() {
|
|
|
67712
67849
|
const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
|
|
67713
67850
|
const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
|
|
67714
67851
|
const containWriter = containWriterSettings(loadConfig().file_integrity).mode !== "off";
|
|
67715
|
-
const
|
|
67852
|
+
const edr = edrSettings(loadConfig().edr);
|
|
67853
|
+
const edrEbpf = edr.enabled && edr.source !== "auditd";
|
|
67854
|
+
const extraCapabilities = unitExtraCapabilities({ containWriter, edrEbpf });
|
|
67716
67855
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths, extraCapabilities });
|
|
67717
67856
|
(0, import_node_fs73.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
67718
67857
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
67719
67858
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
67720
67859
|
if (containWriter) console.log(source_default.dim(" CAP_SYS_PTRACE granted for [file_integrity] contain_writer (reads /proc/<pid>/fd)"));
|
|
67860
|
+
if (edrEbpf) console.log(source_default.dim(' CAP_BPF and CAP_PERFMON granted for [edr] source = "ebpf" (bpftrace loads a tracing program)'));
|
|
67721
67861
|
const nodeDir = nodeVersionDir(nodePath);
|
|
67722
67862
|
const pinnedTo = nodeVersionDir(binPath) ?? (isNodeScript && nodeDir && !nodeDir.endsWith("/latest") ? nodeDir : null);
|
|
67723
67863
|
if (pinnedTo) {
|
|
@@ -69920,7 +70060,7 @@ async function patchesCommand(opts) {
|
|
|
69920
70060
|
}
|
|
69921
70061
|
|
|
69922
70062
|
// src/commands/feeds.ts
|
|
69923
|
-
var
|
|
70063
|
+
var import_node_net26 = require("net");
|
|
69924
70064
|
var import_node_path55 = require("path");
|
|
69925
70065
|
init_paths();
|
|
69926
70066
|
|
|
@@ -70064,8 +70204,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
70064
70204
|
process.exitCode = 2;
|
|
70065
70205
|
return;
|
|
70066
70206
|
}
|
|
70067
|
-
const ipHit = (0,
|
|
70068
|
-
const domainHit = (0,
|
|
70207
|
+
const ipHit = (0, import_node_net26.isIP)(value) ? matchIp(value, set) : null;
|
|
70208
|
+
const domainHit = (0, import_node_net26.isIP)(value) ? null : matchDomain(value, set);
|
|
70069
70209
|
const listed = ipHit ?? domainHit?.indicator ?? null;
|
|
70070
70210
|
if (opts.json) {
|
|
70071
70211
|
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 +70244,7 @@ async function feedsCommand(action, value, opts) {
|
|
|
70104
70244
|
|
|
70105
70245
|
// src/commands/tor.ts
|
|
70106
70246
|
var import_node_fs80 = require("fs");
|
|
70107
|
-
var
|
|
70247
|
+
var import_node_net27 = require("net");
|
|
70108
70248
|
var import_node_path56 = require("path");
|
|
70109
70249
|
init_paths();
|
|
70110
70250
|
async function torCommand(action, value, opts) {
|
|
@@ -70136,7 +70276,7 @@ async function torCommand(action, value, opts) {
|
|
|
70136
70276
|
const remediation = loadConfig((0, import_node_path56.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
70137
70277
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
70138
70278
|
if (action === "check") {
|
|
70139
|
-
if (!value || !(0,
|
|
70279
|
+
if (!value || !(0, import_node_net27.isIP)(value)) {
|
|
70140
70280
|
console.error("Usage: threatcrush tor check <ip>");
|
|
70141
70281
|
process.exitCode = 2;
|
|
70142
70282
|
return;
|
|
@@ -70629,7 +70769,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
70629
70769
|
if (action === "bpftrace") {
|
|
70630
70770
|
console.log("// Generated by threatcrush edr bpftrace: the program the eBPF source runs");
|
|
70631
70771
|
console.log("// as `bpftrace -q -B line -f json -e <program>` when [edr] source selects ebpf.");
|
|
70632
|
-
process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls }));
|
|
70772
|
+
process.stdout.write(bpftraceScript({ network: settings.watchNetworkSyscalls, peers: settings.matchThreatFeeds }));
|
|
70633
70773
|
return;
|
|
70634
70774
|
}
|
|
70635
70775
|
if (action !== "status") {
|
|
@@ -70666,6 +70806,7 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
70666
70806
|
web_service_users: settings.webServiceUsers,
|
|
70667
70807
|
temp_exec_paths: settings.tempExecPaths,
|
|
70668
70808
|
watch_network_syscalls: settings.watchNetworkSyscalls,
|
|
70809
|
+
match_threat_feeds: settings.matchThreatFeeds,
|
|
70669
70810
|
network_baseline_seconds: settings.networkBaselineMs / 1e3,
|
|
70670
70811
|
watch_unknown_temp_cpu: settings.watchUnknownTempCpu,
|
|
70671
70812
|
poll_interval_seconds: settings.pollMs / 1e3,
|