README.md

README.md

Amber Guard Laboratory

Project: Autonomous defense complex for Linux hosts on Go 1.21+. Single binary agl, three daemon modes + interactive TUI panel.

Key circuits:

  • Tar Pit (Tarpit) — base trap on port 22 + multi-trap pool, managed by a single daemon via declarative inventory.
  • Perimeter Armor (Armor) — rate-limit defense lines via UFW, auto-service discovery, kernel tuning (sysctl).
  • Port Castling (Castling) — SSH relocation to a hidden port with backup and rollback.
  • Rescue Channel (Web Rescue) — HTTPS web-knock server (pseudo-2FA), three protection levels (Options A, B, C).
  • Idle Watcher (Watcher) — incineration of temporary doors on idle timeout.
  • Server Auto-update — oneshot apt-get dist-upgrade via systemd timer.
  • Geo-analytics (GEO) - autonomous in-memory engine for countries/cities/ASN instead of the external geoiplookup utility; update under administrator control
  • Forensics and Inventory — scanning /proc, ss, correlation.

Architectural principles: declarative management, fail-closed, three-factor status, layering (TUI → service → protocol), full autonomy, i18n via dictionaries, external commands exclusively via sys.RunTimeout, config mutations exclusively via config.Update(), paths via config/paths.go.

Brief characteristics of the complex

Amber Guard Lab. (AGL) — an autonomous defense complex for Linux hosts (Ubuntu/Debian; Go, TUI, single binary). Not a “lock on the door”, but an active defense ecosystem: detects, deceives, exhausts, protects, rescues, and collects digital fingerprints (metrics) of the attacker (30 parameters).

Features

  • Tar Pit (Tarpit) — SSH trap with variable delays; base trap on port 22 + declarative multi-trap pool managed by a single daemon.
  • Perimeter Armor (Armor) — auto-service discovery and UFW rate-limit defense lines with corporate signatures; self-healing after reboot via reconciliation circuit (Reconcile Armor).
  • Port Castling (Castling) — SSH relocation to a hidden port with auto-backup, rollback, local loopback emergency hatch, and accessibility rule for the moved port (inherits port 22 access type). Lock: castling is rejected if armor is live on port 22.
  • Rescue Channel (Web Rescue) — autonomous HTTPS web-knock server (web gateway) with TLS 1.2+ and bcrypt password: access even with a closed perimeter. Three protection levels:
    • Option A (ssh_allow_in_from_ip): permanent admin door — IP whitelist on the hidden port.
    • Option B (ssh_ip_web_knock): web-knock with incineration of temporary doors on admin idle timeout. Requires Option A.
    • Option C (web_https_panel_active): web panel availability (route /dashboard/overview).
    • Channel is active only when matched: castling ∧ enabled HTTPS server ∧ enabled Option B.
    • Cryptographic route prefixes (12 hex characters): /hash/rescue, /hash/dashboard/overview.
  • Idle Watcher (Watcher) — session detection via /var/run/utmp and “incineration” of temporary doors on admin idle. Lifecycle follows the physical server (web_server_enabled); when the server is disabled, the process terminates itself. Port castling does not affect the watcher lifecycle.
  • Forensics — SIEM chronicle of touches and exhaustion: countries (own geo engine), behavior, extended TCP fingerprints of scanners (30 columns: MSS, RTT, retransmits, IAT statistics, read size buckets, close reason). Log format unchanged: 30 fields, country names in full canonical form, using the vocabulary of previous versions.
  • Geo-analytics (GEO) - an autonomous in-memory directory of countries, cities and ASN. Replaces the external geoiplookup utility: there are no external processes or geolocation timeouts in the trap hot path. The database is compiled into its own binary format TGEO and updated at the will of the administrator - according to a schedule or manually.
  • Server Auto-update (v8.4.0) — autonomous daily OS update cycle (apt-get dist-upgrade in noninteractive mode), reboot necessity detection, and delayed reboot; scheduled via systemd timer, declaratively enabled from SETTINGS.
  • Backup (v8.4.0) — asynchronous generation of three session files (system snapshot, package list, forensics logs) with FIFO rotation under disk shortage. Targets configured via /etc/amberguard/backup_targets.json.

Requirements

  • OS: Ubuntu 22.04+ / Debian 12+ (systemd, UFW, Netfilter)
  • Go: 1.21 or newer (Linux only)
  • Privileges: root (privileges for binding ports < 1024 and managing systemd)
  • Disk: ~1 GB free for the geo-base (geo.bin ≈ 410 MB; for the duration of the update, double the volume for the staging build is needed)
  • External geolocation dependencies: none. The geoip-bin / geoip-database packages are no longer required - the countries are determined by the complex’s own engine.

Build

make build

Build via Makefile injects version and timestamp via -ldflags:

  • VERSION (default v8.5.1, overridden via: make build VERSION=v8.5.2)
  • BUILD_TIME (UTC timestamp of build moment, RFC3339)

Bare go build without Makefile will leave version as dev — this is a marker of a non-release build.

Installation

sudo make install

Binary is copied to /opt/amberguard/agl. Configuration is created automatically on first launch. On first start, cryptographic route prefixes for web-knock are also generated, and logrotate config is installed.

Launch

TUI panel (interactive management)

sudo /opt/amberguard/agl

Trap daemon (systemd unit agld_tarpit.service) Managed automatically from TUI via tarpitctl. Manual launch:

sudo agl --tarpit-daemon

Idle watcher (systemd unit agld_watcher.service) Managed declaratively: alive as long as web_server_enabled toggle is on in SETTINGS; when server is off, process terminates itself. Port castling does not affect watcher lifecycle. Manual launch:

sudo agl --watcher

Server auto-update (systemd units agld_autoupdate.service / agld_autoupdate.timer) Managed declaratively: enabling auto_update_enabled toggle in SETTINGS creates units and activates timer; disabling stops and removes them. Manual run of one cycle:

sudo agl --autoupdate

CLI Flags

# During installation, the installer creates symbolic links.
# CLI flags are invoked using the command `agl --FLAG`.
agl --version      # Version and build timestamp
agl --info         # Interactive info panel (paths, statuses, rescue channel)
agl --info --plain # Plain text output for --info (no pseudo-graphics)
agl --autoupdate   # Oneshot OS update cycle (called by timer)
agl --geo-update   # Oneshot geo database build (scheduler, TUI, manual launch)
agl --lang ru|en   # Interface language for a one-time launch (not saved)

Launch modes

Mode Command Purpose
Trap daemon agl --tarpit-daemon Manager of ALL traps, log pipelines, IPC
Watcher agl --watcher 30-sec admin idle ticker, web-knock, rescue server
Auto-update (oneshot) agl --autoupdate Update cycle: apt-get update + dist-upgrade + reboot check
Geo-base (oneshot) agl --geo-update Downloading, hash checking and streaming build of geo.bin
TUI console agl (no flags) Interactive panel, does NOT start listeners
Version agl --version Version and build time
Info agl --info Interactive panel: rescue channel, services, paths, version

Directory structure

Path Purpose
/opt/amberguard/agl Executable binary
/etc/amberguard/config.json Central config
/etc/amberguard/tarpit_inventory.json Declarative trap inventory
/etc/amberguard/perimeter_inventory.json Perimeter inventory (auto-scan)
/etc/amberguard/backup_targets.json Backup targets
/etc/amberguard/certs/server.crt Web-knock TLS certificate (self-signed, 10 years)
/etc/amberguard/certs/server.key TLS private key (0600)
/var/lib/amberguard/states/ Persistent state markers
/var/lib/amberguard/states/agl_autoupdate_last_run Unix time of last successful update cycle
/var/lib/amberguard/states/agl_rescue_active Active rescue channel marker
/var/lib/amberguard/states/agl_rescue_ip_pending Admin IP detection pending marker
/var/lib/amberguard/states/agl_moved_rule_type Moved port rule type (allow/limit/reject)
/var/lib/amberguard/geo/geo.bin Compiled geo database in TGEO format
/var/lib/amberguard/geo/geo_receipt.json Build receipt: source hashes, counters, time
/var/log/amberguard/amberguard.log Main log (logrotate)
/var/log/amberguard/tarpit_connection.log Socket touches
/var/log/amberguard/tarpit_report.log Forensic chronicle (30 columns)
/var/run/amberguard/ Runtime (flock uniqueness safeguards)
/var/run/amberguard/agl_geo_update.lock flock for geo-update single-flight
/dev/shm/amberguard.counter IPC bot counter in trap
/dev/shm/agl_proto_web_rescue/ Web-knock directory (tmpfs, 0700)
/etc/systemd/system/agld_tarpit.service Trap daemon unit
/etc/systemd/system/agld_watcher.service Watcher unit (Restart=on-failure)
/etc/systemd/system/agld_autoupdate.timer Auto-update schedule (created declaratively)
/etc/logrotate.d/amberguard Log rotation config (created on first start)

Server Auto-update

Toggles in SETTINGS (SYSTEM group): auto_update_enabled and auto_update_reboot — binary switches, inverted with ←/→ arrows. When enabled, AGL declaratively creates agld_autoupdate.service (Type=oneshot) and agld_autoupdate.timer (daily at 04:00 + random jitter up to 1 hour, Persistent=true); when disabled — stops and removes them. Cycle: apt-get update → package count via simulate → apt-get dist-upgrade -y (DEBIAN_FRONTEND=noninteractive, force-confdef/confold) → check /var/run/reboot-required. Delayed reboot via shutdown -r +1 is executed only if auto_update_reboot is enabled; otherwise, the event is logged, administrator reboots manually. Parallel launches are excluded by flock-lock; all events are written to the main log under component AUTOUPDATE.

Geo-analytics (GEO)

Autonomous in-memory engine for countries, cities and ASNs. Replaces the external geoiplookup utility: there are no longer external processes and geolocation timeouts in the trap hot path.

The doctrine of “lazy enrichment”

The forensic log remains “thin”: 30 fields, format unchanged. In the country field, the full canonical name is written exactly in the dictionary that was used by the previous engine (Russian Federation, United States, Iran, Korea…). The city, ASN, provider and coordinates are not written to the log - they are added at the reading stage. Old logs and accumulated statistics remain compatible: there is no need to erase the history.

Two modes — memory economy

Process Mode What’s in RAM Purpose
agld_tarpit country country block only (~23 MB) search for country when writing log, zero-alloc
agld_watcher full header + string-pool offset table (~2 MB) ranges are read from disk using pread; hot pages are held in the reclaimable OS page cache

City and ASN ranges are not loaded into the daemon heap - this is important for a host with 1 GB of RAM. Enrichment of the panel (city/ASN/coordinates in reports) is the next stage of development.

Sources and integrity

Data - open releases of the sapics/ip-location-db project (without registration and API keys): cities dbip-city-ipv4/ipv6.csv.gz (monthly), ASN origin-asn-ipv4/ipv6.csv (daily from BGP/RIR).

Two-level integrity control:

  • primary source — sha256, calculated by GitHub when uploading an asset (assets[].digest in the release API);
  • advisory — the official upstream .sha256 upstream. The discrepancy is logged as WARNING, but does not block the update: these hashes go stale for the upstream city files.

The build goes to a staging file and only after checking the hashes and checking for anomalies (empty base, jump in the number of ranges ×2/÷2 relative to the previous build) does it atomically replace the live database (tmp → fsync → rename). Any failure leaves the previous base intact.

Untrusted-data parser safeguards: caps on downloaded and decompressed volume (gzip-bomb protection), row-count limit, broken-row threshold (>1% → reject), range sortedness validation, string sanitization (valid UTF-8, no control characters). Raw CSVs are not written to disk.

Update under administrator control

  • Auto-update is disabled by default. Toggle switches in SETTINGS (SYSTEM group): geo_auto_update (0/1, arrows ←/→) and geo_update_hour (check hour 0–23).
  • Manual update: GEO: UPDATE DATABASE NOW button in SETTINGS or sudo agl --geo-update.
  • First launch: if there is no database, TUI offers to download it (~120 MB of traffic). Declining does not block operation: the countries in the logs will be Unknown.
  • The scheduler lives in the watcher and checks sources at a given hour; if the hashes have not changed, the download is skipped and traffic is not wasted.
  • The heavy build is moved into a short-lived child process: daemons never see the memory peak. Tarpit picks up the finished database via mtime on its 15-second reconciliation tick; the watcher on its one-minute tick.
  • Parallel launches are excluded by flock-lock. All events are written to the main log under the GEO component.

Panel only reads

The web panel is not a control panel: only GET routes are available from the browser (including api/geo/status - database readiness and build receipt). Commands that change the state of the server are not accepted from the browser: this removes a whole class of attacks during session hijacking. All control is only through the settings menu inside the complex.

Data licenses

The DB-IP city database is distributed under CC BY 4.0 and requires a link to the source when displaying results. The origin-asn database is PDDL (no attribution required). See NOTICE.

Backup

Launched from TUI (BACKUP menu). Asynchronous generation of three files into session directory /backup/YYYY.MM.DD_HH.MM/. Files: *_server_snapshot.tar.gz (system configs), *_package_list.txt (dpkg), *_forensics_logs.tar.gz (SIEM logs). Targets configured via /etc/amberguard/backup_targets.json (created automatically with defaults). FIFO rotation: under disk shortage (<15%), old sessions are deleted automatically.

Principles (Product DNA)

  • Declarative management: admin writes intent — daemon brings system to fact (reconciliation loop, self-healing).
  • Fail closed: any failure drops system to safe state, never to open.
  • Three-factor status: declaration → daemon confirmation → fact on disk.
  • Full autonomy: no external web servers or clouds; one binary — entire perimeter.
  • Uniqueness safeguards: flock-locks for daemon modes; second instance dies with ALERT.
  • POSIX Atomic Write: all disk commits via tmp → fsync → rename.

Disclaimer

For test and isolated servers only. The complex modifies system configurations (sshd_config, UFW, sysctl), creates systemd units and manages network rules. Before installing on a production host:

  • Ensure you understand the consequences of each operation
  • Have a backup access channel (web-knock rescue channel or physical console access)
  • Test in an isolated environment
  • Make a full system backup

The authors are not responsible for any damage arising from the use of this software.

License

GNU AGPLv3 — see LICENSE file for details. Running a modified version as a network service requires publishing your source. Use at your own risk. The authors are not responsible for any damage arising from the use of this software.

Описание
Amber Guard Lab. (AGL) — Автономный оборонный комплекс для Linux-хоста (Ubuntu/Debian; Go, TUI, один бинарник). Не «замок на двери», а экосистема активной обороны: обнаруживает, обманывает, истощает, защищает, спасает и собирает цифровые отпечатки (метрики) атакующего (30 параметров).
Конвейеры
0 успешных
0 с ошибкой
Разработчики