ginger51011/pandoras_pot

GitHub: ginger51011/pandoras_pot

一款基于 Rust 的高性能 HTTP 蜜罐,通过向违规爬虫高速回灌海量数据来消耗恶意流量并保护真实服务。

Stars: 140 | Forks: 5

🔥pandoras_pot🍯

用 Rust 向毫无防备的恶意机器人释放深不可测的诅咒!

[![GitHub 仓库](https://img.shields.io/badge/GitHub-ginger51011%2Fpandoras__pot-FFA400?style=flat&logo=github)](https://github.com/ginger51011/pandoras_pot) [![Crates.io (pandoras_pot)](https://img.shields.io/crates/v/pandoras_pot)](https://crates.io/crates/pandoras_pot) [![GitHub 许可证](https://img.shields.io/github/license/ginger51011/pandoras_pot)](https://github.com/ginger51011/pandoras_pot/blob/main/LICENSE) [![GitHub Actions 工作流状态](https://img.shields.io/github/actions/workflow/status/ginger51011/pandoras_pot/ci.yml)](https://github.com/ginger51011/pandoras_pot/actions/)
# 简介 受 [HellPot](https://github.com/yunginnanet/HellPot) 启发,`pandoras_pot` 是一个 HTTP 蜜罐,旨在给那些不遵守你 `robots.txt` 的野蛮网络爬虫带来更多痛苦。 `pandoras_pot` 的目标是向传入的 不受欢迎的连接发送最大量的数据输出,同时不耗尽你的 Web 服务器上的所有资源, 毕竟你的服务器时间可能用来做点更有意义的事情。 为了确保机器人无法检测到 `pandoras_pot`,它会生成看起来有点像网站的随机数据(对机器人而言),而且生成速度非常非常快。快到疯狂。甚至可以说是快如闪电。*希望如此*。 `pandoras_pot` 支持多种生成模式,具体取决于它的配置。例如,它可以生成随机字符串作为数据,或者使用 Markov 链生成“真正”的句子。太酷了! # 功能 - 快如闪电 - 使用 Rust 编写 - TOML 配置格式,请参阅下方的示例(但即使没有配置也有合理的默认值!) - 可选的健康检查端口,可用于反向代理的健康检查 - 多种生成器模式,并且很容易添加更多模式!可以发送纯随机数据、使用 Markov 链生成的文本,或者静态文件! - 可配置的滥用保护(最大并发生成连接数、时间和大小限制) - 我有提过它是用 Rust 写的吗? # 设置说明 ## Web 与反向代理 最可能的使用场景是使用另一台服务器作为反向代理,然后 选择一些特定的路径转发给 `pandoras_pot`,例如 `/wp-login.php`、`/.git/config` 和 `/.env`。 请注意,你使用的 URI 应该在你的 `/robots.txt` 中设置 `Disallow`, 否则你可能会惹上麻烦,比如 googlebot 就会非常讨厌 你那奇怪的死亡页面。对于上述路径,你可以使用如下所示的 `robots.txt`: ``` User-agent: * Disallow: /wp-login.php Disallow: /.git Disallow: /.env ``` 常见的反向代理包括 `nginx`、`httpd` (apache) 和 `Caddy`。 在 Caddy 中,你可以添加以下内容以匹配我们刚刚创建的 `/robots.txt`: ``` (pandorust) { @pandorust_paths { path /wp-login.php /.git* /.env* } handle @pandorust_paths { reverse_proxy localhost:6669 # Or whatever you run pandoras_pot on } } # ... example.com { # ... # Your actual website # ... import pandorust } ``` 之后,你可以直接运行(如果你是通过 `cargo install pandoras_pot` 安装的): ``` pandoras_pot --help ``` 以获取更多信息。 搞定! ## 使用 Docker 设置 `pandoras_pot` 最简单的方法是使用 docker。你可以选择性地使用 docker 的 `--build-arg CONFIG=<你的配置路径>` 参数来传递配置文件(但该文件必须存在于构建上下文中)。 首先运行以下命令克隆仓库: ``` git clone git@github.com:ginger51011/pandoras_pot.git cd pandoras_pot ``` 然后你可以构建镜像并进行部署,这里我们将其命名为并标记为 `pandoras_pot`,并使其在 `localhost:6669` 端口上可用: ``` docker build -t pandoras_pot . # You can add --build-arg CONFIG=<...> here docker run --name=pandoras_pot --restart=always -p 6669:8080 -d pandoras_pot ``` ## `systemd` 服务 你也可以轻松地设置一个 `systemd` 服务。这要求你 [安装 Rust](https://www.rust-lang.org/tools/install),但这比庞大的 docker 镜像少了一个负担,并且让重载配置变得更加容易。在本示例中, 我将创建一个新用户 `pandora-user`,但你可以使用任何你想要的用户 (不过我们会对 `pandora-user` 进行权限锁定)。 _注意:除了克隆和构建 pandoras_pot 之外,这里的大多数命令 都需要 root 权限。_ 首先克隆仓库并构建 `pandoras_pot`(在安装 Rust 之后): ``` git clone git@github.com:ginger51011/pandoras_pot.git cd pandoras_pot cargo build --release # Move the binary to a better place cp ./target/release/pandoras_pot /usr/bin/ ``` 然后我们创建将运行该进程的用户;该用户不会是 root,甚至 无法登录: ``` adduser --disabled-password --gecos '' --shell /sbin/nologin --no-create-home --home /iamadirandidontexist 'pandora-user' ``` 接着我们创建一个目录来保存我们的配置(以及某些生成器所需的 `data` 文件等): ``` mkdir /etc/pandoras_pot # Ensure the config file exists; you can copy the default one in this README # into this file touch /etc/pandoras_pot/config.toml # Optionally you can create your data file here. You need to point to it from # the config. # Make pandora-user the owner of this dir chown -R pandora-user:pandora-user /etc/pandoras_pot ``` 现在我们来创建实际的服务。如果你使用了这里的示例,你只需 将以下内容复制粘贴到 `/etc/systemd/system/pandorad.service` 这个新文件中即可: ``` [Unit] Description=Pandora's Pot "service" After=network.target StartLimitIntervalSec=0 [Service] # Change to another user/group if needed User=pandora-user Group=pandora-user Restart=always RestartSec=1 WorkingDirectory=/etc/pandoras_pot/ # Requires that the file /etc/pandoras_pot/config.toml exists; you can also # remove config.toml to use plain default settings. ExecStart=/usr/bin/pandoras_pot config.toml ### ## Hardening; this is optional and can be commented out, but is generally ## good practice. Some might prevent pandoras_pot from functioning, see below. ## ## Other settings may exist and be suitable. ## ## For more info, see systemd.exec(5) ## MemoryDenyWriteExecute=yes NoNewPrivileges=yes PrivateDevices=yes PrivateTmp=yes PrivateUsers=yes ProtectClock=yes ProtectControlGroups=yes ProtectHostname=yes ProtectKernelLogs=yes ProtectKernelModules=yes ProtectKernelTunables=yes RestrictNamespaces=yes RestrictSUIDSGID=yes # These might prevent pandoras_pot from writing to a log file if ReadWritePaths is misconfigured. ProtectHome=yes ProtectSystem=strict # This should point to the output log file; this is the default value. # It should be the same as `logging.output_path` in the config.toml. # A sane alternative is `/var/log/pandoras.log`. ReadWritePaths=/etc/pandoras_pot/pandoras.log ## ## End of hardening ### [Install] WantedBy=multi-user.target ``` 接着你需要重载一些 daemon,启用并启动你的服务: ``` systemctl daemon-reload systemctl enable pandorad.service systemctl start pandorad.service ``` 你可以检查一切是否正常: ``` systemctl status pandorad.service ``` 搞定! ## 配置说明 `pandoras_pot` 使用 TOML 作为配置格式。如果你没有使用 docker, 你可以像下面这样将配置作为参数传递: ``` pandoras_pot ``` 或者将其放在 `$HOME/.config/pandoras_pot/config.toml` 文件中。 你随时可以使用以下命令获取默认配置: ``` pandoras_pot --print-default-config ``` 下面是一个示例文件: ``` [http] # Make sure this matches your Dockerfile's "EXPOSE" if using Docker port = "8080" # Routes to send misery to. Is overridden by `http.catch_all` routes = ["/wp-login.php", "/.env"] # If all routes are to be served. catch_all = true # How many connections that can be made over `http.rate_limit_period` seconds. Will # not set any limit if set to 0. rate_limit = 0 # Amount of seconds that `http.rate_limit` checks on. Does nothing if rate limit is set # to 0. rate_limit_period = 300 # 5 minutes # Enables `http.health_port` to be used for health checks (to see if # `pandoras_pot` is running). Useful if you want to use your chad gaming PC # that might not always be up and running to back up an instance running on # your RPi 3 web server. health_port_enabled = false # Port to be used for health checks. Should probably not be accessible from the # outside. Has no effect if `http.health_port_enabled` is `false`. health_port = "8081" # The `Content-Type` header set in responses. content_type = "text/html; charset=utf-8" [generator] # The size of each generated chunk in bytes. Has a big impact on performance, so # play around a bit! Note that if this is set too low (like 10 bytes), `pandoras_pot` # will refuse to run. chunk_size = 16384 # 1024 * 16 # The type of generator to be used type = { name = "random" } # For generator.type it is also possible to set a markov chain generator, using # a text file as a source of data. Then you can use this (but uncommented, duh): # type = { name = "markov_chain", data = "" } # Another alternative is a static generator, that always outputs the full contents # of a file. Does not respect chunking. # type = { name = "static", data = "" } # The max amount of simultaneous generators that can produce output. # Useful for preventing abuse. `0` means no limit. max_concurrent = 100 # The amount of time in seconds a generator can be active before # it stops sending. `0` means no limit. time_limit = 0 # The amount of data in bytes that a generator can # send before it stops sending. `0` means no limit. size_limit = 0 # How many chunks should be buffered for each connection. Higher values mean # more memory usage, but may lead to increased performance. Must be >= 1. chunk_buffer = 20 # Prefix that will be used for the first message to an incoming connection. # Usually used to set an HTML prefix. Can be set to "" to disable. # # Example usage: Set to "{" for a static generator using a JSON file to make # output look like a valid stream of JSON that will eventually end (it won't). prefix = "" [logging] # Output file for logs. output_path = "pandoras.log" # If pretty logs should be written to standard output. print_pretty_logs = true # If no logs at all should be printed to stdout. Overrides other stdout logging # settings. no_stdout = false ``` # 测量输出 你可以使用 `curl` 轻松测量你的设置发送数据的速度。请注意,使用 `localhost` 可能并不准确,因为它无法反映外部访问者的真实情况。更好的 选择可能是使用另一台机器。 此示例假定你已启用 `http.catch_all`,否则你应该添加一个 有效的路由。 ``` curl localhost:8080/ >> /dev/null ``` # 支持 我不接受任何捐款。但是,如果你发现我出于兴趣编写的任何软件 对你有用,请考虑向那些能以最高效的方式拯救或改善生命的慈善机构捐款(让每一单位的 `$CURRENCY` 发挥最大效益)。 [GiveWell.org](https://givewell.org) 是一个非常棒的网站,它可以帮助你 向世界上最有效的慈善机构捐款。另一个列出当前 最适合帮助地球的慈善机构的替代方案是 [Founders Pledge](https://www.founderspledge.com/funds/climate-change-fund),而关于 动物福利的则是 [Animal Charity Evaluators](https://animalcharityevaluators.org/donation-advice/recommended-charity-fund/)。 - 瑞典居民可以通过 [Ge Effektivt](https://geeffektivt.se) 向 GiveWell 进行可抵税的捐赠。 - 挪威居民可以通过 [Gi Effektivt](https://gieffektivt.no/) 进行同样的操作。 此列表并不详尽;你的国家可能也有类似的渠道。
标签:CISA项目, Python安全, Rust, Web安全, 反爬虫, 可视化界面, 网络流量审计, 网络爬虫防护, 蓝队分析, 蜜罐, 证书利用, 请求拦截, 通知系统