@profullstack/threatcrush 0.13.62 → 0.13.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/daemon.js +68 -34
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +75 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30409,37 +30409,63 @@ var DEFAULT_CONFIG = {
|
|
|
30409
30409
|
config_dir: DEFAULT_CONFDIR
|
|
30410
30410
|
}
|
|
30411
30411
|
};
|
|
30412
|
-
function loadConfig(configPath) {
|
|
30412
|
+
function loadConfig(configPath, onError) {
|
|
30413
30413
|
const path2 = configPath || DEFAULT_CONFIG_PATH;
|
|
30414
30414
|
if (!(0, import_node_fs5.existsSync)(path2)) {
|
|
30415
30415
|
return { ...DEFAULT_CONFIG };
|
|
30416
30416
|
}
|
|
30417
30417
|
try {
|
|
30418
|
-
|
|
30419
|
-
|
|
30420
|
-
|
|
30421
|
-
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
30422
|
-
api: { ...DEFAULT_CONFIG.api, ...parsed.api },
|
|
30423
|
-
alerts: parsed.alerts || {},
|
|
30424
|
-
modules: { ...DEFAULT_CONFIG.modules, ...parsed.modules },
|
|
30425
|
-
remediation: parsed.remediation,
|
|
30426
|
-
detection: parsed.detection,
|
|
30427
|
-
cloud: parsed.cloud,
|
|
30428
|
-
watchdog: parsed.watchdog,
|
|
30429
|
-
update: parsed.update,
|
|
30430
|
-
threat_feeds: parsed.threat_feeds,
|
|
30431
|
-
privileged: parsed.privileged,
|
|
30432
|
-
lightning: parsed.lightning,
|
|
30433
|
-
storage: parsed.storage,
|
|
30434
|
-
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
30435
|
-
// the JS-friendly name the rest of the daemon reads.
|
|
30436
|
-
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
30437
|
-
license: parsed.license
|
|
30438
|
-
};
|
|
30439
|
-
} catch {
|
|
30418
|
+
return parseConfigText((0, import_node_fs5.readFileSync)(path2, "utf-8"));
|
|
30419
|
+
} catch (err) {
|
|
30420
|
+
onError?.(err);
|
|
30440
30421
|
return { ...DEFAULT_CONFIG };
|
|
30441
30422
|
}
|
|
30442
30423
|
}
|
|
30424
|
+
function parseConfigText(raw) {
|
|
30425
|
+
const parsed = import_toml.default.parse(raw);
|
|
30426
|
+
return {
|
|
30427
|
+
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
30428
|
+
api: { ...DEFAULT_CONFIG.api, ...parsed.api },
|
|
30429
|
+
alerts: parsed.alerts || {},
|
|
30430
|
+
modules: { ...DEFAULT_CONFIG.modules, ...parsed.modules },
|
|
30431
|
+
remediation: parsed.remediation,
|
|
30432
|
+
detection: parsed.detection,
|
|
30433
|
+
cloud: parsed.cloud,
|
|
30434
|
+
watchdog: parsed.watchdog,
|
|
30435
|
+
update: parsed.update,
|
|
30436
|
+
threat_feeds: parsed.threat_feeds,
|
|
30437
|
+
privileged: parsed.privileged,
|
|
30438
|
+
lightning: parsed.lightning,
|
|
30439
|
+
storage: parsed.storage,
|
|
30440
|
+
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
30441
|
+
// the JS-friendly name the rest of the daemon reads.
|
|
30442
|
+
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
30443
|
+
license: parsed.license
|
|
30444
|
+
};
|
|
30445
|
+
}
|
|
30446
|
+
function loadDaemonConfig(configPath, lastGoodPath) {
|
|
30447
|
+
if (!(0, import_node_fs5.existsSync)(configPath)) return { config: { ...DEFAULT_CONFIG }, usedLastGood: false };
|
|
30448
|
+
let raw = "";
|
|
30449
|
+
try {
|
|
30450
|
+
raw = (0, import_node_fs5.readFileSync)(configPath, "utf-8");
|
|
30451
|
+
const config = parseConfigText(raw);
|
|
30452
|
+
try {
|
|
30453
|
+
(0, import_node_fs5.mkdirSync)((0, import_node_path4.dirname)(lastGoodPath), { recursive: true });
|
|
30454
|
+
(0, import_node_fs5.writeFileSync)(lastGoodPath, raw, { mode: 384 });
|
|
30455
|
+
} catch {
|
|
30456
|
+
}
|
|
30457
|
+
return { config, usedLastGood: false };
|
|
30458
|
+
} catch (err) {
|
|
30459
|
+
const error2 = `${configPath} is not valid TOML: ${err.message.split("\n")[0]}`;
|
|
30460
|
+
try {
|
|
30461
|
+
if ((0, import_node_fs5.existsSync)(lastGoodPath)) {
|
|
30462
|
+
return { config: parseConfigText((0, import_node_fs5.readFileSync)(lastGoodPath, "utf-8")), error: error2, usedLastGood: true };
|
|
30463
|
+
}
|
|
30464
|
+
} catch {
|
|
30465
|
+
}
|
|
30466
|
+
return { config: { ...DEFAULT_CONFIG }, error: error2, usedLastGood: false };
|
|
30467
|
+
}
|
|
30468
|
+
}
|
|
30443
30469
|
function loadModuleConfigs(confDir) {
|
|
30444
30470
|
const dir = confDir || DEFAULT_CONFDIR;
|
|
30445
30471
|
const configs = /* @__PURE__ */ new Map();
|
|
@@ -40029,12 +40055,19 @@ async function modulesCommand(opts) {
|
|
|
40029
40055
|
}
|
|
40030
40056
|
|
|
40031
40057
|
// src/commands/pentest.ts
|
|
40058
|
+
function decodeMarkupForXssDetection(html) {
|
|
40059
|
+
return html.replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'|'/gi, "'").replace(/&#x([0-9a-f]+);?/gi, (_, hex3) => String.fromCodePoint(parseInt(hex3, 16))).replace(/&#([0-9]+);?/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10)));
|
|
40060
|
+
}
|
|
40061
|
+
function containsXssPayload(html) {
|
|
40062
|
+
const candidate = decodeMarkupForXssDetection(html);
|
|
40063
|
+
return /<script\b[^>]*>[\s\S]*?\b(?:alert|confirm|prompt)\s*\(/i.test(candidate) || /<[a-z][^>]*\bon(?:error|load|mouseover|focus)\s*=\s*[^>]*(?:alert|confirm|prompt)\s*\(/i.test(candidate);
|
|
40064
|
+
}
|
|
40032
40065
|
var PENTEST_CHECKS = [
|
|
40033
40066
|
{
|
|
40034
|
-
name: "XSS
|
|
40035
|
-
test: (html) =>
|
|
40036
|
-
severity: "
|
|
40037
|
-
message: "
|
|
40067
|
+
name: "XSS Payload in Response",
|
|
40068
|
+
test: (html) => containsXssPayload(html),
|
|
40069
|
+
severity: "high",
|
|
40070
|
+
message: "Response contains an executable-looking XSS payload (raw or HTML-escaped)"
|
|
40038
40071
|
},
|
|
40039
40072
|
{
|
|
40040
40073
|
name: "Open Redirect",
|
|
@@ -48427,7 +48460,11 @@ async function runDaemon() {
|
|
|
48427
48460
|
} catch (err) {
|
|
48428
48461
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
48429
48462
|
}
|
|
48430
|
-
const
|
|
48463
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path36.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
48464
|
+
const config = loaded.config;
|
|
48465
|
+
if (loaded.error) {
|
|
48466
|
+
logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
|
|
48467
|
+
}
|
|
48431
48468
|
configureAttackDetection(config.detection);
|
|
48432
48469
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
48433
48470
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -48528,6 +48565,16 @@ async function runDaemon() {
|
|
|
48528
48565
|
lightningWatch.start();
|
|
48529
48566
|
let cloudSyncRef = null;
|
|
48530
48567
|
new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
|
|
48568
|
+
if (loaded.error) {
|
|
48569
|
+
setTimeout(() => bus.publish({
|
|
48570
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
48571
|
+
module: "daemon",
|
|
48572
|
+
category: "system",
|
|
48573
|
+
severity: "critical",
|
|
48574
|
+
message: `threatcrushd.conf does not parse; ${loaded.usedLastGood ? "running on the last good copy" : "running on defaults with NO protected list"}: ${loaded.error}`.slice(0, 500),
|
|
48575
|
+
details: { rule_id: "daemon-config-invalid", used_last_good: loaded.usedLastGood }
|
|
48576
|
+
}), 15e3).unref?.();
|
|
48577
|
+
}
|
|
48531
48578
|
const runsWorker = new RunsWorker(bus, {
|
|
48532
48579
|
enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
|
|
48533
48580
|
scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
|