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

┌─────────────────────────────────────────────┐
│               User (CLI)                    │
└───────────────────┬─────────────────────────┘

┌───────────────────▼─────────────────────────┐
│           Command Layer                     │
│   cmd/root.go  +  internal/cli/*            │
│   (Cobra commands, flag parsing)            │
└───────────────────┬─────────────────────────┘

┌───────────────────▼─────────────────────────┐
│           Application Core                  │
│          internal/app/                      │
│   (global state, auth options, context)     │
└──────┬────────────────────────┬─────────────┘
       │                        │
┌──────▼──────┐       ┌─────────▼──────────────┐
│   Module    │       │    Protocol Layer       │
│   Layer     │       │  internal/protocols/    │
│ internal/   │       │  (Kerberos, NTLM,       │
│ modules/    │       │   PKINIT, ADWS, ARP)    │
└──────┬──────┘       └─────────┬───────────────┘
       │                        │
┌──────▼────────────────────────▼───────────────┐
│               Library Layer                   │
│             internal/lib/                     │
│  (DN parsing, PKI, DCE/RPC, AD utilities,     │
│   encoding, Windows registry)                 │
└──────────────────────┬────────────────────────┘

┌──────────────────────▼────────────────────────┐
│            Storage Layer                      │
│   internal/db/    +   internal/vault/         │
│   (Badger KV store + SQLite via GORM)         │
└───────────────────────────────────────────────┘

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.
ModuleKey Operations
ldapLDAP bind, search, modify, create, delete
adcsCA enumeration, ESC detection, certificate requests
adwsADWS protocol for AD queries
adidnsADIDNS record enumeration and modification
kerberosAS-REQ, TGS-REQ, PKINIT, S4U2Self/S4U2Proxy
smbSMB dial, share enumeration, signing checks
rpcDCE/RPC null sessions and named pipe access
sprayMulti-protocol credential spraying
coerceMS-EFSRPC, MS-DFSNM, MS-RPRN, MS-EVEN6, MS-FSRVP coercion
bloodhoundBloodHound collection via LDAP + SMB + RPC
parseLog and data file parsing
ticketsKerberos ccache and kirbi manipulation
sshSSH authentication and command execution
rdpRDP authentication testing
winrmWinRM authentication and command execution
mssqlMSSQL authentication and enumeration
nfsNFS share enumeration
ftpFTP authentication and enumeration
serversHost/service discovery
portsPort scanning
wmiWMI 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 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/)

PackagePurpose
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

PackagePurpose
github.com/spf13/cobraCLI framework
gorm.io/gormORM for SQLite
github.com/glebarez/sqlitePure Go SQLite driver
github.com/dgraph-io/badger/v3Embedded KV store
golang.org/x/cryptoCryptography primitives
go.uber.org/zapStructured logging
github.com/charmbracelet/bubbleteaTUI components (interactive mode)
github.com/fatih/colorTerminal color output
github.com/KrakenTech-LLC/gokrb5Kerberos implementation
github.com/KrakenTech-LLC/el-dapLDAP with obfuscation support
github.com/KrakenTech-LLC/goerceCoercion 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
All concurrent operations share a cancellable context.Context from the App struct, allowing clean shutdown on interrupt.

Data Flow: A Typical LDAP Query

r4t ldap get users -u jsmith -p 'P@ssw0rd' -d corp.example.com


cmd/root.go  →  internal/cli/ldap/ldap.go

         ▼  (resolve auth + target)
cmd/helpers.go  →  internal/app/app.go (populate App struct)


internal/modules/ldap/  (construct LDAP filter, execute search)


github.com/KrakenTech-LLC/el-dap  (LDAP bind + search)


internal/modules/ldap/  (parse results into vault structs)


internal/db/sql.go  (upsert results into SQLite)


internal/system/stdout/  (render table to terminal)