@profullstack/threatcrush 0.13.13 → 0.13.14
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/README.md +6 -1
- package/dist/index.js +223 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,13 +170,18 @@ Config lives at `/etc/threatcrush/threatcrushd.conf` with module configs in `/et
|
|
|
170
170
|
The daemon reports to your ThreatCrush dashboard once the machine is logged in and linked to a server there:
|
|
171
171
|
|
|
172
172
|
```bash
|
|
173
|
-
threatcrush login
|
|
173
|
+
threatcrush login # prints a link: approve it in a browser where you are signed in
|
|
174
174
|
threatcrush servers link # reuses the dashboard server with this hostname, or registers one
|
|
175
175
|
threatcrush servers link --org acme --name web-1
|
|
176
|
+
threatcrush save # store this machine's daemon config on its server (secrets redacted)
|
|
176
177
|
threatcrush status # shows the link
|
|
177
178
|
threatcrush servers unlink # stop reporting
|
|
178
179
|
```
|
|
179
180
|
|
|
181
|
+
`threatcrush login` needs no browser on the machine and never asks for a password: it prints a `threatcrush.com/cli/login` link and a short code, you approve it from any signed-in browser after checking the code matches, and the terminal finishes signing in on its own (PKCE-bound, so only the terminal that started it can redeem it; the link expires after 10 minutes). Each machine gets its own session. `threatcrush login --password` keeps the email-and-password prompt.
|
|
182
|
+
|
|
183
|
+
`threatcrush save` uploads the config the daemon reads (`/etc/threatcrush/threatcrushd.conf` as root). Values under keys that look like secrets (passwords, tokens, webhook URLs, API keys) are replaced with `[redacted]` before upload, and again by the server.
|
|
184
|
+
|
|
180
185
|
A running daemon picks up `link` and `unlink` within a minute; no restart. It then:
|
|
181
186
|
|
|
182
187
|
- uploads detections at or above `[cloud] min_severity` (rule detections, plus events from modules no rule reads, such as dns-monitor), batched (100 events or every 10 s), and every ban and unban the daemon makes;
|
package/dist/index.js
CHANGED
|
@@ -15907,9 +15907,9 @@ var source_default = chalk;
|
|
|
15907
15907
|
// src/index.ts
|
|
15908
15908
|
var import_readline = __toESM(require("readline"));
|
|
15909
15909
|
var import_node_child_process15 = require("child_process");
|
|
15910
|
-
var
|
|
15910
|
+
var import_node_fs36 = require("fs");
|
|
15911
15911
|
var import_node_path24 = require("path");
|
|
15912
|
-
var
|
|
15912
|
+
var import_node_os10 = require("os");
|
|
15913
15913
|
|
|
15914
15914
|
// src/commands/monitor.ts
|
|
15915
15915
|
var import_node_fs7 = require("fs");
|
|
@@ -28019,6 +28019,78 @@ function ask(question, opts = {}) {
|
|
|
28019
28019
|
return stdinIsInteractive() ? askTerminal(question, mask) : askPiped(question, mask);
|
|
28020
28020
|
}
|
|
28021
28021
|
|
|
28022
|
+
// src/core/link-login.ts
|
|
28023
|
+
var import_node_crypto3 = require("crypto");
|
|
28024
|
+
var import_node_os5 = require("os");
|
|
28025
|
+
function createPkce() {
|
|
28026
|
+
const verifier = (0, import_node_crypto3.randomBytes)(32).toString("base64url");
|
|
28027
|
+
const challenge = (0, import_node_crypto3.createHash)("sha256").update(verifier).digest("base64url");
|
|
28028
|
+
return { verifier, challenge };
|
|
28029
|
+
}
|
|
28030
|
+
async function startLinkLogin(pkce, deviceName = (0, import_node_os5.hostname)()) {
|
|
28031
|
+
const res = await fetch(`${apiUrl()}/api/auth/cli/start`, {
|
|
28032
|
+
method: "POST",
|
|
28033
|
+
headers: { "Content-Type": "application/json" },
|
|
28034
|
+
body: JSON.stringify({
|
|
28035
|
+
code_challenge: pkce.challenge,
|
|
28036
|
+
code_challenge_method: "S256",
|
|
28037
|
+
device_name: deviceName
|
|
28038
|
+
}),
|
|
28039
|
+
signal: AbortSignal.timeout(15e3)
|
|
28040
|
+
});
|
|
28041
|
+
const data = await res.json().catch(() => ({}));
|
|
28042
|
+
if (!res.ok || !data.request_id || !data.verification_url || !data.user_code) {
|
|
28043
|
+
throw new Error(data.error || `Could not start login (${res.status})`);
|
|
28044
|
+
}
|
|
28045
|
+
return data;
|
|
28046
|
+
}
|
|
28047
|
+
var sleep = (ms) => new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
28048
|
+
async function waitForApproval(request, pkce, opts = {}) {
|
|
28049
|
+
const wait = opts.sleepMs ?? sleep;
|
|
28050
|
+
const now = opts.now ?? Date.now;
|
|
28051
|
+
const deadline = Date.parse(request.expires_at) || now() + 10 * 6e4;
|
|
28052
|
+
const intervalMs = Math.max(1, request.interval || 3) * 1e3;
|
|
28053
|
+
while (now() < deadline) {
|
|
28054
|
+
await wait(intervalMs);
|
|
28055
|
+
let res;
|
|
28056
|
+
try {
|
|
28057
|
+
res = await fetch(`${apiUrl()}/api/auth/cli/token`, {
|
|
28058
|
+
method: "POST",
|
|
28059
|
+
headers: { "Content-Type": "application/json" },
|
|
28060
|
+
body: JSON.stringify({ request_id: request.request_id, code_verifier: pkce.verifier }),
|
|
28061
|
+
signal: AbortSignal.timeout(15e3)
|
|
28062
|
+
});
|
|
28063
|
+
} catch {
|
|
28064
|
+
continue;
|
|
28065
|
+
}
|
|
28066
|
+
const data = await res.json().catch(() => ({}));
|
|
28067
|
+
if (res.ok && data.session?.access_token && data.user?.id) {
|
|
28068
|
+
updateCliConfig({
|
|
28069
|
+
email: data.user.email,
|
|
28070
|
+
user_id: data.user.id,
|
|
28071
|
+
token: data.session.access_token,
|
|
28072
|
+
refresh_token: data.session.refresh_token,
|
|
28073
|
+
expires_at: data.session.expires_at
|
|
28074
|
+
});
|
|
28075
|
+
return { ok: true, email: data.user.email || data.user.id, userId: data.user.id };
|
|
28076
|
+
}
|
|
28077
|
+
switch (data.error) {
|
|
28078
|
+
case "authorization_pending":
|
|
28079
|
+
continue;
|
|
28080
|
+
case "access_denied":
|
|
28081
|
+
return { ok: false, error: "The login was denied in the browser." };
|
|
28082
|
+
case "expired_token":
|
|
28083
|
+
return { ok: false, error: "The login link expired before it was approved." };
|
|
28084
|
+
case "invalid_grant":
|
|
28085
|
+
return { ok: false, error: "The login request is no longer valid. Run threatcrush login again." };
|
|
28086
|
+
default:
|
|
28087
|
+
if (res.status === 429 || res.status >= 500) continue;
|
|
28088
|
+
return { ok: false, error: data.error || `Login failed (${res.status})` };
|
|
28089
|
+
}
|
|
28090
|
+
}
|
|
28091
|
+
return { ok: false, error: "The login link expired before it was approved." };
|
|
28092
|
+
}
|
|
28093
|
+
|
|
28022
28094
|
// src/commands/login.ts
|
|
28023
28095
|
var API_URL = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
28024
28096
|
var INPUT_CLOSED = {
|
|
@@ -28073,6 +28145,10 @@ async function loginCommand(opts = {}) {
|
|
|
28073
28145
|
`));
|
|
28074
28146
|
return;
|
|
28075
28147
|
}
|
|
28148
|
+
if (!opts.password && !opts.email) {
|
|
28149
|
+
await linkLoginCommand();
|
|
28150
|
+
return;
|
|
28151
|
+
}
|
|
28076
28152
|
console.log(source_default.green(" Log in to threatcrush.com"));
|
|
28077
28153
|
console.log(source_default.gray(" " + "\u2500".repeat(40)));
|
|
28078
28154
|
const result = await login({ email: opts.email });
|
|
@@ -28090,6 +28166,43 @@ async function loginCommand(opts = {}) {
|
|
|
28090
28166
|
\u2713 Logged in as ${source_default.white(result.email)}`));
|
|
28091
28167
|
console.log(source_default.dim(` Credentials saved to ${CLI_CONFIG_PATH}
|
|
28092
28168
|
`));
|
|
28169
|
+
await rememberFirstOrg();
|
|
28170
|
+
}
|
|
28171
|
+
async function linkLoginCommand() {
|
|
28172
|
+
const pkce = createPkce();
|
|
28173
|
+
let request;
|
|
28174
|
+
try {
|
|
28175
|
+
request = await startLinkLogin(pkce);
|
|
28176
|
+
} catch (err) {
|
|
28177
|
+
console.log(source_default.red(` \u2717 ${err.message}
|
|
28178
|
+
`));
|
|
28179
|
+
process.exitCode = 1;
|
|
28180
|
+
return;
|
|
28181
|
+
}
|
|
28182
|
+
console.log(source_default.green(" Log in to threatcrush.com"));
|
|
28183
|
+
console.log(source_default.gray(" " + "\u2500".repeat(40)));
|
|
28184
|
+
console.log(` Open this link in a browser where you are signed in:
|
|
28185
|
+
`);
|
|
28186
|
+
console.log(` ${source_default.white.underline(request.verification_url)}
|
|
28187
|
+
`);
|
|
28188
|
+
console.log(` Check it shows this code: ${source_default.green.bold(request.user_code)}
|
|
28189
|
+
`);
|
|
28190
|
+
console.log(source_default.dim(" Waiting for approval\u2026 (Ctrl-C to cancel)"));
|
|
28191
|
+
const result = await waitForApproval(request, pkce);
|
|
28192
|
+
if (!result.ok) {
|
|
28193
|
+
console.log(source_default.red(`
|
|
28194
|
+
\u2717 ${result.error}
|
|
28195
|
+
`));
|
|
28196
|
+
process.exitCode = 1;
|
|
28197
|
+
return;
|
|
28198
|
+
}
|
|
28199
|
+
console.log(source_default.green(`
|
|
28200
|
+
\u2713 Logged in as ${source_default.white(result.email)}`));
|
|
28201
|
+
console.log(source_default.dim(` Credentials saved to ${CLI_CONFIG_PATH}
|
|
28202
|
+
`));
|
|
28203
|
+
await rememberFirstOrg();
|
|
28204
|
+
}
|
|
28205
|
+
async function rememberFirstOrg() {
|
|
28093
28206
|
try {
|
|
28094
28207
|
const res = await fetch(`${API_URL}/api/orgs`, { headers: authHeaders() });
|
|
28095
28208
|
if (res.ok) {
|
|
@@ -28617,7 +28730,7 @@ var import_toml3 = __toESM(require_toml());
|
|
|
28617
28730
|
init_paths();
|
|
28618
28731
|
|
|
28619
28732
|
// src/daemon/module-trust.ts
|
|
28620
|
-
var
|
|
28733
|
+
var import_node_crypto4 = require("crypto");
|
|
28621
28734
|
var import_node_fs15 = require("fs");
|
|
28622
28735
|
var import_node_path12 = require("path");
|
|
28623
28736
|
init_paths();
|
|
@@ -28641,7 +28754,7 @@ function collectFiles(root, dir = root, out = []) {
|
|
|
28641
28754
|
return out;
|
|
28642
28755
|
}
|
|
28643
28756
|
function computeModuleDigest(modulePath) {
|
|
28644
|
-
const hash = (0,
|
|
28757
|
+
const hash = (0, import_node_crypto4.createHash)("sha256");
|
|
28645
28758
|
for (const entry of collectFiles(modulePath)) {
|
|
28646
28759
|
const relPath = (0, import_node_path12.relative)(modulePath, entry.path).split(import_node_path12.sep).join("/");
|
|
28647
28760
|
hash.update(relPath);
|
|
@@ -28730,7 +28843,7 @@ function verifyModuleSignature(modulePath, digest) {
|
|
|
28730
28843
|
return { ok: false, reason: `mod.sig references unpinned key "${parsed.keyId}"` };
|
|
28731
28844
|
}
|
|
28732
28845
|
try {
|
|
28733
|
-
const valid = (0,
|
|
28846
|
+
const valid = (0, import_node_crypto4.verify)(
|
|
28734
28847
|
null,
|
|
28735
28848
|
Buffer.from(digest, "hex"),
|
|
28736
28849
|
publicKey,
|
|
@@ -29598,7 +29711,7 @@ function selectProbes(categories = []) {
|
|
|
29598
29711
|
}
|
|
29599
29712
|
|
|
29600
29713
|
// src/aiscan/runner.ts
|
|
29601
|
-
var
|
|
29714
|
+
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
29602
29715
|
async function runAiScan(target, send, opts = {}) {
|
|
29603
29716
|
const probes = (opts.probes ?? selectProbes(opts.categories)).slice(
|
|
29604
29717
|
0,
|
|
@@ -29618,7 +29731,7 @@ async function runAiScan(target, send, opts = {}) {
|
|
|
29618
29731
|
}
|
|
29619
29732
|
results.push({ probe, vulnerable, response, error });
|
|
29620
29733
|
opts.onProbe?.(probe, vulnerable);
|
|
29621
|
-
if (opts.delayMs && opts.delayMs > 0) await
|
|
29734
|
+
if (opts.delayMs && opts.delayMs > 0) await sleep2(opts.delayMs);
|
|
29622
29735
|
}
|
|
29623
29736
|
const findings = results.filter((r) => r.vulnerable).map((r) => ({
|
|
29624
29737
|
type: r.probe.id,
|
|
@@ -29817,11 +29930,11 @@ async function aiScanMoshCommand(file, args) {
|
|
|
29817
29930
|
}
|
|
29818
29931
|
|
|
29819
29932
|
// src/commands/orgs.ts
|
|
29820
|
-
var
|
|
29933
|
+
var import_node_os6 = require("os");
|
|
29821
29934
|
var import_node_fs18 = require("fs");
|
|
29822
29935
|
var import_node_path14 = require("path");
|
|
29823
29936
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
29824
|
-
var CONFIG_PATH = (0, import_node_path14.join)((0,
|
|
29937
|
+
var CONFIG_PATH = (0, import_node_path14.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
|
|
29825
29938
|
function readConfig() {
|
|
29826
29939
|
try {
|
|
29827
29940
|
return JSON.parse((0, import_node_fs18.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
@@ -29830,7 +29943,7 @@ function readConfig() {
|
|
|
29830
29943
|
}
|
|
29831
29944
|
}
|
|
29832
29945
|
function writeConfig(config) {
|
|
29833
|
-
const dir = (0, import_node_path14.join)((0,
|
|
29946
|
+
const dir = (0, import_node_path14.join)((0, import_node_os6.homedir)(), ".threatcrush");
|
|
29834
29947
|
if (!(0, import_node_fs18.existsSync)(dir)) (0, import_node_fs18.mkdirSync)(dir, { recursive: true });
|
|
29835
29948
|
(0, import_node_fs18.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
29836
29949
|
}
|
|
@@ -29968,7 +30081,7 @@ async function useOrganization(slug) {
|
|
|
29968
30081
|
|
|
29969
30082
|
// src/commands/servers.ts
|
|
29970
30083
|
var import_node_readline3 = __toESM(require("readline"));
|
|
29971
|
-
var
|
|
30084
|
+
var import_node_os7 = require("os");
|
|
29972
30085
|
async function serversCommand(options) {
|
|
29973
30086
|
const { action, name, org } = options;
|
|
29974
30087
|
if (action === "list" || !action) {
|
|
@@ -30027,7 +30140,7 @@ async function chooseOrg(orgs, flag, ask2) {
|
|
|
30027
30140
|
async function linkServer(opts = {}, ask2 = askChoice) {
|
|
30028
30141
|
if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
|
|
30029
30142
|
const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
|
|
30030
|
-
const host = opts.hostname ?? (0,
|
|
30143
|
+
const host = opts.hostname ?? (0, import_node_os7.hostname)();
|
|
30031
30144
|
const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
|
|
30032
30145
|
if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
|
|
30033
30146
|
const { servers = [] } = await listRes.json();
|
|
@@ -30143,12 +30256,12 @@ function timeAgo(dateStr) {
|
|
|
30143
30256
|
}
|
|
30144
30257
|
|
|
30145
30258
|
// src/commands/connect.ts
|
|
30146
|
-
var
|
|
30259
|
+
var import_node_os8 = require("os");
|
|
30147
30260
|
var import_node_fs19 = require("fs");
|
|
30148
30261
|
var import_node_path15 = require("path");
|
|
30149
30262
|
var import_node_child_process3 = require("child_process");
|
|
30150
30263
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
30151
|
-
var CONFIG_PATH2 = (0, import_node_path15.join)((0,
|
|
30264
|
+
var CONFIG_PATH2 = (0, import_node_path15.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
|
|
30152
30265
|
function readConfig2() {
|
|
30153
30266
|
try {
|
|
30154
30267
|
return JSON.parse((0, import_node_fs19.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
@@ -30273,20 +30386,20 @@ async function resolveServer(nameOrSlug, orgSlug) {
|
|
|
30273
30386
|
}
|
|
30274
30387
|
}
|
|
30275
30388
|
async function sshConnect(options) {
|
|
30276
|
-
const { hostname:
|
|
30277
|
-
if (!
|
|
30389
|
+
const { hostname: hostname3, port, username, identity } = options;
|
|
30390
|
+
if (!hostname3) {
|
|
30278
30391
|
console.log(source_default.red(" No hostname available for this server.\n"));
|
|
30279
30392
|
return;
|
|
30280
30393
|
}
|
|
30281
30394
|
const user = username || "root";
|
|
30282
|
-
console.log(source_default.green(` Connecting to ${user}@${
|
|
30395
|
+
console.log(source_default.green(` Connecting to ${user}@${hostname3}:${port}...
|
|
30283
30396
|
`));
|
|
30284
30397
|
console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
|
|
30285
30398
|
const sshArgs = ["-p", String(port)];
|
|
30286
30399
|
if (identity) {
|
|
30287
30400
|
sshArgs.push("-i", identity);
|
|
30288
30401
|
}
|
|
30289
|
-
sshArgs.push(`${user}@${
|
|
30402
|
+
sshArgs.push(`${user}@${hostname3}`);
|
|
30290
30403
|
const ssh = (0, import_node_child_process3.spawn)("ssh", sshArgs, { stdio: "inherit" });
|
|
30291
30404
|
ssh.on("error", (err) => {
|
|
30292
30405
|
console.log(source_default.red(`
|
|
@@ -30313,7 +30426,7 @@ var import_node_fs31 = require("fs");
|
|
|
30313
30426
|
// src/daemon/index.ts
|
|
30314
30427
|
var import_node_fs29 = require("fs");
|
|
30315
30428
|
var import_node_child_process10 = require("child_process");
|
|
30316
|
-
var
|
|
30429
|
+
var import_node_os9 = require("os");
|
|
30317
30430
|
var import_node_path20 = require("path");
|
|
30318
30431
|
var import_node_util = require("util");
|
|
30319
30432
|
init_paths();
|
|
@@ -32118,7 +32231,7 @@ var RunsWorker = class {
|
|
|
32118
32231
|
};
|
|
32119
32232
|
|
|
32120
32233
|
// src/core/cloud-events.ts
|
|
32121
|
-
var
|
|
32234
|
+
var import_node_crypto5 = require("crypto");
|
|
32122
32235
|
var import_node_net3 = require("net");
|
|
32123
32236
|
function currentLink() {
|
|
32124
32237
|
if (!hasSession()) return null;
|
|
@@ -32191,7 +32304,7 @@ function remediationEvent(serverId, event) {
|
|
|
32191
32304
|
return {
|
|
32192
32305
|
type: "remediation",
|
|
32193
32306
|
server_id: serverId,
|
|
32194
|
-
event_id: (0,
|
|
32307
|
+
event_id: (0, import_node_crypto5.randomUUID)(),
|
|
32195
32308
|
action_type: d.action,
|
|
32196
32309
|
target_value: event.source_ip,
|
|
32197
32310
|
status: d.failed === true ? "failed" : "executed",
|
|
@@ -34295,7 +34408,7 @@ async function runDaemon() {
|
|
|
34295
34408
|
cloudSync = new CloudSync({
|
|
34296
34409
|
bus,
|
|
34297
34410
|
version,
|
|
34298
|
-
hostname: (0,
|
|
34411
|
+
hostname: (0, import_node_os9.hostname)(),
|
|
34299
34412
|
minSeverity,
|
|
34300
34413
|
spoolPath: (0, import_node_path20.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
34301
34414
|
log: logLine,
|
|
@@ -34755,6 +34868,74 @@ async function uninstallServiceCommand() {
|
|
|
34755
34868
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
34756
34869
|
}
|
|
34757
34870
|
|
|
34871
|
+
// src/commands/save.ts
|
|
34872
|
+
var import_node_fs33 = require("fs");
|
|
34873
|
+
var import_toml5 = __toESM(require_toml());
|
|
34874
|
+
init_paths();
|
|
34875
|
+
var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
|
|
34876
|
+
var REDACTED = "[redacted]";
|
|
34877
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
34878
|
+
function redactConfig(value, depth = 0) {
|
|
34879
|
+
if (depth > 10) return REDACTED;
|
|
34880
|
+
if (Array.isArray(value)) return value.map((v) => redactConfig(v, depth + 1));
|
|
34881
|
+
if (value && typeof value === "object") {
|
|
34882
|
+
return Object.fromEntries(
|
|
34883
|
+
Object.entries(value).filter(([key]) => !UNSAFE_KEYS.has(key)).map(([key, v]) => [
|
|
34884
|
+
key,
|
|
34885
|
+
SECRET_KEY.test(key) && v !== null && typeof v !== "object" && typeof v !== "boolean" ? REDACTED : redactConfig(v, depth + 1)
|
|
34886
|
+
])
|
|
34887
|
+
);
|
|
34888
|
+
}
|
|
34889
|
+
return value;
|
|
34890
|
+
}
|
|
34891
|
+
async function saveCommand(opts = {}) {
|
|
34892
|
+
banner();
|
|
34893
|
+
if (!hasSession()) {
|
|
34894
|
+
console.log(source_default.yellow(" Not logged in."));
|
|
34895
|
+
console.log(source_default.dim(` Log in with ${source_default.white("threatcrush login")}, then link this machine with ${source_default.white("threatcrush servers link")}.
|
|
34896
|
+
`));
|
|
34897
|
+
process.exitCode = 1;
|
|
34898
|
+
return;
|
|
34899
|
+
}
|
|
34900
|
+
const link = currentLink();
|
|
34901
|
+
if (!link) {
|
|
34902
|
+
console.log(source_default.yellow(" This machine is not linked to a dashboard server."));
|
|
34903
|
+
console.log(source_default.dim(` Link it with ${source_default.white("threatcrush servers link")}.
|
|
34904
|
+
`));
|
|
34905
|
+
process.exitCode = 1;
|
|
34906
|
+
return;
|
|
34907
|
+
}
|
|
34908
|
+
const path = opts.config ?? PATHS.configFile;
|
|
34909
|
+
let config = {};
|
|
34910
|
+
if ((0, import_node_fs33.existsSync)(path)) {
|
|
34911
|
+
try {
|
|
34912
|
+
config = import_toml5.default.parse((0, import_node_fs33.readFileSync)(path, "utf-8"));
|
|
34913
|
+
} catch (err) {
|
|
34914
|
+
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
34915
|
+
`));
|
|
34916
|
+
process.exitCode = 1;
|
|
34917
|
+
return;
|
|
34918
|
+
}
|
|
34919
|
+
}
|
|
34920
|
+
const res = await cloudFetch(`/api/orgs/${link.orgId}/servers/${link.serverId}/config`, {
|
|
34921
|
+
method: "PUT",
|
|
34922
|
+
body: JSON.stringify({ config: redactConfig(config), source: path })
|
|
34923
|
+
});
|
|
34924
|
+
const data = await res.json().catch(() => ({}));
|
|
34925
|
+
if (!res.ok) {
|
|
34926
|
+
console.log(source_default.red(` \u2717 ${data.error || `Save failed (${res.status})`}
|
|
34927
|
+
`));
|
|
34928
|
+
process.exitCode = 1;
|
|
34929
|
+
return;
|
|
34930
|
+
}
|
|
34931
|
+
const sections = Object.keys(config);
|
|
34932
|
+
console.log(source_default.green(` \u2713 Saved ${path} to ${source_default.white(data.server?.name ?? link.serverId)}`));
|
|
34933
|
+
console.log(source_default.dim(
|
|
34934
|
+
sections.length > 0 ? ` Sections: ${sections.join(", ")} (secrets redacted)
|
|
34935
|
+
` : " No config file here, so the built-in defaults were saved as empty.\n"
|
|
34936
|
+
));
|
|
34937
|
+
}
|
|
34938
|
+
|
|
34758
34939
|
// src/commands/welcome.ts
|
|
34759
34940
|
init_paths();
|
|
34760
34941
|
var LOGO = source_default.green(`
|
|
@@ -34840,7 +35021,7 @@ function welcomeCommand() {
|
|
|
34840
35021
|
}
|
|
34841
35022
|
|
|
34842
35023
|
// src/commands/properties.ts
|
|
34843
|
-
var
|
|
35024
|
+
var import_node_fs34 = require("fs");
|
|
34844
35025
|
var import_node_path23 = require("path");
|
|
34845
35026
|
var import_node_readline6 = __toESM(require("readline"));
|
|
34846
35027
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -35171,7 +35352,7 @@ async function propertiesRunsCommand(opts) {
|
|
|
35171
35352
|
}
|
|
35172
35353
|
function parseImportFile(path) {
|
|
35173
35354
|
const ext = (0, import_node_path23.extname)(path).toLowerCase();
|
|
35174
|
-
const raw = (0,
|
|
35355
|
+
const raw = (0, import_node_fs34.readFileSync)(path, "utf-8");
|
|
35175
35356
|
if (ext === ".json") {
|
|
35176
35357
|
const parsed = JSON.parse(raw);
|
|
35177
35358
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -35366,7 +35547,7 @@ async function rulesCommand(opts) {
|
|
|
35366
35547
|
}
|
|
35367
35548
|
|
|
35368
35549
|
// src/commands/harden.ts
|
|
35369
|
-
var
|
|
35550
|
+
var import_node_fs35 = require("fs");
|
|
35370
35551
|
var import_node_child_process13 = require("child_process");
|
|
35371
35552
|
function tryExec(cmd) {
|
|
35372
35553
|
try {
|
|
@@ -35377,7 +35558,7 @@ function tryExec(cmd) {
|
|
|
35377
35558
|
}
|
|
35378
35559
|
function tryRead(path) {
|
|
35379
35560
|
try {
|
|
35380
|
-
return (0,
|
|
35561
|
+
return (0, import_node_fs35.readFileSync)(path, "utf-8");
|
|
35381
35562
|
} catch {
|
|
35382
35563
|
return null;
|
|
35383
35564
|
}
|
|
@@ -35481,8 +35662,8 @@ function checkSshWeakConfig() {
|
|
|
35481
35662
|
};
|
|
35482
35663
|
}
|
|
35483
35664
|
function checkAutoUpdates() {
|
|
35484
|
-
const unattended = (0,
|
|
35485
|
-
const dnfAuto = (0,
|
|
35665
|
+
const unattended = (0, import_node_fs35.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs35.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
35666
|
+
const dnfAuto = (0, import_node_fs35.existsSync)("/etc/dnf/automatic.conf");
|
|
35486
35667
|
if (unattended || dnfAuto) {
|
|
35487
35668
|
return {
|
|
35488
35669
|
key: "auto-updates",
|
|
@@ -35608,7 +35789,7 @@ function checkFail2ban() {
|
|
|
35608
35789
|
explanation: "fail2ban is installed and running."
|
|
35609
35790
|
};
|
|
35610
35791
|
}
|
|
35611
|
-
if ((0,
|
|
35792
|
+
if ((0, import_node_fs35.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
35612
35793
|
return {
|
|
35613
35794
|
key: checkKey,
|
|
35614
35795
|
status: "warn",
|
|
@@ -36056,7 +36237,7 @@ ${source_default.dim(" C R U S H")}
|
|
|
36056
36237
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
36057
36238
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
36058
36239
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
36059
|
-
var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0,
|
|
36240
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush", "install.json");
|
|
36060
36241
|
function detectPackageManager() {
|
|
36061
36242
|
try {
|
|
36062
36243
|
const npmGlobal = (0, import_node_child_process15.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
@@ -36082,7 +36263,7 @@ function detectPackageManager() {
|
|
|
36082
36263
|
}
|
|
36083
36264
|
function readInstallConfig() {
|
|
36084
36265
|
try {
|
|
36085
|
-
return JSON.parse((0,
|
|
36266
|
+
return JSON.parse((0, import_node_fs36.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
36086
36267
|
} catch {
|
|
36087
36268
|
return {};
|
|
36088
36269
|
}
|
|
@@ -36252,8 +36433,11 @@ program2.command("tui").description("Interactive security dashboard (htop for se
|
|
|
36252
36433
|
program2.command("init").description("Sign in, auto-detect services, and configure ThreatCrush").option("-y, --yes", "Don't ask; answer yes to every question").option("--offline", "Skip signing in to threatcrush.com").action(async (opts) => {
|
|
36253
36434
|
await initCommand({ yes: opts.yes, offline: opts.offline });
|
|
36254
36435
|
});
|
|
36255
|
-
program2.command("login").description("Log in to your threatcrush.com account").option("-e, --email <email>", "Email to log in with").action(async (opts) => {
|
|
36256
|
-
await loginCommand({ email: opts.email });
|
|
36436
|
+
program2.command("login").description("Log in to your threatcrush.com account (prints a link to approve in your browser)").option("-p, --password", "Log in with email and password instead of a link").option("-e, --email <email>", "Email to log in with (implies --password)").action(async (opts) => {
|
|
36437
|
+
await loginCommand({ email: opts.email, password: opts.password });
|
|
36438
|
+
});
|
|
36439
|
+
program2.command("save").description("Save this machine's daemon config to its threatcrush.com server (secrets redacted)").option("-c, --config <path>", "Config file to save (default: the one the daemon reads)").action(async (opts) => {
|
|
36440
|
+
await saveCommand({ config: opts.config });
|
|
36257
36441
|
});
|
|
36258
36442
|
program2.command("logout").description("Clear stored threatcrush.com credentials").action(async () => {
|
|
36259
36443
|
await logoutCommand();
|
|
@@ -36353,7 +36537,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
36353
36537
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
36354
36538
|
console.log(LOGO2);
|
|
36355
36539
|
const logPath = PATHS.logFile;
|
|
36356
|
-
if (!(0,
|
|
36540
|
+
if (!(0, import_node_fs36.existsSync)(logPath)) {
|
|
36357
36541
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
36358
36542
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
36359
36543
|
return;
|
|
@@ -36526,10 +36710,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
36526
36710
|
});
|
|
36527
36711
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
36528
36712
|
console.log(LOGO2);
|
|
36529
|
-
const configPath = (0, import_node_path24.join)((0,
|
|
36713
|
+
const configPath = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
|
|
36530
36714
|
let email = "";
|
|
36531
36715
|
try {
|
|
36532
|
-
const config = JSON.parse((0,
|
|
36716
|
+
const config = JSON.parse((0, import_node_fs36.readFileSync)(configPath, "utf-8"));
|
|
36533
36717
|
email = config.email || "";
|
|
36534
36718
|
} catch {
|
|
36535
36719
|
}
|
|
@@ -36546,9 +36730,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
36546
36730
|
return;
|
|
36547
36731
|
}
|
|
36548
36732
|
try {
|
|
36549
|
-
const dir = (0, import_node_path24.join)((0,
|
|
36550
|
-
if (!(0,
|
|
36551
|
-
(0,
|
|
36733
|
+
const dir = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush");
|
|
36734
|
+
if (!(0, import_node_fs36.existsSync)(dir)) (0, import_node_fs36.mkdirSync)(dir, { recursive: true });
|
|
36735
|
+
(0, import_node_fs36.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
36552
36736
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
36553
36737
|
} catch {
|
|
36554
36738
|
}
|