@profullstack/threatcrush 0.13.78 → 0.13.80
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 +15 -1
- package/dist/daemon.js +522 -88
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +696 -215
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23786,8 +23786,8 @@ var source_default = chalk;
|
|
|
23786
23786
|
|
|
23787
23787
|
// src/index.ts
|
|
23788
23788
|
var import_readline = __toESM(require("readline"));
|
|
23789
|
-
var
|
|
23790
|
-
var
|
|
23789
|
+
var import_node_child_process30 = require("child_process");
|
|
23790
|
+
var import_node_fs76 = require("fs");
|
|
23791
23791
|
var import_node_path58 = require("path");
|
|
23792
23792
|
var import_node_os24 = require("os");
|
|
23793
23793
|
|
|
@@ -30533,13 +30533,13 @@ var CrsEngine = class {
|
|
|
30533
30533
|
}
|
|
30534
30534
|
return hits;
|
|
30535
30535
|
}
|
|
30536
|
-
assess(
|
|
30536
|
+
assess(request2) {
|
|
30537
30537
|
const ctx = new RequestContext({
|
|
30538
|
-
method:
|
|
30539
|
-
uri: asBytes(
|
|
30540
|
-
protocol:
|
|
30541
|
-
userAgent: asBytes(
|
|
30542
|
-
referer: asBytes(
|
|
30538
|
+
method: request2.method,
|
|
30539
|
+
uri: asBytes(request2.uri),
|
|
30540
|
+
protocol: request2.protocol,
|
|
30541
|
+
userAgent: asBytes(request2.userAgent),
|
|
30542
|
+
referer: asBytes(request2.referer)
|
|
30543
30543
|
});
|
|
30544
30544
|
const hit = new Uint8Array(this.rules.length);
|
|
30545
30545
|
for (const [target, rules] of this.byTarget) {
|
|
@@ -30612,9 +30612,9 @@ function parseCaddyAccessLog(line2) {
|
|
|
30612
30612
|
return null;
|
|
30613
30613
|
}
|
|
30614
30614
|
if (typeof entry.logger !== "string" || !/^http\.log\.access(?:\.log\d+)?$/.test(entry.logger)) return null;
|
|
30615
|
-
const
|
|
30616
|
-
if (!
|
|
30617
|
-
const req =
|
|
30615
|
+
const request2 = entry.request;
|
|
30616
|
+
if (!request2 || typeof request2 !== "object" || Array.isArray(request2)) return null;
|
|
30617
|
+
const req = request2;
|
|
30618
30618
|
const host = typeof req.host === "string" ? req.host.toLowerCase() : "";
|
|
30619
30619
|
if (host !== "agent.database.pit.world") return null;
|
|
30620
30620
|
const required = [req.method, req.uri, entry.status, entry.size];
|
|
@@ -30846,6 +30846,7 @@ function parseConfigText(raw) {
|
|
|
30846
30846
|
file_integrity: parsed.file_integrity,
|
|
30847
30847
|
edr: parsed.edr,
|
|
30848
30848
|
lightning: parsed.lightning,
|
|
30849
|
+
docker_logs: parsed.docker_logs,
|
|
30849
30850
|
storage: parsed.storage,
|
|
30850
30851
|
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
30851
30852
|
// the JS-friendly name the rest of the daemon reads.
|
|
@@ -39214,11 +39215,11 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os8.hostname)()
|
|
|
39214
39215
|
return data;
|
|
39215
39216
|
}
|
|
39216
39217
|
var sleep = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
39217
|
-
async function waitForApproval(
|
|
39218
|
+
async function waitForApproval(request2, pkce, opts = {}) {
|
|
39218
39219
|
const wait = opts.sleepMs ?? sleep;
|
|
39219
39220
|
const now = opts.now ?? Date.now;
|
|
39220
|
-
const deadline = Date.parse(
|
|
39221
|
-
const intervalMs = Math.max(1,
|
|
39221
|
+
const deadline = Date.parse(request2.expires_at) || now() + 10 * 6e4;
|
|
39222
|
+
const intervalMs = Math.max(1, request2.interval || 3) * 1e3;
|
|
39222
39223
|
while (now() < deadline) {
|
|
39223
39224
|
await wait(intervalMs);
|
|
39224
39225
|
let res;
|
|
@@ -39226,7 +39227,7 @@ async function waitForApproval(request, pkce, opts = {}) {
|
|
|
39226
39227
|
res = await fetch(`${apiUrl()}/api/auth/cli/token`, {
|
|
39227
39228
|
method: "POST",
|
|
39228
39229
|
headers: { "Content-Type": "application/json" },
|
|
39229
|
-
body: JSON.stringify({ request_id:
|
|
39230
|
+
body: JSON.stringify({ request_id: request2.request_id, code_verifier: pkce.verifier }),
|
|
39230
39231
|
signal: AbortSignal.timeout(15e3)
|
|
39231
39232
|
});
|
|
39232
39233
|
} catch {
|
|
@@ -39339,9 +39340,9 @@ async function loginCommand(opts = {}) {
|
|
|
39339
39340
|
}
|
|
39340
39341
|
async function linkLoginCommand() {
|
|
39341
39342
|
const pkce = createPkce();
|
|
39342
|
-
let
|
|
39343
|
+
let request2;
|
|
39343
39344
|
try {
|
|
39344
|
-
|
|
39345
|
+
request2 = await startLinkLogin(pkce);
|
|
39345
39346
|
} catch (err) {
|
|
39346
39347
|
console.log(source_default.red(` \u2717 ${err.message}
|
|
39347
39348
|
`));
|
|
@@ -39352,12 +39353,12 @@ async function linkLoginCommand() {
|
|
|
39352
39353
|
console.log(source_default.gray(" " + "\u2500".repeat(40)));
|
|
39353
39354
|
console.log(` Open this link in a browser where you are signed in:
|
|
39354
39355
|
`);
|
|
39355
|
-
console.log(` ${source_default.white.underline(
|
|
39356
|
+
console.log(` ${source_default.white.underline(request2.verification_url)}
|
|
39356
39357
|
`);
|
|
39357
|
-
console.log(` Check it shows this code: ${source_default.green.bold(
|
|
39358
|
+
console.log(` Check it shows this code: ${source_default.green.bold(request2.user_code)}
|
|
39358
39359
|
`);
|
|
39359
39360
|
console.log(source_default.dim(" Waiting for approval\u2026 (Ctrl-C to cancel)"));
|
|
39360
|
-
const result = await waitForApproval(
|
|
39361
|
+
const result = await waitForApproval(request2, pkce);
|
|
39361
39362
|
if (!result.ok) {
|
|
39362
39363
|
console.log(source_default.red(`
|
|
39363
39364
|
\u2717 ${result.error}
|
|
@@ -43430,14 +43431,14 @@ async function sshConnect(options) {
|
|
|
43430
43431
|
}
|
|
43431
43432
|
|
|
43432
43433
|
// src/commands/daemon.ts
|
|
43433
|
-
var
|
|
43434
|
-
var import_node_fs59 = require("fs");
|
|
43435
|
-
var import_node_path47 = require("path");
|
|
43434
|
+
var import_node_child_process22 = require("child_process");
|
|
43436
43435
|
var import_node_fs60 = require("fs");
|
|
43436
|
+
var import_node_path47 = require("path");
|
|
43437
|
+
var import_node_fs61 = require("fs");
|
|
43437
43438
|
|
|
43438
43439
|
// src/daemon/index.ts
|
|
43439
|
-
var
|
|
43440
|
-
var
|
|
43440
|
+
var import_node_fs59 = require("fs");
|
|
43441
|
+
var import_node_child_process21 = require("child_process");
|
|
43441
43442
|
var import_node_os19 = require("os");
|
|
43442
43443
|
var import_node_path46 = require("path");
|
|
43443
43444
|
var import_node_util4 = require("util");
|
|
@@ -49827,10 +49828,307 @@ var LightningWatch = class {
|
|
|
49827
49828
|
}
|
|
49828
49829
|
};
|
|
49829
49830
|
|
|
49830
|
-
// src/
|
|
49831
|
+
// src/daemon/workers/docker-logs.ts
|
|
49831
49832
|
var import_node_fs53 = require("fs");
|
|
49832
|
-
var
|
|
49833
|
+
var import_node_http = require("http");
|
|
49833
49834
|
var import_node_net15 = require("net");
|
|
49835
|
+
var DEFAULT_DOCKER_SOCKET = "/var/run/docker.sock";
|
|
49836
|
+
var DEFAULT_NAME_PATTERN = "supabase-db$";
|
|
49837
|
+
var DEFAULT_IMAGE_PATTERN = "(^|/)postgres(:|@|$)";
|
|
49838
|
+
function regexOr(source, fallback) {
|
|
49839
|
+
if (typeof source === "string" && source) {
|
|
49840
|
+
try {
|
|
49841
|
+
return new RegExp(source, "i");
|
|
49842
|
+
} catch {
|
|
49843
|
+
}
|
|
49844
|
+
}
|
|
49845
|
+
return new RegExp(fallback, "i");
|
|
49846
|
+
}
|
|
49847
|
+
function dockerLogsSettings(section) {
|
|
49848
|
+
const poll = Number(section?.poll_seconds);
|
|
49849
|
+
return {
|
|
49850
|
+
enabled: section?.enabled !== false,
|
|
49851
|
+
socket: typeof section?.socket === "string" && section.socket ? section.socket : DEFAULT_DOCKER_SOCKET,
|
|
49852
|
+
namePattern: regexOr(section?.name_pattern, DEFAULT_NAME_PATTERN),
|
|
49853
|
+
imagePattern: regexOr(section?.image_pattern, DEFAULT_IMAGE_PATTERN),
|
|
49854
|
+
pollMs: Number.isFinite(poll) && poll >= 2 ? poll * 1e3 : 15e3
|
|
49855
|
+
};
|
|
49856
|
+
}
|
|
49857
|
+
var PASSWORD_FAILED = /FATAL:\s+password authentication failed for user "([^"]*)"/;
|
|
49858
|
+
var HBA_REJECT = /FATAL:\s+no pg_hba\.conf entry for (?:replication connection from )?host "([^"]+)", user "([^"]*)"(?:, database "([^"]*)")?/;
|
|
49859
|
+
function cleanPgHost(raw) {
|
|
49860
|
+
if (!raw) return void 0;
|
|
49861
|
+
let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
|
|
49862
|
+
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
|
|
49863
|
+
return (0, import_node_net15.isIP)(host) ? host : void 0;
|
|
49864
|
+
}
|
|
49865
|
+
function prefixHost(line2) {
|
|
49866
|
+
const first = cleanPgHost(line2.split(/\s/, 1)[0]);
|
|
49867
|
+
if (first) return first;
|
|
49868
|
+
const m = /\b(?:host|client|remote)=(\S+?)[\s,]/.exec(line2);
|
|
49869
|
+
return cleanPgHost(m?.[1]);
|
|
49870
|
+
}
|
|
49871
|
+
function parsePostgresAuthFailure(line2) {
|
|
49872
|
+
const hba = HBA_REJECT.exec(line2);
|
|
49873
|
+
if (hba) {
|
|
49874
|
+
return {
|
|
49875
|
+
kind: "pg_hba",
|
|
49876
|
+
ip: cleanPgHost(hba[1]) ?? prefixHost(line2),
|
|
49877
|
+
user: hba[2],
|
|
49878
|
+
...hba[3] !== void 0 ? { database: hba[3] } : {}
|
|
49879
|
+
};
|
|
49880
|
+
}
|
|
49881
|
+
const pw = PASSWORD_FAILED.exec(line2);
|
|
49882
|
+
if (pw) {
|
|
49883
|
+
const ip = prefixHost(line2);
|
|
49884
|
+
const db2 = /\s([^\s@]+)@([^\s@]+)\s+FATAL:/.exec(line2);
|
|
49885
|
+
return { kind: "password", ...ip ? { ip } : {}, user: pw[1], ...db2 ? { database: db2[2] } : {} };
|
|
49886
|
+
}
|
|
49887
|
+
return null;
|
|
49888
|
+
}
|
|
49889
|
+
function isUnbannableSource(ip, protectedList = []) {
|
|
49890
|
+
return isProtected(ip, [...DEFAULT_PROTECTED, ...protectedList]);
|
|
49891
|
+
}
|
|
49892
|
+
function postgresAuthEvent(line2, container, protectedList = [], now = /* @__PURE__ */ new Date()) {
|
|
49893
|
+
const failure = parsePostgresAuthFailure(line2);
|
|
49894
|
+
if (!failure?.ip) return null;
|
|
49895
|
+
if (isUnbannableSource(failure.ip, protectedList)) return null;
|
|
49896
|
+
const who = `user "${failure.user ?? ""}"${failure.database !== void 0 ? ` database "${failure.database}"` : ""}`;
|
|
49897
|
+
const message = failure.kind === "password" ? `Postgres password authentication failed for ${who} from ${failure.ip} (${container})` : `Postgres connection rejected by pg_hba for ${who} from ${failure.ip} (${container})`;
|
|
49898
|
+
return {
|
|
49899
|
+
timestamp: now,
|
|
49900
|
+
module: "postgres-guard",
|
|
49901
|
+
category: "auth",
|
|
49902
|
+
// One failure is not an attack, and anything at the remediation floor
|
|
49903
|
+
// (`min_severity`, high by default) bans on its own. The rule decides.
|
|
49904
|
+
severity: "low",
|
|
49905
|
+
message,
|
|
49906
|
+
source_ip: failure.ip,
|
|
49907
|
+
details: {
|
|
49908
|
+
service: "postgres",
|
|
49909
|
+
container,
|
|
49910
|
+
kind: failure.kind,
|
|
49911
|
+
...failure.user !== void 0 ? { user: failure.user } : {},
|
|
49912
|
+
...failure.database !== void 0 ? { database: failure.database } : {},
|
|
49913
|
+
line: line2.slice(0, 500)
|
|
49914
|
+
}
|
|
49915
|
+
};
|
|
49916
|
+
}
|
|
49917
|
+
var DockerLogDecoder = class {
|
|
49918
|
+
constructor(tty4, onLine) {
|
|
49919
|
+
this.tty = tty4;
|
|
49920
|
+
this.onLine = onLine;
|
|
49921
|
+
}
|
|
49922
|
+
tty;
|
|
49923
|
+
onLine;
|
|
49924
|
+
pending = Buffer.alloc(0);
|
|
49925
|
+
partial = /* @__PURE__ */ new Map();
|
|
49926
|
+
push(chunk2) {
|
|
49927
|
+
if (this.tty) {
|
|
49928
|
+
this.text(1, chunk2.toString("utf-8"));
|
|
49929
|
+
return;
|
|
49930
|
+
}
|
|
49931
|
+
this.pending = this.pending.length ? Buffer.concat([this.pending, chunk2]) : chunk2;
|
|
49932
|
+
while (this.pending.length >= 8) {
|
|
49933
|
+
const stream = this.pending[0];
|
|
49934
|
+
const size = this.pending.readUInt32BE(4);
|
|
49935
|
+
if (stream > 2 || this.pending[1] !== 0 || this.pending[2] !== 0 || this.pending[3] !== 0) {
|
|
49936
|
+
this.tty = true;
|
|
49937
|
+
const rest = this.pending;
|
|
49938
|
+
this.pending = Buffer.alloc(0);
|
|
49939
|
+
this.text(1, rest.toString("utf-8"));
|
|
49940
|
+
return;
|
|
49941
|
+
}
|
|
49942
|
+
if (this.pending.length < 8 + size) break;
|
|
49943
|
+
this.text(stream, this.pending.subarray(8, 8 + size).toString("utf-8"));
|
|
49944
|
+
this.pending = this.pending.subarray(8 + size);
|
|
49945
|
+
}
|
|
49946
|
+
}
|
|
49947
|
+
text(stream, text) {
|
|
49948
|
+
let buf = (this.partial.get(stream) ?? "") + text;
|
|
49949
|
+
let idx;
|
|
49950
|
+
while ((idx = buf.indexOf("\n")) >= 0) {
|
|
49951
|
+
const line2 = buf.slice(0, idx).replace(/\r$/, "");
|
|
49952
|
+
buf = buf.slice(idx + 1);
|
|
49953
|
+
if (line2) this.onLine(line2);
|
|
49954
|
+
}
|
|
49955
|
+
this.partial.set(stream, buf.length > 65536 ? "" : buf);
|
|
49956
|
+
}
|
|
49957
|
+
};
|
|
49958
|
+
function socketDeps(socketPath) {
|
|
49959
|
+
return {
|
|
49960
|
+
getJson: (path2) => new Promise((resolve9, reject) => {
|
|
49961
|
+
const req = (0, import_node_http.request)({ socketPath, path: path2, method: "GET", timeout: 1e4 }, (res) => {
|
|
49962
|
+
const chunks = [];
|
|
49963
|
+
res.on("data", (c) => chunks.push(c));
|
|
49964
|
+
res.on("end", () => {
|
|
49965
|
+
const body = Buffer.concat(chunks).toString("utf-8");
|
|
49966
|
+
if ((res.statusCode ?? 500) >= 300) return reject(new Error(`docker ${path2}: HTTP ${res.statusCode} ${body.slice(0, 200)}`));
|
|
49967
|
+
try {
|
|
49968
|
+
resolve9(JSON.parse(body));
|
|
49969
|
+
} catch (err) {
|
|
49970
|
+
reject(err);
|
|
49971
|
+
}
|
|
49972
|
+
});
|
|
49973
|
+
res.on("error", reject);
|
|
49974
|
+
});
|
|
49975
|
+
req.on("timeout", () => req.destroy(new Error(`docker ${path2}: timed out`)));
|
|
49976
|
+
req.on("error", reject);
|
|
49977
|
+
req.end();
|
|
49978
|
+
}),
|
|
49979
|
+
stream: (path2, onData, onEnd) => {
|
|
49980
|
+
let ended = false;
|
|
49981
|
+
const end = () => {
|
|
49982
|
+
if (!ended) {
|
|
49983
|
+
ended = true;
|
|
49984
|
+
onEnd();
|
|
49985
|
+
}
|
|
49986
|
+
};
|
|
49987
|
+
const req = (0, import_node_http.request)({ socketPath, path: path2, method: "GET" }, (res) => {
|
|
49988
|
+
if ((res.statusCode ?? 500) >= 300) {
|
|
49989
|
+
res.resume();
|
|
49990
|
+
end();
|
|
49991
|
+
return;
|
|
49992
|
+
}
|
|
49993
|
+
res.on("data", onData);
|
|
49994
|
+
res.on("end", end);
|
|
49995
|
+
res.on("close", end);
|
|
49996
|
+
res.on("error", end);
|
|
49997
|
+
});
|
|
49998
|
+
req.on("error", end);
|
|
49999
|
+
req.on("close", end);
|
|
50000
|
+
req.end();
|
|
50001
|
+
return req;
|
|
50002
|
+
}
|
|
50003
|
+
};
|
|
50004
|
+
}
|
|
50005
|
+
var DockerLogsWatch = class {
|
|
50006
|
+
constructor(opts) {
|
|
50007
|
+
this.opts = opts;
|
|
50008
|
+
this.deps = opts.deps ?? socketDeps(opts.settings.socket);
|
|
50009
|
+
}
|
|
50010
|
+
opts;
|
|
50011
|
+
follows = /* @__PURE__ */ new Map();
|
|
50012
|
+
/** When each container's stream last closed: a restart resumes from there. */
|
|
50013
|
+
closedAt = /* @__PURE__ */ new Map();
|
|
50014
|
+
timer = null;
|
|
50015
|
+
lastPoll = 0;
|
|
50016
|
+
stopped = false;
|
|
50017
|
+
deps;
|
|
50018
|
+
warned = false;
|
|
50019
|
+
/** False when off or there is no Docker here. */
|
|
50020
|
+
start() {
|
|
50021
|
+
const { settings } = this.opts;
|
|
50022
|
+
if (!settings.enabled) return false;
|
|
50023
|
+
if (!this.opts.deps && !(0, import_node_fs53.existsSync)(settings.socket)) return false;
|
|
50024
|
+
this.opts.log(`[docker-logs] following containers named /${settings.namePattern.source}/ or with image /${settings.imagePattern.source}/ for Postgres auth failures`);
|
|
50025
|
+
void this.poll();
|
|
50026
|
+
this.timer = setInterval(() => {
|
|
50027
|
+
void this.poll();
|
|
50028
|
+
}, settings.pollMs);
|
|
50029
|
+
this.timer.unref?.();
|
|
50030
|
+
return true;
|
|
50031
|
+
}
|
|
50032
|
+
stop() {
|
|
50033
|
+
this.stopped = true;
|
|
50034
|
+
if (this.timer) clearInterval(this.timer);
|
|
50035
|
+
this.timer = null;
|
|
50036
|
+
for (const f of this.follows.values()) {
|
|
50037
|
+
try {
|
|
50038
|
+
f.req.destroy();
|
|
50039
|
+
} catch {
|
|
50040
|
+
}
|
|
50041
|
+
}
|
|
50042
|
+
this.follows.clear();
|
|
50043
|
+
}
|
|
50044
|
+
/** Names of the containers being followed now. */
|
|
50045
|
+
following() {
|
|
50046
|
+
return [...this.follows.values()].map((f) => f.name).sort();
|
|
50047
|
+
}
|
|
50048
|
+
matches(c) {
|
|
50049
|
+
const name = (c.Names?.[0] ?? "").replace(/^\//, "");
|
|
50050
|
+
return this.opts.settings.namePattern.test(name) || this.opts.settings.imagePattern.test(c.Image ?? "");
|
|
50051
|
+
}
|
|
50052
|
+
/** One discovery pass: follow new or restarted matches, drop gone ones. */
|
|
50053
|
+
async poll() {
|
|
50054
|
+
if (this.stopped) return;
|
|
50055
|
+
const now = Date.now();
|
|
50056
|
+
const previous = this.lastPoll;
|
|
50057
|
+
let list;
|
|
50058
|
+
try {
|
|
50059
|
+
list = await this.deps.getJson("/containers/json");
|
|
50060
|
+
this.warned = false;
|
|
50061
|
+
} catch (err) {
|
|
50062
|
+
if (!this.warned) this.opts.log(`[docker-logs] cannot list containers: ${err.message}`);
|
|
50063
|
+
this.warned = true;
|
|
50064
|
+
return;
|
|
50065
|
+
}
|
|
50066
|
+
this.lastPoll = now;
|
|
50067
|
+
const running = /* @__PURE__ */ new Set();
|
|
50068
|
+
for (const c of Array.isArray(list) ? list : []) {
|
|
50069
|
+
if (!c?.Id || !this.matches(c)) continue;
|
|
50070
|
+
running.add(c.Id);
|
|
50071
|
+
if (this.follows.has(c.Id)) continue;
|
|
50072
|
+
const from = this.closedAt.get(c.Id) ?? (previous || now);
|
|
50073
|
+
await this.follow(c, from);
|
|
50074
|
+
}
|
|
50075
|
+
for (const [id, f] of this.follows) {
|
|
50076
|
+
if (!running.has(id)) {
|
|
50077
|
+
try {
|
|
50078
|
+
f.req.destroy();
|
|
50079
|
+
} catch {
|
|
50080
|
+
}
|
|
50081
|
+
this.follows.delete(id);
|
|
50082
|
+
}
|
|
50083
|
+
}
|
|
50084
|
+
for (const id of this.closedAt.keys()) if (!running.has(id)) this.closedAt.delete(id);
|
|
50085
|
+
}
|
|
50086
|
+
async follow(c, fromMs) {
|
|
50087
|
+
const name = (c.Names?.[0] ?? c.Id.slice(0, 12)).replace(/^\//, "");
|
|
50088
|
+
let tty4 = false;
|
|
50089
|
+
try {
|
|
50090
|
+
const info2 = await this.deps.getJson(`/containers/${c.Id}/json`);
|
|
50091
|
+
tty4 = info2?.Config?.Tty === true;
|
|
50092
|
+
} catch {
|
|
50093
|
+
}
|
|
50094
|
+
if (this.stopped || this.follows.has(c.Id)) return;
|
|
50095
|
+
const since = Math.max(1, Math.floor(fromMs / 1e3));
|
|
50096
|
+
const decoder = new DockerLogDecoder(tty4, (line2) => this.line(line2, name));
|
|
50097
|
+
const req = this.deps.stream(
|
|
50098
|
+
`/containers/${c.Id}/logs?follow=1&stdout=1&stderr=1&since=${since}`,
|
|
50099
|
+
(chunk2) => {
|
|
50100
|
+
try {
|
|
50101
|
+
decoder.push(chunk2);
|
|
50102
|
+
} catch {
|
|
50103
|
+
}
|
|
50104
|
+
},
|
|
50105
|
+
() => {
|
|
50106
|
+
if (this.follows.get(c.Id)?.req === req) {
|
|
50107
|
+
this.follows.delete(c.Id);
|
|
50108
|
+
this.closedAt.set(c.Id, Date.now());
|
|
50109
|
+
}
|
|
50110
|
+
}
|
|
50111
|
+
);
|
|
50112
|
+
this.follows.set(c.Id, { req, name });
|
|
50113
|
+
this.opts.log(`[docker-logs] following ${name}`);
|
|
50114
|
+
}
|
|
50115
|
+
/** Exposed for tests and `rules test`: one container log line through the parser. */
|
|
50116
|
+
line(line2, container) {
|
|
50117
|
+
const event = postgresAuthEvent(line2, container, this.opts.protectedList ?? []);
|
|
50118
|
+
if (!event) return null;
|
|
50119
|
+
try {
|
|
50120
|
+
insertEvent(event);
|
|
50121
|
+
} catch {
|
|
50122
|
+
}
|
|
50123
|
+
this.opts.bus.publish(event);
|
|
50124
|
+
return event;
|
|
50125
|
+
}
|
|
50126
|
+
};
|
|
50127
|
+
|
|
50128
|
+
// src/core/tor-exits.ts
|
|
50129
|
+
var import_node_fs54 = require("fs");
|
|
50130
|
+
var import_node_path42 = require("path");
|
|
50131
|
+
var import_node_net16 = require("net");
|
|
49834
50132
|
var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
|
|
49835
50133
|
function parseTorExitList(text) {
|
|
49836
50134
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -49838,7 +50136,7 @@ function parseTorExitList(text) {
|
|
|
49838
50136
|
const line2 = raw.trim();
|
|
49839
50137
|
if (!line2 || line2.startsWith("#")) continue;
|
|
49840
50138
|
const ip = line2.split(/\s+/)[0];
|
|
49841
|
-
if ((0,
|
|
50139
|
+
if ((0, import_node_net16.isIP)(ip)) out.add(normalizeIp(ip));
|
|
49842
50140
|
}
|
|
49843
50141
|
return out;
|
|
49844
50142
|
}
|
|
@@ -49886,6 +50184,10 @@ var TorExitList = class _TorExitList {
|
|
|
49886
50184
|
get size() {
|
|
49887
50185
|
return this.exits.size;
|
|
49888
50186
|
}
|
|
50187
|
+
/** Every exit address currently in memory, for the proactive firewall block. */
|
|
50188
|
+
values() {
|
|
50189
|
+
return [...this.exits];
|
|
50190
|
+
}
|
|
49889
50191
|
/** When the list in memory was downloaded (ms), 0 if never. */
|
|
49890
50192
|
get updated() {
|
|
49891
50193
|
return this.updatedAt;
|
|
@@ -49897,10 +50199,10 @@ var TorExitList = class _TorExitList {
|
|
|
49897
50199
|
}
|
|
49898
50200
|
loadCache() {
|
|
49899
50201
|
try {
|
|
49900
|
-
if (!(0,
|
|
49901
|
-
const parsed = parseTorExitList((0,
|
|
50202
|
+
if (!(0, import_node_fs54.existsSync)(this.opts.cachePath)) return false;
|
|
50203
|
+
const parsed = parseTorExitList((0, import_node_fs54.readFileSync)(this.opts.cachePath, "utf-8"));
|
|
49902
50204
|
if (parsed.size === 0) return false;
|
|
49903
|
-
this.load(parsed, (0,
|
|
50205
|
+
this.load(parsed, (0, import_node_fs54.statSync)(this.opts.cachePath).mtimeMs);
|
|
49904
50206
|
this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
|
|
49905
50207
|
return true;
|
|
49906
50208
|
} catch (err) {
|
|
@@ -49932,9 +50234,9 @@ var TorExitList = class _TorExitList {
|
|
|
49932
50234
|
const before2 = this.exits.size;
|
|
49933
50235
|
this.load(parsed);
|
|
49934
50236
|
try {
|
|
49935
|
-
(0,
|
|
49936
|
-
(0,
|
|
49937
|
-
(0,
|
|
50237
|
+
(0, import_node_fs54.mkdirSync)((0, import_node_path42.dirname)(this.opts.cachePath), { recursive: true });
|
|
50238
|
+
(0, import_node_fs54.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
|
|
50239
|
+
(0, import_node_fs54.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
|
|
49938
50240
|
} catch (err) {
|
|
49939
50241
|
this.log(`[tor] could not save the exit list cache: ${err.message}`);
|
|
49940
50242
|
}
|
|
@@ -49943,6 +50245,88 @@ var TorExitList = class _TorExitList {
|
|
|
49943
50245
|
}
|
|
49944
50246
|
};
|
|
49945
50247
|
|
|
50248
|
+
// src/daemon/firewall/tor-block.ts
|
|
50249
|
+
var import_node_child_process17 = require("child_process");
|
|
50250
|
+
var import_node_net17 = require("net");
|
|
50251
|
+
var TOR_NFT_TABLE = "threatcrush-tor";
|
|
50252
|
+
function defaultNftRunner() {
|
|
50253
|
+
return (args, stdin) => new Promise((resolve9, reject) => {
|
|
50254
|
+
const child = (0, import_node_child_process17.execFile)(
|
|
50255
|
+
"nft",
|
|
50256
|
+
args,
|
|
50257
|
+
{ maxBuffer: 16 * 1024 * 1024 },
|
|
50258
|
+
(err) => err ? reject(err) : resolve9()
|
|
50259
|
+
);
|
|
50260
|
+
if (stdin !== void 0) child.stdin?.end(stdin);
|
|
50261
|
+
});
|
|
50262
|
+
}
|
|
50263
|
+
var TorExitBlockEnforcer = class {
|
|
50264
|
+
constructor(opts) {
|
|
50265
|
+
this.opts = opts;
|
|
50266
|
+
this.runNft = opts.runNft ?? defaultNftRunner();
|
|
50267
|
+
this.log = opts.log ?? (() => {
|
|
50268
|
+
});
|
|
50269
|
+
this.intervalMs = Math.max(6e4, opts.intervalMs ?? 36e5);
|
|
50270
|
+
this.sshPort = opts.sshPort ?? 22;
|
|
50271
|
+
}
|
|
50272
|
+
opts;
|
|
50273
|
+
timer = null;
|
|
50274
|
+
applied = false;
|
|
50275
|
+
runNft;
|
|
50276
|
+
log;
|
|
50277
|
+
intervalMs;
|
|
50278
|
+
sshPort;
|
|
50279
|
+
start() {
|
|
50280
|
+
void this.sync();
|
|
50281
|
+
this.timer = setInterval(() => void this.sync(), this.intervalMs);
|
|
50282
|
+
this.timer.unref?.();
|
|
50283
|
+
}
|
|
50284
|
+
stop() {
|
|
50285
|
+
if (this.timer) clearInterval(this.timer);
|
|
50286
|
+
this.timer = null;
|
|
50287
|
+
}
|
|
50288
|
+
/** Apply (or tear down) the block to match the current setting and list. */
|
|
50289
|
+
async sync() {
|
|
50290
|
+
if (!this.opts.enabled()) {
|
|
50291
|
+
await this.teardown();
|
|
50292
|
+
return;
|
|
50293
|
+
}
|
|
50294
|
+
const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net17.isIP)(ip) === 4);
|
|
50295
|
+
if (ipv4.length === 0) return;
|
|
50296
|
+
try {
|
|
50297
|
+
await this.apply(ipv4);
|
|
50298
|
+
if (!this.applied) {
|
|
50299
|
+
this.log(`[tor] proactively blocking ${ipv4.length} Tor exits on tcp/${this.sshPort} (table inet ${TOR_NFT_TABLE})`);
|
|
50300
|
+
}
|
|
50301
|
+
this.applied = true;
|
|
50302
|
+
} catch (err) {
|
|
50303
|
+
this.log(`[tor] could not apply the proactive Tor exit block: ${err.message}`);
|
|
50304
|
+
}
|
|
50305
|
+
}
|
|
50306
|
+
/** One atomic `nft -f -` transaction: declare the table, then load the set. */
|
|
50307
|
+
async apply(ipv4) {
|
|
50308
|
+
const t = TOR_NFT_TABLE;
|
|
50309
|
+
const ruleset = `add table inet ${t}
|
|
50310
|
+
add set inet ${t} exits { type ipv4_addr; }
|
|
50311
|
+
add chain inet ${t} input { type filter hook input priority -100 ; policy accept ; }
|
|
50312
|
+
flush chain inet ${t} input
|
|
50313
|
+
add rule inet ${t} input tcp dport ${this.sshPort} ip saddr @exits counter drop
|
|
50314
|
+
flush set inet ${t} exits
|
|
50315
|
+
add element inet ${t} exits { ${ipv4.join(", ")} }
|
|
50316
|
+
`;
|
|
50317
|
+
await this.runNft(["-f", "-"], ruleset);
|
|
50318
|
+
}
|
|
50319
|
+
async teardown() {
|
|
50320
|
+
if (!this.applied) return;
|
|
50321
|
+
try {
|
|
50322
|
+
await this.runNft(["delete", "table", "inet", TOR_NFT_TABLE]);
|
|
50323
|
+
this.log("[tor] removed the proactive Tor exit block (block_tor_ssh off)");
|
|
50324
|
+
} catch {
|
|
50325
|
+
}
|
|
50326
|
+
this.applied = false;
|
|
50327
|
+
}
|
|
50328
|
+
};
|
|
50329
|
+
|
|
49946
50330
|
// src/daemon/rules/engine.ts
|
|
49947
50331
|
var MAX_WINDOW_ENTRIES = 1e3;
|
|
49948
50332
|
function live(window) {
|
|
@@ -50155,7 +50539,7 @@ var RuleEngine = class {
|
|
|
50155
50539
|
};
|
|
50156
50540
|
|
|
50157
50541
|
// src/daemon/rules/loader.ts
|
|
50158
|
-
var
|
|
50542
|
+
var import_node_fs55 = require("fs");
|
|
50159
50543
|
var import_node_path43 = require("path");
|
|
50160
50544
|
|
|
50161
50545
|
// src/daemon/rules/default-rules.ts
|
|
@@ -50793,6 +51177,33 @@ var DEFAULT_RULES = [
|
|
|
50793
51177
|
tags: ["agentdb", "rate-limit", "data-access"],
|
|
50794
51178
|
remediation: { action: "alert", description: "Review AgentDB audit metadata for the token and request pattern" },
|
|
50795
51179
|
enabled: true
|
|
51180
|
+
},
|
|
51181
|
+
{
|
|
51182
|
+
// 2026-11-20 dev2: ~10,150 failed `postgres` logins from ~60 addresses in
|
|
51183
|
+
// 72h against a Supabase Postgres published on 0.0.0.0, none banned. Fed by
|
|
51184
|
+
// docker-logs (`[docker_logs]`), which already drops private, Docker-bridge
|
|
51185
|
+
// and protected sources, so every event here names a public client.
|
|
51186
|
+
id: "postgres-auth-bruteforce",
|
|
51187
|
+
title: "Postgres Brute Force Detected",
|
|
51188
|
+
description: "Repeated Postgres password failures or pg_hba rejects from the same source",
|
|
51189
|
+
version: "1.0.0",
|
|
51190
|
+
category: "auth",
|
|
51191
|
+
severity: "high",
|
|
51192
|
+
source_types: ["postgres-guard"],
|
|
51193
|
+
match: {
|
|
51194
|
+
field: "message",
|
|
51195
|
+
operator: "regex",
|
|
51196
|
+
value: "^Postgres (?:password authentication failed|connection rejected by pg_hba) "
|
|
51197
|
+
},
|
|
51198
|
+
threshold: 5,
|
|
51199
|
+
window_seconds: 600,
|
|
51200
|
+
cooldown_seconds: 600,
|
|
51201
|
+
tags: ["postgres", "database", "brute-force", "credential-stuffing"],
|
|
51202
|
+
remediation: {
|
|
51203
|
+
action: "block",
|
|
51204
|
+
description: "Block source IP brute-forcing Postgres"
|
|
51205
|
+
},
|
|
51206
|
+
enabled: true
|
|
50796
51207
|
}
|
|
50797
51208
|
];
|
|
50798
51209
|
|
|
@@ -50801,11 +51212,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
50801
51212
|
function loadAllRules(customDir) {
|
|
50802
51213
|
const rules = [...DEFAULT_RULES];
|
|
50803
51214
|
const dir = customDir || RULES_DIR;
|
|
50804
|
-
if ((0,
|
|
50805
|
-
|
|
51215
|
+
if ((0, import_node_fs55.existsSync)(dir)) {
|
|
51216
|
+
let files = [];
|
|
51217
|
+
try {
|
|
51218
|
+
files = (0, import_node_fs55.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
51219
|
+
} catch (err) {
|
|
51220
|
+
console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
|
|
51221
|
+
}
|
|
50806
51222
|
for (const file of files) {
|
|
50807
51223
|
try {
|
|
50808
|
-
const raw = (0,
|
|
51224
|
+
const raw = (0, import_node_fs55.readFileSync)((0, import_node_path43.join)(dir, file), "utf-8");
|
|
50809
51225
|
const parsed = JSON.parse(raw);
|
|
50810
51226
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
50811
51227
|
for (const rule of customRules) {
|
|
@@ -50836,24 +51252,24 @@ function loadAllRules(customDir) {
|
|
|
50836
51252
|
}
|
|
50837
51253
|
|
|
50838
51254
|
// src/daemon/firewall/adapters.ts
|
|
50839
|
-
var
|
|
50840
|
-
var
|
|
51255
|
+
var import_node_child_process18 = require("child_process");
|
|
51256
|
+
var import_node_fs56 = require("fs");
|
|
50841
51257
|
var import_node_path44 = require("path");
|
|
50842
|
-
var
|
|
51258
|
+
var import_node_net18 = require("net");
|
|
50843
51259
|
function assertValidFirewallIp(ip) {
|
|
50844
|
-
if ((0,
|
|
51260
|
+
if ((0, import_node_net18.isIP)(ip) !== 4) {
|
|
50845
51261
|
throw new Error(`Invalid IPv4 address: ${ip}`);
|
|
50846
51262
|
}
|
|
50847
51263
|
}
|
|
50848
51264
|
function assertBannableIp(ip) {
|
|
50849
|
-
if ((0,
|
|
51265
|
+
if ((0, import_node_net18.isIP)(ip) === 0) {
|
|
50850
51266
|
throw new Error(`Invalid IP address: ${ip}`);
|
|
50851
51267
|
}
|
|
50852
51268
|
}
|
|
50853
51269
|
function writeIfAbsent(path2, contents) {
|
|
50854
|
-
(0,
|
|
51270
|
+
(0, import_node_fs56.mkdirSync)((0, import_node_path44.dirname)(path2), { recursive: true });
|
|
50855
51271
|
try {
|
|
50856
|
-
(0,
|
|
51272
|
+
(0, import_node_fs56.writeFileSync)(path2, contents, { flag: "wx" });
|
|
50857
51273
|
} catch (err) {
|
|
50858
51274
|
if (err.code !== "EEXIST") throw err;
|
|
50859
51275
|
}
|
|
@@ -50872,11 +51288,11 @@ var Fail2banAdapter = class {
|
|
|
50872
51288
|
enforces = true;
|
|
50873
51289
|
jailReady = false;
|
|
50874
51290
|
isAvailable() {
|
|
50875
|
-
const result = (0,
|
|
51291
|
+
const result = (0, import_node_child_process18.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
50876
51292
|
return result.status === 0;
|
|
50877
51293
|
}
|
|
50878
51294
|
client(args) {
|
|
50879
|
-
return (0,
|
|
51295
|
+
return (0, import_node_child_process18.execFileSync)("fail2ban-client", args, {
|
|
50880
51296
|
encoding: "utf-8",
|
|
50881
51297
|
stdio: ["ignore", "pipe", "pipe"]
|
|
50882
51298
|
});
|
|
@@ -50952,7 +51368,7 @@ var Fail2banAdapter = class {
|
|
|
50952
51368
|
const status = this.client(["status", this.jail]);
|
|
50953
51369
|
const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
|
|
50954
51370
|
if (!line2) return [];
|
|
50955
|
-
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0,
|
|
51371
|
+
return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
|
|
50956
51372
|
} catch {
|
|
50957
51373
|
return [];
|
|
50958
51374
|
}
|
|
@@ -50962,45 +51378,45 @@ var Fail2banAdapter = class {
|
|
|
50962
51378
|
function parseBannedList(output) {
|
|
50963
51379
|
const found = [];
|
|
50964
51380
|
for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
50965
|
-
if ((0,
|
|
51381
|
+
if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
|
|
50966
51382
|
}
|
|
50967
51383
|
if (found.length > 0) return found;
|
|
50968
|
-
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0,
|
|
51384
|
+
return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
|
|
50969
51385
|
}
|
|
50970
51386
|
var NftablesAdapter = class {
|
|
50971
51387
|
name = "nftables";
|
|
50972
51388
|
table = "threatcrush";
|
|
50973
51389
|
set = "blocklist";
|
|
50974
51390
|
isAvailable() {
|
|
50975
|
-
const result = (0,
|
|
51391
|
+
const result = (0, import_node_child_process18.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
50976
51392
|
return result.status === 0;
|
|
50977
51393
|
}
|
|
50978
51394
|
ensureSetup() {
|
|
50979
51395
|
try {
|
|
50980
|
-
(0,
|
|
51396
|
+
(0, import_node_child_process18.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
50981
51397
|
} catch {
|
|
50982
|
-
(0,
|
|
50983
|
-
(0,
|
|
50984
|
-
(0,
|
|
50985
|
-
(0,
|
|
51398
|
+
(0, import_node_child_process18.execSync)(`nft add table inet ${this.table}`);
|
|
51399
|
+
(0, import_node_child_process18.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
51400
|
+
(0, import_node_child_process18.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
51401
|
+
(0, import_node_child_process18.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
50986
51402
|
}
|
|
50987
51403
|
}
|
|
50988
51404
|
async block(ip) {
|
|
50989
51405
|
assertValidFirewallIp(ip);
|
|
50990
51406
|
this.ensureSetup();
|
|
50991
|
-
(0,
|
|
51407
|
+
(0, import_node_child_process18.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
50992
51408
|
}
|
|
50993
51409
|
async unblock(ip) {
|
|
50994
51410
|
assertValidFirewallIp(ip);
|
|
50995
51411
|
try {
|
|
50996
|
-
(0,
|
|
51412
|
+
(0, import_node_child_process18.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
50997
51413
|
} catch {
|
|
50998
51414
|
}
|
|
50999
51415
|
}
|
|
51000
51416
|
async isBlocked(ip) {
|
|
51001
51417
|
assertValidFirewallIp(ip);
|
|
51002
51418
|
try {
|
|
51003
|
-
const output = (0,
|
|
51419
|
+
const output = (0, import_node_child_process18.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
51004
51420
|
return output.includes(ip);
|
|
51005
51421
|
} catch {
|
|
51006
51422
|
return false;
|
|
@@ -51008,7 +51424,7 @@ var NftablesAdapter = class {
|
|
|
51008
51424
|
}
|
|
51009
51425
|
async listBlocked() {
|
|
51010
51426
|
try {
|
|
51011
|
-
const output = (0,
|
|
51427
|
+
const output = (0, import_node_child_process18.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
51012
51428
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
51013
51429
|
if (!match) return [];
|
|
51014
51430
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -51021,34 +51437,34 @@ var IptablesAdapter = class {
|
|
|
51021
51437
|
name = "iptables";
|
|
51022
51438
|
chain = "THREATCRUSH";
|
|
51023
51439
|
isAvailable() {
|
|
51024
|
-
const result = (0,
|
|
51440
|
+
const result = (0, import_node_child_process18.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
51025
51441
|
return result.status === 0;
|
|
51026
51442
|
}
|
|
51027
51443
|
ensureChain() {
|
|
51028
51444
|
try {
|
|
51029
|
-
(0,
|
|
51445
|
+
(0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
51030
51446
|
} catch {
|
|
51031
|
-
(0,
|
|
51032
|
-
(0,
|
|
51447
|
+
(0, import_node_child_process18.execSync)(`iptables -N ${this.chain}`);
|
|
51448
|
+
(0, import_node_child_process18.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
51033
51449
|
}
|
|
51034
51450
|
}
|
|
51035
51451
|
async block(ip) {
|
|
51036
51452
|
assertValidFirewallIp(ip);
|
|
51037
51453
|
this.ensureChain();
|
|
51038
51454
|
if (await this.isBlocked(ip)) return;
|
|
51039
|
-
(0,
|
|
51455
|
+
(0, import_node_child_process18.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
51040
51456
|
}
|
|
51041
51457
|
async unblock(ip) {
|
|
51042
51458
|
assertValidFirewallIp(ip);
|
|
51043
51459
|
try {
|
|
51044
|
-
(0,
|
|
51460
|
+
(0, import_node_child_process18.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
51045
51461
|
} catch {
|
|
51046
51462
|
}
|
|
51047
51463
|
}
|
|
51048
51464
|
async isBlocked(ip) {
|
|
51049
51465
|
assertValidFirewallIp(ip);
|
|
51050
51466
|
try {
|
|
51051
|
-
const output = (0,
|
|
51467
|
+
const output = (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
51052
51468
|
return output.includes(ip);
|
|
51053
51469
|
} catch {
|
|
51054
51470
|
return false;
|
|
@@ -51056,7 +51472,7 @@ var IptablesAdapter = class {
|
|
|
51056
51472
|
}
|
|
51057
51473
|
async listBlocked() {
|
|
51058
51474
|
try {
|
|
51059
|
-
const output = (0,
|
|
51475
|
+
const output = (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
51060
51476
|
const ips = [];
|
|
51061
51477
|
for (const line2 of output.split("\n")) {
|
|
51062
51478
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -51112,9 +51528,9 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
51112
51528
|
}
|
|
51113
51529
|
|
|
51114
51530
|
// src/daemon/firewall/remediation.ts
|
|
51115
|
-
var
|
|
51116
|
-
var
|
|
51117
|
-
var
|
|
51531
|
+
var import_node_fs57 = require("fs");
|
|
51532
|
+
var import_node_child_process19 = require("child_process");
|
|
51533
|
+
var import_node_net19 = require("net");
|
|
51118
51534
|
init_paths();
|
|
51119
51535
|
init_backoff();
|
|
51120
51536
|
|
|
@@ -51184,19 +51600,19 @@ var defaultDiscovery = {
|
|
|
51184
51600
|
const snapshot = takeSnapshot({
|
|
51185
51601
|
readFile: (p) => {
|
|
51186
51602
|
try {
|
|
51187
|
-
return (0,
|
|
51603
|
+
return (0, import_node_fs57.readFileSync)(p, "utf-8");
|
|
51188
51604
|
} catch {
|
|
51189
51605
|
return null;
|
|
51190
51606
|
}
|
|
51191
51607
|
},
|
|
51192
51608
|
readDir: (p) => {
|
|
51193
51609
|
try {
|
|
51194
|
-
return (0,
|
|
51610
|
+
return (0, import_node_fs57.readdirSync)(p);
|
|
51195
51611
|
} catch {
|
|
51196
51612
|
return null;
|
|
51197
51613
|
}
|
|
51198
51614
|
},
|
|
51199
|
-
exists: (p) => (0,
|
|
51615
|
+
exists: (p) => (0, import_node_fs57.existsSync)(p)
|
|
51200
51616
|
});
|
|
51201
51617
|
const out = /* @__PURE__ */ new Set();
|
|
51202
51618
|
for (const keys of Object.values(snapshot.keys)) {
|
|
@@ -51205,7 +51621,7 @@ var defaultDiscovery = {
|
|
|
51205
51621
|
return out;
|
|
51206
51622
|
},
|
|
51207
51623
|
keyLoginJournal: (sinceSeconds) => new Promise((resolve9) => {
|
|
51208
|
-
(0,
|
|
51624
|
+
(0, import_node_child_process19.execFile)(
|
|
51209
51625
|
"journalctl",
|
|
51210
51626
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
51211
51627
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
@@ -51285,7 +51701,7 @@ var RemediationManager = class {
|
|
|
51285
51701
|
setTorExitCheck(check2) {
|
|
51286
51702
|
this.isTorExit = check2;
|
|
51287
51703
|
let dropped = 0;
|
|
51288
|
-
this.protectedList = this.protectedList.filter((a) => !(0,
|
|
51704
|
+
this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
|
|
51289
51705
|
for (const ip of Object.keys(this.operators)) {
|
|
51290
51706
|
if (!check2(ip)) continue;
|
|
51291
51707
|
delete this.operators[ip];
|
|
@@ -51378,7 +51794,7 @@ var RemediationManager = class {
|
|
|
51378
51794
|
if (remediation?.action !== "block") return;
|
|
51379
51795
|
}
|
|
51380
51796
|
const ip = event.source_ip;
|
|
51381
|
-
if (!ip || (0,
|
|
51797
|
+
if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
|
|
51382
51798
|
const strict = remediation?.override_operator_protection === true;
|
|
51383
51799
|
if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
51384
51800
|
if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
|
|
@@ -51407,7 +51823,7 @@ var RemediationManager = class {
|
|
|
51407
51823
|
* 4th offence and so on, clamped to `max_ban_seconds`.
|
|
51408
51824
|
*/
|
|
51409
51825
|
async ban(ip, reason, opts = {}) {
|
|
51410
|
-
if ((0,
|
|
51826
|
+
if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
|
|
51411
51827
|
if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
|
|
51412
51828
|
return { ok: false, error: `${ip} is protected and can never be blocked` };
|
|
51413
51829
|
}
|
|
@@ -51684,7 +52100,7 @@ var RemediationManager = class {
|
|
|
51684
52100
|
if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
|
|
51685
52101
|
const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
|
|
51686
52102
|
for (const [ip, at] of Object.entries(saved)) {
|
|
51687
|
-
if (typeof at !== "number" || at < cutoff || !(0,
|
|
52103
|
+
if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
|
|
51688
52104
|
if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
|
|
51689
52105
|
this.operators[ip] = at;
|
|
51690
52106
|
if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
|
|
@@ -51709,7 +52125,7 @@ var RemediationManager = class {
|
|
|
51709
52125
|
}
|
|
51710
52126
|
logLine(line2) {
|
|
51711
52127
|
try {
|
|
51712
|
-
(0,
|
|
52128
|
+
(0, import_node_fs57.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
51713
52129
|
`);
|
|
51714
52130
|
} catch {
|
|
51715
52131
|
}
|
|
@@ -51753,13 +52169,13 @@ function remediationSettings(section) {
|
|
|
51753
52169
|
init_backoff();
|
|
51754
52170
|
|
|
51755
52171
|
// src/daemon/watchdog-service.ts
|
|
51756
|
-
var
|
|
52172
|
+
var import_node_fs58 = require("fs");
|
|
51757
52173
|
var import_node_path45 = require("path");
|
|
51758
52174
|
function defaultShareGid() {
|
|
51759
52175
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
51760
52176
|
if (!isRoot4) return void 0;
|
|
51761
52177
|
try {
|
|
51762
|
-
return (0,
|
|
52178
|
+
return (0, import_node_fs58.statSync)("/var/log/auth.log").gid;
|
|
51763
52179
|
} catch {
|
|
51764
52180
|
return void 0;
|
|
51765
52181
|
}
|
|
@@ -51859,7 +52275,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
51859
52275
|
}
|
|
51860
52276
|
|
|
51861
52277
|
// src/core/node-runtime.ts
|
|
51862
|
-
var
|
|
52278
|
+
var import_node_child_process20 = require("child_process");
|
|
51863
52279
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
51864
52280
|
function nodeMajor(version) {
|
|
51865
52281
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -51873,21 +52289,21 @@ function daemonNodeProblem(version) {
|
|
|
51873
52289
|
}
|
|
51874
52290
|
function versionOfNode(path2) {
|
|
51875
52291
|
if (path2 === process.execPath) return process.versions.node;
|
|
51876
|
-
const res = (0,
|
|
52292
|
+
const res = (0, import_node_child_process20.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
51877
52293
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
51878
52294
|
}
|
|
51879
52295
|
|
|
51880
52296
|
// src/daemon/index.ts
|
|
51881
52297
|
function readVersion2() {
|
|
51882
52298
|
try {
|
|
51883
|
-
const pkg = JSON.parse((0,
|
|
52299
|
+
const pkg = JSON.parse((0, import_node_fs59.readFileSync)((0, import_node_path46.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
51884
52300
|
return pkg.version || "0.0.0";
|
|
51885
52301
|
} catch {
|
|
51886
52302
|
return "0.0.0";
|
|
51887
52303
|
}
|
|
51888
52304
|
}
|
|
51889
52305
|
async function runHardeningChecks() {
|
|
51890
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
52306
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
|
|
51891
52307
|
process.execPath,
|
|
51892
52308
|
[(0, import_node_path46.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
51893
52309
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
@@ -51901,7 +52317,7 @@ async function runHardeningChecks() {
|
|
|
51901
52317
|
return patches ? [...findings2, patches] : findings2;
|
|
51902
52318
|
}
|
|
51903
52319
|
async function runPatchCheck() {
|
|
51904
|
-
const { stdout } = await (0, import_node_util4.promisify)(
|
|
52320
|
+
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
|
|
51905
52321
|
process.execPath,
|
|
51906
52322
|
[(0, import_node_path46.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
|
|
51907
52323
|
{ timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
|
|
@@ -51911,7 +52327,7 @@ async function runPatchCheck() {
|
|
|
51911
52327
|
}
|
|
51912
52328
|
function logLine(line2) {
|
|
51913
52329
|
try {
|
|
51914
|
-
(0,
|
|
52330
|
+
(0, import_node_fs59.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
51915
52331
|
`);
|
|
51916
52332
|
} catch {
|
|
51917
52333
|
}
|
|
@@ -51936,9 +52352,9 @@ async function runDaemon() {
|
|
|
51936
52352
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
51937
52353
|
const restartDaemon = () => {
|
|
51938
52354
|
if (PATHS.mode === "system") {
|
|
51939
|
-
(0,
|
|
52355
|
+
(0, import_node_child_process21.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
51940
52356
|
} else {
|
|
51941
|
-
(0,
|
|
52357
|
+
(0, import_node_child_process21.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
51942
52358
|
setTimeout(() => process.exit(0), 500).unref();
|
|
51943
52359
|
}
|
|
51944
52360
|
};
|
|
@@ -52074,6 +52490,12 @@ async function runDaemon() {
|
|
|
52074
52490
|
log: logLine
|
|
52075
52491
|
});
|
|
52076
52492
|
sshIntrusion.start();
|
|
52493
|
+
const torBlock = new TorExitBlockEnforcer({
|
|
52494
|
+
exits: torExits,
|
|
52495
|
+
enabled: () => remediation.blockTorSsh && firewallAdapter.name === "nftables",
|
|
52496
|
+
log: logLine
|
|
52497
|
+
});
|
|
52498
|
+
torBlock.start();
|
|
52077
52499
|
const lightningWatch = new LightningWatch({
|
|
52078
52500
|
bus,
|
|
52079
52501
|
enabled: config.lightning?.enabled !== false,
|
|
@@ -52081,6 +52503,13 @@ async function runDaemon() {
|
|
|
52081
52503
|
log: logLine
|
|
52082
52504
|
});
|
|
52083
52505
|
lightningWatch.start();
|
|
52506
|
+
const dockerLogs = new DockerLogsWatch({
|
|
52507
|
+
bus,
|
|
52508
|
+
settings: dockerLogsSettings(config.docker_logs),
|
|
52509
|
+
protectedList: remediation.getAllowlist(),
|
|
52510
|
+
log: logLine
|
|
52511
|
+
});
|
|
52512
|
+
dockerLogs.start();
|
|
52084
52513
|
let cloudSyncRef = null;
|
|
52085
52514
|
new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
|
|
52086
52515
|
if (loaded.error) {
|
|
@@ -52137,6 +52566,7 @@ async function runDaemon() {
|
|
|
52137
52566
|
if (torPinned || typeof block_tor_ssh !== "boolean" || block_tor_ssh === remediation.blockTorSsh) return;
|
|
52138
52567
|
remediation.setBlockTorSsh(block_tor_ssh);
|
|
52139
52568
|
logLine(`[ssh-intrusion] Tor SSH ban ${block_tor_ssh ? "ON" : "OFF"} (org setting from the dashboard)`);
|
|
52569
|
+
void torBlock.sync();
|
|
52140
52570
|
}
|
|
52141
52571
|
});
|
|
52142
52572
|
allowlistSync.start();
|
|
@@ -52225,6 +52655,10 @@ async function runDaemon() {
|
|
|
52225
52655
|
lightningWatch.stop();
|
|
52226
52656
|
} catch {
|
|
52227
52657
|
}
|
|
52658
|
+
try {
|
|
52659
|
+
dockerLogs.stop();
|
|
52660
|
+
} catch {
|
|
52661
|
+
}
|
|
52228
52662
|
try {
|
|
52229
52663
|
await ipc.stop();
|
|
52230
52664
|
} catch {
|
|
@@ -52281,7 +52715,7 @@ async function daemonStart() {
|
|
|
52281
52715
|
return;
|
|
52282
52716
|
}
|
|
52283
52717
|
ensureRuntimeDirs();
|
|
52284
|
-
if (!(0,
|
|
52718
|
+
if (!(0, import_node_fs60.existsSync)(DAEMON_ENTRY)) {
|
|
52285
52719
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
52286
52720
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
52287
52721
|
return;
|
|
@@ -52289,8 +52723,8 @@ async function daemonStart() {
|
|
|
52289
52723
|
let out;
|
|
52290
52724
|
let err;
|
|
52291
52725
|
try {
|
|
52292
|
-
out = (0,
|
|
52293
|
-
err = (0,
|
|
52726
|
+
out = (0, import_node_fs61.openSync)(PATHS.logFile, "a");
|
|
52727
|
+
err = (0, import_node_fs61.openSync)(PATHS.logFile, "a");
|
|
52294
52728
|
} catch (e) {
|
|
52295
52729
|
const code = e.code;
|
|
52296
52730
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -52303,7 +52737,7 @@ async function daemonStart() {
|
|
|
52303
52737
|
}
|
|
52304
52738
|
return;
|
|
52305
52739
|
}
|
|
52306
|
-
const child = (0,
|
|
52740
|
+
const child = (0, import_node_child_process22.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
52307
52741
|
detached: true,
|
|
52308
52742
|
stdio: ["ignore", out, err],
|
|
52309
52743
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -52378,41 +52812,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
52378
52812
|
}
|
|
52379
52813
|
async function releaseStaleSocket() {
|
|
52380
52814
|
const deadline = Date.now() + 2e3;
|
|
52381
|
-
while ((0,
|
|
52815
|
+
while ((0, import_node_fs60.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
52382
52816
|
await new Promise((r) => setTimeout(r, 50));
|
|
52383
52817
|
}
|
|
52384
|
-
if ((0,
|
|
52818
|
+
if ((0, import_node_fs60.existsSync)(PATHS.socket)) {
|
|
52385
52819
|
try {
|
|
52386
|
-
(0,
|
|
52820
|
+
(0, import_node_fs60.unlinkSync)(PATHS.socket);
|
|
52387
52821
|
} catch {
|
|
52388
52822
|
}
|
|
52389
52823
|
}
|
|
52390
52824
|
}
|
|
52391
52825
|
|
|
52392
52826
|
// src/commands/service.ts
|
|
52393
|
-
var
|
|
52394
|
-
var
|
|
52827
|
+
var import_node_child_process23 = require("child_process");
|
|
52828
|
+
var import_node_fs62 = require("fs");
|
|
52395
52829
|
var import_node_path48 = require("path");
|
|
52396
52830
|
var import_node_os20 = require("os");
|
|
52397
52831
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
52398
52832
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
52399
52833
|
function resolveTemplate() {
|
|
52400
52834
|
const templatePath = (0, import_node_path48.join)(__dirname, "systemd", "threatcrushd.service");
|
|
52401
|
-
if (!(0,
|
|
52835
|
+
if (!(0, import_node_fs62.existsSync)(templatePath)) {
|
|
52402
52836
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
52403
52837
|
}
|
|
52404
|
-
return (0,
|
|
52838
|
+
return (0, import_node_fs62.readFileSync)(templatePath, "utf-8");
|
|
52405
52839
|
}
|
|
52406
52840
|
function stableBinPath(binPath) {
|
|
52407
52841
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
52408
52842
|
if (stable === binPath) return binPath;
|
|
52409
|
-
return (0,
|
|
52843
|
+
return (0, import_node_fs62.existsSync)(stable) ? stable : binPath;
|
|
52410
52844
|
}
|
|
52411
52845
|
function resolveBinPath() {
|
|
52412
52846
|
const arg = process.argv[1];
|
|
52413
|
-
if (arg && (0,
|
|
52847
|
+
if (arg && (0, import_node_fs62.existsSync)(arg)) return stableBinPath(arg);
|
|
52414
52848
|
try {
|
|
52415
|
-
return (0,
|
|
52849
|
+
return (0, import_node_child_process23.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
52416
52850
|
} catch {
|
|
52417
52851
|
return "threatcrush";
|
|
52418
52852
|
}
|
|
@@ -52420,11 +52854,11 @@ function resolveBinPath() {
|
|
|
52420
52854
|
function stableNodePath(execPath) {
|
|
52421
52855
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
52422
52856
|
if (stable === execPath) return execPath;
|
|
52423
|
-
return (0,
|
|
52857
|
+
return (0, import_node_fs62.existsSync)(stable) ? stable : execPath;
|
|
52424
52858
|
}
|
|
52425
52859
|
function looksLikeNodeScript(path2) {
|
|
52426
52860
|
try {
|
|
52427
|
-
const head2 = (0,
|
|
52861
|
+
const head2 = (0, import_node_fs62.readFileSync)(path2, "utf-8").slice(0, 120);
|
|
52428
52862
|
return /^#!.*\bnode\b/.test(head2);
|
|
52429
52863
|
} catch {
|
|
52430
52864
|
return false;
|
|
@@ -52451,20 +52885,20 @@ function isRoot3() {
|
|
|
52451
52885
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
52452
52886
|
}
|
|
52453
52887
|
function reexecWithSudo(args) {
|
|
52454
|
-
if ((0,
|
|
52888
|
+
if ((0, import_node_child_process23.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
52455
52889
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
52456
52890
|
const bin = resolveBinPath();
|
|
52457
52891
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
52458
|
-
const result = (0,
|
|
52892
|
+
const result = (0, import_node_child_process23.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
52459
52893
|
return result.status === 0;
|
|
52460
52894
|
}
|
|
52461
52895
|
function callerHome() {
|
|
52462
52896
|
const user = process.env.SUDO_USER;
|
|
52463
52897
|
if (!user) return null;
|
|
52464
52898
|
try {
|
|
52465
|
-
const line2 = (0,
|
|
52899
|
+
const line2 = (0, import_node_child_process23.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
52466
52900
|
const home = line2.split(":")[5];
|
|
52467
|
-
return home && (0,
|
|
52901
|
+
return home && (0, import_node_fs62.existsSync)(home) ? home : null;
|
|
52468
52902
|
} catch {
|
|
52469
52903
|
return null;
|
|
52470
52904
|
}
|
|
@@ -52475,10 +52909,10 @@ function stopUserModeDaemon() {
|
|
|
52475
52909
|
const runDir = (0, import_node_path48.join)(home, ".threatcrush", "run");
|
|
52476
52910
|
const pidFile = (0, import_node_path48.join)(runDir, "threatcrushd.pid");
|
|
52477
52911
|
const socket = (0, import_node_path48.join)(runDir, "threatcrushd.sock");
|
|
52478
|
-
if (!(0,
|
|
52912
|
+
if (!(0, import_node_fs62.existsSync)(pidFile) && !(0, import_node_fs62.existsSync)(socket)) return;
|
|
52479
52913
|
let pid = null;
|
|
52480
52914
|
try {
|
|
52481
|
-
pid = Number.parseInt((0,
|
|
52915
|
+
pid = Number.parseInt((0, import_node_fs62.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
52482
52916
|
} catch {
|
|
52483
52917
|
pid = null;
|
|
52484
52918
|
}
|
|
@@ -52491,13 +52925,13 @@ function stopUserModeDaemon() {
|
|
|
52491
52925
|
}
|
|
52492
52926
|
for (const path2 of [socket, pidFile]) {
|
|
52493
52927
|
try {
|
|
52494
|
-
if ((0,
|
|
52928
|
+
if ((0, import_node_fs62.existsSync)(path2)) (0, import_node_fs62.rmSync)(path2);
|
|
52495
52929
|
} catch {
|
|
52496
52930
|
}
|
|
52497
52931
|
}
|
|
52498
52932
|
}
|
|
52499
52933
|
function unitIsActive() {
|
|
52500
|
-
const result = (0,
|
|
52934
|
+
const result = (0, import_node_child_process23.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
52501
52935
|
return result.status === 0;
|
|
52502
52936
|
}
|
|
52503
52937
|
async function installServiceCommand() {
|
|
@@ -52508,8 +52942,8 @@ async function installServiceCommand() {
|
|
|
52508
52942
|
return;
|
|
52509
52943
|
}
|
|
52510
52944
|
const noSystemd = systemdUnavailableReason({
|
|
52511
|
-
hasSystemctl: (0,
|
|
52512
|
-
booted: (0,
|
|
52945
|
+
hasSystemctl: (0, import_node_child_process23.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
52946
|
+
booted: (0, import_node_fs62.existsSync)("/run/systemd/system")
|
|
52513
52947
|
});
|
|
52514
52948
|
if (noSystemd) {
|
|
52515
52949
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -52531,7 +52965,7 @@ async function installServiceCommand() {
|
|
|
52531
52965
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
52532
52966
|
let nodePath = stableNodePath(process.execPath);
|
|
52533
52967
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
52534
|
-
binPath = (0,
|
|
52968
|
+
binPath = (0, import_node_fs62.realpathSync)(binPath);
|
|
52535
52969
|
nodePath = process.execPath;
|
|
52536
52970
|
}
|
|
52537
52971
|
if (isNodeScript) {
|
|
@@ -52548,7 +52982,7 @@ async function installServiceCommand() {
|
|
|
52548
52982
|
const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
|
|
52549
52983
|
const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
|
|
52550
52984
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
|
|
52551
|
-
(0,
|
|
52985
|
+
(0, import_node_fs62.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
52552
52986
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
52553
52987
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
52554
52988
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -52563,8 +52997,8 @@ async function installServiceCommand() {
|
|
|
52563
52997
|
installLogrotate();
|
|
52564
52998
|
stopUserModeDaemon();
|
|
52565
52999
|
try {
|
|
52566
|
-
(0,
|
|
52567
|
-
(0,
|
|
53000
|
+
(0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
53001
|
+
(0, import_node_child_process23.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
52568
53002
|
} catch (err) {
|
|
52569
53003
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
52570
53004
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -52601,9 +53035,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
52601
53035
|
].join("\n");
|
|
52602
53036
|
}
|
|
52603
53037
|
function installLogrotate() {
|
|
52604
|
-
if (!(0,
|
|
53038
|
+
if (!(0, import_node_fs62.existsSync)((0, import_node_path48.dirname)(LOGROTATE_PATH))) return;
|
|
52605
53039
|
try {
|
|
52606
|
-
(0,
|
|
53040
|
+
(0, import_node_fs62.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
52607
53041
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
52608
53042
|
} catch (err) {
|
|
52609
53043
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -52625,20 +53059,20 @@ function ensureSystemDirs(configDir) {
|
|
|
52625
53059
|
];
|
|
52626
53060
|
let admGid2 = null;
|
|
52627
53061
|
try {
|
|
52628
|
-
admGid2 = (0,
|
|
53062
|
+
admGid2 = (0, import_node_fs62.statSync)("/var/log/auth.log").gid;
|
|
52629
53063
|
} catch {
|
|
52630
53064
|
}
|
|
52631
53065
|
for (const { path: path2, groupWritable, sticky } of dirs) {
|
|
52632
53066
|
try {
|
|
52633
|
-
(0,
|
|
53067
|
+
(0, import_node_fs62.mkdirSync)(path2, { recursive: true });
|
|
52634
53068
|
} catch {
|
|
52635
53069
|
}
|
|
52636
53070
|
try {
|
|
52637
53071
|
if (groupWritable && admGid2 !== null) {
|
|
52638
|
-
(0,
|
|
52639
|
-
(0,
|
|
53072
|
+
(0, import_node_fs62.chmodSync)(path2, sticky ? 1533 : 509);
|
|
53073
|
+
(0, import_node_child_process23.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
|
|
52640
53074
|
} else {
|
|
52641
|
-
(0,
|
|
53075
|
+
(0, import_node_fs62.chmodSync)(path2, 493);
|
|
52642
53076
|
}
|
|
52643
53077
|
} catch {
|
|
52644
53078
|
}
|
|
@@ -52658,29 +53092,29 @@ async function uninstallServiceCommand() {
|
|
|
52658
53092
|
return;
|
|
52659
53093
|
}
|
|
52660
53094
|
try {
|
|
52661
|
-
(0,
|
|
53095
|
+
(0, import_node_child_process23.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
52662
53096
|
} catch {
|
|
52663
53097
|
}
|
|
52664
53098
|
try {
|
|
52665
|
-
(0,
|
|
53099
|
+
(0, import_node_child_process23.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
52666
53100
|
} catch {
|
|
52667
53101
|
}
|
|
52668
53102
|
try {
|
|
52669
|
-
if ((0,
|
|
52670
|
-
(0,
|
|
53103
|
+
if ((0, import_node_fs62.existsSync)(UNIT_PATH)) {
|
|
53104
|
+
(0, import_node_child_process23.execSync)(`rm -f ${UNIT_PATH}`);
|
|
52671
53105
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
52672
53106
|
}
|
|
52673
53107
|
} catch {
|
|
52674
53108
|
}
|
|
52675
53109
|
try {
|
|
52676
|
-
(0,
|
|
53110
|
+
(0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
52677
53111
|
} catch {
|
|
52678
53112
|
}
|
|
52679
53113
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
52680
53114
|
}
|
|
52681
53115
|
|
|
52682
53116
|
// src/commands/save.ts
|
|
52683
|
-
var
|
|
53117
|
+
var import_node_fs63 = require("fs");
|
|
52684
53118
|
var import_toml6 = __toESM(require_toml());
|
|
52685
53119
|
init_cli_config();
|
|
52686
53120
|
init_paths();
|
|
@@ -52719,9 +53153,9 @@ async function saveCommand(opts = {}) {
|
|
|
52719
53153
|
}
|
|
52720
53154
|
const path2 = opts.config ?? PATHS.configFile;
|
|
52721
53155
|
let config = {};
|
|
52722
|
-
if ((0,
|
|
53156
|
+
if ((0, import_node_fs63.existsSync)(path2)) {
|
|
52723
53157
|
try {
|
|
52724
|
-
config = import_toml6.default.parse((0,
|
|
53158
|
+
config = import_toml6.default.parse((0, import_node_fs63.readFileSync)(path2, "utf-8"));
|
|
52725
53159
|
} catch (err) {
|
|
52726
53160
|
console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
|
|
52727
53161
|
`));
|
|
@@ -52834,7 +53268,7 @@ function welcomeCommand() {
|
|
|
52834
53268
|
}
|
|
52835
53269
|
|
|
52836
53270
|
// src/commands/properties.ts
|
|
52837
|
-
var
|
|
53271
|
+
var import_node_fs64 = require("fs");
|
|
52838
53272
|
var import_node_path49 = require("path");
|
|
52839
53273
|
var import_node_readline4 = __toESM(require("readline"));
|
|
52840
53274
|
init_cli_config();
|
|
@@ -53166,7 +53600,7 @@ async function propertiesRunsCommand(opts) {
|
|
|
53166
53600
|
}
|
|
53167
53601
|
function parseImportFile(path2) {
|
|
53168
53602
|
const ext = (0, import_node_path49.extname)(path2).toLowerCase();
|
|
53169
|
-
const raw = (0,
|
|
53603
|
+
const raw = (0, import_node_fs64.readFileSync)(path2, "utf-8");
|
|
53170
53604
|
if (ext === ".json") {
|
|
53171
53605
|
const parsed = JSON.parse(raw);
|
|
53172
53606
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -53338,6 +53772,45 @@ async function rulesShowCommand(ruleId) {
|
|
|
53338
53772
|
show(rule.match, "", 0);
|
|
53339
53773
|
console.log();
|
|
53340
53774
|
}
|
|
53775
|
+
async function rulesTestCommand(ruleId, line2, repeat = 1, json2 = false) {
|
|
53776
|
+
const config = loadConfig();
|
|
53777
|
+
const protectedList = [...config.remediation?.protected ?? [], ...config.remediation?.allowlist ?? []].map(String);
|
|
53778
|
+
const rules = loadAllRules();
|
|
53779
|
+
const rule = rules.find((r) => r.id === ruleId);
|
|
53780
|
+
const parsed = parsePostgresAuthFailure(line2);
|
|
53781
|
+
const event = postgresAuthEvent(line2, "dry-run", protectedList);
|
|
53782
|
+
const fired = [];
|
|
53783
|
+
if (rule && event) {
|
|
53784
|
+
const engine2 = new RuleEngine((d) => fired.push({ rule_id: d.rule_id, source_ip: d.source_ip, description: d.description }));
|
|
53785
|
+
engine2.loadRules([rule]);
|
|
53786
|
+
for (let i = 0; i < Math.max(1, repeat); i++) engine2.evaluate({ ...event, timestamp: /* @__PURE__ */ new Date() });
|
|
53787
|
+
}
|
|
53788
|
+
const wouldBan = fired.length > 0 && rule?.remediation?.action === "block" && !!fired[0].source_ip;
|
|
53789
|
+
const result = {
|
|
53790
|
+
rule: rule ? rule.id : null,
|
|
53791
|
+
parsed,
|
|
53792
|
+
event: event ? { module: event.module, severity: event.severity, source_ip: event.source_ip, message: event.message } : null,
|
|
53793
|
+
skipped_reason: !rule ? "unknown rule" : !parsed ? "not a recognised line" : !parsed.ip ? "no client address in the line" : !event ? "protected/private source, never banned" : void 0,
|
|
53794
|
+
repeat,
|
|
53795
|
+
threshold: rule?.threshold,
|
|
53796
|
+
fired: fired.length > 0,
|
|
53797
|
+
would_ban: wouldBan,
|
|
53798
|
+
detections: fired
|
|
53799
|
+
};
|
|
53800
|
+
if (json2) {
|
|
53801
|
+
console.log(JSON.stringify(result, null, 2));
|
|
53802
|
+
} else {
|
|
53803
|
+
banner();
|
|
53804
|
+
console.log(source_default.green.bold(` Dry run: ${ruleId}`));
|
|
53805
|
+
console.log(` Parsed: ${source_default.gray(parsed ? JSON.stringify(parsed) : "no match")}`);
|
|
53806
|
+
console.log(` Event: ${source_default.gray(event ? `${event.module} ${event.severity} ${event.source_ip} ${event.message}` : result.skipped_reason ?? "none")}`);
|
|
53807
|
+
console.log(` Fed: ${repeat}x (threshold ${rule?.threshold ?? "?"})`);
|
|
53808
|
+
console.log(` Fires: ${fired.length ? source_default.red("yes") : source_default.green("no")}`);
|
|
53809
|
+
console.log(` Would ban: ${wouldBan ? source_default.red(fired[0].source_ip) : source_default.green("no")}`);
|
|
53810
|
+
console.log(source_default.gray(" (dry run: nothing was blocked)\n"));
|
|
53811
|
+
}
|
|
53812
|
+
return fired.length > 0;
|
|
53813
|
+
}
|
|
53341
53814
|
async function rulesCommand(opts) {
|
|
53342
53815
|
const action = opts.action || "list";
|
|
53343
53816
|
switch (action) {
|
|
@@ -53353,21 +53826,29 @@ async function rulesCommand(opts) {
|
|
|
53353
53826
|
}
|
|
53354
53827
|
await rulesShowCommand(opts.id);
|
|
53355
53828
|
break;
|
|
53829
|
+
case "test":
|
|
53830
|
+
if (!opts.id || !opts.line) {
|
|
53831
|
+
console.log(source_default.red(' Usage: threatcrush rules test <rule-id> --line "<log line>" [--repeat N] [--json]\n'));
|
|
53832
|
+
process.exitCode = 1;
|
|
53833
|
+
return;
|
|
53834
|
+
}
|
|
53835
|
+
await rulesTestCommand(opts.id, opts.line, opts.repeat ?? 1, opts.json === true);
|
|
53836
|
+
break;
|
|
53356
53837
|
default:
|
|
53357
53838
|
console.log(source_default.yellow(` Unknown action: ${action}`));
|
|
53358
|
-
console.log(source_default.gray(" Available: list, show\n"));
|
|
53839
|
+
console.log(source_default.gray(" Available: list, show, test\n"));
|
|
53359
53840
|
break;
|
|
53360
53841
|
}
|
|
53361
53842
|
}
|
|
53362
53843
|
|
|
53363
53844
|
// src/commands/harden.ts
|
|
53364
|
-
var
|
|
53365
|
-
var
|
|
53845
|
+
var import_node_fs66 = require("fs");
|
|
53846
|
+
var import_node_child_process24 = require("child_process");
|
|
53366
53847
|
init_cli_config();
|
|
53367
53848
|
|
|
53368
53849
|
// src/commands/cis-report.ts
|
|
53369
53850
|
var import_node_os21 = require("os");
|
|
53370
|
-
var
|
|
53851
|
+
var import_node_fs65 = require("fs");
|
|
53371
53852
|
var CIS_UBUNTU_URL = "https://www.cisecurity.org/benchmark/ubuntu_linux";
|
|
53372
53853
|
var CIS_DEBIAN_URL = "https://www.cisecurity.org/benchmark/debian_linux";
|
|
53373
53854
|
var UBUNTU_2404_CIS_CONTROL_SOURCE = "https://github.com/ComplianceAsCode/content/blob/v0.1.78/controls/cis_ubuntu2404.yml";
|
|
@@ -53387,7 +53868,7 @@ var EDITIONS = {
|
|
|
53387
53868
|
function osRelease() {
|
|
53388
53869
|
let raw = "";
|
|
53389
53870
|
try {
|
|
53390
|
-
raw = (0,
|
|
53871
|
+
raw = (0, import_node_fs65.readFileSync)("/etc/os-release", "utf8");
|
|
53391
53872
|
} catch {
|
|
53392
53873
|
return {};
|
|
53393
53874
|
}
|
|
@@ -53567,20 +54048,20 @@ function writeCisReport(path2, format2, report) {
|
|
|
53567
54048
|
const markdown = renderCisMarkdown(report);
|
|
53568
54049
|
const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
|
|
53569
54050
|
` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
|
|
53570
|
-
(0,
|
|
54051
|
+
(0, import_node_fs65.writeFileSync)(path2, content);
|
|
53571
54052
|
}
|
|
53572
54053
|
|
|
53573
54054
|
// src/commands/harden.ts
|
|
53574
54055
|
function tryExec(cmd) {
|
|
53575
54056
|
try {
|
|
53576
|
-
return (0,
|
|
54057
|
+
return (0, import_node_child_process24.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
53577
54058
|
} catch {
|
|
53578
54059
|
return null;
|
|
53579
54060
|
}
|
|
53580
54061
|
}
|
|
53581
54062
|
function tryRead(path2) {
|
|
53582
54063
|
try {
|
|
53583
|
-
return (0,
|
|
54064
|
+
return (0, import_node_fs66.readFileSync)(path2, "utf-8");
|
|
53584
54065
|
} catch {
|
|
53585
54066
|
return null;
|
|
53586
54067
|
}
|
|
@@ -53694,8 +54175,8 @@ function checkSshWeakConfig() {
|
|
|
53694
54175
|
};
|
|
53695
54176
|
}
|
|
53696
54177
|
function checkAutoUpdates() {
|
|
53697
|
-
const unattended = (0,
|
|
53698
|
-
const dnfAuto = (0,
|
|
54178
|
+
const unattended = (0, import_node_fs66.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs66.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
54179
|
+
const dnfAuto = (0, import_node_fs66.existsSync)("/etc/dnf/automatic.conf");
|
|
53699
54180
|
if (unattended || dnfAuto) {
|
|
53700
54181
|
return {
|
|
53701
54182
|
key: "auto-updates",
|
|
@@ -53821,7 +54302,7 @@ function checkFail2ban() {
|
|
|
53821
54302
|
explanation: "fail2ban is installed and running."
|
|
53822
54303
|
};
|
|
53823
54304
|
}
|
|
53824
|
-
if ((0,
|
|
54305
|
+
if ((0, import_node_fs66.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
53825
54306
|
return {
|
|
53826
54307
|
key: checkKey,
|
|
53827
54308
|
status: "warn",
|
|
@@ -54041,9 +54522,9 @@ async function hardenCommand(opts) {
|
|
|
54041
54522
|
}
|
|
54042
54523
|
|
|
54043
54524
|
// src/core/patches/index.ts
|
|
54044
|
-
var
|
|
54525
|
+
var import_node_fs67 = require("fs");
|
|
54045
54526
|
var import_node_path50 = require("path");
|
|
54046
|
-
var
|
|
54527
|
+
var import_node_child_process25 = require("child_process");
|
|
54047
54528
|
var import_node_util5 = require("util");
|
|
54048
54529
|
|
|
54049
54530
|
// src/core/patches/dpkg-version.ts
|
|
@@ -54103,7 +54584,7 @@ var STALE_AFTER_MS = 2 * 864e5;
|
|
|
54103
54584
|
var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
|
|
54104
54585
|
var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
54105
54586
|
var defaultExec = async (file, args) => {
|
|
54106
|
-
const { stdout } = await (0, import_node_util5.promisify)(
|
|
54587
|
+
const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process25.execFile)(file, args, {
|
|
54107
54588
|
timeout: 12e4,
|
|
54108
54589
|
maxBuffer: 32 * 1024 * 1024,
|
|
54109
54590
|
env: { ...process.env, LC_ALL: "C" }
|
|
@@ -54202,9 +54683,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
|
|
|
54202
54683
|
function newestReleaseMtime(dir) {
|
|
54203
54684
|
try {
|
|
54204
54685
|
let newest = 0;
|
|
54205
|
-
for (const name of (0,
|
|
54686
|
+
for (const name of (0, import_node_fs67.readdirSync)(dir)) {
|
|
54206
54687
|
if (!/Release$/.test(name)) continue;
|
|
54207
|
-
newest = Math.max(newest, (0,
|
|
54688
|
+
newest = Math.max(newest, (0, import_node_fs67.statSync)((0, import_node_path50.join)(dir, name)).mtimeMs);
|
|
54208
54689
|
}
|
|
54209
54690
|
return newest > 0 ? new Date(newest) : null;
|
|
54210
54691
|
} catch {
|
|
@@ -54221,7 +54702,7 @@ async function checkPatches(opts = {}) {
|
|
|
54221
54702
|
let osText = opts.osRelease;
|
|
54222
54703
|
if (osText === void 0) {
|
|
54223
54704
|
try {
|
|
54224
|
-
osText = (0,
|
|
54705
|
+
osText = (0, import_node_fs67.readFileSync)("/etc/os-release", "utf-8");
|
|
54225
54706
|
} catch {
|
|
54226
54707
|
osText = "";
|
|
54227
54708
|
}
|
|
@@ -54447,27 +54928,27 @@ async function patchesCommand(opts) {
|
|
|
54447
54928
|
}
|
|
54448
54929
|
|
|
54449
54930
|
// src/commands/feeds.ts
|
|
54450
|
-
var
|
|
54931
|
+
var import_node_net20 = require("net");
|
|
54451
54932
|
var import_node_path52 = require("path");
|
|
54452
54933
|
init_paths();
|
|
54453
54934
|
|
|
54454
54935
|
// src/commands/feeds-resolver.ts
|
|
54455
|
-
var
|
|
54456
|
-
var
|
|
54936
|
+
var import_node_child_process26 = require("child_process");
|
|
54937
|
+
var import_node_fs68 = require("fs");
|
|
54457
54938
|
var import_node_path51 = require("path");
|
|
54458
54939
|
var realIO = {
|
|
54459
|
-
exists: (p) => (0,
|
|
54940
|
+
exists: (p) => (0, import_node_fs68.existsSync)(p),
|
|
54460
54941
|
read: (p) => {
|
|
54461
54942
|
try {
|
|
54462
|
-
return (0,
|
|
54943
|
+
return (0, import_node_fs68.readFileSync)(p, "utf-8");
|
|
54463
54944
|
} catch {
|
|
54464
54945
|
return null;
|
|
54465
54946
|
}
|
|
54466
54947
|
},
|
|
54467
|
-
write: (p, c) => (0,
|
|
54468
|
-
remove: (p) => (0,
|
|
54948
|
+
write: (p, c) => (0, import_node_fs68.writeFileSync)(p, c),
|
|
54949
|
+
remove: (p) => (0, import_node_fs68.rmSync)(p, { force: true }),
|
|
54469
54950
|
run: (cmd, args) => {
|
|
54470
|
-
const r = (0,
|
|
54951
|
+
const r = (0, import_node_child_process26.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
|
|
54471
54952
|
return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
54472
54953
|
}
|
|
54473
54954
|
};
|
|
@@ -54591,8 +55072,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
54591
55072
|
process.exitCode = 2;
|
|
54592
55073
|
return;
|
|
54593
55074
|
}
|
|
54594
|
-
const ipHit = (0,
|
|
54595
|
-
const domainHit = (0,
|
|
55075
|
+
const ipHit = (0, import_node_net20.isIP)(value) ? matchIp(value, set) : null;
|
|
55076
|
+
const domainHit = (0, import_node_net20.isIP)(value) ? null : matchDomain(value, set);
|
|
54596
55077
|
const listed = ipHit ?? domainHit?.indicator ?? null;
|
|
54597
55078
|
if (opts.json) {
|
|
54598
55079
|
console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
|
|
@@ -54620,8 +55101,8 @@ async function feedsCommand(action, value, opts) {
|
|
|
54620
55101
|
}
|
|
54621
55102
|
|
|
54622
55103
|
// src/commands/tor.ts
|
|
54623
|
-
var
|
|
54624
|
-
var
|
|
55104
|
+
var import_node_fs69 = require("fs");
|
|
55105
|
+
var import_node_net21 = require("net");
|
|
54625
55106
|
var import_node_path53 = require("path");
|
|
54626
55107
|
init_paths();
|
|
54627
55108
|
async function torCommand(action, value, opts) {
|
|
@@ -54631,10 +55112,10 @@ async function torCommand(action, value, opts) {
|
|
|
54631
55112
|
for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
|
|
54632
55113
|
const path2 = (0, import_node_path53.join)(dir, "tor-exits.txt");
|
|
54633
55114
|
try {
|
|
54634
|
-
if (!(0,
|
|
54635
|
-
exits = parseTorExitList((0,
|
|
55115
|
+
if (!(0, import_node_fs69.existsSync)(path2)) continue;
|
|
55116
|
+
exits = parseTorExitList((0, import_node_fs69.readFileSync)(path2, "utf-8"));
|
|
54636
55117
|
from = path2;
|
|
54637
|
-
updated = (0,
|
|
55118
|
+
updated = (0, import_node_fs69.statSync)(path2).mtime;
|
|
54638
55119
|
break;
|
|
54639
55120
|
} catch {
|
|
54640
55121
|
}
|
|
@@ -54653,7 +55134,7 @@ async function torCommand(action, value, opts) {
|
|
|
54653
55134
|
const remediation = loadConfig((0, import_node_path53.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
|
|
54654
55135
|
const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
|
|
54655
55136
|
if (action === "check") {
|
|
54656
|
-
if (!value || !(0,
|
|
55137
|
+
if (!value || !(0, import_node_net21.isIP)(value)) {
|
|
54657
55138
|
console.error("Usage: threatcrush tor check <ip>");
|
|
54658
55139
|
process.exitCode = 2;
|
|
54659
55140
|
return;
|
|
@@ -54682,13 +55163,13 @@ async function torCommand(action, value, opts) {
|
|
|
54682
55163
|
|
|
54683
55164
|
// src/commands/reputation.ts
|
|
54684
55165
|
var import_node_os22 = require("os");
|
|
54685
|
-
var
|
|
55166
|
+
var import_node_fs70 = require("fs");
|
|
54686
55167
|
var import_node_path54 = require("path");
|
|
54687
55168
|
var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
54688
55169
|
var CONFIG_PATH4 = (0, import_node_path54.join)((0, import_node_os22.homedir)(), ".threatcrush", "config.json");
|
|
54689
55170
|
function readConfig3() {
|
|
54690
55171
|
try {
|
|
54691
|
-
return JSON.parse((0,
|
|
55172
|
+
return JSON.parse((0, import_node_fs70.readFileSync)(CONFIG_PATH4, "utf-8"));
|
|
54692
55173
|
} catch {
|
|
54693
55174
|
return {};
|
|
54694
55175
|
}
|
|
@@ -54876,7 +55357,7 @@ async function reputationSubscribeCommand(opts) {
|
|
|
54876
55357
|
}
|
|
54877
55358
|
|
|
54878
55359
|
// src/commands/privileged.ts
|
|
54879
|
-
var
|
|
55360
|
+
var import_node_fs71 = require("fs");
|
|
54880
55361
|
init_paths();
|
|
54881
55362
|
var SEV2 = {
|
|
54882
55363
|
critical: source_default.red.bold,
|
|
@@ -54889,19 +55370,19 @@ async function privilegedCommand(opts) {
|
|
|
54889
55370
|
const snapshot = takeSnapshot({
|
|
54890
55371
|
readFile: (p) => {
|
|
54891
55372
|
try {
|
|
54892
|
-
return (0,
|
|
55373
|
+
return (0, import_node_fs71.readFileSync)(p, "utf-8");
|
|
54893
55374
|
} catch {
|
|
54894
55375
|
return null;
|
|
54895
55376
|
}
|
|
54896
55377
|
},
|
|
54897
55378
|
readDir: (p) => {
|
|
54898
55379
|
try {
|
|
54899
|
-
return (0,
|
|
55380
|
+
return (0, import_node_fs71.readdirSync)(p);
|
|
54900
55381
|
} catch {
|
|
54901
55382
|
return null;
|
|
54902
55383
|
}
|
|
54903
55384
|
},
|
|
54904
|
-
exists: (p) => (0,
|
|
55385
|
+
exists: (p) => (0, import_node_fs71.existsSync)(p)
|
|
54905
55386
|
});
|
|
54906
55387
|
let events = [];
|
|
54907
55388
|
let ledgerNote = "";
|
|
@@ -54943,12 +55424,12 @@ async function privilegedCommand(opts) {
|
|
|
54943
55424
|
}
|
|
54944
55425
|
|
|
54945
55426
|
// src/commands/integrity.ts
|
|
54946
|
-
var
|
|
55427
|
+
var import_node_fs72 = require("fs");
|
|
54947
55428
|
var import_node_path55 = require("path");
|
|
54948
55429
|
init_paths();
|
|
54949
55430
|
function readState2(path2) {
|
|
54950
55431
|
try {
|
|
54951
|
-
return JSON.parse((0,
|
|
55432
|
+
return JSON.parse((0, import_node_fs72.readFileSync)(path2, "utf8"));
|
|
54952
55433
|
} catch {
|
|
54953
55434
|
return null;
|
|
54954
55435
|
}
|
|
@@ -54969,7 +55450,7 @@ async function integrityCommand(action = "status", opts = {}) {
|
|
|
54969
55450
|
const config = loadConfig();
|
|
54970
55451
|
const settings = fileIntegritySettings(config.file_integrity);
|
|
54971
55452
|
const systemBaseline = (0, import_node_path55.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
|
|
54972
|
-
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0,
|
|
55453
|
+
const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs72.existsSync)(systemBaseline);
|
|
54973
55454
|
const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
|
|
54974
55455
|
const baselinePath = (0, import_node_path55.join)(stateDir, "file-integrity-baseline.json");
|
|
54975
55456
|
const observedPath = (0, import_node_path55.join)(stateDir, "file-integrity-observed.json");
|
|
@@ -55040,12 +55521,12 @@ async function integrityCommand(action = "status", opts = {}) {
|
|
|
55040
55521
|
}
|
|
55041
55522
|
|
|
55042
55523
|
// src/commands/edr.ts
|
|
55043
|
-
var
|
|
55524
|
+
var import_node_fs74 = require("fs");
|
|
55044
55525
|
init_paths();
|
|
55045
55526
|
|
|
55046
55527
|
// src/daemon/auditd/rules.ts
|
|
55047
|
-
var
|
|
55048
|
-
var
|
|
55528
|
+
var import_node_fs73 = require("fs");
|
|
55529
|
+
var import_node_child_process27 = require("child_process");
|
|
55049
55530
|
var import_node_path56 = require("path");
|
|
55050
55531
|
var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
|
|
55051
55532
|
var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
|
|
@@ -55054,10 +55535,10 @@ var LISTEN_KEY2 = "threatcrush_edr_listen";
|
|
|
55054
55535
|
function passwdByName() {
|
|
55055
55536
|
let raw = "";
|
|
55056
55537
|
try {
|
|
55057
|
-
raw = (0,
|
|
55538
|
+
raw = (0, import_node_child_process27.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
55058
55539
|
} catch {
|
|
55059
55540
|
try {
|
|
55060
|
-
raw = (0,
|
|
55541
|
+
raw = (0, import_node_fs73.readFileSync)("/etc/passwd", "utf8");
|
|
55061
55542
|
} catch {
|
|
55062
55543
|
return /* @__PURE__ */ new Map();
|
|
55063
55544
|
}
|
|
@@ -55076,8 +55557,8 @@ function existingExecutables(names) {
|
|
|
55076
55557
|
for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
|
|
55077
55558
|
const candidate = `${prefix}/${name}`;
|
|
55078
55559
|
try {
|
|
55079
|
-
if (!(0,
|
|
55080
|
-
paths.add((0,
|
|
55560
|
+
if (!(0, import_node_fs73.existsSync)(candidate) || !(0, import_node_fs73.statSync)(candidate).isFile()) continue;
|
|
55561
|
+
paths.add((0, import_node_fs73.realpathSync)(candidate));
|
|
55081
55562
|
} catch {
|
|
55082
55563
|
}
|
|
55083
55564
|
}
|
|
@@ -55088,7 +55569,7 @@ function existingDirectories(paths) {
|
|
|
55088
55569
|
return [...new Set(paths)].filter((path2) => {
|
|
55089
55570
|
if (!(0, import_node_path56.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
|
|
55090
55571
|
try {
|
|
55091
|
-
return (0,
|
|
55572
|
+
return (0, import_node_fs73.statSync)(path2).isDirectory();
|
|
55092
55573
|
} catch {
|
|
55093
55574
|
return false;
|
|
55094
55575
|
}
|
|
@@ -55149,8 +55630,8 @@ async function edrCommand(action = "status", opts = {}) {
|
|
|
55149
55630
|
}
|
|
55150
55631
|
let readable = false;
|
|
55151
55632
|
try {
|
|
55152
|
-
if ((0,
|
|
55153
|
-
readable = (0,
|
|
55633
|
+
if ((0, import_node_fs74.existsSync)(settings.auditLogPath)) (0, import_node_fs74.accessSync)(settings.auditLogPath, import_node_fs74.constants.R_OK);
|
|
55634
|
+
readable = (0, import_node_fs74.existsSync)(settings.auditLogPath);
|
|
55154
55635
|
} catch {
|
|
55155
55636
|
}
|
|
55156
55637
|
let events = [];
|
|
@@ -55336,7 +55817,7 @@ async function allowlistCommand(opts) {
|
|
|
55336
55817
|
}
|
|
55337
55818
|
|
|
55338
55819
|
// src/commands/abuse.ts
|
|
55339
|
-
var
|
|
55820
|
+
var import_node_fs75 = require("fs");
|
|
55340
55821
|
init_paths();
|
|
55341
55822
|
function rows(records) {
|
|
55342
55823
|
if (records.length === 0) {
|
|
@@ -55396,7 +55877,7 @@ function abuseRetractCommand(id, opts = {}) {
|
|
|
55396
55877
|
);
|
|
55397
55878
|
}
|
|
55398
55879
|
function abuseStatusCommand(opts = {}) {
|
|
55399
|
-
const config = loadConfig((0,
|
|
55880
|
+
const config = loadConfig((0, import_node_fs75.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
55400
55881
|
const cfg = resolveConfig(config.abuse_reporter);
|
|
55401
55882
|
const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
|
|
55402
55883
|
const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
|
|
@@ -55419,11 +55900,11 @@ function abuseStatusCommand(opts = {}) {
|
|
|
55419
55900
|
init_paths();
|
|
55420
55901
|
|
|
55421
55902
|
// src/upgrade.ts
|
|
55422
|
-
var
|
|
55903
|
+
var import_node_child_process28 = require("child_process");
|
|
55423
55904
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
55424
55905
|
var defaultRunner = (cmd) => {
|
|
55425
55906
|
try {
|
|
55426
|
-
return (0,
|
|
55907
|
+
return (0, import_node_child_process28.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
55427
55908
|
} catch {
|
|
55428
55909
|
return null;
|
|
55429
55910
|
}
|
|
@@ -55564,7 +56045,7 @@ function installUserAgent(target = globalThis) {
|
|
|
55564
56045
|
}
|
|
55565
56046
|
|
|
55566
56047
|
// src/core/cloud-upload.ts
|
|
55567
|
-
var
|
|
56048
|
+
var import_node_child_process29 = require("child_process");
|
|
55568
56049
|
var import_node_os23 = require("os");
|
|
55569
56050
|
var import_node_path57 = require("path");
|
|
55570
56051
|
init_cli_config();
|
|
@@ -55585,7 +56066,7 @@ function cleanUrl(raw) {
|
|
|
55585
56066
|
return raw.split(/[?#]/)[0];
|
|
55586
56067
|
}
|
|
55587
56068
|
}
|
|
55588
|
-
function repoTarget(path2, run2 = (args) => (0,
|
|
56069
|
+
function repoTarget(path2, run2 = (args) => (0, import_node_child_process29.execFileSync)("git", args, { cwd: (0, import_node_path57.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
|
|
55589
56070
|
const abs = (0, import_node_path57.resolve)(path2);
|
|
55590
56071
|
try {
|
|
55591
56072
|
const root = run2(["rev-parse", "--show-toplevel"]);
|
|
@@ -55961,22 +56442,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
|
55961
56442
|
var INSTALL_CONFIG_PATH = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
|
|
55962
56443
|
function detectPackageManager() {
|
|
55963
56444
|
try {
|
|
55964
|
-
const npmGlobal = (0,
|
|
56445
|
+
const npmGlobal = (0, import_node_child_process30.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
55965
56446
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
55966
56447
|
} catch {
|
|
55967
56448
|
}
|
|
55968
56449
|
try {
|
|
55969
|
-
(0,
|
|
56450
|
+
(0, import_node_child_process30.execSync)("pnpm --version", { stdio: "pipe" });
|
|
55970
56451
|
return "pnpm";
|
|
55971
56452
|
} catch {
|
|
55972
56453
|
}
|
|
55973
56454
|
try {
|
|
55974
|
-
(0,
|
|
56455
|
+
(0, import_node_child_process30.execSync)("yarn --version", { stdio: "pipe" });
|
|
55975
56456
|
return "yarn";
|
|
55976
56457
|
} catch {
|
|
55977
56458
|
}
|
|
55978
56459
|
try {
|
|
55979
|
-
(0,
|
|
56460
|
+
(0, import_node_child_process30.execSync)("bun --version", { stdio: "pipe" });
|
|
55980
56461
|
return "bun";
|
|
55981
56462
|
} catch {
|
|
55982
56463
|
}
|
|
@@ -55984,14 +56465,14 @@ function detectPackageManager() {
|
|
|
55984
56465
|
}
|
|
55985
56466
|
function readInstallConfig() {
|
|
55986
56467
|
try {
|
|
55987
|
-
return JSON.parse((0,
|
|
56468
|
+
return JSON.parse((0, import_node_fs76.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
55988
56469
|
} catch {
|
|
55989
56470
|
return {};
|
|
55990
56471
|
}
|
|
55991
56472
|
}
|
|
55992
56473
|
function packageLooksInstalled(pm, pkgName) {
|
|
55993
56474
|
try {
|
|
55994
|
-
const output = (0,
|
|
56475
|
+
const output = (0, import_node_child_process30.execSync)(globalListCommand(pm, pkgName), {
|
|
55995
56476
|
encoding: "utf-8",
|
|
55996
56477
|
stdio: ["pipe", "pipe", "pipe"]
|
|
55997
56478
|
});
|
|
@@ -56094,14 +56575,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
56094
56575
|
function restartSystemdDaemon() {
|
|
56095
56576
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
56096
56577
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
56097
|
-
if (!asRoot && (0,
|
|
56578
|
+
if (!asRoot && (0, import_node_child_process30.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
56098
56579
|
const [cmd, ...args] = argv;
|
|
56099
|
-
if ((0,
|
|
56100
|
-
return (0,
|
|
56580
|
+
if ((0, import_node_child_process30.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
56581
|
+
return (0, import_node_child_process30.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
56101
56582
|
}
|
|
56102
56583
|
function execQuiet(cmd) {
|
|
56103
56584
|
try {
|
|
56104
|
-
return (0,
|
|
56585
|
+
return (0, import_node_child_process30.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
56105
56586
|
} catch {
|
|
56106
56587
|
return null;
|
|
56107
56588
|
}
|
|
@@ -56342,8 +56823,8 @@ webhooks.command("retry <deliveryId>").description("Send one delivery again").ac
|
|
|
56342
56823
|
program2.command("status").description("Show daemon status and loaded modules").action(async () => {
|
|
56343
56824
|
await statusCommand();
|
|
56344
56825
|
});
|
|
56345
|
-
program2.command("rules").description("Manage detection rules").argument("[action]", "list | show", "list").argument("[id]", "Rule ID (for show)").action(async (action, id) => {
|
|
56346
|
-
await rulesCommand({ action, id });
|
|
56826
|
+
program2.command("rules").description("Manage detection rules").argument("[action]", "list | show | test", "list").argument("[id]", "Rule ID (for show / test)").option("--line <text>", "test: a log line to feed through the parser and rule (dry run, nothing is blocked)").option("--repeat <n>", "test: feed the line this many times", (v) => parseInt(v, 10), 1).option("--json", "test: machine-readable result").action(async (action, id, opts) => {
|
|
56827
|
+
await rulesCommand({ action, id, ...opts });
|
|
56347
56828
|
});
|
|
56348
56829
|
program2.command("harden").description("Run hardening security scan").option("--json", "Output results as JSON").option("--report <framework>", "Export evidence report (cis)").option("--format <format>", "Report format: md, pdf, or json").option("--output <path>", "Write the report to a file (PDF requires this)").option("--no-upload", "Do not upload findings to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
|
|
56349
56830
|
await hardenCommand(opts);
|
|
@@ -56415,7 +56896,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
56415
56896
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
56416
56897
|
console.log(LOGO2);
|
|
56417
56898
|
const logPath2 = PATHS.logFile;
|
|
56418
|
-
if (!(0,
|
|
56899
|
+
if (!(0, import_node_fs76.existsSync)(logPath2)) {
|
|
56419
56900
|
console.log(source_default.yellow(` No log file found at ${logPath2}`));
|
|
56420
56901
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
56421
56902
|
return;
|
|
@@ -56423,7 +56904,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
56423
56904
|
console.log(source_default.green(` Tailing ${logPath2}...
|
|
56424
56905
|
`));
|
|
56425
56906
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
56426
|
-
(0,
|
|
56907
|
+
(0, import_node_child_process30.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
|
|
56427
56908
|
});
|
|
56428
56909
|
program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
|
|
56429
56910
|
console.log(LOGO2);
|
|
@@ -56435,7 +56916,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
56435
56916
|
for (const cmd of commands2) {
|
|
56436
56917
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
56437
56918
|
`));
|
|
56438
|
-
(0,
|
|
56919
|
+
(0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
|
|
56439
56920
|
}
|
|
56440
56921
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
56441
56922
|
await reportIfStillStale();
|
|
@@ -56460,7 +56941,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
56460
56941
|
for (const cmd of commands) {
|
|
56461
56942
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
56462
56943
|
`));
|
|
56463
|
-
(0,
|
|
56944
|
+
(0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
|
|
56464
56945
|
}
|
|
56465
56946
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
56466
56947
|
if (installMode === "desktop") {
|
|
@@ -56511,7 +56992,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
56511
56992
|
for (const cmd of commands) {
|
|
56512
56993
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
56513
56994
|
`));
|
|
56514
|
-
(0,
|
|
56995
|
+
(0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
|
|
56515
56996
|
}
|
|
56516
56997
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
56517
56998
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -56591,7 +57072,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
56591
57072
|
const configPath = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "config.json");
|
|
56592
57073
|
let email = "";
|
|
56593
57074
|
try {
|
|
56594
|
-
const config = JSON.parse((0,
|
|
57075
|
+
const config = JSON.parse((0, import_node_fs76.readFileSync)(configPath, "utf-8"));
|
|
56595
57076
|
email = config.email || "";
|
|
56596
57077
|
} catch {
|
|
56597
57078
|
}
|
|
@@ -56609,8 +57090,8 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
56609
57090
|
}
|
|
56610
57091
|
try {
|
|
56611
57092
|
const dir = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush");
|
|
56612
|
-
if (!(0,
|
|
56613
|
-
(0,
|
|
57093
|
+
if (!(0, import_node_fs76.existsSync)(dir)) (0, import_node_fs76.mkdirSync)(dir, { recursive: true });
|
|
57094
|
+
(0, import_node_fs76.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
56614
57095
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
56615
57096
|
} catch {
|
|
56616
57097
|
}
|