@profullstack/threatcrush 0.13.41 → 0.13.43

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/index.js CHANGED
@@ -48000,6 +48000,8 @@ function formatReport(r) {
48000
48000
  }
48001
48001
  if (r.pro) {
48002
48002
  for (const reason of r.pro.reasons) lines.push(` \xB7 ${reason}`);
48003
+ if (r.pro.owner)
48004
+ 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
48005
  lines.push(` ${r.pro.network}: ${r.pro.neighbours.count} other listed`);
48004
48006
  for (const d of r.pro.history.slice(0, 14)) lines.push(` ${d.day} ${String(d.reports).padStart(5)} ${d.rules.join(", ")}`);
48005
48007
  } else if (r.upgrade) {
@@ -48008,28 +48010,124 @@ function formatReport(r) {
48008
48010
  lines.push(source_default.dim(` public record: ${r.public_record}`));
48009
48011
  return lines;
48010
48012
  }
48011
- async function reputationLookupCommand(ip, opts) {
48013
+ function formatAny(r) {
48014
+ if (r.type !== "domain") return formatReport(r);
48015
+ const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
48016
+ const lines = [` ${source_default.bold(r.domain)} ${head} ${source_default.dim(`(${r.tier})`)}`];
48017
+ for (const reason of r.reasons) lines.push(` \xB7 ${reason}`);
48018
+ for (const a of r.addresses) lines.push(` ${a.ip}: ${a.listed ? source_default.red(`listed, ${a.score}/100`) : "not listed"}`);
48019
+ lines.push(source_default.dim(` public record: ${r.public_record}`));
48020
+ return lines;
48021
+ }
48022
+ function needAuth() {
48012
48023
  const auth = authFor();
48013
48024
  if (!auth) {
48014
48025
  console.log(source_default.red(" Set THREATCRUSH_API_KEY or run `threatcrush login` first. Keyless: https://nichedb.dev/reputation\n"));
48015
48026
  process.exitCode = 2;
48016
- return;
48017
48027
  }
48028
+ return auth;
48029
+ }
48030
+ async function reputationLookupCommand(indicators, opts) {
48031
+ const auth = needAuth();
48032
+ if (!auth) return;
48033
+ const org = opts.org ?? auth.orgId;
48034
+ let reports;
48035
+ if (indicators.length === 1) {
48036
+ const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
48037
+ const res = await fetch(url, { headers: auth.headers });
48038
+ const body = await res.json().catch(() => ({}));
48039
+ if (!res.ok) {
48040
+ console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
48041
+ `));
48042
+ process.exitCode = 2;
48043
+ return;
48044
+ }
48045
+ reports = [body];
48046
+ } else {
48047
+ const res = await fetch(`${API_URL6}/api/v1/reputation/bulk`, {
48048
+ method: "POST",
48049
+ headers: { ...auth.headers, "Content-Type": "application/json" },
48050
+ body: JSON.stringify({ indicators, org: org ?? void 0 })
48051
+ });
48052
+ const body = await res.json().catch(() => ({}));
48053
+ if (!res.ok || !body.results) {
48054
+ console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
48055
+ `));
48056
+ process.exitCode = 2;
48057
+ return;
48058
+ }
48059
+ reports = body.results;
48060
+ }
48061
+ if (opts.json) console.log(JSON.stringify(reports.length === 1 ? reports[0] : reports, null, 2));
48062
+ else {
48063
+ for (const r of reports) {
48064
+ if ("error" in r && r.error) console.log(source_default.red(` ${r.query}: ${r.error}`));
48065
+ else console.log(`
48066
+ ${formatAny(r).join("\n")}`);
48067
+ }
48068
+ console.log("");
48069
+ }
48070
+ if (reports.some((r) => r.listed)) process.exitCode = 1;
48071
+ }
48072
+ async function reputationWatchCommand(action, indicator, opts) {
48073
+ const auth = needAuth();
48074
+ if (!auth) return;
48018
48075
  const org = opts.org ?? auth.orgId;
48019
- const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(ip)}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
48020
- const res = await fetch(url, { headers: auth.headers });
48076
+ if (!org && auth.orgId === null && !process.env.THREATCRUSH_API_KEY) {
48077
+ console.log(source_default.red(" Pick an org first: `threatcrush orgs use <slug>` or --org <id>.\n"));
48078
+ process.exitCode = 2;
48079
+ return;
48080
+ }
48081
+ const qs = org ? `org=${encodeURIComponent(org)}` : "";
48082
+ let res;
48083
+ if (action === "add") {
48084
+ if (!indicator) {
48085
+ console.log(source_default.red(" Usage: threatcrush reputation watch add <ip-or-domain> [--note \u2026]\n"));
48086
+ process.exitCode = 2;
48087
+ return;
48088
+ }
48089
+ res = await fetch(`${API_URL6}/api/v1/reputation/watches`, {
48090
+ method: "POST",
48091
+ headers: { ...auth.headers, "Content-Type": "application/json" },
48092
+ body: JSON.stringify({ indicator, note: opts.note, destination_id: opts.destination, org: org ?? void 0 })
48093
+ });
48094
+ } else if (action === "rm" || action === "remove") {
48095
+ if (!indicator) {
48096
+ console.log(source_default.red(" Usage: threatcrush reputation watch rm <ip-or-domain>\n"));
48097
+ process.exitCode = 2;
48098
+ return;
48099
+ }
48100
+ res = await fetch(`${API_URL6}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
48101
+ method: "DELETE",
48102
+ headers: auth.headers
48103
+ });
48104
+ } else {
48105
+ res = await fetch(`${API_URL6}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
48106
+ }
48021
48107
  const body = await res.json().catch(() => ({}));
48022
48108
  if (!res.ok) {
48023
- console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
48109
+ console.log(source_default.red(` ${String(body.error ?? `HTTP ${res.status}`)}
48024
48110
  `));
48025
48111
  process.exitCode = 2;
48026
48112
  return;
48027
48113
  }
48028
- if (opts.json) console.log(JSON.stringify(body, null, 2));
48029
- else console.log(`
48030
- ${formatReport(body).join("\n")}
48114
+ if (opts.json) {
48115
+ console.log(JSON.stringify(body, null, 2));
48116
+ return;
48117
+ }
48118
+ if (action === "add") console.log(source_default.green(` watching ${indicator}
48119
+ `));
48120
+ else if (action === "rm" || action === "remove") console.log(` removed ${body.removed ?? 0}
48031
48121
  `);
48032
- if (body.listed) process.exitCode = 1;
48122
+ else {
48123
+ const watches = body.watches ?? [];
48124
+ if (!watches.length) console.log(source_default.dim(" no watches yet: threatcrush reputation watch add <ip-or-domain>\n"));
48125
+ for (const w of watches) {
48126
+ 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");
48127
+ console.log(` ${w.indicator.padEnd(40)} ${state}${w.note ? source_default.dim(` ${w.note}`) : ""}`);
48128
+ }
48129
+ console.log("");
48130
+ }
48033
48131
  }
48034
48132
  async function reputationSubscribeCommand(opts) {
48035
48133
  const auth = authFor();
@@ -48790,12 +48888,15 @@ program2.command("patches").description("List OS packages with a security update
48790
48888
  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
48889
  await feedsCommand(action, value, opts);
48792
48890
  });
48793
- var reputationCmd = program2.command("reputation").description("Look an IP up against the ThreatCrush community database (exit 1 when listed); `reputation subscribe` starts a Reputation Pro payment through CoinPay").argument("[ip]", "IP address to look up").option("--json", "Output as JSON").option("--org <id>", "Org to look up as (defaults to `orgs use`)").action(async (ip, opts) => {
48794
- if (!ip) {
48891
+ 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) => {
48892
+ if (!indicators?.length) {
48795
48893
  reputationCmd.help();
48796
48894
  return;
48797
48895
  }
48798
- await reputationLookupCommand(ip, opts);
48896
+ await reputationLookupCommand(indicators, opts);
48897
+ });
48898
+ 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) => {
48899
+ await reputationWatchCommand(action, indicator, opts);
48799
48900
  });
48800
48901
  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
48902
  await reputationSubscribeCommand(opts);