typescript-virtual-container 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/HONEYPOT.md +358 -0
- package/README.md +471 -16
- package/dist/SSHMimic/exec.d.ts.map +1 -1
- package/dist/SSHMimic/exec.js +8 -2
- package/dist/SSHMimic/index.d.ts +3 -1
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +21 -4
- package/dist/SSHMimic/sftp.d.ts +48 -0
- package/dist/SSHMimic/sftp.d.ts.map +1 -0
- package/dist/SSHMimic/sftp.js +595 -0
- package/dist/VirtualFileSystem/index.d.ts +8 -5
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +152 -154
- package/dist/VirtualShell/index.d.ts +8 -1
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +22 -5
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +7 -0
- package/dist/VirtualUserManager/index.d.ts +3 -1
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.js +34 -1
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +1 -0
- package/dist/honeypot.d.ts +132 -0
- package/dist/honeypot.d.ts.map +1 -0
- package/dist/honeypot.js +289 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/standalone.js +10 -1
- package/examples/README.md +210 -0
- package/examples/honeypot-audit.ts +180 -0
- package/examples/honeypot-export.ts +253 -0
- package/examples/honeypot-quickstart.ts +110 -0
- package/package.json +1 -1
- package/src/Honeypot/index.ts +422 -0
- package/src/SSHMimic/exec.ts +18 -12
- package/src/SSHMimic/index.ts +29 -8
- package/src/SSHMimic/sftp.ts +853 -0
- package/src/VirtualFileSystem/index.ts +167 -190
- package/src/VirtualShell/index.ts +25 -9
- package/src/VirtualShell/shell.ts +7 -0
- package/src/VirtualUserManager/index.ts +41 -3
- package/src/commands/exit.ts +1 -0
- package/src/index.ts +8 -1
- package/src/standalone.ts +11 -1
- package/tests/sftp.test.ts +319 -0
- package/tests/ssh-exec.test.ts +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,48 @@ The format is based on Keep a Changelog.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.5] - 2026-04-16
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `HoneyPot` auditing utility for tracking and auditing SSH/SFTP activity across virtual shell, filesystem, user manager, and server components.
|
|
14
|
+
- HoneyPot attaches event listeners to `VirtualShell`, `VirtualFileSystem`, `VirtualUserManager`, `SshMimic`, and `SftpMimic` for holistic activity capture.
|
|
15
|
+
- HoneyPot event tracking, statistics, anomaly detection, and audit log export support.
|
|
16
|
+
- Comprehensive HoneyPot documentation in `README.md` and dedicated example files.
|
|
17
|
+
- Added `examples/honeypot-quickstart.ts`, `examples/honeypot-audit.ts`, `examples/honeypot-export.ts`, and `examples/README.md`.
|
|
18
|
+
- Added `HONEYPOT.md` implementation guide for HoneyPot usage patterns and integrations.
|
|
19
|
+
|
|
20
|
+
## [1.1.4] - 2026-04-16
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- New SFTP server implementation (`SftpMimic`), exported as `VirtualSftpServer`.
|
|
25
|
+
- SFTP handlers for file/directory operations: `OPEN`, `READ`, `WRITE`, `FSTAT`, `CLOSE`, `OPENDIR`, `READDIR`, `STAT`, `LSTAT`, `SETSTAT`, `FSETSTAT`, `REALPATH`, `MKDIR`, `RMDIR`, `REMOVE`, `RENAME`.
|
|
26
|
+
- Home-directory confinement for SFTP sessions (`/home/<user>`) with path traversal blocking.
|
|
27
|
+
- Keyboard-interactive authentication support in SFTP in addition to password auth.
|
|
28
|
+
- Standalone runtime now starts both SSH and SFTP servers with a shared `VirtualShell`.
|
|
29
|
+
- New SFTP test suite covering authentication, read/write flows, system-user login, and traversal protection.
|
|
30
|
+
- **Event-Driven Integration**: Core classes now extend `EventEmitter` for full lifecycle visibility:
|
|
31
|
+
- `VirtualShell`: `initialized`, `command`, `session:start` events
|
|
32
|
+
- `VirtualFileSystem`: `file:read`, `file:write`, `dir:create`, `mirror:flush` events
|
|
33
|
+
- `VirtualUserManager`: `initialized`, `user:add`, `user:delete`, `session:register`, `session:unregister` events
|
|
34
|
+
- `SshMimic` & `SftpMimic`: `start`, `stop`, `auth:success`, `auth:failure`, `client:connect`, `client:disconnect` events
|
|
35
|
+
- New `HoneyPot` utility for tracking and auditing server activity via event listeners.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- `VirtualFileSystem` mirror strategy now uses `.vfs/mirror` directory storage as the persistence boundary.
|
|
40
|
+
- SSH and SFTP startup now explicitly wait for full shell/user initialization before accepting connections.
|
|
41
|
+
- SFTP `start()` returns the actual bound port (including when configured with port `0`).
|
|
42
|
+
- Relative SFTP request paths are resolved from the authenticated user home.
|
|
43
|
+
- `VirtualUserManager.initialize()` auto-creates the current system user (`$USER` / `$USERNAME`) for easier local auth flows.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- Added stronger error handling/logging for SFTP client/session/stream lifecycle events.
|
|
48
|
+
- Fixed flaky SFTP tests by isolating each test run with temporary VFS base paths and deterministic cleanup.
|
|
49
|
+
- Fixed `ssh-exec` test timeout by resolving the mocked exec stream completion correctly.
|
|
50
|
+
|
|
9
51
|
## [1.0.6...1.0.8] - 2026-04-15
|
|
10
52
|
|
|
11
53
|
Too much refactor to list.
|
package/HONEYPOT.md
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# HoneyPot Implementation Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The `HoneyPot` class is a comprehensive auditing and event tracking utility that monitors all activity across your virtual environment. It provides real-time event logging, statistics collection, and anomaly detection.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
`HoneyPot` is included in the main `typescript-virtual-container` package:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install typescript-virtual-container
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then import it:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { HoneyPot } from "typescript-virtual-container";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Setup
|
|
22
|
+
|
|
23
|
+
### Step 1: Create Your Environment
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import {
|
|
27
|
+
VirtualSshServer,
|
|
28
|
+
VirtualShell,
|
|
29
|
+
HoneyPot,
|
|
30
|
+
} from "typescript-virtual-container";
|
|
31
|
+
|
|
32
|
+
// Create shell and SSH server
|
|
33
|
+
const shell = new VirtualShell("my-environment");
|
|
34
|
+
const ssh = new VirtualSshServer({ port: 2222, shell });
|
|
35
|
+
await ssh.start();
|
|
36
|
+
|
|
37
|
+
// Get references to key components
|
|
38
|
+
const users = ssh.getUsers()!;
|
|
39
|
+
const vfs = ssh.getVfs()!;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Step 2: Initialize HoneyPot
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Create HoneyPot with optional log size limit
|
|
46
|
+
const honeypot = new HoneyPot(5000); // Keep last 5000 entries
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Step 3: Attach to Components
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Attach HoneyPot to all components
|
|
53
|
+
// Now all events are automatically tracked
|
|
54
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Core Operations
|
|
58
|
+
|
|
59
|
+
### Collecting Statistics
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const stats = honeypot.getStats();
|
|
63
|
+
|
|
64
|
+
console.log(`Successful logins: ${stats.authSuccesses}`);
|
|
65
|
+
console.log(`Failed logins: ${stats.authFailures}`);
|
|
66
|
+
console.log(`Commands executed: ${stats.commands}`);
|
|
67
|
+
console.log(`File operations: ${stats.fileWrites + stats.fileReads}`);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Retrieving Audit Logs
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// Get all entries
|
|
74
|
+
const allEntries = honeypot.getAuditLog();
|
|
75
|
+
|
|
76
|
+
// Filter by event type
|
|
77
|
+
const authFailures = honeypot.getAuditLog("auth:failure");
|
|
78
|
+
|
|
79
|
+
// Filter by source component
|
|
80
|
+
const sshEvents = honeypot.getAuditLog(undefined, "SshMimic");
|
|
81
|
+
|
|
82
|
+
// Combined filter
|
|
83
|
+
const sshAuthEvents = honeypot.getAuditLog("auth:success", "SshMimic");
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Getting Recent Events
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Last 10 events (default)
|
|
90
|
+
const recent10 = honeypot.getRecent();
|
|
91
|
+
|
|
92
|
+
// Last 100 events
|
|
93
|
+
const recent100 = honeypot.getRecent(100);
|
|
94
|
+
|
|
95
|
+
// Process events
|
|
96
|
+
recent100.forEach((entry) => {
|
|
97
|
+
console.log(`[${entry.timestamp}] ${entry.source}: ${entry.type}`);
|
|
98
|
+
console.log(` Details: ${JSON.stringify(entry.details)}`);
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Detecting Anomalies
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const anomalies = honeypot.detectAnomalies();
|
|
106
|
+
|
|
107
|
+
anomalies.forEach((anomaly) => {
|
|
108
|
+
console.log(`Severity: ${anomaly.severity}`);
|
|
109
|
+
console.log(`Type: ${anomaly.type}`);
|
|
110
|
+
console.log(`Message: ${anomaly.message}`);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Severity levels: "low", "medium", "high"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Common Patterns
|
|
117
|
+
|
|
118
|
+
### Pattern 1: Real-Time Monitoring
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
async function monitorAuthAttempts() {
|
|
122
|
+
const honeypot = new HoneyPot();
|
|
123
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
124
|
+
|
|
125
|
+
// Monitor continuously
|
|
126
|
+
setInterval(() => {
|
|
127
|
+
const stats = honeypot.getStats();
|
|
128
|
+
|
|
129
|
+
if (stats.authFailures > 10) {
|
|
130
|
+
console.log("🚨 High number of failed auth attempts!");
|
|
131
|
+
const failures = honeypot.getAuditLog("auth:failure");
|
|
132
|
+
console.log(failures.map((f) => f.details.username));
|
|
133
|
+
}
|
|
134
|
+
}, 5000); // Check every 5 seconds
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Pattern 2: Post-Execution Analysis
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
async function runTestAndAnalyze() {
|
|
142
|
+
const shell = new VirtualShell("test-env");
|
|
143
|
+
const ssh = new VirtualSshServer({ port: 2222, shell });
|
|
144
|
+
await ssh.start();
|
|
145
|
+
|
|
146
|
+
const honeypot = new HoneyPot();
|
|
147
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
148
|
+
|
|
149
|
+
// ... run your tests/operations ...
|
|
150
|
+
|
|
151
|
+
// Generate report
|
|
152
|
+
const report = {
|
|
153
|
+
executedAt: new Date().toISOString(),
|
|
154
|
+
statistics: honeypot.getStats(),
|
|
155
|
+
anomalies: honeypot.detectAnomalies(),
|
|
156
|
+
allEvents: honeypot.getAuditLog(),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return report;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Pattern 3: Security Analysis by User
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
function analyzeUserActivity(honeypot, username) {
|
|
167
|
+
// Get all events related to this user
|
|
168
|
+
const userEvents = honeypot
|
|
169
|
+
.getAuditLog()
|
|
170
|
+
.filter((entry) => entry.details.username === username);
|
|
171
|
+
|
|
172
|
+
const analysis = {
|
|
173
|
+
totalActions: userEvents.length,
|
|
174
|
+
fileWrites: userEvents.filter(
|
|
175
|
+
(e) => e.type === "file:write",
|
|
176
|
+
).length,
|
|
177
|
+
failedAuthAttempts: userEvents.filter(
|
|
178
|
+
(e) => e.type === "auth:failure",
|
|
179
|
+
).length,
|
|
180
|
+
commands: userEvents.filter((e) => e.type === "command").length,
|
|
181
|
+
timeline: userEvents.map((e) => ({
|
|
182
|
+
time: e.timestamp,
|
|
183
|
+
action: e.type,
|
|
184
|
+
details: e.details,
|
|
185
|
+
})),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return analysis;
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Pattern 4: Compliance Export
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
function generateComplianceReport(honeypot) {
|
|
196
|
+
const timestamp = new Date().toISOString();
|
|
197
|
+
const stats = honeypot.getStats();
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
reportDate: timestamp,
|
|
201
|
+
auditTrail: {
|
|
202
|
+
totalEvents: stats.authAttempts + stats.commands,
|
|
203
|
+
authenticationEvents: {
|
|
204
|
+
attempts: stats.authAttempts,
|
|
205
|
+
successes: stats.authSuccesses,
|
|
206
|
+
failures: stats.authFailures,
|
|
207
|
+
},
|
|
208
|
+
commandExecution: {
|
|
209
|
+
total: stats.commands,
|
|
210
|
+
fileOperations: stats.fileWrites + stats.fileReads,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
anomalyDetection: honeypot.detectAnomalies(),
|
|
214
|
+
detailedLog: honeypot.getAuditLog(),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Event Types
|
|
220
|
+
|
|
221
|
+
### Authentication Events
|
|
222
|
+
|
|
223
|
+
- `auth:success` - User authenticated successfully
|
|
224
|
+
- `auth:failure` - Authentication failed
|
|
225
|
+
|
|
226
|
+
### File System Events
|
|
227
|
+
|
|
228
|
+
- `file:read` - File read operation
|
|
229
|
+
- `file:write` - File write operation
|
|
230
|
+
- `dir:create` - Directory created
|
|
231
|
+
|
|
232
|
+
### User Management Events
|
|
233
|
+
|
|
234
|
+
- `user:add` - User account created
|
|
235
|
+
- `user:delete` - User account deleted
|
|
236
|
+
|
|
237
|
+
### Session Events
|
|
238
|
+
|
|
239
|
+
- `session:register` - Session started
|
|
240
|
+
- `session:unregister` - Session ended
|
|
241
|
+
|
|
242
|
+
### Command Execution
|
|
243
|
+
|
|
244
|
+
- `command` - Command executed
|
|
245
|
+
|
|
246
|
+
## Integration Examples
|
|
247
|
+
|
|
248
|
+
### With a Database
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
const honeypot = new HoneyPot();
|
|
252
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
253
|
+
|
|
254
|
+
// Later, export to database
|
|
255
|
+
async function exportToDatabase() {
|
|
256
|
+
const entries = honeypot.getAuditLog();
|
|
257
|
+
|
|
258
|
+
for (const entry of entries) {
|
|
259
|
+
await db.collection("audit_logs").insertOne({
|
|
260
|
+
timestamp: entry.timestamp,
|
|
261
|
+
type: entry.type,
|
|
262
|
+
source: entry.source,
|
|
263
|
+
details: entry.details,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### With a Logging Service
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
const honeypot = new HoneyPot();
|
|
273
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
274
|
+
|
|
275
|
+
// Export to external logging
|
|
276
|
+
const report = honeypot.getRecent(1000);
|
|
277
|
+
await loggingService.send({
|
|
278
|
+
environment: "production",
|
|
279
|
+
auditTrail: report,
|
|
280
|
+
timestamp: new Date().toISOString(),
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### With Monitoring/Alerting
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
const honeypot = new HoneyPot();
|
|
288
|
+
honeypot.attach(shell, vfs, users, ssh);
|
|
289
|
+
|
|
290
|
+
// Check for anomalies periodically
|
|
291
|
+
setInterval(() => {
|
|
292
|
+
const anomalies = honeypot.detectAnomalies();
|
|
293
|
+
|
|
294
|
+
anomalies.forEach((a) => {
|
|
295
|
+
if (a.severity === "high") {
|
|
296
|
+
alerting.triggerAlert({
|
|
297
|
+
type: a.type,
|
|
298
|
+
message: a.message,
|
|
299
|
+
timestamp: new Date().toISOString(),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}, 10000);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Performance Considerations
|
|
307
|
+
|
|
308
|
+
- HoneyPot maintains an in-memory buffer with configurable max size
|
|
309
|
+
- Older entries are automatically trimmed when limit is reached
|
|
310
|
+
- All operations are O(1) or O(n) where n is reasonable
|
|
311
|
+
- Statistics computation is cached and efficient
|
|
312
|
+
- For long-running processes, consider periodic exports and resets
|
|
313
|
+
|
|
314
|
+
## Cleanup and Reset
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
// Clear all logs and reset statistics
|
|
318
|
+
honeypot.reset();
|
|
319
|
+
|
|
320
|
+
// Continues to listen for new events after reset
|
|
321
|
+
// Useful for clearing after each test phase
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Best Practices
|
|
325
|
+
|
|
326
|
+
1. **Initialize Early**: Attach HoneyPot right after creating components
|
|
327
|
+
2. **Export Regularly**: Don't rely solely on in-memory storage
|
|
328
|
+
3. **Monitor Continuously**: Use periodic checks for real-time monitoring
|
|
329
|
+
4. **Archive Audit Trails**: Save audit logs for compliance/forensics
|
|
330
|
+
5. **Set Appropriate Log Size**: Balance memory usage with data retention
|
|
331
|
+
6. **Use Filters**: Filter large logs by type or source for analysis
|
|
332
|
+
7. **Automate Anomaly Response**: Set up automated responses to detected anomalies
|
|
333
|
+
|
|
334
|
+
## Troubleshooting
|
|
335
|
+
|
|
336
|
+
### No events recorded?
|
|
337
|
+
|
|
338
|
+
- Ensure `honeypot.attach()` is called after all components are initialized
|
|
339
|
+
- Verify that actual operations are being performed (commands, file ops, etc.)
|
|
340
|
+
- Check that components extend EventEmitter (they should by default)
|
|
341
|
+
|
|
342
|
+
### Memory growing?
|
|
343
|
+
|
|
344
|
+
- Reduce `maxLogSize` in the constructor
|
|
345
|
+
- Call `honeypot.reset()` between test phases
|
|
346
|
+
- Export logs periodically to external storage
|
|
347
|
+
|
|
348
|
+
### Missing specific events?
|
|
349
|
+
|
|
350
|
+
- Check the exact event name in the events list
|
|
351
|
+
- Use `honeypot.getAuditLog()` to verify events exist
|
|
352
|
+
- Filter by source and type to narrow down search
|
|
353
|
+
|
|
354
|
+
## See Also
|
|
355
|
+
|
|
356
|
+
- [API Reference](../README.md#honeypot-auditing--event-tracking)
|
|
357
|
+
- [Example 8: Security Auditing](../README.md#example-8-security-auditing-with-honeypot)
|
|
358
|
+
- [Examples Directory](./README.md)
|