@dimzxzzx07/file-watcher 1.0.0
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/.env +13 -0
- package/.eslintrc.json +128 -0
- package/.prettierrc +18 -0
- package/Dimzxzzx07.png +0 -0
- package/README.md +1024 -0
- package/dist/core/BackupManager.d.ts +25 -0
- package/dist/core/BackupManager.d.ts.map +1 -0
- package/dist/core/BackupManager.js +290 -0
- package/dist/core/BackupManager.js.map +1 -0
- package/dist/core/IntegrityValidator.d.ts +18 -0
- package/dist/core/IntegrityValidator.d.ts.map +1 -0
- package/dist/core/IntegrityValidator.js +212 -0
- package/dist/core/IntegrityValidator.js.map +1 -0
- package/dist/core/SecurityManager.d.ts +40 -0
- package/dist/core/SecurityManager.d.ts.map +1 -0
- package/dist/core/SecurityManager.js +320 -0
- package/dist/core/SecurityManager.js.map +1 -0
- package/dist/core/WatcherEngine.d.ts +44 -0
- package/dist/core/WatcherEngine.d.ts.map +1 -0
- package/dist/core/WatcherEngine.js +470 -0
- package/dist/core/WatcherEngine.js.map +1 -0
- package/dist/crypto/HashGenerator.d.ts +26 -0
- package/dist/crypto/HashGenerator.d.ts.map +1 -0
- package/dist/crypto/HashGenerator.js +220 -0
- package/dist/crypto/HashGenerator.js.map +1 -0
- package/dist/crypto/KeyManager.d.ts +30 -0
- package/dist/crypto/KeyManager.d.ts.map +1 -0
- package/dist/crypto/KeyManager.js +235 -0
- package/dist/crypto/KeyManager.js.map +1 -0
- package/dist/crypto/SignatureValidator.d.ts +11 -0
- package/dist/crypto/SignatureValidator.d.ts.map +1 -0
- package/dist/crypto/SignatureValidator.js +102 -0
- package/dist/crypto/SignatureValidator.js.map +1 -0
- package/dist/detectors/AnomalyDetector.d.ts +24 -0
- package/dist/detectors/AnomalyDetector.d.ts.map +1 -0
- package/dist/detectors/AnomalyDetector.js +209 -0
- package/dist/detectors/AnomalyDetector.js.map +1 -0
- package/dist/detectors/InjectionDetector.d.ts +14 -0
- package/dist/detectors/InjectionDetector.d.ts.map +1 -0
- package/dist/detectors/InjectionDetector.js +204 -0
- package/dist/detectors/InjectionDetector.js.map +1 -0
- package/dist/detectors/PatternMatcher.d.ts +28 -0
- package/dist/detectors/PatternMatcher.d.ts.map +1 -0
- package/dist/detectors/PatternMatcher.js +283 -0
- package/dist/detectors/PatternMatcher.js.map +1 -0
- package/dist/guards/FileGuard.d.ts +35 -0
- package/dist/guards/FileGuard.d.ts.map +1 -0
- package/dist/guards/FileGuard.js +357 -0
- package/dist/guards/FileGuard.js.map +1 -0
- package/dist/guards/MemoryGuard.d.ts +28 -0
- package/dist/guards/MemoryGuard.d.ts.map +1 -0
- package/dist/guards/MemoryGuard.js +256 -0
- package/dist/guards/MemoryGuard.js.map +1 -0
- package/dist/guards/ProcessGuard.d.ts +25 -0
- package/dist/guards/ProcessGuard.d.ts.map +1 -0
- package/dist/guards/ProcessGuard.js +221 -0
- package/dist/guards/ProcessGuard.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +186 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +69 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/Constants.d.ts +407 -0
- package/dist/utils/Constants.d.ts.map +1 -0
- package/dist/utils/Constants.js +505 -0
- package/dist/utils/Constants.js.map +1 -0
- package/dist/utils/Logger.d.ts +45 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +285 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/Validator.d.ts +27 -0
- package/dist/utils/Validator.d.ts.map +1 -0
- package/dist/utils/Validator.js +245 -0
- package/dist/utils/Validator.js.map +1 -0
- package/favicon.png +0 -0
- package/jest.config.js +69 -0
- package/package.json +69 -0
- package/src/core/BackupManager.ts +305 -0
- package/src/core/IntegrityValidator.ts +200 -0
- package/src/core/SecurityManager.ts +348 -0
- package/src/core/WatcherEngine.ts +537 -0
- package/src/crypto/HashGenerator.ts +234 -0
- package/src/crypto/KeyManager.ts +249 -0
- package/src/crypto/SignatureValidator.ts +76 -0
- package/src/detectors/AnomalyDetector.ts +247 -0
- package/src/detectors/InjectionDetector.ts +233 -0
- package/src/detectors/PatternMatcher.ts +319 -0
- package/src/guards/FileGuard.ts +385 -0
- package/src/guards/MemoryGuard.ts +263 -0
- package/src/guards/ProcessGuard.ts +219 -0
- package/src/index.ts +189 -0
- package/src/types/index.ts +72 -0
- package/src/utils/Constants.ts +532 -0
- package/src/utils/Logger.ts +279 -0
- package/src/utils/Validator.ts +248 -0
- package/tests/setup.ts +80 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PatternMatcher.d.ts","sourceRoot":"","sources":["../../src/detectors/PatternMatcher.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;;IAanD,OAAO,CAAC,kBAAkB;IA+D1B,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,oBAAoB;IAoErB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAcrD,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAcvD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAoBtD,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;QACvC,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACrE,KAAK,EAAE,MAAM,CAAC;KACjB;IAkDD,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,SAAS;IAaV,WAAW,IAAI,MAAM,EAAE;IAIvB,aAAa,IAAI,MAAM,EAAE;IAIzB,aAAa,IAAI,MAAM,EAAE;CAGnC"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatternMatcher = void 0;
|
|
4
|
+
const Logger_1 = require("../utils/Logger");
|
|
5
|
+
class PatternMatcher {
|
|
6
|
+
logger;
|
|
7
|
+
patterns;
|
|
8
|
+
signatures;
|
|
9
|
+
heuristics;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.logger = Logger_1.Logger.getInstance();
|
|
12
|
+
this.patterns = new Map();
|
|
13
|
+
this.signatures = new Map();
|
|
14
|
+
this.heuristics = new Map();
|
|
15
|
+
this.initializePatterns();
|
|
16
|
+
this.initializeSignatures();
|
|
17
|
+
this.initializeHeuristics();
|
|
18
|
+
}
|
|
19
|
+
initializePatterns() {
|
|
20
|
+
this.patterns.set('injection', [
|
|
21
|
+
/eval\s*\(\s*['"`][^)]*['"`]\s*\)/gi,
|
|
22
|
+
/Function\s*\(\s*['"`][^)]*['"`]\s*\)/gi,
|
|
23
|
+
/setTimeout\s*\(\s*['"`][^)]*['"`]\s*\)/gi,
|
|
24
|
+
/setInterval\s*\(\s*['"`][^)]*['"`]\s*\)/gi,
|
|
25
|
+
/new\s+Function\s*\(\s*['"`][^)]*['"`]\s*\)/gi,
|
|
26
|
+
/require\s*\(\s*['"`](?:fs|child_process|vm|cluster)['"`]\s*\)/gi,
|
|
27
|
+
/process\.(?:binding|dlopen|kill)\s*\(/gi,
|
|
28
|
+
/child_process\.(?:exec|spawn|fork)\s*\(/gi,
|
|
29
|
+
/vm\.(?:runIn|create)\s*\(/gi
|
|
30
|
+
]);
|
|
31
|
+
this.patterns.set('obfuscation', [
|
|
32
|
+
/String\.fromCharCode\s*\([^)]+\)/gi,
|
|
33
|
+
/unescape\s*\([^)]+\)/gi,
|
|
34
|
+
/escape\s*\([^)]+\)/gi,
|
|
35
|
+
/decodeURI(?:Component)?\s*\([^)]+\)/gi,
|
|
36
|
+
/atob\s*\([^)]+\)/gi,
|
|
37
|
+
/btoa\s*\([^)]+\)/gi,
|
|
38
|
+
/Buffer\.from\s*\([^)]+\)/gi,
|
|
39
|
+
/new\s+Buffer\s*\([^)]+\)/gi,
|
|
40
|
+
/\[[A-Za-z0-9+/]{50,}\]/g,
|
|
41
|
+
/\\x[0-9a-f]{2,50}/gi
|
|
42
|
+
]);
|
|
43
|
+
this.patterns.set('backdoor', [
|
|
44
|
+
/net\.(?:createServer|connect)\s*\(/gi,
|
|
45
|
+
/http\.(?:createServer|request)\s*\(/gi,
|
|
46
|
+
/tls\.(?:createServer|connect)\s*\(/gi,
|
|
47
|
+
/dgram\.createSocket\s*\(/gi,
|
|
48
|
+
/WebSocket\s*\(/gi,
|
|
49
|
+
/Socket\.(?:connect|bind|listen)\s*\(/gi,
|
|
50
|
+
/server\.listen\s*\(\s*(?:[0-9]+|['"`][^)]*['"`])\s*\)/gi
|
|
51
|
+
]);
|
|
52
|
+
this.patterns.set('malware', [
|
|
53
|
+
/crypto\.(?:miner|monero)/gi,
|
|
54
|
+
/xmr\./gi,
|
|
55
|
+
/coinhive/gi,
|
|
56
|
+
/Crypt(?:o)?Night/gi,
|
|
57
|
+
/webchain/gi,
|
|
58
|
+
/miner\./gi
|
|
59
|
+
]);
|
|
60
|
+
this.patterns.set('anti-debug', [
|
|
61
|
+
/debugger;/g,
|
|
62
|
+
/--inspect/g,
|
|
63
|
+
/--debug/g,
|
|
64
|
+
/process\.(?:_getActiveRequests|_getActiveHandles)/g,
|
|
65
|
+
/Error\.captureStackTrace/g,
|
|
66
|
+
/process\.binding\(['"`]debug['"`]\)/g
|
|
67
|
+
]);
|
|
68
|
+
this.patterns.set('self-modify', [
|
|
69
|
+
/fs\.(?:writeFile|unlink|rename)Sync?\s*\(\s*__filename/gi,
|
|
70
|
+
/fs\.(?:writeFile|unlink|rename)Sync?\s*\(\s*module\.filename/gi,
|
|
71
|
+
/process\.argv\s*\[\s*1\s*\]/gi,
|
|
72
|
+
/module\.exports\s*=\s*\{/gi,
|
|
73
|
+
/exports\.[a-zA-Z_]+\s*=/gi
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
initializeSignatures() {
|
|
77
|
+
this.signatures.set('malware', [
|
|
78
|
+
'4d5a90',
|
|
79
|
+
'7f454c46',
|
|
80
|
+
'cafebabe',
|
|
81
|
+
'1f8b08',
|
|
82
|
+
'504b0304',
|
|
83
|
+
'25504446',
|
|
84
|
+
'd0cf11e0',
|
|
85
|
+
'38425053'
|
|
86
|
+
]);
|
|
87
|
+
this.signatures.set('injection', [
|
|
88
|
+
'eval(atob(',
|
|
89
|
+
'new Function(atob(',
|
|
90
|
+
'process.binding',
|
|
91
|
+
'Reflect.construct',
|
|
92
|
+
'Object.defineProperty',
|
|
93
|
+
'__defineGetter__',
|
|
94
|
+
'__defineSetter__'
|
|
95
|
+
]);
|
|
96
|
+
this.signatures.set('backdoor', [
|
|
97
|
+
'reverse shell',
|
|
98
|
+
'bind shell',
|
|
99
|
+
'backconnect',
|
|
100
|
+
'command injection',
|
|
101
|
+
'remote access'
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
initializeHeuristics() {
|
|
105
|
+
this.heuristics.set('suspicious_structure', (content) => {
|
|
106
|
+
let score = 0;
|
|
107
|
+
const tryCount = (content.match(/try\s*{/g) || []).length;
|
|
108
|
+
const catchCount = (content.match(/catch\s*\(/g) || []).length;
|
|
109
|
+
if (tryCount > catchCount)
|
|
110
|
+
score += 10;
|
|
111
|
+
const concatCount = (content.match(/\+/g) || []).length;
|
|
112
|
+
if (concatCount > 100)
|
|
113
|
+
score += 20;
|
|
114
|
+
const functionCount = (content.match(/function\s*\(/g) || []).length;
|
|
115
|
+
if (functionCount > 20)
|
|
116
|
+
score += 15;
|
|
117
|
+
return score > 30;
|
|
118
|
+
});
|
|
119
|
+
this.heuristics.set('weird_variables', (content) => {
|
|
120
|
+
const varPattern = /(?:var|let|const)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/g;
|
|
121
|
+
const matches = content.match(varPattern) || [];
|
|
122
|
+
let weirdCount = 0;
|
|
123
|
+
for (const match of matches) {
|
|
124
|
+
const varName = match.split(/\s+/)[1];
|
|
125
|
+
if (varName && (varName.length > 30 ||
|
|
126
|
+
/^_+$/.test(varName) ||
|
|
127
|
+
/^[0-9]+$/.test(varName) ||
|
|
128
|
+
varName.includes('_0x'))) {
|
|
129
|
+
weirdCount++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return weirdCount > 5;
|
|
133
|
+
});
|
|
134
|
+
this.heuristics.set('suspicious_strings', (content) => {
|
|
135
|
+
const suspiciousStrings = [
|
|
136
|
+
'eval', 'Function', 'constructor', 'prototype',
|
|
137
|
+
'__proto__', 'defineProperty', 'getOwnProperty',
|
|
138
|
+
'caller', 'callee', 'arguments', 'apply', 'bind',
|
|
139
|
+
'toString', 'valueOf', 'hasOwnProperty',
|
|
140
|
+
'isPrototypeOf', 'propertyIsEnumerable',
|
|
141
|
+
'toLocaleString', 'watch', 'unwatch'
|
|
142
|
+
];
|
|
143
|
+
let suspiciousCount = 0;
|
|
144
|
+
for (const str of suspiciousStrings) {
|
|
145
|
+
const regex = new RegExp(`['"\`]${str}['"\`]`, 'g');
|
|
146
|
+
const matches = content.match(regex) || [];
|
|
147
|
+
suspiciousCount += matches.length;
|
|
148
|
+
}
|
|
149
|
+
return suspiciousCount > 10;
|
|
150
|
+
});
|
|
151
|
+
this.heuristics.set('encoded_content', (content) => {
|
|
152
|
+
const base64Matches = content.match(/[A-Za-z0-9+/]{100,}={0,2}/g) || [];
|
|
153
|
+
const hexMatches = content.match(/[0-9a-fA-F]{100,}/g) || [];
|
|
154
|
+
const unicodeMatches = content.match(/\\u[0-9a-fA-F]{4}/g) || [];
|
|
155
|
+
return base64Matches.length > 0 ||
|
|
156
|
+
hexMatches.length > 0 ||
|
|
157
|
+
unicodeMatches.length > 20;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
matchPatterns(content, type) {
|
|
161
|
+
const patterns = this.patterns.get(type);
|
|
162
|
+
if (!patterns)
|
|
163
|
+
return false;
|
|
164
|
+
for (const pattern of patterns) {
|
|
165
|
+
if (pattern.test(content)) {
|
|
166
|
+
this.logger.debug(`Pattern matched: ${type}`, { pattern: pattern.source });
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
matchSignatures(content, type) {
|
|
173
|
+
const signatures = this.signatures.get(type);
|
|
174
|
+
if (!signatures)
|
|
175
|
+
return false;
|
|
176
|
+
for (const signature of signatures) {
|
|
177
|
+
if (content.includes(signature)) {
|
|
178
|
+
this.logger.debug(`Signature matched: ${type}`, { signature });
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
applyHeuristics(content) {
|
|
185
|
+
const results = new Map();
|
|
186
|
+
for (const [name, heuristic] of this.heuristics) {
|
|
187
|
+
try {
|
|
188
|
+
const result = heuristic(content);
|
|
189
|
+
results.set(name, result);
|
|
190
|
+
if (result) {
|
|
191
|
+
this.logger.debug(`Heuristic triggered: ${name}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
this.logger.error(`Heuristic failed: ${name}`, { error });
|
|
196
|
+
results.set(name, false);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return results;
|
|
200
|
+
}
|
|
201
|
+
comprehensiveScan(content) {
|
|
202
|
+
const findings = [];
|
|
203
|
+
let totalScore = 0;
|
|
204
|
+
for (const [type, patterns] of this.patterns) {
|
|
205
|
+
for (const pattern of patterns) {
|
|
206
|
+
const matches = content.match(new RegExp(pattern.source, 'g')) || [];
|
|
207
|
+
if (matches.length > 0) {
|
|
208
|
+
findings.push({
|
|
209
|
+
type,
|
|
210
|
+
pattern: pattern.source,
|
|
211
|
+
severity: this.getSeverity(type, matches.length)
|
|
212
|
+
});
|
|
213
|
+
totalScore += matches.length * this.getWeight(type);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
for (const [type, signatures] of this.signatures) {
|
|
218
|
+
for (const signature of signatures) {
|
|
219
|
+
if (content.includes(signature)) {
|
|
220
|
+
findings.push({
|
|
221
|
+
type,
|
|
222
|
+
pattern: signature,
|
|
223
|
+
severity: 'high'
|
|
224
|
+
});
|
|
225
|
+
totalScore += 20;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const heuristicResults = this.applyHeuristics(content);
|
|
230
|
+
for (const [name, result] of heuristicResults) {
|
|
231
|
+
if (result) {
|
|
232
|
+
findings.push({
|
|
233
|
+
type: 'heuristic',
|
|
234
|
+
pattern: name,
|
|
235
|
+
severity: 'medium'
|
|
236
|
+
});
|
|
237
|
+
totalScore += 10;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
matched: findings.length > 0,
|
|
242
|
+
findings,
|
|
243
|
+
score: totalScore
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
getSeverity(type, count) {
|
|
247
|
+
if (type === 'malware' || type === 'backdoor')
|
|
248
|
+
return 'critical';
|
|
249
|
+
if (type === 'injection')
|
|
250
|
+
return 'high';
|
|
251
|
+
if (type === 'anti-debug' || type === 'self-modify')
|
|
252
|
+
return 'high';
|
|
253
|
+
if (type === 'obfuscation')
|
|
254
|
+
return 'medium';
|
|
255
|
+
if (count > 10)
|
|
256
|
+
return 'high';
|
|
257
|
+
if (count > 5)
|
|
258
|
+
return 'medium';
|
|
259
|
+
return 'low';
|
|
260
|
+
}
|
|
261
|
+
getWeight(type) {
|
|
262
|
+
const weights = {
|
|
263
|
+
'malware': 10,
|
|
264
|
+
'backdoor': 10,
|
|
265
|
+
'injection': 8,
|
|
266
|
+
'anti-debug': 6,
|
|
267
|
+
'self-modify': 6,
|
|
268
|
+
'obfuscation': 4
|
|
269
|
+
};
|
|
270
|
+
return weights[type] || 1;
|
|
271
|
+
}
|
|
272
|
+
getPatterns() {
|
|
273
|
+
return Array.from(this.patterns.keys());
|
|
274
|
+
}
|
|
275
|
+
getSignatures() {
|
|
276
|
+
return Array.from(this.signatures.keys());
|
|
277
|
+
}
|
|
278
|
+
getHeuristics() {
|
|
279
|
+
return Array.from(this.heuristics.keys());
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.PatternMatcher = PatternMatcher;
|
|
283
|
+
//# sourceMappingURL=PatternMatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PatternMatcher.js","sourceRoot":"","sources":["../../src/detectors/PatternMatcher.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AAEzC,MAAa,cAAc;IACN,MAAM,CAAS;IACf,QAAQ,CAAwB;IAChC,UAAU,CAAwB;IAClC,UAAU,CAAwB;IAEnD;QACI,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAE5B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEO,kBAAkB;QACtB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE;YAC3B,oCAAoC;Y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B,CAAC;IACN,CAAC;IAEO,WAAW,CAAC,IAAY,EAAE,KAAa;QAC3C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU;YAAE,OAAO,UAAU,CAAC;QACjE,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO,MAAM,CAAC;QACxC,IAAI,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,aAAa;YAAE,OAAO,MAAM,CAAC;QACnE,IAAI,IAAI,KAAK,aAAa;YAAE,OAAO,QAAQ,CAAC;QAE5C,IAAI,KAAK,GAAG,EAAE;YAAE,OAAO,MAAM,CAAC;QAC9B,IAAI,KAAK,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAC;QAC/B,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,SAAS,CAAC,IAAY;QAC1B,MAAM,OAAO,GAA2B;YACpC,SAAS,EAAE,EAAE;YACb,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,aAAa,EAAE,CAAC;YAChB,aAAa,EAAE,CAAC;SACnB,CAAC;QAEF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAEM,WAAW;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAEM,aAAa;QAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,aAAa;QAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;CACJ;AA5TD,wCA4TC","sourcesContent":["import { Logger } from '../utils/Logger';\n\nexport class PatternMatcher {\n private readonly logger: Logger;\n private readonly patterns: Map<string, RegExp[]>;\n private readonly signatures: Map<string, string[]>;\n private readonly heuristics: Map<string, Function>;\n\n constructor() {\n this.logger = Logger.getInstance();\n this.patterns = new Map();\n this.signatures = new Map();\n this.heuristics = new Map();\n \n this.initializePatterns();\n this.initializeSignatures();\n this.initializeHeuristics();\n }\n\n private initializePatterns(): void {\n this.patterns.set('injection', [\n /eval\\s*\\(\\s*['\"`][^)]*['\"`]\\s*\\)/gi,\n /Function\\s*\\(\\s*['\"`][^)]*['\"`]\\s*\\)/gi,\n /setTimeout\\s*\\(\\s*['\"`][^)]*['\"`]\\s*\\)/gi,\n /setInterval\\s*\\(\\s*['\"`][^)]*['\"`]\\s*\\)/gi,\n /new\\s+Function\\s*\\(\\s*['\"`][^)]*['\"`]\\s*\\)/gi,\n /require\\s*\\(\\s*['\"`](?:fs|child_process|vm|cluster)['\"`]\\s*\\)/gi,\n /process\\.(?:binding|dlopen|kill)\\s*\\(/gi,\n /child_process\\.(?:exec|spawn|fork)\\s*\\(/gi,\n /vm\\.(?:runIn|create)\\s*\\(/gi\n ]);\n\n this.patterns.set('obfuscation', [\n /String\\.fromCharCode\\s*\\([^)]+\\)/gi,\n /unescape\\s*\\([^)]+\\)/gi,\n /escape\\s*\\([^)]+\\)/gi,\n /decodeURI(?:Component)?\\s*\\([^)]+\\)/gi,\n /atob\\s*\\([^)]+\\)/gi,\n /btoa\\s*\\([^)]+\\)/gi,\n /Buffer\\.from\\s*\\([^)]+\\)/gi,\n /new\\s+Buffer\\s*\\([^)]+\\)/gi,\n /\\[[A-Za-z0-9+/]{50,}\\]/g,\n /\\\\x[0-9a-f]{2,50}/gi\n ]);\n\n this.patterns.set('backdoor', [\n /net\\.(?:createServer|connect)\\s*\\(/gi,\n /http\\.(?:createServer|request)\\s*\\(/gi,\n /tls\\.(?:createServer|connect)\\s*\\(/gi,\n /dgram\\.createSocket\\s*\\(/gi,\n /WebSocket\\s*\\(/gi,\n /Socket\\.(?:connect|bind|listen)\\s*\\(/gi,\n /server\\.listen\\s*\\(\\s*(?:[0-9]+|['\"`][^)]*['\"`])\\s*\\)/gi\n ]);\n\n this.patterns.set('malware', [\n /crypto\\.(?:miner|monero)/gi,\n /xmr\\./gi,\n /coinhive/gi,\n /Crypt(?:o)?Night/gi,\n /webchain/gi,\n /miner\\./gi\n ]);\n\n this.patterns.set('anti-debug', [\n /debugger;/g,\n /--inspect/g,\n /--debug/g,\n /process\\.(?:_getActiveRequests|_getActiveHandles)/g,\n /Error\\.captureStackTrace/g,\n /process\\.binding\\(['\"`]debug['\"`]\\)/g\n ]);\n\n this.patterns.set('self-modify', [\n /fs\\.(?:writeFile|unlink|rename)Sync?\\s*\\(\\s*__filename/gi,\n /fs\\.(?:writeFile|unlink|rename)Sync?\\s*\\(\\s*module\\.filename/gi,\n /process\\.argv\\s*\\[\\s*1\\s*\\]/gi,\n /module\\.exports\\s*=\\s*\\{/gi,\n /exports\\.[a-zA-Z_]+\\s*=/gi\n ]);\n }\n\n private initializeSignatures(): void {\n this.signatures.set('malware', [\n '4d5a90',\n '7f454c46',\n 'cafebabe',\n '1f8b08',\n '504b0304',\n '25504446',\n 'd0cf11e0',\n '38425053'\n ]);\n\n this.signatures.set('injection', [\n 'eval(atob(',\n 'new Function(atob(',\n 'process.binding',\n 'Reflect.construct',\n 'Object.defineProperty',\n '__defineGetter__',\n '__defineSetter__'\n ]);\n\n this.signatures.set('backdoor', [\n 'reverse shell',\n 'bind shell',\n 'backconnect',\n 'command injection',\n 'remote access'\n ]);\n }\n\n private initializeHeuristics(): void {\n this.heuristics.set('suspicious_structure', (content: string) => {\n let score = 0;\n \n const tryCount = (content.match(/try\\s*{/g) || []).length;\n const catchCount = (content.match(/catch\\s*\\(/g) || []).length;\n if (tryCount > catchCount) score += 10;\n \n const concatCount = (content.match(/\\+/g) || []).length;\n if (concatCount > 100) score += 20;\n \n const functionCount = (content.match(/function\\s*\\(/g) || []).length;\n if (functionCount > 20) score += 15;\n \n return score > 30;\n });\n\n this.heuristics.set('weird_variables', (content: string) => {\n const varPattern = /(?:var|let|const)\\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/g;\n const matches = content.match(varPattern) || [];\n \n let weirdCount = 0;\n for (const match of matches) {\n const varName = match.split(/\\s+/)[1];\n if (varName && (\n varName.length > 30 ||\n /^_+$/.test(varName) ||\n /^[0-9]+$/.test(varName) ||\n varName.includes('_0x')\n )) {\n weirdCount++;\n }\n }\n \n return weirdCount > 5;\n });\n\n this.heuristics.set('suspicious_strings', (content: string) => {\n const suspiciousStrings = [\n 'eval', 'Function', 'constructor', 'prototype',\n '__proto__', 'defineProperty', 'getOwnProperty',\n 'caller', 'callee', 'arguments', 'apply', 'bind',\n 'toString', 'valueOf', 'hasOwnProperty',\n 'isPrototypeOf', 'propertyIsEnumerable',\n 'toLocaleString', 'watch', 'unwatch'\n ];\n \n let suspiciousCount = 0;\n for (const str of suspiciousStrings) {\n const regex = new RegExp(`['\"\\`]${str}['\"\\`]`, 'g');\n const matches = content.match(regex) || [];\n suspiciousCount += matches.length;\n }\n \n return suspiciousCount > 10;\n });\n\n this.heuristics.set('encoded_content', (content: string) => {\n const base64Matches = content.match(/[A-Za-z0-9+/]{100,}={0,2}/g) || [];\n const hexMatches = content.match(/[0-9a-fA-F]{100,}/g) || [];\n const unicodeMatches = content.match(/\\\\u[0-9a-fA-F]{4}/g) || [];\n \n return base64Matches.length > 0 || \n hexMatches.length > 0 || \n unicodeMatches.length > 20;\n });\n }\n\n public matchPatterns(content: string, type: string): boolean {\n const patterns = this.patterns.get(type);\n if (!patterns) return false;\n\n for (const pattern of patterns) {\n if (pattern.test(content)) {\n this.logger.debug(`Pattern matched: ${type}`, { pattern: pattern.source });\n return true;\n }\n }\n\n return false;\n }\n\n public matchSignatures(content: string, type: string): boolean {\n const signatures = this.signatures.get(type);\n if (!signatures) return false;\n\n for (const signature of signatures) {\n if (content.includes(signature)) {\n this.logger.debug(`Signature matched: ${type}`, { signature });\n return true;\n }\n }\n\n return false;\n }\n\n public applyHeuristics(content: string): Map<string, boolean> {\n const results = new Map<string, boolean>();\n\n for (const [name, heuristic] of this.heuristics) {\n try {\n const result = heuristic(content);\n results.set(name, result);\n \n if (result) {\n this.logger.debug(`Heuristic triggered: ${name}`);\n }\n } catch (error) {\n this.logger.error(`Heuristic failed: ${name}`, { error });\n results.set(name, false);\n }\n }\n\n return results;\n }\n\n public comprehensiveScan(content: string): {\n matched: boolean;\n findings: Array<{ type: string; pattern: string; severity: string }>;\n score: number;\n } {\n const findings: Array<{ type: string; pattern: string; severity: string }> = [];\n let totalScore = 0;\n\n for (const [type, patterns] of this.patterns) {\n for (const pattern of patterns) {\n const matches = content.match(new RegExp(pattern.source, 'g')) || [];\n if (matches.length > 0) {\n findings.push({\n type,\n pattern: pattern.source,\n severity: this.getSeverity(type, matches.length)\n });\n totalScore += matches.length * this.getWeight(type);\n }\n }\n }\n\n for (const [type, signatures] of this.signatures) {\n for (const signature of signatures) {\n if (content.includes(signature)) {\n findings.push({\n type,\n pattern: signature,\n severity: 'high'\n });\n totalScore += 20;\n }\n }\n }\n\n const heuristicResults = this.applyHeuristics(content);\n for (const [name, result] of heuristicResults) {\n if (result) {\n findings.push({\n type: 'heuristic',\n pattern: name,\n severity: 'medium'\n });\n totalScore += 10;\n }\n }\n\n return {\n matched: findings.length > 0,\n findings,\n score: totalScore\n };\n }\n\n private getSeverity(type: string, count: number): string {\n if (type === 'malware' || type === 'backdoor') return 'critical';\n if (type === 'injection') return 'high';\n if (type === 'anti-debug' || type === 'self-modify') return 'high';\n if (type === 'obfuscation') return 'medium';\n \n if (count > 10) return 'high';\n if (count > 5) return 'medium';\n return 'low';\n }\n\n private getWeight(type: string): number {\n const weights: Record<string, number> = {\n 'malware': 10,\n 'backdoor': 10,\n 'injection': 8,\n 'anti-debug': 6,\n 'self-modify': 6,\n 'obfuscation': 4\n };\n \n return weights[type] || 1;\n }\n\n public getPatterns(): string[] {\n return Array.from(this.patterns.keys());\n }\n\n public getSignatures(): string[] {\n return Array.from(this.signatures.keys());\n }\n\n public getHeuristics(): string[] {\n return Array.from(this.heuristics.keys());\n }\n}"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class FileGuard {
|
|
2
|
+
private static instance;
|
|
3
|
+
private readonly logger;
|
|
4
|
+
private readonly fileLocks;
|
|
5
|
+
private readonly filePermissions;
|
|
6
|
+
private readonly watchedFiles;
|
|
7
|
+
private readonly quarantineDir;
|
|
8
|
+
private isActive;
|
|
9
|
+
private constructor();
|
|
10
|
+
static getInstance(): FileGuard;
|
|
11
|
+
private initializeQuarantine;
|
|
12
|
+
private startFileMonitoring;
|
|
13
|
+
protectFile(filePath: string): Promise<boolean>;
|
|
14
|
+
lockFile(filePath: string): Promise<boolean>;
|
|
15
|
+
unlockFile(filePath: string): Promise<boolean>;
|
|
16
|
+
quarantineFile(filePath: string, reason: string): Promise<string>;
|
|
17
|
+
restoreFromQuarantine(quarantinePath: string): Promise<boolean>;
|
|
18
|
+
verifyFileIntegrity(filePath: string): Promise<boolean>;
|
|
19
|
+
createBackup(filePath: string): Promise<string>;
|
|
20
|
+
restoreFromBackup(backupPath: string, targetPath: string): Promise<boolean>;
|
|
21
|
+
monitorFile(filePath: string): Promise<void>;
|
|
22
|
+
private handleFileChange;
|
|
23
|
+
private handleFileDelete;
|
|
24
|
+
private checkFileIntegrity;
|
|
25
|
+
private fileExists;
|
|
26
|
+
private calculateFileHash;
|
|
27
|
+
private getStoredHash;
|
|
28
|
+
private findBackups;
|
|
29
|
+
getLockedFiles(): string[];
|
|
30
|
+
getWatchedFiles(): string[];
|
|
31
|
+
getQuarantinedFiles(): Promise<string[]>;
|
|
32
|
+
deactivate(): void;
|
|
33
|
+
getStatus(): any;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=FileGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileGuard.d.ts","sourceRoot":"","sources":["../../src/guards/FileGuard.ts"],"names":[],"mappings":"AAKA,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAY;IACnC,OAAO,CAAC,Q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