@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/daemon.js
CHANGED
|
@@ -11053,7 +11053,6 @@ var DnsMonitor = class {
|
|
|
11053
11053
|
var import_node_fs13 = require("fs");
|
|
11054
11054
|
var import_node_path6 = require("path");
|
|
11055
11055
|
var import_toml = __toESM(require_toml());
|
|
11056
|
-
var DEFAULT_CONFIG_PATH = "/etc/threatcrush/threatcrushd.conf";
|
|
11057
11056
|
var DEFAULT_CONFDIR = "/etc/threatcrush/threatcrushd.conf.d";
|
|
11058
11057
|
var DEFAULT_CONFIG = {
|
|
11059
11058
|
daemon: {
|
|
@@ -11075,35 +11074,49 @@ var DEFAULT_CONFIG = {
|
|
|
11075
11074
|
config_dir: DEFAULT_CONFDIR
|
|
11076
11075
|
}
|
|
11077
11076
|
};
|
|
11078
|
-
function
|
|
11079
|
-
const
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11077
|
+
function parseConfigText(raw) {
|
|
11078
|
+
const parsed = import_toml.default.parse(raw);
|
|
11079
|
+
return {
|
|
11080
|
+
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
11081
|
+
api: { ...DEFAULT_CONFIG.api, ...parsed.api },
|
|
11082
|
+
alerts: parsed.alerts || {},
|
|
11083
|
+
modules: { ...DEFAULT_CONFIG.modules, ...parsed.modules },
|
|
11084
|
+
remediation: parsed.remediation,
|
|
11085
|
+
detection: parsed.detection,
|
|
11086
|
+
cloud: parsed.cloud,
|
|
11087
|
+
watchdog: parsed.watchdog,
|
|
11088
|
+
update: parsed.update,
|
|
11089
|
+
threat_feeds: parsed.threat_feeds,
|
|
11090
|
+
privileged: parsed.privileged,
|
|
11091
|
+
lightning: parsed.lightning,
|
|
11092
|
+
storage: parsed.storage,
|
|
11093
|
+
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
11094
|
+
// the JS-friendly name the rest of the daemon reads.
|
|
11095
|
+
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
11096
|
+
license: parsed.license
|
|
11097
|
+
};
|
|
11098
|
+
}
|
|
11099
|
+
function loadDaemonConfig(configPath, lastGoodPath) {
|
|
11100
|
+
if (!(0, import_node_fs13.existsSync)(configPath)) return { config: { ...DEFAULT_CONFIG }, usedLastGood: false };
|
|
11101
|
+
let raw = "";
|
|
11083
11102
|
try {
|
|
11084
|
-
|
|
11085
|
-
const
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
// the JS-friendly name the rest of the daemon reads.
|
|
11102
|
-
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
11103
|
-
license: parsed.license
|
|
11104
|
-
};
|
|
11105
|
-
} catch {
|
|
11106
|
-
return { ...DEFAULT_CONFIG };
|
|
11103
|
+
raw = (0, import_node_fs13.readFileSync)(configPath, "utf-8");
|
|
11104
|
+
const config = parseConfigText(raw);
|
|
11105
|
+
try {
|
|
11106
|
+
(0, import_node_fs13.mkdirSync)((0, import_node_path6.dirname)(lastGoodPath), { recursive: true });
|
|
11107
|
+
(0, import_node_fs13.writeFileSync)(lastGoodPath, raw, { mode: 384 });
|
|
11108
|
+
} catch {
|
|
11109
|
+
}
|
|
11110
|
+
return { config, usedLastGood: false };
|
|
11111
|
+
} catch (err) {
|
|
11112
|
+
const error = `${configPath} is not valid TOML: ${err.message.split("\n")[0]}`;
|
|
11113
|
+
try {
|
|
11114
|
+
if ((0, import_node_fs13.existsSync)(lastGoodPath)) {
|
|
11115
|
+
return { config: parseConfigText((0, import_node_fs13.readFileSync)(lastGoodPath, "utf-8")), error, usedLastGood: true };
|
|
11116
|
+
}
|
|
11117
|
+
} catch {
|
|
11118
|
+
}
|
|
11119
|
+
return { config: { ...DEFAULT_CONFIG }, error, usedLastGood: false };
|
|
11107
11120
|
}
|
|
11108
11121
|
}
|
|
11109
11122
|
function loadModuleConfigs(confDir) {
|
|
@@ -16004,12 +16017,19 @@ async function runScan(targetPath) {
|
|
|
16004
16017
|
}
|
|
16005
16018
|
|
|
16006
16019
|
// src/commands/pentest.ts
|
|
16020
|
+
function decodeMarkupForXssDetection(html) {
|
|
16021
|
+
return html.replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'|'/gi, "'").replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16))).replace(/&#([0-9]+);?/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10)));
|
|
16022
|
+
}
|
|
16023
|
+
function containsXssPayload(html) {
|
|
16024
|
+
const candidate = decodeMarkupForXssDetection(html);
|
|
16025
|
+
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);
|
|
16026
|
+
}
|
|
16007
16027
|
var PENTEST_CHECKS = [
|
|
16008
16028
|
{
|
|
16009
|
-
name: "XSS
|
|
16010
|
-
test: (html) =>
|
|
16011
|
-
severity: "
|
|
16012
|
-
message: "
|
|
16029
|
+
name: "XSS Payload in Response",
|
|
16030
|
+
test: (html) => containsXssPayload(html),
|
|
16031
|
+
severity: "high",
|
|
16032
|
+
message: "Response contains an executable-looking XSS payload (raw or HTML-escaped)"
|
|
16013
16033
|
},
|
|
16014
16034
|
{
|
|
16015
16035
|
name: "Open Redirect",
|
|
@@ -20978,7 +20998,11 @@ async function runDaemon() {
|
|
|
20978
20998
|
} catch (err) {
|
|
20979
20999
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
20980
21000
|
}
|
|
20981
|
-
const
|
|
21001
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path26.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
21002
|
+
const config = loaded.config;
|
|
21003
|
+
if (loaded.error) {
|
|
21004
|
+
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)"}`);
|
|
21005
|
+
}
|
|
20982
21006
|
configureAttackDetection(config.detection);
|
|
20983
21007
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
20984
21008
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -21079,6 +21103,16 @@ async function runDaemon() {
|
|
|
21079
21103
|
lightningWatch.start();
|
|
21080
21104
|
let cloudSyncRef = null;
|
|
21081
21105
|
new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
|
|
21106
|
+
if (loaded.error) {
|
|
21107
|
+
setTimeout(() => bus.publish({
|
|
21108
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
21109
|
+
module: "daemon",
|
|
21110
|
+
category: "system",
|
|
21111
|
+
severity: "critical",
|
|
21112
|
+
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),
|
|
21113
|
+
details: { rule_id: "daemon-config-invalid", used_last_good: loaded.usedLastGood }
|
|
21114
|
+
}), 15e3).unref?.();
|
|
21115
|
+
}
|
|
21082
21116
|
const runsWorker = new RunsWorker(bus, {
|
|
21083
21117
|
enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
|
|
21084
21118
|
scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
|