ItzNotABug/vitepot

GitHub: ItzNotABug/vitepot

一个基于 Vite/VitePress 的静态站点蜜罐插件,用于生成假敏感文件以误导爬虫与扫描器。

Stars: 3 | Forks: 0

# VitePot 🐝 [![npm 版本](https://img.shields.io/npm/v/@itznotabug/vitepot.svg?logo=npm&logoColor=white)](https://www.npmjs.com/package/@itznotabug/vitepot) [![CI](https://img.shields.io/github/actions/workflow/status/itznotabug/vitepot/ci.yaml?branch=main&logo=github&logoColor=white)](https://github.com/itznotabug/vitepot/actions/workflows/ci.yaml) [![许可证](https://img.shields.io/npm/l/%40itznotabug%2Fvitepot?logo=apache&logoColor=white&color=blue)](https://github.com/ItzNotABug/vitepot/blob/main/LICENSE) [![Vite](https://img.shields.io/badge/Vite-6.x-646CFF.svg?logo=vite&logoColor=white)](https://vite.dev/) [![VitePress](https://img.shields.io/badge/VitePress-1.x-5a67d8.svg?logo=vitepress&logoColor=white)](https://vitepress.dev/) [![TypeScript](https://img.shields.io/badge/TypeScript-ready-3178C6.svg?logo=typescript&logoColor=white)](https://www.typescriptlang.org.org/) 适用于 VitePress 和其他基于 Vite 的静态站点的静态优先蜜罐插件。 VitePot 会生成看起来很真实的敏感文件,例如 `/.env`、`/wp-config.php`、`/backup.sql`、`/.git/config`、 `/vercel.json` 和 `settings.py`,这样嘈杂的爬虫、路径探测器和低成本的扫描器就会把时间花在诱饵上, 而不是你的真实攻击面上。 ## 它的功能 - 在 `vitepress dev` 期间从内存中提供陷阱 - 在 `vitepress build` 期间生成真实的陷阱文件 - 在预览中重用相同的陷阱响应(dotfile 除外) - 为 env、PHP、SQL、Git、JSON、JS、YAML、Python、INI、日志和纯文本生成具备语法感知的伪造内容 - 使用保留的 `.test` 域名和 RFC 5737 test-net IP,因此生成的数据绝不会指向真实的基础设施 - 支持带有同步内容、异步内容、二进制内容的自定义陷阱,并为每个陷阱指定目录放置位置 ## 安装 ``` bun add @itznotabug/vitepot ``` ## 用法 ### 快速开始 ``` // .vitepress/config.mts import { defineConfig } from 'vitepress'; import { vitepot } from '@itznotabug/vitepot'; export default defineConfig({ vite: { plugins: [ vitepot() ], }, }); ``` 这将在站点根目录启用内置陷阱集。 ### 完整示例 ``` import { defineConfig } from 'vitepress'; import { vitepot } from '@itznotabug/vitepot'; export default defineConfig({ vite: { plugins: [ vitepot({ variants: ['cms-roots', 'archive-roots'], dirs: ['/legacy'], custom: [ { path: '/private.env' }, { path: '/secrets.ini', kind: 'ini' }, { path: '/credentials.txt', content: 'admin=disabled\nroot=disabled\n', }, { path: '/ai-keys.json', contentType: 'application/json', content: async ({ helpers }) => JSON.stringify( { openai: helpers.fakeOpenAIKey(), anthropic: helpers.fakeAnthropicKey(), google: helpers.fakeGoogleAIKey(), }, null, 2, ), }, { path: '/archive.bin', contentType: 'application/octet-stream', content: new Uint8Array([0xde, 0xad, 0xbe, 0xef]), }, ], }), ], }, }); ``` ## 运行时模型 ### 开发 在 `vitepress dev` 期间,VitePot 会注册中间件并直接从内存中提供陷阱响应。不会写入任何文件。 ### 构建 在 `vitepress build` 期间,VitePot 会生成陷阱集并将静态资源输出到打包目录中。如果陷阱路径 与现有的输出文件发生冲突,VitePot 将**跳过它**并记录一条警告。 ### 预览 在预览期间,将挂载相同的陷阱中间件,以便本地预览行为与构建输出保持一致。 注意:由于 Vite/VitePress 的限制,不会提供 dotfile。 ## 内置陷阱集 默认集包含分布在以下类别的 43 个文件陷阱: - 泄漏的 env 和凭证文件 - Git 和源代码控制元数据 - WordPress 和 PHP 配置文件 - SQL 转储和备份 - 服务器配置和认证文件 - 框架和部署配置文件 - 应用程序日志 示例: - `/.env` - `/.aws/credentials` - `/.git/config` - `/wp-config.php` - `/config.php` - `/backup.sql` - `/web.config` - `/wp-login.php` - `/xmlrpc.php` - `/vercel.json` - `/next.config.js` - `/config/database.yml` - `/settings.py` - `/connectionstrings.config` ## 放置 ### 变体 变体会将兼容的内置陷阱镜像到常见的子路径中。 ``` vitepot({ variants: ['cms-roots'], }); ``` 可用的预设: - `cms-roots` → `/blog`、`/site`、`/wordpress` - `app-roots` → `/public`、`/api` - `archive-roots` → `/backup`、`/backups`、`/old` 变体扩展会根据陷阱的兼容性进行过滤。例如:`cms-roots` 会扩展 `/wp-config.php`,但不会扩展 `/.env`。 ### 显式目录 您还可以将陷阱镜像到您选择的目录中: ``` vitepot({ dirs: ['/legacy', '/staging'], }); ``` ## API ### 插件选项 ``` interface VitePotOptions { enabled?: boolean; variants?: VariantPreset[]; dirs?: string[]; custom?: CustomTrap[]; } ``` ### `enabled` 打开或关闭插件。默认值为 `true`。 ### `variants` 为兼容的内置陷阱添加内置预设目录。 ### `dirs` 添加用于扩展的显式额外目录。始终会自动包含根目录。 ### `custom` 添加用户定义的文件陷阱。 ``` type CustomTrap = { path: string; kind?: TrapKind; content?: string | Uint8Array | Promise | ((ctx: CustomTrapContext) => string | Uint8Array | Promise); contentType?: string; dirs?: string[]; }; ``` 规则: - `path` 必须以 `/` 开头 - 文件路径不能以 `/` 结尾 - `content` 会覆盖内置生成器 - 自定义陷阱上的 `dirs` 仅适用于该陷阱 ### 陷阱类型 内置生成器系列将文件路径映射为真实的内容结构: - `env` - `wordpress` - `php` - `sql` - `git` - `server` - `json` - `js` - `yaml` - `python` - `ini` - `log` - `text` 如果在自定义陷阱上省略了 `kind`,VitePot 会根据路径推断它。 ### 伪造数据助手 自定义内容工厂会接收确定性助手: ``` helpers.fakeDomain() // calmrouter.test helpers.fakeEmail() // admin@calmrouter.test helpers.fakeHostname() // db-3.calmrouter.test helpers.fakeTestNetIPv4() // 192.0.2.15 helpers.fakeMysqlPassword() // strong fake password helpers.fakeApiToken() // generic token helpers.fakePhpSecret() // 64-char hex secret helpers.fakeJwtLikeSecret() // JWT-like secret helpers.fakeCloudKey() // AWS-style access key helpers.fakeTimestamp() // ISO timestamp helpers.fakeOpenAIKey() // sk-proj-... helpers.fakeAnthropicKey() // sk-ant-api... helpers.fakeGoogleAIKey() // AIzaSy... helpers.fakeHuggingFaceToken() // hf_... helpers.fakeStripeKey() // sk_live_... helpers.fakeSupabaseKey() // JWT-like Supabase key helpers.fakeClerkKey() // sk_live_... helpers.fakeVercelToken() // Vercel-style token helpers.fakeSentryDSN() // https://key@host.test/123 ``` 所有生成的域名都使用保留的 `.test` TLD,并且所有生成的 IP 都使用 RFC 5737 test-net 范围。 ## 重要提示 ### 防止服务器端执行 如果您的生产服务器能够执行某些文件类型(PHP、Python、Ruby 等),请将其配置为将蜜罐文件作为静态文本提供,而不是执行它们。使用 `.htaccess` (Apache)、`nginx.conf` (Nginx) 或针对您的 Web 服务器的等效配置,以禁用执行并强制为陷阱文件使用 `text/plain` 内容类型。 ### dotfile 限制 **VitePress 预览:**dotfile(`.env`、`.git/config` 等)会被 VitePress 的预览服务器阻止。它们在开发模式下可以通过中间件工作,并在构建期间会被输出,但在 `vitepress preview` 中不会被提供服务。 **生产托管:**出于安全考虑,某些托管服务提供商可能会阻止 dotfile。非 dotfile 陷阱(`wp-config.php`、`backup.sql` 等)可在任何地方使用。dotfile 应该在您拥有完全控制权的服务器上工作(VPS、具有自定义 Web 服务器配置的专用服务器)。 ## 开发 ``` bun install bun run check bun test bun run typecheck bun run build ```
标签:CISA项目, TypeScript, VitePress插件, Web安全, 前端工程化, 安全插件, 密码管理, 爬虫对抗, 自动化攻击, 蓝队分析, 蜜罐, 证书利用