@profullstack/threatcrush 0.15.1 → 0.15.2
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/dist/daemon.js +27 -5
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56786,6 +56786,7 @@ var import_node_readline3 = require("readline");
|
|
|
56786
56786
|
var import_node_fs44 = require("fs");
|
|
56787
56787
|
var import_node_path30 = require("path");
|
|
56788
56788
|
var import_node_net10 = require("net");
|
|
56789
|
+
var CARRY_MAX_MS = 24 * 36e5;
|
|
56789
56790
|
var FEEDS = {
|
|
56790
56791
|
/** POST `{ query: 'get_iocs', days }` with an `Auth-Key` header. */
|
|
56791
56792
|
threatfoxApi: "https://threatfox-api.abuse.ch/api/v1/",
|
|
@@ -57016,7 +57017,7 @@ function redact(message, key) {
|
|
|
57016
57017
|
if (!key) return message;
|
|
57017
57018
|
return message.split(key).join("<auth-key>").split(encodeURIComponent(key)).join("<auth-key>");
|
|
57018
57019
|
}
|
|
57019
|
-
async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
57020
|
+
async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3, previous = null, now = /* @__PURE__ */ new Date()) {
|
|
57020
57021
|
const sources = [];
|
|
57021
57022
|
const parts = [];
|
|
57022
57023
|
const key = settings.authKey?.trim() || void 0;
|
|
@@ -57048,8 +57049,11 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
|
57048
57049
|
}
|
|
57049
57050
|
const count = (part.ips?.size ?? 0) + (part.domains?.size ?? 0);
|
|
57050
57051
|
if (count === 0 && !emptyOk) throw new Error("no entries in the response");
|
|
57052
|
+
for (const map of [part.ips, part.domains]) {
|
|
57053
|
+
for (const [k, ind] of map ?? []) map.set(k, { ...ind, source: feed });
|
|
57054
|
+
}
|
|
57051
57055
|
parts.push(part);
|
|
57052
|
-
sources.push({ feed, ok: true, count });
|
|
57056
|
+
sources.push({ feed, ok: true, count, last_ok_at: now.toISOString() });
|
|
57053
57057
|
} catch (err) {
|
|
57054
57058
|
sources.push({ feed, ok: false, count: 0, error: redact(err.message, key) });
|
|
57055
57059
|
}
|
|
@@ -57069,8 +57073,26 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
|
57069
57073
|
// Feodo has been near-empty since 2025; an empty list there is real.
|
|
57070
57074
|
get2("feodo", { url: FEEDS.feodoIps }, (t) => ({ ips: parseIpList(t, "feodo") }), true)
|
|
57071
57075
|
]);
|
|
57076
|
+
carryForward(previous, sources, parts, now);
|
|
57072
57077
|
sources.sort((a, b) => a.feed.localeCompare(b.feed));
|
|
57073
|
-
return buildFeedSet(parts, settings.allow, sources);
|
|
57078
|
+
return buildFeedSet(parts, settings.allow, sources, now);
|
|
57079
|
+
}
|
|
57080
|
+
function carryForward(previous, sources, parts, now) {
|
|
57081
|
+
if (!previous) return;
|
|
57082
|
+
for (const s of sources) {
|
|
57083
|
+
if (s.ok || s.error === NEEDS_KEY) continue;
|
|
57084
|
+
const prev = previous.sources?.find((p) => p.feed === s.feed);
|
|
57085
|
+
const lastOk = prev?.last_ok_at;
|
|
57086
|
+
if (!lastOk || now.getTime() - Date.parse(lastOk) > CARRY_MAX_MS) continue;
|
|
57087
|
+
const part = { ips: /* @__PURE__ */ new Map(), domains: /* @__PURE__ */ new Map() };
|
|
57088
|
+
for (const [ip, ind] of Object.entries(previous.ips)) if (ind.source === s.feed) part.ips.set(ip, ind);
|
|
57089
|
+
for (const [d, ind] of Object.entries(previous.domains)) if (ind.source === s.feed) part.domains.set(d, ind);
|
|
57090
|
+
const kept = part.ips.size + part.domains.size;
|
|
57091
|
+
s.last_ok_at = lastOk;
|
|
57092
|
+
if (!kept) continue;
|
|
57093
|
+
parts.push(part);
|
|
57094
|
+
s.carried = kept;
|
|
57095
|
+
}
|
|
57074
57096
|
}
|
|
57075
57097
|
function readFeedCache(path2) {
|
|
57076
57098
|
try {
|
|
@@ -59694,7 +59716,7 @@ var ThreatFeeds = class {
|
|
|
59694
59716
|
}
|
|
59695
59717
|
async refresh() {
|
|
59696
59718
|
try {
|
|
59697
|
-
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs);
|
|
59719
|
+
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs, this.set, new Date(this.now()));
|
|
59698
59720
|
const failed = set.sources.filter((s) => !s.ok);
|
|
59699
59721
|
if (failed.length === set.sources.length) {
|
|
59700
59722
|
this.opts.log(`[threat-feeds] refresh failed, keeping previous list: ${failed.map((s) => `${s.feed}: ${s.error}`).join("; ")}`);
|
|
@@ -59722,7 +59744,7 @@ var ThreatFeeds = class {
|
|
|
59722
59744
|
this.blocking = ok;
|
|
59723
59745
|
mode = ok ? "blocking egress" : "detecting (nft load failed)";
|
|
59724
59746
|
}
|
|
59725
|
-
const failed = (set.sources ?? []).filter((s) => !s.ok).map((s) => s.feed);
|
|
59747
|
+
const failed = (set.sources ?? []).filter((s) => !s.ok).map((s) => s.carried ? `${s.feed}: kept ${s.carried} from ${s.last_ok_at?.slice(11, 16)} UTC` : s.feed);
|
|
59726
59748
|
const failing = failed.length ? `; ${failed.length}/${set.sources.length} feeds failing (${failed.join(", ")}), see \`threatcrush feeds\`` : "";
|
|
59727
59749
|
const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}${failing}`;
|
|
59728
59750
|
this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);
|
|
@@ -69076,7 +69098,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
69076
69098
|
console.log(` Fetched: ${set.fetched_at.replace("T", " ").slice(0, 16)} UTC`);
|
|
69077
69099
|
console.log(` ${ips} C2/payload IPs, ${domains} malware domains; ${set.skipped_shared} shared or protected entries skipped`);
|
|
69078
69100
|
for (const s of set.sources) {
|
|
69079
|
-
|
|
69101
|
+
const kept = s.carried ? source_default.yellow(` (keeping ${s.carried} from ${s.last_ok_at?.replace("T", " ").slice(0, 16)} UTC)`) : "";
|
|
69102
|
+
console.log(` ${s.ok ? source_default.green("\u2713") : source_default.red("\u2717")} ${s.feed.padEnd(16)} ${s.ok ? `${s.count}` : source_default.red(s.error ?? "failed")}${kept}`);
|
|
69080
69103
|
}
|
|
69081
69104
|
const failed = set.sources.filter((s) => !s.ok);
|
|
69082
69105
|
if (failed.length) {
|