@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.
Files changed (100) hide show
  1. package/.env +13 -0
  2. package/.eslintrc.json +128 -0
  3. package/.prettierrc +18 -0
  4. package/Dimzxzzx07.png +0 -0
  5. package/README.md +1024 -0
  6. package/dist/core/BackupManager.d.ts +25 -0
  7. package/dist/core/BackupManager.d.ts.map +1 -0
  8. package/dist/core/BackupManager.js +290 -0
  9. package/dist/core/BackupManager.js.map +1 -0
  10. package/dist/core/IntegrityValidator.d.ts +18 -0
  11. package/dist/core/IntegrityValidator.d.ts.map +1 -0
  12. package/dist/core/IntegrityValidator.js +212 -0
  13. package/dist/core/IntegrityValidator.js.map +1 -0
  14. package/dist/core/SecurityManager.d.ts +40 -0
  15. package/dist/core/SecurityManager.d.ts.map +1 -0
  16. package/dist/core/SecurityManager.js +320 -0
  17. package/dist/core/SecurityManager.js.map +1 -0
  18. package/dist/core/WatcherEngine.d.ts +44 -0
  19. package/dist/core/WatcherEngine.d.ts.map +1 -0
  20. package/dist/core/WatcherEngine.js +470 -0
  21. package/dist/core/WatcherEngine.js.map +1 -0
  22. package/dist/crypto/HashGenerator.d.ts +26 -0
  23. package/dist/crypto/HashGenerator.d.ts.map +1 -0
  24. package/dist/crypto/HashGenerator.js +220 -0
  25. package/dist/crypto/HashGenerator.js.map +1 -0
  26. package/dist/crypto/KeyManager.d.ts +30 -0
  27. package/dist/crypto/KeyManager.d.ts.map +1 -0
  28. package/dist/crypto/KeyManager.js +235 -0
  29. package/dist/crypto/KeyManager.js.map +1 -0
  30. package/dist/crypto/SignatureValidator.d.ts +11 -0
  31. package/dist/crypto/SignatureValidator.d.ts.map +1 -0
  32. package/dist/crypto/SignatureValidator.js +102 -0
  33. package/dist/crypto/SignatureValidator.js.map +1 -0
  34. package/dist/detectors/AnomalyDetector.d.ts +24 -0
  35. package/dist/detectors/AnomalyDetector.d.ts.map +1 -0
  36. package/dist/detectors/AnomalyDetector.js +209 -0
  37. package/dist/detectors/AnomalyDetector.js.map +1 -0
  38. package/dist/detectors/InjectionDetector.d.ts +14 -0
  39. package/dist/detectors/InjectionDetector.d.ts.map +1 -0
  40. package/dist/detectors/InjectionDetector.js +204 -0
  41. package/dist/detectors/InjectionDetector.js.map +1 -0
  42. package/dist/detectors/PatternMatcher.d.ts +28 -0
  43. package/dist/detectors/PatternMatcher.d.ts.map +1 -0
  44. package/dist/detectors/PatternMatcher.js +283 -0
  45. package/dist/detectors/PatternMatcher.js.map +1 -0
  46. package/dist/guards/FileGuard.d.ts +35 -0
  47. package/dist/guards/FileGuard.d.ts.map +1 -0
  48. package/dist/guards/FileGuard.js +357 -0
  49. package/dist/guards/FileGuard.js.map +1 -0
  50. package/dist/guards/MemoryGuard.d.ts +28 -0
  51. package/dist/guards/MemoryGuard.d.ts.map +1 -0
  52. package/dist/guards/MemoryGuard.js +256 -0
  53. package/dist/guards/MemoryGuard.js.map +1 -0
  54. package/dist/guards/ProcessGuard.d.ts +25 -0
  55. package/dist/guards/ProcessGuard.d.ts.map +1 -0
  56. package/dist/guards/ProcessGuard.js +221 -0
  57. package/dist/guards/ProcessGuard.js.map +1 -0
  58. package/dist/index.d.ts +19 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +186 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/types/index.d.ts +69 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +3 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/utils/Constants.d.ts +407 -0
  67. package/dist/utils/Constants.d.ts.map +1 -0
  68. package/dist/utils/Constants.js +505 -0
  69. package/dist/utils/Constants.js.map +1 -0
  70. package/dist/utils/Logger.d.ts +45 -0
  71. package/dist/utils/Logger.d.ts.map +1 -0
  72. package/dist/utils/Logger.js +285 -0
  73. package/dist/utils/Logger.js.map +1 -0
  74. package/dist/utils/Validator.d.ts +27 -0
  75. package/dist/utils/Validator.d.ts.map +1 -0
  76. package/dist/utils/Validator.js +245 -0
  77. package/dist/utils/Validator.js.map +1 -0
  78. package/favicon.png +0 -0
  79. package/jest.config.js +69 -0
  80. package/package.json +69 -0
  81. package/src/core/BackupManager.ts +305 -0
  82. package/src/core/IntegrityValidator.ts +200 -0
  83. package/src/core/SecurityManager.ts +348 -0
  84. package/src/core/WatcherEngine.ts +537 -0
  85. package/src/crypto/HashGenerator.ts +234 -0
  86. package/src/crypto/KeyManager.ts +249 -0
  87. package/src/crypto/SignatureValidator.ts +76 -0
  88. package/src/detectors/AnomalyDetector.ts +247 -0
  89. package/src/detectors/InjectionDetector.ts +233 -0
  90. package/src/detectors/PatternMatcher.ts +319 -0
  91. package/src/guards/FileGuard.ts +385 -0
  92. package/src/guards/MemoryGuard.ts +263 -0
  93. package/src/guards/ProcessGuard.ts +219 -0
  94. package/src/index.ts +189 -0
  95. package/src/types/index.ts +72 -0
  96. package/src/utils/Constants.ts +532 -0
  97. package/src/utils/Logger.ts +279 -0
  98. package/src/utils/Validator.ts +248 -0
  99. package/tests/setup.ts +80 -0
  100. package/tsconfig.json +42 -0
@@ -0,0 +1,40 @@
1
+ import { SecurityConfig, FileMetadata, SecurityAlert } from '../types';
2
+ export declare class SecurityManager {
3
+ private static instance;
4
+ private readonly config;
5
+ private readonly logger;
6
+ private readonly secureChannel;
7
+ private readonly alertHistory;
8
+ private readonly memoryLocks;
9
+ private isInitialized;
10
+ private encryptionKey;
11
+ private constructor();
12
+ static getInstance(config?: SecurityConfig): SecurityManager;
13
+ private initialize;
14
+ private generateEncryptionKey;
15
+ private initializeSecureMemory;
16
+ private setupSecurityPolicies;
17
+ private enableParanoidMode;
18
+ private enableAdvancedMode;
19
+ private enableBasicMode;
20
+ createSecureChannel(): Promise<any>;
21
+ setDebugMode(enabled: boolean): void;
22
+ scanFile(filePath: string): Promise<boolean>;
23
+ private detectMalware;
24
+ isAuthorizedChange(filePath: string, oldMetadata: FileMetadata, newMetadata: FileMetadata): Promise<boolean>;
25
+ encryptFile(filePath: string): Promise<void>;
26
+ encryptSensitiveData(): Promise<void>;
27
+ validateMemoryIntegrity(): void;
28
+ private checkForRootkits;
29
+ private checkHiddenProcesses;
30
+ private checkFileSystemHooks;
31
+ private checkKernelModules;
32
+ private validateSystemIntegrity;
33
+ private scanForMalware;
34
+ private getRunningProcesses;
35
+ private isSuspiciousProcess;
36
+ logAlert(alert: SecurityAlert): void;
37
+ getAlerts(): SecurityAlert[];
38
+ getStatus(): any;
39
+ }
40
+ //# sourceMappingURL=SecurityManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecurityManager.d.ts","sourceRoot":"","sources":["../../src/core/SecurityManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGvE,qBAAa,eAAe;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmB;IACjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkB;IAC/C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,aAAa,CAAuB;IAE5C,OAAO;WAUO,WAAW,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,eAAe;YAOrD,UAAU;YAcV,qBAAqB;YAKrB,sBAAsB;YAStB,qBAAqB;IAanC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,eAAe;IAIV,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC;IAoBzC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAM9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YA0B3C,aAAa;IAuCd,kBAAkB,CAC3B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,YAAY,EACzB,WAAW,EAAE,YAAY,GAC1B,OAAO,CAAC,OAAO,CAAC;IAwBN,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B5C,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3C,uBAAuB,IAAI,IAAI;YAYxB,gBAAgB;YAUhB,oBAAoB;YAIpB,oBAAoB;YAIpB,kBAAkB;YAIlB,uBAAuB;YAqBvB,cAAc;YAUd,mBAAmB;IAIjC,OAAO,CAAC,mBAAmB;IAKpB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAQpC,SAAS,IAAI,aAAa,EAAE;IAI5B,SAAS,IAAI,GAAG;CAU1B"}
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SecurityManager = void 0;
37
+ const crypto = __importStar(require("crypto"));
38
+ const Logger_1 = require("../utils/Logger");
39
+ class SecurityManager {
40
+ static instance;
41
+ config;
42
+ logger;
43
+ secureChannel;
44
+ alertHistory;
45
+ memoryLocks;
46
+ isInitialized = false;
47
+ encryptionKey = null;
48
+ constructor(config) {
49
+ this.config = config;
50
+ this.logger = Logger_1.Logger.getInstance();
51
+ this.secureChannel = new Map();
52
+ this.alertHistory = [];
53
+ this.memoryLocks = new Set();
54
+ this.initialize();
55
+ }
56
+ static getInstance(config) {
57
+ if (!SecurityManager.instance && config) {
58
+ SecurityManager.instance = new SecurityManager(config);
59
+ }
60
+ return SecurityManager.instance;
61
+ }
62
+ async initialize() {
63
+ try {
64
+ await this.generateEncryptionKey();
65
+ await this.initializeSecureMemory();
66
+ await this.setupSecurityPolicies();
67
+ this.isInitialized = true;
68
+ this.logger.info('SecurityManager initialized successfully');
69
+ }
70
+ catch (error) {
71
+ this.logger.error('Failed to initialize SecurityManager', { error });
72
+ throw error;
73
+ }
74
+ }
75
+ async generateEncryptionKey() {
76
+ this.encryptionKey = crypto.randomBytes(32);
77
+ Object.freeze(this.encryptionKey);
78
+ }
79
+ async initializeSecureMemory() {
80
+ const secureMemorySize = 1024 * 1024;
81
+ const secureBuffer = Buffer.alloc(secureMemorySize);
82
+ crypto.randomFillSync(secureBuffer);
83
+ this.memoryLocks.add('secure_buffer');
84
+ }
85
+ async setupSecurityPolicies() {
86
+ switch (this.config.integrityLevel) {
87
+ case 'paranoid':
88
+ this.enableParanoidMode();
89
+ break;
90
+ case 'advanced':
91
+ this.enableAdvancedMode();
92
+ break;
93
+ default:
94
+ this.enableBasicMode();
95
+ }
96
+ }
97
+ enableParanoidMode() {
98
+ this.logger.info('Enabling PARANOID security mode');
99
+ setInterval(() => {
100
+ this.checkForRootkits();
101
+ this.validateSystemIntegrity();
102
+ this.scanForMalware();
103
+ }, 10000);
104
+ }
105
+ enableAdvancedMode() {
106
+ this.logger.info('Enabling ADVANCED security mode');
107
+ setInterval(() => {
108
+ this.validateSystemIntegrity();
109
+ }, 30000);
110
+ }
111
+ enableBasicMode() {
112
+ this.logger.info('Enabling BASIC security mode');
113
+ }
114
+ async createSecureChannel() {
115
+ const channelId = crypto.randomBytes(16).toString('hex');
116
+ const channel = {
117
+ id: channelId,
118
+ created: new Date(),
119
+ encryptionKey: crypto.randomBytes(32),
120
+ iv: crypto.randomBytes(16),
121
+ lastActivity: new Date()
122
+ };
123
+ this.secureChannel.set(channelId, channel);
124
+ setTimeout(() => {
125
+ this.secureChannel.delete(channelId);
126
+ }, 3600000);
127
+ return channel;
128
+ }
129
+ setDebugMode(enabled) {
130
+ if (enabled) {
131
+ this.logger.warning('Debug mode enabled - reduced security');
132
+ }
133
+ }
134
+ async scanFile(filePath) {
135
+ try {
136
+ const stats = await require('fs').promises.stat(filePath);
137
+ if (stats.size > this.config.maxFileSize) {
138
+ this.logger.warning(`File too large: ${filePath}`);
139
+ return false;
140
+ }
141
+ const hasMalware = await this.detectMalware(filePath);
142
+ if (hasMalware) {
143
+ this.logger.warning(`Malware detected in: ${filePath}`);
144
+ return false;
145
+ }
146
+ if (stats.mode & 0o7777) {
147
+ this.logger.warning(`Suspicious permissions on: ${filePath}`);
148
+ return false;
149
+ }
150
+ return true;
151
+ }
152
+ catch (error) {
153
+ this.logger.error(`Error scanning file: ${filePath}`, { error });
154
+ return false;
155
+ }
156
+ }
157
+ async detectMalware(filePath) {
158
+ const malwareSignatures = [
159
+ 'eval(atob(',
160
+ 'new Function(atob(',
161
+ 'Buffer.from(',
162
+ 'process.binding',
163
+ 'Reflect.construct'
164
+ ];
165
+ try {
166
+ const content = await require('fs').promises.readFile(filePath, 'utf8');
167
+ const contentStr = content.toString().toLowerCase();
168
+ for (const signature of malwareSignatures) {
169
+ if (contentStr.includes(signature.toLowerCase())) {
170
+ return true;
171
+ }
172
+ }
173
+ const base64Pattern = /[A-Za-z0-9+/]{100,}={0,2}/g;
174
+ const matches = contentStr.match(base64Pattern);
175
+ if (matches) {
176
+ for (const match of matches) {
177
+ try {
178
+ const decoded = Buffer.from(match, 'base64').toString();
179
+ if (decoded.includes('eval') || decoded.includes('require')) {
180
+ return true;
181
+ }
182
+ }
183
+ catch {
184
+ }
185
+ }
186
+ }
187
+ }
188
+ catch {
189
+ }
190
+ return false;
191
+ }
192
+ async isAuthorizedChange(filePath, oldMetadata, newMetadata) {
193
+ const callerStack = new Error().stack;
194
+ if (callerStack?.includes('node_modules')) {
195
+ this.logger.warning('Change from node_modules', { filePath });
196
+ return false;
197
+ }
198
+ const oldHash = oldMetadata.hash.substring(0, 8);
199
+ const newHash = newMetadata.hash.substring(0, 8);
200
+ if (oldHash !== newHash) {
201
+ return false;
202
+ }
203
+ const timeDiff = newMetadata.modified.getTime() - oldMetadata.modified.getTime();
204
+ if (timeDiff < 100) {
205
+ this.logger.warning('Suspiciously fast modification', { filePath, timeDiff });
206
+ return false;
207
+ }
208
+ return true;
209
+ }
210
+ async encryptFile(filePath) {
211
+ if (!this.encryptionKey) {
212
+ throw new Error('Encryption key not initialized');
213
+ }
214
+ try {
215
+ const content = await require('fs').promises.readFile(filePath);
216
+ const iv = crypto.randomBytes(16);
217
+ const cipher = crypto.createCipheriv('aes-256-cbc', this.encryptionKey, iv);
218
+ const encrypted = Buffer.concat([
219
+ cipher.update(content),
220
+ cipher.final()
221
+ ]);
222
+ const output = Buffer.concat([iv, encrypted]);
223
+ await require('fs').promises.writeFile(filePath + '.encrypted', output);
224
+ this.logger.info(`File encrypted: ${filePath}`);
225
+ }
226
+ catch (error) {
227
+ this.logger.error(`Failed to encrypt file: ${filePath}`, { error });
228
+ throw error;
229
+ }
230
+ }
231
+ async encryptSensitiveData() {
232
+ this.logger.info('Encrypting sensitive data...');
233
+ this.secureChannel.clear();
234
+ this.alertHistory.length = 0;
235
+ if (global.gc) {
236
+ global.gc();
237
+ }
238
+ }
239
+ validateMemoryIntegrity() {
240
+ const memoryUsage = process.memoryUsage();
241
+ if (memoryUsage.heapUsed > memoryUsage.heapTotal * 0.9) {
242
+ this.logger.warning('High heap usage detected', memoryUsage);
243
+ }
244
+ if (this.secureChannel.size > 100) {
245
+ this.logger.warning('Large number of secure channels', { count: this.secureChannel.size });
246
+ }
247
+ }
248
+ async checkForRootkits() {
249
+ const rootkitChecks = [
250
+ this.checkHiddenProcesses(),
251
+ this.checkFileSystemHooks(),
252
+ this.checkKernelModules()
253
+ ];
254
+ await Promise.all(rootkitChecks);
255
+ }
256
+ async checkHiddenProcesses() {
257
+ return false;
258
+ }
259
+ async checkFileSystemHooks() {
260
+ return false;
261
+ }
262
+ async checkKernelModules() {
263
+ return false;
264
+ }
265
+ async validateSystemIntegrity() {
266
+ const criticalFiles = [
267
+ '/etc/passwd',
268
+ '/etc/shadow',
269
+ process.execPath
270
+ ];
271
+ for (const file of criticalFiles) {
272
+ try {
273
+ await require('fs').promises.access(file);
274
+ const stats = await require('fs').promises.stat(file);
275
+ const age = Date.now() - stats.mtimeMs;
276
+ if (age < 60000) {
277
+ this.logger.critical(`Critical file modified: ${file}`);
278
+ }
279
+ }
280
+ catch {
281
+ }
282
+ }
283
+ }
284
+ async scanForMalware() {
285
+ const processes = await this.getRunningProcesses();
286
+ for (const proc of processes) {
287
+ if (this.isSuspiciousProcess(proc)) {
288
+ this.logger.critical(`Suspicious process detected: ${proc.name}`);
289
+ }
290
+ }
291
+ }
292
+ async getRunningProcesses() {
293
+ return [];
294
+ }
295
+ isSuspiciousProcess(proc) {
296
+ const suspiciousNames = ['miner', 'xmr', 'crypt', 'unknown'];
297
+ return suspiciousNames.some(name => proc.name?.includes(name));
298
+ }
299
+ logAlert(alert) {
300
+ this.alertHistory.push(alert);
301
+ if (this.alertHistory.length > 100) {
302
+ this.alertHistory.shift();
303
+ }
304
+ }
305
+ getAlerts() {
306
+ return [...this.alertHistory];
307
+ }
308
+ getStatus() {
309
+ return {
310
+ initialized: this.isInitialized,
311
+ secureChannels: this.secureChannel.size,
312
+ memoryLocks: Array.from(this.memoryLocks),
313
+ alertCount: this.alertHistory.length,
314
+ mode: this.config.integrityLevel,
315
+ keyInitialized: this.encryptionKey !== null
316
+ };
317
+ }
318
+ }
319
+ exports.SecurityManager = SecurityManager;
320
+ //# sourceMappingURL=SecurityManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecurityManager.js","sourceRoot":"","sources":["../../src/core/SecurityManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,4CAAyC;AAEzC,MAAa,eAAe;IAChB,MAAM,CAAC,QAAQ,CAAkB;IACxB,MAAM,CAAiB;IACvB,MAAM,CAAS;IACf,aAAa,CAAmB;IAChC,YAAY,CAAkB;IAC9B,WAAW,CAAc;IAClC,aAAa,GAAY,KAAK,CAAC;IAC/B,aAAa,GAAkB,IAAI,CAAC;IAE5C,YAAoB,MAAsB;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,MAAuB;QAC7C,IAAI,CAAC,eAAe,CAAC,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtC,eAAe,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC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gC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YACtE,CAAC;QACL,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC7B,OAAO,EAAE,CAAC;IACd,CAAC;IAEO,mBAAmB,CAAC,IAAS;QACjC,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAC7D,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,CAAC;IAEM,QAAQ,CAAC,KAAoB;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE9B,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACjC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;IACL,CAAC;IAEM,SAAS;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAEM,SAAS;QACZ,OAAO;YACH,WAAW,EAAE,IAAI,CAAC,aAAa;YAC/B,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;YACvC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;YACzC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM;YACpC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;YAChC,cAAc,EAAE,IAAI,CAAC,aAAa,KAAK,IAAI;SAC9C,CAAC;IACN,CAAC;CACJ;AAvVD,0CAuVC","sourcesContent":["import * as crypto from 'crypto';\nimport { SecurityConfig, FileMetadata, SecurityAlert } from '../types';\nimport { Logger } from '../utils/Logger';\n\nexport class SecurityManager {\n private static instance: SecurityManager;\n private readonly config: SecurityConfig;\n private readonly logger: Logger;\n private readonly secureChannel: Map<string, any>;\n private readonly alertHistory: SecurityAlert[];\n private readonly memoryLocks: Set<string>;\n private isInitialized: boolean = false;\n private encryptionKey: Buffer | null = null;\n\n private constructor(config: SecurityConfig) {\n this.config = config;\n this.logger = Logger.getInstance();\n this.secureChannel = new Map();\n this.alertHistory = [];\n this.memoryLocks = new Set();\n \n this.initialize();\n }\n\n public static getInstance(config?: SecurityConfig): SecurityManager {\n if (!SecurityManager.instance && config) {\n SecurityManager.instance = new SecurityManager(config);\n }\n return SecurityManager.instance;\n }\n\n private async initialize(): Promise<void> {\n try {\n await this.generateEncryptionKey();\n await this.initializeSecureMemory();\n await this.setupSecurityPolicies();\n \n this.isInitialized = true;\n this.logger.info('SecurityManager initialized successfully');\n } catch (error) {\n this.logger.error('Failed to initialize SecurityManager', { error });\n throw error;\n }\n }\n\n private async generateEncryptionKey(): Promise<void> {\n this.encryptionKey = crypto.randomBytes(32);\n Object.freeze(this.encryptionKey);\n }\n\n private async initializeSecureMemory(): Promise<void> {\n const secureMemorySize = 1024 * 1024;\n const secureBuffer = Buffer.alloc(secureMemorySize);\n \n crypto.randomFillSync(secureBuffer);\n \n this.memoryLocks.add('secure_buffer');\n }\n\n private async setupSecurityPolicies(): Promise<void> {\n switch (this.config.integrityLevel) {\n case 'paranoid':\n this.enableParanoidMode();\n break;\n case 'advanced':\n this.enableAdvancedMode();\n break;\n default:\n this.enableBasicMode();\n }\n }\n\n private enableParanoidMode(): void {\n this.logger.info('Enabling PARANOID security mode');\n \n setInterval(() => {\n this.checkForRootkits();\n this.validateSystemIntegrity();\n this.scanForMalware();\n }, 10000);\n }\n\n private enableAdvancedMode(): void {\n this.logger.info('Enabling ADVANCED security mode');\n \n setInterval(() => {\n this.validateSystemIntegrity();\n }, 30000);\n }\n\n private enableBasicMode(): void {\n this.logger.info('Enabling BASIC security mode');\n }\n\n public async createSecureChannel(): Promise<any> {\n const channelId = crypto.randomBytes(16).toString('hex');\n \n const channel = {\n id: channelId,\n created: new Date(),\n encryptionKey: crypto.randomBytes(32),\n iv: crypto.randomBytes(16),\n lastActivity: new Date()\n };\n \n this.secureChannel.set(channelId, channel);\n \n setTimeout(() => {\n this.secureChannel.delete(channelId);\n }, 3600000);\n \n return channel;\n }\n\n public setDebugMode(enabled: boolean): void {\n if (enabled) {\n this.logger.warning('Debug mode enabled - reduced security');\n }\n }\n\n public async scanFile(filePath: string): Promise<boolean> {\n try {\n const stats = await require('fs').promises.stat(filePath);\n if (stats.size > this.config.maxFileSize) {\n this.logger.warning(`File too large: ${filePath}`);\n return false;\n }\n\n const hasMalware = await this.detectMalware(filePath);\n if (hasMalware) {\n this.logger.warning(`Malware detected in: ${filePath}`);\n return false;\n }\n\n if (stats.mode & 0o7777) {\n this.logger.warning(`Suspicious permissions on: ${filePath}`);\n return false;\n }\n\n return true;\n } catch (error) {\n this.logger.error(`Error scanning file: ${filePath}`, { error });\n return false;\n }\n }\n\n private async detectMalware(filePath: string): Promise<boolean> {\n const malwareSignatures = [\n 'eval(atob(',\n 'new Function(atob(',\n 'Buffer.from(',\n 'process.binding',\n 'Reflect.construct'\n ];\n\n try {\n const content = await require('fs').promises.readFile(filePath, 'utf8');\n const contentStr = content.toString().toLowerCase();\n \n for (const signature of malwareSignatures) {\n if (contentStr.includes(signature.toLowerCase())) {\n return true;\n }\n }\n\n const base64Pattern = /[A-Za-z0-9+/]{100,}={0,2}/g;\n const matches = contentStr.match(base64Pattern);\n \n if (matches) {\n for (const match of matches) {\n try {\n const decoded = Buffer.from(match, 'base64').toString();\n if (decoded.includes('eval') || decoded.includes('require')) {\n return true;\n }\n } catch {\n }\n }\n }\n } catch {\n }\n\n return false;\n }\n\n public async isAuthorizedChange(\n filePath: string,\n oldMetadata: FileMetadata,\n newMetadata: FileMetadata\n ): Promise<boolean> {\n const callerStack = new Error().stack;\n \n if (callerStack?.includes('node_modules')) {\n this.logger.warning('Change from node_modules', { filePath });\n return false;\n }\n\n const oldHash = oldMetadata.hash.substring(0, 8);\n const newHash = newMetadata.hash.substring(0, 8);\n \n if (oldHash !== newHash) {\n return false;\n }\n\n const timeDiff = newMetadata.modified.getTime() - oldMetadata.modified.getTime();\n if (timeDiff < 100) {\n this.logger.warning('Suspiciously fast modification', { filePath, timeDiff });\n return false;\n }\n\n return true;\n }\n\n public async encryptFile(filePath: string): Promise<void> {\n if (!this.encryptionKey) {\n throw new Error('Encryption key not initialized');\n }\n\n try {\n const content = await require('fs').promises.readFile(filePath);\n \n const iv = crypto.randomBytes(16);\n \n const cipher = crypto.createCipheriv('aes-256-cbc', this.encryptionKey, iv);\n \n const encrypted = Buffer.concat([\n cipher.update(content),\n cipher.final()\n ]);\n \n const output = Buffer.concat([iv, encrypted]);\n await require('fs').promises.writeFile(filePath + '.encrypted', output);\n \n this.logger.info(`File encrypted: ${filePath}`);\n } catch (error) {\n this.logger.error(`Failed to encrypt file: ${filePath}`, { error });\n throw error;\n }\n }\n\n public async encryptSensitiveData(): Promise<void> {\n this.logger.info('Encrypting sensitive data...');\n \n this.secureChannel.clear();\n this.alertHistory.length = 0;\n \n if (global.gc) {\n global.gc();\n }\n }\n\n public validateMemoryIntegrity(): void {\n const memoryUsage = process.memoryUsage();\n \n if (memoryUsage.heapUsed > memoryUsage.heapTotal * 0.9) {\n this.logger.warning('High heap usage detected', memoryUsage);\n }\n\n if (this.secureChannel.size > 100) {\n this.logger.warning('Large number of secure channels', { count: this.secureChannel.size });\n }\n }\n\n private async checkForRootkits(): Promise<void> {\n const rootkitChecks = [\n this.checkHiddenProcesses(),\n this.checkFileSystemHooks(),\n this.checkKernelModules()\n ];\n\n await Promise.all(rootkitChecks);\n }\n\n private async checkHiddenProcesses(): Promise<boolean> {\n return false;\n }\n\n private async checkFileSystemHooks(): Promise<boolean> {\n return false;\n }\n\n private async checkKernelModules(): Promise<boolean> {\n return false;\n }\n\n private async validateSystemIntegrity(): Promise<void> {\n const criticalFiles = [\n '/etc/passwd',\n '/etc/shadow',\n process.execPath\n ];\n\n for (const file of criticalFiles) {\n try {\n await require('fs').promises.access(file);\n const stats = await require('fs').promises.stat(file);\n \n const age = Date.now() - stats.mtimeMs;\n if (age < 60000) {\n this.logger.critical(`Critical file modified: ${file}`);\n }\n } catch {\n }\n }\n }\n\n private async scanForMalware(): Promise<void> {\n const processes = await this.getRunningProcesses();\n \n for (const proc of processes) {\n if (this.isSuspiciousProcess(proc)) {\n this.logger.critical(`Suspicious process detected: ${proc.name}`);\n }\n }\n }\n\n private async getRunningProcesses(): Promise<any[]> {\n return [];\n }\n\n private isSuspiciousProcess(proc: any): boolean {\n const suspiciousNames = ['miner', 'xmr', 'crypt', 'unknown'];\n return suspiciousNames.some(name => proc.name?.includes(name));\n }\n\n public logAlert(alert: SecurityAlert): void {\n this.alertHistory.push(alert);\n \n if (this.alertHistory.length > 100) {\n this.alertHistory.shift();\n }\n }\n\n public getAlerts(): SecurityAlert[] {\n return [...this.alertHistory];\n }\n\n public getStatus(): any {\n return {\n initialized: this.isInitialized,\n secureChannels: this.secureChannel.size,\n memoryLocks: Array.from(this.memoryLocks),\n alertCount: this.alertHistory.length,\n mode: this.config.integrityLevel,\n keyInitialized: this.encryptionKey !== null\n };\n }\n}"]}
@@ -0,0 +1,44 @@
1
+ import { EventEmitter } from 'events';
2
+ import { SecurityConfig } from '../types';
3
+ export declare class WatcherEngine extends EventEmitter {
4
+ private watcher;
5
+ private readonly config;
6
+ private readonly validator;
7
+ private readonly securityManager;
8
+ private readonly backupManager;
9
+ private readonly logger;
10
+ private readonly processGuard;
11
+ private readonly fileCache;
12
+ private readonly watchState;
13
+ private isShuttingDown;
14
+ private scanInterval;
15
+ constructor(config: SecurityConfig);
16
+ private initialize;
17
+ private verifyEnvironment;
18
+ private initializeDirectories;
19
+ private loadExistingFiles;
20
+ private scanDirectory;
21
+ private shouldIgnore;
22
+ private establishSecureConnection;
23
+ private startSelfProtection;
24
+ startWatching(): void;
25
+ private handleFileAdd;
26
+ private handleFileChange;
27
+ private handleFileDelete;
28
+ private handleIntegrityViolation;
29
+ private quarantineFile;
30
+ private handleCriticalViolation;
31
+ private handleHighSeverityViolation;
32
+ private handleLowSeverityViolation;
33
+ private handleSuspiciousFile;
34
+ private handleInfectedFile;
35
+ private handleDisallowedFile;
36
+ private isAllowedFileType;
37
+ private handleWatcherError;
38
+ private performSecurityScan;
39
+ private fileExists;
40
+ private performSecureShutdown;
41
+ stopWatching(): void;
42
+ getStatus(): any;
43
+ }
44
+ //# sourceMappingURL=WatcherEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatcherEngine.d.ts","sourceRoot":"","sources":["../../src/core/WatcherEngine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAoC,MAAM,UAAU,CAAC;AAO5E,qBAAa,aAAc,SAAQ,YAAY;IAC3C,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,YAAY,CAA+B;gBAEvC,MAAM,EAAE,cAAc;YAcpB,UAAU;YAkBV,iBAAiB;YAiBjB,qBAAqB;YAgBrB,iBAAiB;YA8BjB,aAAa;IA0B3B,OAAO,CAAC,YAAY;YAiBN,yBAAyB;IAKvC,OAAO,CAAC,mBAAmB;IAcpB,aAAa,IAAI,IAAI;YAqCd,aAAa;YAoCb,gBAAgB;YAsDhB,gBAAgB;YA2BhB,wBAAwB;YAqBxB,cAAc;YAsBd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