badmfck-api-server 6.0.12 → 6.0.13
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/CHANGELOG.md +86 -0
- package/README.md +207 -73
- package/dist/apiServer/APIService.d.ts +3 -1
- package/dist/apiServer/APIService.js +25 -1
- package/dist/apiServer/LogService.d.ts +2 -0
- package/dist/apiServer/LogService.js +10 -8
- package/dist/apiServer/MonitorService.d.ts +4 -1
- package/dist/apiServer/MonitorService.js +28 -5
- package/dist/apiServer/deployment/Bundler.d.ts +12 -0
- package/dist/apiServer/deployment/Bundler.js +178 -0
- package/dist/apiServer/deployment/ConfigService.d.ts +6 -0
- package/dist/apiServer/deployment/ConfigService.js +17 -1
- package/dist/apiServer/deployment/Deploy.js +96 -54
- package/dist/apiServer/deployment/DeployKeyWizard.d.ts +1 -0
- package/dist/apiServer/deployment/DeployKeyWizard.js +17 -1
- package/dist/apiServer/deployment/DeployerService.d.ts +4 -1
- package/dist/apiServer/deployment/DeployerService.js +87 -18
- package/dist/apiServer/deployment/HashPassword.js +2 -2
- package/dist/apiServer/deployment/MigrateConfigsWizard.js +9 -5
- package/dist/apiServer/deployment/ProjectConfigWizard.js +4 -2
- package/dist/apiServer/deployment/Restore.js +5 -5
- package/dist/apiServer/deployment/SecretsInjector.js +2 -1
- package/dist/apiServer/deployment/SetupConfigWizard.js +1 -1
- package/dist/apiServer/deployment/Status.js +1 -1
- package/dist/apiServer/deployment/Watchdog.js +1 -1
- package/dist/apiServer/deployment/Wizards.js +11 -11
- package/dist/apiServer/deployment/cli.js +25 -16
- package/dist/apiServer/deployment/cliCommon.d.ts +12 -0
- package/dist/apiServer/deployment/cliCommon.js +44 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +2 -0
- package/dist/apiServer/deployment/resolveConfig.js +10 -0
- package/dist/apiServer/external/MicroserviceClient.d.ts +7 -2
- package/dist/apiServer/external/MicroserviceClient.js +90 -10
- package/dist/apiServer/external/MicroserviceHost.d.ts +35 -8
- package/dist/apiServer/external/MicroserviceHost.js +148 -55
- package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
- package/dist/apiServer/helper/AppDataPath.js +81 -0
- package/dist/apiServer/helper/ClientIp.d.ts +1 -0
- package/dist/apiServer/helper/ClientIp.js +5 -0
- package/dist/apiServer/helper/Trace.d.ts +8 -0
- package/dist/apiServer/helper/Trace.js +30 -0
- package/dist/apiServer/helper/Validator.d.ts +1 -0
- package/dist/apiServer/helper/Validator.js +21 -18
- package/dist/apiServer/http/Http.d.ts +1 -0
- package/dist/apiServer/http/Http.js +5 -2
- package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +2 -1
- package/dist/apiServer/interceptors/InterceptorSignedAuth.js +1 -1
- package/dist/apiServer/monitor/MonitorAuth.js +8 -5
- package/dist/apiServer/monitor/ThreatMonitor.d.ts +8 -0
- package/dist/apiServer/monitor/ThreatMonitor.js +87 -1
- package/dist/apiServer/monitor/index.html +66 -66
- package/dist/apiServer/security/BlockedIps.js +10 -14
- package/dist/apiServer/structures/Interfaces.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +21 -6
- package/bluegreen.help.md +0 -392
- package/cocroach.help.md +0 -191
- package/connections.help.md +0 -0
- package/monitoring.help.md +0 -350
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ThreatMonitor = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
4
9
|
const LogService_1 = require("../LogService");
|
|
10
|
+
const AppDataPath_1 = require("../helper/AppDataPath");
|
|
5
11
|
const SCANNER_PATHS = [
|
|
6
12
|
/\/\.(?:env|git|svn|hg|aws|ssh|DS_Store|htaccess|htpasswd|npmrc|dockerenv)(?:[\/.]|$)/i,
|
|
7
13
|
/\/wp-(?:login|admin|content|includes|config|json)/i,
|
|
@@ -32,6 +38,85 @@ class ThreatMonitor {
|
|
|
32
38
|
static MAX_BODY_SCAN = 8 * 1024;
|
|
33
39
|
static records = new Map();
|
|
34
40
|
static events = [];
|
|
41
|
+
static SAVE_EVERY_MS = 60_000;
|
|
42
|
+
static file = null;
|
|
43
|
+
static writer = false;
|
|
44
|
+
static dirty = false;
|
|
45
|
+
static timer = null;
|
|
46
|
+
static configure(file) {
|
|
47
|
+
ThreatMonitor.file = file;
|
|
48
|
+
if (!file)
|
|
49
|
+
return;
|
|
50
|
+
ThreatMonitor.load();
|
|
51
|
+
(0, AppDataPath_1.onWriterChange)(writer => {
|
|
52
|
+
ThreatMonitor.writer = writer;
|
|
53
|
+
if (writer)
|
|
54
|
+
ThreatMonitor.load();
|
|
55
|
+
});
|
|
56
|
+
if (!ThreatMonitor.timer) {
|
|
57
|
+
ThreatMonitor.timer = setInterval(() => ThreatMonitor.save(), ThreatMonitor.SAVE_EVERY_MS);
|
|
58
|
+
ThreatMonitor.timer.unref?.();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static save() {
|
|
62
|
+
const file = ThreatMonitor.file;
|
|
63
|
+
if (!file || !ThreatMonitor.writer || !ThreatMonitor.dirty)
|
|
64
|
+
return false;
|
|
65
|
+
try {
|
|
66
|
+
const doc = {
|
|
67
|
+
version: 1,
|
|
68
|
+
savedAt: Date.now(),
|
|
69
|
+
records: Array.from(ThreatMonitor.records.values()).map(r => ({ ...r, notFound: Array.from(r.notFound.entries()) })),
|
|
70
|
+
events: ThreatMonitor.events,
|
|
71
|
+
};
|
|
72
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true, mode: 0o700 });
|
|
73
|
+
const tmp = file + ".tmp";
|
|
74
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(doc), { mode: 0o600 });
|
|
75
|
+
fs_1.default.renameSync(tmp, file);
|
|
76
|
+
ThreatMonitor.dirty = false;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
(0, LogService_1.logWarn)("threats: cannot save " + file + ": " + (e?.message ?? e));
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
static load() {
|
|
85
|
+
const file = ThreatMonitor.file;
|
|
86
|
+
if (!file || !fs_1.default.existsSync(file))
|
|
87
|
+
return;
|
|
88
|
+
let doc;
|
|
89
|
+
try {
|
|
90
|
+
doc = JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
(0, LogService_1.logWarn)("threats: cannot read " + file + ": " + (e?.message ?? e));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
97
|
+
for (const raw of Array.isArray(doc?.records) ? doc.records : []) {
|
|
98
|
+
if (!raw || typeof raw.ip !== "string")
|
|
99
|
+
continue;
|
|
100
|
+
const mine = ThreatMonitor.records.get(raw.ip);
|
|
101
|
+
if (mine && mine.lastSeen >= num(raw.lastSeen))
|
|
102
|
+
continue;
|
|
103
|
+
ThreatMonitor.records.set(raw.ip, {
|
|
104
|
+
ip: raw.ip, score: num(raw.score), scoreAt: num(raw.scoreAt),
|
|
105
|
+
firstSeen: num(raw.firstSeen), lastSeen: num(raw.lastSeen), hits: num(raw.hits),
|
|
106
|
+
categories: raw.categories && typeof raw.categories === "object" ? raw.categories : {},
|
|
107
|
+
ua: typeof raw.ua === "string" ? raw.ua : null,
|
|
108
|
+
samples: Array.isArray(raw.samples) ? raw.samples.slice(-10) : [],
|
|
109
|
+
notFound: new Map(Array.isArray(raw.notFound) ? raw.notFound : []),
|
|
110
|
+
enumFlaggedAt: num(raw.enumFlaggedAt),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const sorted = Array.from(ThreatMonitor.records.values()).sort((a, b) => a.lastSeen - b.lastSeen);
|
|
114
|
+
ThreatMonitor.records = new Map(sorted.slice(-ThreatMonitor.MAX_IPS).map(r => [r.ip, r]));
|
|
115
|
+
const seen = new Set(ThreatMonitor.events.map(e => `${e.ts}|${e.ip}|${e.url}`));
|
|
116
|
+
const incoming = (Array.isArray(doc?.events) ? doc.events : [])
|
|
117
|
+
.filter((e) => e && typeof e.ip === "string" && typeof e.ts === "number" && !seen.has(`${e.ts}|${e.ip}|${e.url}`));
|
|
118
|
+
ThreatMonitor.events = ThreatMonitor.events.concat(incoming).sort((a, b) => a.ts - b.ts).slice(-ThreatMonitor.MAX_EVENTS);
|
|
119
|
+
}
|
|
35
120
|
static decayed(r, now) {
|
|
36
121
|
return r.score * Math.pow(0.5, (now - r.scoreAt) / ThreatMonitor.HALF_LIFE_MS);
|
|
37
122
|
}
|
|
@@ -112,6 +197,7 @@ class ThreatMonitor {
|
|
|
112
197
|
if (r.samples.length > 10)
|
|
113
198
|
r.samples.shift();
|
|
114
199
|
ThreatMonitor.records.set(o.ip, r);
|
|
200
|
+
ThreatMonitor.dirty = true;
|
|
115
201
|
while (ThreatMonitor.records.size > ThreatMonitor.MAX_IPS)
|
|
116
202
|
ThreatMonitor.records.delete(ThreatMonitor.records.keys().next().value);
|
|
117
203
|
if (add >= WEIGHT.auth) {
|
|
@@ -148,6 +234,6 @@ class ThreatMonitor {
|
|
|
148
234
|
recent: ThreatMonitor.events.slice(-Math.max(1, Math.min(limit, 500))).reverse(),
|
|
149
235
|
};
|
|
150
236
|
}
|
|
151
|
-
static reset() { ThreatMonitor.records.clear(); ThreatMonitor.events = []; }
|
|
237
|
+
static reset() { ThreatMonitor.records.clear(); ThreatMonitor.events = []; ThreatMonitor.dirty = true; }
|
|
152
238
|
}
|
|
153
239
|
exports.ThreatMonitor = ThreatMonitor;
|