# 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. ## How it works ```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 host"| 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 looks at the `Host` header. A request for a host it doesn't know, or for a trap path, is caught. Requests for a known host (the dashboard's) pass through to the dashboard. 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 (answers only to private addresses) ## Quick start There is no public image; build it from source. ```bash git clone flypaper cd flypaper ``` Create a `compose.yaml` next to the `Dockerfile`: ```yaml services: flypaper: build: . image: flypaper:local container_name: flypaper restart: unless-stopped ports: - "8080:8080" environment: TZ: Europe/Berlin # Host names that reach the dashboard. Every other Host header is trapped. Flypaper__Http__KnownHosts__0: localhost # The reverse proxy that sets X-Real-IP (IP or CIDR), see below. Flypaper__Http__TrustedProxies__0: 172.16.0.0/12 Flypaper__Admin__Password: ${FLYPAPER_ADMIN_PASSWORD:?set FLYPAPER_ADMIN_PASSWORD} volumes: - flypaper-data:/data volumes: flypaper-data: ``` ```bash FLYPAPER_ADMIN_PASSWORD='a-long-random-password' docker compose up -d --build ``` - Dashboard: , log in with the password. - See the trap in action (any unknown host works): ```bash curl -N -H "Host: example.invalid" http://localhost:8080/ ``` This catch comes from a private address and is therefore not stored; the log line ends with `(not stored)`. 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. ## Behind a reverse proxy Flypaper is meant to sit behind the reverse proxy that already owns ports 80/443. Two rules apply to every proxy: - **Set `X-Real-IP`** (and `X-Forwarded-For`) to the client address. - **Trust the proxy in Flypaper**: `Flypaper__Http__TrustedProxies__0` must contain the proxy's IP or subnet. Headers from anyone else are ignored, so bots can't fake their address. For a Docker network: ```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. Your domains are unknown to Flypaper, so these requests are caught as well. Never forward a whole domain that is listed as a known host: its other paths would show the dashboard login. ### 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 ```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 above 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, `TrustedProxies` can stay empty: 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" ``` ## Configuration ### Environment variables Read at startup. List entries need an index (`__0`, `__1`, ...). | Variable | Purpose | Default | |---|---|---| | `Flypaper__Http__KnownHosts__0` | Host names that reach the dashboard (`*.example.com` allowed). Every other host is trapped. | none | | `Flypaper__Http__TrustedProxies__0` | IP or CIDR of the reverse proxy allowed to set `X-Real-IP` / `X-Forwarded-For` | loopback only | | `Flypaper__Admin__Password` | Dashboard password. Without it the dashboard stays locked. | none | | `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 notes - **Keep the dashboard internal.** Only list internal names or LAN addresses as known hosts and never route a known host through your public proxy. - **Use a strong admin password.** 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. ## 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 (known host `localhost`, password `dev`), 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 | ## Attribution - [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). ## License To be decided. The project does not have a license yet.