From 2a639a6b59ea4c87effee96a4314fd5942a24a3e Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 15 Nov 2026 12:50:10 +0100 Subject: [PATCH] Trim README and move details to docs Co-Authored-By: Claude Opus 5.5 --- README.md | 387 ++++++------------------------------------ docs/configuration.md | 60 +++++++ docs/development.md | 27 +++ docs/overview.md | 66 +++++++ docs/releases.md | 40 +++++ docs/reverse-proxy.md | 153 +++++++++++++++++ docs/unraid.md | 35 ++++ 7 files changed, 434 insertions(+), 334 deletions(-) create mode 100644 docs/configuration.md create mode 100644 docs/development.md create mode 100644 docs/overview.md create mode 100644 docs/releases.md create mode 100644 docs/reverse-proxy.md create mode 100644 docs/unraid.md diff --git a/README.md b/README.md index b910d5c..52e3c34 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,9 @@ # Flypaper -Self-hosted tarpit that traps and slows down scanning bots, with event logging and analysis. - -Every server on the internet gets a steady stream of bots probing for `/.env`, `/.git/config`, -`/wp-login.php` and friends, usually sent to the bare IP address or to host names that don't -exist. Blocklists play whack-a-mole with addresses that change daily. Flypaper takes the -opposite approach: it lets the bot in and then answers very, very slowly. While a scanner waits -for an endless HTML page that trickles in a few bytes at a time, it isn't scanning someone -else, and every catch is logged with its origin for you to look at. +An HTTP tarpit for scanning bots. Instead of blocking the bots that probe your server for +`/.env`, `/.git/config` or `/wp-login.php`, Flypaper lets them in and answers with an endless +HTML page, a few bytes at a time. While a scanner waits, it isn't scanning someone else, and +the dashboard shows you who knocked: country, network provider and what they were after. ## How it works @@ -21,44 +17,17 @@ flowchart LR you["You (LAN)"] -->|"dashboard, port 8081"| flypaper ``` -1. Your reverse proxy keeps serving your real sites. Everything it has no site for (the - default/catch-all server) goes to Flypaper, optionally also a few bait paths on your real - domains. -2. Flypaper listens on two ports. Port `8080` is the trap: everything that arrives there is - caught. Port `8081` serves the dashboard and never traps; keep it inside your LAN. -3. A caught request gets `200 OK` and an endless, plausible-looking HTML page: random chunks - of 1 to 64 bytes with random pauses of 50 ms to 1 s in between. -4. A connection governor caps the number of catches overall and per IP and ends every catch - after a maximum hold time. If there is no free slot, the request gets a quick `404`. -5. When a catch ends, Flypaper logs one line and stores the event in SQLite, enriched with - country, city and network provider (ASN) from the free DB-IP databases. +- Your reverse proxy sends everything it has no site for (its catch-all server) to Flypaper's + trap port `8080`. +- Every request there gets `200 OK` and an endless page in random chunks with random pauses, + within limits per IP, overall and per catch. +- Each catch is logged and stored with its origin (DB-IP GeoIP); the dashboard on port `8081` + shows maps and tables. -## Features - -- **Traps** for unknown hosts (catch-all) and for configurable trap paths such as `/.env`, - `/.git/*` or `/wp-login.php` -- **Slow delivery** of endless generated HTML with irregular timing -- **Limits**: maximum connections overall and per IP, maximum hold time per catch -- **Dashboard**: totals, a world map, top countries, providers, IPs and paths, the latest - catches with expandable details; login with an admin password -- **GeoIP**: country, city and ASN per catch from DB-IP Lite, downloaded and refreshed - monthly; existing catches are filled in once the databases are available -- **Settings page**: trap paths, extra known hosts, limits and retention, changed at runtime - without a restart -- **Retention**: old catches are deleted daily (90 days by default); catches from private - networks are not stored by default; buttons to delete private or all catches -- **One log line per catch**, so `docker logs` alone shows whether the trap works -- **Health endpoint** `/health` for container health checks (on the trap port it answers only - to private addresses) -- **No configuration needed to start**: one volume, two ports, the admin password is set on - first visit +More: [how it works and all features](docs/overview.md). ## Quick start -Images for `linux/amd64` and `linux/arm64` (e.g. Raspberry Pi 4/5 with a 64-bit OS) are -published in the author's Gitea registry; no login is needed to pull. No environment variable -is required. - ```bash docker run -d --name flypaper --restart unless-stopped \ -p 8080:8080 -p 127.0.0.1:8081:8081 \ @@ -75,8 +44,8 @@ services: container_name: flypaper restart: unless-stopped ports: - - "8080:8080" # trap: point your reverse proxy here - - "127.0.0.1:8081:8081" # dashboard: LAN or localhost only + - "8080:8080" # trap + - "127.0.0.1:8081:8081" # dashboard volumes: - flypaper-data:/data @@ -84,184 +53,21 @@ volumes: flypaper-data: ``` -You can also build the image yourself: clone the repository and replace the `image:` line with -`build: .`, or run `docker build -t flypaper .`. +Port `8080` is the trap, port `8081` the dashboard (keep it in your LAN), and `/data` holds the +database, login keys and GeoIP files. Images exist for `linux/amd64` and `linux/arm64`. Open +: the first visit sets the admin password (changeable later on the +settings page). Try the trap with `curl -N http://localhost:8080/`. -- Dashboard: . On the first visit Flypaper asks you to set the admin - password; afterwards you log in with it and can change it on the settings page. -- See the trap in action: +On Unraid, use the template: [docs/unraid.md](docs/unraid.md). - ```bash - curl -N http://localhost:8080/ - ``` +## Connect your reverse proxy - This catch comes from a private address and is therefore not stored; the log line ends with - `(not stored)`. +Make Flypaper the target of your proxy's catch-all (default) server on port `8080`, so every +request for a host you don't serve lands in the trap. The proxy must set `X-Real-IP`; Flypaper +trusts proxies in private networks by default. Turn off response buffering so the drip reaches +the bot. -The container runs as a non-root user (UID 1654) and keeps everything under `/data`: the SQLite -database, the Data Protection keys for logins and the GeoIP databases. A named volume gets -the right owner automatically; for a bind mount, `chown 1654:1654` the host folder first. - -The files in [`deploy/unraid/`](deploy/unraid) and `.gitea/workflows/deploy.yml` are the -author's personal deployment (Gitea Actions to Unraid). They are an example only and not -needed to run Flypaper. - -## Unraid - -[`unraid/flypaper.xml`](unraid/flypaper.xml) is a Docker template for Unraid. It sets up both -ports, the appdata folder `/mnt/user/appdata/flypaper` and the optional variables (under -*Show more settings*). - -1. Copy the template to the flash drive, in the Unraid terminal: - - ```bash - wget -O /boot/config/plugins/dockerMan/templates-user/my-Flypaper.xml \ - https://gitea.anticarnist.de/Tom/Flypaper/raw/branch/main/unraid/flypaper.xml - ``` - -2. **Docker → Add Container**, pick *Flypaper* under the user templates, choose free host ports - (8080 is often taken on Unraid) and **Apply**. -3. Open the WebUI (the dashboard port) and set the admin password. - -Unraid can also read templates from a *template repository* (Docker tab, Advanced View), but -that feature is built around GitHub repositories and may not accept this Gitea URL; the manual -copy above always works. - -The template starts the container as root (`--user 0:0`) only so it can hand the appdata folder -to its app user; Flypaper then drops to UID 1654 for good. Without it, a freshly created appdata -folder belongs to root and the database cannot be created. - -**Connecting Nginx Proxy Manager:** follow the [NPM section](#nginx-proxy-manager) below. If NPM -runs in a user-defined Docker network (e.g. `proxynet`), put Flypaper into the same network -(*Network Type* in the template) and use `http://Flypaper:8080` as the target. If NPM can't -share a network with it, forward to `http://:` instead. Either way the -request comes from a private address, which Flypaper trusts by default. - -The template is not part of the official Community Applications yet; that needs a separate -submission. - -## Versions and updates - -Flypaper follows [Semantic Versioning](https://semver.org); every release is listed in -[CHANGELOG.md](CHANGELOG.md) and on the -[releases page](https://gitea.anticarnist.de/Tom/Flypaper/releases). The running version is -shown in the dashboard footer and in the first log line. - -All images live at `gitea.anticarnist.de/tom/flypaper` -([package page](https://gitea.anticarnist.de/Tom/-/packages/container/flypaper/latest)). - -| Image tag | Meaning | Platforms | -|---|---|---| -| `:latest` | The newest release. The right choice for most setups. | amd64, arm64 | -| `:X.Y.Z` | A fixed release, e.g. `:0.1.0`. Pin it if you update deliberately. | amd64, arm64 | -| `:X.Y`, `:X` | The newest release of that minor or major line, e.g. `:0.1`, `:0`. | amd64, arm64 | -| `:main` | Development build of the latest commit on `main`. May break. | amd64 | -| `:` | Development build of one commit (short SHA), e.g. for a rollback. | amd64 | - -Pull a fixed version with `docker pull gitea.anticarnist.de/tom/flypaper:0.1.0`. To build a -specific release from source instead: - -```bash -git checkout v0.1.0 -docker build --build-arg VERSION=0.1.0 -t flypaper:0.1.0 . -``` - -To update, pull or rebuild the image and recreate the container -(`docker compose pull && docker compose up -d`). The database is migrated automatically on -start; back up the `/data` volume first. Before 1.0, a minor version may contain breaking -changes, so read the changelog. - -## Behind a reverse proxy - -Flypaper is meant to sit behind the reverse proxy that already owns ports 80/443. The proxy -forwards to the trap port `8080`; the dashboard port `8081` is never forwarded. Two rules -apply to every proxy: - -- **Set `X-Real-IP`** (and `X-Forwarded-For`) to the client address. -- **Flypaper must trust the proxy.** By default it trusts every private network (`10/8`, - `172.16/12`, `192.168/16`, loopback, `fc00::/7`), which covers a proxy in a Docker network - or on the LAN. Headers from public addresses are ignored, so bots can't fake their address. - To narrow it down, set `Flypaper__Http__TrustedProxies__0` to the proxy's IP or subnet, e.g. - the Docker network's subnet: - - ```bash - docker network inspect -f '{{(index .IPAM.Config 0).Subnet}}' - ``` - -Also turn off response buffering for Flypaper, otherwise the proxy collects the drip and the -bot never sees it. Flypaper sends `X-Accel-Buffering: no`, which nginx honors. - -### What to send to Flypaper - -- **The catch-all server.** Requests for hosts you don't serve (mostly the bare IP) go to - Flypaper. This is where almost all scanners end up. -- **Optionally, trap paths on your real domains.** Forward only the bait paths, e.g. `/.env` - or `/wp-login.php`, from your real sites to Flypaper. Every request on the trap port is - caught, so nothing else is needed. - -*Known hosts* (optional) change this for hosts you list: on the trap port, a known host is -caught only on the configured trap paths, and its other paths get a plain `404` without being -logged. That is useful if your proxy forwards more than the bait paths of a real domain, for -example a whole location. Unknown hosts are always caught. The dashboard is never reachable -on the trap port. - -### Nginx Proxy Manager - -Put Flypaper into the same Docker network as NPM (the examples use the container name -`flypaper`). - -1. **Settings → Default Site → Congratulations Page.** With this setting NPM writes no - default server of its own. Any other choice (404, redirect, HTML) creates one, and nginx - refuses to start with two default servers. -2. Create `/data/nginx/custom/http.conf` in the NPM container (on the host: inside NPM's - data volume): - - ```nginx - # Catch-all: every HTTP request whose Host matches no proxy host goes to Flypaper. - server { - listen 80 default_server; # the HTTP port NPM listens on inside its container - listen [::]:80 default_server; - server_name _; - - location / { - # A variable makes nginx resolve the name per request, so NPM still starts - # (and serves your sites) while the Flypaper container is down. - resolver 127.0.0.11 valid=30s; - set $flypaper http://flypaper:8080; - proxy_pass $flypaper; - - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_buffering off; - proxy_read_timeout 1h; - } - } - ``` - -3. Test and reload: `docker exec nginx -t`, then - `docker exec nginx -s reload`. -4. Optional trap paths on a real domain: in the proxy host's **Advanced** tab add - - ```nginx - location ~* ^/(\.env|\.git/|wp-login\.php|xmlrpc\.php) { - resolver 127.0.0.11 valid=30s; - set $flypaper http://flypaper:8080; - proxy_pass $flypaper; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_buffering off; - } - ``` - -To undo the catch-all, delete `custom/http.conf` and reload. - -### Plain nginx - -Same idea: remove any existing `default_server` (on Debian/Ubuntu often -`sites-enabled/default`) and add +Plain nginx, with Flypaper on the same host: ```nginx server { @@ -270,7 +76,7 @@ server { server_name _; location / { - proxy_pass http://127.0.0.1:8080; # or a variable + resolver for a Docker name, see above + proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -280,136 +86,49 @@ server { } ``` -With Flypaper on the same host, nothing else is needed: loopback is trusted by default. - -### Caddy - -```caddyfile -# Catch-all for every host on port 80 without its own site block -:80 { - reverse_proxy flypaper:8080 { - header_up X-Real-IP {remote_host} - flush_interval -1 - } -} - -# Optional trap paths on a real site -example.com { - @trap path /.env /.git/* /wp-login.php /xmlrpc.php - reverse_proxy @trap flypaper:8080 { - header_up X-Real-IP {remote_host} - flush_interval -1 - } - reverse_proxy your-app:8080 -} -``` - -### Traefik - -Traefik sets `X-Real-Ip` and `X-Forwarded-For` by default. Labels on the Flypaper container -(Traefik v3): - -```yaml -labels: - traefik.enable: "true" - # Lowest priority: matches only hosts no other router claims - traefik.http.routers.flypaper-catchall.rule: "HostRegexp(`.+`)" - traefik.http.routers.flypaper-catchall.entrypoints: web - traefik.http.routers.flypaper-catchall.priority: "1" - # Optional trap paths on a real site - traefik.http.routers.flypaper-bait.rule: "Host(`example.com`) && (Path(`/.env`) || PathPrefix(`/.git/`) || Path(`/wp-login.php`))" - traefik.http.routers.flypaper-bait.priority: "1000" - traefik.http.services.flypaper.loadbalancer.server.port: "8080" -``` +Nginx Proxy Manager, Caddy, Traefik and bait paths on your real domains: +[docs/reverse-proxy.md](docs/reverse-proxy.md). ## Configuration -### Environment variables +Nothing is required. The most useful optional environment variables: -All optional. Read at startup; list entries need an index (`__0`, `__1`, ...). - -| Variable | Purpose | Default | -|---|---|---| -| `Flypaper__Admin__Password` | Fixes the dashboard password and disables the first-visit setup and the password change | set on first visit | -| `Flypaper__Http__TrustedProxies__0` | IP or CIDR of the reverse proxy allowed to set `X-Real-IP` / `X-Forwarded-For`; replaces the default | private networks | -| `Flypaper__Http__KnownHosts__0` | Hosts that are caught only on trap paths (`*.example.com` allowed), see above | none | -| `Flypaper__Ports__Trap` / `Flypaper__Ports__Dashboard` | Container ports | `8080` / `8081` | -| `ConnectionStrings__Flypaper` | SQLite database | `Data Source=/data/flypaper.db` | -| `Flypaper__DataProtection__KeysPath` | Keys for login cookies and forms | `/data/keys` | -| `Flypaper__GeoIp__Directory` | Folder for the DB-IP databases; empty disables GeoIP | `/data/geoip` | -| `Flypaper__Drip__MinDelay` / `MaxDelay` | Pause between chunks | `00:00:00.05` / `00:00:01` | -| `Flypaper__Drip__MinChunkSize` / `MaxChunkSize` | Bytes per chunk | `1` / `64` | -| `TZ` | Time zone for the dashboard | UTC | - -The defaults of the runtime settings below can also be set this way, e.g. -`Flypaper__MaxConnections`. Values saved on the settings page override them. - -### Runtime settings - -Changed on the dashboard's settings page, stored in the database, effective immediately. The -reset button removes all saved values. - -| Setting | Default | +| Variable | Purpose | |---|---| -| Trap paths (exact, or prefix with a trailing `*`) | `/.env`, `/.env.*`, `/.git/*`, `/.aws/*`, `/.DS_Store`, `/wp-login.php`, `/wp-admin/*`, `/xmlrpc.php`, `/phpmyadmin/*`, `/vendor/phpunit/*`, `/server-status`, `/actuator/*`, `/cgi-bin/*`, `/boaform/*` | -| Extra known hosts (merged with `KnownHosts`) | none | -| Maximum hold time per catch | `01:00:00` | -| Maximum connections overall | `1000` | -| Maximum connections per IP | `10` | -| Keep catches (days, `0` = forever) | `90` | -| Don't store catches from private networks | on | +| `Flypaper__Admin__Password` | Fixes the dashboard password instead of setting it on first visit | +| `Flypaper__Http__TrustedProxies__0` | Proxy IP or CIDR allowed to set `X-Real-IP` (default: private networks) | +| `Flypaper__Http__KnownHosts__0` | Host that is caught only on trap paths | +| `TZ` | Time zone for the dashboard | -## Security notes +Trap paths, limits and retention are changed on the dashboard's settings page. All variables +and settings: [docs/configuration.md](docs/configuration.md). -- **Keep the dashboard internal.** Publish port `8081` only to your LAN or to localhost and - never forward it from your public proxy. -- **Finish the setup before the dashboard is reachable by anyone else.** Until a password is - set, whoever opens the dashboard first can set it. The setup page disappears once a password - exists. -- **Use a strong admin password** (at least 12 characters). Only a salted hash is stored. The - login runs over plain HTTP unless you put the dashboard behind TLS yourself. -- **The limits protect you, not the bots.** Every catch holds a socket in Flypaper and in your - proxy for up to the maximum hold time. Keep `MaxConnections` well below what your proxy can - handle (nginx: `worker_connections`), and keep the per-IP limit low so a single scanner - can't fill all slots. -- **An HTTPS catch-all is rarely worth it.** Scanners of unknown hosts mostly speak plain - HTTP to the bare IP, and an HTTPS catch-all would need a certificate for names you don't - own. Let the proxy reject unknown TLS handshakes instead (nginx: `ssl_reject_handshake on;`). -- **Privacy.** Flypaper stores IP addresses, requested URLs and user agents. Keep retention - short if that matters in your jurisdiction. +## Security + +- Keep the dashboard port `8081` internal; never forward it from your public proxy. +- Set the admin password right after the first start: until then, anyone who reaches the + dashboard can set it. +- The limits protect your own bandwidth and sockets, keep them below what your proxy can + handle. ## Development -Requires the .NET 10 SDK. - ```bash -dotnet build +dotnet build # .NET 10 SDK dotnet test -dotnet run --project src/Flypaper.Web +dotnet run --project src/Flypaper.Web # dashboard :5248 (password "dev"), trap :5247 ``` -`dotnet run` starts in the Development environment: the dashboard is at - (password `dev`), the trap at , the database is -`src/Flypaper.Web/flypaper.db`, and GeoIP is off unless `Flypaper__GeoIp__Directory` is set. -`docker build -t flypaper .` builds the image. +Details and project layout: [docs/development.md](docs/development.md). -| Project | Contents | -|---|---| -| `Flypaper.Core` | Protocol-independent core: sessions, governor, strategies, settings | -| `Flypaper.Http` | ASP.NET Core middleware, trap matching, forwarded headers | -| `Flypaper.GeoIp` | DB-IP download and lookups | -| `Flypaper.Storage` | EF Core with SQLite, event writer, retention, dashboard queries | -| `Flypaper.Web` | Host, dashboard and settings (Blazor static SSR) | -| `Flypaper.Tests` | xUnit, NSubstitute, Shouldly | +## Versions -## Attribution +Use `:latest` for the newest release or pin `:X.Y.Z`; changes are listed in +[CHANGELOG.md](CHANGELOG.md), tags and updates in [docs/releases.md](docs/releases.md). The +author's own Unraid deployment lives in [`deploy/unraid/`](deploy/unraid). -- [IP Geolocation by DB-IP](https://db-ip.com), licensed under - [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The dashboard shows this - attribution in its footer. -- The world map is generated from [Natural Earth](https://www.naturalearthdata.com) data - (public domain). +## Attribution and license -## License - -[MIT](LICENSE). Third-party data keeps its own license (see *Attribution*). +[IP Geolocation by DB-IP](https://db-ip.com) ([CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)), +world map from [Natural Earth](https://www.naturalearthdata.com) (public domain). Flypaper is +[MIT](LICENSE) licensed; third-party data keeps its own license. diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..ca22b99 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,60 @@ +# Configuration + +## Data volume + +The container runs as a non-root user (UID 1654) and keeps everything under `/data`: the SQLite +database, the Data Protection keys for logins and the GeoIP databases. A named volume gets +the right owner automatically; for a bind mount, `chown 1654:1654` the host folder first (or +start the container as root once, as the [Unraid template](unraid.md) does). + +## Environment variables + +All optional. Read at startup; list entries need an index (`__0`, `__1`, ...). + +| Variable | Purpose | Default | +|---|---|---| +| `Flypaper__Admin__Password` | Fixes the dashboard password and disables the first-visit setup and the password change | set on first visit | +| `Flypaper__Http__TrustedProxies__0` | IP or CIDR of the reverse proxy allowed to set `X-Real-IP` / `X-Forwarded-For`; replaces the default | private networks | +| `Flypaper__Http__KnownHosts__0` | Hosts that are caught only on trap paths (`*.example.com` allowed), see [reverse proxy](reverse-proxy.md#what-to-send-to-flypaper) | none | +| `Flypaper__Ports__Trap` / `Flypaper__Ports__Dashboard` | Container ports | `8080` / `8081` | +| `ConnectionStrings__Flypaper` | SQLite database | `Data Source=/data/flypaper.db` | +| `Flypaper__DataProtection__KeysPath` | Keys for login cookies and forms | `/data/keys` | +| `Flypaper__GeoIp__Directory` | Folder for the DB-IP databases; empty disables GeoIP | `/data/geoip` | +| `Flypaper__Drip__MinDelay` / `MaxDelay` | Pause between chunks | `00:00:00.05` / `00:00:01` | +| `Flypaper__Drip__MinChunkSize` / `MaxChunkSize` | Bytes per chunk | `1` / `64` | +| `TZ` | Time zone for the dashboard | UTC | + +The defaults of the runtime settings below can also be set this way, e.g. +`Flypaper__MaxConnections`. Values saved on the settings page override them. + +## Runtime settings + +Changed on the dashboard's settings page, stored in the database, effective immediately. The +reset button removes all saved values. + +| Setting | Default | +|---|---| +| Trap paths (exact, or prefix with a trailing `*`) | `/.env`, `/.env.*`, `/.git/*`, `/.aws/*`, `/.DS_Store`, `/wp-login.php`, `/wp-admin/*`, `/xmlrpc.php`, `/phpmyadmin/*`, `/vendor/phpunit/*`, `/server-status`, `/actuator/*`, `/cgi-bin/*`, `/boaform/*` | +| Extra known hosts (merged with `KnownHosts`) | none | +| Maximum hold time per catch | `01:00:00` | +| Maximum connections overall | `1000` | +| Maximum connections per IP | `10` | +| Keep catches (days, `0` = forever) | `90` | +| Don't store catches from private networks | on | + +## Security and privacy + +- **Keep the dashboard internal.** Publish port `8081` only to your LAN or to localhost and + never forward it from your public proxy. +- **Finish the setup before the dashboard is reachable by anyone else.** Until a password is + set, whoever opens the dashboard first can set it. The setup page disappears once a password + exists. +- **Use a strong admin password** (at least 12 characters). Only a salted hash is stored. The + login runs over plain HTTP unless you put the dashboard behind TLS yourself. +- **The limits protect you, not the bots.** Every catch holds a socket in Flypaper and in your + proxy for up to the maximum hold time. Keep `MaxConnections` well below what your proxy can + handle (nginx: `worker_connections`), and keep the per-IP limit low so a single scanner + can't fill all slots. +- **An HTTPS catch-all is rarely worth it**, see [reverse proxy](reverse-proxy.md#what-to-send-to-flypaper). +- **Privacy.** Flypaper stores IP addresses, requested URLs and user agents. Keep retention + short if that matters in your jurisdiction. diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..d096b41 --- /dev/null +++ b/docs/development.md @@ -0,0 +1,27 @@ +# Development + +Requires the .NET 10 SDK. + +```bash +dotnet build +dotnet test +dotnet run --project src/Flypaper.Web +``` + +`dotnet run` starts in the Development environment: the dashboard is at + (password `dev`), the trap at , the database is +`src/Flypaper.Web/flypaper.db`, and GeoIP is off unless `Flypaper__GeoIp__Directory` is set. +`docker build -t flypaper .` builds the image. + +| Project | Contents | +|---|---| +| `Flypaper.Core` | Protocol-independent core: sessions, governor, strategies, settings | +| `Flypaper.Http` | ASP.NET Core middleware, trap matching, forwarded headers | +| `Flypaper.GeoIp` | DB-IP download and lookups | +| `Flypaper.Storage` | EF Core with SQLite, event writer, retention, dashboard queries | +| `Flypaper.Web` | Host, dashboard and settings (Blazor static SSR) | +| `Flypaper.Tests` | xUnit, NSubstitute, Shouldly | + +The files in [`deploy/unraid/`](../deploy/unraid) and `.gitea/workflows/` are the author's +personal deployment (Gitea Actions to Unraid) and release pipeline. They are an example only and +not needed to run Flypaper. diff --git a/docs/overview.md b/docs/overview.md new file mode 100644 index 0000000..431d223 --- /dev/null +++ b/docs/overview.md @@ -0,0 +1,66 @@ +# How Flypaper works + +Every server on the internet gets a steady stream of bots probing for `/.env`, `/.git/config`, +`/wp-login.php` and friends, usually sent to the bare IP address or to host names that don't +exist. Blocklists play whack-a-mole with addresses that change daily. Flypaper takes the +opposite approach: it lets the bot in and then answers very, very slowly. While a scanner waits +for an endless HTML page that trickles in a few bytes at a time, it isn't scanning someone +else, and every catch is logged with its origin for you to look at. + +```mermaid +flowchart LR + bot["Scanner bot"] -->|"GET /.env
Host: 203.0.113.7"| proxy["Reverse proxy"] + proxy -->|"known site"| apps["Your apps"] + proxy -->|"unknown host or trap path
+ X-Real-IP"| flypaper["Flypaper"] + flypaper -.->|"endless HTML,
a few bytes at a time"| bot + flypaper --> db[("SQLite:
catches, settings")] + you["You (LAN)"] -->|"dashboard, port 8081"| flypaper +``` + +1. Your reverse proxy keeps serving your real sites. Everything it has no site for (the + default/catch-all server) goes to Flypaper, optionally also a few bait paths on your real + domains. +2. Flypaper listens on two ports. Port `8080` is the trap: everything that arrives there is + caught. Port `8081` serves the dashboard and never traps; keep it inside your LAN. +3. A caught request gets `200 OK` and an endless, plausible-looking HTML page: random chunks + of 1 to 64 bytes with random pauses of 50 ms to 1 s in between. +4. A connection governor caps the number of catches overall and per IP and ends every catch + after a maximum hold time. If there is no free slot, the request gets a quick `404`. +5. When a catch ends, Flypaper logs one line and stores the event in SQLite, enriched with + country, city and network provider (ASN) from the free DB-IP databases. + +## Features + +- **Traps** for unknown hosts (catch-all) and for configurable trap paths such as `/.env`, + `/.git/*` or `/wp-login.php` +- **Slow delivery** of endless generated HTML with irregular timing +- **Limits**: maximum connections overall and per IP, maximum hold time per catch +- **Dashboard**: totals, a world map, top countries, providers, IPs and paths, the latest + catches with expandable details; login with an admin password +- **GeoIP**: country, city and ASN per catch from DB-IP Lite, downloaded and refreshed + monthly; existing catches are filled in once the databases are available +- **Settings page**: trap paths, extra known hosts, limits and retention, changed at runtime + without a restart +- **Retention**: old catches are deleted daily (90 days by default); catches from private + networks are not stored by default; buttons to delete private or all catches +- **One log line per catch**, so `docker logs` alone shows whether the trap works +- **Health endpoint** `/health` for container health checks (on the trap port it answers only + to private addresses) +- **No configuration needed to start**: one volume, two ports, the admin password is set on + first visit + +## Trying the trap locally + +```bash +curl -N http://localhost:8080/ +``` + +This catch comes from a private address and is therefore not stored; the log line ends with +`(not stored)`. + +## Attribution + +Origins come from [IP Geolocation by DB-IP](https://db-ip.com), licensed under +[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/); the dashboard shows this attribution +in its footer. The world map is generated from [Natural Earth](https://www.naturalearthdata.com) +data (public domain). diff --git a/docs/releases.md b/docs/releases.md new file mode 100644 index 0000000..4c37d0f --- /dev/null +++ b/docs/releases.md @@ -0,0 +1,40 @@ +# Versions, images and updates + +Flypaper follows [Semantic Versioning](https://semver.org); every release is listed in +[CHANGELOG.md](../CHANGELOG.md) and on the +[releases page](https://gitea.anticarnist.de/Tom/Flypaper/releases). The running version is +shown in the dashboard footer and in the first log line. + +All images live at `gitea.anticarnist.de/tom/flypaper` +([package page](https://gitea.anticarnist.de/Tom/-/packages/container/flypaper/latest)); no +login is needed to pull. + +| Image tag | Meaning | Platforms | +|---|---|---| +| `:latest` | The newest release. The right choice for most setups. | amd64, arm64 | +| `:X.Y.Z` | A fixed release, e.g. `:0.1.0`. Pin it if you update deliberately. | amd64, arm64 | +| `:X.Y`, `:X` | The newest release of that minor or major line, e.g. `:0.1`, `:0`. | amd64, arm64 | +| `:main` | Development build of the latest commit on `main`. May break. | amd64 | +| `:` | Development build of one commit (short SHA), e.g. for a rollback. | amd64 | + +arm64 covers e.g. a Raspberry Pi 4/5 with a 64-bit OS. + +Pull a fixed version with `docker pull gitea.anticarnist.de/tom/flypaper:0.1.0`. To build a +specific release from source instead: + +```bash +git checkout v0.1.0 +docker build --build-arg VERSION=0.1.0 -t flypaper:0.1.0 . +``` + +You can always build the current source yourself: clone the repository and replace the +`image:` line in your compose file with `build: .`, or run `docker build -t flypaper .`. + +## Updating + +Pull or rebuild the image and recreate the container +(`docker compose pull && docker compose up -d`). The database is migrated automatically on +start; back up the `/data` volume first. Before 1.0, a minor version may contain breaking +changes, so read the changelog. + +How releases are cut is described in [`deploy/unraid/README.md`](../deploy/unraid/README.md#releases). diff --git a/docs/reverse-proxy.md b/docs/reverse-proxy.md new file mode 100644 index 0000000..ec8a681 --- /dev/null +++ b/docs/reverse-proxy.md @@ -0,0 +1,153 @@ +# Behind a reverse proxy + +Flypaper is meant to sit behind the reverse proxy that already owns ports 80/443. The proxy +forwards to the trap port `8080`; the dashboard port `8081` is never forwarded. Two rules +apply to every proxy: + +- **Set `X-Real-IP`** (and `X-Forwarded-For`) to the client address. +- **Flypaper must trust the proxy.** By default it trusts every private network (`10/8`, + `172.16/12`, `192.168/16`, loopback, `fc00::/7`), which covers a proxy in a Docker network + or on the LAN. Headers from public addresses are ignored, so bots can't fake their address. + To narrow it down, set `Flypaper__Http__TrustedProxies__0` to the proxy's IP or subnet, e.g. + the Docker network's subnet: + + ```bash + docker network inspect -f '{{(index .IPAM.Config 0).Subnet}}' + ``` + +Also turn off response buffering for Flypaper, otherwise the proxy collects the drip and the +bot never sees it. Flypaper sends `X-Accel-Buffering: no`, which nginx honors. + +## What to send to Flypaper + +- **The catch-all server.** Requests for hosts you don't serve (mostly the bare IP) go to + Flypaper. This is where almost all scanners end up. +- **Optionally, trap paths on your real domains.** Forward only the bait paths, e.g. `/.env` + or `/wp-login.php`, from your real sites to Flypaper. Every request on the trap port is + caught, so nothing else is needed. + +*Known hosts* (optional) change this for hosts you list: on the trap port, a known host is +caught only on the configured trap paths, and its other paths get a plain `404` without being +logged. That is useful if your proxy forwards more than the bait paths of a real domain, for +example a whole location. Unknown hosts are always caught. The dashboard is never reachable +on the trap port. + +**An HTTPS catch-all is rarely worth it.** Scanners of unknown hosts mostly speak plain HTTP to +the bare IP, and an HTTPS catch-all would need a certificate for names you don't own. Let the +proxy reject unknown TLS handshakes instead (nginx: `ssl_reject_handshake on;`). + +## Nginx Proxy Manager + +Put Flypaper into the same Docker network as NPM (the examples use the container name +`flypaper`). + +1. **Settings → Default Site → Congratulations Page.** With this setting NPM writes no + default server of its own. Any other choice (404, redirect, HTML) creates one, and nginx + refuses to start with two default servers. +2. Create `/data/nginx/custom/http.conf` in the NPM container (on the host: inside NPM's + data volume): + + ```nginx + # Catch-all: every HTTP request whose Host matches no proxy host goes to Flypaper. + server { + listen 80 default_server; # the HTTP port NPM listens on inside its container + listen [::]:80 default_server; + server_name _; + + location / { + # A variable makes nginx resolve the name per request, so NPM still starts + # (and serves your sites) while the Flypaper container is down. + resolver 127.0.0.11 valid=30s; + set $flypaper http://flypaper:8080; + proxy_pass $flypaper; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_buffering off; + proxy_read_timeout 1h; + } + } + ``` + +3. Test and reload: `docker exec nginx -t`, then + `docker exec nginx -s reload`. +4. Optional trap paths on a real domain: in the proxy host's **Advanced** tab add + + ```nginx + location ~* ^/(\.env|\.git/|wp-login\.php|xmlrpc\.php) { + resolver 127.0.0.11 valid=30s; + set $flypaper http://flypaper:8080; + proxy_pass $flypaper; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_buffering off; + } + ``` + +To undo the catch-all, delete `custom/http.conf` and reload. + +## Plain nginx + +Remove any existing `default_server` (on Debian/Ubuntu often `sites-enabled/default`) and add + +```nginx +server { + listen 80 default_server; + listen [::]:80 default_server; + server_name _; + + location / { + proxy_pass http://127.0.0.1:8080; # or a variable + resolver for a Docker name, see NPM + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_buffering off; + proxy_read_timeout 1h; + } +} +``` + +With Flypaper on the same host, nothing else is needed: loopback is trusted by default. + +## Caddy + +```caddyfile +# Catch-all for every host on port 80 without its own site block +:80 { + reverse_proxy flypaper:8080 { + header_up X-Real-IP {remote_host} + flush_interval -1 + } +} + +# Optional trap paths on a real site +example.com { + @trap path /.env /.git/* /wp-login.php /xmlrpc.php + reverse_proxy @trap flypaper:8080 { + header_up X-Real-IP {remote_host} + flush_interval -1 + } + reverse_proxy your-app:8080 +} +``` + +## Traefik + +Traefik sets `X-Real-Ip` and `X-Forwarded-For` by default. Labels on the Flypaper container +(Traefik v3): + +```yaml +labels: + traefik.enable: "true" + # Lowest priority: matches only hosts no other router claims + traefik.http.routers.flypaper-catchall.rule: "HostRegexp(`.+`)" + traefik.http.routers.flypaper-catchall.entrypoints: web + traefik.http.routers.flypaper-catchall.priority: "1" + # Optional trap paths on a real site + traefik.http.routers.flypaper-bait.rule: "Host(`example.com`) && (Path(`/.env`) || PathPrefix(`/.git/`) || Path(`/wp-login.php`))" + traefik.http.routers.flypaper-bait.priority: "1000" + traefik.http.services.flypaper.loadbalancer.server.port: "8080" +``` diff --git a/docs/unraid.md b/docs/unraid.md new file mode 100644 index 0000000..4a67b98 --- /dev/null +++ b/docs/unraid.md @@ -0,0 +1,35 @@ +# Unraid + +[`unraid/flypaper.xml`](../unraid/flypaper.xml) is a Docker template for Unraid. It sets up both +ports, the appdata folder `/mnt/user/appdata/flypaper` and the optional variables (under +*Show more settings*). + +1. Copy the template to the flash drive, in the Unraid terminal: + + ```bash + wget -O /boot/config/plugins/dockerMan/templates-user/my-Flypaper.xml \ + https://gitea.anticarnist.de/Tom/Flypaper/raw/branch/main/unraid/flypaper.xml + ``` + +2. **Docker → Add Container**, pick *Flypaper* under the user templates, choose free host ports + (8080 is often taken on Unraid) and **Apply**. +3. Open the WebUI (the dashboard port) and set the admin password. + +Unraid can also read templates from a *template repository* (Docker tab, Advanced View), but +that feature is built around GitHub repositories and may not accept this Gitea URL; the manual +copy above always works. + +The template starts the container as root (`--user 0:0`) only so it can hand the appdata folder +to its app user; Flypaper then drops to UID 1654 for good. Without it, a freshly created appdata +folder belongs to root and the database cannot be created. + +## Connecting Nginx Proxy Manager + +Follow the [NPM section](reverse-proxy.md#nginx-proxy-manager). If NPM runs in a user-defined +Docker network (e.g. `proxynet`), put Flypaper into the same network (*Network Type* in the +template) and use `http://Flypaper:8080` as the target. If NPM can't share a network with it, +forward to `http://:` instead. Either way the request comes from a +private address, which Flypaper trusts by default. + +The template is not part of the official Community Applications yet; that needs a separate +submission.