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.
| Module | Key Operations |
|---|---|
ldap | LDAP bind, search, modify, create, delete |
adcs | CA enumeration, ESC detection, certificate requests |
adws | ADWS protocol for AD queries |
adidns | ADIDNS record enumeration and modification |
kerberos | AS-REQ, TGS-REQ, PKINIT, S4U2Self/S4U2Proxy |
smb | SMB dial, share enumeration, signing checks |
rpc | DCE/RPC null sessions and named pipe access |
spray | Multi-protocol credential spraying |
coerce | MS-EFSRPC, MS-DFSNM, MS-RPRN, MS-EVEN6, MS-FSRVP coercion |
bloodhound | BloodHound collection via LDAP + SMB + RPC |
parse | Log and data file parsing |
tickets | Kerberos ccache and kirbi manipulation |
ssh | SSH authentication and command execution |
rdp | RDP authentication testing |
winrm | WinRM authentication and command execution |
mssql | MSSQL authentication and enumeration |
nfs | NFS share enumeration |
ftp | FTP authentication and enumeration |
servers | Host/service discovery |
ports | Port scanning |
wmi | WMI query execution |
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/)
| Package | Purpose |
|---|---|
dirs/ | Filesystem path management (~/.local/share/r4t/) |
stdout/ | Colorized output, table rendering, tree rendering |
logger/ | Structured logging with zap + log rotation via lumberjack |
edr/ | Windows Defender exclusion management |
errors/ | Shared error types |
Key Dependencies
| Package | Purpose |
|---|---|
github.com/spf13/cobra | CLI framework |
gorm.io/gorm | ORM for SQLite |
github.com/glebarez/sqlite | Pure Go SQLite driver |
github.com/dgraph-io/badger/v3 | Embedded KV store |
golang.org/x/crypto | Cryptography primitives |
go.uber.org/zap | Structured logging |
github.com/charmbracelet/bubbletea | TUI components (interactive mode) |
github.com/fatih/color | Terminal color output |
github.com/KrakenTech-LLC/gokrb5 | Kerberos implementation |
github.com/KrakenTech-LLC/el-dap | LDAP with obfuscation support |
github.com/KrakenTech-LLC/goerce | Coercion protocol implementations |
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.

