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 domainNameserver— DNS nameserverTimeout/Jitter— connection timingProxy— SOCKS5 proxy settings- Auth options per protocol: LDAP, Kerberos, NTLM, PKINIT, SMB, RDP, SSH, WinRM, TFTP
- Output file handle (for
--teemode) - 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 utilitiespki/— Certificate generation, PFX parsing, key operationsdce/— DCE/RPC stub and NDR utilitiesregistry/— Windows registry accessencoding/— Base64, hex, and AD-specific encodingext/— 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 helpersinternal/vault/structs.go— All 60+ GORM model definitionsinternal/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
context.Context from the App struct, allowing clean shutdown on interrupt.

