Skip to content

Feature Request: Optional fail2ban Integration #329

Description

@Humble-Helper-96

The Problem

A production OpenTAKServer running on a server with a public IP receives a continuous, high volume of unsolicited probe traffic against the nginx-facing ports (80, 443, 8443, 8446). On my deployment, in a representative 24-hour window I observed roughly 800+ remote HTTP requests from over 100 unique source IPs, with the bulk concentrated in three families of scanners:

  • Asus router exploit scanners hitting /SETTINGS.CFG, /login.cgi, and /appGet.cgi?hook=get_cfg_clientlist() with the asusrouter-- user agent
  • Generic CGI/path-traversal probes against URLs like /cgi-bin/.%2e/.%2e/.%2e/bin/sh
  • Censys/Shodan-style inventory scanners

All of these are rejected by nginx with a 400 response and never reach OTS itself — so functionally my server is fine. But the noise has practical costs:

  1. AbuseIPDB shows the top two scanner IPs in my logs (a /24 in Romania, ASN 47890) have each been reported over 4,000 times. This is not background internet noise — it's targeted, persistent, automated probing that will not stop on its own.
  2. The eud_handler_ssl.log fills with PEER_DID_NOT_RETURN_A_CERTIFICATE SSL handshake warnings every few minutes from scanners hitting :8443 without a client cert. This obscures real SSL issues with legitimate EUDs.
  3. The nginx access log grows much faster than it would otherwise, making forensic review harder and chewing through disk on smaller deployments.
  4. Every probe consumes a small amount of CPU and a TLS handshake. Multiplied by hundreds per day across multiple scanners, this is a measurable load on smaller hardware (RPi installs especially).

A standard, well-understood remediation for this exists — fail2ban — and it's already a dependency-friendly addition on every platform OTS currently supports. But setting it up correctly requires knowing the OTS log file paths, the nginx access log location, what a legitimate vs. malicious request looks like, and which ports to protect. None of that is documented in the OTS install path today, so most operators either don't deploy it or set it up incorrectly.

Proposed Solution

Add optional fail2ban integration to the OpenTAKServer installer (OpenTAKServer-Installer). On supported platforms, the installer would:

  1. Prompt the user (or accept a CLI flag like --install-fail2ban) to enable fail2ban integration during the OTS install
  2. Install fail2ban if not already present
  3. Drop in OTS-specific filter files and a jail config that fail2ban can pick up automatically
  4. Pre-populate sensible defaults for the threshold/findtime/bantime that match the threat profile (persistent scanners with no legitimate use case → long bans)
  5. Add a documentation section in docs.opentakserver.io explaining what the jails do and how to tune them

The default config would protect the nginx-facing ports (80, 443, 8443, 8446) by banning IPs that generate excessive 400 responses from nginx. Legitimate ATAK/iTAK/WinTAK clients hit /Marti/api/... endpoints with 200/201/401 responses and would never trigger the filter. I have verified this on my own deployment across a representative sample of normal client traffic vs. scanner traffic — they are cleanly distinguishable by status code alone.

This would be opt-in since some operators run OTS behind their own WAF, reverse proxy, or VPN where fail2ban would be redundant or harmful.

Implementation Outline

Within the existing OTS ecosystem, this could be done with relatively few moving pieces:

OpenTAKServer-Installer changes

In ubuntu_installer, debian_installer, and raspberry_pi_installer:

  1. Add a step (after nginx config) that asks: "Install and configure fail2ban to protect OTS from internet scanners? [Y/n]" — or skip the prompt if --install-fail2ban / --no-fail2ban is passed
  2. If yes:
    • apt install -y fail2ban
    • Copy filter file to /etc/fail2ban/filter.d/opentakserver-nginx.conf
    • Copy jail file to /etc/fail2ban/jail.d/opentakserver.conf
    • Restart fail2ban

Filter file: /etc/fail2ban/filter.d/opentakserver-nginx.conf

[Definition]
# Match any 400 response in nginx access log for OTS-facing ports
# Legitimate TAK clients (ATAK/iTAK/WinTAK) hitting /Marti/api/* endpoints
# get 200/201/401 responses, not 400 - so this is scanner-specific.
failregex = ^<HOST> - .* "(GET|POST|HEAD|OPTIONS|PROPFIND|PRI) .* HTTP/.*" 400 .*$
ignoreregex =

Jail file: /etc/fail2ban/jail.d/opentakserver.conf

[opentakserver-nginx]
enabled = true
filter = opentakserver-nginx
action = iptables-multiport[name=ots-nginx, port="80,443,8443,8446", protocol=tcp]
logpath = /var/log/nginx/access.log
maxretry = 10
findtime = 3600
bantime = 30d

Defaults rationale

  • maxretry = 10 — Generous enough that legitimate misconfigured clients aren't penalized for a handful of bad requests; tight enough to catch determined scanners quickly
  • findtime = 1 hour — Matches the cadence of the most persistent scanners observed in the wild (typically one probe every 5–15 minutes)
  • bantime = 30 days — These scanners are not transient or accidental. They've been reported thousands of times across the internet. There is no benefit to a short ban; the same IP will return the moment the ban expires

Optional: second jail for EUD handler SSL probes

The EUD handler logs PEER_DID_NOT_RETURN_A_CERTIFICATE warnings to ~/ots/logs/eud_handler_ssl.log when scanners hit :8443 without a client cert. A second jail could ban on this pattern with similar thresholds. This would have to be configured carefully since the OTS logs live in the OTS user's home directory by default (~/ots/logs/), but fail2ban needs to be able to read them — either by symlinking into /var/log/opentakserver/ or by adjusting fail2ban's permissions config. The nginx-based jail alone catches roughly 90% of the scanner traffic in my observation, so this could be a phase-2 enhancement.

Documentation

Add a "Hardening" section to the docs covering:

  • What the fail2ban integration does and doesn't protect against
  • How to view currently banned IPs (fail2ban-client status opentakserver-nginx and iptables -L f2b-ots-nginx -n)
  • How to unban an IP if needed
  • How to whitelist trusted source IPs via ignoreip
  • How to disable the jail without uninstalling fail2ban
  • Note that this is a complement to, not a replacement for, proper OTS authentication and certificate-based EUD enrollment

Why This Is Worth Building In Rather Than Documenting

The pattern detection is mechanical and well-understood — every operator who deploys OTS to the public internet is going to face the same scanner traffic and benefit from the same configuration. Documenting it as a "highly recommended optional step" works, but most operators won't do it. Bundling it as an opt-in installer step makes secure-by-default deployment practical without sacrificing flexibility for operators who don't want it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions