@profullstack/threatcrush 0.13.53 → 0.13.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/index.js +436 -150
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1655,20 +1655,20 @@ var require_parse_async = __commonJS({
|
|
|
1655
1655
|
const index = 0;
|
|
1656
1656
|
const blocksize = opts.blocksize || 40960;
|
|
1657
1657
|
const parser = new TOMLParser();
|
|
1658
|
-
return new Promise((
|
|
1659
|
-
setImmediate(parseAsyncNext, index, blocksize,
|
|
1658
|
+
return new Promise((resolve7, reject) => {
|
|
1659
|
+
setImmediate(parseAsyncNext, index, blocksize, resolve7, reject);
|
|
1660
1660
|
});
|
|
1661
|
-
function parseAsyncNext(index2, blocksize2,
|
|
1661
|
+
function parseAsyncNext(index2, blocksize2, resolve7, reject) {
|
|
1662
1662
|
if (index2 >= str3.length) {
|
|
1663
1663
|
try {
|
|
1664
|
-
return
|
|
1664
|
+
return resolve7(parser.finish());
|
|
1665
1665
|
} catch (err) {
|
|
1666
1666
|
return reject(prettyError(err, str3));
|
|
1667
1667
|
}
|
|
1668
1668
|
}
|
|
1669
1669
|
try {
|
|
1670
1670
|
parser.parse(str3.slice(index2, index2 + blocksize2));
|
|
1671
|
-
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2,
|
|
1671
|
+
setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve7, reject);
|
|
1672
1672
|
} catch (err) {
|
|
1673
1673
|
reject(prettyError(err, str3));
|
|
1674
1674
|
}
|
|
@@ -1694,7 +1694,7 @@ var require_parse_stream = __commonJS({
|
|
|
1694
1694
|
function parseReadable(stm) {
|
|
1695
1695
|
const parser = new TOMLParser();
|
|
1696
1696
|
stm.setEncoding("utf8");
|
|
1697
|
-
return new Promise((
|
|
1697
|
+
return new Promise((resolve7, reject) => {
|
|
1698
1698
|
let readable;
|
|
1699
1699
|
let ended = false;
|
|
1700
1700
|
let errored = false;
|
|
@@ -1702,7 +1702,7 @@ var require_parse_stream = __commonJS({
|
|
|
1702
1702
|
ended = true;
|
|
1703
1703
|
if (readable) return;
|
|
1704
1704
|
try {
|
|
1705
|
-
|
|
1705
|
+
resolve7(parser.finish());
|
|
1706
1706
|
} catch (err) {
|
|
1707
1707
|
reject(err);
|
|
1708
1708
|
}
|
|
@@ -5597,11 +5597,11 @@ function daysInMonth(year, month) {
|
|
|
5597
5597
|
function isLeapYear(year) {
|
|
5598
5598
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
5599
5599
|
}
|
|
5600
|
-
function dayOfWeek(year, month,
|
|
5600
|
+
function dayOfWeek(year, month, day2) {
|
|
5601
5601
|
const offsets = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
|
|
5602
5602
|
const y = month < 3 ? year - 1 : year;
|
|
5603
5603
|
const leaps = Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400);
|
|
5604
|
-
const value = (y + leaps + offsets[month - 1] +
|
|
5604
|
+
const value = (y + leaps + offsets[month - 1] + day2) % 7;
|
|
5605
5605
|
return (value % 7 + 7) % 7;
|
|
5606
5606
|
}
|
|
5607
5607
|
function drawCalendar(surface, options) {
|
|
@@ -5639,20 +5639,20 @@ function drawCalendar(surface, options) {
|
|
|
5639
5639
|
}
|
|
5640
5640
|
const first = (dayOfWeek(year, month, 1) - weekStart + 7) % 7;
|
|
5641
5641
|
const total = daysInMonth(year, month);
|
|
5642
|
-
for (let
|
|
5643
|
-
const cell = first +
|
|
5642
|
+
for (let day2 = 1; day2 <= total; day2++) {
|
|
5643
|
+
const cell = first + day2 - 1;
|
|
5644
5644
|
const y = row + Math.floor(cell / 7);
|
|
5645
5645
|
if (y >= surface.height)
|
|
5646
5646
|
break;
|
|
5647
5647
|
const x = cell % 7 * DAY_WIDTH;
|
|
5648
|
-
const mark = marks.get(
|
|
5649
|
-
const selected = options.selected ===
|
|
5648
|
+
const mark = marks.get(day2);
|
|
5649
|
+
const selected = options.selected === day2;
|
|
5650
5650
|
const style = {
|
|
5651
5651
|
fg: selected ? theme.background : mark?.color ?? base,
|
|
5652
5652
|
bg: selected ? theme.accent : mark?.background ?? bg,
|
|
5653
5653
|
attrs: selected || mark?.bold ? Attr.Bold : 0
|
|
5654
5654
|
};
|
|
5655
|
-
surface.text(x, y, fit(String(
|
|
5655
|
+
surface.text(x, y, fit(String(day2), 2, "right"), style);
|
|
5656
5656
|
}
|
|
5657
5657
|
}
|
|
5658
5658
|
function calendarHeight(options) {
|
|
@@ -14535,12 +14535,12 @@ function load() {
|
|
|
14535
14535
|
if (table)
|
|
14536
14536
|
return table;
|
|
14537
14537
|
const byKey = /* @__PURE__ */ new Map();
|
|
14538
|
-
for (const [key,
|
|
14538
|
+
for (const [key, short2, name, group, keywords] of OPENEMOJI_ROWS) {
|
|
14539
14539
|
byKey.set(key, {
|
|
14540
14540
|
key,
|
|
14541
14541
|
char: charOf(key),
|
|
14542
14542
|
name,
|
|
14543
|
-
shortcode: `oe_${
|
|
14543
|
+
shortcode: `oe_${short2 || slugOf(name)}`,
|
|
14544
14544
|
group: OPENEMOJI_GROUPS[group] ?? "",
|
|
14545
14545
|
keywords: keywords ? keywords.split(" ") : []
|
|
14546
14546
|
});
|
|
@@ -16764,8 +16764,8 @@ var init_app = __esm({
|
|
|
16764
16764
|
this.frame();
|
|
16765
16765
|
}, interval);
|
|
16766
16766
|
this.timer.unref?.();
|
|
16767
|
-
await new Promise((
|
|
16768
|
-
this.exitResolve =
|
|
16767
|
+
await new Promise((resolve7) => {
|
|
16768
|
+
this.exitResolve = resolve7;
|
|
16769
16769
|
});
|
|
16770
16770
|
}
|
|
16771
16771
|
targetFps() {
|
|
@@ -17238,7 +17238,7 @@ var init_ipc_client = __esm({
|
|
|
17238
17238
|
if (!(0, import_node_fs8.existsSync)(this.socketPath)) {
|
|
17239
17239
|
throw new Error(`threatcrushd socket not found at ${this.socketPath}`);
|
|
17240
17240
|
}
|
|
17241
|
-
return new Promise((
|
|
17241
|
+
return new Promise((resolve7, reject) => {
|
|
17242
17242
|
const sock = (0, import_node_net.createConnection)(this.socketPath);
|
|
17243
17243
|
const timer = setTimeout(() => {
|
|
17244
17244
|
sock.destroy();
|
|
@@ -17251,7 +17251,7 @@ var init_ipc_client = __esm({
|
|
|
17251
17251
|
sock.on("data", (chunk2) => this.onData(chunk2.toString()));
|
|
17252
17252
|
sock.on("close", () => this.onClose());
|
|
17253
17253
|
sock.on("error", () => this.onClose());
|
|
17254
|
-
|
|
17254
|
+
resolve7();
|
|
17255
17255
|
});
|
|
17256
17256
|
sock.once("error", (err) => {
|
|
17257
17257
|
clearTimeout(timer);
|
|
@@ -17267,14 +17267,14 @@ var init_ipc_client = __esm({
|
|
|
17267
17267
|
if (!this.socket) throw new Error("not connected");
|
|
17268
17268
|
const id = this.nextId++;
|
|
17269
17269
|
const frame = params ? { id, method, params } : { id, method };
|
|
17270
|
-
return new Promise((
|
|
17270
|
+
return new Promise((resolve7, reject) => {
|
|
17271
17271
|
const timer = setTimeout(() => {
|
|
17272
17272
|
this.pending.delete(id);
|
|
17273
17273
|
reject(new Error(
|
|
17274
17274
|
`threatcrushd did not answer "${method}" within ${REQUEST_TIMEOUT_MS / 1e3}s; if it is older than this CLI, update it`
|
|
17275
17275
|
));
|
|
17276
17276
|
}, REQUEST_TIMEOUT_MS);
|
|
17277
|
-
this.pending.set(id, { resolve:
|
|
17277
|
+
this.pending.set(id, { resolve: resolve7, reject, timer });
|
|
17278
17278
|
this.socket.write(JSON.stringify(frame) + "\n", (err) => {
|
|
17279
17279
|
if (err && this.pending.delete(id)) {
|
|
17280
17280
|
clearTimeout(timer);
|
|
@@ -18276,7 +18276,7 @@ function isPublicAddress(ip) {
|
|
|
18276
18276
|
if (v === 6) return !/^(::1?$|f[cd]|fe[89ab]|ff)/i.test(ip);
|
|
18277
18277
|
return false;
|
|
18278
18278
|
}
|
|
18279
|
-
function localMapData(state, geo,
|
|
18279
|
+
function localMapData(state, geo, hostname5, now = Date.now()) {
|
|
18280
18280
|
const by = /* @__PURE__ */ new Map();
|
|
18281
18281
|
for (const e of state.events) {
|
|
18282
18282
|
const ip = e.source_ip;
|
|
@@ -18300,7 +18300,7 @@ function localMapData(state, geo, hostname4, now = Date.now()) {
|
|
|
18300
18300
|
const o = by.get(t.ip);
|
|
18301
18301
|
if (o) o.count = Math.max(o.count, t.count);
|
|
18302
18302
|
}
|
|
18303
|
-
const servers = geo.self ? [{ id: "self", name:
|
|
18303
|
+
const servers = geo.self ? [{ id: "self", name: hostname5, ...geo.self, online: state.connection === "live" }] : [];
|
|
18304
18304
|
return { servers, origins: [...by.values()], windowMinutes: 0, generatedAt: new Date(now).toISOString() };
|
|
18305
18305
|
}
|
|
18306
18306
|
function sourceAddresses(state) {
|
|
@@ -22084,7 +22084,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22084
22084
|
const negativeNumberArg = (arg) => {
|
|
22085
22085
|
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
22086
22086
|
return !this._getCommandAndAncestors().some(
|
|
22087
|
-
(cmd) => cmd.options.map((opt) => opt.short).some((
|
|
22087
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short2) => /^-\d$/.test(short2))
|
|
22088
22088
|
);
|
|
22089
22089
|
};
|
|
22090
22090
|
let activeVariadicOption = null;
|
|
@@ -23425,10 +23425,10 @@ var source_default = chalk;
|
|
|
23425
23425
|
|
|
23426
23426
|
// src/index.ts
|
|
23427
23427
|
var import_readline = __toESM(require("readline"));
|
|
23428
|
-
var
|
|
23428
|
+
var import_node_child_process24 = require("child_process");
|
|
23429
23429
|
var import_node_fs55 = require("fs");
|
|
23430
|
-
var
|
|
23431
|
-
var
|
|
23430
|
+
var import_node_path42 = require("path");
|
|
23431
|
+
var import_node_os17 = require("os");
|
|
23432
23432
|
|
|
23433
23433
|
// src/commands/monitor.ts
|
|
23434
23434
|
var import_node_fs11 = require("fs");
|
|
@@ -31121,20 +31121,20 @@ function groupFindings(records, triage = {}) {
|
|
|
31121
31121
|
}
|
|
31122
31122
|
f.samples.push(r);
|
|
31123
31123
|
}
|
|
31124
|
-
const
|
|
31124
|
+
const findings2 = [];
|
|
31125
31125
|
for (const f of byId.values()) {
|
|
31126
31126
|
const { _ips, ...rest } = f;
|
|
31127
31127
|
rest.source_count = _ips.size;
|
|
31128
31128
|
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);
|
|
31129
|
-
|
|
31129
|
+
findings2.push(rest);
|
|
31130
31130
|
}
|
|
31131
31131
|
const triaged = (f) => f.triage.status === "new" ? 0 : 1;
|
|
31132
|
-
return
|
|
31132
|
+
return findings2.sort((a, b) => triaged(a) - triaged(b) || OUTCOME_ORDER.indexOf(a.outcome) - OUTCOME_ORDER.indexOf(b.outcome) || SEVERITY_RANK2[b.severity] - SEVERITY_RANK2[a.severity] || b.count - a.count || b.last_seen.localeCompare(a.last_seen));
|
|
31133
31133
|
}
|
|
31134
|
-
function findFinding(
|
|
31135
|
-
const exact =
|
|
31134
|
+
function findFinding(findings2, id) {
|
|
31135
|
+
const exact = findings2.find((f) => f.id === id);
|
|
31136
31136
|
if (exact) return exact;
|
|
31137
|
-
const matches2 =
|
|
31137
|
+
const matches2 = findings2.filter((f) => f.id.startsWith(id));
|
|
31138
31138
|
return matches2.length === 1 ? matches2[0] : null;
|
|
31139
31139
|
}
|
|
31140
31140
|
function shellQuote(s) {
|
|
@@ -31231,32 +31231,32 @@ function where(f) {
|
|
|
31231
31231
|
}
|
|
31232
31232
|
function watchdogListCommand(opts) {
|
|
31233
31233
|
const dir = resolveWatchdogDir(opts.dir);
|
|
31234
|
-
let
|
|
31235
|
-
if (opts.status)
|
|
31236
|
-
if (opts.outcome)
|
|
31234
|
+
let findings2 = load2(dir);
|
|
31235
|
+
if (opts.status) findings2 = findings2.filter((f) => f.triage.status === opts.status);
|
|
31236
|
+
if (opts.outcome) findings2 = findings2.filter((f) => f.outcome === opts.outcome);
|
|
31237
31237
|
if (!opts.all && !opts.status && !opts.outcome) {
|
|
31238
|
-
|
|
31238
|
+
findings2 = findings2.filter((f) => (f.triage.status === "new" || f.triage.status === "hole") && f.outcome !== "refused");
|
|
31239
31239
|
}
|
|
31240
31240
|
const limit = opts.limit ? Math.max(1, parseInt(opts.limit, 10) || 50) : 50;
|
|
31241
31241
|
if (opts.json) {
|
|
31242
|
-
console.log(JSON.stringify(
|
|
31242
|
+
console.log(JSON.stringify(findings2.slice(0, limit), null, 2));
|
|
31243
31243
|
return;
|
|
31244
31244
|
}
|
|
31245
|
-
if (
|
|
31245
|
+
if (findings2.length === 0) {
|
|
31246
31246
|
const empty = (0, import_node_fs13.existsSync)((0, import_node_path11.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).`;
|
|
31247
31247
|
console.log(source_default.dim(empty));
|
|
31248
31248
|
return;
|
|
31249
31249
|
}
|
|
31250
|
-
console.log(source_default.dim(`${dir} \xB7 ${
|
|
31250
|
+
console.log(source_default.dim(`${dir} \xB7 ${findings2.length} finding(s)
|
|
31251
31251
|
`));
|
|
31252
|
-
for (const f of
|
|
31252
|
+
for (const f of findings2.slice(0, limit)) {
|
|
31253
31253
|
const statuses = Object.keys(f.statuses).join(",") || "\u2014";
|
|
31254
31254
|
console.log(
|
|
31255
31255
|
`${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)}`
|
|
31256
31256
|
);
|
|
31257
31257
|
}
|
|
31258
|
-
if (
|
|
31259
|
-
\u2026 ${
|
|
31258
|
+
if (findings2.length > limit) console.log(source_default.dim(`
|
|
31259
|
+
\u2026 ${findings2.length - limit} more (--limit)`));
|
|
31260
31260
|
console.log(source_default.dim("\nthreatcrush watchdog show <id> \xB7 brief <id> \xB7 mark <id> hole|fp|fixed"));
|
|
31261
31261
|
}
|
|
31262
31262
|
function resolve(dir, id) {
|
|
@@ -34773,9 +34773,9 @@ var import_node_os7 = __toESM(require("os"));
|
|
|
34773
34773
|
function emptyCounts() {
|
|
34774
34774
|
return { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
34775
34775
|
}
|
|
34776
|
-
function summarize(
|
|
34776
|
+
function summarize(findings2) {
|
|
34777
34777
|
const counts = emptyCounts();
|
|
34778
|
-
for (const f of
|
|
34778
|
+
for (const f of findings2) counts[f.severity] = (counts[f.severity] || 0) + 1;
|
|
34779
34779
|
return counts;
|
|
34780
34780
|
}
|
|
34781
34781
|
function workerId() {
|
|
@@ -36972,13 +36972,13 @@ function isRiskyLifecycleScript(body) {
|
|
|
36972
36972
|
return /\b(?:curl|wget)\b[^\n|]*\|\s*(?:\w*sh|bash|node|python)\b|\b(?:curl|wget)\b[^\n]*(?:https?:|--upload-file)|\b(?:node|python|ruby|perl)\s+-e\b|\b(?:base64|openssl)\b[^\n]*(?:-d|--decode)|\beval\s+|\bchmod\s+(?:\S+\s+)*(?:777|a\+rwx)\b/i.test(body);
|
|
36973
36973
|
}
|
|
36974
36974
|
function scanPackageJson(text) {
|
|
36975
|
-
const
|
|
36975
|
+
const findings2 = [];
|
|
36976
36976
|
const lines = text.split("\n");
|
|
36977
36977
|
let parsed;
|
|
36978
36978
|
try {
|
|
36979
36979
|
parsed = JSON.parse(text);
|
|
36980
36980
|
} catch {
|
|
36981
|
-
return
|
|
36981
|
+
return findings2;
|
|
36982
36982
|
}
|
|
36983
36983
|
const lineOf = (needle) => {
|
|
36984
36984
|
const index = lines.findIndex((line2) => line2.includes(`"${needle}"`));
|
|
@@ -36991,7 +36991,7 @@ function scanPackageJson(text) {
|
|
|
36991
36991
|
for (const name of Object.keys(deps)) {
|
|
36992
36992
|
const line2 = lineOf(name);
|
|
36993
36993
|
if (INTERNAL_MARKER.test(name)) {
|
|
36994
|
-
|
|
36994
|
+
findings2.push({
|
|
36995
36995
|
ruleId: "manifest-dependency-confusion",
|
|
36996
36996
|
title: "internal-looking package resolved from a public registry",
|
|
36997
36997
|
line: line2,
|
|
@@ -37005,7 +37005,7 @@ function scanPackageJson(text) {
|
|
|
37005
37005
|
}
|
|
37006
37006
|
const squat = detectTyposquat(name, "npm");
|
|
37007
37007
|
if (squat) {
|
|
37008
|
-
|
|
37008
|
+
findings2.push({
|
|
37009
37009
|
ruleId: "manifest-typosquat",
|
|
37010
37010
|
title: "dependency name close to a popular package",
|
|
37011
37011
|
line: line2,
|
|
@@ -37023,7 +37023,7 @@ function scanPackageJson(text) {
|
|
|
37023
37023
|
for (const [name, body] of Object.entries(scripts)) {
|
|
37024
37024
|
if (!LIFECYCLE_SCRIPTS.includes(name)) continue;
|
|
37025
37025
|
if (!isRiskyLifecycleScript(body)) continue;
|
|
37026
|
-
|
|
37026
|
+
findings2.push({
|
|
37027
37027
|
ruleId: "manifest-risky-install-lifecycle-script",
|
|
37028
37028
|
title: "risky install-time lifecycle script",
|
|
37029
37029
|
line: lineOf(name),
|
|
@@ -37035,10 +37035,10 @@ function scanPackageJson(text) {
|
|
|
37035
37035
|
});
|
|
37036
37036
|
}
|
|
37037
37037
|
}
|
|
37038
|
-
return
|
|
37038
|
+
return findings2;
|
|
37039
37039
|
}
|
|
37040
37040
|
function scanRequirementsTxt(text) {
|
|
37041
|
-
const
|
|
37041
|
+
const findings2 = [];
|
|
37042
37042
|
const lines = text.split("\n");
|
|
37043
37043
|
lines.forEach((raw, index) => {
|
|
37044
37044
|
const line2 = raw.trim();
|
|
@@ -37047,7 +37047,7 @@ function scanRequirementsTxt(text) {
|
|
|
37047
37047
|
const name = match?.[1];
|
|
37048
37048
|
if (!name) return;
|
|
37049
37049
|
if (INTERNAL_MARKER.test(name)) {
|
|
37050
|
-
|
|
37050
|
+
findings2.push({
|
|
37051
37051
|
ruleId: "manifest-dependency-confusion",
|
|
37052
37052
|
title: "internal-looking package resolved from a public index",
|
|
37053
37053
|
line: index + 1,
|
|
@@ -37061,7 +37061,7 @@ function scanRequirementsTxt(text) {
|
|
|
37061
37061
|
}
|
|
37062
37062
|
const squat = detectTyposquat(name, "pypi");
|
|
37063
37063
|
if (squat) {
|
|
37064
|
-
|
|
37064
|
+
findings2.push({
|
|
37065
37065
|
ruleId: "manifest-typosquat",
|
|
37066
37066
|
title: "dependency name close to a popular package",
|
|
37067
37067
|
line: index + 1,
|
|
@@ -37073,7 +37073,7 @@ function scanRequirementsTxt(text) {
|
|
|
37073
37073
|
});
|
|
37074
37074
|
}
|
|
37075
37075
|
});
|
|
37076
|
-
return
|
|
37076
|
+
return findings2;
|
|
37077
37077
|
}
|
|
37078
37078
|
|
|
37079
37079
|
// ../../packages/scan/src/secret-rules.ts
|
|
@@ -37700,7 +37700,7 @@ var CODE_SOFTENING = {
|
|
|
37700
37700
|
"self-describing": "in a value that describes itself"
|
|
37701
37701
|
};
|
|
37702
37702
|
function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
37703
|
-
const
|
|
37703
|
+
const findings2 = [];
|
|
37704
37704
|
const lines = text.split("\n");
|
|
37705
37705
|
const suppressions = collectSuppressions(lines);
|
|
37706
37706
|
const inTests = isTestPath(relativePath);
|
|
@@ -37722,7 +37722,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
37722
37722
|
placeholder: isPlaceholderAttribute(line2, value),
|
|
37723
37723
|
"self-describing": rule.keywordShaped === true && describesItsOwnKey(line2, value)
|
|
37724
37724
|
});
|
|
37725
|
-
|
|
37725
|
+
findings2.push({
|
|
37726
37726
|
ruleId: rule.id,
|
|
37727
37727
|
title: rule.name,
|
|
37728
37728
|
file: relativePath,
|
|
@@ -37753,7 +37753,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
37753
37753
|
docs: inDocs,
|
|
37754
37754
|
suppressed: foreignSecurityMark(lines[index] ?? "")
|
|
37755
37755
|
});
|
|
37756
|
-
|
|
37756
|
+
findings2.push({
|
|
37757
37757
|
ruleId: rule.id,
|
|
37758
37758
|
title: rule.title,
|
|
37759
37759
|
file: relativePath,
|
|
@@ -37777,7 +37777,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
37777
37777
|
docs: inDocs,
|
|
37778
37778
|
suppressed: foreignSecurityMark(lines[index] ?? "")
|
|
37779
37779
|
});
|
|
37780
|
-
|
|
37780
|
+
findings2.push({
|
|
37781
37781
|
ruleId: match.rule.id,
|
|
37782
37782
|
title: match.rule.title,
|
|
37783
37783
|
file: relativePath,
|
|
@@ -37791,7 +37791,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
37791
37791
|
category: "code"
|
|
37792
37792
|
});
|
|
37793
37793
|
}
|
|
37794
|
-
return
|
|
37794
|
+
return findings2;
|
|
37795
37795
|
}
|
|
37796
37796
|
function scanManifest(relativePath, filename, text) {
|
|
37797
37797
|
const manifestFindings = filename === "package.json" ? scanPackageJson(text) : filename === "requirements.txt" ? scanRequirementsTxt(text) : [];
|
|
@@ -37809,10 +37809,10 @@ function scanManifest(relativePath, filename, text) {
|
|
|
37809
37809
|
category: "manifest"
|
|
37810
37810
|
}));
|
|
37811
37811
|
}
|
|
37812
|
-
function meetsFailThreshold(
|
|
37812
|
+
function meetsFailThreshold(findings2, threshold) {
|
|
37813
37813
|
if (threshold.length === 0) return false;
|
|
37814
37814
|
const floor = Math.min(...threshold.map(severityRank));
|
|
37815
|
-
return
|
|
37815
|
+
return findings2.some((finding) => severityRank(finding.severity) >= floor);
|
|
37816
37816
|
}
|
|
37817
37817
|
|
|
37818
37818
|
// ../../packages/scan/src/node/walk.ts
|
|
@@ -37896,7 +37896,7 @@ function readIgnoreFile(root) {
|
|
|
37896
37896
|
function scanPath(targetPath, options = {}) {
|
|
37897
37897
|
const maxFileBytes = options.maxFileBytes ?? 1024 * 1024;
|
|
37898
37898
|
const allowed = options.categories ? new Set(options.categories) : null;
|
|
37899
|
-
const
|
|
37899
|
+
const findings2 = [];
|
|
37900
37900
|
const controls = new ControlAudit();
|
|
37901
37901
|
const unreadable = [];
|
|
37902
37902
|
let filesScanned = 0;
|
|
@@ -37918,7 +37918,7 @@ function scanPath(targetPath, options = {}) {
|
|
|
37918
37918
|
const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
|
|
37919
37919
|
const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
|
|
37920
37920
|
if (!scannable && !isManifest && !mayDeclareInterpreter) {
|
|
37921
|
-
recordSensitiveFile(filename, relativePath,
|
|
37921
|
+
recordSensitiveFile(filename, relativePath, findings2, []);
|
|
37922
37922
|
return;
|
|
37923
37923
|
}
|
|
37924
37924
|
let text;
|
|
@@ -37956,8 +37956,8 @@ function scanPath(targetPath, options = {}) {
|
|
|
37956
37956
|
...scanText(relativePath, text, declared ?? languageOf(filename)),
|
|
37957
37957
|
...isManifest ? scanManifest(relativePath, filename, text) : []
|
|
37958
37958
|
];
|
|
37959
|
-
|
|
37960
|
-
recordSensitiveFile(filename, relativePath,
|
|
37959
|
+
findings2.push(...fileFindings);
|
|
37960
|
+
recordSensitiveFile(filename, relativePath, findings2, fileFindings);
|
|
37961
37961
|
};
|
|
37962
37962
|
const walk = (currentPath) => {
|
|
37963
37963
|
let entries;
|
|
@@ -37994,8 +37994,8 @@ function scanPath(targetPath, options = {}) {
|
|
|
37994
37994
|
} else {
|
|
37995
37995
|
scanFile(targetPath, (0, import_node_path12.basename)(targetPath));
|
|
37996
37996
|
}
|
|
37997
|
-
if (options.missingControls)
|
|
37998
|
-
const filtered = allowed ?
|
|
37997
|
+
if (options.missingControls) findings2.push(...controls.findings());
|
|
37998
|
+
const filtered = allowed ? findings2.filter((f) => allowed.has(f.category)) : findings2;
|
|
37999
37999
|
filtered.sort(
|
|
38000
38000
|
(a, b) => severityRank(b.severity) - severityRank(a.severity) || a.file.localeCompare(b.file) || a.line - b.line
|
|
38001
38001
|
);
|
|
@@ -38033,7 +38033,7 @@ var import_node_fs15 = require("fs");
|
|
|
38033
38033
|
var import_node_path13 = require("path");
|
|
38034
38034
|
var MAX_DEPS_PER_LOCKFILE = 50;
|
|
38035
38035
|
async function scanDependencies(targetPath) {
|
|
38036
|
-
const
|
|
38036
|
+
const findings2 = [];
|
|
38037
38037
|
for (const { file, ecosystem, parse: parse3 } of LOCKFILES) {
|
|
38038
38038
|
const lockPath = (0, import_node_path13.join)(targetPath, file);
|
|
38039
38039
|
if (!(0, import_node_fs15.existsSync)(lockPath)) continue;
|
|
@@ -38044,11 +38044,11 @@ async function scanDependencies(targetPath) {
|
|
|
38044
38044
|
continue;
|
|
38045
38045
|
}
|
|
38046
38046
|
if (deps.length === 0) {
|
|
38047
|
-
|
|
38047
|
+
findings2.push(incompleteFinding(file, "No dependencies could be read from this lockfile."));
|
|
38048
38048
|
continue;
|
|
38049
38049
|
}
|
|
38050
38050
|
if (deps.length > MAX_DEPS_PER_LOCKFILE) {
|
|
38051
|
-
|
|
38051
|
+
findings2.push(
|
|
38052
38052
|
incompleteFinding(
|
|
38053
38053
|
file,
|
|
38054
38054
|
`Only the first ${MAX_DEPS_PER_LOCKFILE} of ${deps.length} locked packages were checked against OSV.`
|
|
@@ -38064,7 +38064,7 @@ async function scanDependencies(targetPath) {
|
|
|
38064
38064
|
}
|
|
38065
38065
|
for (const vuln of vulns) {
|
|
38066
38066
|
const cvss = vuln.severity?.find((entry) => entry.type === "CVSS_V3")?.score;
|
|
38067
|
-
|
|
38067
|
+
findings2.push({
|
|
38068
38068
|
ruleId: "dependency-known-vulnerability",
|
|
38069
38069
|
title: "Dependency CVE",
|
|
38070
38070
|
file,
|
|
@@ -38079,7 +38079,7 @@ async function scanDependencies(targetPath) {
|
|
|
38079
38079
|
}
|
|
38080
38080
|
}
|
|
38081
38081
|
}
|
|
38082
|
-
return
|
|
38082
|
+
return findings2;
|
|
38083
38083
|
}
|
|
38084
38084
|
function incompleteFinding(file, message) {
|
|
38085
38085
|
return {
|
|
@@ -38301,9 +38301,9 @@ function toArtifactUri(filePath, base, prefix = "", root = base) {
|
|
|
38301
38301
|
const trimmed = prefix.replace(/^\/+|\/+$/g, "");
|
|
38302
38302
|
return trimmed ? `${trimmed}/${posix}` : posix;
|
|
38303
38303
|
}
|
|
38304
|
-
function buildSarif(
|
|
38304
|
+
function buildSarif(findings2, options) {
|
|
38305
38305
|
const rules = /* @__PURE__ */ new Map();
|
|
38306
|
-
for (const finding of
|
|
38306
|
+
for (const finding of findings2) {
|
|
38307
38307
|
if (rules.has(finding.ruleId)) continue;
|
|
38308
38308
|
const tags = ["security"];
|
|
38309
38309
|
if (finding.cwe) tags.push(`external/cwe/${finding.cwe.toLowerCase()}`);
|
|
@@ -38333,7 +38333,7 @@ ${finding.consequence}` : `**${finding.title}**`
|
|
|
38333
38333
|
}
|
|
38334
38334
|
const base = options.base ?? process.cwd();
|
|
38335
38335
|
const root = options.root ?? base;
|
|
38336
|
-
const results =
|
|
38336
|
+
const results = findings2.map((finding) => ({
|
|
38337
38337
|
ruleId: finding.ruleId,
|
|
38338
38338
|
level: sarifLevel(finding.severity),
|
|
38339
38339
|
message: { text: finding.message },
|
|
@@ -38408,8 +38408,8 @@ function parseFailOn(raw) {
|
|
|
38408
38408
|
}
|
|
38409
38409
|
return requested;
|
|
38410
38410
|
}
|
|
38411
|
-
function toRunResult(targetPath,
|
|
38412
|
-
const structured =
|
|
38411
|
+
function toRunResult(targetPath, findings2, filesScanned) {
|
|
38412
|
+
const structured = findings2.map((finding) => ({
|
|
38413
38413
|
type: finding.title,
|
|
38414
38414
|
severity: finding.severity,
|
|
38415
38415
|
message: finding.message,
|
|
@@ -38429,7 +38429,7 @@ function toRunResult(targetPath, findings, filesScanned) {
|
|
|
38429
38429
|
target: targetPath,
|
|
38430
38430
|
findings: structured,
|
|
38431
38431
|
severity_summary: counts,
|
|
38432
|
-
summary:
|
|
38432
|
+
summary: findings2.length === 0 ? `No issues found across ${filesScanned} files` : `${findings2.length} issue(s): ${counts.critical}C ${counts.high}H ${counts.medium}M ${counts.low}L`
|
|
38433
38433
|
};
|
|
38434
38434
|
}
|
|
38435
38435
|
function failedResult(targetPath, message) {
|
|
@@ -38445,8 +38445,8 @@ function failedResult(targetPath, message) {
|
|
|
38445
38445
|
async function runScan(targetPath) {
|
|
38446
38446
|
try {
|
|
38447
38447
|
const report = scanPath(targetPath);
|
|
38448
|
-
const
|
|
38449
|
-
return toRunResult(targetPath,
|
|
38448
|
+
const findings2 = [...report.findings, ...await scanDependencies(targetPath)];
|
|
38449
|
+
return toRunResult(targetPath, findings2, report.filesScanned);
|
|
38450
38450
|
} catch (err) {
|
|
38451
38451
|
return failedResult(targetPath, err.message);
|
|
38452
38452
|
}
|
|
@@ -38579,8 +38579,8 @@ function emitMachineReadable(format2, outcome, targetPath, options, say) {
|
|
|
38579
38579
|
process.stdout.write(serialized);
|
|
38580
38580
|
}
|
|
38581
38581
|
function printHuman(outcome) {
|
|
38582
|
-
const { findings, filesScanned } = outcome;
|
|
38583
|
-
if (
|
|
38582
|
+
const { findings: findings2, filesScanned } = outcome;
|
|
38583
|
+
if (findings2.length === 0) {
|
|
38584
38584
|
console.log(source_default.green.bold(" \u2713 No security issues found!"));
|
|
38585
38585
|
console.log();
|
|
38586
38586
|
return;
|
|
@@ -38593,7 +38593,7 @@ function printHuman(outcome) {
|
|
|
38593
38593
|
);
|
|
38594
38594
|
console.log(source_default.gray(" " + "\u2500".repeat(70)));
|
|
38595
38595
|
console.log();
|
|
38596
|
-
for (const finding of
|
|
38596
|
+
for (const finding of findings2) {
|
|
38597
38597
|
const label = finding.severity.toUpperCase();
|
|
38598
38598
|
const badge = finding.severity === "critical" ? source_default.bgRed.white.bold(` ${label} `) : finding.severity === "high" ? source_default.red(`[${label}]`) : finding.severity === "medium" ? source_default.yellow(`[${label}]`) : source_default.gray(`[${label}]`);
|
|
38599
38599
|
console.log(` ${badge} ${source_default.white.bold(finding.title)}`);
|
|
@@ -38614,7 +38614,7 @@ function printHuman(outcome) {
|
|
|
38614
38614
|
}
|
|
38615
38615
|
console.log(source_default.gray(" " + "\u2500".repeat(70)));
|
|
38616
38616
|
console.log(
|
|
38617
|
-
` ${source_default.white.bold(`${
|
|
38617
|
+
` ${source_default.white.bold(`${findings2.length} issue(s) found`)} across ${filesScanned} files`
|
|
38618
38618
|
);
|
|
38619
38619
|
console.log();
|
|
38620
38620
|
}
|
|
@@ -38664,8 +38664,8 @@ function askPiped(question, mask) {
|
|
|
38664
38664
|
if (reader.lines.length > 0) return Promise.resolve(settle2(reader.lines.shift()));
|
|
38665
38665
|
if (reader.ended) return Promise.resolve(settle2(null));
|
|
38666
38666
|
reader.rl.resume();
|
|
38667
|
-
return new Promise((
|
|
38668
|
-
reader.waiting = (line2) =>
|
|
38667
|
+
return new Promise((resolve7) => {
|
|
38668
|
+
reader.waiting = (line2) => resolve7(settle2(line2));
|
|
38669
38669
|
});
|
|
38670
38670
|
}
|
|
38671
38671
|
function askTerminal(question, mask) {
|
|
@@ -38673,20 +38673,20 @@ function askTerminal(question, mask) {
|
|
|
38673
38673
|
cb();
|
|
38674
38674
|
} }) : process.stdout;
|
|
38675
38675
|
const rl = import_node_readline.default.createInterface({ input: process.stdin, output, terminal: true });
|
|
38676
|
-
return new Promise((
|
|
38676
|
+
return new Promise((resolve7) => {
|
|
38677
38677
|
let settled = false;
|
|
38678
38678
|
rl.on("close", () => {
|
|
38679
38679
|
if (settled) return;
|
|
38680
38680
|
settled = true;
|
|
38681
38681
|
process.stdout.write("\n");
|
|
38682
|
-
|
|
38682
|
+
resolve7(null);
|
|
38683
38683
|
});
|
|
38684
38684
|
if (mask) process.stdout.write(question);
|
|
38685
38685
|
rl.question(mask ? "" : question, (answer) => {
|
|
38686
38686
|
settled = true;
|
|
38687
38687
|
rl.close();
|
|
38688
38688
|
if (mask) process.stdout.write("\n");
|
|
38689
|
-
|
|
38689
|
+
resolve7(answer);
|
|
38690
38690
|
});
|
|
38691
38691
|
});
|
|
38692
38692
|
}
|
|
@@ -38724,7 +38724,7 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os8.hostname)()
|
|
|
38724
38724
|
}
|
|
38725
38725
|
return data;
|
|
38726
38726
|
}
|
|
38727
|
-
var sleep = (ms) => new Promise((
|
|
38727
|
+
var sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
38728
38728
|
async function waitForApproval(request, pkce, opts = {}) {
|
|
38729
38729
|
const wait = opts.sleepMs ?? sleep;
|
|
38730
38730
|
const now = opts.now ?? Date.now;
|
|
@@ -40414,7 +40414,7 @@ async function runAiScan(target, send, opts = {}) {
|
|
|
40414
40414
|
opts.onProbe?.(probe, vulnerable);
|
|
40415
40415
|
if (opts.delayMs && opts.delayMs > 0) await sleep2(opts.delayMs);
|
|
40416
40416
|
}
|
|
40417
|
-
const
|
|
40417
|
+
const findings2 = results.filter((r) => r.vulnerable).map((r) => ({
|
|
40418
40418
|
type: r.probe.id,
|
|
40419
40419
|
severity: r.probe.severity,
|
|
40420
40420
|
message: `${r.probe.owasp} ${r.probe.title}`,
|
|
@@ -40427,11 +40427,11 @@ async function runAiScan(target, send, opts = {}) {
|
|
|
40427
40427
|
evidence: r.response.slice(0, 200)
|
|
40428
40428
|
}
|
|
40429
40429
|
}));
|
|
40430
|
-
const counts = summarize(
|
|
40430
|
+
const counts = summarize(findings2);
|
|
40431
40431
|
const tested = results.length;
|
|
40432
40432
|
const errored = results.filter((r) => r.error).length;
|
|
40433
|
-
const summary =
|
|
40434
|
-
return { type: "scan", target, findings, severity_summary: counts, summary };
|
|
40433
|
+
const summary = findings2.length === 0 ? `No guardrail failures across ${tested} probe(s)${errored ? ` (${errored} errored)` : ""}` : `${findings2.length}/${tested} probe(s) breached a guardrail: ${counts.critical}C ${counts.high}H ${counts.medium}M ${counts.low}L`;
|
|
40434
|
+
return { type: "scan", target, findings: findings2, severity_summary: counts, summary };
|
|
40435
40435
|
}
|
|
40436
40436
|
function httpSender(cfg) {
|
|
40437
40437
|
const template = cfg.template ?? '{"input":"{{PROMPT}}"}';
|
|
@@ -40664,7 +40664,7 @@ async function aiScanMoshCommand(file, args) {
|
|
|
40664
40664
|
} catch (err) {
|
|
40665
40665
|
logger.error(`Cannot read ${file}: ${err.message}`);
|
|
40666
40666
|
process.exitCode = 1;
|
|
40667
|
-
return;
|
|
40667
|
+
return [];
|
|
40668
40668
|
}
|
|
40669
40669
|
const t0 = Date.now();
|
|
40670
40670
|
const res = await runMosh(source, { argv: args, out: (s) => console.log(" " + s) });
|
|
@@ -40679,12 +40679,13 @@ async function aiScanMoshCommand(file, args) {
|
|
|
40679
40679
|
console.log();
|
|
40680
40680
|
console.log(` ${source_default.red("\u2717 script failed:")} ${res.failed}`);
|
|
40681
40681
|
process.exitCode = 1;
|
|
40682
|
-
return;
|
|
40682
|
+
return [];
|
|
40683
40683
|
}
|
|
40684
40684
|
const breached = res.scans.reduce((n, s) => n + s.findings.length, 0);
|
|
40685
40685
|
console.log();
|
|
40686
40686
|
console.log(` ${breached === 0 ? source_default.green("\u2713") : source_default.red("\u2716")} ${res.scans.length} scan(s), ${breached} guardrail failure(s)`);
|
|
40687
40687
|
console.log();
|
|
40688
|
+
return res.scans;
|
|
40688
40689
|
}
|
|
40689
40690
|
|
|
40690
40691
|
// src/commands/orgs.ts
|
|
@@ -40987,9 +40988,9 @@ async function fetchOrgs() {
|
|
|
40987
40988
|
}
|
|
40988
40989
|
function askChoice(question) {
|
|
40989
40990
|
const rl = import_node_readline2.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
40990
|
-
return new Promise((
|
|
40991
|
+
return new Promise((resolve7) => rl.question(question, (answer) => {
|
|
40991
40992
|
rl.close();
|
|
40992
|
-
|
|
40993
|
+
resolve7(answer.trim());
|
|
40993
40994
|
}));
|
|
40994
40995
|
}
|
|
40995
40996
|
async function chooseOrg(orgs, flag, ask2) {
|
|
@@ -41261,20 +41262,20 @@ async function resolveServer(nameOrSlug, orgSlug) {
|
|
|
41261
41262
|
}
|
|
41262
41263
|
}
|
|
41263
41264
|
async function sshConnect(options) {
|
|
41264
|
-
const { hostname:
|
|
41265
|
-
if (!
|
|
41265
|
+
const { hostname: hostname5, port, username, identity } = options;
|
|
41266
|
+
if (!hostname5) {
|
|
41266
41267
|
console.log(source_default.red(" No hostname available for this server.\n"));
|
|
41267
41268
|
return;
|
|
41268
41269
|
}
|
|
41269
41270
|
const user = username || "root";
|
|
41270
|
-
console.log(source_default.green(` Connecting to ${user}@${
|
|
41271
|
+
console.log(source_default.green(` Connecting to ${user}@${hostname5}:${port}...
|
|
41271
41272
|
`));
|
|
41272
41273
|
console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
|
|
41273
41274
|
const sshArgs = ["-p", String(port)];
|
|
41274
41275
|
if (identity) {
|
|
41275
41276
|
sshArgs.push("-i", identity);
|
|
41276
41277
|
}
|
|
41277
|
-
sshArgs.push(`${user}@${
|
|
41278
|
+
sshArgs.push(`${user}@${hostname5}`);
|
|
41278
41279
|
const ssh = (0, import_node_child_process5.spawn)("ssh", sshArgs, { stdio: "inherit" });
|
|
41279
41280
|
ssh.on("error", (err) => {
|
|
41280
41281
|
console.log(source_default.red(`
|
|
@@ -41368,7 +41369,7 @@ var IpcServer = class {
|
|
|
41368
41369
|
} catch {
|
|
41369
41370
|
}
|
|
41370
41371
|
}
|
|
41371
|
-
return new Promise((
|
|
41372
|
+
return new Promise((resolve7, reject) => {
|
|
41372
41373
|
this.server = (0, import_node_net3.createServer)((sock) => this.handleClient(sock));
|
|
41373
41374
|
this.server.on("error", reject);
|
|
41374
41375
|
this.server.listen(PATHS.socket, () => {
|
|
@@ -41387,7 +41388,7 @@ var IpcServer = class {
|
|
|
41387
41388
|
}
|
|
41388
41389
|
}
|
|
41389
41390
|
}
|
|
41390
|
-
|
|
41391
|
+
resolve7();
|
|
41391
41392
|
});
|
|
41392
41393
|
});
|
|
41393
41394
|
}
|
|
@@ -41399,20 +41400,20 @@ var IpcServer = class {
|
|
|
41399
41400
|
}
|
|
41400
41401
|
}
|
|
41401
41402
|
this.clients.clear();
|
|
41402
|
-
return new Promise((
|
|
41403
|
+
return new Promise((resolve7) => {
|
|
41403
41404
|
if (!this.server) {
|
|
41404
41405
|
try {
|
|
41405
41406
|
if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
|
|
41406
41407
|
} catch {
|
|
41407
41408
|
}
|
|
41408
|
-
return
|
|
41409
|
+
return resolve7();
|
|
41409
41410
|
}
|
|
41410
41411
|
this.server.close(() => {
|
|
41411
41412
|
try {
|
|
41412
41413
|
if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
|
|
41413
41414
|
} catch {
|
|
41414
41415
|
}
|
|
41415
|
-
|
|
41416
|
+
resolve7();
|
|
41416
41417
|
});
|
|
41417
41418
|
});
|
|
41418
41419
|
}
|
|
@@ -44725,7 +44726,7 @@ function updateSettings(section, env3 = process.env) {
|
|
|
44725
44726
|
};
|
|
44726
44727
|
}
|
|
44727
44728
|
function defaultRun(argv, env3) {
|
|
44728
|
-
return new Promise((
|
|
44729
|
+
return new Promise((resolve7) => {
|
|
44729
44730
|
const child = (0, import_node_child_process10.spawn)(argv[0], argv.slice(1), {
|
|
44730
44731
|
env: { ...process.env, ...env3 },
|
|
44731
44732
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -44736,8 +44737,8 @@ function defaultRun(argv, env3) {
|
|
|
44736
44737
|
};
|
|
44737
44738
|
child.stdout?.on("data", keep);
|
|
44738
44739
|
child.stderr?.on("data", keep);
|
|
44739
|
-
child.on("error", (err) =>
|
|
44740
|
-
child.on("close", (code) =>
|
|
44740
|
+
child.on("error", (err) => resolve7({ code: -1, output: err.message }));
|
|
44741
|
+
child.on("close", (code) => resolve7({ code: code ?? -1, output }));
|
|
44741
44742
|
});
|
|
44742
44743
|
}
|
|
44743
44744
|
var AutoUpdate = class {
|
|
@@ -46586,12 +46587,12 @@ var defaultDiscovery = {
|
|
|
46586
46587
|
}
|
|
46587
46588
|
return out;
|
|
46588
46589
|
},
|
|
46589
|
-
keyLoginJournal: (sinceSeconds) => new Promise((
|
|
46590
|
+
keyLoginJournal: (sinceSeconds) => new Promise((resolve7) => {
|
|
46590
46591
|
(0, import_node_child_process14.execFile)(
|
|
46591
46592
|
"journalctl",
|
|
46592
46593
|
["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
|
|
46593
46594
|
{ maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
|
|
46594
|
-
(_err, stdout) =>
|
|
46595
|
+
(_err, stdout) => resolve7(stdout ?? "")
|
|
46595
46596
|
);
|
|
46596
46597
|
})
|
|
46597
46598
|
};
|
|
@@ -47202,12 +47203,12 @@ async function runHardeningChecks() {
|
|
|
47202
47203
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
47203
47204
|
);
|
|
47204
47205
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
47205
|
-
const
|
|
47206
|
+
const findings2 = Array.isArray(parsed.findings) ? parsed.findings : [];
|
|
47206
47207
|
const patches = await runPatchCheck().catch((err) => {
|
|
47207
47208
|
logLine(`[cloud] patch check failed: ${err.message.split("\n")[0]}`);
|
|
47208
47209
|
return null;
|
|
47209
47210
|
});
|
|
47210
|
-
return patches ? [...
|
|
47211
|
+
return patches ? [...findings2, patches] : findings2;
|
|
47211
47212
|
}
|
|
47212
47213
|
async function runPatchCheck() {
|
|
47213
47214
|
const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
|
|
@@ -48049,9 +48050,9 @@ var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
|
48049
48050
|
var KINDS = ["url", "api", "domain", "ip", "repo"];
|
|
48050
48051
|
function prompt(question) {
|
|
48051
48052
|
const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
48052
|
-
return new Promise((
|
|
48053
|
+
return new Promise((resolve7) => rl.question(question, (answer) => {
|
|
48053
48054
|
rl.close();
|
|
48054
|
-
|
|
48055
|
+
resolve7(answer.trim());
|
|
48055
48056
|
}));
|
|
48056
48057
|
}
|
|
48057
48058
|
async function requireAuth() {
|
|
@@ -50172,7 +50173,7 @@ init_ipc_client();
|
|
|
50172
50173
|
// src/core/user-agent.ts
|
|
50173
50174
|
init_cli_config();
|
|
50174
50175
|
var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
|
|
50175
|
-
function isOurHost(url,
|
|
50176
|
+
function isOurHost(url, api3 = apiUrl()) {
|
|
50176
50177
|
let host;
|
|
50177
50178
|
try {
|
|
50178
50179
|
host = new URL(url).hostname.toLowerCase();
|
|
@@ -50181,7 +50182,7 @@ function isOurHost(url, api2 = apiUrl()) {
|
|
|
50181
50182
|
}
|
|
50182
50183
|
let apiHost = "";
|
|
50183
50184
|
try {
|
|
50184
|
-
apiHost = new URL(
|
|
50185
|
+
apiHost = new URL(api3).hostname.toLowerCase();
|
|
50185
50186
|
} catch {
|
|
50186
50187
|
}
|
|
50187
50188
|
return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
|
|
@@ -50205,6 +50206,248 @@ function installUserAgent(target = globalThis) {
|
|
|
50205
50206
|
target.fetch = wrapped;
|
|
50206
50207
|
}
|
|
50207
50208
|
|
|
50209
|
+
// src/core/cloud-upload.ts
|
|
50210
|
+
var import_node_child_process23 = require("child_process");
|
|
50211
|
+
var import_node_os16 = require("os");
|
|
50212
|
+
var import_node_path41 = require("path");
|
|
50213
|
+
init_cli_config();
|
|
50214
|
+
function uploadDisabled(upload, env3 = process.env) {
|
|
50215
|
+
if (upload === false) return true;
|
|
50216
|
+
const v = (env3.THREATCRUSH_UPLOAD ?? "").trim().toLowerCase();
|
|
50217
|
+
return ["0", "off", "false", "no"].includes(v);
|
|
50218
|
+
}
|
|
50219
|
+
function cleanUrl(raw) {
|
|
50220
|
+
try {
|
|
50221
|
+
const u = new URL(raw);
|
|
50222
|
+
u.username = "";
|
|
50223
|
+
u.password = "";
|
|
50224
|
+
u.search = "";
|
|
50225
|
+
u.hash = "";
|
|
50226
|
+
return u.toString();
|
|
50227
|
+
} catch {
|
|
50228
|
+
return raw.split(/[?#]/)[0];
|
|
50229
|
+
}
|
|
50230
|
+
}
|
|
50231
|
+
function repoTarget(path2, run = (args) => (0, import_node_child_process23.execFileSync)("git", args, { cwd: (0, import_node_path41.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
|
|
50232
|
+
const abs = (0, import_node_path41.resolve)(path2);
|
|
50233
|
+
try {
|
|
50234
|
+
const root = run(["rev-parse", "--show-toplevel"]);
|
|
50235
|
+
const sub = abs === root ? "." : abs.slice(root.length + 1);
|
|
50236
|
+
let remote = "";
|
|
50237
|
+
try {
|
|
50238
|
+
remote = run(["remote", "get-url", "origin"]);
|
|
50239
|
+
} catch {
|
|
50240
|
+
}
|
|
50241
|
+
if (remote) {
|
|
50242
|
+
const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
|
|
50243
|
+
if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
|
|
50244
|
+
}
|
|
50245
|
+
return { target: `${(0, import_node_os16.hostname)()}:${root}`, root, sub };
|
|
50246
|
+
} catch {
|
|
50247
|
+
return { target: `${(0, import_node_os16.hostname)()}:${abs}`, root: abs, sub: "." };
|
|
50248
|
+
}
|
|
50249
|
+
}
|
|
50250
|
+
async function uploadResult(result, opts) {
|
|
50251
|
+
const say = (line2) => (opts.machineReadable ? process.stderr : process.stdout).write(`${line2}
|
|
50252
|
+
`);
|
|
50253
|
+
if (uploadDisabled(opts.upload, opts.env)) return { uploaded: false, reason: "disabled" };
|
|
50254
|
+
if (!hasSession()) {
|
|
50255
|
+
if (!opts.machineReadable && process.stdout.isTTY) {
|
|
50256
|
+
say(source_default.dim(` Sign in with ${source_default.white("threatcrush login")} to track these findings in the cloud and triage them anywhere.
|
|
50257
|
+
`));
|
|
50258
|
+
}
|
|
50259
|
+
return { uploaded: false, reason: "signed-out" };
|
|
50260
|
+
}
|
|
50261
|
+
const cfg = readCliConfig();
|
|
50262
|
+
if (!cfg.current_org_id) {
|
|
50263
|
+
say(source_default.yellow(` Not saved to the cloud: no current org. Pick one with ${source_default.white("threatcrush orgs use <slug>")}.
|
|
50264
|
+
`));
|
|
50265
|
+
return { uploaded: false, reason: "no-org" };
|
|
50266
|
+
}
|
|
50267
|
+
try {
|
|
50268
|
+
const res = await cloudFetch(`/api/orgs/${cfg.current_org_id}/scan-findings/report`, {
|
|
50269
|
+
method: "POST",
|
|
50270
|
+
timeoutMs: 3e4,
|
|
50271
|
+
body: JSON.stringify({
|
|
50272
|
+
source: opts.source,
|
|
50273
|
+
target: opts.target,
|
|
50274
|
+
kind: opts.kind,
|
|
50275
|
+
scope: opts.scope ?? "",
|
|
50276
|
+
worker_id: workerId(),
|
|
50277
|
+
result: {
|
|
50278
|
+
findings: result.findings,
|
|
50279
|
+
severity_summary: result.severity_summary,
|
|
50280
|
+
summary: result.summary,
|
|
50281
|
+
error: result.error
|
|
50282
|
+
}
|
|
50283
|
+
})
|
|
50284
|
+
});
|
|
50285
|
+
const data = await res.json().catch(() => ({}));
|
|
50286
|
+
if (!res.ok || !data.sync) {
|
|
50287
|
+
say(source_default.yellow(` Not saved to the cloud: ${data.error || `HTTP ${res.status}`}.
|
|
50288
|
+
`));
|
|
50289
|
+
return { uploaded: false, reason: "error" };
|
|
50290
|
+
}
|
|
50291
|
+
const s = data.sync;
|
|
50292
|
+
const org = cfg.current_org_slug || "your org";
|
|
50293
|
+
const parts = [`${s.new} new`, `${s.seen + s.reopened} still open${s.reopened ? ` (${s.reopened} back after a fix)` : ""}`, `${s.fixed} fixed`];
|
|
50294
|
+
say(source_default.cyan(` \u2601 Saved to ${org}: ${parts.join(" \xB7 ")}. Triage with ${source_default.white("threatcrush findings")} or on threatcrush.com/org/${org}/findings
|
|
50295
|
+
`));
|
|
50296
|
+
return { uploaded: true, sync: s, propertyName: data.property_name };
|
|
50297
|
+
} catch (err) {
|
|
50298
|
+
say(source_default.yellow(` Not saved to the cloud: ${err.message}.
|
|
50299
|
+
`));
|
|
50300
|
+
return { uploaded: false, reason: "error" };
|
|
50301
|
+
}
|
|
50302
|
+
}
|
|
50303
|
+
|
|
50304
|
+
// src/commands/findings.ts
|
|
50305
|
+
init_cli_config();
|
|
50306
|
+
var TRIAGE = {
|
|
50307
|
+
ack: "acknowledged",
|
|
50308
|
+
fix: "fixed",
|
|
50309
|
+
fp: "false_positive",
|
|
50310
|
+
ignore: "ignored",
|
|
50311
|
+
reopen: "open"
|
|
50312
|
+
};
|
|
50313
|
+
var SEV_COLOR = {
|
|
50314
|
+
critical: source_default.bgRed.white,
|
|
50315
|
+
high: source_default.red,
|
|
50316
|
+
medium: source_default.yellow,
|
|
50317
|
+
low: source_default.blue,
|
|
50318
|
+
info: source_default.gray
|
|
50319
|
+
};
|
|
50320
|
+
var STATUS_LABEL = {
|
|
50321
|
+
open: "open",
|
|
50322
|
+
acknowledged: "ack",
|
|
50323
|
+
fixed: "fixed",
|
|
50324
|
+
false_positive: "false+",
|
|
50325
|
+
ignored: "ignored"
|
|
50326
|
+
};
|
|
50327
|
+
function orgOrExplain() {
|
|
50328
|
+
if (!hasSession()) {
|
|
50329
|
+
console.log(source_default.red(` Not signed in. Run ${source_default.white("threatcrush login")} first.
|
|
50330
|
+
`));
|
|
50331
|
+
process.exitCode = 1;
|
|
50332
|
+
return null;
|
|
50333
|
+
}
|
|
50334
|
+
const org = readCliConfig().current_org_id;
|
|
50335
|
+
if (!org) {
|
|
50336
|
+
console.log(source_default.red(` No current org. Run ${source_default.white("threatcrush orgs use <slug>")}.
|
|
50337
|
+
`));
|
|
50338
|
+
process.exitCode = 1;
|
|
50339
|
+
return null;
|
|
50340
|
+
}
|
|
50341
|
+
return org;
|
|
50342
|
+
}
|
|
50343
|
+
async function api2(path2, init) {
|
|
50344
|
+
const res = await cloudFetch(path2, init);
|
|
50345
|
+
const data = await res.json().catch(() => ({}));
|
|
50346
|
+
if (!res.ok) {
|
|
50347
|
+
console.log(source_default.red(` ${data.error || `HTTP ${res.status}`}${res.status === 401 ? ` \u2014 run ${source_default.white("threatcrush login")}` : ""}
|
|
50348
|
+
`));
|
|
50349
|
+
process.exitCode = 1;
|
|
50350
|
+
return null;
|
|
50351
|
+
}
|
|
50352
|
+
return data;
|
|
50353
|
+
}
|
|
50354
|
+
var short = (id) => id.slice(0, 8);
|
|
50355
|
+
var day = (iso) => iso.slice(0, 10);
|
|
50356
|
+
async function findingsListCommand(opts) {
|
|
50357
|
+
const org = orgOrExplain();
|
|
50358
|
+
if (!org) return;
|
|
50359
|
+
const qs = new URLSearchParams();
|
|
50360
|
+
if (opts.status) qs.set("status", opts.status);
|
|
50361
|
+
if (opts.severity) qs.set("severity", opts.severity);
|
|
50362
|
+
if (opts.source) qs.set("source", opts.source);
|
|
50363
|
+
qs.set("limit", String(Math.min(500, Number(opts.limit) || 100)));
|
|
50364
|
+
const data = await api2(`/api/orgs/${org}/scan-findings?${qs}`);
|
|
50365
|
+
if (!data) return;
|
|
50366
|
+
if (opts.json) {
|
|
50367
|
+
console.log(JSON.stringify(data, null, 2));
|
|
50368
|
+
return;
|
|
50369
|
+
}
|
|
50370
|
+
const slug = readCliConfig().current_org_slug || org;
|
|
50371
|
+
const c = data.counts;
|
|
50372
|
+
console.log(source_default.bold(`
|
|
50373
|
+
Findings in ${slug}`) + source_default.dim(` open ${c.open ?? 0} \xB7 ack ${c.acknowledged ?? 0} \xB7 fixed ${c.fixed ?? 0} \xB7 false+ ${c.false_positive ?? 0} \xB7 ignored ${c.ignored ?? 0}
|
|
50374
|
+
`));
|
|
50375
|
+
if (!data.findings.length) {
|
|
50376
|
+
console.log(source_default.green(" Nothing matches. ") + source_default.dim(opts.status ? "" : "Showing open + acknowledged; use --status all for everything.") + "\n");
|
|
50377
|
+
return;
|
|
50378
|
+
}
|
|
50379
|
+
for (const f of data.findings) {
|
|
50380
|
+
const sev = (SEV_COLOR[f.severity] ?? source_default.white)(f.severity.toUpperCase().padEnd(8));
|
|
50381
|
+
console.log(` ${source_default.gray(short(f.id))} ${sev} ${source_default.dim((STATUS_LABEL[f.status] ?? f.status).padEnd(7))} ${f.message}`);
|
|
50382
|
+
console.log(source_default.dim(` ${f.source} \xB7 ${f.properties?.name ?? "?"}${f.location ? ` \xB7 ${f.location}` : ""} \xB7 seen ${f.times_seen}x, last ${day(f.last_seen_at)}`));
|
|
50383
|
+
}
|
|
50384
|
+
if (data.total > data.findings.length) console.log(source_default.dim(`
|
|
50385
|
+
${data.findings.length} of ${data.total} shown; --limit for more.`));
|
|
50386
|
+
console.log(source_default.dim(`
|
|
50387
|
+
Triage: threatcrush findings ack|fix|fp|ignore|reopen <id...> [--note "why"] \xB7 details: threatcrush findings show <id>
|
|
50388
|
+
`));
|
|
50389
|
+
}
|
|
50390
|
+
async function resolveIds(org, prefixes) {
|
|
50391
|
+
const full = prefixes.filter((p) => /^[0-9a-f-]{36}$/i.test(p));
|
|
50392
|
+
const partial = prefixes.filter((p) => !full.includes(p));
|
|
50393
|
+
if (!partial.length) return full;
|
|
50394
|
+
const data = await api2(`/api/orgs/${org}/scan-findings?status=all&limit=500`);
|
|
50395
|
+
if (!data) return null;
|
|
50396
|
+
for (const p of partial) {
|
|
50397
|
+
const hits = data.findings.filter((f) => f.id.startsWith(p.toLowerCase()));
|
|
50398
|
+
if (hits.length !== 1) {
|
|
50399
|
+
console.log(source_default.red(` ${p}: ${hits.length ? "matches more than one finding, use more characters" : "no such finding"}
|
|
50400
|
+
`));
|
|
50401
|
+
process.exitCode = 1;
|
|
50402
|
+
return null;
|
|
50403
|
+
}
|
|
50404
|
+
full.push(hits[0].id);
|
|
50405
|
+
}
|
|
50406
|
+
return full;
|
|
50407
|
+
}
|
|
50408
|
+
async function findingsShowCommand(id, opts) {
|
|
50409
|
+
const org = orgOrExplain();
|
|
50410
|
+
if (!org) return;
|
|
50411
|
+
const [full] = await resolveIds(org, [id]) ?? [];
|
|
50412
|
+
if (!full) return;
|
|
50413
|
+
const data = await api2(`/api/orgs/${org}/scan-findings/${full}`);
|
|
50414
|
+
if (!data) return;
|
|
50415
|
+
if (opts.json) {
|
|
50416
|
+
console.log(JSON.stringify(data.finding, null, 2));
|
|
50417
|
+
return;
|
|
50418
|
+
}
|
|
50419
|
+
const f = data.finding;
|
|
50420
|
+
const d = f.details ?? {};
|
|
50421
|
+
console.log(`
|
|
50422
|
+
${(SEV_COLOR[f.severity] ?? source_default.white)(f.severity.toUpperCase())} ${source_default.bold(f.message)}`);
|
|
50423
|
+
console.log(source_default.dim(` ${f.id} \xB7 ${f.status} \xB7 ${f.source} \xB7 ${f.type}`));
|
|
50424
|
+
console.log(` ${source_default.gray("Property:")} ${f.properties?.name ?? "?"} ${source_default.dim(f.properties?.target ?? "")}`);
|
|
50425
|
+
if (f.location) console.log(` ${source_default.gray("Where:")} ${f.location}`);
|
|
50426
|
+
if (typeof d.snippet === "string") console.log(` ${source_default.gray("Code:")} ${d.snippet}`);
|
|
50427
|
+
if (typeof d.remediation === "string") console.log(` ${source_default.gray("Fix:")} ${d.remediation}`);
|
|
50428
|
+
console.log(` ${source_default.gray("Seen:")} ${f.times_seen}x, first ${day(f.first_seen_at)}, last ${day(f.last_seen_at)}`);
|
|
50429
|
+
if (f.note) console.log(` ${source_default.gray("Note:")} ${f.note}`);
|
|
50430
|
+
console.log();
|
|
50431
|
+
}
|
|
50432
|
+
async function findingsTriageCommand(verb, ids, opts) {
|
|
50433
|
+
const org = orgOrExplain();
|
|
50434
|
+
if (!org) return;
|
|
50435
|
+
if (!ids.length) {
|
|
50436
|
+
console.log(source_default.red(` Give at least one finding id (see threatcrush findings).
|
|
50437
|
+
`));
|
|
50438
|
+
process.exitCode = 1;
|
|
50439
|
+
return;
|
|
50440
|
+
}
|
|
50441
|
+
const full = await resolveIds(org, ids);
|
|
50442
|
+
if (!full) return;
|
|
50443
|
+
const body = { ids: full, status: TRIAGE[verb] };
|
|
50444
|
+
if (opts.note !== void 0) body.note = opts.note;
|
|
50445
|
+
const data = await api2(`/api/orgs/${org}/scan-findings`, { method: "PATCH", body: JSON.stringify(body) });
|
|
50446
|
+
if (!data) return;
|
|
50447
|
+
console.log(source_default.green(` \u2713 ${data.updated.length} finding(s) \u2192 ${TRIAGE[verb].replace("_", " ")}
|
|
50448
|
+
`));
|
|
50449
|
+
}
|
|
50450
|
+
|
|
50208
50451
|
// src/index.ts
|
|
50209
50452
|
installUserAgent();
|
|
50210
50453
|
var LOGO2 = `
|
|
@@ -50219,25 +50462,25 @@ ${source_default.dim(" C R U S H")}
|
|
|
50219
50462
|
var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
50220
50463
|
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
50221
50464
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
50222
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
50465
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
|
|
50223
50466
|
function detectPackageManager() {
|
|
50224
50467
|
try {
|
|
50225
|
-
const npmGlobal = (0,
|
|
50468
|
+
const npmGlobal = (0, import_node_child_process24.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
50226
50469
|
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
50227
50470
|
} catch {
|
|
50228
50471
|
}
|
|
50229
50472
|
try {
|
|
50230
|
-
(0,
|
|
50473
|
+
(0, import_node_child_process24.execSync)("pnpm --version", { stdio: "pipe" });
|
|
50231
50474
|
return "pnpm";
|
|
50232
50475
|
} catch {
|
|
50233
50476
|
}
|
|
50234
50477
|
try {
|
|
50235
|
-
(0,
|
|
50478
|
+
(0, import_node_child_process24.execSync)("yarn --version", { stdio: "pipe" });
|
|
50236
50479
|
return "yarn";
|
|
50237
50480
|
} catch {
|
|
50238
50481
|
}
|
|
50239
50482
|
try {
|
|
50240
|
-
(0,
|
|
50483
|
+
(0, import_node_child_process24.execSync)("bun --version", { stdio: "pipe" });
|
|
50241
50484
|
return "bun";
|
|
50242
50485
|
} catch {
|
|
50243
50486
|
}
|
|
@@ -50252,7 +50495,7 @@ function readInstallConfig() {
|
|
|
50252
50495
|
}
|
|
50253
50496
|
function packageLooksInstalled(pm, pkgName) {
|
|
50254
50497
|
try {
|
|
50255
|
-
const output = (0,
|
|
50498
|
+
const output = (0, import_node_child_process24.execSync)(globalListCommand(pm, pkgName), {
|
|
50256
50499
|
encoding: "utf-8",
|
|
50257
50500
|
stdio: ["pipe", "pipe", "pipe"]
|
|
50258
50501
|
});
|
|
@@ -50355,14 +50598,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
50355
50598
|
function restartSystemdDaemon() {
|
|
50356
50599
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
50357
50600
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
50358
|
-
if (!asRoot && (0,
|
|
50601
|
+
if (!asRoot && (0, import_node_child_process24.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
50359
50602
|
const [cmd, ...args] = argv;
|
|
50360
|
-
if ((0,
|
|
50361
|
-
return (0,
|
|
50603
|
+
if ((0, import_node_child_process24.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
50604
|
+
return (0, import_node_child_process24.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
50362
50605
|
}
|
|
50363
50606
|
function execQuiet(cmd) {
|
|
50364
50607
|
try {
|
|
50365
|
-
return (0,
|
|
50608
|
+
return (0, import_node_child_process24.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
50366
50609
|
} catch {
|
|
50367
50610
|
return null;
|
|
50368
50611
|
}
|
|
@@ -50485,7 +50728,7 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
|
|
|
50485
50728
|
).option(
|
|
50486
50729
|
"--missing-controls",
|
|
50487
50730
|
"also report security controls the tree shows no evidence of (headers, CSRF, rate limiting, body size limits)"
|
|
50488
|
-
).option("-v, --verbose", "list the paths that could not be read").action(async (targetPath, opts) => {
|
|
50731
|
+
).option("-v, --verbose", "list the paths that could not be read").option("--no-upload", "do not save the results to your threatcrush.com org (also THREATCRUSH_UPLOAD=0)").action(async (targetPath, opts) => {
|
|
50489
50732
|
const format2 = (opts.format ?? "text").toLowerCase();
|
|
50490
50733
|
if (!["text", "json", "sarif"].includes(format2)) {
|
|
50491
50734
|
console.error(source_default.red(`Unknown --format "${opts.format}" (expected text, json, or sarif)`));
|
|
@@ -50498,7 +50741,7 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
|
|
|
50498
50741
|
console.error(source_default.red(err.message));
|
|
50499
50742
|
process.exit(2);
|
|
50500
50743
|
}
|
|
50501
|
-
await scanCommand(targetPath, {
|
|
50744
|
+
const result = await scanCommand(targetPath, {
|
|
50502
50745
|
format: format2,
|
|
50503
50746
|
output: opts.output,
|
|
50504
50747
|
failOn,
|
|
@@ -50508,16 +50751,59 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
|
|
|
50508
50751
|
missingControls: opts.missingControls,
|
|
50509
50752
|
verbose: opts.verbose
|
|
50510
50753
|
});
|
|
50754
|
+
if (!result.error) {
|
|
50755
|
+
const repo = repoTarget(targetPath);
|
|
50756
|
+
const scope = [
|
|
50757
|
+
`path=${repo.sub}`,
|
|
50758
|
+
opts.deps ? "deps" : "",
|
|
50759
|
+
opts.missingControls ? "missing-controls" : "",
|
|
50760
|
+
...(opts.exclude ?? []).map((g) => `exclude=${g}`)
|
|
50761
|
+
].filter(Boolean).join(";");
|
|
50762
|
+
await uploadResult(result, { source: "scan", target: repo.target, kind: "repo", scope, upload: opts.upload, machineReadable: format2 !== "text" });
|
|
50763
|
+
}
|
|
50764
|
+
});
|
|
50765
|
+
program2.command("pentest").description("Penetration test URLs and APIs").argument("<url>", "Target URL to pentest").option("--no-upload", "do not save the results to your threatcrush.com org (also THREATCRUSH_UPLOAD=0)").action(async (url, opts) => {
|
|
50766
|
+
const result = await pentestCommand(url);
|
|
50767
|
+
await uploadResult(result, { source: "pentest", target: cleanUrl(url), kind: "url", upload: opts.upload });
|
|
50768
|
+
});
|
|
50769
|
+
program2.command("ai-scan").description("Red-team an AI/LLM endpoint you own for OWASP LLM Top 10 guardrail gaps").argument("<url>", "Target AI endpoint URL").option("--categories <list>", "comma list: prompt-injection,system-prompt-leak,sensitive-disclosure,excessive-agency,output-handling").option("--template <json>", 'request body with {{PROMPT}} marker (default {"input":"{{PROMPT}}"})').option("--header <k:v...>", "extra request header (repeatable)").option("--response-path <path>", 'dotted JSON path to the reply text, or "text"').option("--delay <ms>", "delay between probes").option("--json", "emit JSON").option("--no-upload", "do not save the results to your threatcrush.com org (also THREATCRUSH_UPLOAD=0)").action(async (url, opts) => {
|
|
50770
|
+
const result = await aiScanCommand(url, opts);
|
|
50771
|
+
const categories = String(opts.categories ?? "").split(",").map((c) => c.trim()).filter(Boolean).sort();
|
|
50772
|
+
await uploadResult(result, {
|
|
50773
|
+
source: "ai-scan",
|
|
50774
|
+
target: cleanUrl(url),
|
|
50775
|
+
kind: "api",
|
|
50776
|
+
scope: categories.length ? `categories=${categories.join(",")}` : "",
|
|
50777
|
+
upload: opts.upload,
|
|
50778
|
+
machineReadable: Boolean(opts.json)
|
|
50779
|
+
});
|
|
50780
|
+
});
|
|
50781
|
+
program2.command("ai-scan-run").description("Drive the AI red-team scanner from a .mosh script").argument("<file>", "Path to a .mosh script").argument("[args...]", "Arguments passed to the script as argv").option("--no-upload", "do not save the results to your threatcrush.com org (also THREATCRUSH_UPLOAD=0)").action(async (file, args, opts) => {
|
|
50782
|
+
const scans = await aiScanMoshCommand(file, args ?? []);
|
|
50783
|
+
for (const r of scans) await uploadResult(r, { source: "ai-scan", target: cleanUrl(r.target), kind: "api", scope: `mosh=${file.split("/").pop()}`, upload: opts.upload });
|
|
50511
50784
|
});
|
|
50512
|
-
|
|
50513
|
-
|
|
50785
|
+
var listOpts = (c) => c.option("--status <list>", "open,acknowledged,fixed,false_positive,ignored or all (default: open,acknowledged)").option("--severity <list>", "critical,high,medium,low,info").option("--source <list>", "scan,pentest,ai-scan").option("--limit <n>", "how many to show (max 500)").option("--json", "emit JSON");
|
|
50786
|
+
var findings = listOpts(program2.command("findings").description("List and triage your org's tracked findings (also on the web and desktop apps)")).action(async (opts) => {
|
|
50787
|
+
await findingsListCommand(opts);
|
|
50514
50788
|
});
|
|
50515
|
-
|
|
50516
|
-
await
|
|
50789
|
+
listOpts(findings.command("list").description("List findings (default: open + acknowledged)")).action(async (opts) => {
|
|
50790
|
+
await findingsListCommand(opts);
|
|
50517
50791
|
});
|
|
50518
|
-
|
|
50519
|
-
await
|
|
50792
|
+
findings.command("show <id>").description("Details of one finding (id or the 8-char prefix from the list)").option("--json", "emit JSON").action(async (id, opts) => {
|
|
50793
|
+
await findingsShowCommand(id, opts);
|
|
50520
50794
|
});
|
|
50795
|
+
var VERB_HELP = {
|
|
50796
|
+
ack: "acknowledge: seen it, working on it",
|
|
50797
|
+
fix: "mark fixed (a later run reopens it if it is still there)",
|
|
50798
|
+
fp: "mark a false positive (runs never reopen it)",
|
|
50799
|
+
ignore: "ignore: accepted risk (runs never reopen it)",
|
|
50800
|
+
reopen: "set back to open"
|
|
50801
|
+
};
|
|
50802
|
+
for (const verb of Object.keys(TRIAGE)) {
|
|
50803
|
+
findings.command(`${verb} <ids...>`).description(VERB_HELP[verb]).option("--note <text>", "why (shown everywhere the finding is)").action(async (ids, opts) => {
|
|
50804
|
+
await findingsTriageCommand(verb, ids, opts);
|
|
50805
|
+
});
|
|
50806
|
+
}
|
|
50521
50807
|
program2.command("status").description("Show daemon status and loaded modules").action(async () => {
|
|
50522
50808
|
await statusCommand();
|
|
50523
50809
|
});
|
|
@@ -50593,7 +50879,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
50593
50879
|
console.log(source_default.green(` Tailing ${logPath2}...
|
|
50594
50880
|
`));
|
|
50595
50881
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
50596
|
-
(0,
|
|
50882
|
+
(0, import_node_child_process24.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
|
|
50597
50883
|
});
|
|
50598
50884
|
program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
|
|
50599
50885
|
console.log(LOGO2);
|
|
@@ -50605,7 +50891,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
50605
50891
|
for (const cmd of commands2) {
|
|
50606
50892
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
50607
50893
|
`));
|
|
50608
|
-
(0,
|
|
50894
|
+
(0, import_node_child_process24.execSync)(cmd, { stdio: "inherit" });
|
|
50609
50895
|
}
|
|
50610
50896
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
50611
50897
|
await reportIfStillStale();
|
|
@@ -50630,7 +50916,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
50630
50916
|
for (const cmd of commands) {
|
|
50631
50917
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
50632
50918
|
`));
|
|
50633
|
-
(0,
|
|
50919
|
+
(0, import_node_child_process24.execSync)(cmd, { stdio: "inherit" });
|
|
50634
50920
|
}
|
|
50635
50921
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
50636
50922
|
if (installMode === "desktop") {
|
|
@@ -50653,10 +50939,10 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
50653
50939
|
program2.command("remove").description("Uninstall ThreatCrush and the installed bundle").alias("uninstall").action(async () => {
|
|
50654
50940
|
console.log(LOGO2);
|
|
50655
50941
|
const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
50656
|
-
const confirm = await new Promise((
|
|
50942
|
+
const confirm = await new Promise((resolve7) => {
|
|
50657
50943
|
rl.question(source_default.yellow(" Are you sure you want to uninstall ThreatCrush? (y/N): "), (answer) => {
|
|
50658
50944
|
rl.close();
|
|
50659
|
-
|
|
50945
|
+
resolve7(answer.trim().toLowerCase());
|
|
50660
50946
|
});
|
|
50661
50947
|
});
|
|
50662
50948
|
if (confirm !== "y" && confirm !== "yes") {
|
|
@@ -50681,7 +50967,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
50681
50967
|
for (const cmd of commands) {
|
|
50682
50968
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
50683
50969
|
`));
|
|
50684
|
-
(0,
|
|
50970
|
+
(0, import_node_child_process24.execSync)(cmd, { stdio: "inherit" });
|
|
50685
50971
|
}
|
|
50686
50972
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
50687
50973
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -50758,7 +51044,7 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
50758
51044
|
});
|
|
50759
51045
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
50760
51046
|
console.log(LOGO2);
|
|
50761
|
-
const configPath = (0,
|
|
51047
|
+
const configPath = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
|
|
50762
51048
|
let email = "";
|
|
50763
51049
|
try {
|
|
50764
51050
|
const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
|
|
@@ -50767,10 +51053,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
50767
51053
|
}
|
|
50768
51054
|
if (!email) {
|
|
50769
51055
|
const rl2 = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
50770
|
-
email = await new Promise((
|
|
51056
|
+
email = await new Promise((resolve7) => {
|
|
50771
51057
|
rl2.question(source_default.green(" Enter your email: "), (answer) => {
|
|
50772
51058
|
rl2.close();
|
|
50773
|
-
|
|
51059
|
+
resolve7(answer.trim());
|
|
50774
51060
|
});
|
|
50775
51061
|
});
|
|
50776
51062
|
if (!email || !email.includes("@")) {
|
|
@@ -50778,7 +51064,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
50778
51064
|
return;
|
|
50779
51065
|
}
|
|
50780
51066
|
try {
|
|
50781
|
-
const dir = (0,
|
|
51067
|
+
const dir = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush");
|
|
50782
51068
|
if (!(0, import_node_fs55.existsSync)(dir)) (0, import_node_fs55.mkdirSync)(dir, { recursive: true });
|
|
50783
51069
|
(0, import_node_fs55.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
50784
51070
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
@@ -50824,10 +51110,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
50824
51110
|
}
|
|
50825
51111
|
console.log();
|
|
50826
51112
|
const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
50827
|
-
const confirm = await new Promise((
|
|
51113
|
+
const confirm = await new Promise((resolve7) => {
|
|
50828
51114
|
rl.question(source_default.yellow(" Publish this module? (y/N): "), (answer) => {
|
|
50829
51115
|
rl.close();
|
|
50830
|
-
|
|
51116
|
+
resolve7(answer.trim().toLowerCase());
|
|
50831
51117
|
});
|
|
50832
51118
|
});
|
|
50833
51119
|
if (confirm !== "y" && confirm !== "yes") {
|