@profullstack/threatcrush 0.13.19 → 0.13.21
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 +293 -48
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +1001 -414
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -598,8 +598,8 @@ var require_help = __commonJS({
|
|
|
598
598
|
* @param {string} str
|
|
599
599
|
* @returns {number}
|
|
600
600
|
*/
|
|
601
|
-
displayWidth(
|
|
602
|
-
return stripColor(
|
|
601
|
+
displayWidth(str3) {
|
|
602
|
+
return stripColor(str3).length;
|
|
603
603
|
}
|
|
604
604
|
/**
|
|
605
605
|
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
@@ -607,11 +607,11 @@ var require_help = __commonJS({
|
|
|
607
607
|
* @param {string} str
|
|
608
608
|
* @returns {string}
|
|
609
609
|
*/
|
|
610
|
-
styleTitle(
|
|
611
|
-
return
|
|
610
|
+
styleTitle(str3) {
|
|
611
|
+
return str3;
|
|
612
612
|
}
|
|
613
|
-
styleUsage(
|
|
614
|
-
return
|
|
613
|
+
styleUsage(str3) {
|
|
614
|
+
return str3.split(" ").map((word) => {
|
|
615
615
|
if (word === "[options]") return this.styleOptionText(word);
|
|
616
616
|
if (word === "[command]") return this.styleSubcommandText(word);
|
|
617
617
|
if (word[0] === "[" || word[0] === "<")
|
|
@@ -619,46 +619,46 @@ var require_help = __commonJS({
|
|
|
619
619
|
return this.styleCommandText(word);
|
|
620
620
|
}).join(" ");
|
|
621
621
|
}
|
|
622
|
-
styleCommandDescription(
|
|
623
|
-
return this.styleDescriptionText(
|
|
622
|
+
styleCommandDescription(str3) {
|
|
623
|
+
return this.styleDescriptionText(str3);
|
|
624
624
|
}
|
|
625
|
-
styleOptionDescription(
|
|
626
|
-
return this.styleDescriptionText(
|
|
625
|
+
styleOptionDescription(str3) {
|
|
626
|
+
return this.styleDescriptionText(str3);
|
|
627
627
|
}
|
|
628
|
-
styleSubcommandDescription(
|
|
629
|
-
return this.styleDescriptionText(
|
|
628
|
+
styleSubcommandDescription(str3) {
|
|
629
|
+
return this.styleDescriptionText(str3);
|
|
630
630
|
}
|
|
631
|
-
styleArgumentDescription(
|
|
632
|
-
return this.styleDescriptionText(
|
|
631
|
+
styleArgumentDescription(str3) {
|
|
632
|
+
return this.styleDescriptionText(str3);
|
|
633
633
|
}
|
|
634
|
-
styleDescriptionText(
|
|
635
|
-
return
|
|
634
|
+
styleDescriptionText(str3) {
|
|
635
|
+
return str3;
|
|
636
636
|
}
|
|
637
|
-
styleOptionTerm(
|
|
638
|
-
return this.styleOptionText(
|
|
637
|
+
styleOptionTerm(str3) {
|
|
638
|
+
return this.styleOptionText(str3);
|
|
639
639
|
}
|
|
640
|
-
styleSubcommandTerm(
|
|
641
|
-
return
|
|
640
|
+
styleSubcommandTerm(str3) {
|
|
641
|
+
return str3.split(" ").map((word) => {
|
|
642
642
|
if (word === "[options]") return this.styleOptionText(word);
|
|
643
643
|
if (word[0] === "[" || word[0] === "<")
|
|
644
644
|
return this.styleArgumentText(word);
|
|
645
645
|
return this.styleSubcommandText(word);
|
|
646
646
|
}).join(" ");
|
|
647
647
|
}
|
|
648
|
-
styleArgumentTerm(
|
|
649
|
-
return this.styleArgumentText(
|
|
648
|
+
styleArgumentTerm(str3) {
|
|
649
|
+
return this.styleArgumentText(str3);
|
|
650
650
|
}
|
|
651
|
-
styleOptionText(
|
|
652
|
-
return
|
|
651
|
+
styleOptionText(str3) {
|
|
652
|
+
return str3;
|
|
653
653
|
}
|
|
654
|
-
styleArgumentText(
|
|
655
|
-
return
|
|
654
|
+
styleArgumentText(str3) {
|
|
655
|
+
return str3;
|
|
656
656
|
}
|
|
657
|
-
styleSubcommandText(
|
|
658
|
-
return
|
|
657
|
+
styleSubcommandText(str3) {
|
|
658
|
+
return str3;
|
|
659
659
|
}
|
|
660
|
-
styleCommandText(
|
|
661
|
-
return
|
|
660
|
+
styleCommandText(str3) {
|
|
661
|
+
return str3;
|
|
662
662
|
}
|
|
663
663
|
/**
|
|
664
664
|
* Calculate the pad width from the maximum term length.
|
|
@@ -681,8 +681,8 @@ var require_help = __commonJS({
|
|
|
681
681
|
* @param {string} str
|
|
682
682
|
* @returns {boolean}
|
|
683
683
|
*/
|
|
684
|
-
preformatted(
|
|
685
|
-
return /\n[^\S\r\n]/.test(
|
|
684
|
+
preformatted(str3) {
|
|
685
|
+
return /\n[^\S\r\n]/.test(str3);
|
|
686
686
|
}
|
|
687
687
|
/**
|
|
688
688
|
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
@@ -728,9 +728,9 @@ ${itemIndentStr}`);
|
|
|
728
728
|
* @param {number} width
|
|
729
729
|
* @returns {string}
|
|
730
730
|
*/
|
|
731
|
-
boxWrap(
|
|
732
|
-
if (width < this.minWidthToWrap) return
|
|
733
|
-
const rawLines =
|
|
731
|
+
boxWrap(str3, width) {
|
|
732
|
+
if (width < this.minWidthToWrap) return str3;
|
|
733
|
+
const rawLines = str3.split(/\r\n|\n/);
|
|
734
734
|
const chunkPattern = /[\s]*[^\s]+/g;
|
|
735
735
|
const wrappedLines = [];
|
|
736
736
|
rawLines.forEach((line) => {
|
|
@@ -758,9 +758,9 @@ ${itemIndentStr}`);
|
|
|
758
758
|
return wrappedLines.join("\n");
|
|
759
759
|
}
|
|
760
760
|
};
|
|
761
|
-
function stripColor(
|
|
761
|
+
function stripColor(str3) {
|
|
762
762
|
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
763
|
-
return
|
|
763
|
+
return str3.replace(sgrPattern, "");
|
|
764
764
|
}
|
|
765
765
|
exports2.Help = Help2;
|
|
766
766
|
exports2.stripColor = stripColor;
|
|
@@ -1020,9 +1020,9 @@ var require_option = __commonJS({
|
|
|
1020
1020
|
return option.negate === (negativeValue === value);
|
|
1021
1021
|
}
|
|
1022
1022
|
};
|
|
1023
|
-
function camelcase(
|
|
1024
|
-
return
|
|
1025
|
-
return
|
|
1023
|
+
function camelcase(str3) {
|
|
1024
|
+
return str3.split("-").reduce((str4, word) => {
|
|
1025
|
+
return str4 + word[0].toUpperCase() + word.slice(1);
|
|
1026
1026
|
});
|
|
1027
1027
|
}
|
|
1028
1028
|
function splitOptionFlags(flags) {
|
|
@@ -1205,14 +1205,14 @@ var require_command = __commonJS({
|
|
|
1205
1205
|
this._showSuggestionAfterError = true;
|
|
1206
1206
|
this._savedState = null;
|
|
1207
1207
|
this._outputConfiguration = {
|
|
1208
|
-
writeOut: (
|
|
1209
|
-
writeErr: (
|
|
1210
|
-
outputError: (
|
|
1208
|
+
writeOut: (str3) => process10.stdout.write(str3),
|
|
1209
|
+
writeErr: (str3) => process10.stderr.write(str3),
|
|
1210
|
+
outputError: (str3, write) => write(str3),
|
|
1211
1211
|
getOutHelpWidth: () => process10.stdout.isTTY ? process10.stdout.columns : void 0,
|
|
1212
1212
|
getErrHelpWidth: () => process10.stderr.isTTY ? process10.stderr.columns : void 0,
|
|
1213
1213
|
getOutHasColors: () => useColor() ?? (process10.stdout.isTTY && process10.stdout.hasColors?.()),
|
|
1214
1214
|
getErrHasColors: () => useColor() ?? (process10.stderr.isTTY && process10.stderr.hasColors?.()),
|
|
1215
|
-
stripColor: (
|
|
1215
|
+
stripColor: (str3) => stripColor(str3)
|
|
1216
1216
|
};
|
|
1217
1217
|
this._hidden = false;
|
|
1218
1218
|
this._helpOption = void 0;
|
|
@@ -2918,18 +2918,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2918
2918
|
* @param {string} [description]
|
|
2919
2919
|
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
2920
2920
|
*/
|
|
2921
|
-
version(
|
|
2922
|
-
if (
|
|
2923
|
-
this._version =
|
|
2921
|
+
version(str3, flags, description) {
|
|
2922
|
+
if (str3 === void 0) return this._version;
|
|
2923
|
+
this._version = str3;
|
|
2924
2924
|
flags = flags || "-V, --version";
|
|
2925
2925
|
description = description || "output the version number";
|
|
2926
2926
|
const versionOption = this.createOption(flags, description);
|
|
2927
2927
|
this._versionOptionName = versionOption.attributeName();
|
|
2928
2928
|
this._registerOption(versionOption);
|
|
2929
2929
|
this.on("option:" + versionOption.name(), () => {
|
|
2930
|
-
this._outputConfiguration.writeOut(`${
|
|
2930
|
+
this._outputConfiguration.writeOut(`${str3}
|
|
2931
2931
|
`);
|
|
2932
|
-
this._exit(0, "commander.version",
|
|
2932
|
+
this._exit(0, "commander.version", str3);
|
|
2933
2933
|
});
|
|
2934
2934
|
return this;
|
|
2935
2935
|
}
|
|
@@ -2940,10 +2940,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2940
2940
|
* @param {object} [argsDescription]
|
|
2941
2941
|
* @return {(string|Command)}
|
|
2942
2942
|
*/
|
|
2943
|
-
description(
|
|
2944
|
-
if (
|
|
2943
|
+
description(str3, argsDescription) {
|
|
2944
|
+
if (str3 === void 0 && argsDescription === void 0)
|
|
2945
2945
|
return this._description;
|
|
2946
|
-
this._description =
|
|
2946
|
+
this._description = str3;
|
|
2947
2947
|
if (argsDescription) {
|
|
2948
2948
|
this._argsDescription = argsDescription;
|
|
2949
2949
|
}
|
|
@@ -2955,9 +2955,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2955
2955
|
* @param {string} [str]
|
|
2956
2956
|
* @return {(string|Command)}
|
|
2957
2957
|
*/
|
|
2958
|
-
summary(
|
|
2959
|
-
if (
|
|
2960
|
-
this._summary =
|
|
2958
|
+
summary(str3) {
|
|
2959
|
+
if (str3 === void 0) return this._summary;
|
|
2960
|
+
this._summary = str3;
|
|
2961
2961
|
return this;
|
|
2962
2962
|
}
|
|
2963
2963
|
/**
|
|
@@ -3005,8 +3005,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3005
3005
|
* @param {string} [str]
|
|
3006
3006
|
* @return {(string|Command)}
|
|
3007
3007
|
*/
|
|
3008
|
-
usage(
|
|
3009
|
-
if (
|
|
3008
|
+
usage(str3) {
|
|
3009
|
+
if (str3 === void 0) {
|
|
3010
3010
|
if (this._usage) return this._usage;
|
|
3011
3011
|
const args = this.registeredArguments.map((arg) => {
|
|
3012
3012
|
return humanReadableArgName(arg);
|
|
@@ -3017,7 +3017,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3017
3017
|
this.registeredArguments.length ? args : []
|
|
3018
3018
|
).join(" ");
|
|
3019
3019
|
}
|
|
3020
|
-
this._usage =
|
|
3020
|
+
this._usage = str3;
|
|
3021
3021
|
return this;
|
|
3022
3022
|
}
|
|
3023
3023
|
/**
|
|
@@ -3026,9 +3026,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3026
3026
|
* @param {string} [str]
|
|
3027
3027
|
* @return {(string|Command)}
|
|
3028
3028
|
*/
|
|
3029
|
-
name(
|
|
3030
|
-
if (
|
|
3031
|
-
this._name =
|
|
3029
|
+
name(str3) {
|
|
3030
|
+
if (str3 === void 0) return this._name;
|
|
3031
|
+
this._name = str3;
|
|
3032
3032
|
return this;
|
|
3033
3033
|
}
|
|
3034
3034
|
/**
|
|
@@ -3099,17 +3099,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3099
3099
|
let hasColors;
|
|
3100
3100
|
let helpWidth;
|
|
3101
3101
|
if (error) {
|
|
3102
|
-
baseWrite = (
|
|
3102
|
+
baseWrite = (str3) => this._outputConfiguration.writeErr(str3);
|
|
3103
3103
|
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3104
3104
|
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
3105
3105
|
} else {
|
|
3106
|
-
baseWrite = (
|
|
3106
|
+
baseWrite = (str3) => this._outputConfiguration.writeOut(str3);
|
|
3107
3107
|
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3108
3108
|
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
3109
3109
|
}
|
|
3110
|
-
const write = (
|
|
3111
|
-
if (!hasColors)
|
|
3112
|
-
return baseWrite(
|
|
3110
|
+
const write = (str3) => {
|
|
3111
|
+
if (!hasColors) str3 = this._outputConfiguration.stripColor(str3);
|
|
3112
|
+
return baseWrite(str3);
|
|
3113
3113
|
};
|
|
3114
3114
|
return { error, write, hasColors, helpWidth };
|
|
3115
3115
|
}
|
|
@@ -3370,9 +3370,9 @@ var require_parser = __commonJS({
|
|
|
3370
3370
|
this.ii = 0;
|
|
3371
3371
|
this.state = new State(this.parseStart);
|
|
3372
3372
|
}
|
|
3373
|
-
parse(
|
|
3374
|
-
if (
|
|
3375
|
-
this._buf = String(
|
|
3373
|
+
parse(str3) {
|
|
3374
|
+
if (str3.length === 0 || str3.length == null) return;
|
|
3375
|
+
this._buf = String(str3);
|
|
3376
3376
|
this.ii = -1;
|
|
3377
3377
|
this.char = -1;
|
|
3378
3378
|
let getNext;
|
|
@@ -4919,16 +4919,16 @@ var require_parse_string = __commonJS({
|
|
|
4919
4919
|
module2.exports = parseString;
|
|
4920
4920
|
var TOMLParser = require_toml_parser();
|
|
4921
4921
|
var prettyError = require_parse_pretty_error();
|
|
4922
|
-
function parseString(
|
|
4923
|
-
if (global.Buffer && global.Buffer.isBuffer(
|
|
4924
|
-
|
|
4922
|
+
function parseString(str3) {
|
|
4923
|
+
if (global.Buffer && global.Buffer.isBuffer(str3)) {
|
|
4924
|
+
str3 = str3.toString("utf8");
|
|
4925
4925
|
}
|
|
4926
4926
|
const parser = new TOMLParser();
|
|
4927
4927
|
try {
|
|
4928
|
-
parser.parse(
|
|
4928
|
+
parser.parse(str3);
|
|
4929
4929
|
return parser.finish();
|
|
4930
4930
|
} catch (err) {
|
|
4931
|
-
throw prettyError(err,
|
|
4931
|
+
throw prettyError(err, str3);
|
|
4932
4932
|
}
|
|
4933
4933
|
}
|
|
4934
4934
|
}
|
|
@@ -4941,27 +4941,27 @@ var require_parse_async = __commonJS({
|
|
|
4941
4941
|
module2.exports = parseAsync;
|
|
4942
4942
|
var TOMLParser = require_toml_parser();
|
|
4943
4943
|
var prettyError = require_parse_pretty_error();
|
|
4944
|
-
function parseAsync(
|
|
4944
|
+
function parseAsync(str3, opts) {
|
|
4945
4945
|
if (!opts) opts = {};
|
|
4946
4946
|
const index = 0;
|
|
4947
4947
|
const blocksize = opts.blocksize || 40960;
|
|
4948
4948
|
const parser = new TOMLParser();
|
|
4949
|
-
return new Promise((
|
|
4950
|
-
setImmediate(parseAsyncNext, index, blocksize,
|
|
4949
|
+
return new Promise((resolve6, reject) => {
|
|
4950
|
+
setImmediate(parseAsyncNext, index, blocksize, resolve6, reject);
|
|
4951
4951
|
});
|
|
4952
|
-
function parseAsyncNext(index2, blocksize2,
|
|
4953
|
-
if (index2 >=
|
|
4952
|
+
function parseAsyncNext(index2, blocksize2, resolve6, reject) {
|
|
4953
|
+
if (index2 >= str3.length) {
|
|
4954
4954
|
try {
|
|
4955
|
-
return
|
|
4955
|
+
return resolve6(parser.finish());
|
|
4956
4956
|
} catch (err) {
|
|
4957
|
-
return reject(prettyError(err,
|
|
4957
|
+
return reject(prettyError(err, str3));
|
|
4958
4958
|
}
|
|
4959
4959
|
}
|
|
4960
4960
|
try {
|
|
4961
|
-
parser.parse(
|
|
4962
|
-
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2,
|
|
4961
|
+
parser.parse(str3.slice(index2, index2 + blocksize2));
|
|
4962
|
+
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve6, reject);
|
|
4963
4963
|
} catch (err) {
|
|
4964
|
-
reject(prettyError(err,
|
|
4964
|
+
reject(prettyError(err, str3));
|
|
4965
4965
|
}
|
|
4966
4966
|
}
|
|
4967
4967
|
}
|
|
@@ -4985,7 +4985,7 @@ var require_parse_stream = __commonJS({
|
|
|
4985
4985
|
function parseReadable(stm) {
|
|
4986
4986
|
const parser = new TOMLParser();
|
|
4987
4987
|
stm.setEncoding("utf8");
|
|
4988
|
-
return new Promise((
|
|
4988
|
+
return new Promise((resolve6, reject) => {
|
|
4989
4989
|
let readable;
|
|
4990
4990
|
let ended = false;
|
|
4991
4991
|
let errored = false;
|
|
@@ -4993,7 +4993,7 @@ var require_parse_stream = __commonJS({
|
|
|
4993
4993
|
ended = true;
|
|
4994
4994
|
if (readable) return;
|
|
4995
4995
|
try {
|
|
4996
|
-
|
|
4996
|
+
resolve6(parser.finish());
|
|
4997
4997
|
} catch (err) {
|
|
4998
4998
|
reject(err);
|
|
4999
4999
|
}
|
|
@@ -5167,22 +5167,22 @@ var require_stringify = __commonJS({
|
|
|
5167
5167
|
return stringifyBasicString(keyStr);
|
|
5168
5168
|
}
|
|
5169
5169
|
}
|
|
5170
|
-
function stringifyBasicString(
|
|
5171
|
-
return '"' + escapeString(
|
|
5170
|
+
function stringifyBasicString(str3) {
|
|
5171
|
+
return '"' + escapeString(str3).replace(/"/g, '\\"') + '"';
|
|
5172
5172
|
}
|
|
5173
|
-
function stringifyLiteralString(
|
|
5174
|
-
return "'" +
|
|
5173
|
+
function stringifyLiteralString(str3) {
|
|
5174
|
+
return "'" + str3 + "'";
|
|
5175
5175
|
}
|
|
5176
|
-
function numpad(num,
|
|
5177
|
-
while (
|
|
5178
|
-
return
|
|
5176
|
+
function numpad(num, str3) {
|
|
5177
|
+
while (str3.length < num) str3 = "0" + str3;
|
|
5178
|
+
return str3;
|
|
5179
5179
|
}
|
|
5180
|
-
function escapeString(
|
|
5181
|
-
return
|
|
5180
|
+
function escapeString(str3) {
|
|
5181
|
+
return str3.replace(/\\/g, "\\\\").replace(/[\b]/g, "\\b").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\f/g, "\\f").replace(/\r/g, "\\r").replace(/([\u0000-\u001f\u007f])/, (c) => "\\u" + numpad(4, c.codePointAt(0).toString(16)));
|
|
5182
5182
|
}
|
|
5183
|
-
function stringifyMultilineString(
|
|
5184
|
-
let escaped =
|
|
5185
|
-
return escapeString(
|
|
5183
|
+
function stringifyMultilineString(str3) {
|
|
5184
|
+
let escaped = str3.split(/\n/).map((str4) => {
|
|
5185
|
+
return escapeString(str4).replace(/"(?="")/g, '\\"');
|
|
5186
5186
|
}).join("\n");
|
|
5187
5187
|
if (escaped.slice(-1) === '"') escaped += "\\\n";
|
|
5188
5188
|
return '"""\n' + escaped + '"""';
|
|
@@ -12546,8 +12546,8 @@ var init_app = __esm({
|
|
|
12546
12546
|
this.frame();
|
|
12547
12547
|
}, interval);
|
|
12548
12548
|
this.timer.unref?.();
|
|
12549
|
-
await new Promise((
|
|
12550
|
-
this.exitResolve =
|
|
12549
|
+
await new Promise((resolve6) => {
|
|
12550
|
+
this.exitResolve = resolve6;
|
|
12551
12551
|
});
|
|
12552
12552
|
}
|
|
12553
12553
|
targetFps() {
|
|
@@ -12911,7 +12911,7 @@ var init_ipc_client = __esm({
|
|
|
12911
12911
|
if (!(0, import_node_fs6.existsSync)(this.socketPath)) {
|
|
12912
12912
|
throw new Error(`threatcrushd socket not found at ${this.socketPath}`);
|
|
12913
12913
|
}
|
|
12914
|
-
return new Promise((
|
|
12914
|
+
return new Promise((resolve6, reject) => {
|
|
12915
12915
|
const sock = (0, import_node_net.createConnection)(this.socketPath);
|
|
12916
12916
|
const timer = setTimeout(() => {
|
|
12917
12917
|
sock.destroy();
|
|
@@ -12924,7 +12924,7 @@ var init_ipc_client = __esm({
|
|
|
12924
12924
|
sock.on("data", (chunk) => this.onData(chunk.toString()));
|
|
12925
12925
|
sock.on("close", () => this.onClose());
|
|
12926
12926
|
sock.on("error", () => this.onClose());
|
|
12927
|
-
|
|
12927
|
+
resolve6();
|
|
12928
12928
|
});
|
|
12929
12929
|
sock.once("error", (err) => {
|
|
12930
12930
|
clearTimeout(timer);
|
|
@@ -12940,14 +12940,14 @@ var init_ipc_client = __esm({
|
|
|
12940
12940
|
if (!this.socket) throw new Error("not connected");
|
|
12941
12941
|
const id = this.nextId++;
|
|
12942
12942
|
const frame = params ? { id, method, params } : { id, method };
|
|
12943
|
-
return new Promise((
|
|
12943
|
+
return new Promise((resolve6, reject) => {
|
|
12944
12944
|
const timer = setTimeout(() => {
|
|
12945
12945
|
this.pending.delete(id);
|
|
12946
12946
|
reject(new Error(
|
|
12947
12947
|
`threatcrushd did not answer "${method}" within ${REQUEST_TIMEOUT_MS / 1e3}s; if it is older than this CLI, update it`
|
|
12948
12948
|
));
|
|
12949
12949
|
}, REQUEST_TIMEOUT_MS);
|
|
12950
|
-
this.pending.set(id, { resolve:
|
|
12950
|
+
this.pending.set(id, { resolve: resolve6, reject, timer });
|
|
12951
12951
|
this.socket.write(JSON.stringify(frame) + "\n", (err) => {
|
|
12952
12952
|
if (err && this.pending.delete(id)) {
|
|
12953
12953
|
clearTimeout(timer);
|
|
@@ -13030,6 +13030,11 @@ var init_ipc_client = __esm({
|
|
|
13030
13030
|
});
|
|
13031
13031
|
|
|
13032
13032
|
// src/tui/state.ts
|
|
13033
|
+
function watchdogView(status) {
|
|
13034
|
+
const wd = status.watchdog;
|
|
13035
|
+
if (!wd) return OFF_WATCHDOG;
|
|
13036
|
+
return { on: wd.enabled, logged: wd.logged, answered: wd.answered, errored: wd.errored };
|
|
13037
|
+
}
|
|
13033
13038
|
function initialState(now = Date.now()) {
|
|
13034
13039
|
return {
|
|
13035
13040
|
connection: "searching",
|
|
@@ -13057,23 +13062,30 @@ function initialState(now = Date.now()) {
|
|
|
13057
13062
|
moduleIndex: 0,
|
|
13058
13063
|
moduleFilter: null,
|
|
13059
13064
|
sourceFilter: null,
|
|
13060
|
-
showNoise: false
|
|
13065
|
+
showNoise: false,
|
|
13066
|
+
muteCron: false,
|
|
13067
|
+
watchdog: OFF_WATCHDOG
|
|
13061
13068
|
};
|
|
13062
13069
|
}
|
|
13063
|
-
function
|
|
13070
|
+
function isCronLine(event) {
|
|
13071
|
+
if (event.severity !== "low" && event.severity !== "info") return false;
|
|
13072
|
+
return /\[CRON\] \([^)]+\) CMD /.test(event.message);
|
|
13073
|
+
}
|
|
13074
|
+
function isNoise(event, muteCron = false) {
|
|
13064
13075
|
if (event.severity !== "low" && event.severity !== "info") return false;
|
|
13065
13076
|
if (/^Client error 4\d\d:/.test(event.message)) return true;
|
|
13077
|
+
if (muteCron && isCronLine(event)) return true;
|
|
13066
13078
|
return /\b(veth|docker|br-|cni|cali|flannel|vxlan)[\w.-]*: entered (promiscuous|allmulticast) mode|\(unregistering\): left (promiscuous|allmulticast) mode/.test(event.message);
|
|
13067
13079
|
}
|
|
13068
13080
|
function matchesFilters(state, e) {
|
|
13069
13081
|
return (!state.moduleFilter || e.module === state.moduleFilter) && (!state.sourceFilter || e.source_ip === state.sourceFilter);
|
|
13070
13082
|
}
|
|
13071
13083
|
function visibleEvents(state) {
|
|
13072
|
-
return state.events.filter((e) => matchesFilters(state, e) && (state.showNoise || !isNoise(e)));
|
|
13084
|
+
return state.events.filter((e) => matchesFilters(state, e) && (state.showNoise || !isNoise(e, state.muteCron)));
|
|
13073
13085
|
}
|
|
13074
13086
|
function hiddenNoise(state) {
|
|
13075
13087
|
if (state.showNoise) return 0;
|
|
13076
|
-
return state.events.filter((e) => matchesFilters(state, e) && isNoise(e)).length;
|
|
13088
|
+
return state.events.filter((e) => matchesFilters(state, e) && isNoise(e, state.muteCron)).length;
|
|
13077
13089
|
}
|
|
13078
13090
|
function hasFilter(state) {
|
|
13079
13091
|
return Boolean(state.moduleFilter || state.sourceFilter);
|
|
@@ -13112,6 +13124,7 @@ function reducer(state, action) {
|
|
|
13112
13124
|
connectionLabel: action.label,
|
|
13113
13125
|
daemon: action.status,
|
|
13114
13126
|
modules: action.status.modules,
|
|
13127
|
+
watchdog: watchdogView(action.status),
|
|
13115
13128
|
counters: {
|
|
13116
13129
|
events: action.status.counters.events,
|
|
13117
13130
|
threats: action.status.counters.threats,
|
|
@@ -13119,7 +13132,7 @@ function reducer(state, action) {
|
|
|
13119
13132
|
}
|
|
13120
13133
|
};
|
|
13121
13134
|
case "connection_lost":
|
|
13122
|
-
return { ...state, connection: "lost", connectionLabel: action.label, daemon: null };
|
|
13135
|
+
return { ...state, connection: "lost", connectionLabel: action.label, daemon: null, watchdog: OFF_WATCHDOG };
|
|
13123
13136
|
case "event": {
|
|
13124
13137
|
if (state.paused) {
|
|
13125
13138
|
return { ...state, parked: [...state.parked, action.event].slice(-FEED_LIMIT) };
|
|
@@ -13223,6 +13236,8 @@ function reducer(state, action) {
|
|
|
13223
13236
|
return { ...state, sourceFilter: null, scrollBack: 0 };
|
|
13224
13237
|
case "toggle_noise":
|
|
13225
13238
|
return { ...state, showNoise: !state.showNoise, scrollBack: 0 };
|
|
13239
|
+
case "toggle_cron":
|
|
13240
|
+
return { ...state, muteCron: !state.muteCron, scrollBack: 0 };
|
|
13226
13241
|
case "counters":
|
|
13227
13242
|
return {
|
|
13228
13243
|
...state,
|
|
@@ -13258,7 +13273,10 @@ function reducer(state, action) {
|
|
|
13258
13273
|
moduleFilter: state.moduleFilter,
|
|
13259
13274
|
sourceFilter: state.sourceFilter,
|
|
13260
13275
|
moduleIndex: state.moduleIndex,
|
|
13261
|
-
showNoise: state.showNoise
|
|
13276
|
+
showNoise: state.showNoise,
|
|
13277
|
+
muteCron: state.muteCron,
|
|
13278
|
+
// Reset clears the view; the watchdog log on disk is not the view.
|
|
13279
|
+
watchdog: state.watchdog
|
|
13262
13280
|
};
|
|
13263
13281
|
}
|
|
13264
13282
|
}
|
|
@@ -13287,12 +13305,13 @@ function formatCount(n) {
|
|
|
13287
13305
|
if (n < 1e6) return `${(n / 1e3).toFixed(n < 1e4 ? 1 : 0)}k`;
|
|
13288
13306
|
return `${(n / 1e6).toFixed(1)}M`;
|
|
13289
13307
|
}
|
|
13290
|
-
var FOCUS_ORDER, NOTICE_MS, TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
|
|
13308
|
+
var FOCUS_ORDER, NOTICE_MS, OFF_WATCHDOG, TIMELINE_SLOTS, FEED_LIMIT, SEVERITIES;
|
|
13291
13309
|
var init_state = __esm({
|
|
13292
13310
|
"src/tui/state.ts"() {
|
|
13293
13311
|
"use strict";
|
|
13294
13312
|
FOCUS_ORDER = ["feed", "modules", "threats", "bans"];
|
|
13295
13313
|
NOTICE_MS = 6e3;
|
|
13314
|
+
OFF_WATCHDOG = { on: false, logged: 0, answered: 0, errored: 0 };
|
|
13296
13315
|
TIMELINE_SLOTS = 60;
|
|
13297
13316
|
FEED_LIMIT = 500;
|
|
13298
13317
|
SEVERITIES = ["info", "low", "medium", "high", "critical"];
|
|
@@ -13421,6 +13440,15 @@ function connectionBadge(state, demo) {
|
|
|
13421
13440
|
}
|
|
13422
13441
|
return { glyph: "\u25CB", label: "OFFLINE", color: severityColors.high };
|
|
13423
13442
|
}
|
|
13443
|
+
function watchdogBadge(state) {
|
|
13444
|
+
const wd = state.watchdog;
|
|
13445
|
+
if (!wd.on) return null;
|
|
13446
|
+
const hot = wd.answered + wd.errored;
|
|
13447
|
+
const parts = [`\u25C9 WATCHDOG ${formatCount(wd.logged)}`];
|
|
13448
|
+
if (wd.answered) parts.push(`${formatCount(wd.answered)} answered`);
|
|
13449
|
+
if (wd.errored) parts.push(`${formatCount(wd.errored)} 5xx`);
|
|
13450
|
+
return { label: parts.join(" \xB7 "), color: hot > 0 ? severityColors.high : severityColors.medium };
|
|
13451
|
+
}
|
|
13424
13452
|
function header(ui, state, theme, demo) {
|
|
13425
13453
|
const badge = connectionBadge(state, demo);
|
|
13426
13454
|
const uptime = state.daemon ? formatUptime(state.daemon.uptimeSeconds) : "\u2014";
|
|
@@ -13430,6 +13458,8 @@ function header(ui, state, theme, demo) {
|
|
|
13430
13458
|
row.text(`${badge.glyph} ${badge.label}`, { fg: badge.color, bold: true, size: 12 });
|
|
13431
13459
|
row.text(state.connectionLabel, { fg: theme.muted, size: "fill" });
|
|
13432
13460
|
if (state.paused) row.text("\u23F8 PAUSED", { fg: severityColors.medium, bold: true, size: 10 });
|
|
13461
|
+
const wd = watchdogBadge(state);
|
|
13462
|
+
if (wd) row.text(wd.label, { fg: wd.color, bold: true, size: wd.label.length + 1 });
|
|
13433
13463
|
row.text(`uptime ${uptime}`, { fg: theme.muted, size: 16, align: "right" });
|
|
13434
13464
|
});
|
|
13435
13465
|
});
|
|
@@ -13550,7 +13580,9 @@ function severityPanel(parent, state, theme) {
|
|
|
13550
13580
|
}
|
|
13551
13581
|
function noiseNote(state) {
|
|
13552
13582
|
const hidden = hiddenNoise(state);
|
|
13553
|
-
|
|
13583
|
+
if (hidden === 0) return void 0;
|
|
13584
|
+
const keys = state.muteCron ? "n/c show" : "n shows";
|
|
13585
|
+
return `${hidden} routine hidden \xB7 ${keys}`;
|
|
13554
13586
|
}
|
|
13555
13587
|
function filterLabel(state) {
|
|
13556
13588
|
return [state.moduleFilter, state.sourceFilter ? `src ${state.sourceFilter}` : null].filter(Boolean).join(" \xB7 ");
|
|
@@ -13791,7 +13823,10 @@ function footer(ui, state, theme) {
|
|
|
13791
13823
|
...state.focus === "modules" ? [{ key: "\u23CE", label: state.moduleFilter ? "unfilter" : "filter" }] : state.focus === "threats" || state.focus === "bans" ? [{ key: "\u23CE", label: state.sourceFilter ? "unfilter" : "filter" }, { key: "b", label: "ban" }, { key: "u", label: "unban" }] : [{ key: "b", label: "ban" }, { key: "u", label: "unban" }],
|
|
13792
13824
|
{ key: "p", label: state.paused ? "resume" : "pause" },
|
|
13793
13825
|
{ key: "r", label: "reset" },
|
|
13794
|
-
{ key: "n", label: state.showNoise ? "hide 4xx" : "show 4xx" }
|
|
13826
|
+
{ key: "n", label: state.showNoise ? "hide 4xx" : "show 4xx" },
|
|
13827
|
+
// Only offer the cron toggle once a cron line has actually shown up, or
|
|
13828
|
+
// while it is muting, so the hint never advertises a key with nothing to act on.
|
|
13829
|
+
...state.muteCron || state.events.some(isCronLine) ? [{ key: "c", label: state.muteCron ? "show cron" : "mute cron" }] : []
|
|
13795
13830
|
],
|
|
13796
13831
|
right: [
|
|
13797
13832
|
// The notice is the answer to "did my keypress do anything", so it takes
|
|
@@ -14060,6 +14095,9 @@ async function startDashboard(options = {}) {
|
|
|
14060
14095
|
case "n":
|
|
14061
14096
|
dispatch({ type: "toggle_noise" });
|
|
14062
14097
|
break;
|
|
14098
|
+
case "c":
|
|
14099
|
+
dispatch({ type: "toggle_cron" });
|
|
14100
|
+
break;
|
|
14063
14101
|
case "tab":
|
|
14064
14102
|
dispatch({ type: "focus_next" });
|
|
14065
14103
|
break;
|
|
@@ -16302,8 +16340,8 @@ var source_default = chalk;
|
|
|
16302
16340
|
// src/index.ts
|
|
16303
16341
|
var import_readline = __toESM(require("readline"));
|
|
16304
16342
|
var import_node_child_process15 = require("child_process");
|
|
16305
|
-
var
|
|
16306
|
-
var
|
|
16343
|
+
var import_node_fs39 = require("fs");
|
|
16344
|
+
var import_node_path27 = require("path");
|
|
16307
16345
|
var import_node_os11 = require("os");
|
|
16308
16346
|
|
|
16309
16347
|
// src/commands/monitor.ts
|
|
@@ -23108,6 +23146,7 @@ function loadConfig(configPath) {
|
|
|
23108
23146
|
remediation: parsed.remediation,
|
|
23109
23147
|
detection: parsed.detection,
|
|
23110
23148
|
cloud: parsed.cloud,
|
|
23149
|
+
watchdog: parsed.watchdog,
|
|
23111
23150
|
license: parsed.license
|
|
23112
23151
|
};
|
|
23113
23152
|
} catch {
|
|
@@ -23510,9 +23549,470 @@ async function runDemoMode() {
|
|
|
23510
23549
|
});
|
|
23511
23550
|
}
|
|
23512
23551
|
|
|
23552
|
+
// src/commands/watchdog.ts
|
|
23553
|
+
var import_node_fs9 = require("fs");
|
|
23554
|
+
var import_node_path7 = require("path");
|
|
23555
|
+
init_paths();
|
|
23556
|
+
|
|
23557
|
+
// src/core/watchdog.ts
|
|
23558
|
+
var import_node_fs8 = require("fs");
|
|
23559
|
+
var import_node_crypto2 = require("crypto");
|
|
23560
|
+
var import_node_path6 = require("path");
|
|
23561
|
+
var WATCHDOG_DIRNAME = "watchdog";
|
|
23562
|
+
var LOG_FILE = "attacks.jsonl";
|
|
23563
|
+
var ROTATED_FILE = "attacks.1.jsonl";
|
|
23564
|
+
var TRIAGE_FILE = "triage.json";
|
|
23565
|
+
var ROTATE_BYTES = 50 * 1024 * 1024;
|
|
23566
|
+
var SEEN_LIMIT = 5e3;
|
|
23567
|
+
var OUTCOME_ORDER = ["answered", "errored", "unknown", "redirected", "refused"];
|
|
23568
|
+
var TRIAGE_STATUSES = ["new", "hole", "fp", "fixed"];
|
|
23569
|
+
var SEVERITY_RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
23570
|
+
function str(v) {
|
|
23571
|
+
return typeof v === "string" && v !== "" && v !== "-" ? v : void 0;
|
|
23572
|
+
}
|
|
23573
|
+
function isAttack(event) {
|
|
23574
|
+
if (event.module === "firewall-rules") return false;
|
|
23575
|
+
const d = event.details ?? {};
|
|
23576
|
+
if (d.heartbeat) return false;
|
|
23577
|
+
const crs = typeof d.crs_score === "number" ? d.crs_score : 0;
|
|
23578
|
+
if (crs > 0 || str(d.attack_type)) return true;
|
|
23579
|
+
if (event.category === "web" && typeof d.status === "number" && !str(d.rule_id)) return false;
|
|
23580
|
+
return SEVERITY_RANK[event.severity] >= SEVERITY_RANK.medium;
|
|
23581
|
+
}
|
|
23582
|
+
function outcomeFor(status) {
|
|
23583
|
+
if (typeof status !== "number" || !Number.isFinite(status)) return "unknown";
|
|
23584
|
+
if (status >= 500) return "errored";
|
|
23585
|
+
if (status >= 400) return "refused";
|
|
23586
|
+
if (status >= 300) return "redirected";
|
|
23587
|
+
if (status >= 100) return "answered";
|
|
23588
|
+
return "unknown";
|
|
23589
|
+
}
|
|
23590
|
+
function requestFromMessage(message) {
|
|
23591
|
+
const m = /\b(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|CONNECT|TRACE|PROPFIND)\s+(\S+)/.exec(message);
|
|
23592
|
+
return m ? { method: m[1], url: m[2] } : {};
|
|
23593
|
+
}
|
|
23594
|
+
function signatureOf(r) {
|
|
23595
|
+
if (r.path) {
|
|
23596
|
+
return ["web", r.host ?? "", r.method ?? "", r.path, r.attack_type ?? r.rule_id ?? ""].join("|");
|
|
23597
|
+
}
|
|
23598
|
+
if (r.rule_id) return ["rule", r.module, r.rule_id].join("|");
|
|
23599
|
+
const shape = r.message.replace(/\b\d{1,3}(?:\.\d{1,3}){3}(?:\/\d+)?\b/g, "<ip>").replace(/\b[0-9a-f]*:[0-9a-f:]+\b/gi, "<ip>").replace(/\d+/g, "#");
|
|
23600
|
+
return ["msg", r.module, shape].join("|");
|
|
23601
|
+
}
|
|
23602
|
+
function findingId(signature) {
|
|
23603
|
+
return (0, import_node_crypto2.createHash)("sha1").update(signature).digest("hex").slice(0, 10);
|
|
23604
|
+
}
|
|
23605
|
+
function toRecord(event) {
|
|
23606
|
+
const d = event.details ?? {};
|
|
23607
|
+
const fromMsg = requestFromMessage(event.message);
|
|
23608
|
+
const url = str(d.url) ?? fromMsg.url;
|
|
23609
|
+
const path = str(d.path) ?? (url ? url.split("?")[0] : void 0);
|
|
23610
|
+
const status = typeof d.status === "number" ? d.status : void 0;
|
|
23611
|
+
const base = {
|
|
23612
|
+
module: event.module,
|
|
23613
|
+
host: str(d.host),
|
|
23614
|
+
method: str(d.method) ?? fromMsg.method,
|
|
23615
|
+
path,
|
|
23616
|
+
attack_type: str(d.attack_type),
|
|
23617
|
+
rule_id: str(d.rule_id),
|
|
23618
|
+
message: event.message
|
|
23619
|
+
};
|
|
23620
|
+
const timestamp = event.timestamp instanceof Date ? event.timestamp : new Date(event.timestamp);
|
|
23621
|
+
const record = {
|
|
23622
|
+
v: 1,
|
|
23623
|
+
id: findingId(signatureOf(base)),
|
|
23624
|
+
at: (Number.isNaN(timestamp.getTime()) ? /* @__PURE__ */ new Date() : timestamp).toISOString(),
|
|
23625
|
+
category: event.category,
|
|
23626
|
+
severity: event.severity,
|
|
23627
|
+
...base,
|
|
23628
|
+
ip: event.source_ip,
|
|
23629
|
+
url,
|
|
23630
|
+
status,
|
|
23631
|
+
outcome: outcomeFor(status),
|
|
23632
|
+
crs_score: typeof d.crs_score === "number" ? d.crs_score : void 0,
|
|
23633
|
+
ua: str(d.ua)
|
|
23634
|
+
};
|
|
23635
|
+
for (const k of Object.keys(record)) {
|
|
23636
|
+
if (record[k] === void 0) delete record[k];
|
|
23637
|
+
}
|
|
23638
|
+
return record;
|
|
23639
|
+
}
|
|
23640
|
+
function dedupeKey(r) {
|
|
23641
|
+
return `${r.at}|${r.ip ?? ""}|${r.message}`;
|
|
23642
|
+
}
|
|
23643
|
+
function isShared(dir) {
|
|
23644
|
+
try {
|
|
23645
|
+
return ((0, import_node_fs8.statSync)(dir).mode & 1024) !== 0;
|
|
23646
|
+
} catch {
|
|
23647
|
+
return false;
|
|
23648
|
+
}
|
|
23649
|
+
}
|
|
23650
|
+
var WatchdogLog = class {
|
|
23651
|
+
dir;
|
|
23652
|
+
file;
|
|
23653
|
+
buffer = [];
|
|
23654
|
+
seen = /* @__PURE__ */ new Set();
|
|
23655
|
+
shareGid;
|
|
23656
|
+
stats = { logged: 0, answered: 0, errored: 0 };
|
|
23657
|
+
constructor(dir, options = {}) {
|
|
23658
|
+
this.dir = dir;
|
|
23659
|
+
this.file = (0, import_node_path6.join)(dir, LOG_FILE);
|
|
23660
|
+
this.shareGid = options.shareGid;
|
|
23661
|
+
(0, import_node_fs8.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
|
|
23662
|
+
if (this.shareGid !== void 0) {
|
|
23663
|
+
(0, import_node_fs8.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
|
|
23664
|
+
(0, import_node_fs8.chmodSync)(dir, 1528);
|
|
23665
|
+
}
|
|
23666
|
+
for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
|
|
23667
|
+
}
|
|
23668
|
+
remember(key) {
|
|
23669
|
+
this.seen.add(key);
|
|
23670
|
+
if (this.seen.size > SEEN_LIMIT) {
|
|
23671
|
+
const oldest = this.seen.values().next().value;
|
|
23672
|
+
if (oldest !== void 0) this.seen.delete(oldest);
|
|
23673
|
+
}
|
|
23674
|
+
}
|
|
23675
|
+
/** Logs the event if it is an attack not already logged. Returns the record when it was. */
|
|
23676
|
+
record(event) {
|
|
23677
|
+
if (!isAttack(event)) return null;
|
|
23678
|
+
const rec = toRecord(event);
|
|
23679
|
+
const key = dedupeKey(rec);
|
|
23680
|
+
if (this.seen.has(key)) return null;
|
|
23681
|
+
this.remember(key);
|
|
23682
|
+
this.buffer.push(JSON.stringify(rec));
|
|
23683
|
+
this.stats.logged++;
|
|
23684
|
+
if (rec.outcome === "answered") this.stats.answered++;
|
|
23685
|
+
if (rec.outcome === "errored") this.stats.errored++;
|
|
23686
|
+
return rec;
|
|
23687
|
+
}
|
|
23688
|
+
flush() {
|
|
23689
|
+
if (this.buffer.length === 0) return;
|
|
23690
|
+
const chunk = this.buffer.join("\n") + "\n";
|
|
23691
|
+
this.buffer = [];
|
|
23692
|
+
try {
|
|
23693
|
+
if ((0, import_node_fs8.statSync)(this.file).size > ROTATE_BYTES) {
|
|
23694
|
+
(0, import_node_fs8.renameSync)(this.file, (0, import_node_path6.join)(this.dir, ROTATED_FILE));
|
|
23695
|
+
}
|
|
23696
|
+
} catch {
|
|
23697
|
+
}
|
|
23698
|
+
(0, import_node_fs8.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
|
|
23699
|
+
if (this.shareGid !== void 0) {
|
|
23700
|
+
try {
|
|
23701
|
+
(0, import_node_fs8.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
|
|
23702
|
+
(0, import_node_fs8.chmodSync)(this.file, 432);
|
|
23703
|
+
} catch {
|
|
23704
|
+
}
|
|
23705
|
+
}
|
|
23706
|
+
}
|
|
23707
|
+
};
|
|
23708
|
+
function parseLines(text) {
|
|
23709
|
+
const out = [];
|
|
23710
|
+
for (const line of text.split("\n")) {
|
|
23711
|
+
if (!line) continue;
|
|
23712
|
+
try {
|
|
23713
|
+
const r = JSON.parse(line);
|
|
23714
|
+
if (r && r.v === 1 && typeof r.id === "string") out.push(r);
|
|
23715
|
+
} catch {
|
|
23716
|
+
}
|
|
23717
|
+
}
|
|
23718
|
+
return out;
|
|
23719
|
+
}
|
|
23720
|
+
function readTail(file, bytes) {
|
|
23721
|
+
let fd;
|
|
23722
|
+
try {
|
|
23723
|
+
fd = (0, import_node_fs8.openSync)(file, "r");
|
|
23724
|
+
} catch (err) {
|
|
23725
|
+
if (err.code === "ENOENT") return [];
|
|
23726
|
+
throw err;
|
|
23727
|
+
}
|
|
23728
|
+
try {
|
|
23729
|
+
const size = (0, import_node_fs8.fstatSync)(fd).size;
|
|
23730
|
+
const start = Math.max(0, size - bytes);
|
|
23731
|
+
const buf = Buffer.alloc(size - start);
|
|
23732
|
+
(0, import_node_fs8.readSync)(fd, buf, 0, buf.length, start);
|
|
23733
|
+
let text = buf.toString("utf8");
|
|
23734
|
+
if (start > 0) text = text.slice(text.indexOf("\n") + 1);
|
|
23735
|
+
return parseLines(text);
|
|
23736
|
+
} finally {
|
|
23737
|
+
(0, import_node_fs8.closeSync)(fd);
|
|
23738
|
+
}
|
|
23739
|
+
}
|
|
23740
|
+
function readAttacks(dir) {
|
|
23741
|
+
const out = [];
|
|
23742
|
+
for (const name of [ROTATED_FILE, LOG_FILE]) {
|
|
23743
|
+
const file = (0, import_node_path6.join)(dir, name);
|
|
23744
|
+
if ((0, import_node_fs8.existsSync)(file)) out.push(...parseLines((0, import_node_fs8.readFileSync)(file, "utf8")));
|
|
23745
|
+
}
|
|
23746
|
+
return out;
|
|
23747
|
+
}
|
|
23748
|
+
function readTriage(dir) {
|
|
23749
|
+
const file = (0, import_node_path6.join)(dir, TRIAGE_FILE);
|
|
23750
|
+
if (!(0, import_node_fs8.existsSync)(file)) return {};
|
|
23751
|
+
try {
|
|
23752
|
+
return JSON.parse((0, import_node_fs8.readFileSync)(file, "utf8"));
|
|
23753
|
+
} catch {
|
|
23754
|
+
return {};
|
|
23755
|
+
}
|
|
23756
|
+
}
|
|
23757
|
+
function writeTriage(dir, map) {
|
|
23758
|
+
(0, import_node_fs8.mkdirSync)(dir, { recursive: true });
|
|
23759
|
+
const file = (0, import_node_path6.join)(dir, TRIAGE_FILE);
|
|
23760
|
+
const mode = isShared(dir) ? 432 : 384;
|
|
23761
|
+
(0, import_node_fs8.writeFileSync)(`${file}.tmp`, JSON.stringify(map, null, 2) + "\n", { mode });
|
|
23762
|
+
try {
|
|
23763
|
+
(0, import_node_fs8.chmodSync)(`${file}.tmp`, mode);
|
|
23764
|
+
} catch {
|
|
23765
|
+
}
|
|
23766
|
+
(0, import_node_fs8.renameSync)(`${file}.tmp`, file);
|
|
23767
|
+
}
|
|
23768
|
+
function setTriage(dir, id, update, now = /* @__PURE__ */ new Date()) {
|
|
23769
|
+
const map = readTriage(dir);
|
|
23770
|
+
const prev = map[id];
|
|
23771
|
+
const entry = {
|
|
23772
|
+
status: update.status,
|
|
23773
|
+
note: update.note ?? prev?.note,
|
|
23774
|
+
pr: update.pr ?? prev?.pr,
|
|
23775
|
+
updated_at: now.toISOString()
|
|
23776
|
+
};
|
|
23777
|
+
if (!entry.note) delete entry.note;
|
|
23778
|
+
if (!entry.pr) delete entry.pr;
|
|
23779
|
+
map[id] = entry;
|
|
23780
|
+
writeTriage(dir, map);
|
|
23781
|
+
return entry;
|
|
23782
|
+
}
|
|
23783
|
+
var SOURCES_CAP = 20;
|
|
23784
|
+
var SAMPLES_CAP = 5;
|
|
23785
|
+
function groupFindings(records, triage = {}) {
|
|
23786
|
+
const byId = /* @__PURE__ */ new Map();
|
|
23787
|
+
for (const r of records) {
|
|
23788
|
+
let f = byId.get(r.id);
|
|
23789
|
+
if (!f) {
|
|
23790
|
+
f = {
|
|
23791
|
+
id: r.id,
|
|
23792
|
+
outcome: r.outcome,
|
|
23793
|
+
severity: r.severity,
|
|
23794
|
+
count: 0,
|
|
23795
|
+
first_seen: r.at,
|
|
23796
|
+
last_seen: r.at,
|
|
23797
|
+
host: r.host,
|
|
23798
|
+
method: r.method,
|
|
23799
|
+
path: r.path,
|
|
23800
|
+
attack_type: r.attack_type,
|
|
23801
|
+
rule_id: r.rule_id,
|
|
23802
|
+
module: r.module,
|
|
23803
|
+
title: r.message,
|
|
23804
|
+
sources: [],
|
|
23805
|
+
source_count: 0,
|
|
23806
|
+
statuses: {},
|
|
23807
|
+
samples: [],
|
|
23808
|
+
triage: triage[r.id] ?? { status: "new", updated_at: r.at },
|
|
23809
|
+
_ips: /* @__PURE__ */ new Set()
|
|
23810
|
+
};
|
|
23811
|
+
byId.set(r.id, f);
|
|
23812
|
+
}
|
|
23813
|
+
f.count++;
|
|
23814
|
+
if (r.at < f.first_seen) f.first_seen = r.at;
|
|
23815
|
+
if (r.at > f.last_seen) f.last_seen = r.at;
|
|
23816
|
+
if (OUTCOME_ORDER.indexOf(r.outcome) < OUTCOME_ORDER.indexOf(f.outcome)) f.outcome = r.outcome;
|
|
23817
|
+
if (SEVERITY_RANK[r.severity] > SEVERITY_RANK[f.severity]) f.severity = r.severity;
|
|
23818
|
+
if (r.status !== void 0) f.statuses[r.status] = (f.statuses[r.status] ?? 0) + 1;
|
|
23819
|
+
if (r.ip && !f._ips.has(r.ip)) {
|
|
23820
|
+
f._ips.add(r.ip);
|
|
23821
|
+
if (f.sources.length < SOURCES_CAP) f.sources.push(r.ip);
|
|
23822
|
+
}
|
|
23823
|
+
f.samples.push(r);
|
|
23824
|
+
}
|
|
23825
|
+
const findings = [];
|
|
23826
|
+
for (const f of byId.values()) {
|
|
23827
|
+
const { _ips, ...rest } = f;
|
|
23828
|
+
rest.source_count = _ips.size;
|
|
23829
|
+
rest.samples = rest.samples.sort((a, b) => OUTCOME_ORDER.indexOf(a.outcome) - OUTCOME_ORDER.indexOf(b.outcome) || b.at.localeCompare(a.at)).slice(0, SAMPLES_CAP);
|
|
23830
|
+
findings.push(rest);
|
|
23831
|
+
}
|
|
23832
|
+
const triaged = (f) => f.triage.status === "new" ? 0 : 1;
|
|
23833
|
+
return findings.sort((a, b) => triaged(a) - triaged(b) || OUTCOME_ORDER.indexOf(a.outcome) - OUTCOME_ORDER.indexOf(b.outcome) || SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity] || b.count - a.count || b.last_seen.localeCompare(a.last_seen));
|
|
23834
|
+
}
|
|
23835
|
+
function findFinding(findings, id) {
|
|
23836
|
+
const exact = findings.find((f) => f.id === id);
|
|
23837
|
+
if (exact) return exact;
|
|
23838
|
+
const matches2 = findings.filter((f) => f.id.startsWith(id));
|
|
23839
|
+
return matches2.length === 1 ? matches2[0] : null;
|
|
23840
|
+
}
|
|
23841
|
+
function shellQuote(s) {
|
|
23842
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
23843
|
+
}
|
|
23844
|
+
function reproCommand(r) {
|
|
23845
|
+
if (!r.host || !r.url) return null;
|
|
23846
|
+
const method = r.method && r.method !== "GET" ? ` -X ${r.method}` : "";
|
|
23847
|
+
return `curl -sk -o /dev/null -w '%{http_code}\\n'${method} ${shellQuote(`https://${r.host}${r.url}`)}`;
|
|
23848
|
+
}
|
|
23849
|
+
function findingBrief(f) {
|
|
23850
|
+
const lines = [];
|
|
23851
|
+
const where2 = f.host ? `${f.host} ${f.method ?? ""} ${f.path ?? ""}`.trim() : f.title;
|
|
23852
|
+
lines.push(`# Watchdog finding ${f.id}: ${f.attack_type ?? f.rule_id ?? f.module} on ${where2}`);
|
|
23853
|
+
lines.push("");
|
|
23854
|
+
lines.push(`- **Outcome:** ${f.outcome}${outcomeExplainer(f.outcome)}`);
|
|
23855
|
+
lines.push(`- **Severity:** ${f.severity} \xB7 **hits:** ${f.count} from ${f.source_count} source(s)`);
|
|
23856
|
+
lines.push(`- **Seen:** ${f.first_seen} \u2192 ${f.last_seen}`);
|
|
23857
|
+
const statuses = Object.entries(f.statuses).map(([s, n]) => `${s}\xD7${n}`).join(", ");
|
|
23858
|
+
if (statuses) lines.push(`- **Status codes:** ${statuses}`);
|
|
23859
|
+
if (f.host) lines.push(`- **Vhost:** ${f.host}`);
|
|
23860
|
+
if (f.path) lines.push(`- **Endpoint:** ${f.method ?? ""} ${f.path}`.replace(" ", " "));
|
|
23861
|
+
if (f.rule_id) lines.push(`- **Rule:** ${f.rule_id}`);
|
|
23862
|
+
lines.push(`- **Detected by:** ${f.module}`);
|
|
23863
|
+
lines.push(`- **Triage:** ${f.triage.status}${f.triage.note ? ` \u2014 ${f.triage.note}` : ""}${f.triage.pr ? ` (${f.triage.pr})` : ""}`);
|
|
23864
|
+
lines.push("");
|
|
23865
|
+
lines.push("## Sample requests");
|
|
23866
|
+
lines.push("");
|
|
23867
|
+
for (const s of f.samples) {
|
|
23868
|
+
lines.push(`- \`${s.at}\` ${s.ip ?? "?"} \u2192 ${s.status ?? "\u2014"} \`${(s.method ? `${s.method} ` : "") + (s.url ?? s.message)}\``);
|
|
23869
|
+
if (s.ua) lines.push(` - UA: \`${s.ua}\``);
|
|
23870
|
+
}
|
|
23871
|
+
const repro = f.samples.map(reproCommand).find(Boolean);
|
|
23872
|
+
if (repro) {
|
|
23873
|
+
lines.push("");
|
|
23874
|
+
lines.push("## Reproduce (against our own site only)");
|
|
23875
|
+
lines.push("");
|
|
23876
|
+
lines.push("```sh");
|
|
23877
|
+
lines.push(repro);
|
|
23878
|
+
lines.push("```");
|
|
23879
|
+
}
|
|
23880
|
+
lines.push("");
|
|
23881
|
+
lines.push("## Verify, then fix");
|
|
23882
|
+
lines.push("");
|
|
23883
|
+
lines.push("1. Find the repo that serves this vhost and the handler for the endpoint above.");
|
|
23884
|
+
lines.push("2. Decide whether the request did anything it should not: read the handler, replay the sample against a dev instance, check the response body, not just the status code.");
|
|
23885
|
+
lines.push(`3. Not a hole: \`threatcrush watchdog mark ${f.id} fp --note "<why>"\`.`);
|
|
23886
|
+
lines.push("4. A hole: write a failing test that sends the sample payload, fix the handler, open a PR with this brief in the body, merge it once checks are green and ship it.");
|
|
23887
|
+
lines.push(`5. Record it: \`threatcrush watchdog mark ${f.id} fixed --pr <url>\`.`);
|
|
23888
|
+
return lines.join("\n") + "\n";
|
|
23889
|
+
}
|
|
23890
|
+
function outcomeExplainer(o) {
|
|
23891
|
+
switch (o) {
|
|
23892
|
+
case "answered":
|
|
23893
|
+
return " \u2014 the app served this request (2xx). Verify it did not do what the payload asked.";
|
|
23894
|
+
case "errored":
|
|
23895
|
+
return " \u2014 the app crashed on it (5xx). Input reached code that did not expect it.";
|
|
23896
|
+
case "redirected":
|
|
23897
|
+
return " \u2014 answered with a redirect (3xx); usually auth bouncing it.";
|
|
23898
|
+
case "refused":
|
|
23899
|
+
return " \u2014 refused (4xx). Probably not a hole; kept for the record.";
|
|
23900
|
+
default:
|
|
23901
|
+
return " \u2014 not an HTTP request (ssh, network, rule); check the detection itself.";
|
|
23902
|
+
}
|
|
23903
|
+
}
|
|
23904
|
+
|
|
23905
|
+
// src/commands/watchdog.ts
|
|
23906
|
+
function resolveWatchdogDir(dir) {
|
|
23907
|
+
if (dir) return dir;
|
|
23908
|
+
if (process.env.THREATCRUSH_WATCHDOG_DIR) return process.env.THREATCRUSH_WATCHDOG_DIR;
|
|
23909
|
+
const system = (0, import_node_path7.join)("/var/lib/threatcrush", WATCHDOG_DIRNAME);
|
|
23910
|
+
if ((0, import_node_fs9.existsSync)(system)) return system;
|
|
23911
|
+
return (0, import_node_path7.join)(PATHS.stateDir, WATCHDOG_DIRNAME);
|
|
23912
|
+
}
|
|
23913
|
+
function load(dir) {
|
|
23914
|
+
return groupFindings(readAttacks(dir), readTriage(dir));
|
|
23915
|
+
}
|
|
23916
|
+
var OUTCOME_COLOR = {
|
|
23917
|
+
answered: source_default.red.bold,
|
|
23918
|
+
errored: source_default.magenta.bold,
|
|
23919
|
+
unknown: source_default.yellow,
|
|
23920
|
+
redirected: source_default.cyan,
|
|
23921
|
+
refused: source_default.gray
|
|
23922
|
+
};
|
|
23923
|
+
var TRIAGE_COLOR = {
|
|
23924
|
+
new: source_default.white,
|
|
23925
|
+
hole: source_default.red.bold,
|
|
23926
|
+
fp: source_default.gray,
|
|
23927
|
+
fixed: source_default.green
|
|
23928
|
+
};
|
|
23929
|
+
function where(f) {
|
|
23930
|
+
if (f.path) return `${f.host ? `${f.host} ` : ""}${f.method ?? ""} ${f.path}`.trim();
|
|
23931
|
+
return f.title;
|
|
23932
|
+
}
|
|
23933
|
+
function watchdogListCommand(opts) {
|
|
23934
|
+
const dir = resolveWatchdogDir(opts.dir);
|
|
23935
|
+
let findings = load(dir);
|
|
23936
|
+
if (opts.status) findings = findings.filter((f) => f.triage.status === opts.status);
|
|
23937
|
+
if (opts.outcome) findings = findings.filter((f) => f.outcome === opts.outcome);
|
|
23938
|
+
if (!opts.all && !opts.status && !opts.outcome) {
|
|
23939
|
+
findings = findings.filter((f) => (f.triage.status === "new" || f.triage.status === "hole") && f.outcome !== "refused");
|
|
23940
|
+
}
|
|
23941
|
+
const limit = opts.limit ? Math.max(1, parseInt(opts.limit, 10) || 50) : 50;
|
|
23942
|
+
if (opts.json) {
|
|
23943
|
+
console.log(JSON.stringify(findings.slice(0, limit), null, 2));
|
|
23944
|
+
return;
|
|
23945
|
+
}
|
|
23946
|
+
if (findings.length === 0) {
|
|
23947
|
+
const empty = (0, import_node_fs9.existsSync)((0, import_node_path7.join)(dir, "attacks.jsonl")) ? "Nothing to triage." + (opts.all ? "" : " (refused and triaged findings hidden; --all shows them)") : `No watchdog log at ${dir}. The daemon writes it: threatcrush start (or upgrade + restart an older daemon).`;
|
|
23948
|
+
console.log(source_default.dim(empty));
|
|
23949
|
+
return;
|
|
23950
|
+
}
|
|
23951
|
+
console.log(source_default.dim(`${dir} \xB7 ${findings.length} finding(s)
|
|
23952
|
+
`));
|
|
23953
|
+
for (const f of findings.slice(0, limit)) {
|
|
23954
|
+
const statuses = Object.keys(f.statuses).join(",") || "\u2014";
|
|
23955
|
+
console.log(
|
|
23956
|
+
`${source_default.bold(f.id)} ${OUTCOME_COLOR[f.outcome](f.outcome.padEnd(10))} ${TRIAGE_COLOR[f.triage.status](f.triage.status.padEnd(5))} ${f.severity.padEnd(8)} ${String(f.count).padStart(5)}\xD7 ${source_default.dim(statuses.padEnd(9))} ${source_default.cyan(f.attack_type ?? f.rule_id ?? f.module)} ${where(f)}`
|
|
23957
|
+
);
|
|
23958
|
+
}
|
|
23959
|
+
if (findings.length > limit) console.log(source_default.dim(`
|
|
23960
|
+
\u2026 ${findings.length - limit} more (--limit)`));
|
|
23961
|
+
console.log(source_default.dim("\nthreatcrush watchdog show <id> \xB7 brief <id> \xB7 mark <id> hole|fp|fixed"));
|
|
23962
|
+
}
|
|
23963
|
+
function resolve(dir, id) {
|
|
23964
|
+
const found = findFinding(load(dir), id);
|
|
23965
|
+
if (!found) {
|
|
23966
|
+
console.error(source_default.red(`No single finding matches "${id}" in ${dir}.`));
|
|
23967
|
+
process.exit(1);
|
|
23968
|
+
}
|
|
23969
|
+
return found;
|
|
23970
|
+
}
|
|
23971
|
+
function watchdogShowCommand(id, opts) {
|
|
23972
|
+
const dir = resolveWatchdogDir(opts.dir);
|
|
23973
|
+
const f = resolve(dir, id);
|
|
23974
|
+
if (opts.json) {
|
|
23975
|
+
console.log(JSON.stringify(f, null, 2));
|
|
23976
|
+
return;
|
|
23977
|
+
}
|
|
23978
|
+
console.log(`${source_default.bold(f.id)} ${OUTCOME_COLOR[f.outcome](f.outcome)} ${TRIAGE_COLOR[f.triage.status](f.triage.status)}`);
|
|
23979
|
+
console.log(`${source_default.cyan(f.attack_type ?? f.rule_id ?? f.module)} ${where(f)}`);
|
|
23980
|
+
console.log(source_default.dim(`${f.count} hit(s) from ${f.source_count} source(s) \xB7 ${f.first_seen} \u2192 ${f.last_seen}`));
|
|
23981
|
+
const statuses = Object.entries(f.statuses).map(([s, n]) => `${s}\xD7${n}`).join(" ");
|
|
23982
|
+
if (statuses) console.log(source_default.dim(`status codes: ${statuses}`));
|
|
23983
|
+
if (f.triage.note) console.log(`note: ${f.triage.note}`);
|
|
23984
|
+
if (f.triage.pr) console.log(`pr: ${f.triage.pr}`);
|
|
23985
|
+
console.log("\nsamples:");
|
|
23986
|
+
for (const s of f.samples) {
|
|
23987
|
+
console.log(` ${source_default.dim(s.at)} ${s.ip ?? "?"} \u2192 ${s.status ?? "\u2014"} ${s.method ? `${s.method} ` : ""}${s.url ?? s.message}`);
|
|
23988
|
+
}
|
|
23989
|
+
console.log(`
|
|
23990
|
+
sources: ${f.sources.join(", ")}${f.source_count > f.sources.length ? ` (+${f.source_count - f.sources.length})` : ""}`);
|
|
23991
|
+
const repro = f.samples.map(reproCommand).find(Boolean);
|
|
23992
|
+
if (repro) console.log(`
|
|
23993
|
+
reproduce: ${repro}`);
|
|
23994
|
+
}
|
|
23995
|
+
function watchdogBriefCommand(id, opts) {
|
|
23996
|
+
const dir = resolveWatchdogDir(opts.dir);
|
|
23997
|
+
process.stdout.write(findingBrief(resolve(dir, id)));
|
|
23998
|
+
}
|
|
23999
|
+
function watchdogMarkCommand(id, status, opts) {
|
|
24000
|
+
if (!TRIAGE_STATUSES.includes(status)) {
|
|
24001
|
+
console.error(source_default.red(`Status must be one of: ${TRIAGE_STATUSES.join(", ")}`));
|
|
24002
|
+
process.exit(1);
|
|
24003
|
+
}
|
|
24004
|
+
const dir = resolveWatchdogDir(opts.dir);
|
|
24005
|
+
const f = resolve(dir, id);
|
|
24006
|
+
const entry = setTriage(dir, f.id, { status, note: opts.note, pr: opts.pr });
|
|
24007
|
+
console.log(`${source_default.bold(f.id)} \u2192 ${TRIAGE_COLOR[entry.status](entry.status)}${entry.pr ? ` (${entry.pr})` : ""}`);
|
|
24008
|
+
}
|
|
24009
|
+
function watchdogPathCommand(opts) {
|
|
24010
|
+
console.log(resolveWatchdogDir(opts.dir));
|
|
24011
|
+
}
|
|
24012
|
+
|
|
23513
24013
|
// src/commands/scan.ts
|
|
23514
|
-
var
|
|
23515
|
-
var
|
|
24014
|
+
var import_node_fs12 = require("fs");
|
|
24015
|
+
var import_node_path11 = require("path");
|
|
23516
24016
|
|
|
23517
24017
|
// ../../node_modules/.pnpm/ora@8.2.0/node_modules/ora/index.js
|
|
23518
24018
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
@@ -23840,7 +24340,7 @@ var {
|
|
|
23840
24340
|
*
|
|
23841
24341
|
* @internal
|
|
23842
24342
|
*/
|
|
23843
|
-
load,
|
|
24343
|
+
load: load2,
|
|
23844
24344
|
/**
|
|
23845
24345
|
* Unload the listeners. Likely you never need to call this, unless
|
|
23846
24346
|
* doing a rather deep integration with signal-exit functionality.
|
|
@@ -27141,7 +27641,7 @@ function isTestPath(relativePath) {
|
|
|
27141
27641
|
function rustCodeLines(lines) {
|
|
27142
27642
|
const out = [];
|
|
27143
27643
|
let commentDepth = 0;
|
|
27144
|
-
let
|
|
27644
|
+
let str3 = null;
|
|
27145
27645
|
for (const line of lines) {
|
|
27146
27646
|
let code = "";
|
|
27147
27647
|
let i = 0;
|
|
@@ -27165,15 +27665,15 @@ function rustCodeLines(lines) {
|
|
|
27165
27665
|
i += 1;
|
|
27166
27666
|
continue;
|
|
27167
27667
|
}
|
|
27168
|
-
if (
|
|
27169
|
-
if (
|
|
27668
|
+
if (str3) {
|
|
27669
|
+
if (str3.raw) {
|
|
27170
27670
|
if (c === '"') {
|
|
27171
27671
|
let hashes = 0;
|
|
27172
27672
|
while (line[i + 1 + hashes] === "#") hashes += 1;
|
|
27173
|
-
if (hashes >=
|
|
27174
|
-
code += " ".repeat(1 +
|
|
27175
|
-
i += 1 +
|
|
27176
|
-
|
|
27673
|
+
if (hashes >= str3.hashes) {
|
|
27674
|
+
code += " ".repeat(1 + str3.hashes);
|
|
27675
|
+
i += 1 + str3.hashes;
|
|
27676
|
+
str3 = null;
|
|
27177
27677
|
continue;
|
|
27178
27678
|
}
|
|
27179
27679
|
}
|
|
@@ -27187,7 +27687,7 @@ function rustCodeLines(lines) {
|
|
|
27187
27687
|
continue;
|
|
27188
27688
|
}
|
|
27189
27689
|
if (c === '"') {
|
|
27190
|
-
|
|
27690
|
+
str3 = null;
|
|
27191
27691
|
code += " ";
|
|
27192
27692
|
i += 1;
|
|
27193
27693
|
continue;
|
|
@@ -27209,14 +27709,14 @@ function rustCodeLines(lines) {
|
|
|
27209
27709
|
if (i === 0 || !/[A-Za-z0-9_]/.test(line[i - 1])) {
|
|
27210
27710
|
const raw = /^b?r(#*)"/.exec(line.slice(i));
|
|
27211
27711
|
if (raw) {
|
|
27212
|
-
|
|
27712
|
+
str3 = { raw: true, hashes: raw[1].length };
|
|
27213
27713
|
code += " ".repeat(raw[0].length);
|
|
27214
27714
|
i += raw[0].length;
|
|
27215
27715
|
continue;
|
|
27216
27716
|
}
|
|
27217
27717
|
}
|
|
27218
27718
|
if (c === '"') {
|
|
27219
|
-
|
|
27719
|
+
str3 = { raw: false, hashes: 0 };
|
|
27220
27720
|
code += " ";
|
|
27221
27721
|
i += 1;
|
|
27222
27722
|
continue;
|
|
@@ -27426,8 +27926,8 @@ function meetsFailThreshold(findings, threshold) {
|
|
|
27426
27926
|
}
|
|
27427
27927
|
|
|
27428
27928
|
// ../../packages/scan/src/node/walk.ts
|
|
27429
|
-
var
|
|
27430
|
-
var
|
|
27929
|
+
var import_node_fs10 = require("fs");
|
|
27930
|
+
var import_node_path8 = require("path");
|
|
27431
27931
|
function compileExcludes(patterns) {
|
|
27432
27932
|
const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
|
|
27433
27933
|
if (matchers.length === 0) return () => false;
|
|
@@ -27498,7 +27998,7 @@ function matchPrefix(parts, segs) {
|
|
|
27498
27998
|
}
|
|
27499
27999
|
function readIgnoreFile(root) {
|
|
27500
28000
|
try {
|
|
27501
|
-
return (0,
|
|
28001
|
+
return (0, import_node_fs10.readFileSync)((0, import_node_path8.join)(root, ".threatcrushignore"), "utf-8").split("\n");
|
|
27502
28002
|
} catch {
|
|
27503
28003
|
return [];
|
|
27504
28004
|
}
|
|
@@ -27514,16 +28014,16 @@ function scanPath(targetPath, options = {}) {
|
|
|
27514
28014
|
let excluded = 0;
|
|
27515
28015
|
const rootIsDirectory = (() => {
|
|
27516
28016
|
try {
|
|
27517
|
-
return (0,
|
|
28017
|
+
return (0, import_node_fs10.statSync)(targetPath).isDirectory();
|
|
27518
28018
|
} catch {
|
|
27519
28019
|
return true;
|
|
27520
28020
|
}
|
|
27521
28021
|
})();
|
|
27522
|
-
const walkRoot = rootIsDirectory ? targetPath : (0,
|
|
28022
|
+
const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path8.dirname)(targetPath);
|
|
27523
28023
|
const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
|
|
27524
28024
|
const scanFile = (fullPath, filename) => {
|
|
27525
28025
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
27526
|
-
const extension = (0,
|
|
28026
|
+
const extension = (0, import_node_path8.extname)(filename).toLowerCase();
|
|
27527
28027
|
const isManifest = filename === "package.json" || filename === "requirements.txt";
|
|
27528
28028
|
const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
|
|
27529
28029
|
const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
|
|
@@ -27535,26 +28035,26 @@ function scanPath(targetPath, options = {}) {
|
|
|
27535
28035
|
let handle;
|
|
27536
28036
|
let declared = null;
|
|
27537
28037
|
try {
|
|
27538
|
-
handle = (0,
|
|
28038
|
+
handle = (0, import_node_fs10.openSync)(fullPath, "r");
|
|
27539
28039
|
} catch {
|
|
27540
28040
|
unreadable.push(relativePath);
|
|
27541
28041
|
return;
|
|
27542
28042
|
}
|
|
27543
28043
|
try {
|
|
27544
|
-
if ((0,
|
|
28044
|
+
if ((0, import_node_fs10.fstatSync)(handle).size > maxFileBytes) return;
|
|
27545
28045
|
if (mayDeclareInterpreter) {
|
|
27546
28046
|
const prefix = Buffer.alloc(128);
|
|
27547
|
-
const read = (0,
|
|
28047
|
+
const read = (0, import_node_fs10.readSync)(handle, prefix, 0, prefix.length, 0);
|
|
27548
28048
|
declared = languageOfShebang(prefix.subarray(0, read).toString("utf-8").split("\n", 1)[0] ?? "");
|
|
27549
28049
|
if (!declared) return;
|
|
27550
28050
|
}
|
|
27551
|
-
text = (0,
|
|
28051
|
+
text = (0, import_node_fs10.readFileSync)(handle, "utf-8");
|
|
27552
28052
|
} catch {
|
|
27553
28053
|
unreadable.push(relativePath);
|
|
27554
28054
|
return;
|
|
27555
28055
|
} finally {
|
|
27556
28056
|
try {
|
|
27557
|
-
(0,
|
|
28057
|
+
(0, import_node_fs10.closeSync)(handle);
|
|
27558
28058
|
} catch {
|
|
27559
28059
|
}
|
|
27560
28060
|
}
|
|
@@ -27572,13 +28072,13 @@ function scanPath(targetPath, options = {}) {
|
|
|
27572
28072
|
const walk = (currentPath) => {
|
|
27573
28073
|
let entries;
|
|
27574
28074
|
try {
|
|
27575
|
-
entries = (0,
|
|
28075
|
+
entries = (0, import_node_fs10.readdirSync)(currentPath, { withFileTypes: true });
|
|
27576
28076
|
} catch {
|
|
27577
28077
|
unreadable.push(toRelative(walkRoot, currentPath));
|
|
27578
28078
|
return;
|
|
27579
28079
|
}
|
|
27580
28080
|
for (const entry of entries) {
|
|
27581
|
-
const fullPath = (0,
|
|
28081
|
+
const fullPath = (0, import_node_path8.join)(currentPath, entry.name);
|
|
27582
28082
|
const relativePath = toRelative(walkRoot, fullPath);
|
|
27583
28083
|
if (entry.isDirectory()) {
|
|
27584
28084
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
@@ -27602,7 +28102,7 @@ function scanPath(targetPath, options = {}) {
|
|
|
27602
28102
|
} else if (isExcluded(toRelative(walkRoot, targetPath))) {
|
|
27603
28103
|
excluded += 1;
|
|
27604
28104
|
} else {
|
|
27605
|
-
scanFile(targetPath, (0,
|
|
28105
|
+
scanFile(targetPath, (0, import_node_path8.basename)(targetPath));
|
|
27606
28106
|
}
|
|
27607
28107
|
if (options.missingControls) findings.push(...controls.findings());
|
|
27608
28108
|
const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
|
|
@@ -27634,22 +28134,22 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
|
|
|
27634
28134
|
}
|
|
27635
28135
|
}
|
|
27636
28136
|
function toRelative(base, target) {
|
|
27637
|
-
const rel = (0,
|
|
27638
|
-
return (rel === "" ? target : rel).split(
|
|
28137
|
+
const rel = (0, import_node_path8.relative)(base, target);
|
|
28138
|
+
return (rel === "" ? target : rel).split(import_node_path8.sep).join("/");
|
|
27639
28139
|
}
|
|
27640
28140
|
|
|
27641
28141
|
// ../../packages/scan/src/node/dependencies.ts
|
|
27642
|
-
var
|
|
27643
|
-
var
|
|
28142
|
+
var import_node_fs11 = require("fs");
|
|
28143
|
+
var import_node_path9 = require("path");
|
|
27644
28144
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
27645
28145
|
async function scanDependencies(targetPath) {
|
|
27646
28146
|
const findings = [];
|
|
27647
28147
|
for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
|
|
27648
|
-
const lockPath = (0,
|
|
27649
|
-
if (!(0,
|
|
28148
|
+
const lockPath = (0, import_node_path9.join)(targetPath, file);
|
|
28149
|
+
if (!(0, import_node_fs11.existsSync)(lockPath)) continue;
|
|
27650
28150
|
let deps;
|
|
27651
28151
|
try {
|
|
27652
|
-
deps = dedupe(parse2((0,
|
|
28152
|
+
deps = dedupe(parse2((0, import_node_fs11.readFileSync)(lockPath, "utf-8")));
|
|
27653
28153
|
} catch {
|
|
27654
28154
|
continue;
|
|
27655
28155
|
}
|
|
@@ -27863,12 +28363,12 @@ async function queryOsv(name, version, ecosystem) {
|
|
|
27863
28363
|
}
|
|
27864
28364
|
|
|
27865
28365
|
// ../../packages/scan/src/node/sarif.ts
|
|
27866
|
-
var
|
|
27867
|
-
var
|
|
28366
|
+
var import_node_crypto3 = require("crypto");
|
|
28367
|
+
var import_node_path10 = require("path");
|
|
27868
28368
|
var FINGERPRINT_KEY = "threatcrush/contentHash/v1";
|
|
27869
28369
|
function fingerprintOf(finding) {
|
|
27870
28370
|
const content = finding.excerpt.replace(/\s+/g, " ").trim();
|
|
27871
|
-
return (0,
|
|
28371
|
+
return (0, import_node_crypto3.createHash)("sha256").update(`${finding.ruleId}
|
|
27872
28372
|
${finding.file}
|
|
27873
28373
|
${content}`).digest("hex").slice(0, 32);
|
|
27874
28374
|
}
|
|
@@ -27902,11 +28402,11 @@ function securitySeverity(severity) {
|
|
|
27902
28402
|
}
|
|
27903
28403
|
}
|
|
27904
28404
|
function toArtifactUri(filePath, base, prefix = "", root = base) {
|
|
27905
|
-
const absolute = (0,
|
|
27906
|
-
const relativePath = (0,
|
|
28405
|
+
const absolute = (0, import_node_path10.isAbsolute)(filePath) ? filePath : (0, import_node_path10.resolve)(root, filePath);
|
|
28406
|
+
const relativePath = (0, import_node_path10.relative)(base, absolute);
|
|
27907
28407
|
const escapedOut = relativePath.startsWith("..") || relativePath === "";
|
|
27908
28408
|
const chosen = escapedOut ? absolute : relativePath;
|
|
27909
|
-
const posix = chosen.split(
|
|
28409
|
+
const posix = chosen.split(import_node_path10.sep).join("/").replace(/^\.\//, "");
|
|
27910
28410
|
if (!prefix || escapedOut) return posix;
|
|
27911
28411
|
const trimmed = prefix.replace(/^\/+|\/+$/g, "");
|
|
27912
28412
|
return trimmed ? `${trimmed}/${posix}` : posix;
|
|
@@ -27996,11 +28496,11 @@ ${finding.consequence}` : `**${finding.title}**`
|
|
|
27996
28496
|
// src/commands/scan.ts
|
|
27997
28497
|
function readVersion() {
|
|
27998
28498
|
for (const candidate of [
|
|
27999
|
-
(0,
|
|
28000
|
-
(0,
|
|
28499
|
+
(0, import_node_path11.join)(__dirname, "..", "package.json"),
|
|
28500
|
+
(0, import_node_path11.join)(__dirname, "..", "..", "package.json")
|
|
28001
28501
|
]) {
|
|
28002
28502
|
try {
|
|
28003
|
-
return JSON.parse((0,
|
|
28503
|
+
return JSON.parse((0, import_node_fs12.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
|
|
28004
28504
|
} catch {
|
|
28005
28505
|
}
|
|
28006
28506
|
}
|
|
@@ -28067,7 +28567,7 @@ async function scanCommand(targetPath, options = {}) {
|
|
|
28067
28567
|
const say = machineReadable ? (line) => process.stderr.write(`${line}
|
|
28068
28568
|
`) : (line) => process.stdout.write(`${line}
|
|
28069
28569
|
`);
|
|
28070
|
-
if (!(0,
|
|
28570
|
+
if (!(0, import_node_fs12.existsSync)(targetPath)) {
|
|
28071
28571
|
say(source_default.red(`Scan target does not exist: ${targetPath}`));
|
|
28072
28572
|
process.exitCode = 2;
|
|
28073
28573
|
return failedResult(targetPath, `no such path: ${targetPath}`);
|
|
@@ -28163,7 +28663,7 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
28163
28663
|
// and it fails silently. `--path-prefix` covers the remaining case:
|
|
28164
28664
|
// a scan run from inside the subdirectory it is scanning.
|
|
28165
28665
|
base: process.cwd(),
|
|
28166
|
-
root: (0,
|
|
28666
|
+
root: (0, import_node_path11.resolve)(outcome.root)
|
|
28167
28667
|
}) : {
|
|
28168
28668
|
tool: "threatcrush",
|
|
28169
28669
|
version: PKG_VERSION2,
|
|
@@ -28177,8 +28677,8 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
|
|
|
28177
28677
|
const serialized = `${JSON.stringify(payload, null, 2)}
|
|
28178
28678
|
`;
|
|
28179
28679
|
if (options.output) {
|
|
28180
|
-
(0,
|
|
28181
|
-
(0,
|
|
28680
|
+
(0, import_node_fs12.mkdirSync)((0, import_node_path11.dirname)((0, import_node_path11.resolve)(options.output)), { recursive: true });
|
|
28681
|
+
(0, import_node_fs12.writeFileSync)(options.output, serialized, "utf-8");
|
|
28182
28682
|
say(
|
|
28183
28683
|
source_default.gray(
|
|
28184
28684
|
` ${format.toUpperCase()} written to ${options.output} (${outcome.findings.length} finding(s))`
|
|
@@ -28230,30 +28730,30 @@ function printHuman(outcome) {
|
|
|
28230
28730
|
}
|
|
28231
28731
|
|
|
28232
28732
|
// src/commands/init.ts
|
|
28233
|
-
var
|
|
28733
|
+
var import_node_fs14 = require("fs");
|
|
28234
28734
|
var import_node_child_process = require("child_process");
|
|
28235
28735
|
|
|
28236
28736
|
// src/core/cli-config.ts
|
|
28237
|
-
var
|
|
28238
|
-
var
|
|
28737
|
+
var import_node_fs13 = require("fs");
|
|
28738
|
+
var import_node_path12 = require("path");
|
|
28239
28739
|
var import_node_os4 = require("os");
|
|
28240
|
-
var CLI_CONFIG_DIR = (0,
|
|
28241
|
-
var CLI_CONFIG_PATH = (0,
|
|
28740
|
+
var CLI_CONFIG_DIR = (0, import_node_path12.join)((0, import_node_os4.homedir)(), ".threatcrush");
|
|
28741
|
+
var CLI_CONFIG_PATH = (0, import_node_path12.join)(CLI_CONFIG_DIR, "config.json");
|
|
28242
28742
|
function apiUrl() {
|
|
28243
28743
|
return process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
28244
28744
|
}
|
|
28245
28745
|
function readCliConfig() {
|
|
28246
28746
|
try {
|
|
28247
|
-
return JSON.parse((0,
|
|
28747
|
+
return JSON.parse((0, import_node_fs13.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
|
|
28248
28748
|
} catch {
|
|
28249
28749
|
return {};
|
|
28250
28750
|
}
|
|
28251
28751
|
}
|
|
28252
28752
|
function writeCliConfig(config) {
|
|
28253
|
-
if (!(0,
|
|
28254
|
-
(0,
|
|
28753
|
+
if (!(0, import_node_fs13.existsSync)(CLI_CONFIG_DIR)) (0, import_node_fs13.mkdirSync)(CLI_CONFIG_DIR, { recursive: true });
|
|
28754
|
+
(0, import_node_fs13.writeFileSync)(CLI_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
28255
28755
|
try {
|
|
28256
|
-
(0,
|
|
28756
|
+
(0, import_node_fs13.chmodSync)(CLI_CONFIG_PATH, 384);
|
|
28257
28757
|
} catch {
|
|
28258
28758
|
}
|
|
28259
28759
|
}
|
|
@@ -28383,8 +28883,8 @@ function askPiped(question, mask) {
|
|
|
28383
28883
|
if (reader.lines.length > 0) return Promise.resolve(settle(reader.lines.shift()));
|
|
28384
28884
|
if (reader.ended) return Promise.resolve(settle(null));
|
|
28385
28885
|
reader.rl.resume();
|
|
28386
|
-
return new Promise((
|
|
28387
|
-
reader.waiting = (line) =>
|
|
28886
|
+
return new Promise((resolve6) => {
|
|
28887
|
+
reader.waiting = (line) => resolve6(settle(line));
|
|
28388
28888
|
});
|
|
28389
28889
|
}
|
|
28390
28890
|
function askTerminal(question, mask) {
|
|
@@ -28392,20 +28892,20 @@ function askTerminal(question, mask) {
|
|
|
28392
28892
|
cb();
|
|
28393
28893
|
} }) : process.stdout;
|
|
28394
28894
|
const rl = import_node_readline2.default.createInterface({ input: process.stdin, output, terminal: true });
|
|
28395
|
-
return new Promise((
|
|
28895
|
+
return new Promise((resolve6) => {
|
|
28396
28896
|
let settled = false;
|
|
28397
28897
|
rl.on("close", () => {
|
|
28398
28898
|
if (settled) return;
|
|
28399
28899
|
settled = true;
|
|
28400
28900
|
process.stdout.write("\n");
|
|
28401
|
-
|
|
28901
|
+
resolve6(null);
|
|
28402
28902
|
});
|
|
28403
28903
|
if (mask) process.stdout.write(question);
|
|
28404
28904
|
rl.question(mask ? "" : question, (answer) => {
|
|
28405
28905
|
settled = true;
|
|
28406
28906
|
rl.close();
|
|
28407
28907
|
if (mask) process.stdout.write("\n");
|
|
28408
|
-
|
|
28908
|
+
resolve6(answer);
|
|
28409
28909
|
});
|
|
28410
28910
|
});
|
|
28411
28911
|
}
|
|
@@ -28415,11 +28915,11 @@ function ask(question, opts = {}) {
|
|
|
28415
28915
|
}
|
|
28416
28916
|
|
|
28417
28917
|
// src/core/link-login.ts
|
|
28418
|
-
var
|
|
28918
|
+
var import_node_crypto4 = require("crypto");
|
|
28419
28919
|
var import_node_os5 = require("os");
|
|
28420
28920
|
function createPkce() {
|
|
28421
|
-
const verifier = (0,
|
|
28422
|
-
const challenge = (0,
|
|
28921
|
+
const verifier = (0, import_node_crypto4.randomBytes)(32).toString("base64url");
|
|
28922
|
+
const challenge = (0, import_node_crypto4.createHash)("sha256").update(verifier).digest("base64url");
|
|
28423
28923
|
return { verifier, challenge };
|
|
28424
28924
|
}
|
|
28425
28925
|
async function startLinkLogin(pkce, deviceName = (0, import_node_os5.hostname)()) {
|
|
@@ -28439,7 +28939,7 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os5.hostname)()
|
|
|
28439
28939
|
}
|
|
28440
28940
|
return data;
|
|
28441
28941
|
}
|
|
28442
|
-
var sleep = (ms) => new Promise((
|
|
28942
|
+
var sleep = (ms) => new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
28443
28943
|
async function waitForApproval(request, pkce, opts = {}) {
|
|
28444
28944
|
const wait = opts.sleepMs ?? sleep;
|
|
28445
28945
|
const now = opts.now ?? Date.now;
|
|
@@ -28723,7 +29223,7 @@ function binaryExists(name) {
|
|
|
28723
29223
|
}
|
|
28724
29224
|
}
|
|
28725
29225
|
function findLogPath(paths) {
|
|
28726
|
-
return paths.find((p) => (0,
|
|
29226
|
+
return paths.find((p) => (0, import_node_fs14.existsSync)(p));
|
|
28727
29227
|
}
|
|
28728
29228
|
async function promptYesNo(question, fallback2) {
|
|
28729
29229
|
const hint = fallback2 ? "(Y/n)" : "(y/N)";
|
|
@@ -28867,11 +29367,11 @@ async function initCommand(opts = {}) {
|
|
|
28867
29367
|
}
|
|
28868
29368
|
} else {
|
|
28869
29369
|
const spinner2 = ora({ text: "Writing configuration files...", color: "green" }).start();
|
|
28870
|
-
(0,
|
|
28871
|
-
(0,
|
|
28872
|
-
(0,
|
|
29370
|
+
(0, import_node_fs14.mkdirSync)(confDDir, { recursive: true });
|
|
29371
|
+
(0, import_node_fs14.mkdirSync)("/var/log/threatcrush", { recursive: true });
|
|
29372
|
+
(0, import_node_fs14.mkdirSync)("/var/lib/threatcrush", { recursive: true });
|
|
28873
29373
|
const mainConfig = generateDefaultConfig(detected.map((d) => d.name));
|
|
28874
|
-
(0,
|
|
29374
|
+
(0, import_node_fs14.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
|
|
28875
29375
|
for (const svc of detected) {
|
|
28876
29376
|
const svcDef = SERVICES_TO_DETECT.find((s) => s.name === svc.name);
|
|
28877
29377
|
if (!svcDef) continue;
|
|
@@ -28880,7 +29380,7 @@ async function initCommand(opts = {}) {
|
|
|
28880
29380
|
...svcDef.moduleConfig,
|
|
28881
29381
|
log_path: svc.logPath || svcDef.logPaths[0]
|
|
28882
29382
|
});
|
|
28883
|
-
(0,
|
|
29383
|
+
(0, import_node_fs14.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
|
|
28884
29384
|
}
|
|
28885
29385
|
spinner2.succeed("Configuration written successfully");
|
|
28886
29386
|
console.log();
|
|
@@ -28898,8 +29398,8 @@ async function initCommand(opts = {}) {
|
|
|
28898
29398
|
}
|
|
28899
29399
|
function checkWriteAccess(dir) {
|
|
28900
29400
|
try {
|
|
28901
|
-
if (!(0,
|
|
28902
|
-
(0,
|
|
29401
|
+
if (!(0, import_node_fs14.existsSync)(dir)) {
|
|
29402
|
+
(0, import_node_fs14.mkdirSync)(dir, { recursive: true });
|
|
28903
29403
|
}
|
|
28904
29404
|
return true;
|
|
28905
29405
|
} catch {
|
|
@@ -28917,8 +29417,8 @@ var BUILTIN_MODULES = [
|
|
|
28917
29417
|
];
|
|
28918
29418
|
|
|
28919
29419
|
// src/core/module-loader.ts
|
|
28920
|
-
var
|
|
28921
|
-
var
|
|
29420
|
+
var import_node_fs15 = require("fs");
|
|
29421
|
+
var import_node_path13 = require("path");
|
|
28922
29422
|
var import_toml2 = __toESM(require_toml());
|
|
28923
29423
|
init_paths();
|
|
28924
29424
|
function discoverModules(moduleDir, confDir) {
|
|
@@ -28926,22 +29426,22 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28926
29426
|
const configs = loadModuleConfigs(confDir || PATHS.confD);
|
|
28927
29427
|
const searchPaths = [
|
|
28928
29428
|
moduleDir || PATHS.moduleDir,
|
|
28929
|
-
(0,
|
|
29429
|
+
(0, import_node_path13.resolve)(process.cwd(), "modules")
|
|
28930
29430
|
];
|
|
28931
|
-
const builtinDir = (0,
|
|
28932
|
-
if ((0,
|
|
29431
|
+
const builtinDir = (0, import_node_path13.resolve)(__dirname || ".", "..", "modules");
|
|
29432
|
+
if ((0, import_node_fs15.existsSync)(builtinDir)) {
|
|
28933
29433
|
searchPaths.push(builtinDir);
|
|
28934
29434
|
}
|
|
28935
29435
|
for (const basePath of searchPaths) {
|
|
28936
|
-
if (!(0,
|
|
28937
|
-
const entries = (0,
|
|
29436
|
+
if (!(0, import_node_fs15.existsSync)(basePath)) continue;
|
|
29437
|
+
const entries = (0, import_node_fs15.readdirSync)(basePath, { withFileTypes: true });
|
|
28938
29438
|
for (const entry of entries) {
|
|
28939
29439
|
if (!entry.isDirectory()) continue;
|
|
28940
|
-
const modPath = (0,
|
|
28941
|
-
const manifestPath = (0,
|
|
28942
|
-
if (!(0,
|
|
29440
|
+
const modPath = (0, import_node_path13.join)(basePath, entry.name);
|
|
29441
|
+
const manifestPath = (0, import_node_path13.join)(modPath, "mod.toml");
|
|
29442
|
+
if (!(0, import_node_fs15.existsSync)(manifestPath)) continue;
|
|
28943
29443
|
try {
|
|
28944
|
-
const raw = (0,
|
|
29444
|
+
const raw = (0, import_node_fs15.readFileSync)(manifestPath, "utf-8");
|
|
28945
29445
|
const manifest = import_toml2.default.parse(raw);
|
|
28946
29446
|
const config = configs.get(manifest.module.name) || { enabled: true };
|
|
28947
29447
|
modules.push({
|
|
@@ -28967,21 +29467,21 @@ function discoverModules(moduleDir, confDir) {
|
|
|
28967
29467
|
init_ipc_client();
|
|
28968
29468
|
|
|
28969
29469
|
// src/daemon/pidfile.ts
|
|
28970
|
-
var
|
|
29470
|
+
var import_node_fs16 = require("fs");
|
|
28971
29471
|
init_paths();
|
|
28972
29472
|
function writePidFile() {
|
|
28973
29473
|
ensureRuntimeDirs();
|
|
28974
|
-
(0,
|
|
29474
|
+
(0, import_node_fs16.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
|
|
28975
29475
|
}
|
|
28976
29476
|
function readPidFile() {
|
|
28977
|
-
if (!(0,
|
|
28978
|
-
const raw = (0,
|
|
29477
|
+
if (!(0, import_node_fs16.existsSync)(PATHS.pidFile)) return null;
|
|
29478
|
+
const raw = (0, import_node_fs16.readFileSync)(PATHS.pidFile, "utf-8").trim();
|
|
28979
29479
|
const pid = parseInt(raw, 10);
|
|
28980
29480
|
return Number.isFinite(pid) ? pid : null;
|
|
28981
29481
|
}
|
|
28982
29482
|
function removePidFile() {
|
|
28983
29483
|
try {
|
|
28984
|
-
if ((0,
|
|
29484
|
+
if ((0, import_node_fs16.existsSync)(PATHS.pidFile)) (0, import_node_fs16.unlinkSync)(PATHS.pidFile);
|
|
28985
29485
|
} catch {
|
|
28986
29486
|
}
|
|
28987
29487
|
}
|
|
@@ -28993,7 +29493,7 @@ function procStatState(stat) {
|
|
|
28993
29493
|
function isZombie(pid) {
|
|
28994
29494
|
let stat;
|
|
28995
29495
|
try {
|
|
28996
|
-
stat = (0,
|
|
29496
|
+
stat = (0, import_node_fs16.readFileSync)(`/proc/${pid}/stat`, "utf-8");
|
|
28997
29497
|
} catch {
|
|
28998
29498
|
return false;
|
|
28999
29499
|
}
|
|
@@ -29119,24 +29619,24 @@ function formatUptime2(seconds) {
|
|
|
29119
29619
|
|
|
29120
29620
|
// src/commands/modules.ts
|
|
29121
29621
|
var import_node_child_process2 = require("child_process");
|
|
29122
|
-
var
|
|
29123
|
-
var
|
|
29622
|
+
var import_node_fs18 = require("fs");
|
|
29623
|
+
var import_node_path15 = require("path");
|
|
29124
29624
|
var import_toml3 = __toESM(require_toml());
|
|
29125
29625
|
init_paths();
|
|
29126
29626
|
|
|
29127
29627
|
// src/daemon/module-trust.ts
|
|
29128
|
-
var
|
|
29129
|
-
var
|
|
29130
|
-
var
|
|
29628
|
+
var import_node_crypto5 = require("crypto");
|
|
29629
|
+
var import_node_fs17 = require("fs");
|
|
29630
|
+
var import_node_path14 = require("path");
|
|
29131
29631
|
init_paths();
|
|
29132
|
-
var TRUST_FILE = (0,
|
|
29133
|
-
var PUBLISHER_KEYS_FILE = (0,
|
|
29632
|
+
var TRUST_FILE = (0, import_node_path14.join)(PATHS.configDir, "trusted-modules.json");
|
|
29633
|
+
var PUBLISHER_KEYS_FILE = (0, import_node_path14.join)(PATHS.configDir, "publisher-keys.json");
|
|
29134
29634
|
var DIGEST_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".git"]);
|
|
29135
29635
|
function collectFiles(root, dir = root, out = []) {
|
|
29136
|
-
for (const entry of (0,
|
|
29636
|
+
for (const entry of (0, import_node_fs17.readdirSync)(dir, { withFileTypes: true }).sort(
|
|
29137
29637
|
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
29138
29638
|
)) {
|
|
29139
|
-
const full = (0,
|
|
29639
|
+
const full = (0, import_node_path14.join)(dir, entry.name);
|
|
29140
29640
|
if (entry.isSymbolicLink()) {
|
|
29141
29641
|
out.push({ path: full, isSymlink: true });
|
|
29142
29642
|
} else if (entry.isDirectory()) {
|
|
@@ -29149,26 +29649,26 @@ function collectFiles(root, dir = root, out = []) {
|
|
|
29149
29649
|
return out;
|
|
29150
29650
|
}
|
|
29151
29651
|
function computeModuleDigest(modulePath) {
|
|
29152
|
-
const hash = (0,
|
|
29652
|
+
const hash = (0, import_node_crypto5.createHash)("sha256");
|
|
29153
29653
|
for (const entry of collectFiles(modulePath)) {
|
|
29154
|
-
const relPath = (0,
|
|
29654
|
+
const relPath = (0, import_node_path14.relative)(modulePath, entry.path).split(import_node_path14.sep).join("/");
|
|
29155
29655
|
hash.update(relPath);
|
|
29156
29656
|
hash.update("\0");
|
|
29157
29657
|
if (entry.isSymlink) {
|
|
29158
29658
|
hash.update("symlink:");
|
|
29159
|
-
hash.update((0,
|
|
29659
|
+
hash.update((0, import_node_fs17.readlinkSync)(entry.path));
|
|
29160
29660
|
} else {
|
|
29161
29661
|
hash.update("file:");
|
|
29162
|
-
hash.update((0,
|
|
29662
|
+
hash.update((0, import_node_fs17.readFileSync)(entry.path));
|
|
29163
29663
|
}
|
|
29164
29664
|
hash.update("\0");
|
|
29165
29665
|
}
|
|
29166
29666
|
return hash.digest("hex");
|
|
29167
29667
|
}
|
|
29168
29668
|
function readTrustFile() {
|
|
29169
|
-
if (!(0,
|
|
29669
|
+
if (!(0, import_node_fs17.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
|
|
29170
29670
|
try {
|
|
29171
|
-
const parsed = JSON.parse((0,
|
|
29671
|
+
const parsed = JSON.parse((0, import_node_fs17.readFileSync)(TRUST_FILE, "utf-8"));
|
|
29172
29672
|
if (parsed.version !== 1 || typeof parsed.modules !== "object" || !parsed.modules) {
|
|
29173
29673
|
return { version: 1, modules: {} };
|
|
29174
29674
|
}
|
|
@@ -29178,9 +29678,9 @@ function readTrustFile() {
|
|
|
29178
29678
|
}
|
|
29179
29679
|
}
|
|
29180
29680
|
function writeTrustFile(file) {
|
|
29181
|
-
(0,
|
|
29681
|
+
(0, import_node_fs17.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
|
|
29182
29682
|
try {
|
|
29183
|
-
(0,
|
|
29683
|
+
(0, import_node_fs17.chmodSync)(TRUST_FILE, 384);
|
|
29184
29684
|
} catch {
|
|
29185
29685
|
}
|
|
29186
29686
|
}
|
|
@@ -29206,9 +29706,9 @@ function listTrustedModules() {
|
|
|
29206
29706
|
return readTrustFile().modules;
|
|
29207
29707
|
}
|
|
29208
29708
|
function readPublisherKeys() {
|
|
29209
|
-
if (!(0,
|
|
29709
|
+
if (!(0, import_node_fs17.existsSync)(PUBLISHER_KEYS_FILE)) return {};
|
|
29210
29710
|
try {
|
|
29211
|
-
const parsed = JSON.parse((0,
|
|
29711
|
+
const parsed = JSON.parse((0, import_node_fs17.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
|
|
29212
29712
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
29213
29713
|
} catch {
|
|
29214
29714
|
return {};
|
|
@@ -29217,16 +29717,16 @@ function readPublisherKeys() {
|
|
|
29217
29717
|
function verifyModuleSignature(modulePath, digest) {
|
|
29218
29718
|
const keys = readPublisherKeys();
|
|
29219
29719
|
const pinnedKeyIds = Object.keys(keys);
|
|
29220
|
-
const sigPath = (0,
|
|
29720
|
+
const sigPath = (0, import_node_path14.join)(modulePath, "mod.sig");
|
|
29221
29721
|
if (pinnedKeyIds.length === 0) {
|
|
29222
29722
|
return { ok: true };
|
|
29223
29723
|
}
|
|
29224
|
-
if (!(0,
|
|
29724
|
+
if (!(0, import_node_fs17.existsSync)(sigPath)) {
|
|
29225
29725
|
return { ok: false, reason: "publisher keys are pinned but the module ships no mod.sig" };
|
|
29226
29726
|
}
|
|
29227
29727
|
let parsed;
|
|
29228
29728
|
try {
|
|
29229
|
-
parsed = JSON.parse((0,
|
|
29729
|
+
parsed = JSON.parse((0, import_node_fs17.readFileSync)(sigPath, "utf-8"));
|
|
29230
29730
|
} catch {
|
|
29231
29731
|
return { ok: false, reason: "mod.sig is not valid JSON" };
|
|
29232
29732
|
}
|
|
@@ -29238,7 +29738,7 @@ function verifyModuleSignature(modulePath, digest) {
|
|
|
29238
29738
|
return { ok: false, reason: `mod.sig references unpinned key "${parsed.keyId}"` };
|
|
29239
29739
|
}
|
|
29240
29740
|
try {
|
|
29241
|
-
const valid = (0,
|
|
29741
|
+
const valid = (0, import_node_crypto5.verify)(
|
|
29242
29742
|
null,
|
|
29243
29743
|
Buffer.from(digest, "hex"),
|
|
29244
29744
|
publicKey,
|
|
@@ -29287,7 +29787,7 @@ function safeModuleDirName(name, label = "module name") {
|
|
|
29287
29787
|
return name;
|
|
29288
29788
|
}
|
|
29289
29789
|
function moduleDestination(dir, name, label) {
|
|
29290
|
-
return (0,
|
|
29790
|
+
return (0, import_node_path15.join)(dir, safeModuleDirName(name, label));
|
|
29291
29791
|
}
|
|
29292
29792
|
function assertSafeTarballEntries(tarPath) {
|
|
29293
29793
|
const listing = (0, import_node_child_process2.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
|
|
@@ -29300,12 +29800,12 @@ function assertSafeTarballEntries(tarPath) {
|
|
|
29300
29800
|
}
|
|
29301
29801
|
}
|
|
29302
29802
|
function validateManifest(modPath) {
|
|
29303
|
-
const manifestPath = (0,
|
|
29304
|
-
if (!(0,
|
|
29803
|
+
const manifestPath = (0, import_node_path15.join)(modPath, "mod.toml");
|
|
29804
|
+
if (!(0, import_node_fs18.existsSync)(manifestPath)) {
|
|
29305
29805
|
return { ok: false, error: `mod.toml not found at ${manifestPath}` };
|
|
29306
29806
|
}
|
|
29307
29807
|
try {
|
|
29308
|
-
const raw = (0,
|
|
29808
|
+
const raw = (0, import_node_fs18.readFileSync)(manifestPath, "utf-8");
|
|
29309
29809
|
const parsed = import_toml3.default.parse(raw);
|
|
29310
29810
|
const name = parsed.module?.name;
|
|
29311
29811
|
const version = parsed.module?.version;
|
|
@@ -29367,8 +29867,8 @@ async function modulesInstallCommand(source) {
|
|
|
29367
29867
|
console.log();
|
|
29368
29868
|
const dir = modulesDir();
|
|
29369
29869
|
if (source.startsWith("./") || source.startsWith("/") || source.startsWith("~")) {
|
|
29370
|
-
const absPath = (0,
|
|
29371
|
-
if (!(0,
|
|
29870
|
+
const absPath = (0, import_node_path15.resolve)(source.startsWith("~") ? source.replace("~", process.env.HOME || "") : source);
|
|
29871
|
+
if (!(0, import_node_fs18.existsSync)(absPath)) {
|
|
29372
29872
|
console.log(source_default.red(` \u2717 Path not found: ${absPath}
|
|
29373
29873
|
`));
|
|
29374
29874
|
return;
|
|
@@ -29387,7 +29887,7 @@ async function modulesInstallCommand(source) {
|
|
|
29387
29887
|
`));
|
|
29388
29888
|
return;
|
|
29389
29889
|
}
|
|
29390
|
-
if ((0,
|
|
29890
|
+
if ((0, import_node_fs18.existsSync)(dest2)) {
|
|
29391
29891
|
console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
|
|
29392
29892
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
|
|
29393
29893
|
`));
|
|
@@ -29395,7 +29895,7 @@ async function modulesInstallCommand(source) {
|
|
|
29395
29895
|
}
|
|
29396
29896
|
const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
|
|
29397
29897
|
try {
|
|
29398
|
-
(0,
|
|
29898
|
+
(0, import_node_fs18.cpSync)(absPath, dest2, { recursive: true, dereference: true });
|
|
29399
29899
|
spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
|
|
29400
29900
|
} catch (err) {
|
|
29401
29901
|
spinner2.fail(`Copy failed: ${err.message}`);
|
|
@@ -29411,14 +29911,14 @@ async function modulesInstallCommand(source) {
|
|
|
29411
29911
|
let name;
|
|
29412
29912
|
let dest2;
|
|
29413
29913
|
try {
|
|
29414
|
-
name = safeModuleDirName((0,
|
|
29914
|
+
name = safeModuleDirName((0, import_node_path15.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
|
|
29415
29915
|
dest2 = moduleDestination(dir, name);
|
|
29416
29916
|
} catch (err) {
|
|
29417
29917
|
console.log(source_default.red(` x ${err.message}
|
|
29418
29918
|
`));
|
|
29419
29919
|
return;
|
|
29420
29920
|
}
|
|
29421
|
-
if ((0,
|
|
29921
|
+
if ((0, import_node_fs18.existsSync)(dest2)) {
|
|
29422
29922
|
console.log(source_default.yellow(` ! ${name} is already installed at ${dest2}`));
|
|
29423
29923
|
console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${name}`)} first.
|
|
29424
29924
|
`));
|
|
@@ -29435,7 +29935,7 @@ async function modulesInstallCommand(source) {
|
|
|
29435
29935
|
if (!check.ok) {
|
|
29436
29936
|
spinner2.fail(check.error);
|
|
29437
29937
|
try {
|
|
29438
|
-
(0,
|
|
29938
|
+
(0, import_node_fs18.rmSync)(dest2, { recursive: true, force: true });
|
|
29439
29939
|
} catch {
|
|
29440
29940
|
}
|
|
29441
29941
|
return;
|
|
@@ -29482,7 +29982,7 @@ async function modulesInstallCommand(source) {
|
|
|
29482
29982
|
`));
|
|
29483
29983
|
return;
|
|
29484
29984
|
}
|
|
29485
|
-
if ((0,
|
|
29985
|
+
if ((0, import_node_fs18.existsSync)(dest)) {
|
|
29486
29986
|
console.log(source_default.yellow(` ! ${mod.slug} is already installed at ${dest}
|
|
29487
29987
|
`));
|
|
29488
29988
|
return;
|
|
@@ -29508,7 +30008,7 @@ async function modulesInstallCommand(source) {
|
|
|
29508
30008
|
if (!check.ok) {
|
|
29509
30009
|
cloneSpinner.fail(check.error);
|
|
29510
30010
|
try {
|
|
29511
|
-
(0,
|
|
30011
|
+
(0, import_node_fs18.rmSync)(dest, { recursive: true, force: true });
|
|
29512
30012
|
} catch {
|
|
29513
30013
|
}
|
|
29514
30014
|
return;
|
|
@@ -29522,11 +30022,11 @@ async function modulesInstallCommand(source) {
|
|
|
29522
30022
|
dlSpinner.fail(`HTTP ${res.status}`);
|
|
29523
30023
|
return;
|
|
29524
30024
|
}
|
|
29525
|
-
const tar = (0,
|
|
29526
|
-
(0,
|
|
30025
|
+
const tar = (0, import_node_path15.join)(dir, `${mod.slug}.tar.gz`);
|
|
30026
|
+
(0, import_node_fs18.writeFileSync)(tar, Buffer.from(await res.arrayBuffer()));
|
|
29527
30027
|
assertSafeTarballEntries(tar);
|
|
29528
30028
|
(0, import_node_child_process2.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
|
|
29529
|
-
(0,
|
|
30029
|
+
(0, import_node_fs18.rmSync)(tar, { force: true });
|
|
29530
30030
|
const check = validateManifest(dest);
|
|
29531
30031
|
if (!check.ok) {
|
|
29532
30032
|
dlSpinner.fail(check.error);
|
|
@@ -29558,7 +30058,7 @@ async function modulesRemoveCommand(name) {
|
|
|
29558
30058
|
`));
|
|
29559
30059
|
return;
|
|
29560
30060
|
}
|
|
29561
|
-
if (!(0,
|
|
30061
|
+
if (!(0, import_node_fs18.existsSync)(target)) {
|
|
29562
30062
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
29563
30063
|
`));
|
|
29564
30064
|
return;
|
|
@@ -29568,7 +30068,7 @@ async function modulesRemoveCommand(name) {
|
|
|
29568
30068
|
console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
|
|
29569
30069
|
}
|
|
29570
30070
|
try {
|
|
29571
|
-
(0,
|
|
30071
|
+
(0, import_node_fs18.rmSync)(target, { recursive: true, force: true });
|
|
29572
30072
|
untrustModule(name);
|
|
29573
30073
|
console.log(source_default.green(` \u2713 Removed ${name} from ${dir}
|
|
29574
30074
|
`));
|
|
@@ -29593,7 +30093,7 @@ async function modulesTrustCommand(name) {
|
|
|
29593
30093
|
`));
|
|
29594
30094
|
return;
|
|
29595
30095
|
}
|
|
29596
|
-
if (!(0,
|
|
30096
|
+
if (!(0, import_node_fs18.existsSync)(target)) {
|
|
29597
30097
|
console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
|
|
29598
30098
|
`));
|
|
29599
30099
|
return;
|
|
@@ -30028,7 +30528,7 @@ async function pentestCommand(targetUrl) {
|
|
|
30028
30528
|
}
|
|
30029
30529
|
|
|
30030
30530
|
// src/commands/ai-scan.ts
|
|
30031
|
-
var
|
|
30531
|
+
var import_node_fs19 = require("fs");
|
|
30032
30532
|
|
|
30033
30533
|
// src/aiscan/probes.ts
|
|
30034
30534
|
function makeCanary() {
|
|
@@ -30305,7 +30805,7 @@ async function aiScanMoshCommand(file, args) {
|
|
|
30305
30805
|
console.log();
|
|
30306
30806
|
let source;
|
|
30307
30807
|
try {
|
|
30308
|
-
source = (0,
|
|
30808
|
+
source = (0, import_node_fs19.readFileSync)(file, "utf-8");
|
|
30309
30809
|
} catch (err) {
|
|
30310
30810
|
logger.error(`Cannot read ${file}: ${err.message}`);
|
|
30311
30811
|
process.exitCode = 1;
|
|
@@ -30326,21 +30826,21 @@ async function aiScanMoshCommand(file, args) {
|
|
|
30326
30826
|
|
|
30327
30827
|
// src/commands/orgs.ts
|
|
30328
30828
|
var import_node_os6 = require("os");
|
|
30329
|
-
var
|
|
30330
|
-
var
|
|
30829
|
+
var import_node_fs20 = require("fs");
|
|
30830
|
+
var import_node_path16 = require("path");
|
|
30331
30831
|
var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
30332
|
-
var CONFIG_PATH = (0,
|
|
30832
|
+
var CONFIG_PATH = (0, import_node_path16.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
|
|
30333
30833
|
function readConfig() {
|
|
30334
30834
|
try {
|
|
30335
|
-
return JSON.parse((0,
|
|
30835
|
+
return JSON.parse((0, import_node_fs20.readFileSync)(CONFIG_PATH, "utf-8"));
|
|
30336
30836
|
} catch {
|
|
30337
30837
|
return {};
|
|
30338
30838
|
}
|
|
30339
30839
|
}
|
|
30340
30840
|
function writeConfig(config) {
|
|
30341
|
-
const dir = (0,
|
|
30342
|
-
if (!(0,
|
|
30343
|
-
(0,
|
|
30841
|
+
const dir = (0, import_node_path16.join)((0, import_node_os6.homedir)(), ".threatcrush");
|
|
30842
|
+
if (!(0, import_node_fs20.existsSync)(dir)) (0, import_node_fs20.mkdirSync)(dir, { recursive: true });
|
|
30843
|
+
(0, import_node_fs20.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
30344
30844
|
}
|
|
30345
30845
|
function getAuthHeaders() {
|
|
30346
30846
|
const config = readConfig();
|
|
@@ -30541,9 +31041,9 @@ async function fetchOrgs() {
|
|
|
30541
31041
|
}
|
|
30542
31042
|
function askChoice(question) {
|
|
30543
31043
|
const rl = import_node_readline3.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
30544
|
-
return new Promise((
|
|
31044
|
+
return new Promise((resolve6) => rl.question(question, (answer) => {
|
|
30545
31045
|
rl.close();
|
|
30546
|
-
|
|
31046
|
+
resolve6(answer.trim());
|
|
30547
31047
|
}));
|
|
30548
31048
|
}
|
|
30549
31049
|
async function chooseOrg(orgs, flag, ask2) {
|
|
@@ -30685,14 +31185,14 @@ function timeAgo(dateStr) {
|
|
|
30685
31185
|
|
|
30686
31186
|
// src/commands/connect.ts
|
|
30687
31187
|
var import_node_os8 = require("os");
|
|
30688
|
-
var
|
|
30689
|
-
var
|
|
31188
|
+
var import_node_fs21 = require("fs");
|
|
31189
|
+
var import_node_path17 = require("path");
|
|
30690
31190
|
var import_node_child_process3 = require("child_process");
|
|
30691
31191
|
var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
30692
|
-
var CONFIG_PATH2 = (0,
|
|
31192
|
+
var CONFIG_PATH2 = (0, import_node_path17.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
|
|
30693
31193
|
function readConfig2() {
|
|
30694
31194
|
try {
|
|
30695
|
-
return JSON.parse((0,
|
|
31195
|
+
return JSON.parse((0, import_node_fs21.readFileSync)(CONFIG_PATH2, "utf-8"));
|
|
30696
31196
|
} catch {
|
|
30697
31197
|
return {};
|
|
30698
31198
|
}
|
|
@@ -30847,21 +31347,21 @@ async function sshConnect(options) {
|
|
|
30847
31347
|
|
|
30848
31348
|
// src/commands/daemon.ts
|
|
30849
31349
|
var import_node_child_process11 = require("child_process");
|
|
30850
|
-
var
|
|
30851
|
-
var
|
|
30852
|
-
var
|
|
31350
|
+
var import_node_fs33 = require("fs");
|
|
31351
|
+
var import_node_path24 = require("path");
|
|
31352
|
+
var import_node_fs34 = require("fs");
|
|
30853
31353
|
|
|
30854
31354
|
// src/daemon/index.ts
|
|
30855
|
-
var
|
|
31355
|
+
var import_node_fs32 = require("fs");
|
|
30856
31356
|
var import_node_child_process10 = require("child_process");
|
|
30857
31357
|
var import_node_os9 = require("os");
|
|
30858
|
-
var
|
|
31358
|
+
var import_node_path23 = require("path");
|
|
30859
31359
|
var import_node_util = require("util");
|
|
30860
31360
|
init_paths();
|
|
30861
31361
|
|
|
30862
31362
|
// src/daemon/ipc-server.ts
|
|
30863
31363
|
var import_node_net2 = require("net");
|
|
30864
|
-
var
|
|
31364
|
+
var import_node_fs22 = require("fs");
|
|
30865
31365
|
init_paths();
|
|
30866
31366
|
init_control_token();
|
|
30867
31367
|
|
|
@@ -30884,10 +31384,11 @@ bus.setMaxListeners(50);
|
|
|
30884
31384
|
// src/daemon/ipc-server.ts
|
|
30885
31385
|
init_backoff();
|
|
30886
31386
|
var IpcServer = class {
|
|
30887
|
-
constructor(version, moduleHost, remediation) {
|
|
31387
|
+
constructor(version, moduleHost, remediation, watchdog) {
|
|
30888
31388
|
this.version = version;
|
|
30889
31389
|
this.moduleHost = moduleHost;
|
|
30890
31390
|
this.remediation = remediation;
|
|
31391
|
+
this.watchdog = watchdog;
|
|
30891
31392
|
bus.on("event", (event) => {
|
|
30892
31393
|
this.counters.events++;
|
|
30893
31394
|
if (event.severity === "medium" || event.severity === "high" || event.severity === "critical") {
|
|
@@ -30905,6 +31406,7 @@ var IpcServer = class {
|
|
|
30905
31406
|
version;
|
|
30906
31407
|
moduleHost;
|
|
30907
31408
|
remediation;
|
|
31409
|
+
watchdog;
|
|
30908
31410
|
server = null;
|
|
30909
31411
|
clients = /* @__PURE__ */ new Map();
|
|
30910
31412
|
nextClientId = 1;
|
|
@@ -30913,13 +31415,13 @@ var IpcServer = class {
|
|
|
30913
31415
|
controlToken = "";
|
|
30914
31416
|
async start() {
|
|
30915
31417
|
this.controlToken = issueControlToken();
|
|
30916
|
-
if ((0,
|
|
31418
|
+
if ((0, import_node_fs22.existsSync)(PATHS.socket)) {
|
|
30917
31419
|
try {
|
|
30918
|
-
(0,
|
|
31420
|
+
(0, import_node_fs22.unlinkSync)(PATHS.socket);
|
|
30919
31421
|
} catch {
|
|
30920
31422
|
}
|
|
30921
31423
|
}
|
|
30922
|
-
return new Promise((
|
|
31424
|
+
return new Promise((resolve6, reject) => {
|
|
30923
31425
|
this.server = (0, import_node_net2.createServer)((sock) => this.handleClient(sock));
|
|
30924
31426
|
this.server.on("error", reject);
|
|
30925
31427
|
this.server.listen(PATHS.socket, () => {
|
|
@@ -30936,7 +31438,7 @@ var IpcServer = class {
|
|
|
30936
31438
|
} catch {
|
|
30937
31439
|
}
|
|
30938
31440
|
}
|
|
30939
|
-
|
|
31441
|
+
resolve6();
|
|
30940
31442
|
});
|
|
30941
31443
|
});
|
|
30942
31444
|
}
|
|
@@ -30948,20 +31450,20 @@ var IpcServer = class {
|
|
|
30948
31450
|
}
|
|
30949
31451
|
}
|
|
30950
31452
|
this.clients.clear();
|
|
30951
|
-
return new Promise((
|
|
31453
|
+
return new Promise((resolve6) => {
|
|
30952
31454
|
if (!this.server) {
|
|
30953
31455
|
try {
|
|
30954
|
-
if ((0,
|
|
31456
|
+
if ((0, import_node_fs22.existsSync)(PATHS.socket)) (0, import_node_fs22.unlinkSync)(PATHS.socket);
|
|
30955
31457
|
} catch {
|
|
30956
31458
|
}
|
|
30957
|
-
return
|
|
31459
|
+
return resolve6();
|
|
30958
31460
|
}
|
|
30959
31461
|
this.server.close(() => {
|
|
30960
31462
|
try {
|
|
30961
|
-
if ((0,
|
|
31463
|
+
if ((0, import_node_fs22.existsSync)(PATHS.socket)) (0, import_node_fs22.unlinkSync)(PATHS.socket);
|
|
30962
31464
|
} catch {
|
|
30963
31465
|
}
|
|
30964
|
-
|
|
31466
|
+
resolve6();
|
|
30965
31467
|
});
|
|
30966
31468
|
});
|
|
30967
31469
|
}
|
|
@@ -31029,7 +31531,8 @@ var IpcServer = class {
|
|
|
31029
31531
|
},
|
|
31030
31532
|
modules: this.moduleHost.summary(),
|
|
31031
31533
|
counters: { ...this.counters },
|
|
31032
|
-
stateDb: isStateDbAvailable()
|
|
31534
|
+
stateDb: isStateDbAvailable(),
|
|
31535
|
+
...this.watchdog ? { watchdog: this.watchdog() } : {}
|
|
31033
31536
|
};
|
|
31034
31537
|
return this.send(client, { id: req.id, ok: true, result: status });
|
|
31035
31538
|
}
|
|
@@ -31139,14 +31642,14 @@ var IpcServer = class {
|
|
|
31139
31642
|
};
|
|
31140
31643
|
|
|
31141
31644
|
// src/daemon/module-host.ts
|
|
31142
|
-
var
|
|
31143
|
-
var
|
|
31645
|
+
var import_node_fs26 = require("fs");
|
|
31646
|
+
var import_node_path18 = require("path");
|
|
31144
31647
|
var import_node_url = require("url");
|
|
31145
31648
|
var import_toml4 = __toESM(require_toml());
|
|
31146
31649
|
init_paths();
|
|
31147
31650
|
|
|
31148
31651
|
// src/daemon/watchers/log-watcher.ts
|
|
31149
|
-
var
|
|
31652
|
+
var import_node_fs23 = require("fs");
|
|
31150
31653
|
var import_node_readline4 = require("readline");
|
|
31151
31654
|
var DEFAULT_SOURCES = [
|
|
31152
31655
|
{ path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
|
|
@@ -31167,9 +31670,9 @@ var LogWatcher = class {
|
|
|
31167
31670
|
start() {
|
|
31168
31671
|
const started = [];
|
|
31169
31672
|
for (const src of this.sources) {
|
|
31170
|
-
if (!(0,
|
|
31673
|
+
if (!(0, import_node_fs23.existsSync)(src.path)) continue;
|
|
31171
31674
|
try {
|
|
31172
|
-
(0,
|
|
31675
|
+
(0, import_node_fs23.accessSync)(src.path, import_node_fs23.constants.R_OK);
|
|
31173
31676
|
} catch {
|
|
31174
31677
|
continue;
|
|
31175
31678
|
}
|
|
@@ -31197,7 +31700,7 @@ var LogWatcher = class {
|
|
|
31197
31700
|
}
|
|
31198
31701
|
tail(src) {
|
|
31199
31702
|
try {
|
|
31200
|
-
this.positions.set(src.path, (0,
|
|
31703
|
+
this.positions.set(src.path, (0, import_node_fs23.statSync)(src.path).size);
|
|
31201
31704
|
} catch {
|
|
31202
31705
|
this.positions.set(src.path, 0);
|
|
31203
31706
|
}
|
|
@@ -31208,7 +31711,7 @@ var LogWatcher = class {
|
|
|
31208
31711
|
poll(src) {
|
|
31209
31712
|
let stat;
|
|
31210
31713
|
try {
|
|
31211
|
-
stat = (0,
|
|
31714
|
+
stat = (0, import_node_fs23.statSync)(src.path);
|
|
31212
31715
|
} catch {
|
|
31213
31716
|
return;
|
|
31214
31717
|
}
|
|
@@ -31218,7 +31721,7 @@ var LogWatcher = class {
|
|
|
31218
31721
|
return;
|
|
31219
31722
|
}
|
|
31220
31723
|
if (stat.size === prev) return;
|
|
31221
|
-
const stream = (0,
|
|
31724
|
+
const stream = (0, import_node_fs23.createReadStream)(src.path, { start: prev, encoding: "utf-8" });
|
|
31222
31725
|
stream.on("error", () => this.positions.set(src.path, stat.size));
|
|
31223
31726
|
const rl = (0, import_node_readline4.createInterface)({ input: stream });
|
|
31224
31727
|
rl.on("error", () => {
|
|
@@ -31254,6 +31757,9 @@ var LogWatcher = class {
|
|
|
31254
31757
|
const reqPath = (entry.fields.path || "").split("?")[0];
|
|
31255
31758
|
if (reqPath) details.path = reqPath;
|
|
31256
31759
|
if (entry.fields.user_agent) details.ua = entry.fields.user_agent;
|
|
31760
|
+
if (Number.isFinite(status)) details.status = status;
|
|
31761
|
+
if (entry.fields.method) details.method = entry.fields.method;
|
|
31762
|
+
if (entry.fields.path) details.url = entry.fields.path.slice(0, 2048);
|
|
31257
31763
|
if (crs.score > 0) {
|
|
31258
31764
|
Object.assign(details, {
|
|
31259
31765
|
attack_type: crs.attackType,
|
|
@@ -31479,7 +31985,7 @@ function realtimeToDate(rt) {
|
|
|
31479
31985
|
|
|
31480
31986
|
// src/modules/network-monitor/index.ts
|
|
31481
31987
|
var import_node_child_process5 = require("child_process");
|
|
31482
|
-
var
|
|
31988
|
+
var import_node_fs24 = require("fs");
|
|
31483
31989
|
var NetworkMonitor = class {
|
|
31484
31990
|
constructor(bus2) {
|
|
31485
31991
|
this.bus = bus2;
|
|
@@ -31543,7 +32049,7 @@ var NetworkMonitor = class {
|
|
|
31543
32049
|
hasConntrackOrSs() {
|
|
31544
32050
|
const ss = (0, import_node_child_process5.spawnSync)("ss", ["--version"], { stdio: "pipe" });
|
|
31545
32051
|
if (ss.status === 0) return true;
|
|
31546
|
-
return (0,
|
|
32052
|
+
return (0, import_node_fs24.existsSync)("/proc/net/tcp");
|
|
31547
32053
|
}
|
|
31548
32054
|
/**
|
|
31549
32055
|
* The TCP ports this host actually listens on.
|
|
@@ -31730,7 +32236,7 @@ var NetworkMonitor = class {
|
|
|
31730
32236
|
};
|
|
31731
32237
|
|
|
31732
32238
|
// src/modules/dns-monitor/index.ts
|
|
31733
|
-
var
|
|
32239
|
+
var import_node_fs25 = require("fs");
|
|
31734
32240
|
var import_node_child_process6 = require("child_process");
|
|
31735
32241
|
var import_node_readline5 = require("readline");
|
|
31736
32242
|
var DNS_LOG_SOURCES = [
|
|
@@ -31812,9 +32318,9 @@ var DnsMonitor = class {
|
|
|
31812
32318
|
}
|
|
31813
32319
|
start() {
|
|
31814
32320
|
const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
|
|
31815
|
-
if (!(0,
|
|
32321
|
+
if (!(0, import_node_fs25.existsSync)(p)) return false;
|
|
31816
32322
|
try {
|
|
31817
|
-
(0,
|
|
32323
|
+
(0, import_node_fs25.accessSync)(p, import_node_fs25.constants.R_OK);
|
|
31818
32324
|
return true;
|
|
31819
32325
|
} catch {
|
|
31820
32326
|
return false;
|
|
@@ -31890,7 +32396,7 @@ var DnsMonitor = class {
|
|
|
31890
32396
|
}
|
|
31891
32397
|
tailLog(path) {
|
|
31892
32398
|
try {
|
|
31893
|
-
this.positions.set(path, (0,
|
|
32399
|
+
this.positions.set(path, (0, import_node_fs25.statSync)(path).size);
|
|
31894
32400
|
} catch {
|
|
31895
32401
|
this.positions.set(path, 0);
|
|
31896
32402
|
}
|
|
@@ -31900,7 +32406,7 @@ var DnsMonitor = class {
|
|
|
31900
32406
|
pollLog(path) {
|
|
31901
32407
|
let stat;
|
|
31902
32408
|
try {
|
|
31903
|
-
stat = (0,
|
|
32409
|
+
stat = (0, import_node_fs25.statSync)(path);
|
|
31904
32410
|
} catch {
|
|
31905
32411
|
return;
|
|
31906
32412
|
}
|
|
@@ -31910,7 +32416,7 @@ var DnsMonitor = class {
|
|
|
31910
32416
|
return;
|
|
31911
32417
|
}
|
|
31912
32418
|
if (stat.size === prev) return;
|
|
31913
|
-
const stream = (0,
|
|
32419
|
+
const stream = (0, import_node_fs25.createReadStream)(path, { start: prev, encoding: "utf-8" });
|
|
31914
32420
|
stream.on("error", () => this.positions.set(path, stat.size));
|
|
31915
32421
|
const rl = (0, import_node_readline5.createInterface)({ input: stream });
|
|
31916
32422
|
rl.on("line", (line) => this.parseDnsLine(line));
|
|
@@ -32020,14 +32526,14 @@ var DnsMonitor = class {
|
|
|
32020
32526
|
);
|
|
32021
32527
|
}
|
|
32022
32528
|
}
|
|
32023
|
-
shannonEntropy(
|
|
32529
|
+
shannonEntropy(str3) {
|
|
32024
32530
|
const freq = /* @__PURE__ */ new Map();
|
|
32025
|
-
for (const ch of
|
|
32531
|
+
for (const ch of str3) {
|
|
32026
32532
|
freq.set(ch, (freq.get(ch) || 0) + 1);
|
|
32027
32533
|
}
|
|
32028
32534
|
let entropy = 0;
|
|
32029
32535
|
for (const count of freq.values()) {
|
|
32030
|
-
const p = count /
|
|
32536
|
+
const p = count / str3.length;
|
|
32031
32537
|
if (p > 0) entropy -= p * Math.log2(p);
|
|
32032
32538
|
}
|
|
32033
32539
|
return entropy;
|
|
@@ -32169,15 +32675,15 @@ var ModuleHost = class {
|
|
|
32169
32675
|
}
|
|
32170
32676
|
}
|
|
32171
32677
|
async discoverAndStartInstalled() {
|
|
32172
|
-
if (!(0,
|
|
32678
|
+
if (!(0, import_node_fs26.existsSync)(PATHS.moduleDir)) return;
|
|
32173
32679
|
const configs = loadModuleConfigs(PATHS.confD);
|
|
32174
|
-
const entries = (0,
|
|
32680
|
+
const entries = (0, import_node_fs26.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
|
|
32175
32681
|
for (const entry of entries) {
|
|
32176
32682
|
if (!entry.isDirectory()) continue;
|
|
32177
|
-
const manifestPath = (0,
|
|
32178
|
-
if (!(0,
|
|
32683
|
+
const manifestPath = (0, import_node_path18.join)(PATHS.moduleDir, entry.name, "mod.toml");
|
|
32684
|
+
if (!(0, import_node_fs26.existsSync)(manifestPath)) continue;
|
|
32179
32685
|
try {
|
|
32180
|
-
const manifest = import_toml4.default.parse((0,
|
|
32686
|
+
const manifest = import_toml4.default.parse((0, import_node_fs26.readFileSync)(manifestPath, "utf-8"));
|
|
32181
32687
|
const name = manifest.module?.name || entry.name;
|
|
32182
32688
|
const defaults = manifest.module?.config?.defaults || {};
|
|
32183
32689
|
const config = {
|
|
@@ -32191,7 +32697,7 @@ var ModuleHost = class {
|
|
|
32191
32697
|
source: "installed",
|
|
32192
32698
|
status: config.enabled === false ? "disabled" : "loaded",
|
|
32193
32699
|
events: 0,
|
|
32194
|
-
path: (0,
|
|
32700
|
+
path: (0, import_node_path18.join)(PATHS.moduleDir, entry.name),
|
|
32195
32701
|
config
|
|
32196
32702
|
};
|
|
32197
32703
|
this.modules.set(name, hosted);
|
|
@@ -32206,7 +32712,7 @@ var ModuleHost = class {
|
|
|
32206
32712
|
status: "error",
|
|
32207
32713
|
events: 0,
|
|
32208
32714
|
detail: `manifest load failed: ${String(err.message || err)}`,
|
|
32209
|
-
path: (0,
|
|
32715
|
+
path: (0, import_node_path18.join)(PATHS.moduleDir, entry.name)
|
|
32210
32716
|
});
|
|
32211
32717
|
}
|
|
32212
32718
|
}
|
|
@@ -32245,17 +32751,17 @@ var ModuleHost = class {
|
|
|
32245
32751
|
}
|
|
32246
32752
|
}
|
|
32247
32753
|
installedEntrypoint(modulePath) {
|
|
32248
|
-
const packageJson = (0,
|
|
32754
|
+
const packageJson = (0, import_node_path18.join)(modulePath, "package.json");
|
|
32249
32755
|
const candidates = [];
|
|
32250
|
-
if ((0,
|
|
32756
|
+
if ((0, import_node_fs26.existsSync)(packageJson)) {
|
|
32251
32757
|
try {
|
|
32252
|
-
const pkg = JSON.parse((0,
|
|
32253
|
-
if (pkg.main) candidates.push((0,
|
|
32758
|
+
const pkg = JSON.parse((0, import_node_fs26.readFileSync)(packageJson, "utf-8"));
|
|
32759
|
+
if (pkg.main) candidates.push((0, import_node_path18.join)(modulePath, pkg.main));
|
|
32254
32760
|
} catch {
|
|
32255
32761
|
}
|
|
32256
32762
|
}
|
|
32257
|
-
candidates.push((0,
|
|
32258
|
-
return candidates.find((candidate) => (0,
|
|
32763
|
+
candidates.push((0, import_node_path18.join)(modulePath, "dist", "index.js"), (0, import_node_path18.join)(modulePath, "index.js"));
|
|
32764
|
+
return candidates.find((candidate) => (0, import_node_fs26.existsSync)(candidate)) || null;
|
|
32259
32765
|
}
|
|
32260
32766
|
isThreatCrushModule(value) {
|
|
32261
32767
|
return Boolean(
|
|
@@ -32299,7 +32805,7 @@ var ModuleHost = class {
|
|
|
32299
32805
|
// src/daemon/alerts/smtp.ts
|
|
32300
32806
|
var transporter = null;
|
|
32301
32807
|
var nodemailer = null;
|
|
32302
|
-
var
|
|
32808
|
+
var SEVERITY_RANK2 = {
|
|
32303
32809
|
info: 0,
|
|
32304
32810
|
low: 1,
|
|
32305
32811
|
medium: 2,
|
|
@@ -32326,7 +32832,7 @@ async function ensureTransporter(config) {
|
|
|
32326
32832
|
}
|
|
32327
32833
|
function meetsSeverity(event, min) {
|
|
32328
32834
|
if (!min) return true;
|
|
32329
|
-
return (
|
|
32835
|
+
return (SEVERITY_RANK2[event.severity] ?? 0) >= (SEVERITY_RANK2[min] ?? 0);
|
|
32330
32836
|
}
|
|
32331
32837
|
function renderBody(event) {
|
|
32332
32838
|
const ts = event.timestamp.toISOString();
|
|
@@ -32360,7 +32866,7 @@ function smtpChannel(config) {
|
|
|
32360
32866
|
}
|
|
32361
32867
|
|
|
32362
32868
|
// src/daemon/alerts/discord.ts
|
|
32363
|
-
var
|
|
32869
|
+
var SEVERITY_RANK3 = {
|
|
32364
32870
|
info: 0,
|
|
32365
32871
|
low: 1,
|
|
32366
32872
|
medium: 2,
|
|
@@ -32382,8 +32888,8 @@ var SEVERITY_COLORS2 = {
|
|
|
32382
32888
|
function discordChannel(config) {
|
|
32383
32889
|
return async (event) => {
|
|
32384
32890
|
if (config.min_severity) {
|
|
32385
|
-
const eventRank =
|
|
32386
|
-
const minRank =
|
|
32891
|
+
const eventRank = SEVERITY_RANK3[event.severity] ?? 0;
|
|
32892
|
+
const minRank = SEVERITY_RANK3[config.min_severity] ?? 0;
|
|
32387
32893
|
if (eventRank < minRank) return;
|
|
32388
32894
|
}
|
|
32389
32895
|
const embed = {
|
|
@@ -32406,7 +32912,7 @@ function discordChannel(config) {
|
|
|
32406
32912
|
}
|
|
32407
32913
|
|
|
32408
32914
|
// src/daemon/alerts/pagerduty.ts
|
|
32409
|
-
var
|
|
32915
|
+
var SEVERITY_RANK4 = {
|
|
32410
32916
|
info: 0,
|
|
32411
32917
|
low: 1,
|
|
32412
32918
|
medium: 2,
|
|
@@ -32423,8 +32929,8 @@ var PD_SEVERITY = {
|
|
|
32423
32929
|
function pagerdutyChannel(config) {
|
|
32424
32930
|
return async (event) => {
|
|
32425
32931
|
if (config.min_severity) {
|
|
32426
|
-
const eventRank =
|
|
32427
|
-
const minRank =
|
|
32932
|
+
const eventRank = SEVERITY_RANK4[event.severity] ?? 0;
|
|
32933
|
+
const minRank = SEVERITY_RANK4[config.min_severity] ?? 0;
|
|
32428
32934
|
if (eventRank < minRank) return;
|
|
32429
32935
|
}
|
|
32430
32936
|
const payload = {
|
|
@@ -32659,7 +33165,7 @@ var RunsWorker = class {
|
|
|
32659
33165
|
};
|
|
32660
33166
|
|
|
32661
33167
|
// src/core/cloud-events.ts
|
|
32662
|
-
var
|
|
33168
|
+
var import_node_crypto6 = require("crypto");
|
|
32663
33169
|
var import_node_net3 = require("net");
|
|
32664
33170
|
function currentLink() {
|
|
32665
33171
|
if (!hasSession()) return null;
|
|
@@ -32667,7 +33173,7 @@ function currentLink() {
|
|
|
32667
33173
|
if (!cfg.server_id || !cfg.server_org_id) return null;
|
|
32668
33174
|
return { serverId: cfg.server_id, orgId: cfg.server_org_id };
|
|
32669
33175
|
}
|
|
32670
|
-
var
|
|
33176
|
+
var SEVERITY_RANK5 = {
|
|
32671
33177
|
info: 0,
|
|
32672
33178
|
low: 1,
|
|
32673
33179
|
medium: 2,
|
|
@@ -32704,7 +33210,7 @@ function trimMetadata(meta) {
|
|
|
32704
33210
|
}
|
|
32705
33211
|
return truncated ? { ...out, _truncated: true } : out;
|
|
32706
33212
|
}
|
|
32707
|
-
function
|
|
33213
|
+
function str2(value) {
|
|
32708
33214
|
return typeof value === "string" && value ? value : void 0;
|
|
32709
33215
|
}
|
|
32710
33216
|
function detectionEvent(serverId, event) {
|
|
@@ -32715,10 +33221,10 @@ function detectionEvent(serverId, event) {
|
|
|
32715
33221
|
server_id: serverId,
|
|
32716
33222
|
severity: event.severity,
|
|
32717
33223
|
title: title.slice(0, MAX_TITLE_CHARS) || event.module,
|
|
32718
|
-
rule_id:
|
|
32719
|
-
description:
|
|
33224
|
+
rule_id: str2(rule_id) ?? event.module,
|
|
33225
|
+
description: str2(description),
|
|
32720
33226
|
source_ip: event.source_ip && (0, import_node_net3.isIP)(event.source_ip) ? event.source_ip : void 0,
|
|
32721
|
-
username:
|
|
33227
|
+
username: str2(username) ?? str2(user),
|
|
32722
33228
|
raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
|
|
32723
33229
|
detected_at: event.timestamp.toISOString()
|
|
32724
33230
|
};
|
|
@@ -32732,13 +33238,13 @@ function remediationEvent(serverId, event) {
|
|
|
32732
33238
|
return {
|
|
32733
33239
|
type: "remediation",
|
|
32734
33240
|
server_id: serverId,
|
|
32735
|
-
event_id: (0,
|
|
33241
|
+
event_id: (0, import_node_crypto6.randomUUID)(),
|
|
32736
33242
|
action_type: d.action,
|
|
32737
33243
|
target_value: event.source_ip,
|
|
32738
33244
|
status: d.failed === true ? "failed" : "executed",
|
|
32739
|
-
rule_id:
|
|
32740
|
-
reason:
|
|
32741
|
-
error:
|
|
33245
|
+
rule_id: str2(d.rule_id),
|
|
33246
|
+
reason: str2(d.reason),
|
|
33247
|
+
error: str2(d.error),
|
|
32742
33248
|
dry_run: d.dry_run === true,
|
|
32743
33249
|
executed_at: at.toISOString(),
|
|
32744
33250
|
expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
|
|
@@ -32758,16 +33264,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
|
|
|
32758
33264
|
}
|
|
32759
33265
|
|
|
32760
33266
|
// src/daemon/workers/cloud-spool.ts
|
|
32761
|
-
var
|
|
33267
|
+
var import_node_fs27 = require("fs");
|
|
32762
33268
|
var import_promises = require("fs/promises");
|
|
32763
|
-
var
|
|
33269
|
+
var import_node_path19 = require("path");
|
|
32764
33270
|
var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
|
|
32765
33271
|
var CloudSpool = class {
|
|
32766
33272
|
constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
|
|
32767
33273
|
this.path = path;
|
|
32768
33274
|
this.limits = limits;
|
|
32769
33275
|
try {
|
|
32770
|
-
(0,
|
|
33276
|
+
(0, import_node_fs27.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
|
|
32771
33277
|
} catch {
|
|
32772
33278
|
}
|
|
32773
33279
|
this.load();
|
|
@@ -32836,7 +33342,7 @@ var CloudSpool = class {
|
|
|
32836
33342
|
load() {
|
|
32837
33343
|
let raw;
|
|
32838
33344
|
try {
|
|
32839
|
-
raw = (0,
|
|
33345
|
+
raw = (0, import_node_fs27.readFileSync)(this.path, "utf-8");
|
|
32840
33346
|
} catch {
|
|
32841
33347
|
return;
|
|
32842
33348
|
}
|
|
@@ -32962,7 +33468,7 @@ var CloudSync = class {
|
|
|
32962
33468
|
let out = null;
|
|
32963
33469
|
if (event.module === "firewall-rules") {
|
|
32964
33470
|
out = remediationEvent(link.serverId, event);
|
|
32965
|
-
} else if ((event.module === "rule-engine" || !this.opts.ruleModules.has(event.module)) && event.details?.heartbeat !== true &&
|
|
33471
|
+
} else if ((event.module === "rule-engine" || !this.opts.ruleModules.has(event.module)) && event.details?.heartbeat !== true && SEVERITY_RANK5[event.severity] >= SEVERITY_RANK5[this.opts.minSeverity]) {
|
|
32966
33472
|
out = detectionEvent(link.serverId, event);
|
|
32967
33473
|
}
|
|
32968
33474
|
if (!out) return;
|
|
@@ -33541,8 +34047,8 @@ var RuleEngine = class {
|
|
|
33541
34047
|
};
|
|
33542
34048
|
|
|
33543
34049
|
// src/daemon/rules/loader.ts
|
|
33544
|
-
var
|
|
33545
|
-
var
|
|
34050
|
+
var import_node_fs28 = require("fs");
|
|
34051
|
+
var import_node_path20 = require("path");
|
|
33546
34052
|
|
|
33547
34053
|
// src/daemon/rules/default-rules.ts
|
|
33548
34054
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -33943,11 +34449,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
33943
34449
|
function loadAllRules(customDir) {
|
|
33944
34450
|
const rules = [...DEFAULT_RULES];
|
|
33945
34451
|
const dir = customDir || RULES_DIR;
|
|
33946
|
-
if ((0,
|
|
33947
|
-
const files = (0,
|
|
34452
|
+
if ((0, import_node_fs28.existsSync)(dir)) {
|
|
34453
|
+
const files = (0, import_node_fs28.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
33948
34454
|
for (const file of files) {
|
|
33949
34455
|
try {
|
|
33950
|
-
const raw = (0,
|
|
34456
|
+
const raw = (0, import_node_fs28.readFileSync)((0, import_node_path20.join)(dir, file), "utf-8");
|
|
33951
34457
|
const parsed = JSON.parse(raw);
|
|
33952
34458
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
33953
34459
|
for (const rule of customRules) {
|
|
@@ -33979,8 +34485,8 @@ function loadAllRules(customDir) {
|
|
|
33979
34485
|
|
|
33980
34486
|
// src/daemon/firewall/adapters.ts
|
|
33981
34487
|
var import_node_child_process8 = require("child_process");
|
|
33982
|
-
var
|
|
33983
|
-
var
|
|
34488
|
+
var import_node_fs29 = require("fs");
|
|
34489
|
+
var import_node_path21 = require("path");
|
|
33984
34490
|
var import_node_net7 = require("net");
|
|
33985
34491
|
function assertValidFirewallIp(ip) {
|
|
33986
34492
|
if ((0, import_node_net7.isIP)(ip) !== 4) {
|
|
@@ -33993,9 +34499,9 @@ function assertBannableIp(ip) {
|
|
|
33993
34499
|
}
|
|
33994
34500
|
}
|
|
33995
34501
|
function writeIfAbsent(path, contents) {
|
|
33996
|
-
(0,
|
|
34502
|
+
(0, import_node_fs29.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
|
|
33997
34503
|
try {
|
|
33998
|
-
(0,
|
|
34504
|
+
(0, import_node_fs29.writeFileSync)(path, contents, { flag: "wx" });
|
|
33999
34505
|
} catch (err) {
|
|
34000
34506
|
if (err.code !== "EEXIST") throw err;
|
|
34001
34507
|
}
|
|
@@ -34250,7 +34756,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
34250
34756
|
}
|
|
34251
34757
|
|
|
34252
34758
|
// src/daemon/firewall/remediation.ts
|
|
34253
|
-
var
|
|
34759
|
+
var import_node_fs30 = require("fs");
|
|
34254
34760
|
var import_node_net8 = require("net");
|
|
34255
34761
|
init_paths();
|
|
34256
34762
|
init_backoff();
|
|
@@ -34311,7 +34817,7 @@ var DEFAULT_CONFIG2 = {
|
|
|
34311
34817
|
protect_current_ssh_client: true,
|
|
34312
34818
|
spare_verified_crawlers: true
|
|
34313
34819
|
};
|
|
34314
|
-
var
|
|
34820
|
+
var SEVERITY_RANK6 = {
|
|
34315
34821
|
info: 0,
|
|
34316
34822
|
low: 1,
|
|
34317
34823
|
medium: 2,
|
|
@@ -34375,8 +34881,8 @@ var RemediationManager = class {
|
|
|
34375
34881
|
}
|
|
34376
34882
|
async handleDetection(event) {
|
|
34377
34883
|
if (!this.config.enabled) return;
|
|
34378
|
-
const eventRank =
|
|
34379
|
-
const minRank =
|
|
34884
|
+
const eventRank = SEVERITY_RANK6[event.severity] ?? 0;
|
|
34885
|
+
const minRank = SEVERITY_RANK6[this.config.min_severity] ?? 3;
|
|
34380
34886
|
if (eventRank < minRank) return;
|
|
34381
34887
|
if (isSuccessfulAuth(event.message)) return;
|
|
34382
34888
|
if (event.details?.rule_id) {
|
|
@@ -34660,7 +35166,7 @@ var RemediationManager = class {
|
|
|
34660
35166
|
}
|
|
34661
35167
|
logLine(line) {
|
|
34662
35168
|
try {
|
|
34663
|
-
(0,
|
|
35169
|
+
(0, import_node_fs30.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
34664
35170
|
`);
|
|
34665
35171
|
} catch {
|
|
34666
35172
|
}
|
|
@@ -34697,6 +35203,63 @@ function remediationSettings(section) {
|
|
|
34697
35203
|
// src/daemon/index.ts
|
|
34698
35204
|
init_backoff();
|
|
34699
35205
|
|
|
35206
|
+
// src/daemon/watchdog-service.ts
|
|
35207
|
+
var import_node_fs31 = require("fs");
|
|
35208
|
+
var import_node_path22 = require("path");
|
|
35209
|
+
function defaultShareGid() {
|
|
35210
|
+
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
35211
|
+
if (!isRoot4) return void 0;
|
|
35212
|
+
try {
|
|
35213
|
+
return (0, import_node_fs31.statSync)("/var/log/auth.log").gid;
|
|
35214
|
+
} catch {
|
|
35215
|
+
return void 0;
|
|
35216
|
+
}
|
|
35217
|
+
}
|
|
35218
|
+
function startWatchdog(opts) {
|
|
35219
|
+
const dir = opts.config?.dir ?? (0, import_node_path22.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
35220
|
+
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
35221
|
+
if (opts.config?.enabled === false) {
|
|
35222
|
+
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
35223
|
+
return { status: () => ({ enabled: false, ...base }), stop: () => {
|
|
35224
|
+
} };
|
|
35225
|
+
}
|
|
35226
|
+
let log;
|
|
35227
|
+
try {
|
|
35228
|
+
log = new WatchdogLog(dir, { shareGid: opts.shareGid ?? defaultShareGid() });
|
|
35229
|
+
} catch (err) {
|
|
35230
|
+
const error2 = err.message;
|
|
35231
|
+
opts.log(`[watchdog] cannot open ${dir}: ${error2}`);
|
|
35232
|
+
return { status: () => ({ enabled: false, ...base, error: error2 }), stop: () => {
|
|
35233
|
+
} };
|
|
35234
|
+
}
|
|
35235
|
+
let error;
|
|
35236
|
+
const onEvent = (event) => {
|
|
35237
|
+
log.record(event);
|
|
35238
|
+
};
|
|
35239
|
+
const flush = () => {
|
|
35240
|
+
try {
|
|
35241
|
+
log.flush();
|
|
35242
|
+
error = void 0;
|
|
35243
|
+
} catch (err) {
|
|
35244
|
+
const message = err.message;
|
|
35245
|
+
if (message !== error) opts.log(`[watchdog] write failed: ${message}`);
|
|
35246
|
+
error = message;
|
|
35247
|
+
}
|
|
35248
|
+
};
|
|
35249
|
+
opts.bus.on("event", onEvent);
|
|
35250
|
+
const timer = setInterval(flush, opts.flushMs ?? 1e3);
|
|
35251
|
+
timer.unref?.();
|
|
35252
|
+
opts.log(`[watchdog] logging attacks to ${log.file}`);
|
|
35253
|
+
return {
|
|
35254
|
+
status: () => ({ enabled: true, dir, ...log.stats, ...error ? { error } : {} }),
|
|
35255
|
+
stop: () => {
|
|
35256
|
+
clearInterval(timer);
|
|
35257
|
+
opts.bus.off("event", onEvent);
|
|
35258
|
+
flush();
|
|
35259
|
+
}
|
|
35260
|
+
};
|
|
35261
|
+
}
|
|
35262
|
+
|
|
34700
35263
|
// src/core/telemetry.ts
|
|
34701
35264
|
var ready = false;
|
|
34702
35265
|
var sentry = null;
|
|
@@ -34765,7 +35328,7 @@ function versionOfNode(path) {
|
|
|
34765
35328
|
// src/daemon/index.ts
|
|
34766
35329
|
function readVersion2() {
|
|
34767
35330
|
try {
|
|
34768
|
-
const pkg = JSON.parse((0,
|
|
35331
|
+
const pkg = JSON.parse((0, import_node_fs32.readFileSync)((0, import_node_path23.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
34769
35332
|
return pkg.version || "0.0.0";
|
|
34770
35333
|
} catch {
|
|
34771
35334
|
return "0.0.0";
|
|
@@ -34774,7 +35337,7 @@ function readVersion2() {
|
|
|
34774
35337
|
async function runHardeningChecks() {
|
|
34775
35338
|
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process10.execFile)(
|
|
34776
35339
|
process.execPath,
|
|
34777
|
-
[(0,
|
|
35340
|
+
[(0, import_node_path23.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
34778
35341
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
34779
35342
|
);
|
|
34780
35343
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -34782,7 +35345,7 @@ async function runHardeningChecks() {
|
|
|
34782
35345
|
}
|
|
34783
35346
|
function logLine(line) {
|
|
34784
35347
|
try {
|
|
34785
|
-
(0,
|
|
35348
|
+
(0, import_node_fs32.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
34786
35349
|
`);
|
|
34787
35350
|
} catch {
|
|
34788
35351
|
}
|
|
@@ -34824,7 +35387,7 @@ async function runDaemon() {
|
|
|
34824
35387
|
} catch (err) {
|
|
34825
35388
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
34826
35389
|
}
|
|
34827
|
-
const config = loadConfig((0,
|
|
35390
|
+
const config = loadConfig((0, import_node_fs32.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
34828
35391
|
configureAttackDetection(config.detection);
|
|
34829
35392
|
bus.on("event", (event) => {
|
|
34830
35393
|
logLine(`[event] ${event.severity} ${event.module} ${event.message}`);
|
|
@@ -34891,7 +35454,7 @@ async function runDaemon() {
|
|
|
34891
35454
|
version,
|
|
34892
35455
|
hostname: (0, import_node_os9.hostname)(),
|
|
34893
35456
|
minSeverity,
|
|
34894
|
-
spoolPath: (0,
|
|
35457
|
+
spoolPath: (0, import_node_path23.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
34895
35458
|
log: logLine,
|
|
34896
35459
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
34897
35460
|
runHardening: runHardeningChecks
|
|
@@ -34904,7 +35467,8 @@ async function runDaemon() {
|
|
|
34904
35467
|
const link = currentLink();
|
|
34905
35468
|
logLine(link ? `[cloud] reporting as server ${link.serverId} (org ${link.orgId}), detections >= ${minSeverity}` : "[cloud] not linked; run `threatcrush login` and `threatcrush servers link` to report to the dashboard");
|
|
34906
35469
|
}
|
|
34907
|
-
const
|
|
35470
|
+
const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
|
|
35471
|
+
const ipc = new IpcServer(version, moduleHost, remediation, () => watchdog.status());
|
|
34908
35472
|
await ipc.start();
|
|
34909
35473
|
logLine(`[daemon] ipc listening on ${PATHS.socket}`);
|
|
34910
35474
|
const shutdown = async (signal) => {
|
|
@@ -34933,6 +35497,10 @@ async function runDaemon() {
|
|
|
34933
35497
|
await moduleHost.stop();
|
|
34934
35498
|
} catch {
|
|
34935
35499
|
}
|
|
35500
|
+
try {
|
|
35501
|
+
watchdog.stop();
|
|
35502
|
+
} catch {
|
|
35503
|
+
}
|
|
34936
35504
|
try {
|
|
34937
35505
|
await ipc.stop();
|
|
34938
35506
|
} catch {
|
|
@@ -34968,7 +35536,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
34968
35536
|
function isRoot2() {
|
|
34969
35537
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
34970
35538
|
}
|
|
34971
|
-
var DAEMON_ENTRY = (0,
|
|
35539
|
+
var DAEMON_ENTRY = (0, import_node_path24.join)(__dirname, "daemon.js");
|
|
34972
35540
|
async function daemonForeground() {
|
|
34973
35541
|
await runDaemon();
|
|
34974
35542
|
}
|
|
@@ -34989,7 +35557,7 @@ async function daemonStart() {
|
|
|
34989
35557
|
return;
|
|
34990
35558
|
}
|
|
34991
35559
|
ensureRuntimeDirs();
|
|
34992
|
-
if (!(0,
|
|
35560
|
+
if (!(0, import_node_fs33.existsSync)(DAEMON_ENTRY)) {
|
|
34993
35561
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
34994
35562
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
34995
35563
|
return;
|
|
@@ -34997,8 +35565,8 @@ async function daemonStart() {
|
|
|
34997
35565
|
let out;
|
|
34998
35566
|
let err;
|
|
34999
35567
|
try {
|
|
35000
|
-
out = (0,
|
|
35001
|
-
err = (0,
|
|
35568
|
+
out = (0, import_node_fs34.openSync)(PATHS.logFile, "a");
|
|
35569
|
+
err = (0, import_node_fs34.openSync)(PATHS.logFile, "a");
|
|
35002
35570
|
} catch (e) {
|
|
35003
35571
|
const code = e.code;
|
|
35004
35572
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -35086,12 +35654,12 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
35086
35654
|
}
|
|
35087
35655
|
async function releaseStaleSocket() {
|
|
35088
35656
|
const deadline = Date.now() + 2e3;
|
|
35089
|
-
while ((0,
|
|
35657
|
+
while ((0, import_node_fs33.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
35090
35658
|
await new Promise((r) => setTimeout(r, 50));
|
|
35091
35659
|
}
|
|
35092
|
-
if ((0,
|
|
35660
|
+
if ((0, import_node_fs33.existsSync)(PATHS.socket)) {
|
|
35093
35661
|
try {
|
|
35094
|
-
(0,
|
|
35662
|
+
(0, import_node_fs33.unlinkSync)(PATHS.socket);
|
|
35095
35663
|
} catch {
|
|
35096
35664
|
}
|
|
35097
35665
|
}
|
|
@@ -35099,26 +35667,26 @@ async function releaseStaleSocket() {
|
|
|
35099
35667
|
|
|
35100
35668
|
// src/commands/service.ts
|
|
35101
35669
|
var import_node_child_process12 = require("child_process");
|
|
35102
|
-
var
|
|
35103
|
-
var
|
|
35670
|
+
var import_node_fs35 = require("fs");
|
|
35671
|
+
var import_node_path25 = require("path");
|
|
35104
35672
|
var import_node_os10 = require("os");
|
|
35105
35673
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
35106
35674
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
35107
35675
|
function resolveTemplate() {
|
|
35108
|
-
const templatePath = (0,
|
|
35109
|
-
if (!(0,
|
|
35676
|
+
const templatePath = (0, import_node_path25.join)(__dirname, "systemd", "threatcrushd.service");
|
|
35677
|
+
if (!(0, import_node_fs35.existsSync)(templatePath)) {
|
|
35110
35678
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
35111
35679
|
}
|
|
35112
|
-
return (0,
|
|
35680
|
+
return (0, import_node_fs35.readFileSync)(templatePath, "utf-8");
|
|
35113
35681
|
}
|
|
35114
35682
|
function stableBinPath(binPath) {
|
|
35115
35683
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
35116
35684
|
if (stable === binPath) return binPath;
|
|
35117
|
-
return (0,
|
|
35685
|
+
return (0, import_node_fs35.existsSync)(stable) ? stable : binPath;
|
|
35118
35686
|
}
|
|
35119
35687
|
function resolveBinPath() {
|
|
35120
35688
|
const arg = process.argv[1];
|
|
35121
|
-
if (arg && (0,
|
|
35689
|
+
if (arg && (0, import_node_fs35.existsSync)(arg)) return stableBinPath(arg);
|
|
35122
35690
|
try {
|
|
35123
35691
|
return (0, import_node_child_process12.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
35124
35692
|
} catch {
|
|
@@ -35128,11 +35696,11 @@ function resolveBinPath() {
|
|
|
35128
35696
|
function stableNodePath(execPath) {
|
|
35129
35697
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
35130
35698
|
if (stable === execPath) return execPath;
|
|
35131
|
-
return (0,
|
|
35699
|
+
return (0, import_node_fs35.existsSync)(stable) ? stable : execPath;
|
|
35132
35700
|
}
|
|
35133
35701
|
function looksLikeNodeScript(path) {
|
|
35134
35702
|
try {
|
|
35135
|
-
const head = (0,
|
|
35703
|
+
const head = (0, import_node_fs35.readFileSync)(path, "utf-8").slice(0, 120);
|
|
35136
35704
|
return /^#!.*\bnode\b/.test(head);
|
|
35137
35705
|
} catch {
|
|
35138
35706
|
return false;
|
|
@@ -35172,7 +35740,7 @@ function callerHome() {
|
|
|
35172
35740
|
try {
|
|
35173
35741
|
const line = (0, import_node_child_process12.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
35174
35742
|
const home = line.split(":")[5];
|
|
35175
|
-
return home && (0,
|
|
35743
|
+
return home && (0, import_node_fs35.existsSync)(home) ? home : null;
|
|
35176
35744
|
} catch {
|
|
35177
35745
|
return null;
|
|
35178
35746
|
}
|
|
@@ -35180,13 +35748,13 @@ function callerHome() {
|
|
|
35180
35748
|
function stopUserModeDaemon() {
|
|
35181
35749
|
const home = callerHome();
|
|
35182
35750
|
if (!home) return;
|
|
35183
|
-
const runDir = (0,
|
|
35184
|
-
const pidFile = (0,
|
|
35185
|
-
const socket = (0,
|
|
35186
|
-
if (!(0,
|
|
35751
|
+
const runDir = (0, import_node_path25.join)(home, ".threatcrush", "run");
|
|
35752
|
+
const pidFile = (0, import_node_path25.join)(runDir, "threatcrushd.pid");
|
|
35753
|
+
const socket = (0, import_node_path25.join)(runDir, "threatcrushd.sock");
|
|
35754
|
+
if (!(0, import_node_fs35.existsSync)(pidFile) && !(0, import_node_fs35.existsSync)(socket)) return;
|
|
35187
35755
|
let pid = null;
|
|
35188
35756
|
try {
|
|
35189
|
-
pid = Number.parseInt((0,
|
|
35757
|
+
pid = Number.parseInt((0, import_node_fs35.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
35190
35758
|
} catch {
|
|
35191
35759
|
pid = null;
|
|
35192
35760
|
}
|
|
@@ -35199,7 +35767,7 @@ function stopUserModeDaemon() {
|
|
|
35199
35767
|
}
|
|
35200
35768
|
for (const path of [socket, pidFile]) {
|
|
35201
35769
|
try {
|
|
35202
|
-
if ((0,
|
|
35770
|
+
if ((0, import_node_fs35.existsSync)(path)) (0, import_node_fs35.rmSync)(path);
|
|
35203
35771
|
} catch {
|
|
35204
35772
|
}
|
|
35205
35773
|
}
|
|
@@ -35217,7 +35785,7 @@ async function installServiceCommand() {
|
|
|
35217
35785
|
}
|
|
35218
35786
|
const noSystemd = systemdUnavailableReason({
|
|
35219
35787
|
hasSystemctl: (0, import_node_child_process12.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
35220
|
-
booted: (0,
|
|
35788
|
+
booted: (0, import_node_fs35.existsSync)("/run/systemd/system")
|
|
35221
35789
|
});
|
|
35222
35790
|
if (noSystemd) {
|
|
35223
35791
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -35239,7 +35807,7 @@ async function installServiceCommand() {
|
|
|
35239
35807
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
35240
35808
|
let nodePath = stableNodePath(process.execPath);
|
|
35241
35809
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
35242
|
-
binPath = (0,
|
|
35810
|
+
binPath = (0, import_node_fs35.realpathSync)(binPath);
|
|
35243
35811
|
nodePath = process.execPath;
|
|
35244
35812
|
}
|
|
35245
35813
|
if (isNodeScript) {
|
|
@@ -35252,9 +35820,9 @@ async function installServiceCommand() {
|
|
|
35252
35820
|
}
|
|
35253
35821
|
}
|
|
35254
35822
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
35255
|
-
const configDir = (0,
|
|
35823
|
+
const configDir = (0, import_node_path25.join)((0, import_node_os10.homedir)(), ".threatcrush");
|
|
35256
35824
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
35257
|
-
(0,
|
|
35825
|
+
(0, import_node_fs35.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
35258
35826
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
35259
35827
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
35260
35828
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -35303,20 +35871,20 @@ function ensureSystemDirs(configDir) {
|
|
|
35303
35871
|
];
|
|
35304
35872
|
let admGid = null;
|
|
35305
35873
|
try {
|
|
35306
|
-
admGid = (0,
|
|
35874
|
+
admGid = (0, import_node_fs35.statSync)("/var/log/auth.log").gid;
|
|
35307
35875
|
} catch {
|
|
35308
35876
|
}
|
|
35309
35877
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
35310
35878
|
try {
|
|
35311
|
-
(0,
|
|
35879
|
+
(0, import_node_fs35.mkdirSync)(path, { recursive: true });
|
|
35312
35880
|
} catch {
|
|
35313
35881
|
}
|
|
35314
35882
|
try {
|
|
35315
35883
|
if (groupWritable && admGid !== null) {
|
|
35316
|
-
(0,
|
|
35884
|
+
(0, import_node_fs35.chmodSync)(path, sticky ? 1533 : 509);
|
|
35317
35885
|
(0, import_node_child_process12.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
35318
35886
|
} else {
|
|
35319
|
-
(0,
|
|
35887
|
+
(0, import_node_fs35.chmodSync)(path, 493);
|
|
35320
35888
|
}
|
|
35321
35889
|
} catch {
|
|
35322
35890
|
}
|
|
@@ -35344,7 +35912,7 @@ async function uninstallServiceCommand() {
|
|
|
35344
35912
|
} catch {
|
|
35345
35913
|
}
|
|
35346
35914
|
try {
|
|
35347
|
-
if ((0,
|
|
35915
|
+
if ((0, import_node_fs35.existsSync)(UNIT_PATH)) {
|
|
35348
35916
|
(0, import_node_child_process12.execSync)(`rm -f ${UNIT_PATH}`);
|
|
35349
35917
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
35350
35918
|
}
|
|
@@ -35358,7 +35926,7 @@ async function uninstallServiceCommand() {
|
|
|
35358
35926
|
}
|
|
35359
35927
|
|
|
35360
35928
|
// src/commands/save.ts
|
|
35361
|
-
var
|
|
35929
|
+
var import_node_fs36 = require("fs");
|
|
35362
35930
|
var import_toml5 = __toESM(require_toml());
|
|
35363
35931
|
init_paths();
|
|
35364
35932
|
var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
|
|
@@ -35396,9 +35964,9 @@ async function saveCommand(opts = {}) {
|
|
|
35396
35964
|
}
|
|
35397
35965
|
const path = opts.config ?? PATHS.configFile;
|
|
35398
35966
|
let config = {};
|
|
35399
|
-
if ((0,
|
|
35967
|
+
if ((0, import_node_fs36.existsSync)(path)) {
|
|
35400
35968
|
try {
|
|
35401
|
-
config = import_toml5.default.parse((0,
|
|
35969
|
+
config = import_toml5.default.parse((0, import_node_fs36.readFileSync)(path, "utf-8"));
|
|
35402
35970
|
} catch (err) {
|
|
35403
35971
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
35404
35972
|
`));
|
|
@@ -35510,16 +36078,16 @@ function welcomeCommand() {
|
|
|
35510
36078
|
}
|
|
35511
36079
|
|
|
35512
36080
|
// src/commands/properties.ts
|
|
35513
|
-
var
|
|
35514
|
-
var
|
|
36081
|
+
var import_node_fs37 = require("fs");
|
|
36082
|
+
var import_node_path26 = require("path");
|
|
35515
36083
|
var import_node_readline6 = __toESM(require("readline"));
|
|
35516
36084
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
35517
36085
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
35518
36086
|
function prompt(question) {
|
|
35519
36087
|
const rl = import_node_readline6.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
35520
|
-
return new Promise((
|
|
36088
|
+
return new Promise((resolve6) => rl.question(question, (answer) => {
|
|
35521
36089
|
rl.close();
|
|
35522
|
-
|
|
36090
|
+
resolve6(answer.trim());
|
|
35523
36091
|
}));
|
|
35524
36092
|
}
|
|
35525
36093
|
async function requireAuth() {
|
|
@@ -35840,8 +36408,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
35840
36408
|
}
|
|
35841
36409
|
}
|
|
35842
36410
|
function parseImportFile(path) {
|
|
35843
|
-
const ext = (0,
|
|
35844
|
-
const raw = (0,
|
|
36411
|
+
const ext = (0, import_node_path26.extname)(path).toLowerCase();
|
|
36412
|
+
const raw = (0, import_node_fs37.readFileSync)(path, "utf-8");
|
|
35845
36413
|
if (ext === ".json") {
|
|
35846
36414
|
const parsed = JSON.parse(raw);
|
|
35847
36415
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -36036,7 +36604,7 @@ async function rulesCommand(opts) {
|
|
|
36036
36604
|
}
|
|
36037
36605
|
|
|
36038
36606
|
// src/commands/harden.ts
|
|
36039
|
-
var
|
|
36607
|
+
var import_node_fs38 = require("fs");
|
|
36040
36608
|
var import_node_child_process13 = require("child_process");
|
|
36041
36609
|
function tryExec(cmd) {
|
|
36042
36610
|
try {
|
|
@@ -36047,7 +36615,7 @@ function tryExec(cmd) {
|
|
|
36047
36615
|
}
|
|
36048
36616
|
function tryRead(path) {
|
|
36049
36617
|
try {
|
|
36050
|
-
return (0,
|
|
36618
|
+
return (0, import_node_fs38.readFileSync)(path, "utf-8");
|
|
36051
36619
|
} catch {
|
|
36052
36620
|
return null;
|
|
36053
36621
|
}
|
|
@@ -36151,8 +36719,8 @@ function checkSshWeakConfig() {
|
|
|
36151
36719
|
};
|
|
36152
36720
|
}
|
|
36153
36721
|
function checkAutoUpdates() {
|
|
36154
|
-
const unattended = (0,
|
|
36155
|
-
const dnfAuto = (0,
|
|
36722
|
+
const unattended = (0, import_node_fs38.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs38.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
36723
|
+
const dnfAuto = (0, import_node_fs38.existsSync)("/etc/dnf/automatic.conf");
|
|
36156
36724
|
if (unattended || dnfAuto) {
|
|
36157
36725
|
return {
|
|
36158
36726
|
key: "auto-updates",
|
|
@@ -36278,7 +36846,7 @@ function checkFail2ban() {
|
|
|
36278
36846
|
explanation: "fail2ban is installed and running."
|
|
36279
36847
|
};
|
|
36280
36848
|
}
|
|
36281
|
-
if ((0,
|
|
36849
|
+
if ((0, import_node_fs38.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
36282
36850
|
return {
|
|
36283
36851
|
key: checkKey,
|
|
36284
36852
|
status: "warn",
|
|
@@ -36726,7 +37294,7 @@ ${source_default.dim(" C R U S H")}
|
|
|
36726
37294
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
36727
37295
|
var PKG_NAME = "@profullstack/threatcrush";
|
|
36728
37296
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
36729
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
37297
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush", "install.json");
|
|
36730
37298
|
function detectPackageManager() {
|
|
36731
37299
|
try {
|
|
36732
37300
|
const npmGlobal = (0, import_node_child_process15.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
@@ -36752,7 +37320,7 @@ function detectPackageManager() {
|
|
|
36752
37320
|
}
|
|
36753
37321
|
function readInstallConfig() {
|
|
36754
37322
|
try {
|
|
36755
|
-
return JSON.parse((0,
|
|
37323
|
+
return JSON.parse((0, import_node_fs39.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
36756
37324
|
} catch {
|
|
36757
37325
|
return {};
|
|
36758
37326
|
}
|
|
@@ -36889,6 +37457,7 @@ program2.name("threatcrush").description(
|
|
|
36889
37457
|
${source_default.dim("Examples:")}
|
|
36890
37458
|
${source_default.green("$")} threatcrush monitor ${source_default.dim("# Real-time monitoring")}
|
|
36891
37459
|
${source_default.green("$")} threatcrush tui ${source_default.dim("# Interactive dashboard")}
|
|
37460
|
+
${source_default.green("$")} threatcrush watchdog ${source_default.dim("# Triage logged attacks: hole or not?")}
|
|
36892
37461
|
${source_default.green("$")} threatcrush scan ./src ${source_default.dim("# Scan code for vulns")}
|
|
36893
37462
|
${source_default.green("$")} threatcrush pentest URL ${source_default.dim("# Quick web checks on a URL")}
|
|
36894
37463
|
${source_default.green("$")} threatcrush ai-scan URL ${source_default.dim("# Red-team your AI/LLM endpoint (OWASP LLM Top 10)")}
|
|
@@ -36919,6 +37488,24 @@ program2.command("monitor").description("Watch nginx, auth and syslog for attack
|
|
|
36919
37488
|
program2.command("tui").description("Interactive security dashboard (htop for security)").alias("dashboard").option("--demo", "Run on canned events instead of connecting to the daemon").action(async (opts) => {
|
|
36920
37489
|
await monitorCommand({ tui: true, demo: opts.demo });
|
|
36921
37490
|
});
|
|
37491
|
+
var watchdogCmd = program2.command("watchdog").description("Triage the attacks the daemon logged: was it a hole? fix it, PR it, mark it").option("--dir <dir>", "Watchdog log directory").action((opts) => {
|
|
37492
|
+
watchdogListCommand(opts);
|
|
37493
|
+
});
|
|
37494
|
+
watchdogCmd.command("list").alias("ls").description("Findings to triage, worst first (answered 2xx, then 5xx, ...)").option("--status <status>", "Only this triage status: new | hole | fp | fixed").option("--outcome <outcome>", "Only this outcome: answered | errored | unknown | redirected | refused").option("-a, --all", "Include refused and already-triaged findings").option("-n, --limit <n>", "Show at most n findings", "50").option("--json", "Output findings as JSON").action((_opts, cmd) => {
|
|
37495
|
+
watchdogListCommand(cmd.optsWithGlobals());
|
|
37496
|
+
});
|
|
37497
|
+
watchdogCmd.command("show <id>").description("Every detail of one finding: samples, sources, a repro command").option("--json", "Output as JSON").action((id, _opts, cmd) => {
|
|
37498
|
+
watchdogShowCommand(id, cmd.optsWithGlobals());
|
|
37499
|
+
});
|
|
37500
|
+
watchdogCmd.command("brief <id>").description("Markdown hand-off to verify and fix one finding (paste into an issue, PR or agent)").action((id, _opts, cmd) => {
|
|
37501
|
+
watchdogBriefCommand(id, cmd.optsWithGlobals());
|
|
37502
|
+
});
|
|
37503
|
+
watchdogCmd.command("mark <id> <status>").description("Record a verdict: hole | fp | fixed | new").option("--note <text>", "Why: what you checked, what you found").option("--pr <url>", "The PR that fixes it").action((id, status, _opts, cmd) => {
|
|
37504
|
+
watchdogMarkCommand(id, status, cmd.optsWithGlobals());
|
|
37505
|
+
});
|
|
37506
|
+
watchdogCmd.command("path").description("Print the watchdog log directory").action((_opts, cmd) => {
|
|
37507
|
+
watchdogPathCommand(cmd.optsWithGlobals());
|
|
37508
|
+
});
|
|
36922
37509
|
program2.command("init").description("Sign in, auto-detect services, and configure ThreatCrush").option("-y, --yes", "Don't ask; answer yes to every question").option("--offline", "Skip signing in to threatcrush.com").action(async (opts) => {
|
|
36923
37510
|
await initCommand({ yes: opts.yes, offline: opts.offline });
|
|
36924
37511
|
});
|
|
@@ -37026,7 +37613,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
37026
37613
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
37027
37614
|
console.log(LOGO2);
|
|
37028
37615
|
const logPath = PATHS.logFile;
|
|
37029
|
-
if (!(0,
|
|
37616
|
+
if (!(0, import_node_fs39.existsSync)(logPath)) {
|
|
37030
37617
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
37031
37618
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
37032
37619
|
return;
|
|
@@ -37094,10 +37681,10 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
37094
37681
|
program2.command("remove").description("Uninstall ThreatCrush and the installed bundle").alias("uninstall").action(async () => {
|
|
37095
37682
|
console.log(LOGO2);
|
|
37096
37683
|
const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
37097
|
-
const confirm = await new Promise((
|
|
37684
|
+
const confirm = await new Promise((resolve6) => {
|
|
37098
37685
|
rl.question(source_default.yellow(" Are you sure you want to uninstall ThreatCrush? (y/N): "), (answer) => {
|
|
37099
37686
|
rl.close();
|
|
37100
|
-
|
|
37687
|
+
resolve6(answer.trim().toLowerCase());
|
|
37101
37688
|
});
|
|
37102
37689
|
});
|
|
37103
37690
|
if (confirm !== "y" && confirm !== "yes") {
|
|
@@ -37199,19 +37786,19 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
37199
37786
|
});
|
|
37200
37787
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
37201
37788
|
console.log(LOGO2);
|
|
37202
|
-
const configPath = (0,
|
|
37789
|
+
const configPath = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush", "config.json");
|
|
37203
37790
|
let email = "";
|
|
37204
37791
|
try {
|
|
37205
|
-
const config = JSON.parse((0,
|
|
37792
|
+
const config = JSON.parse((0, import_node_fs39.readFileSync)(configPath, "utf-8"));
|
|
37206
37793
|
email = config.email || "";
|
|
37207
37794
|
} catch {
|
|
37208
37795
|
}
|
|
37209
37796
|
if (!email) {
|
|
37210
37797
|
const rl2 = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
37211
|
-
email = await new Promise((
|
|
37798
|
+
email = await new Promise((resolve6) => {
|
|
37212
37799
|
rl2.question(source_default.green(" Enter your email: "), (answer) => {
|
|
37213
37800
|
rl2.close();
|
|
37214
|
-
|
|
37801
|
+
resolve6(answer.trim());
|
|
37215
37802
|
});
|
|
37216
37803
|
});
|
|
37217
37804
|
if (!email || !email.includes("@")) {
|
|
@@ -37219,9 +37806,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
37219
37806
|
return;
|
|
37220
37807
|
}
|
|
37221
37808
|
try {
|
|
37222
|
-
const dir = (0,
|
|
37223
|
-
if (!(0,
|
|
37224
|
-
(0,
|
|
37809
|
+
const dir = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush");
|
|
37810
|
+
if (!(0, import_node_fs39.existsSync)(dir)) (0, import_node_fs39.mkdirSync)(dir, { recursive: true });
|
|
37811
|
+
(0, import_node_fs39.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
37225
37812
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
37226
37813
|
} catch {
|
|
37227
37814
|
}
|
|
@@ -37265,10 +37852,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
37265
37852
|
}
|
|
37266
37853
|
console.log();
|
|
37267
37854
|
const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
37268
|
-
const confirm = await new Promise((
|
|
37855
|
+
const confirm = await new Promise((resolve6) => {
|
|
37269
37856
|
rl.question(source_default.yellow(" Publish this module? (y/N): "), (answer) => {
|
|
37270
37857
|
rl.close();
|
|
37271
|
-
|
|
37858
|
+
resolve6(answer.trim().toLowerCase());
|
|
37272
37859
|
});
|
|
37273
37860
|
});
|
|
37274
37861
|
if (confirm !== "y" && confirm !== "yes") {
|