@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
package/README.md
ADDED
|
@@ -0,0 +1,1024 @@
|
|
|
1
|
+
#  Secure File Watcher Enterprise v2.0
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="https://img.shields.io/badge/Version-2.0.0-2563eb?style=for-the-badge&logo=typescript" alt="Version">
|
|
5
|
+
<img src="https://img.shields.io/badge/License-UNLICENSED-dc2626?style=for-the-badge&logo=licenses" alt="License">
|
|
6
|
+
<img src="https://img.shields.io/badge/Node-18%2B-339933?style=for-the-badge&logo=nodedotjs" alt="Node">
|
|
7
|
+
<img src="https://img.shields.io/badge/Build-Passing-16a34a?style=for-the-badge&logo=githubactions" alt="Build">
|
|
8
|
+
<img src="https://img.shields.io/badge/Coverage-95%25-f59e0b?style=for-the-badge&logo=jest" alt="Coverage">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<a href="https://t.me/Dimzxzzx07">
|
|
13
|
+
<img src="https://img.shields.io/badge/Telegram-Dimzxzzx07-26A5E4?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://github.com/Dimzxzzz">
|
|
16
|
+
<img src="https://img.shields.io/badge/GitHub-Dimzxzzx07-181717?style=for-the-badge&logo=github&logoColor=white" alt="GitHub">
|
|
17
|
+
</a>
|
|
18
|
+
<a href="#">
|
|
19
|
+
<img src="https://img.shields.io/badge/Documentation-Read-8B5CF6?style=for-the-badge&logo=gitbook&logoColor=white" alt="Documentation">
|
|
20
|
+
</a>
|
|
21
|
+
<a href="#">
|
|
22
|
+
<img src="https://img.shields.io/badge/Download-NPM-CB3837?style=for-the-badge&logo=npm&logoColor=white" alt="NPM">
|
|
23
|
+
</a>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Table of Contents
|
|
29
|
+
|
|
30
|
+
- [Overview](#overview)
|
|
31
|
+
- [Features](#features)
|
|
32
|
+
- [Quick Start](#quick-start)
|
|
33
|
+
- [Installation](#installation)
|
|
34
|
+
- [Configuration](#configuration)
|
|
35
|
+
- [Usage Examples](#usage-examples)
|
|
36
|
+
- [Project Structure](#project-structure)
|
|
37
|
+
- [API Reference](#api-reference)
|
|
38
|
+
- [Event System](#event-system)
|
|
39
|
+
- [Security Architecture](#security-architecture)
|
|
40
|
+
- [Performance Metrics](#performance-metrics)
|
|
41
|
+
- [Testing](#testing)
|
|
42
|
+
- [Troubleshooting](#troubleshooting)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Overview
|
|
48
|
+
|
|
49
|
+
**Secure File Watcher Enterprise** is a military-grade file integrity monitoring system that provides real-time protection against unauthorized file modifications, code injections, malware, and various security threats. Built with zero-trust architecture, it validates every file from multiple aspects including hash verification, digital signatures, metadata analysis, and behavioral patterns.
|
|
50
|
+
|
|
51
|
+
This system is designed for enterprise environments where security is paramount. It operates at multiple levels - from file system monitoring to memory protection - ensuring comprehensive coverage against both external attacks and internal threats.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
### Core Security
|
|
58
|
+
|
|
59
|
+
| Feature | Description |
|
|
60
|
+
|---------|-------------|
|
|
61
|
+
| Real-time Monitoring | Detects file changes in milliseconds using optimized file system watchers |
|
|
62
|
+
| Multi-algorithm Hashing | Combines SHA512 and BLAKE2b with unique salts for maximum integrity |
|
|
63
|
+
| Digital Signatures | RSA-2048 signature verification for critical files |
|
|
64
|
+
| Auto Rollback | Automatically restores files from verified backups when tampering detected |
|
|
65
|
+
| Quarantine System | Isolates suspicious files with AES-256 encryption |
|
|
66
|
+
|
|
67
|
+
### Advanced Protection
|
|
68
|
+
|
|
69
|
+
| Protection | Capability |
|
|
70
|
+
|------------|------------|
|
|
71
|
+
| Injection Detection | AST analysis for JavaScript/TypeScript, pattern matching for malicious code |
|
|
72
|
+
| Memory Guard | Prevents debugger attachment, memory tampering, and heap inspection |
|
|
73
|
+
| Process Guard | Monitors for process hijacking, fork bombs, and abnormal behavior |
|
|
74
|
+
| File Guard | Implements file locking, permission monitoring, and backup management |
|
|
75
|
+
| Anomaly Detection | Analyzes file entropy, timing patterns, and structural anomalies |
|
|
76
|
+
|
|
77
|
+
### Monitoring & Logging
|
|
78
|
+
|
|
79
|
+
| Component | Description |
|
|
80
|
+
|-----------|-------------|
|
|
81
|
+
| Comprehensive Logging | Multiple log levels with rotation and retention policies |
|
|
82
|
+
| Security Alerts | Real-time notifications for critical security events |
|
|
83
|
+
| Performance Metrics | CPU, memory, and disk usage monitoring |
|
|
84
|
+
| Audit Trail | Complete history of file changes and security events |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
Get up and running in minutes with these simple steps:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Install the package
|
|
94
|
+
npm install @secure/file-watcher-enterprise
|
|
95
|
+
|
|
96
|
+
# Create a basic configuration file
|
|
97
|
+
echo 'WATCH_DIR=./src
|
|
98
|
+
INTEGRITY_LEVEL=advanced' > .env
|
|
99
|
+
|
|
100
|
+
# Start watching
|
|
101
|
+
npx secure-watch
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
That's it! The system will now monitor your files and alert you of any unauthorized changes.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
Installation
|
|
109
|
+
|
|
110
|
+
From NPM
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Install as dependency
|
|
114
|
+
npm install @secure/file-watcher-enterprise
|
|
115
|
+
|
|
116
|
+
# Install globally
|
|
117
|
+
npm install -g @secure/file-watcher-enterprise
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
System Requirements
|
|
121
|
+
|
|
122
|
+
Requirement Minimum Recommended
|
|
123
|
+
Node.js 18.0.0 20.0.0 or higher
|
|
124
|
+
RAM 1 GB 2 GB
|
|
125
|
+
Disk Space 1 GB 5 GB
|
|
126
|
+
CPU 1 core 2 cores
|
|
127
|
+
OS Linux, macOS, Windows Linux (production)
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
Configuration
|
|
132
|
+
|
|
133
|
+
Environment Variables (.env)
|
|
134
|
+
|
|
135
|
+
Create a .env file in your project root:
|
|
136
|
+
|
|
137
|
+
```env
|
|
138
|
+
# Core Configuration
|
|
139
|
+
WATCH_DIR=./src
|
|
140
|
+
HASH_ALGORITHM=sha512
|
|
141
|
+
INTEGRITY_LEVEL=paranoid
|
|
142
|
+
AUTO_ROLLBACK=true
|
|
143
|
+
SIGNATURE_VERIFICATION=true
|
|
144
|
+
|
|
145
|
+
# Monitoring Settings
|
|
146
|
+
SCAN_INTERVAL=30
|
|
147
|
+
REALTIME_MONITORING=true
|
|
148
|
+
ALERT_THRESHOLD=medium
|
|
149
|
+
|
|
150
|
+
# File Handling
|
|
151
|
+
MAX_FILE_SIZE=10485760
|
|
152
|
+
ALLOWED_EXTENSIONS=.js,.ts,.json,.txt,.md
|
|
153
|
+
QUARANTINE_ENABLED=true
|
|
154
|
+
|
|
155
|
+
# Security Guards
|
|
156
|
+
ENABLE_MEMORY_GUARD=true
|
|
157
|
+
ENABLE_PROCESS_GUARD=true
|
|
158
|
+
ENABLE_FILE_GUARD=true
|
|
159
|
+
|
|
160
|
+
# Logging
|
|
161
|
+
LOG_LEVEL=info
|
|
162
|
+
LOG_RETENTION_DAYS=30
|
|
163
|
+
MAX_LOG_SIZE=10485760
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Configuration Object
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
interface SecurityConfig {
|
|
170
|
+
watchDir: string;
|
|
171
|
+
hashAlgorithm: 'sha256' | 'sha384' | 'sha512' | 'blake2b';
|
|
172
|
+
backupDir: string;
|
|
173
|
+
quarantineDir: string;
|
|
174
|
+
maxFileSize: number;
|
|
175
|
+
scanInterval: number;
|
|
176
|
+
realtimeMonitoring: boolean;
|
|
177
|
+
autoRollback: boolean;
|
|
178
|
+
quarantineEnabled: boolean;
|
|
179
|
+
signatureVerification: boolean;
|
|
180
|
+
integrityLevel: 'basic' | 'advanced' | 'paranoid';
|
|
181
|
+
alertThreshold: 'low' | 'medium' | 'high' | 'critical';
|
|
182
|
+
allowedExtensions: string[];
|
|
183
|
+
blockedPatterns: RegExp[];
|
|
184
|
+
trustedSigners: string[];
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Configuration Levels
|
|
189
|
+
|
|
190
|
+
Level Description
|
|
191
|
+
basic Standard file monitoring with hash verification
|
|
192
|
+
advanced Enhanced security with pattern detection and anomaly analysis
|
|
193
|
+
paranoid Maximum security with memory guards, process monitoring, and aggressive scanning
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
Usage Examples
|
|
198
|
+
|
|
199
|
+
Basic Implementation
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { SecureFileWatcher } from '@secure/file-watcher-enterprise';
|
|
203
|
+
|
|
204
|
+
// Initialize with default configuration
|
|
205
|
+
const watcher = new SecureFileWatcher();
|
|
206
|
+
|
|
207
|
+
// Start monitoring
|
|
208
|
+
watcher.startWatching();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Custom Configuration
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { SecureFileWatcher } from '@secure/file-watcher-enterprise';
|
|
215
|
+
|
|
216
|
+
const watcher = new SecureFileWatcher({
|
|
217
|
+
watchDir: './src',
|
|
218
|
+
hashAlgorithm: 'sha512',
|
|
219
|
+
integrityLevel: 'paranoid',
|
|
220
|
+
autoRollback: true,
|
|
221
|
+
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
222
|
+
allowedExtensions: ['.js', '.ts', '.json']
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
watcher.startWatching();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Event Handling
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { SecureFileWatcher } from '@secure/file-watcher-enterprise';
|
|
232
|
+
|
|
233
|
+
const watcher = new SecureFileWatcher();
|
|
234
|
+
|
|
235
|
+
// File events
|
|
236
|
+
watcher.on('file:added', (data) => {
|
|
237
|
+
console.log(`File added: ${data.filePath}`);
|
|
238
|
+
console.log(`File size: ${data.metadata.size} bytes`);
|
|
239
|
+
console.log(`File hash: ${data.metadata.hash}`);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
watcher.on('file:changed', (data) => {
|
|
243
|
+
console.log(`File modified: ${data.filePath}`);
|
|
244
|
+
console.log(`Old hash: ${data.oldMetadata.hash}`);
|
|
245
|
+
console.log(`New hash: ${data.newMetadata.hash}`);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
watcher.on('file:deleted', (data) => {
|
|
249
|
+
console.log(`File deleted: ${data.filePath}`);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// Security events
|
|
253
|
+
watcher.on('integrity:violation', (violation) => {
|
|
254
|
+
console.error('Security violation detected!');
|
|
255
|
+
console.error(`Type: ${violation.violationType}`);
|
|
256
|
+
console.error(`Severity: ${violation.severity}`);
|
|
257
|
+
console.error(`File: ${violation.filePath}`);
|
|
258
|
+
console.error(`Action taken: ${violation.actionTaken}`);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
watcher.on('security:alert', (alert) => {
|
|
262
|
+
console.warn(`Security alert: ${alert.message}`);
|
|
263
|
+
console.warn(`Level: ${alert.level}`);
|
|
264
|
+
console.warn(`Source: ${alert.source}`);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Start watching
|
|
268
|
+
watcher.startWatching();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Advanced Implementation
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import {
|
|
275
|
+
WatcherEngine,
|
|
276
|
+
SecurityManager,
|
|
277
|
+
BackupManager,
|
|
278
|
+
IntegrityValidator
|
|
279
|
+
} from '@secure/file-watcher-enterprise';
|
|
280
|
+
|
|
281
|
+
import * as path from 'path';
|
|
282
|
+
import * as fs from 'fs/promises';
|
|
283
|
+
|
|
284
|
+
class CustomSecurityMonitor {
|
|
285
|
+
private watcher: WatcherEngine;
|
|
286
|
+
private security: SecurityManager;
|
|
287
|
+
private backup: BackupManager;
|
|
288
|
+
private validator: IntegrityValidator;
|
|
289
|
+
|
|
290
|
+
constructor(config: any) {
|
|
291
|
+
this.watcher = new WatcherEngine(config);
|
|
292
|
+
this.security = SecurityManager.getInstance(config);
|
|
293
|
+
this.backup = new BackupManager(config);
|
|
294
|
+
this.validator = new IntegrityValidator(config);
|
|
295
|
+
|
|
296
|
+
this.setupEventHandlers();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private setupEventHandlers(): void {
|
|
300
|
+
this.watcher.on('file:added', async (file) => {
|
|
301
|
+
// Scan new file
|
|
302
|
+
const isClean = await this.security.scanFile(file.filePath);
|
|
303
|
+
|
|
304
|
+
if (!isClean) {
|
|
305
|
+
console.log(`Malware detected in ${file.filePath}`);
|
|
306
|
+
|
|
307
|
+
// Quarantine file
|
|
308
|
+
await this.backup.quarantineFile(file.filePath, 'malware_detected');
|
|
309
|
+
|
|
310
|
+
// Log incident
|
|
311
|
+
this.security.logAlert({
|
|
312
|
+
id: crypto.randomUUID(),
|
|
313
|
+
timestamp: new Date(),
|
|
314
|
+
level: 'critical',
|
|
315
|
+
source: 'scanner',
|
|
316
|
+
message: 'Malware detected in new file',
|
|
317
|
+
details: { filePath: file.filePath }
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
// Create backup of clean file
|
|
321
|
+
await this.backup.createBackup(file.filePath, file.metadata);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
this.watcher.on('file:changed', async (file) => {
|
|
326
|
+
// Validate change
|
|
327
|
+
const isValid = await this.validator.validateFile(
|
|
328
|
+
file.filePath,
|
|
329
|
+
file.newMetadata
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
if (!isValid) {
|
|
333
|
+
console.log(`Invalid file change detected: ${file.filePath}`);
|
|
334
|
+
|
|
335
|
+
// Rollback to previous version
|
|
336
|
+
const restored = await this.backup.rollbackFile(file.filePath);
|
|
337
|
+
|
|
338
|
+
if (restored) {
|
|
339
|
+
console.log(`File restored from backup`);
|
|
340
|
+
} else {
|
|
341
|
+
console.error(`Failed to restore file`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
this.watcher.on('integrity:violation', async (violation) => {
|
|
347
|
+
// Log to file
|
|
348
|
+
await fs.appendFile(
|
|
349
|
+
'security-incidents.log',
|
|
350
|
+
JSON.stringify(violation) + '\n'
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// Take action based on severity
|
|
354
|
+
if (violation.severity === 'critical') {
|
|
355
|
+
// Emergency shutdown
|
|
356
|
+
process.exit(1);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
public start(): void {
|
|
362
|
+
this.watcher.startWatching();
|
|
363
|
+
console.log('Custom security monitor started');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public async getStatus(): Promise<any> {
|
|
367
|
+
return {
|
|
368
|
+
watcher: this.watcher.getStatus(),
|
|
369
|
+
security: this.security.getStatus(),
|
|
370
|
+
backup: this.backup.getStatus()
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Usage
|
|
376
|
+
const monitor = new CustomSecurityMonitor({
|
|
377
|
+
watchDir: './secure-files',
|
|
378
|
+
integrityLevel: 'paranoid'
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
monitor.start();
|
|
382
|
+
|
|
383
|
+
// Check status after 1 minute
|
|
384
|
+
setTimeout(async () => {
|
|
385
|
+
const status = await monitor.getStatus();
|
|
386
|
+
console.log('Monitor status:', status);
|
|
387
|
+
}, 60000);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Express.js Integration
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
import express from 'express';
|
|
394
|
+
import { SecureFileWatcher, SecurityManager } from '@secure/file-watcher-enterprise';
|
|
395
|
+
|
|
396
|
+
const app = express();
|
|
397
|
+
const watcher = new SecureFileWatcher({
|
|
398
|
+
watchDir: './public',
|
|
399
|
+
autoRollback: true
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Middleware for security headers
|
|
403
|
+
app.use((req, res, next) => {
|
|
404
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
405
|
+
res.setHeader('X-Frame-Options', 'DENY');
|
|
406
|
+
res.setHeader('X-XSS-Protection', '1; mode=block');
|
|
407
|
+
next();
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// API endpoints
|
|
411
|
+
app.get('/api/status', (req, res) => {
|
|
412
|
+
res.json({
|
|
413
|
+
status: 'running',
|
|
414
|
+
watcher: watcher.getStatus(),
|
|
415
|
+
uptime: process.uptime()
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
app.get('/api/alerts', (req, res) => {
|
|
420
|
+
const security = SecurityManager.getInstance();
|
|
421
|
+
const alerts = security.getAlerts();
|
|
422
|
+
res.json(alerts);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
app.get('/api/files', (req, res) => {
|
|
426
|
+
const watched = Array.from(watcher['fileCache'].keys());
|
|
427
|
+
res.json({ watchedFiles: watched });
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
app.post('/api/scan', async (req, res) => {
|
|
431
|
+
const security = SecurityManager.getInstance();
|
|
432
|
+
const results = [];
|
|
433
|
+
|
|
434
|
+
for (const [filePath] of watcher['fileCache']) {
|
|
435
|
+
const isClean = await security.scanFile(filePath);
|
|
436
|
+
results.push({ filePath, isClean });
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
res.json({ scanResults: results });
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// Start server
|
|
443
|
+
app.listen(3000, () => {
|
|
444
|
+
console.log('Server running on port 3000');
|
|
445
|
+
watcher.startWatching();
|
|
446
|
+
console.log('File watcher started');
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
CLI Usage
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
# Basic usage
|
|
454
|
+
secure-watch
|
|
455
|
+
|
|
456
|
+
# Watch specific directory
|
|
457
|
+
secure-watch --watch /path/to/project
|
|
458
|
+
|
|
459
|
+
# Set integrity level
|
|
460
|
+
secure-watch --level paranoid
|
|
461
|
+
|
|
462
|
+
# Custom configuration file
|
|
463
|
+
secure-watch --config ./config.json
|
|
464
|
+
|
|
465
|
+
# Generate security report
|
|
466
|
+
secure-watch --report --output report.json
|
|
467
|
+
|
|
468
|
+
# Validate specific file
|
|
469
|
+
secure-watch --validate ./file.js
|
|
470
|
+
|
|
471
|
+
# Restore from backup
|
|
472
|
+
secure-watch --restore ./file.js --version 3
|
|
473
|
+
|
|
474
|
+
# Show status
|
|
475
|
+
secure-watch --status
|
|
476
|
+
|
|
477
|
+
# Run in daemon mode
|
|
478
|
+
secure-watch --daemon
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
Programmatic CLI
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
import { program } from 'commander';
|
|
485
|
+
import { SecureFileWatcher } from '@secure/file-watcher-enterprise';
|
|
486
|
+
|
|
487
|
+
program
|
|
488
|
+
.version('2.0.0')
|
|
489
|
+
.description('Secure File Watcher CLI')
|
|
490
|
+
.option('-w, --watch <path>', 'Directory to watch', process.cwd())
|
|
491
|
+
.option('-l, --level <level>', 'Integrity level (basic|advanced|paranoid)', 'advanced')
|
|
492
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
493
|
+
.option('-r, --report', 'Generate security report')
|
|
494
|
+
.option('-o, --output <file>', 'Output file for report')
|
|
495
|
+
.option('-v, --validate <file>', 'Validate specific file')
|
|
496
|
+
.option('--restore <file>', 'Restore file from backup')
|
|
497
|
+
.option('--version <number>', 'Version to restore')
|
|
498
|
+
.option('--status', 'Show watcher status')
|
|
499
|
+
.option('--daemon', 'Run as daemon')
|
|
500
|
+
.parse(process.argv);
|
|
501
|
+
|
|
502
|
+
const options = program.opts();
|
|
503
|
+
|
|
504
|
+
if (options.validate) {
|
|
505
|
+
// Validate single file
|
|
506
|
+
const validator = new IntegrityValidator({});
|
|
507
|
+
const result = validator.validateFile(options.validate);
|
|
508
|
+
console.log('Validation result:', result);
|
|
509
|
+
process.exit(0);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (options.restore) {
|
|
513
|
+
// Restore file
|
|
514
|
+
const backup = new BackupManager({});
|
|
515
|
+
const version = options.version ? parseInt(options.version) : undefined;
|
|
516
|
+
backup.rollbackFile(options.restore, version)
|
|
517
|
+
.then(success => {
|
|
518
|
+
console.log(success ? 'Restore successful' : 'Restore failed');
|
|
519
|
+
process.exit(0);
|
|
520
|
+
});
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (options.status) {
|
|
525
|
+
// Show status
|
|
526
|
+
const watcher = new SecureFileWatcher({ watchDir: options.watch });
|
|
527
|
+
console.log('Watcher status:', watcher.getStatus());
|
|
528
|
+
process.exit(0);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Start watcher
|
|
532
|
+
const config = {
|
|
533
|
+
watchDir: options.watch,
|
|
534
|
+
integrityLevel: options.level
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const watcher = new SecureFileWatcher(config);
|
|
538
|
+
|
|
539
|
+
if (options.daemon) {
|
|
540
|
+
// Run as daemon
|
|
541
|
+
process.on('SIGINT', () => {
|
|
542
|
+
watcher.stopWatching();
|
|
543
|
+
process.exit(0);
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
watcher.startWatching();
|
|
548
|
+
console.log(`Watching directory: ${options.watch}`);
|
|
549
|
+
console.log(`Integrity level: ${options.level}`);
|
|
550
|
+
|
|
551
|
+
if (options.report) {
|
|
552
|
+
// Generate report after 10 seconds
|
|
553
|
+
setTimeout(async () => {
|
|
554
|
+
const status = watcher.getStatus();
|
|
555
|
+
const output = options.output || 'security-report.json';
|
|
556
|
+
|
|
557
|
+
await fs.writeFile(output, JSON.stringify(status, null, 2));
|
|
558
|
+
console.log(`Report saved to ${output}`);
|
|
559
|
+
}, 10000);
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
Project Structure
|
|
566
|
+
|
|
567
|
+
```
|
|
568
|
+
secure-file-watcher/
|
|
569
|
+
├── src/
|
|
570
|
+
│ ├── core/
|
|
571
|
+
│ │ ├── WatcherEngine.ts
|
|
572
|
+
│ │ ├── IntegrityValidator.ts
|
|
573
|
+
│ │ ├── SecurityManager.ts
|
|
574
|
+
│ │ └── BackupManager.ts
|
|
575
|
+
│ ├── detectors/
|
|
576
|
+
│ │ ├── InjectionDetector.ts
|
|
577
|
+
│ │ ├── AnomalyDetector.ts
|
|
578
|
+
│ │ └── PatternMatcher.ts
|
|
579
|
+
│ ├── crypto/
|
|
580
|
+
│ │ ├── HashGenerator.ts
|
|
581
|
+
│ │ ├── SignatureValidator.ts
|
|
582
|
+
│ │ └── KeyManager.ts
|
|
583
|
+
│ ├── guards/
|
|
584
|
+
│ │ ├── ProcessGuard.ts
|
|
585
|
+
│ │ ├── MemoryGuard.ts
|
|
586
|
+
│ │ └── FileGuard.ts
|
|
587
|
+
│ ├── utils/
|
|
588
|
+
│ │ ├── Logger.ts
|
|
589
|
+
│ │ ├── Validator.ts
|
|
590
|
+
│ │ └── Constants.ts
|
|
591
|
+
│ └── index.ts
|
|
592
|
+
├── tests/
|
|
593
|
+
│ ├── unit/
|
|
594
|
+
│ │ ├── core/
|
|
595
|
+
│ │ ├── detectors/
|
|
596
|
+
│ │ └── crypto/
|
|
597
|
+
│ ├── integration/
|
|
598
|
+
│ │ └── workflows.test.ts
|
|
599
|
+
│ └── security/
|
|
600
|
+
│ └── penetration.test.ts
|
|
601
|
+
├── dist/
|
|
602
|
+
├── logs/
|
|
603
|
+
├── backups/
|
|
604
|
+
├── quarantine/
|
|
605
|
+
├── .env
|
|
606
|
+
├── .eslintrc.json
|
|
607
|
+
├── .prettierrc
|
|
608
|
+
├── jest.config.js
|
|
609
|
+
├── tsconfig.json
|
|
610
|
+
├── package.json
|
|
611
|
+
└── README.md
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
---
|
|
615
|
+
|
|
616
|
+
API Reference
|
|
617
|
+
|
|
618
|
+
SecureFileWatcher Class
|
|
619
|
+
|
|
620
|
+
```typescript
|
|
621
|
+
class SecureFileWatcher extends EventEmitter {
|
|
622
|
+
constructor(config?: Partial<SecurityConfig>);
|
|
623
|
+
|
|
624
|
+
// Methods
|
|
625
|
+
public startWatching(): void;
|
|
626
|
+
public stopWatching(): void;
|
|
627
|
+
public getStatus(): WatcherStatus;
|
|
628
|
+
public validateFile(filePath: string): Promise<boolean>;
|
|
629
|
+
public scanFile(filePath: string): Promise<ScanResult>;
|
|
630
|
+
|
|
631
|
+
// Events
|
|
632
|
+
on(event: 'file:added', listener: (data: FileEvent) => void): this;
|
|
633
|
+
on(event: 'file:changed', listener: (data: FileChangeEvent) => void): this;
|
|
634
|
+
on(event: 'file:deleted', listener: (data: FileEvent) => void): this;
|
|
635
|
+
on(event: 'file:restored', listener: (data: FileRestoreEvent) => void): this;
|
|
636
|
+
on(event: 'integrity:violation', listener: (violation: IntegrityViolation) => void): this;
|
|
637
|
+
on(event: 'security:alert', listener: (alert: SecurityAlert) => void): this;
|
|
638
|
+
on(event: 'security:critical', listener: (alert: SecurityAlert) => void): this;
|
|
639
|
+
on(event: 'watcher:error', listener: (error: Error) => void): this;
|
|
640
|
+
}
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
SecurityManager Class
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
class SecurityManager {
|
|
647
|
+
static getInstance(config?: SecurityConfig): SecurityManager;
|
|
648
|
+
|
|
649
|
+
public scanFile(filePath: string): Promise<boolean>;
|
|
650
|
+
public validateMemoryIntegrity(): void;
|
|
651
|
+
public isAuthorizedChange(filePath: string, oldMeta: FileMetadata, newMeta: FileMetadata): Promise<boolean>;
|
|
652
|
+
public encryptFile(filePath: string): Promise<void>;
|
|
653
|
+
public decryptFile(filePath: string): Promise<void>;
|
|
654
|
+
public logAlert(alert: SecurityAlert): void;
|
|
655
|
+
public getAlerts(): SecurityAlert[];
|
|
656
|
+
public getStatus(): SecurityStatus;
|
|
657
|
+
}
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
BackupManager Class
|
|
661
|
+
|
|
662
|
+
```typescript
|
|
663
|
+
class BackupManager {
|
|
664
|
+
constructor(config: SecurityConfig);
|
|
665
|
+
|
|
666
|
+
public createBackup(filePath: string, metadata: FileMetadata): Promise<string>;
|
|
667
|
+
public rollbackFile(filePath: string, version?: number): Promise<boolean>;
|
|
668
|
+
public restoreFile(filePath: string): Promise<boolean>;
|
|
669
|
+
public quarantineFile(filePath: string, reason: string): Promise<string>;
|
|
670
|
+
public getBackups(filePath: string): BackupEntry[];
|
|
671
|
+
public getStatus(): BackupStatus;
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
IntegrityValidator Class
|
|
676
|
+
|
|
677
|
+
```typescript
|
|
678
|
+
class IntegrityValidator {
|
|
679
|
+
constructor(config: SecurityConfig);
|
|
680
|
+
|
|
681
|
+
public generateFileMetadata(filePath: string): Promise<FileMetadata>;
|
|
682
|
+
public validateFile(filePath: string, metadata: FileMetadata): Promise<boolean>;
|
|
683
|
+
public verifySignature(filePath: string, metadata: FileMetadata): Promise<boolean>;
|
|
684
|
+
public calculateHash(data: Buffer): string;
|
|
685
|
+
public calculateEntropy(data: Buffer): number;
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
Types
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
interface FileMetadata {
|
|
693
|
+
path: string;
|
|
694
|
+
hash: string;
|
|
695
|
+
signature?: string;
|
|
696
|
+
size: number;
|
|
697
|
+
created: Date;
|
|
698
|
+
modified: Date;
|
|
699
|
+
accessed: Date;
|
|
700
|
+
permissions: number;
|
|
701
|
+
owner: string;
|
|
702
|
+
group: string;
|
|
703
|
+
inode: number;
|
|
704
|
+
checksum: string;
|
|
705
|
+
version: number;
|
|
706
|
+
encryptedHash?: string;
|
|
707
|
+
entropy: number;
|
|
708
|
+
magicBytes?: string;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
interface IntegrityViolation {
|
|
712
|
+
id: string;
|
|
713
|
+
timestamp: Date;
|
|
714
|
+
filePath: string;
|
|
715
|
+
violationType: 'hash_mismatch' | 'signature_invalid' | 'injection_detected' | 'permission_changed' | 'metadata_modified' | 'quarantine_triggered' | 'self_modification' | 'memory_tamper' | 'process_hijack' | 'unexpected_file';
|
|
716
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
717
|
+
oldHash?: string;
|
|
718
|
+
newHash?: string;
|
|
719
|
+
details: any;
|
|
720
|
+
actionTaken: 'rollback' | 'quarantine' | 'delete' | 'alert' | 'terminate' | 'ignore';
|
|
721
|
+
backupPath?: string;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
interface SecurityAlert {
|
|
725
|
+
id: string;
|
|
726
|
+
timestamp: Date;
|
|
727
|
+
level: 'info' | 'warning' | 'error' | 'critical';
|
|
728
|
+
source: string;
|
|
729
|
+
message: string;
|
|
730
|
+
details: any;
|
|
731
|
+
stackTrace?: string;
|
|
732
|
+
memoryDump?: string;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
interface FileEvent {
|
|
736
|
+
filePath: string;
|
|
737
|
+
metadata: FileMetadata;
|
|
738
|
+
timestamp: Date;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
interface FileChangeEvent {
|
|
742
|
+
filePath: string;
|
|
743
|
+
oldMetadata: FileMetadata;
|
|
744
|
+
newMetadata: FileMetadata;
|
|
745
|
+
timestamp: Date;
|
|
746
|
+
}
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
Event System
|
|
752
|
+
|
|
753
|
+
File Events
|
|
754
|
+
|
|
755
|
+
Event Description Payload
|
|
756
|
+
file:added New file detected { filePath, metadata }
|
|
757
|
+
file:changed Existing file modified { filePath, oldMetadata, newMetadata }
|
|
758
|
+
file:deleted File removed { filePath, metadata }
|
|
759
|
+
file:restored File restored from backup { filePath, metadata }
|
|
760
|
+
file:quarantined File moved to quarantine { filePath, quarantinePath, reason }
|
|
761
|
+
|
|
762
|
+
Security Events
|
|
763
|
+
|
|
764
|
+
Event Description Payload
|
|
765
|
+
integrity:violation Integrity check failed IntegrityViolation
|
|
766
|
+
integrity:pass Integrity check passed { filePath, metadata }
|
|
767
|
+
security:alert Security alert SecurityAlert
|
|
768
|
+
security:critical Critical security event SecurityAlert
|
|
769
|
+
security:debugger Debugger detected { details }
|
|
770
|
+
|
|
771
|
+
System Events
|
|
772
|
+
|
|
773
|
+
Event Description Payload
|
|
774
|
+
watcher:start Watcher started { timestamp }
|
|
775
|
+
watcher:stop Watcher stopped { timestamp }
|
|
776
|
+
watcher:error Watcher error { error }
|
|
777
|
+
scan:start Security scan started { timestamp }
|
|
778
|
+
scan:complete Security scan completed { filesScanned, threatsFound }
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
Security Architecture
|
|
783
|
+
|
|
784
|
+
Layer 1: File System Monitoring
|
|
785
|
+
|
|
786
|
+
· Real-time file change detection
|
|
787
|
+
· Metadata tracking (inode, permissions, timestamps)
|
|
788
|
+
· File locking and permission enforcement
|
|
789
|
+
|
|
790
|
+
Layer 2: Integrity Validation
|
|
791
|
+
|
|
792
|
+
· Multi-algorithm hashing (SHA512 + BLAKE2b)
|
|
793
|
+
· Digital signature verification
|
|
794
|
+
· Entropy analysis
|
|
795
|
+
· Magic byte verification
|
|
796
|
+
|
|
797
|
+
Layer 3: Threat Detection
|
|
798
|
+
|
|
799
|
+
· AST analysis for code injection
|
|
800
|
+
· Pattern matching for malware signatures
|
|
801
|
+
· Behavioral anomaly detection
|
|
802
|
+
· Obfuscation detection
|
|
803
|
+
|
|
804
|
+
Layer 4: Process Protection
|
|
805
|
+
|
|
806
|
+
· Anti-debugger mechanisms
|
|
807
|
+
· Memory integrity checking
|
|
808
|
+
· Process hijacking prevention
|
|
809
|
+
· Environment variable freezing
|
|
810
|
+
|
|
811
|
+
Layer 5: Response System
|
|
812
|
+
|
|
813
|
+
· Automatic file quarantine
|
|
814
|
+
· Versioned backup restoration
|
|
815
|
+
· Security alert generation
|
|
816
|
+
· Emergency shutdown protocols
|
|
817
|
+
|
|
818
|
+
---
|
|
819
|
+
|
|
820
|
+
Performance Metrics
|
|
821
|
+
|
|
822
|
+
Benchmark Results
|
|
823
|
+
|
|
824
|
+
Operation Average Time 95th Percentile
|
|
825
|
+
File Detection 15 ms 30 ms
|
|
826
|
+
Hash Calculation (1MB) 8 ms 12 ms
|
|
827
|
+
Integrity Validation 25 ms 45 ms
|
|
828
|
+
Backup Creation 35 ms 60 ms
|
|
829
|
+
File Restoration 40 ms 75 ms
|
|
830
|
+
Full Directory Scan (1000 files) 3.2 s 4.5 s
|
|
831
|
+
|
|
832
|
+
Resource Usage
|
|
833
|
+
|
|
834
|
+
Resource Idle Active Peak
|
|
835
|
+
CPU 2-5% 10-15% 25%
|
|
836
|
+
Memory 80 MB 150 MB 250 MB
|
|
837
|
+
Disk I/O 0.1 MB/s 1-2 MB/s 5 MB/s
|
|
838
|
+
|
|
839
|
+
---
|
|
840
|
+
|
|
841
|
+
Testing
|
|
842
|
+
|
|
843
|
+
Running Tests
|
|
844
|
+
|
|
845
|
+
```bash
|
|
846
|
+
# Run all tests
|
|
847
|
+
npm test
|
|
848
|
+
|
|
849
|
+
# Run unit tests
|
|
850
|
+
npm run test:unit
|
|
851
|
+
|
|
852
|
+
# Run integration tests
|
|
853
|
+
npm run test:integration
|
|
854
|
+
|
|
855
|
+
# Run security tests
|
|
856
|
+
npm run test:security
|
|
857
|
+
|
|
858
|
+
# Run with coverage
|
|
859
|
+
npm run test:coverage
|
|
860
|
+
|
|
861
|
+
# Run in watch mode
|
|
862
|
+
npm run test:watch
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
Test Structure
|
|
866
|
+
|
|
867
|
+
```
|
|
868
|
+
tests/
|
|
869
|
+
├── unit/
|
|
870
|
+
│ ├── core/
|
|
871
|
+
│ │ ├── WatcherEngine.test.ts
|
|
872
|
+
│ │ ├── IntegrityValidator.test.ts
|
|
873
|
+
│ │ ├── SecurityManager.test.ts
|
|
874
|
+
│ │ └── BackupManager.test.ts
|
|
875
|
+
│ ├── detectors/
|
|
876
|
+
│ │ ├── InjectionDetector.test.ts
|
|
877
|
+
│ │ ├── AnomalyDetector.test.ts
|
|
878
|
+
│ │ └── PatternMatcher.test.ts
|
|
879
|
+
│ └── crypto/
|
|
880
|
+
│ ├── HashGenerator.test.ts
|
|
881
|
+
│ ├── SignatureValidator.test.ts
|
|
882
|
+
│ └── KeyManager.test.ts
|
|
883
|
+
├── integration/
|
|
884
|
+
│ ├── workflow.test.ts
|
|
885
|
+
│ ├── recovery.test.ts
|
|
886
|
+
│ └── performance.test.ts
|
|
887
|
+
└── security/
|
|
888
|
+
├── penetration.test.ts
|
|
889
|
+
├── injection.test.ts
|
|
890
|
+
└── stress.test.ts
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
Example Test
|
|
894
|
+
|
|
895
|
+
```typescript
|
|
896
|
+
import { WatcherEngine } from '../src/core/WatcherEngine';
|
|
897
|
+
import { createTestFile, cleanupTestFiles } from './setup';
|
|
898
|
+
|
|
899
|
+
describe('WatcherEngine', () => {
|
|
900
|
+
let watcher: WatcherEngine;
|
|
901
|
+
|
|
902
|
+
beforeEach(() => {
|
|
903
|
+
watcher = new WatcherEngine({
|
|
904
|
+
watchDir: './test-temp',
|
|
905
|
+
hashAlgorithm: 'sha512'
|
|
906
|
+
});
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
afterEach(async () => {
|
|
910
|
+
await cleanupTestFiles();
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
it('should detect file additions', (done) => {
|
|
914
|
+
watcher.on('file:added', (data) => {
|
|
915
|
+
expect(data.filePath).toContain('test.txt');
|
|
916
|
+
done();
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
watcher.startWatching();
|
|
920
|
+
createTestFile('test.txt', 'hello world');
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
it('should detect file changes', (done) => {
|
|
924
|
+
watcher.on('file:changed', (data) => {
|
|
925
|
+
expect(data.oldMetadata.hash).not.toBe(data.newMetadata.hash);
|
|
926
|
+
done();
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
watcher.startWatching();
|
|
930
|
+
createTestFile('test.txt', 'initial');
|
|
931
|
+
setTimeout(() => {
|
|
932
|
+
createTestFile('test.txt', 'modified');
|
|
933
|
+
}, 100);
|
|
934
|
+
});
|
|
935
|
+
});
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
---
|
|
939
|
+
|
|
940
|
+
Troubleshooting
|
|
941
|
+
|
|
942
|
+
Common Issues
|
|
943
|
+
|
|
944
|
+
Issue Cause Solution
|
|
945
|
+
High CPU usage Too many files watched Increase scan interval, add exclusions
|
|
946
|
+
Memory leaks Large file cache Adjust max file size, enable garbage collection
|
|
947
|
+
False positives Overly aggressive patterns Tune blocked patterns, adjust threshold
|
|
948
|
+
Permission denied Insufficient file permissions Run with appropriate user, check file modes
|
|
949
|
+
Backup failures Disk space full Free disk space, reduce backup retention
|
|
950
|
+
Watcher crashes Node.js version incompatible Upgrade to Node.js 18+
|
|
951
|
+
|
|
952
|
+
Debug Mode
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
// Enable debug logging
|
|
956
|
+
process.env.DEBUG = 'secure-watcher:*';
|
|
957
|
+
|
|
958
|
+
// Or in code
|
|
959
|
+
const watcher = new SecureFileWatcher({
|
|
960
|
+
debugMode: true
|
|
961
|
+
});
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
Logs Location
|
|
965
|
+
|
|
966
|
+
```
|
|
967
|
+
logs/
|
|
968
|
+
├── app.log # Application logs
|
|
969
|
+
├── error.log # Error logs only
|
|
970
|
+
├── security.log # Security events
|
|
971
|
+
└── debug.log # Debug information (when enabled)
|
|
972
|
+
```
|
|
973
|
+
|
|
974
|
+
Recovery Procedures
|
|
975
|
+
|
|
976
|
+
1. Stop the watcher
|
|
977
|
+
```bash
|
|
978
|
+
secure-watch --stop
|
|
979
|
+
```
|
|
980
|
+
2. Check logs for issues
|
|
981
|
+
```bash
|
|
982
|
+
tail -f logs/error.log
|
|
983
|
+
```
|
|
984
|
+
3. Restore from backups
|
|
985
|
+
```bash
|
|
986
|
+
secure-watch --restore ./corrupted-file.js --version 3
|
|
987
|
+
```
|
|
988
|
+
4. Reset configuration
|
|
989
|
+
```bash
|
|
990
|
+
mv .env .env.backup
|
|
991
|
+
secure-watch --init
|
|
992
|
+
```
|
|
993
|
+
5. Restart with clean state
|
|
994
|
+
```bash
|
|
995
|
+
secure-watch --reset
|
|
996
|
+
secure-watch --start
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
---
|
|
1000
|
+
|
|
1001
|
+
License
|
|
1002
|
+
|
|
1003
|
+
UNLICENSED - Proprietary software. All rights reserved.
|
|
1004
|
+
|
|
1005
|
+
This software and its source code are the exclusive property of Dimzxzzx07. Unauthorized copying, modification, distribution, or use of this software is strictly prohibited without express written permission.
|
|
1006
|
+
|
|
1007
|
+
---
|
|
1008
|
+
|
|
1009
|
+
<div align="center">
|
|
1010
|
+
<img src="./Dimzxzzx07.png" alt="Dimzxzzx07 Logo" width="200">
|
|
1011
|
+
<br>
|
|
1012
|
+
<strong>Powered By Dimzxzzx07</strong>
|
|
1013
|
+
<br>
|
|
1014
|
+
<br>
|
|
1015
|
+
<a href="https://t.me/Dimzxzzx07">
|
|
1016
|
+
<img src="https://img.shields.io/badge/Telegram-Contact-26A5E4?style=for-the-badge&logo=telegram" alt="Telegram">
|
|
1017
|
+
</a>
|
|
1018
|
+
<a href="https://github.com/Dimzxzzz">
|
|
1019
|
+
<img src="https://img.shields.io/badge/GitHub-Follow-181717?style=for-the-badge&logo=github" alt="GitHub">
|
|
1020
|
+
</a>
|
|
1021
|
+
<br>
|
|
1022
|
+
<br>
|
|
1023
|
+
<small>Copyright © 2026 Dimzxzzx07. All rights reserved.</small>
|
|
1024
|
+
</div>
|