@profullstack/threatcrush 0.13.39 → 0.13.41

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
@@ -24746,9 +24746,9 @@ var source_default = chalk;
24746
24746
  // src/index.ts
24747
24747
  var import_readline = __toESM(require("readline"));
24748
24748
  var import_node_child_process22 = require("child_process");
24749
- var import_node_fs51 = require("fs");
24750
- var import_node_path37 = require("path");
24751
- var import_node_os13 = require("os");
24749
+ var import_node_fs52 = require("fs");
24750
+ var import_node_path38 = require("path");
24751
+ var import_node_os14 = require("os");
24752
24752
 
24753
24753
  // src/commands/monitor.ts
24754
24754
  var import_node_fs10 = require("fs");
@@ -47969,8 +47969,105 @@ async function feedsCommand(action, value, opts) {
47969
47969
  console.log(source_default.gray("\n Blocking egress needs [threat_feeds] block = true and [remediation] in enforce mode."));
47970
47970
  }
47971
47971
 
47972
- // src/commands/privileged.ts
47972
+ // src/commands/reputation.ts
47973
+ var import_node_os13 = require("os");
47973
47974
  var import_node_fs49 = require("fs");
47975
+ var import_node_path37 = require("path");
47976
+ var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47977
+ var CONFIG_PATH3 = (0, import_node_path37.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
47978
+ function readConfig3() {
47979
+ try {
47980
+ return JSON.parse((0, import_node_fs49.readFileSync)(CONFIG_PATH3, "utf-8"));
47981
+ } catch {
47982
+ return {};
47983
+ }
47984
+ }
47985
+ function authFor(env2 = process.env, config = readConfig3()) {
47986
+ const key = env2.THREATCRUSH_API_KEY?.trim();
47987
+ if (key) return { headers: { Authorization: `Bearer ${key}` }, orgId: null };
47988
+ if (config.token) return { headers: { Authorization: `Bearer ${config.token}` }, orgId: config.current_org_id ?? null };
47989
+ return null;
47990
+ }
47991
+ function formatReport(r) {
47992
+ const lines = [];
47993
+ const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
47994
+ lines.push(` ${source_default.bold(r.ip)} ${head} ${source_default.dim(`(${r.tier})`)}`);
47995
+ if (r.reports) {
47996
+ lines.push(
47997
+ ` ${r.severity} \xB7 ${r.reports} reports from ${r.reporters} reporter${r.reporters === 1 ? "" : "s"} \xB7 last seen ${String(r.last_seen ?? "").slice(0, 10)}${r.country ? ` \xB7 ${r.country}` : ""}`
47998
+ );
47999
+ if (r.rule_ids.length) lines.push(` rules: ${r.rule_ids.join(", ")}`);
48000
+ }
48001
+ if (r.pro) {
48002
+ for (const reason of r.pro.reasons) lines.push(` \xB7 ${reason}`);
48003
+ lines.push(` ${r.pro.network}: ${r.pro.neighbours.count} other listed`);
48004
+ for (const d of r.pro.history.slice(0, 14)) lines.push(` ${d.day} ${String(d.reports).padStart(5)} ${d.rules.join(", ")}`);
48005
+ } else if (r.upgrade) {
48006
+ lines.push(source_default.dim(` history, /24 neighbours and score reasons: ${r.upgrade.url}`));
48007
+ }
48008
+ lines.push(source_default.dim(` public record: ${r.public_record}`));
48009
+ return lines;
48010
+ }
48011
+ async function reputationLookupCommand(ip, opts) {
48012
+ const auth = authFor();
48013
+ if (!auth) {
48014
+ console.log(source_default.red(" Set THREATCRUSH_API_KEY or run `threatcrush login` first. Keyless: https://nichedb.dev/reputation\n"));
48015
+ process.exitCode = 2;
48016
+ return;
48017
+ }
48018
+ 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 });
48021
+ const body = await res.json().catch(() => ({}));
48022
+ if (!res.ok) {
48023
+ console.log(source_default.red(` ${body.error ?? `HTTP ${res.status}`}
48024
+ `));
48025
+ process.exitCode = 2;
48026
+ return;
48027
+ }
48028
+ if (opts.json) console.log(JSON.stringify(body, null, 2));
48029
+ else console.log(`
48030
+ ${formatReport(body).join("\n")}
48031
+ `);
48032
+ if (body.listed) process.exitCode = 1;
48033
+ }
48034
+ async function reputationSubscribeCommand(opts) {
48035
+ const auth = authFor();
48036
+ if (!auth) {
48037
+ console.log(source_default.red(" Set THREATCRUSH_API_KEY (an admin key) or run `threatcrush login` first.\n"));
48038
+ process.exitCode = 2;
48039
+ return;
48040
+ }
48041
+ const res = await fetch(`${API_URL6}/api/v1/reputation/subscribe`, {
48042
+ method: "POST",
48043
+ headers: { ...auth.headers, "Content-Type": "application/json" },
48044
+ body: JSON.stringify({
48045
+ plan: opts.plan ?? "pro-monthly",
48046
+ currency: opts.currency ?? "usdc_pol",
48047
+ org_id: opts.org ?? auth.orgId ?? void 0
48048
+ })
48049
+ });
48050
+ const body = await res.json().catch(() => ({}));
48051
+ if (!res.ok) {
48052
+ console.log(source_default.red(` ${String(body.error ?? `HTTP ${res.status}`)}
48053
+ `));
48054
+ process.exitCode = 2;
48055
+ return;
48056
+ }
48057
+ if (opts.json) {
48058
+ console.log(JSON.stringify(body, null, 2));
48059
+ return;
48060
+ }
48061
+ console.log(`
48062
+ ${source_default.bold("Reputation Pro")} ${body.plan}: $${body.amount_usd} in ${body.currency}`);
48063
+ if (body.address) console.log(` send ${body.amount_crypto ?? ""} to ${source_default.green(String(body.address))}`);
48064
+ if (body.checkout_url) console.log(` or pay at ${body.checkout_url}`);
48065
+ console.log(source_default.dim(` payment ${body.payment_id}; Pro turns on when CoinPay confirms it.
48066
+ `));
48067
+ }
48068
+
48069
+ // src/commands/privileged.ts
48070
+ var import_node_fs50 = require("fs");
47974
48071
  init_paths();
47975
48072
  var SEV2 = {
47976
48073
  critical: source_default.red.bold,
@@ -47983,19 +48080,19 @@ async function privilegedCommand(opts) {
47983
48080
  const snapshot = takeSnapshot({
47984
48081
  readFile: (p) => {
47985
48082
  try {
47986
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
48083
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
47987
48084
  } catch {
47988
48085
  return null;
47989
48086
  }
47990
48087
  },
47991
48088
  readDir: (p) => {
47992
48089
  try {
47993
- return (0, import_node_fs49.readdirSync)(p);
48090
+ return (0, import_node_fs50.readdirSync)(p);
47994
48091
  } catch {
47995
48092
  return null;
47996
48093
  }
47997
48094
  },
47998
- exists: (p) => (0, import_node_fs49.existsSync)(p)
48095
+ exists: (p) => (0, import_node_fs50.existsSync)(p)
47999
48096
  });
48000
48097
  let events = [];
48001
48098
  let ledgerNote = "";
@@ -48177,7 +48274,7 @@ async function allowlistCommand(opts) {
48177
48274
  }
48178
48275
 
48179
48276
  // src/commands/abuse.ts
48180
- var import_node_fs50 = require("fs");
48277
+ var import_node_fs51 = require("fs");
48181
48278
  init_paths();
48182
48279
  function rows(records) {
48183
48280
  if (records.length === 0) {
@@ -48237,7 +48334,7 @@ function abuseRetractCommand(id, opts = {}) {
48237
48334
  );
48238
48335
  }
48239
48336
  function abuseStatusCommand(opts = {}) {
48240
- const config = loadConfig((0, import_node_fs50.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
48337
+ const config = loadConfig((0, import_node_fs51.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
48241
48338
  const cfg = resolveConfig(config.abuse_reporter);
48242
48339
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
48243
48340
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -48376,10 +48473,10 @@ ${source_default.green(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u25
48376
48473
  ${source_default.green(" \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D")}
48377
48474
  ${source_default.dim(" C R U S H")}
48378
48475
  `;
48379
- var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48476
+ var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48380
48477
  var PKG_NAME2 = "@profullstack/threatcrush";
48381
48478
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
48382
- var INSTALL_CONFIG_PATH = (0, import_node_path37.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
48479
+ var INSTALL_CONFIG_PATH = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush", "install.json");
48383
48480
  function detectPackageManager() {
48384
48481
  try {
48385
48482
  const npmGlobal = (0, import_node_child_process22.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -48405,7 +48502,7 @@ function detectPackageManager() {
48405
48502
  }
48406
48503
  function readInstallConfig() {
48407
48504
  try {
48408
- return JSON.parse((0, import_node_fs51.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
48505
+ return JSON.parse((0, import_node_fs52.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
48409
48506
  } catch {
48410
48507
  return {};
48411
48508
  }
@@ -48693,6 +48790,16 @@ program2.command("patches").description("List OS packages with a security update
48693
48790
  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) => {
48694
48791
  await feedsCommand(action, value, opts);
48695
48792
  });
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) {
48795
+ reputationCmd.help();
48796
+ return;
48797
+ }
48798
+ await reputationLookupCommand(ip, opts);
48799
+ });
48800
+ 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
+ await reputationSubscribeCommand(opts);
48802
+ });
48696
48803
  program2.command("privileged").description("Who can become root here (uid 0, sudo groups, sudoers, SSH keys) and the daemon's record of changes and sudo commands").option("--json", "Output as JSON").option("--limit <n>", "How many recent events to show", "25").action(async (opts) => {
48697
48804
  await privilegedCommand(opts);
48698
48805
  });
@@ -48732,7 +48839,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
48732
48839
  program2.command("logs").description("Tail daemon logs").action(async () => {
48733
48840
  console.log(LOGO2);
48734
48841
  const logPath2 = PATHS.logFile;
48735
- if (!(0, import_node_fs51.existsSync)(logPath2)) {
48842
+ if (!(0, import_node_fs52.existsSync)(logPath2)) {
48736
48843
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
48737
48844
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
48738
48845
  return;
@@ -48853,7 +48960,7 @@ var storeCmd = program2.command("store").description("Browse the module marketpl
48853
48960
  console.log(source_default.green(" Module Marketplace\n"));
48854
48961
  console.log(source_default.dim(" Loading available modules..."));
48855
48962
  try {
48856
- const res = await fetch(`${API_URL6}/api/modules`);
48963
+ const res = await fetch(`${API_URL7}/api/modules`);
48857
48964
  if (!res.ok) {
48858
48965
  console.log(source_default.red(` \u2717 Failed to load modules: ${res.statusText}
48859
48966
  `));
@@ -48880,7 +48987,7 @@ storeCmd.command("search <query>").description("Search for modules in the store"
48880
48987
  console.log(source_default.green(` Searching for "${query}"...
48881
48988
  `));
48882
48989
  try {
48883
- const res = await fetch(`${API_URL6}/api/modules?q=${encodeURIComponent(query)}`);
48990
+ const res = await fetch(`${API_URL7}/api/modules?q=${encodeURIComponent(query)}`);
48884
48991
  if (!res.ok) {
48885
48992
  console.log(source_default.red(` \u2717 Search failed: ${res.statusText}
48886
48993
  `));
@@ -48905,10 +49012,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
48905
49012
  });
48906
49013
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
48907
49014
  console.log(LOGO2);
48908
- const configPath = (0, import_node_path37.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
49015
+ const configPath = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
48909
49016
  let email = "";
48910
49017
  try {
48911
- const config = JSON.parse((0, import_node_fs51.readFileSync)(configPath, "utf-8"));
49018
+ const config = JSON.parse((0, import_node_fs52.readFileSync)(configPath, "utf-8"));
48912
49019
  email = config.email || "";
48913
49020
  } catch {
48914
49021
  }
@@ -48925,9 +49032,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
48925
49032
  return;
48926
49033
  }
48927
49034
  try {
48928
- const dir = (0, import_node_path37.join)((0, import_node_os13.homedir)(), ".threatcrush");
48929
- if (!(0, import_node_fs51.existsSync)(dir)) (0, import_node_fs51.mkdirSync)(dir, { recursive: true });
48930
- (0, import_node_fs51.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
49035
+ const dir = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush");
49036
+ if (!(0, import_node_fs52.existsSync)(dir)) (0, import_node_fs52.mkdirSync)(dir, { recursive: true });
49037
+ (0, import_node_fs52.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
48931
49038
  console.log(source_default.dim(` Saved email to ${configPath}`));
48932
49039
  } catch {
48933
49040
  }
@@ -48937,7 +49044,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
48937
49044
  `));
48938
49045
  let meta;
48939
49046
  try {
48940
- const res = await fetch(`${API_URL6}/api/modules/fetch-meta`, {
49047
+ const res = await fetch(`${API_URL7}/api/modules/fetch-meta`, {
48941
49048
  method: "POST",
48942
49049
  headers: { "Content-Type": "application/json" },
48943
49050
  body: JSON.stringify({ url, git_url: url })
@@ -48983,7 +49090,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
48983
49090
  }
48984
49091
  console.log(source_default.dim("\n Publishing..."));
48985
49092
  try {
48986
- const res = await fetch(`${API_URL6}/api/modules`, {
49093
+ const res = await fetch(`${API_URL7}/api/modules`, {
48987
49094
  method: "POST",
48988
49095
  headers: { "Content-Type": "application/json" },
48989
49096
  body: JSON.stringify({
@@ -49004,7 +49111,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
49004
49111
  const slug = mod?.slug || meta.name;
49005
49112
  console.log(source_default.green(`
49006
49113
  \u2713 Module submitted for review. It appears in the store once approved.`));
49007
- console.log(source_default.dim(` ${API_URL6}/store/${slug}
49114
+ console.log(source_default.dim(` ${API_URL7}/store/${slug}
49008
49115
  `));
49009
49116
  } catch (err) {
49010
49117
  console.log(source_default.red(`