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

flowchart LR
    bot["Scanner bot"] -->|"GET /.env<br/>Host: 203.0.113.7"| proxy["Reverse proxy"]
    proxy -->|"known site"| apps["Your apps"]
    proxy -->|"unknown host or trap path<br/>+ X-Real-IP"| flypaper["Flypaper"]
    flypaper -.->|"endless HTML,<br/>a few bytes at a time"| bot
    flypaper --> db[("SQLite:<br/>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

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.

docker run -d --name flypaper --restart unless-stopped \
  -p 8080:8080 -p 127.0.0.1:8081:8081 \
  -v flypaper-data:/data \
  gitea.anticarnist.de/tom/flypaper:latest

Or with Compose:

services:
  flypaper:
    image: gitea.anticarnist.de/tom/flypaper:latest
    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
    volumes:
      - flypaper-data:/data

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 ..

  • Dashboard: http://localhost:8081. 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:

    curl -N 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/ 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.

Versions and updates

Flypaper follows Semantic Versioning; every release is listed in CHANGELOG.md. The running version is shown in the dashboard footer and in the first log line.

Image tag Meaning
:latest The newest release. The right choice for most setups.
:X.Y.Z A fixed release, e.g. :0.1.0. Pin it if you update deliberately.
:X.Y, :X The newest release of that minor or major line.
:main Development build of every commit on main. May break.

Pull a fixed version with docker pull gitea.anticarnist.de/tom/flypaper:0.1.0. To build a specific release from source instead:

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:

    docker network inspect <network> -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):

    # 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 <npm-container> nginx -t, then docker exec <npm-container> nginx -s reload.

  4. Optional trap paths on a real domain: in the proxy host's Advanced tab add

    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

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, nothing else is needed: loopback is trusted by default.

Caddy

# 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):

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

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
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. 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.

Development

Requires the .NET 10 SDK.

dotnet build
dotnet test
dotnet run --project src/Flypaper.Web

dotnet run starts in the Development environment: the dashboard is at http://localhost:5248 (password dev), the trap at http://localhost:5247, 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

License

MIT. Third-party data keeps its own license (see Attribution).

S
Description
Self-hosted tarpit that traps and slows down scanning bots, with event logging and analysis.
Readme MIT
1.5 MiB
0 Stars 1 Watchers 0 Forks
2026-12-03 22:27:35 +01:00
Languages
C# 80.1%
HTML 13.1%
CSS 5%
JavaScript 1.4%
Dockerfile 0.3%