@profullstack/threatcrush 0.13.42 → 0.13.44
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 +32 -11
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +145 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42484,6 +42484,17 @@ var NEVER_REPORT_RANGES = [
|
|
|
42484
42484
|
];
|
|
42485
42485
|
var CONNECTION_VERIFIED_CATEGORIES = /* @__PURE__ */ new Set(["auth", "web", "pentest"]);
|
|
42486
42486
|
var CONNECTION_VERIFIED_MODULES = ["honeypot", "honey-pot", "webhoneypot"];
|
|
42487
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
42488
|
+
function formSpamIdentity(event) {
|
|
42489
|
+
const raw = event.details?.form_spam;
|
|
42490
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
42491
|
+
const { username, email } = raw;
|
|
42492
|
+
if (typeof username !== "string" || typeof email !== "string") return void 0;
|
|
42493
|
+
const u = username.trim();
|
|
42494
|
+
const e = email.trim();
|
|
42495
|
+
if (!u || u.length > 255 || !EMAIL_RE.test(e) || e.length > 254) return void 0;
|
|
42496
|
+
return { username: u, email: e };
|
|
42497
|
+
}
|
|
42487
42498
|
function summarizeEvidence(events) {
|
|
42488
42499
|
const modules = /* @__PURE__ */ new Set();
|
|
42489
42500
|
const categories = /* @__PURE__ */ new Set();
|
|
@@ -42492,9 +42503,12 @@ function summarizeEvidence(events) {
|
|
|
42492
42503
|
let firstSeen = Infinity;
|
|
42493
42504
|
let lastSeen = 0;
|
|
42494
42505
|
let total = 0;
|
|
42506
|
+
let formSpam;
|
|
42495
42507
|
for (const event of events) {
|
|
42496
42508
|
if (event.module === "firewall-rules") continue;
|
|
42497
42509
|
total++;
|
|
42510
|
+
const identity = formSpamIdentity(event);
|
|
42511
|
+
if (identity && event.timestamp.getTime() >= lastSeen) formSpam = identity;
|
|
42498
42512
|
modules.add(event.module);
|
|
42499
42513
|
categories.add(event.category);
|
|
42500
42514
|
const ruleId = event.details?.rule_id;
|
|
@@ -42513,7 +42527,8 @@ function summarizeEvidence(events) {
|
|
|
42513
42527
|
lastSeen,
|
|
42514
42528
|
total,
|
|
42515
42529
|
categories: [...categories],
|
|
42516
|
-
ruleIds: [...ruleIds]
|
|
42530
|
+
ruleIds: [...ruleIds],
|
|
42531
|
+
...formSpam ? { formSpam } : {}
|
|
42517
42532
|
};
|
|
42518
42533
|
}
|
|
42519
42534
|
function isReportable(ip, evidence, config, now = Date.now()) {
|
|
@@ -42608,22 +42623,28 @@ async function reportToAbuseIPDB(payload, apiKey) {
|
|
|
42608
42623
|
}
|
|
42609
42624
|
}
|
|
42610
42625
|
async function reportToStopForumSpam(payload, apiKey) {
|
|
42626
|
+
const identity = payload.evidence.formSpam;
|
|
42627
|
+
if (!identity) {
|
|
42628
|
+
return { destination: "stopforumspam", ok: false, detail: "skipped: no form-spam username/email in evidence" };
|
|
42629
|
+
}
|
|
42611
42630
|
const body = new URLSearchParams({
|
|
42612
|
-
|
|
42613
|
-
|
|
42614
|
-
|
|
42631
|
+
username: identity.username,
|
|
42632
|
+
email: identity.email,
|
|
42633
|
+
ip_addr: payload.ip,
|
|
42634
|
+
evidence: payload.comment.slice(0, 1e3),
|
|
42635
|
+
api_key: apiKey
|
|
42615
42636
|
});
|
|
42616
42637
|
try {
|
|
42617
|
-
const res = await fetch("https://www.stopforumspam.
|
|
42638
|
+
const res = await fetch("https://www.stopforumspam.com/add.php", {
|
|
42618
42639
|
method: "POST",
|
|
42619
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded"
|
|
42640
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
42620
42641
|
body,
|
|
42621
42642
|
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
42622
42643
|
});
|
|
42623
42644
|
const text = await res.text().catch(() => "");
|
|
42624
|
-
if (
|
|
42625
|
-
const
|
|
42626
|
-
return { destination: "stopforumspam", ok, detail:
|
|
42645
|
+
if (res.status === 200) return { destination: "stopforumspam", ok: true, detail: "reported" };
|
|
42646
|
+
const reason = /<p[^>]*>([\s\S]*?)<\/p>/i.exec(text)?.[1]?.replace(/<[^>]+>/g, "").trim();
|
|
42647
|
+
return { destination: "stopforumspam", ok: false, detail: `HTTP ${res.status} ${(reason || text).slice(0, 160)}`.trim() };
|
|
42627
42648
|
} catch (err) {
|
|
42628
42649
|
return { destination: "stopforumspam", ok: false, detail: err.message };
|
|
42629
42650
|
}
|
|
@@ -42632,7 +42653,7 @@ async function dispatch(payload, destinations, keys) {
|
|
|
42632
42653
|
const jobs = [];
|
|
42633
42654
|
for (const dest of destinations) {
|
|
42634
42655
|
if (dest === "abuseipdb" && keys.abuseipdb) jobs.push(reportToAbuseIPDB(payload, keys.abuseipdb));
|
|
42635
|
-
else if (dest === "stopforumspam" && keys.stopforumspam) jobs.push(reportToStopForumSpam(payload, keys.stopforumspam));
|
|
42656
|
+
else if (dest === "stopforumspam" && keys.stopforumspam && payload.evidence.formSpam) jobs.push(reportToStopForumSpam(payload, keys.stopforumspam));
|
|
42636
42657
|
}
|
|
42637
42658
|
return Promise.all(jobs);
|
|
42638
42659
|
}
|
|
@@ -42758,7 +42779,7 @@ var AbuseReporter = class {
|
|
|
42758
42779
|
}
|
|
42759
42780
|
if (!this.active) {
|
|
42760
42781
|
this.opts.log(
|
|
42761
|
-
"[abuse] reporter on but inert: no destination API key set (ABUSEIPDB_API_KEY or [abuse-reporter]
|
|
42782
|
+
"[abuse] reporter on but inert: no destination API key set (ABUSEIPDB_API_KEY / STOPFORUMSPAM_API_KEY or [abuse-reporter] *_api_key). Nothing will be reported."
|
|
42762
42783
|
);
|
|
42763
42784
|
return;
|
|
42764
42785
|
}
|
|
@@ -48000,6 +48021,8 @@ function formatReport(r) {
|
|
|
48000
48021
|
}
|
|
48001
48022
|
if (r.pro) {
|
|
48002
48023
|
for (const reason of r.pro.reasons) lines.push(` \xB7 ${reason}`);
|
|
48024
|
+
if (r.pro.owner)
|
|
48025
|
+
lines.push(` AS${r.pro.owner.asn} ${r.pro.owner.org ?? ""}${r.pro.owner.network ? ` (${r.pro.owner.network})` : ""}: ${r.pro.owner.listed_addresses} other listed`);
|
|
48003
48026
|
lines.push(` ${r.pro.network}: ${r.pro.neighbours.count} other listed`);
|
|
48004
48027
|
for (const d of r.pro.history.slice(0, 14)) lines.push(` ${d.day} ${String(d.reports).padStart(5)} ${d.rules.join(", ")}`);
|
|
48005
48028
|
} else if (r.upgrade) {
|
|
@@ -48008,28 +48031,124 @@ function formatReport(r) {
|
|
|
48008
48031
|
lines.push(source_default.dim(` public record: ${r.public_record}`));
|
|
48009
48032
|
return lines;
|
|
48010
48033
|
}
|
|
48011
|
-
|
|
48034
|
+
function formatAny(r) {
|
|
48035
|
+
if (r.type !== "domain") return formatReport(r);
|
|
48036
|
+
const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
|
|
48037
|
+
const lines = [` ${source_default.bold(r.domain)} ${head} ${source_default.dim(`(${r.tier})`)}`];
|
|
48038
|
+
for (const reason of r.reasons) lines.push(` \xB7 ${reason}`);
|
|
48039
|
+
for (const a of r.addresses) lines.push(` ${a.ip}: ${a.listed ? source_default.red(`listed, ${a.score}/100`) : "not listed"}`);
|
|
48040
|
+
lines.push(source_default.dim(` public record: ${r.public_record}`));
|
|
48041
|
+
return lines;
|
|
48042
|
+
}
|
|
48043
|
+
function needAuth() {
|
|
48012
48044
|
const auth = authFor();
|
|
48013
48045
|
if (!auth) {
|
|
48014
48046
|
console.log(source_default.red(" Set THREATCRUSH_API_KEY or run `threatcrush login` first. Keyless: https://nichedb.dev/reputation\n"));
|
|
48015
48047
|
process.exitCode = 2;
|
|
48016
|
-
return;
|
|
48017
48048
|
}
|
|
48049
|
+
return auth;
|
|
48050
|
+
}
|
|
48051
|
+
async function reputationLookupCommand(indicators, opts) {
|
|
48052
|
+
const auth = needAuth();
|
|
48053
|
+
if (!auth) return;
|
|
48054
|
+
const org = opts.org ?? auth.orgId;
|
|
48055
|
+
let reports;
|
|
48056
|
+
if (indicators.length === 1) {
|
|
48057
|
+
const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
|
|
48058
|
+
const res = await fetch(url, { headers: auth.headers });
|
|
48059
|
+
const body = await res.json().catch(() => ({}));
|
|
48060
|
+
if (!res.ok) {
|
|
48061
|
+
console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
|
|
48062
|
+
`));
|
|
48063
|
+
process.exitCode = 2;
|
|
48064
|
+
return;
|
|
48065
|
+
}
|
|
48066
|
+
reports = [body];
|
|
48067
|
+
} else {
|
|
48068
|
+
const res = await fetch(`${API_URL6}/api/v1/reputation/bulk`, {
|
|
48069
|
+
method: "POST",
|
|
48070
|
+
headers: { ...auth.headers, "Content-Type": "application/json" },
|
|
48071
|
+
body: JSON.stringify({ indicators, org: org ?? void 0 })
|
|
48072
|
+
});
|
|
48073
|
+
const body = await res.json().catch(() => ({}));
|
|
48074
|
+
if (!res.ok || !body.results) {
|
|
48075
|
+
console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
|
|
48076
|
+
`));
|
|
48077
|
+
process.exitCode = 2;
|
|
48078
|
+
return;
|
|
48079
|
+
}
|
|
48080
|
+
reports = body.results;
|
|
48081
|
+
}
|
|
48082
|
+
if (opts.json) console.log(JSON.stringify(reports.length === 1 ? reports[0] : reports, null, 2));
|
|
48083
|
+
else {
|
|
48084
|
+
for (const r of reports) {
|
|
48085
|
+
if ("error" in r && r.error) console.log(source_default.red(` ${r.query}: ${r.error}`));
|
|
48086
|
+
else console.log(`
|
|
48087
|
+
${formatAny(r).join("\n")}`);
|
|
48088
|
+
}
|
|
48089
|
+
console.log("");
|
|
48090
|
+
}
|
|
48091
|
+
if (reports.some((r) => r.listed)) process.exitCode = 1;
|
|
48092
|
+
}
|
|
48093
|
+
async function reputationWatchCommand(action, indicator, opts) {
|
|
48094
|
+
const auth = needAuth();
|
|
48095
|
+
if (!auth) return;
|
|
48018
48096
|
const org = opts.org ?? auth.orgId;
|
|
48019
|
-
|
|
48020
|
-
|
|
48097
|
+
if (!org && auth.orgId === null && !process.env.THREATCRUSH_API_KEY) {
|
|
48098
|
+
console.log(source_default.red(" Pick an org first: `threatcrush orgs use <slug>` or --org <id>.\n"));
|
|
48099
|
+
process.exitCode = 2;
|
|
48100
|
+
return;
|
|
48101
|
+
}
|
|
48102
|
+
const qs = org ? `org=${encodeURIComponent(org)}` : "";
|
|
48103
|
+
let res;
|
|
48104
|
+
if (action === "add") {
|
|
48105
|
+
if (!indicator) {
|
|
48106
|
+
console.log(source_default.red(" Usage: threatcrush reputation watch add <ip-or-domain> [--note \u2026]\n"));
|
|
48107
|
+
process.exitCode = 2;
|
|
48108
|
+
return;
|
|
48109
|
+
}
|
|
48110
|
+
res = await fetch(`${API_URL6}/api/v1/reputation/watches`, {
|
|
48111
|
+
method: "POST",
|
|
48112
|
+
headers: { ...auth.headers, "Content-Type": "application/json" },
|
|
48113
|
+
body: JSON.stringify({ indicator, note: opts.note, destination_id: opts.destination, org: org ?? void 0 })
|
|
48114
|
+
});
|
|
48115
|
+
} else if (action === "rm" || action === "remove") {
|
|
48116
|
+
if (!indicator) {
|
|
48117
|
+
console.log(source_default.red(" Usage: threatcrush reputation watch rm <ip-or-domain>\n"));
|
|
48118
|
+
process.exitCode = 2;
|
|
48119
|
+
return;
|
|
48120
|
+
}
|
|
48121
|
+
res = await fetch(`${API_URL6}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
|
|
48122
|
+
method: "DELETE",
|
|
48123
|
+
headers: auth.headers
|
|
48124
|
+
});
|
|
48125
|
+
} else {
|
|
48126
|
+
res = await fetch(`${API_URL6}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
|
|
48127
|
+
}
|
|
48021
48128
|
const body = await res.json().catch(() => ({}));
|
|
48022
48129
|
if (!res.ok) {
|
|
48023
|
-
console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
|
|
48130
|
+
console.log(source_default.red(` ${String(body.error ?? `HTTP ${res.status}`)}
|
|
48024
48131
|
`));
|
|
48025
48132
|
process.exitCode = 2;
|
|
48026
48133
|
return;
|
|
48027
48134
|
}
|
|
48028
|
-
if (opts.json)
|
|
48029
|
-
|
|
48030
|
-
|
|
48135
|
+
if (opts.json) {
|
|
48136
|
+
console.log(JSON.stringify(body, null, 2));
|
|
48137
|
+
return;
|
|
48138
|
+
}
|
|
48139
|
+
if (action === "add") console.log(source_default.green(` watching ${indicator}
|
|
48140
|
+
`));
|
|
48141
|
+
else if (action === "rm" || action === "remove") console.log(` removed ${body.removed ?? 0}
|
|
48031
48142
|
`);
|
|
48032
|
-
|
|
48143
|
+
else {
|
|
48144
|
+
const watches = body.watches ?? [];
|
|
48145
|
+
if (!watches.length) console.log(source_default.dim(" no watches yet: threatcrush reputation watch add <ip-or-domain>\n"));
|
|
48146
|
+
for (const w of watches) {
|
|
48147
|
+
const state = w.last_listed == null ? source_default.dim("not checked yet") : w.last_listed ? source_default.red(`LISTED ${w.last_score}/100`) : source_default.green("clear");
|
|
48148
|
+
console.log(` ${w.indicator.padEnd(40)} ${state}${w.note ? source_default.dim(` ${w.note}`) : ""}`);
|
|
48149
|
+
}
|
|
48150
|
+
console.log("");
|
|
48151
|
+
}
|
|
48033
48152
|
}
|
|
48034
48153
|
async function reputationSubscribeCommand(opts) {
|
|
48035
48154
|
const auth = authFor();
|
|
@@ -48790,12 +48909,15 @@ program2.command("patches").description("List OS packages with a security update
|
|
|
48790
48909
|
program2.command("feeds [action] [value]").description("Show the abuse.ch C2/malware list the daemon matches; `feeds check <ip|domain>` looks one up (exit 1 when listed); `feeds resolver install|remove|status` lets dnsmasq/unbound refuse the listed domains").option("--json", "Output as JSON").action(async (action, value, opts) => {
|
|
48791
48910
|
await feedsCommand(action, value, opts);
|
|
48792
48911
|
});
|
|
48793
|
-
var reputationCmd = program2.command("reputation").description("Look
|
|
48794
|
-
if (!
|
|
48912
|
+
var reputationCmd = program2.command("reputation").description("Look IPs or domains up against the ThreatCrush community database (exit 1 when any is listed; several at once go as one bulk request); `reputation watch` alerts on changes, `reputation subscribe` starts a Reputation Pro payment through CoinPay").argument("[indicators...]", "IP addresses or domains to look up").option("--json", "Output as JSON").option("--org <id>", "Org to look up as (defaults to `orgs use`)").action(async (indicators, opts) => {
|
|
48913
|
+
if (!indicators?.length) {
|
|
48795
48914
|
reputationCmd.help();
|
|
48796
48915
|
return;
|
|
48797
48916
|
}
|
|
48798
|
-
await reputationLookupCommand(
|
|
48917
|
+
await reputationLookupCommand(indicators, opts);
|
|
48918
|
+
});
|
|
48919
|
+
reputationCmd.command("watch [action] [indicator]").description("Reputation Pro watch lists: `watch list`, `watch add <ip-or-domain> [--note]`, `watch rm <ip-or-domain>`; alerts go to the org's alert destinations").option("--org <id>", "Org (defaults to `orgs use`)").option("--note <text>", "Why you watch it, shown in the alert").option("--destination <id>", "Alert destination id (default: every enabled destination)").option("--json", "Output as JSON").action(async (action, indicator, opts) => {
|
|
48920
|
+
await reputationWatchCommand(action, indicator, opts);
|
|
48799
48921
|
});
|
|
48800
48922
|
reputationCmd.command("subscribe").description("Pay for Reputation Pro in crypto (history, /24 neighbours, score reasons, more lookups)").option("--plan <id>", "pro-monthly or pro-yearly", "pro-monthly").option("--currency <c>", "usdc_pol, usdc_sol, usdc_eth, usdt, pol, sol, btc or eth", "usdc_pol").option("--org <id>", "Org to pay for (defaults to `orgs use`)").option("--json", "Output as JSON").action(async (opts) => {
|
|
48801
48923
|
await reputationSubscribeCommand(opts);
|