Skip to main content

Architecture

R4t is a layered Go application. Each layer has a clear responsibility and only depends on layers below it.

Layer Overview


Component Breakdown

Command Layer (cmd/ + internal/cli/)

The entry point is rat.go, which delegates immediately to cmd.Execute(). The root command (cmd/root.go) registers all 32+ top-level subcommands and declares persistent flags that propagate to every command. Each top-level command has a corresponding implementation in internal/cli/<name>/. The CLI layer is responsible for:
  • Parsing flags and arguments
  • Validating inputs
  • Resolving targets and credentials (stored or inline)
  • Calling into the module layer
  • Formatting and printing results
cmd/helpers.go contains shared initialization logic including:
  • Authentication resolution (inline flags → stored credential → anonymous)
  • LDAP connection setup
  • Domain and nameserver resolution
  • Database initialization and migration

Application Core (internal/app/)

internal/app/app.go holds the global App struct that is threaded through all module calls. It carries:
  • Domain — the active AD domain
  • Nameserver — DNS nameserver
  • Timeout / Jitter — connection timing
  • Proxy — SOCKS5 proxy settings
  • Auth options per protocol: LDAP, Kerberos, NTLM, PKINIT, SMB, RDP, SSH, WinRM, TFTP
  • Output file handle (for --tee mode)
  • Context and cancellation

Module Layer (internal/modules/)

23+ specialized modules implement the actual exploitation and enumeration logic. Each module receives an App struct and handles its own protocol connections.

Protocol Layer (internal/protocols/)

Low-level protocol implementations that modules build on:
  • Kerberos — AS-REQ/AS-REP, TGS-REQ/TGS-REP via gokrb5
  • NTLM — NTLM authentication flows
  • PKINIT — Public key Kerberos authentication
  • ADWS — Active Directory Web Services (SOAP over .NET)
  • ARP — ARP table manipulation
  • NBFS/NBFX — NetBIOS framing

Library Layer (internal/lib/)

Utility code shared across modules:
  • ad/ — DN parsing, object identifier resolution, SID/RID utilities
  • pki/ — Certificate generation, PFX parsing, key operations
  • dce/ — DCE/RPC stub and NDR utilities
  • registry/ — Windows registry access
  • encoding/ — Base64, hex, and AD-specific encoding
  • ext/ — Extended AD function wrappers

Storage Layer (internal/db/ + internal/vault/)

R4t uses a dual-storage architecture. See Database for full details.
  • internal/db/badger.go — Badger KV store (encrypted, compressed, fast)
  • internal/db/sql.go — SQLite via GORM (relational, persistent)
  • internal/db/queries.go — Shared query helpers
  • internal/vault/structs.go — All 60+ GORM model definitions
  • internal/vault/tableNames.go — Table name constants

Supporting Systems (internal/system/)


Key Dependencies


Concurrency Model

R4t uses Go goroutines for parallelism in operations that benefit from it:
  • Spraying — configurable thread count (--threads) with synchronized result collection
  • Coercion — configurable concurrent coercion attempts
  • BloodHound collection — configurable worker pool (--workers)
  • Port scanning — concurrent scanning
All concurrent operations share a cancellable context.Context from the App struct, allowing clean shutdown on interrupt.

Data Flow: A Typical LDAP Query