typescript-virtual-container 1.5.3 → 1.5.4

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 (365) hide show
  1. package/README.md +43 -23
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/SSHMimic/executor.js +23 -5
  4. package/dist/VirtualPackageManager/index.js +10 -0
  5. package/dist/commands/basename.d.ts +13 -0
  6. package/dist/commands/basename.js +45 -0
  7. package/dist/commands/file.d.ts +8 -0
  8. package/dist/commands/file.js +57 -0
  9. package/dist/commands/fun.d.ts +32 -0
  10. package/dist/commands/fun.js +172 -0
  11. package/dist/commands/ifconfig.d.ts +7 -0
  12. package/dist/commands/ifconfig.js +52 -0
  13. package/dist/commands/last.d.ts +13 -0
  14. package/dist/commands/last.js +68 -0
  15. package/dist/commands/manuals-bundle.js +598 -6
  16. package/dist/commands/registry.js +24 -2
  17. package/dist/commands/runtime.js +22 -2
  18. package/dist/commands/sh.js +5 -0
  19. package/dist/commands/tput.d.ts +13 -0
  20. package/dist/commands/tput.js +76 -0
  21. package/dist/commands/w.d.ts +7 -0
  22. package/dist/commands/w.js +38 -0
  23. package/dist/utils/expand.d.ts +12 -0
  24. package/dist/utils/expand.js +84 -0
  25. package/package.json +9 -3
  26. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -50
  27. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -31
  28. package/.github/dependabot.yml +0 -27
  29. package/.github/pull_request_template.md +0 -21
  30. package/.github/workflows/create-pull-request.yml +0 -85
  31. package/.github/workflows/publish.yml +0 -25
  32. package/.github/workflows/test-battery.yml +0 -102
  33. package/.vscode/settings.json +0 -20
  34. package/CODE_OF_CONDUCT.md +0 -39
  35. package/CONTRIBUTING.md +0 -59
  36. package/HONEYPOT.md +0 -358
  37. package/SECURITY.md +0 -33
  38. package/benchmark-results.txt +0 -40
  39. package/benchmark-virtualshell.ts +0 -88
  40. package/biome.json +0 -37
  41. package/build.js +0 -22
  42. package/builds/fortune-nyx-v1.5.3-directbash-k6.1.0.mjs +0 -1764
  43. package/builds/fortune-nyx-v1.5.3-ssh-nosftp.js +0 -1764
  44. package/builds/fortune-nyx-v1.5.3-ssh.cjs +0 -1765
  45. package/builds/fortune-nyx-v1.5.3-web.min.js +0 -17036
  46. package/bun.lock +0 -244
  47. package/docs/.nojekyll +0 -1
  48. package/docs/app.js +0 -1751
  49. package/docs/assets/hierarchy.js +0 -1
  50. package/docs/assets/highlight.css +0 -162
  51. package/docs/assets/icons.js +0 -18
  52. package/docs/assets/icons.svg +0 -1
  53. package/docs/assets/main.js +0 -60
  54. package/docs/assets/navigation.js +0 -1
  55. package/docs/assets/search.js +0 -1
  56. package/docs/assets/style.css +0 -1633
  57. package/docs/classes/HoneyPot.html +0 -31
  58. package/docs/classes/IdleManager.html +0 -162
  59. package/docs/classes/SshClient.html +0 -66
  60. package/docs/classes/VirtualFileSystem.html +0 -279
  61. package/docs/classes/VirtualPackageManager.html +0 -63
  62. package/docs/classes/VirtualSftpServer.html +0 -169
  63. package/docs/classes/VirtualShell.html +0 -285
  64. package/docs/classes/VirtualSshServer.html +0 -182
  65. package/docs/classes/VirtualUserManager.html +0 -276
  66. package/docs/demo.html +0 -82
  67. package/docs/functions/assertDiff.html +0 -6
  68. package/docs/functions/diffSnapshots.html +0 -7
  69. package/docs/functions/formatDiff.html +0 -6
  70. package/docs/functions/getArg.html +0 -13
  71. package/docs/functions/getFlag.html +0 -15
  72. package/docs/functions/ifFlag.html +0 -11
  73. package/docs/hierarchy.html +0 -1
  74. package/docs/index.html +0 -1869
  75. package/docs/interfaces/AuditLogEntry.html +0 -6
  76. package/docs/interfaces/CommandContext.html +0 -22
  77. package/docs/interfaces/CommandResult.html +0 -26
  78. package/docs/interfaces/ExecStream.html +0 -11
  79. package/docs/interfaces/HoneyPotStats.html +0 -16
  80. package/docs/interfaces/IdleManagerOptions.html +0 -7
  81. package/docs/interfaces/InstalledPackage.html +0 -20
  82. package/docs/interfaces/NanoEditorSession.html +0 -8
  83. package/docs/interfaces/PackageDefinition.html +0 -30
  84. package/docs/interfaces/PackageFile.html +0 -8
  85. package/docs/interfaces/PasswordChallenge.html +0 -16
  86. package/docs/interfaces/RemoveOptions.html +0 -4
  87. package/docs/interfaces/ShellEnv.html +0 -6
  88. package/docs/interfaces/ShellModule.html +0 -14
  89. package/docs/interfaces/ShellProperties.html +0 -14
  90. package/docs/interfaces/ShellStream.html +0 -11
  91. package/docs/interfaces/SudoChallenge.html +0 -24
  92. package/docs/interfaces/VfsBaseNode.html +0 -12
  93. package/docs/interfaces/VfsDiff.html +0 -10
  94. package/docs/interfaces/VfsDiffEntry.html +0 -6
  95. package/docs/interfaces/VfsDiffModified.html +0 -10
  96. package/docs/interfaces/VfsDirectoryNode.html +0 -15
  97. package/docs/interfaces/VfsFileNode.html +0 -17
  98. package/docs/interfaces/VfsOptions.html +0 -26
  99. package/docs/interfaces/VfsSnapshot.html +0 -3
  100. package/docs/interfaces/VfsSnapshotBaseNode.html +0 -8
  101. package/docs/interfaces/VfsSnapshotDirectoryNode.html +0 -10
  102. package/docs/interfaces/VfsSnapshotFileNode.html +0 -12
  103. package/docs/interfaces/VirtualActiveSession.html +0 -12
  104. package/docs/interfaces/VirtualSftpServerOptions.html +0 -7
  105. package/docs/interfaces/VirtualShellVfsLike.html +0 -15
  106. package/docs/interfaces/VirtualShellVfsOptions.html +0 -3
  107. package/docs/interfaces/WriteFileOptions.html +0 -6
  108. package/docs/media/LICENSE +0 -21
  109. package/docs/modules.html +0 -1
  110. package/docs/types/ArgParseOptions.html +0 -4
  111. package/docs/types/CommandMode.html +0 -2
  112. package/docs/types/CommandOutcome.html +0 -2
  113. package/docs/types/IdleState.html +0 -1
  114. package/docs/types/VfsNodeStats.html +0 -2
  115. package/docs/types/VfsNodeType.html +0 -2
  116. package/docs/types/VfsPersistenceMode.html +0 -5
  117. package/docs/types/VfsSnapshotNode.html +0 -2
  118. package/examples/README.md +0 -288
  119. package/examples/app.js +0 -1751
  120. package/examples/app.ts +0 -299
  121. package/examples/build.js +0 -27
  122. package/examples/demo.html +0 -33
  123. package/examples/honeypot-audit.ts +0 -180
  124. package/examples/honeypot-export.ts +0 -253
  125. package/examples/honeypot-quickstart.ts +0 -110
  126. package/examples/index.html +0 -82
  127. package/examples/server.js +0 -55
  128. package/polyfills/buffer.js +0 -117
  129. package/polyfills/node_child_process/index.js +0 -2
  130. package/polyfills/node_crypto/index.js +0 -167
  131. package/polyfills/node_events/index.js +0 -9
  132. package/polyfills/node_fs/index.js +0 -202
  133. package/polyfills/node_fs/promises.js +0 -4
  134. package/polyfills/node_os/index.js +0 -9
  135. package/polyfills/node_path/index.js +0 -28
  136. package/polyfills/node_vm/index.js +0 -7
  137. package/polyfills/node_zlib/index.js +0 -3
  138. package/polyfills/process.js +0 -14
  139. package/polyfills/ssh2/index.js +0 -75
  140. package/scripts/build-all.mjs +0 -226
  141. package/scripts/build-names.mjs +0 -43
  142. package/scripts/generate-manuals-bundle.mjs +0 -49
  143. package/scripts/postinstall.js +0 -42
  144. package/scripts/publish-package.sh +0 -70
  145. package/src/Honeypot/index.ts +0 -457
  146. package/src/SSHClient/index.ts +0 -270
  147. package/src/SSHMimic/exec.ts +0 -49
  148. package/src/SSHMimic/executor.ts +0 -251
  149. package/src/SSHMimic/hostKey.ts +0 -21
  150. package/src/SSHMimic/index.ts +0 -337
  151. package/src/SSHMimic/loginBanner.ts +0 -36
  152. package/src/SSHMimic/loginFormat.ts +0 -10
  153. package/src/SSHMimic/prompt.ts +0 -14
  154. package/src/SSHMimic/sftp.ts +0 -883
  155. package/src/VirtualFileSystem/binaryPack.ts +0 -258
  156. package/src/VirtualFileSystem/index.ts +0 -1193
  157. package/src/VirtualFileSystem/internalTypes.ts +0 -43
  158. package/src/VirtualFileSystem/journal.ts +0 -171
  159. package/src/VirtualFileSystem/path.ts +0 -74
  160. package/src/VirtualPackageManager/index.ts +0 -996
  161. package/src/VirtualShell/idleManager.ts +0 -137
  162. package/src/VirtualShell/index.ts +0 -475
  163. package/src/VirtualShell/shell.ts +0 -700
  164. package/src/VirtualShell/shellParser.ts +0 -285
  165. package/src/VirtualUserManager/index.ts +0 -758
  166. package/src/bun.d.ts +0 -1
  167. package/src/commands/adduser.ts +0 -103
  168. package/src/commands/alias.ts +0 -69
  169. package/src/commands/apt.ts +0 -233
  170. package/src/commands/awk.ts +0 -168
  171. package/src/commands/base64.ts +0 -29
  172. package/src/commands/cat.ts +0 -52
  173. package/src/commands/cd.ts +0 -25
  174. package/src/commands/chmod.ts +0 -85
  175. package/src/commands/clear.ts +0 -15
  176. package/src/commands/command-helpers.ts +0 -286
  177. package/src/commands/cp.ts +0 -83
  178. package/src/commands/curl.ts +0 -147
  179. package/src/commands/cut.ts +0 -36
  180. package/src/commands/date.ts +0 -30
  181. package/src/commands/declare.ts +0 -49
  182. package/src/commands/deluser.ts +0 -98
  183. package/src/commands/df.ts +0 -23
  184. package/src/commands/diff.ts +0 -43
  185. package/src/commands/dpkg.ts +0 -180
  186. package/src/commands/du.ts +0 -56
  187. package/src/commands/echo.ts +0 -58
  188. package/src/commands/env.ts +0 -23
  189. package/src/commands/exit.ts +0 -18
  190. package/src/commands/export.ts +0 -34
  191. package/src/commands/find.ts +0 -68
  192. package/src/commands/free.ts +0 -47
  193. package/src/commands/grep.ts +0 -116
  194. package/src/commands/groups.ts +0 -19
  195. package/src/commands/gzip.ts +0 -88
  196. package/src/commands/head.ts +0 -52
  197. package/src/commands/help.ts +0 -152
  198. package/src/commands/helpers.ts +0 -234
  199. package/src/commands/history.ts +0 -34
  200. package/src/commands/hostname.ts +0 -14
  201. package/src/commands/htop.ts +0 -20
  202. package/src/commands/id.ts +0 -19
  203. package/src/commands/index.ts +0 -9
  204. package/src/commands/kill.ts +0 -19
  205. package/src/commands/ln.ts +0 -71
  206. package/src/commands/ls.ts +0 -243
  207. package/src/commands/lsb-release.ts +0 -63
  208. package/src/commands/man.ts +0 -31
  209. package/src/commands/manuals/adduser.txt +0 -11
  210. package/src/commands/manuals/apt-cache.txt +0 -12
  211. package/src/commands/manuals/apt.txt +0 -20
  212. package/src/commands/manuals/awk.txt +0 -13
  213. package/src/commands/manuals/cat.txt +0 -14
  214. package/src/commands/manuals/cd.txt +0 -16
  215. package/src/commands/manuals/chmod.txt +0 -16
  216. package/src/commands/manuals/clear.txt +0 -10
  217. package/src/commands/manuals/cp.txt +0 -10
  218. package/src/commands/manuals/curl.txt +0 -20
  219. package/src/commands/manuals/date.txt +0 -14
  220. package/src/commands/manuals/declare.txt +0 -12
  221. package/src/commands/manuals/deluser.txt +0 -10
  222. package/src/commands/manuals/df.txt +0 -10
  223. package/src/commands/manuals/dpkg-query.txt +0 -11
  224. package/src/commands/manuals/dpkg.txt +0 -14
  225. package/src/commands/manuals/du.txt +0 -11
  226. package/src/commands/manuals/echo.txt +0 -11
  227. package/src/commands/manuals/false.txt +0 -10
  228. package/src/commands/manuals/find.txt +0 -11
  229. package/src/commands/manuals/free.txt +0 -12
  230. package/src/commands/manuals/grep.txt +0 -13
  231. package/src/commands/manuals/groups.txt +0 -10
  232. package/src/commands/manuals/gzip.txt +0 -11
  233. package/src/commands/manuals/head.txt +0 -10
  234. package/src/commands/manuals/help.txt +0 -11
  235. package/src/commands/manuals/history.txt +0 -11
  236. package/src/commands/manuals/hostname.txt +0 -10
  237. package/src/commands/manuals/id.txt +0 -10
  238. package/src/commands/manuals/kill.txt +0 -13
  239. package/src/commands/manuals/ls.txt +0 -20
  240. package/src/commands/manuals/lsb_release.txt +0 -14
  241. package/src/commands/manuals/mkdir.txt +0 -10
  242. package/src/commands/manuals/mv.txt +0 -10
  243. package/src/commands/manuals/nano.txt +0 -11
  244. package/src/commands/manuals/neofetch.txt +0 -10
  245. package/src/commands/manuals/node.txt +0 -13
  246. package/src/commands/manuals/npm.txt +0 -13
  247. package/src/commands/manuals/npx.txt +0 -13
  248. package/src/commands/manuals/passwd.txt +0 -11
  249. package/src/commands/manuals/ping.txt +0 -10
  250. package/src/commands/manuals/printf.txt +0 -11
  251. package/src/commands/manuals/ps.txt +0 -10
  252. package/src/commands/manuals/pwd.txt +0 -10
  253. package/src/commands/manuals/python3.txt +0 -13
  254. package/src/commands/manuals/readlink.txt +0 -10
  255. package/src/commands/manuals/return.txt +0 -10
  256. package/src/commands/manuals/rm.txt +0 -10
  257. package/src/commands/manuals/sed.txt +0 -11
  258. package/src/commands/manuals/set.txt +0 -11
  259. package/src/commands/manuals/shift.txt +0 -10
  260. package/src/commands/manuals/sleep.txt +0 -10
  261. package/src/commands/manuals/sort.txt +0 -12
  262. package/src/commands/manuals/source.txt +0 -11
  263. package/src/commands/manuals/ssh.txt +0 -11
  264. package/src/commands/manuals/stat.txt +0 -10
  265. package/src/commands/manuals/su.txt +0 -13
  266. package/src/commands/manuals/sudo.txt +0 -11
  267. package/src/commands/manuals/tail.txt +0 -10
  268. package/src/commands/manuals/tar.txt +0 -19
  269. package/src/commands/manuals/tee.txt +0 -10
  270. package/src/commands/manuals/test.txt +0 -11
  271. package/src/commands/manuals/touch.txt +0 -11
  272. package/src/commands/manuals/tr.txt +0 -10
  273. package/src/commands/manuals/trap.txt +0 -10
  274. package/src/commands/manuals/true.txt +0 -10
  275. package/src/commands/manuals/type.txt +0 -10
  276. package/src/commands/manuals/uname.txt +0 -12
  277. package/src/commands/manuals/uniq.txt +0 -12
  278. package/src/commands/manuals/unset.txt +0 -10
  279. package/src/commands/manuals/uptime.txt +0 -11
  280. package/src/commands/manuals/wc.txt +0 -12
  281. package/src/commands/manuals/wget.txt +0 -12
  282. package/src/commands/manuals/which.txt +0 -10
  283. package/src/commands/manuals/whoami.txt +0 -10
  284. package/src/commands/manuals/xargs.txt +0 -10
  285. package/src/commands/manuals-bundle.ts +0 -898
  286. package/src/commands/mkdir.ts +0 -31
  287. package/src/commands/mv.ts +0 -50
  288. package/src/commands/nano.ts +0 -38
  289. package/src/commands/neofetch.ts +0 -53
  290. package/src/commands/node.ts +0 -341
  291. package/src/commands/npm.ts +0 -132
  292. package/src/commands/passwd.ts +0 -50
  293. package/src/commands/ping.ts +0 -32
  294. package/src/commands/printf.ts +0 -129
  295. package/src/commands/ps.ts +0 -58
  296. package/src/commands/pwd.ts +0 -9
  297. package/src/commands/python.ts +0 -2229
  298. package/src/commands/read.ts +0 -46
  299. package/src/commands/registry.ts +0 -249
  300. package/src/commands/rm.ts +0 -42
  301. package/src/commands/runtime.ts +0 -421
  302. package/src/commands/sed.ts +0 -68
  303. package/src/commands/seq.ts +0 -43
  304. package/src/commands/set.ts +0 -29
  305. package/src/commands/sh.ts +0 -467
  306. package/src/commands/shift.ts +0 -63
  307. package/src/commands/sleep.ts +0 -20
  308. package/src/commands/sort.ts +0 -46
  309. package/src/commands/source.ts +0 -52
  310. package/src/commands/stat.ts +0 -61
  311. package/src/commands/su.ts +0 -72
  312. package/src/commands/sudo.ts +0 -76
  313. package/src/commands/tail.ts +0 -53
  314. package/src/commands/tar.ts +0 -102
  315. package/src/commands/tee.ts +0 -36
  316. package/src/commands/test.ts +0 -137
  317. package/src/commands/touch.ts +0 -28
  318. package/src/commands/tr.ts +0 -70
  319. package/src/commands/tree.ts +0 -20
  320. package/src/commands/true.ts +0 -27
  321. package/src/commands/type.ts +0 -48
  322. package/src/commands/uname.ts +0 -29
  323. package/src/commands/uniq.ts +0 -39
  324. package/src/commands/unset.ts +0 -17
  325. package/src/commands/uptime.ts +0 -54
  326. package/src/commands/wc.ts +0 -55
  327. package/src/commands/wget.ts +0 -148
  328. package/src/commands/which.ts +0 -37
  329. package/src/commands/who.ts +0 -25
  330. package/src/commands/whoami.ts +0 -14
  331. package/src/commands/xargs.ts +0 -31
  332. package/src/index.ts +0 -67
  333. package/src/modules/linuxRootfs.ts +0 -1961
  334. package/src/modules/neofetch.ts +0 -358
  335. package/src/modules/shellInteractive.ts +0 -57
  336. package/src/modules/shellRuntime.ts +0 -76
  337. package/src/self-standalone.ts +0 -542
  338. package/src/standalone-wo-sftp.ts +0 -38
  339. package/src/standalone.ts +0 -72
  340. package/src/types/commands.ts +0 -146
  341. package/src/types/pipeline.ts +0 -52
  342. package/src/types/streams.ts +0 -32
  343. package/src/types/tar-stream.d.ts +0 -38
  344. package/src/types/vfs.ts +0 -98
  345. package/src/utils/expand.ts +0 -491
  346. package/src/utils/perfLogger.ts +0 -72
  347. package/src/utils/tokenize.ts +0 -98
  348. package/src/utils/vfsDiff.ts +0 -275
  349. package/tests/command-helpers.test.ts +0 -116
  350. package/tests/commands-admin-net.test.ts +0 -441
  351. package/tests/commands-advanced.test.ts +0 -456
  352. package/tests/commands-core.test.ts +0 -562
  353. package/tests/commands-missing.test.ts +0 -570
  354. package/tests/commands-specific-units.test.ts +0 -327
  355. package/tests/commands-text-sys.test.ts +0 -445
  356. package/tests/expand.test.ts +0 -170
  357. package/tests/helpers.test.ts +0 -97
  358. package/tests/new-features.test.ts +0 -1036
  359. package/tests/parser-executor.test.ts +0 -37
  360. package/tests/sftp.test.ts +0 -323
  361. package/tests/ssh-exec.test.ts +0 -45
  362. package/tests/test-helper.ts +0 -79
  363. package/tests/users.test.ts +0 -86
  364. package/tsconfig.json +0 -49
  365. package/typedoc.json +0 -47
@@ -1,253 +0,0 @@
1
- /**
2
- * HoneyPot Advanced: Audit Export & Analysis
3
- *
4
- * Shows how to export audit data for external analysis, storage,
5
- * or integration with security monitoring systems.
6
- *
7
- * Run with: bun run examples/honeypot-export.ts
8
- */
9
-
10
- import * as fs from "node:fs";
11
- import {
12
- HoneyPot,
13
- SshClient,
14
- VirtualShell,
15
- VirtualSshServer,
16
- } from "../src/index";
17
-
18
- interface AuditReport {
19
- timestamp: string;
20
- environment: string;
21
- durationMs: number;
22
- summary: {
23
- totalEvents: number;
24
- totalUsers: number;
25
- totalCommands: number;
26
- failedAuthAttempts: number;
27
- };
28
- statistics: Record<string, number>;
29
- anomalies: Array<{
30
- type: string;
31
- severity: string;
32
- message: string;
33
- }>;
34
- timeline: Array<{
35
- time: string;
36
- event: string;
37
- user?: string;
38
- details: Record<string, unknown>;
39
- }>;
40
- }
41
-
42
- async function generateAuditReport() {
43
- const startTime = Date.now();
44
-
45
- console.log("📊 HoneyPot Advanced: Generating Audit Report\n");
46
-
47
- // Setup
48
- const shell = new VirtualShell("audit-lab");
49
- const ssh = new VirtualSshServer({ port: 2222, shell });
50
- await ssh.start();
51
-
52
- const users = shell.getUsers()!;
53
- const vfs = shell.getVfs()!;
54
-
55
- const honeypot = new HoneyPot(5000);
56
- honeypot.attach(shell, vfs, users, ssh);
57
-
58
- console.log("Running simulated workload...\n");
59
-
60
- // Simulate various user activities
61
- await users.addUser("analyst", "pass123");
62
- await users.addUser("developer", "pass456");
63
- await users.removeSudoer("developer");
64
-
65
- // Analyst activities (authorized)
66
- const analyst = new SshClient(shell, "analyst");
67
- await analyst.mkdir("/data/reports", true);
68
- await analyst.writeFile(
69
- "/data/reports/analysis.txt",
70
- "Security analysis report",
71
- );
72
- await analyst.ls("/data/reports");
73
-
74
- // Developer activities
75
- const dev = new SshClient(shell, "developer");
76
- await dev.mkdir("/code/project", true);
77
- await dev.writeFile("/code/project/main.ts", "export function main() {}");
78
-
79
- // Some failed operations (tracked)
80
- try {
81
- await dev.readFile("/etc/shadow"); // Will fail
82
- } catch {
83
- // Ignored
84
- }
85
-
86
- try {
87
- await dev.writeFile("/root/.bashrc", "malicious"); // Will fail
88
- } catch {
89
- // Ignored
90
- }
91
-
92
- // Get final duration
93
- const duration = Date.now() - startTime;
94
-
95
- console.log("Generating audit report...\n");
96
-
97
- // Build comprehensive audit report
98
- const stats = honeypot.getStats();
99
- const anomalies = honeypot.detectAnomalies();
100
- const auditLog = honeypot.getAuditLog();
101
-
102
- const report: AuditReport = {
103
- timestamp: new Date().toISOString(),
104
- environment: "audit-lab",
105
- durationMs: duration,
106
-
107
- summary: {
108
- totalEvents: auditLog.length,
109
- totalUsers: stats.userCreated,
110
- totalCommands: stats.commands,
111
- failedAuthAttempts: stats.authFailures,
112
- },
113
-
114
- statistics: {
115
- authAttempts: stats.authAttempts,
116
- authSuccesses: stats.authSuccesses,
117
- authFailures: stats.authFailures,
118
- commandsExecuted: stats.commands,
119
- fileReads: stats.fileReads,
120
- fileWrites: stats.fileWrites,
121
- sessionsStarted: stats.sessionStarts,
122
- sessionsEnded: stats.sessionEnds,
123
- usersCreated: stats.userCreated,
124
- usersDeleted: stats.userDeleted,
125
- clientConnects: stats.clientConnects,
126
- clientDisconnects: stats.clientDisconnects,
127
- },
128
-
129
- anomalies: anomalies.map((a) => ({
130
- type: a.type,
131
- severity: a.severity,
132
- message: a.message,
133
- })),
134
-
135
- timeline: auditLog.map((entry) => ({
136
- time: entry.timestamp,
137
- event: `${entry.source}:${entry.type}`,
138
- user: (entry.details.username as string) || undefined,
139
- details: entry.details,
140
- })),
141
- };
142
-
143
- // Display summary
144
- console.log("📋 Audit Report Summary\n");
145
- console.log(` Environment: ${report.environment}`);
146
- console.log(` Generated: ${report.timestamp}`);
147
- console.log(` Duration: ${report.durationMs}ms\n`);
148
-
149
- console.log("📊 Statistics:");
150
- console.log(` • Total events: ${report.summary.totalEvents}`);
151
- console.log(` • Total users: ${report.summary.totalUsers}`);
152
- console.log(` • Commands executed: ${report.summary.totalCommands}`);
153
- console.log(
154
- ` • Failed auth attempts: ${report.summary.failedAuthAttempts}\n`,
155
- );
156
-
157
- // Display anomalies if any
158
- if (report.anomalies.length > 0) {
159
- console.log("⚠️ Anomalies:");
160
- report.anomalies.forEach((a) => {
161
- console.log(` • [${a.severity}] ${a.type}`);
162
- console.log(` ${a.message}`);
163
- });
164
- console.log();
165
- }
166
-
167
- // Export to JSON file
168
- const reportPath = "./audit_report.json";
169
- fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
170
- console.log(`✅ Report exported to: ${reportPath}\n`);
171
-
172
- // Export CSV for spreadsheet analysis
173
- const csvPath = "./audit_events.csv";
174
- const csvHeader = "Timestamp,Source,Event,User,Details\n";
175
- const csvRows = report.timeline
176
- .map((entry) => {
177
- const details = JSON.stringify(entry.details).replace(/"/g, '""');
178
- return `"${entry.time}","${entry.event.split(":")[0]}","${
179
- entry.event.split(":")[1]
180
- }","${entry.user || ""}","${details}"`;
181
- })
182
- .join("\n");
183
-
184
- fs.writeFileSync(csvPath, csvHeader + csvRows);
185
- console.log(`✅ CSV export to: ${csvPath}\n`);
186
-
187
- // Generate summary stats file
188
- const statsPath = "./audit_stats.json";
189
- fs.writeFileSync(
190
- statsPath,
191
- JSON.stringify(
192
- {
193
- summary: report.summary,
194
- statistics: report.statistics,
195
- anomalies: report.anomalies,
196
- },
197
- null,
198
- 2,
199
- ),
200
- );
201
- console.log(`✅ Stats export to: ${statsPath}\n`);
202
-
203
- // Show sample data
204
- console.log("📄 Sample Report Data:");
205
- console.log(`${JSON.stringify(report, null, 2).substring(0, 500)}...\n`);
206
-
207
- // Integration example: Send to external system
208
- console.log("🔗 Integration Example:");
209
- console.log("To send this data to external systems:");
210
- console.log(" • Database: INSERT INTO audit_logs VALUES (...)");
211
- console.log(" • API: POST /api/audit-reports (JSON payload)");
212
- console.log(" • Message Queue: PUBLISH audit_report (for async processing)");
213
- console.log(" • SIEM: Send via syslog or CEF format\n");
214
-
215
- // Query examples
216
- console.log("🔍 Query Examples:");
217
-
218
- // Auth failures by user
219
- const authFailures = honeypot.getAuditLog("auth:failure");
220
- const failuresByUser = new Map<string, number>();
221
- authFailures.forEach((entry) => {
222
- const user = entry.details.username as string;
223
- failuresByUser.set(user, (failuresByUser.get(user) || 0) + 1);
224
- });
225
-
226
- if (failuresByUser.size > 0) {
227
- console.log("\n Auth Failures by User:");
228
- failuresByUser.forEach((count, user) => {
229
- console.log(` • ${user}: ${count} failures`);
230
- });
231
- }
232
-
233
- // File operations
234
- const fileWrites = honeypot.getAuditLog("file:write");
235
- if (fileWrites.length > 0) {
236
- console.log(`\n File Writes: ${fileWrites.length}`);
237
- fileWrites.slice(-3).forEach((entry) => {
238
- console.log(` • ${entry.details.path} (${entry.details.size} B)`);
239
- });
240
- }
241
-
242
- console.log();
243
-
244
- // Cleanup
245
- ssh.stop();
246
-
247
- console.log("✅ Audit report generation complete!");
248
- console.log(
249
- "💡 Tip: Open the generated .json files to view full audit trails.\n",
250
- );
251
- }
252
-
253
- generateAuditReport().catch(console.error);
@@ -1,110 +0,0 @@
1
- /**
2
- * HoneyPot Quick Start Example
3
- *
4
- * A minimal, step-by-step introduction to HoneyPot auditing.
5
- * Perfect for beginners.
6
- *
7
- * Run with: bun run examples/honeypot-quickstart.ts
8
- */
9
-
10
- import {
11
- HoneyPot,
12
- SshClient,
13
- VirtualShell,
14
- VirtualSshServer,
15
- } from "../src/index";
16
-
17
- async function quickStart() {
18
- console.log("🍯 HoneyPot Quick Start\n");
19
-
20
- // Step 1: Create virtual environment
21
- console.log("Step 1️⃣ Creating virtual environment...");
22
- const shell = new VirtualShell("my-lab");
23
- const ssh = new VirtualSshServer({ port: 2222, shell });
24
- await ssh.start();
25
-
26
- const users = shell.getUsers()!;
27
- const vfs = shell.getVfs()!;
28
-
29
- console.log("✅ Environment ready\n");
30
-
31
- // Step 2: Create HoneyPot instance
32
- console.log("Step 2️⃣ Initializing HoneyPot...");
33
- const honeypot = new HoneyPot();
34
-
35
- // Step 3: Attach HoneyPot to all components
36
- console.log("Step 3️⃣ Attaching HoneyPot to components...");
37
- honeypot.attach(shell, vfs, users, ssh);
38
-
39
- console.log("✅ HoneyPot is now tracking all activity\n");
40
-
41
- // Step 4: Do some work (which will be audited)
42
- console.log("Step 4️⃣ Performing some operations...\n");
43
-
44
- // Create a user
45
- await users.addUser("dev_user", "secure_pass");
46
- console.log(" ✓ Created user 'dev_user'");
47
-
48
- // Create a client
49
- const client = new SshClient(shell, "dev_user");
50
-
51
- // Create files
52
- await client.mkdir("/app", true);
53
- await client.writeFile("/app/config.json", '{"debug":true}');
54
- await client.readFile("/app/config.json");
55
-
56
- console.log(" ✓ Created /app directory and config.json");
57
- console.log(" ✓ Read config.json\n");
58
-
59
- // Step 5: Get statistics
60
- console.log("Step 5️⃣ Viewing activity statistics...\n");
61
- const stats = honeypot.getStats();
62
- console.log(` 📊 Commands: ${stats.commands}`);
63
- console.log(` 📝 File writes: ${stats.fileWrites}`);
64
- console.log(` 📖 File reads: ${stats.fileReads}`);
65
- console.log(` 👤 Users created: ${stats.userCreated}\n`);
66
-
67
- // Step 6: Get recent events
68
- console.log("Step 6️⃣ Last 5 events:\n");
69
- honeypot.getRecent(5).forEach((entry, idx) => {
70
- console.log(` ${idx + 1}. [${entry.source}] ${entry.type}`);
71
- if (Object.keys(entry.details).length > 0) {
72
- console.log(` └─ ${JSON.stringify(entry.details)}`);
73
- }
74
- });
75
- console.log();
76
-
77
- // Step 7: Query filtered logs
78
- console.log("Step 7️⃣ Querying specific event types...\n");
79
-
80
- const userEvents = honeypot.getAuditLog("user:add");
81
- console.log(` 👤 User creation events: ${userEvents.length}`);
82
-
83
- const fileEvents = honeypot.getAuditLog(undefined, "VirtualFileSystem");
84
- console.log(` 📁 VirtualFileSystem events: ${fileEvents.length}\n`);
85
-
86
- // Step 8: Detect anomalies
87
- console.log("Step 8️⃣ Checking for anomalies...\n");
88
- const anomalies = honeypot.detectAnomalies();
89
- if (anomalies.length === 0) {
90
- console.log(" ✅ No anomalies detected\n");
91
- } else {
92
- console.log(" ⚠️ Anomalies found:");
93
- anomalies.forEach((a) => {
94
- console.log(` • ${a.message}`);
95
- });
96
- console.log();
97
- }
98
-
99
- // Step 9: Export audit data (for storage/analysis)
100
- console.log("Step 9️⃣ Exporting audit log...\n");
101
- const fullLog = honeypot.getAuditLog();
102
- console.log(` ✓ Exported ${fullLog.length} audit entries`);
103
- console.log(` ✓ Ready to store in database, file, or monitoring system\n`);
104
-
105
- // Cleanup
106
- ssh.stop();
107
- console.log("✅ Example complete!");
108
- }
109
-
110
- quickStart().catch(console.error);
@@ -1,82 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- <title>Virtual Shell — Web Demo</title>
7
- <style>
8
- *, *::before, *::after { box-sizing: border-box; }
9
-
10
- html, body {
11
- height: 100%;
12
- margin: 0;
13
- }
14
-
15
- body {
16
- display: flex;
17
- flex-direction: column;
18
- font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
19
- font-size: 14px;
20
- line-height: 1.5;
21
- background: #0b0f14;
22
- color: #e6eef6;
23
- }
24
-
25
- #terminal {
26
- flex: 1;
27
- overflow-y: auto;
28
- padding: 12px 16px;
29
- cursor: text;
30
- user-select: text;
31
- scrollbar-width: none; /* Firefox */
32
- }
33
-
34
- #terminal::-webkit-scrollbar {
35
- display: none; /* Chrome/Safari */
36
- }
37
-
38
- #output {
39
- white-space: pre-wrap;
40
- word-break: break-all;
41
- user-select: text;
42
- }
43
-
44
- #output span,
45
- #output .input-line {
46
- user-select: text;
47
- }
48
-
49
- /* Hidden input — keystroke sink only */
50
- #cmd {
51
- position: fixed;
52
- left: -9999px;
53
- opacity: 0;
54
- width: 1px;
55
- height: 1px;
56
- pointer-events: none;
57
- }
58
-
59
- .cursor {
60
- display: inline-block;
61
- min-width: 0.6em;
62
- background: #e6eef6;
63
- color: #0b0f14;
64
- animation: blink 1s step-start infinite;
65
- pointer-events: none;
66
- user-select: none;
67
- }
68
-
69
- @keyframes blink {
70
- 0%, 100% { opacity: 1; }
71
- 50% { opacity: 0; }
72
- }
73
- </style>
74
- </head>
75
- <body>
76
- <div id="terminal">
77
- <div id="output"></div>
78
- </div>
79
- <input id="cmd" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
80
- <script type="module" src="./app.js"></script>
81
- </body>
82
- </html>
@@ -1,55 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { createServer } from 'node:http';
3
- import { extname, join, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
-
6
- const __dirname = resolve(fileURLToPath(import.meta.url), '..');
7
- const examplesDir = __dirname;
8
-
9
- const mimeTypes = {
10
- '.html': 'text/html',
11
- '.js': 'application/javascript',
12
- '.json': 'application/json',
13
- '.css': 'text/css',
14
- '.map': 'application/json',
15
- };
16
-
17
- const server = createServer(async (req, res) => {
18
- const reqPath = req.url === '/' ? '/index.html' : req.url;
19
- const filePath = join(examplesDir, reqPath);
20
- console.log(`[${new Date().toISOString()}] ${req.method} ${req.url} -> ${filePath}`);
21
-
22
- try {
23
- const content = await readFile(filePath);
24
- const ext = extname(filePath);
25
- const mimeType = mimeTypes[ext] || 'application/octet-stream';
26
-
27
- // Headers to bypass Cloudflare challenges and allow ES6 modules
28
- const headers = {
29
- 'Content-Type': mimeType,
30
- 'Cache-Control': 'public, max-age=3600',
31
- 'X-Content-Type-Options': 'nosniff',
32
- 'Access-Control-Allow-Origin': '*',
33
- 'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
34
- };
35
-
36
- // Cloudflare-specific header to bypass challenge
37
- if (reqPath === '/index.html' || reqPath === '/app.js' || reqPath === '/web.min.js') {
38
- headers['CF-Mitigate-Challenge'] = 'bypass';
39
- }
40
-
41
- res.writeHead(200, headers);
42
- res.end(content);
43
- console.log(` ✓ 200 ${mimeType}`);
44
- } catch (err) {
45
- console.log(` ✗ 404 ${err.code}`);
46
- res.writeHead(404, { 'Content-Type': 'text/plain' });
47
- res.end('404 Not Found');
48
- }
49
- });
50
-
51
- const PORT = 8787;
52
- server.listen(PORT, () => {
53
- console.log(`Server running at http://localhost:${PORT}`);
54
- console.log(`Serving files from: ${examplesDir}`);
55
- });
@@ -1,117 +0,0 @@
1
- class BrowserBuffer extends Uint8Array {
2
- static from(data, encoding) {
3
- if (typeof data === 'string') {
4
- const enc = encoding || 'utf8';
5
- if (enc === 'hex') {
6
- const arr = new BrowserBuffer(data.length / 2);
7
- for (let i = 0; i < arr.length; i++)
8
- arr[i] = parseInt(data.slice(i * 2, i * 2 + 2), 16);
9
- return arr;
10
- }
11
- if (enc === 'base64') {
12
- const bin = atob(data);
13
- const arr = new BrowserBuffer(bin.length);
14
- for (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);
15
- return arr;
16
- }
17
- return new BrowserBuffer(new TextEncoder().encode(data));
18
- }
19
- if (data instanceof ArrayBuffer) return new BrowserBuffer(data);
20
- return new BrowserBuffer(data);
21
- }
22
-
23
- static alloc(size, fill = 0) {
24
- return new BrowserBuffer(size).fill(fill);
25
- }
26
-
27
- static allocUnsafe(size) {
28
- return new BrowserBuffer(size);
29
- }
30
-
31
- static isBuffer(obj) {
32
- return obj instanceof BrowserBuffer || obj instanceof Uint8Array;
33
- }
34
-
35
- static concat(bufs, totalLength) {
36
- const len = totalLength ?? bufs.reduce((s, b) => s + b.length, 0);
37
- const out = new BrowserBuffer(len);
38
- let offset = 0;
39
- for (const b of bufs) { out.set(b, offset); offset += b.length; }
40
- return out;
41
- }
42
-
43
- static byteLength(str, enc = 'utf8') {
44
- if (enc === 'hex') return str.length / 2;
45
- if (enc === 'base64') return Math.floor(str.length * 3 / 4);
46
- return new TextEncoder().encode(str).length;
47
- }
48
-
49
- // ── write methods ──────────────────────────────────────────────────────────
50
- writeUInt8(val, offset = 0) { this[offset] = val & 0xff; return offset + 1; }
51
- writeInt8(val, offset = 0) { this[offset] = val & 0xff; return offset + 1; }
52
-
53
- writeUInt16BE(val, offset = 0) { this[offset] = (val >>> 8) & 0xff; this[offset + 1] = val & 0xff; return offset + 2; }
54
- writeUInt16LE(val, offset = 0) { this[offset] = val & 0xff; this[offset + 1] = (val >>> 8) & 0xff; return offset + 2; }
55
- writeInt16BE(val, offset = 0) { return this.writeUInt16BE(val, offset); }
56
- writeInt16LE(val, offset = 0) { return this.writeUInt16LE(val, offset); }
57
-
58
- writeUInt32BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setUint32(0, val, false); return offset + 4; }
59
- writeUInt32LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setUint32(0, val, true); return offset + 4; }
60
- writeInt32BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setInt32(0, val, false); return offset + 4; }
61
- writeInt32LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setInt32(0, val, true); return offset + 4; }
62
-
63
- writeBigUInt64BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setBigUint64(0, BigInt(val), false); return offset + 8; }
64
- writeBigUInt64LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setBigUint64(0, BigInt(val), true); return offset + 8; }
65
-
66
- writeFloatBE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat32(0, val, false); return offset + 4; }
67
- writeFloatLE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat32(0, val, true); return offset + 4; }
68
- writeDoubleBE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat64(0, val, false); return offset + 8; }
69
- writeDoubleLE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat64(0, val, true); return offset + 8; }
70
-
71
- // ── read methods ───────────────────────────────────────────────────────────
72
- readUInt8(offset = 0) { return this[offset]; }
73
- readInt8(offset = 0) { const v = this[offset]; return v >= 128 ? v - 256 : v; }
74
-
75
- readUInt16BE(offset = 0) { return (this[offset] << 8) | this[offset + 1]; }
76
- readUInt16LE(offset = 0) { return this[offset] | (this[offset + 1] << 8); }
77
- readInt16BE(offset = 0) { const v = this.readUInt16BE(offset); return v >= 0x8000 ? v - 0x10000 : v; }
78
- readInt16LE(offset = 0) { const v = this.readUInt16LE(offset); return v >= 0x8000 ? v - 0x10000 : v; }
79
-
80
- readUInt32BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getUint32(0, false); }
81
- readUInt32LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getUint32(0, true); }
82
- readInt32BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getInt32(0, false); }
83
- readInt32LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getInt32(0, true); }
84
-
85
- readBigUInt64BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getBigUint64(0, false); }
86
- readBigUInt64LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getBigUint64(0, true); }
87
-
88
- readFloatBE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat32(0, false); }
89
- readFloatLE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat32(0, true); }
90
- readDoubleBE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat64(0, false); }
91
- readDoubleLE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat64(0, true); }
92
-
93
- // ── misc ───────────────────────────────────────────────────────────────────
94
- toString(enc = 'utf8', start = 0, end = this.length) {
95
- const slice = this.subarray(start, end);
96
- if (enc === 'hex') return Array.from(slice).map(b => b.toString(16).padStart(2, '0')).join('');
97
- if (enc === 'base64') return btoa(String.fromCharCode(...slice));
98
- return new TextDecoder(enc === 'utf8' ? 'utf-8' : enc).decode(slice);
99
- }
100
-
101
- copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.length) {
102
- target.set(this.subarray(sourceStart, sourceEnd), targetStart);
103
- }
104
- equals(other) {
105
- if (this.length !== other.length) return false;
106
- for (let i = 0; i < this.length; i++)
107
- if (this[i] !== other[i]) return false;
108
- return true;
109
- }
110
-
111
- slice(start, end) { return new BrowserBuffer(super.slice(start, end)); }
112
- subarray(start, end) { return new BrowserBuffer(super.subarray(start, end)); }
113
-
114
- get length() { return this.byteLength; }
115
- }
116
-
117
- globalThis.Buffer = BrowserBuffer;
@@ -1,2 +0,0 @@
1
- export function spawn(){ throw new Error('child_process.spawn not supported in browser'); }
2
- export default { spawn };