@profullstack/threatcrush 0.15.1 → 0.15.3
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/av-worker.js +6 -1
- package/dist/av-worker.js.map +1 -1
- package/dist/daemon.js +27 -5
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +35 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53385,6 +53385,9 @@ var WIN_SCRIPT_EXTS = /* @__PURE__ */ new Set(["js", "jse", "vbs", "vbe", "wsf",
|
|
|
53385
53385
|
var WEB_EXTS = /* @__PURE__ */ new Set(["html", "htm", "shtml", "xhtml", "svg", "hta"]);
|
|
53386
53386
|
var SERVER_SCRIPT_EXTS = /* @__PURE__ */ new Set(["php", "phtml", "php3", "php4", "php5", "php7", "phar", "asp", "aspx", "ashx", "jsp", "jspx"]);
|
|
53387
53387
|
var isScript = (c) => c.kind === "script" || SCRIPT_EXTS.has(c.ext);
|
|
53388
|
+
var SHELL_EXTS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "command", "bat", "cmd"]);
|
|
53389
|
+
var isShellScript = (c) => SHELL_EXTS.has(c.ext) || !c.ext && /^#!\s*\S*\/(?:env\s+)?(?:ba|z|da|k)?sh\b/.test(c.text);
|
|
53390
|
+
var EXEC_SINK = /child_process|\bexecSync\b|\bspawn(?:Sync)?\s*\(|\bexecFile\b|subprocess\.|os\.(?:system|popen|exec\w*)\s*\(|\bPopen\s*\(|\bsystem\s*\(|(?<![.\w$])exec\s*\(|\bshell_exec\b|\bpassthru\b|\bproc_open\b|Invoke-Expression|\bIEX\b|Start-Process|WScript\.Shell|Runtime\.getRuntime/;
|
|
53388
53391
|
var POWERSHELL_HOST_EXTS = /* @__PURE__ */ new Set(["ps1", "psm1", "bat", "cmd", "vbs", "vbe", "wsf", "hta"]);
|
|
53389
53392
|
var isWindowsScriptContext = (c) => POWERSHELL_HOST_EXTS.has(c.ext) || c.kind === "lnk" || ["js", "jse"].includes(c.ext) && /ActiveXObject|WScript\.|GetObject\(\s*["']winmgmts/i.test(c.text);
|
|
53390
53393
|
var NON_RUNNABLE_SOURCE_EXTS = /* @__PURE__ */ new Set(["ts", "tsx", "mts", "cts", "md", "markdown", "rst", "go", "rs", "c", "h", "cc", "cpp", "hpp", "java", "kt", "cs", "swift", "scala"]);
|
|
@@ -53536,7 +53539,9 @@ var RULES = [
|
|
|
53536
53539
|
test: (c) => {
|
|
53537
53540
|
if (!isScript(c)) return false;
|
|
53538
53541
|
const t = c.text;
|
|
53539
|
-
|
|
53542
|
+
const oneLiner = /bash\s+-i\s*>&\s*\/dev\/tcp\//.test(t) || /\/dev\/tcp\/\d{1,3}(?:\.\d{1,3}){3}\/\d{2,5}\s*0>&1/.test(t) || /\bnc(?:at)?\s+(?:-\w+\s+)*-e\s+\/bin\/(?:ba)?sh\b/.test(t);
|
|
53543
|
+
if (oneLiner && (isShellScript(c) || EXEC_SINK.test(t))) return true;
|
|
53544
|
+
return /socket\.socket\([\s\S]{0,300}?(?:os\.dup2|pty\.spawn)\([\s\S]{0,300}?\/bin\/(?:ba)?sh/.test(t) || /New-Object\s+System\.Net\.Sockets\.TCPClient\([\s\S]{0,600}?(?:\bIEX\b|Invoke-Expression)/i.test(t);
|
|
53540
53545
|
}
|
|
53541
53546
|
},
|
|
53542
53547
|
{
|
|
@@ -56786,6 +56791,7 @@ var import_node_readline3 = require("readline");
|
|
|
56786
56791
|
var import_node_fs44 = require("fs");
|
|
56787
56792
|
var import_node_path30 = require("path");
|
|
56788
56793
|
var import_node_net10 = require("net");
|
|
56794
|
+
var CARRY_MAX_MS = 24 * 36e5;
|
|
56789
56795
|
var FEEDS = {
|
|
56790
56796
|
/** POST `{ query: 'get_iocs', days }` with an `Auth-Key` header. */
|
|
56791
56797
|
threatfoxApi: "https://threatfox-api.abuse.ch/api/v1/",
|
|
@@ -57016,7 +57022,7 @@ function redact(message, key) {
|
|
|
57016
57022
|
if (!key) return message;
|
|
57017
57023
|
return message.split(key).join("<auth-key>").split(encodeURIComponent(key)).join("<auth-key>");
|
|
57018
57024
|
}
|
|
57019
|
-
async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
57025
|
+
async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3, previous = null, now = /* @__PURE__ */ new Date()) {
|
|
57020
57026
|
const sources = [];
|
|
57021
57027
|
const parts = [];
|
|
57022
57028
|
const key = settings.authKey?.trim() || void 0;
|
|
@@ -57048,8 +57054,11 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
|
57048
57054
|
}
|
|
57049
57055
|
const count = (part.ips?.size ?? 0) + (part.domains?.size ?? 0);
|
|
57050
57056
|
if (count === 0 && !emptyOk) throw new Error("no entries in the response");
|
|
57057
|
+
for (const map of [part.ips, part.domains]) {
|
|
57058
|
+
for (const [k, ind] of map ?? []) map.set(k, { ...ind, source: feed });
|
|
57059
|
+
}
|
|
57051
57060
|
parts.push(part);
|
|
57052
|
-
sources.push({ feed, ok: true, count });
|
|
57061
|
+
sources.push({ feed, ok: true, count, last_ok_at: now.toISOString() });
|
|
57053
57062
|
} catch (err) {
|
|
57054
57063
|
sources.push({ feed, ok: false, count: 0, error: redact(err.message, key) });
|
|
57055
57064
|
}
|
|
@@ -57069,8 +57078,26 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
|
57069
57078
|
// Feodo has been near-empty since 2025; an empty list there is real.
|
|
57070
57079
|
get2("feodo", { url: FEEDS.feodoIps }, (t) => ({ ips: parseIpList(t, "feodo") }), true)
|
|
57071
57080
|
]);
|
|
57081
|
+
carryForward(previous, sources, parts, now);
|
|
57072
57082
|
sources.sort((a, b) => a.feed.localeCompare(b.feed));
|
|
57073
|
-
return buildFeedSet(parts, settings.allow, sources);
|
|
57083
|
+
return buildFeedSet(parts, settings.allow, sources, now);
|
|
57084
|
+
}
|
|
57085
|
+
function carryForward(previous, sources, parts, now) {
|
|
57086
|
+
if (!previous) return;
|
|
57087
|
+
for (const s of sources) {
|
|
57088
|
+
if (s.ok || s.error === NEEDS_KEY) continue;
|
|
57089
|
+
const prev = previous.sources?.find((p) => p.feed === s.feed);
|
|
57090
|
+
const lastOk = prev?.last_ok_at;
|
|
57091
|
+
if (!lastOk || now.getTime() - Date.parse(lastOk) > CARRY_MAX_MS) continue;
|
|
57092
|
+
const part = { ips: /* @__PURE__ */ new Map(), domains: /* @__PURE__ */ new Map() };
|
|
57093
|
+
for (const [ip, ind] of Object.entries(previous.ips)) if (ind.source === s.feed) part.ips.set(ip, ind);
|
|
57094
|
+
for (const [d, ind] of Object.entries(previous.domains)) if (ind.source === s.feed) part.domains.set(d, ind);
|
|
57095
|
+
const kept = part.ips.size + part.domains.size;
|
|
57096
|
+
s.last_ok_at = lastOk;
|
|
57097
|
+
if (!kept) continue;
|
|
57098
|
+
parts.push(part);
|
|
57099
|
+
s.carried = kept;
|
|
57100
|
+
}
|
|
57074
57101
|
}
|
|
57075
57102
|
function readFeedCache(path2) {
|
|
57076
57103
|
try {
|
|
@@ -59694,7 +59721,7 @@ var ThreatFeeds = class {
|
|
|
59694
59721
|
}
|
|
59695
59722
|
async refresh() {
|
|
59696
59723
|
try {
|
|
59697
|
-
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs);
|
|
59724
|
+
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs, this.set, new Date(this.now()));
|
|
59698
59725
|
const failed = set.sources.filter((s) => !s.ok);
|
|
59699
59726
|
if (failed.length === set.sources.length) {
|
|
59700
59727
|
this.opts.log(`[threat-feeds] refresh failed, keeping previous list: ${failed.map((s) => `${s.feed}: ${s.error}`).join("; ")}`);
|
|
@@ -59722,7 +59749,7 @@ var ThreatFeeds = class {
|
|
|
59722
59749
|
this.blocking = ok;
|
|
59723
59750
|
mode = ok ? "blocking egress" : "detecting (nft load failed)";
|
|
59724
59751
|
}
|
|
59725
|
-
const failed = (set.sources ?? []).filter((s) => !s.ok).map((s) => s.feed);
|
|
59752
|
+
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
59753
|
const failing = failed.length ? `; ${failed.length}/${set.sources.length} feeds failing (${failed.join(", ")}), see \`threatcrush feeds\`` : "";
|
|
59727
59754
|
const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}${failing}`;
|
|
59728
59755
|
this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);
|
|
@@ -69076,7 +69103,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
69076
69103
|
console.log(` Fetched: ${set.fetched_at.replace("T", " ").slice(0, 16)} UTC`);
|
|
69077
69104
|
console.log(` ${ips} C2/payload IPs, ${domains} malware domains; ${set.skipped_shared} shared or protected entries skipped`);
|
|
69078
69105
|
for (const s of set.sources) {
|
|
69079
|
-
|
|
69106
|
+
const kept = s.carried ? source_default.yellow(` (keeping ${s.carried} from ${s.last_ok_at?.replace("T", " ").slice(0, 16)} UTC)`) : "";
|
|
69107
|
+
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
69108
|
}
|
|
69081
69109
|
const failed = set.sources.filter((s) => !s.ok);
|
|
69082
69110
|
if (failed.length) {
|