Designing Agents That Survive C2 Burns
The most expensive moment in a red team engagement isn’t initial access. It’s re-doing initial access because you lost an implant to an infrastructure problem — not a detection, not a blue team response, but your own C2 server going down, a CDN provider rotating an IP, or a domain getting flagged by a threat intelligence feed.
Agent resilience isn’t glamorous like evasion techniques. Nobody writes conference talks about retry logic. But in real engagements, it’s the difference between a brief operational interruption and having to re-phish a target three weeks into an assessment.
The Problem: Agents Are Stateless Clients
A C2 agent is fundamentally an HTTP (or DNS, or SMB) client that polls a server. If the server is unreachable, the agent has two choices: keep trying the same address, or give up.
Most C2 frameworks ship with one callback URL. If that URL stops responding — server seized, domain sinkholed, cloud provider abuse report, CDN misconfiguration — every agent that depends on it goes dark. The operator has to burn the engagement’s initial access to redeploy new agents with a different callback address. If initial access was a carefully crafted phishing campaign, that’s days of work lost.
The problem isn’t that servers go down. The problem is that agents treat a single point of failure as the only option.
Multiple Callback URLs
The first line of defense is the simplest: don’t build agents with one callback address. Krait supports up to three callback URLs baked into the agent configuration at build time. The primary URL is tried first, with backup URLs activated on failure rotation.
This isn’t just a comma-separated list of servers. Each URL can point to a completely different infrastructure tier — the primary might be a domain-fronted CDN, the first backup a direct IP on a different cloud provider, the second backup a DNS-over-HTTPS transport on a third domain. The diversity matters because different takedown mechanisms affect different infrastructure: a domain seizure doesn’t affect an IP-based backup, and a cloud provider abuse report doesn’t affect a CDN.
The agent stores these URLs at build time and rotates between them automatically. No operator intervention required. The agent’s decision about when and how to rotate is where the design gets interesting.
Adding Backup URLs to Running Agents
Build-time URLs cover the planned case: you know your infrastructure layout before deployment and bake it in. But engagements evolve. You stand up a new redirector mid-operation. You move to a new cloud provider after the original gets flagged. You need to add a fallback to agents that are already deployed and checking in.
Krait’s set-backup-url command handles this. From the operator console, you can push a new backup URL to any running agent. The agent receives it as a task, writes it into its in-memory configuration alongside the existing URLs, and immediately includes it in the rotation pool. No rebuild, no redeployment, no touching disk.
This is operationally significant because infrastructure changes mid-engagement are the norm, not the exception. A redirector gets burned on day three — you stand up a replacement and push its address to all active agents in one command. Agents that were previously running with a single URL now have a backup they didn’t ship with. Agents that already had backups gain an additional failover tier.
The pushed URL participates in the same rotation, backoff, and abandon logic as build-time URLs. It can be abandoned later if it gets burned. It’s probed during primary recovery just like any other backup. From the agent’s perspective, there’s no distinction between a URL it was born with and one the operator added later — they’re all entries in the same rotation pool.
Failure Counting and Backoff
Naive retry logic — “if the server doesn’t respond, try again immediately” — creates two problems. First, it generates a burst of traffic that’s detectable in network monitoring: a process that makes 50 HTTP requests in 10 seconds to a dead host stands out. Second, if the server is temporarily overloaded rather than dead, hammering it with retries makes the problem worse.
Krait uses a configurable failure threshold before triggering any behavioral change. Below the threshold, the agent retries at its normal poll interval with standard jitter. It treats occasional failures as normal network noise — transient DNS resolution failures, packet loss, brief server restarts. No change in behavior, no escalation.
Once consecutive failures exceed the threshold, two things happen: the agent rotates to the next available callback URL, and it begins exponential backoff on the sleep interval. Each successive failure doubles the sleep time up to a configurable maximum. The sleep values are jittered to prevent all agents on the same server from synchronizing their retry bursts.
The exponential backoff serves two purposes. Operationally, it reduces the agent’s network footprint during disruptions — fewer callbacks means less observable traffic while the operator is working on restoring infrastructure. Tactically, it prevents the agent from burning through all its backup URLs too quickly. If the first backup is also down (perhaps the operator is rebuilding their entire infrastructure), the backoff gives the operator time to bring up at least one endpoint before the agent exhausts all options.
URL Rotation
When the failure threshold triggers rotation, the agent advances to the next URL in its list. If that URL also fails, it continues rotating — cycling through all available URLs before incrementing a “full rotation” counter.
The rotation is not random. It’s sequential and deterministic, which means the operator knows exactly which server a given agent will try next based on how many failures have occurred. This predictability is an operational feature: during an infrastructure crisis, the operator can prioritize bringing up the server that most agents will rotate to next, rather than guessing.
The agent tracks which URLs have been explicitly abandoned (more on that below) and skips them during rotation. If all URLs are abandoned, the agent stays on its current URL — which may be dead, but is the best option available.
Abandon URL: Intentional Infrastructure Teardown
Sometimes the operator needs to tear down a server deliberately. A domain appeared on a threat intel feed. A hosting provider received a law enforcement request. A CDN is being investigated. The operator needs to tell all agents: “stop talking to this address, permanently.”
Krait’s abandon-url task handles this. The operator issues a task targeting a specific URL index, and every agent that receives the task marks that URL as permanently abandoned. The agent won’t rotate back to it, won’t include it in failure rotation cycles, and won’t probe it (see below). From the agent’s perspective, that URL no longer exists.
This is different from the URL simply being unreachable. An unreachable URL might come back — the agent should keep it in rotation. An abandoned URL is a deliberate operator decision that the address is burned and should never be contacted again. The distinction matters because it affects whether the agent will probe the address during primary recovery.
Primary Server Probing
When an agent is running on a backup URL after rotating away from the primary, a question arises: should it ever try to go back?
The answer is yes, but carefully. The primary server might have been temporarily down — a restart, a brief outage, a network partition. Once it’s back, the operator wants agents to return to it without manual intervention, because the primary typically has the best infrastructure (domain fronting, CDN, traffic profiles).
Krait implements primary probing: periodically, while operating on a backup URL, the agent makes a single test request to the primary server. If it responds successfully, the agent switches back. If it fails, the agent stays on the backup and tries again later.
The probe interval is measured in successful poll cycles on the backup, not in wall-clock time. This means a fast-polling agent probes more frequently than a slow-polling one, which is the right behavior — an agent polling every 5 seconds on a backup is in an active operation that benefits from fast recovery, while an agent polling every hour on a backup is in a dormant state where probe frequency doesn’t matter.
Critically, if the primary URL has been explicitly abandoned via abandon-url, probing is disabled for that URL. The operator said stop talking to it — the agent listens, even for probes.
Transport Fallback
The most extreme resilience mechanism is transport fallback. If the agent has exhausted all HTTP/HTTPS URLs through multiple full rotation cycles, and if the build configuration includes a DNS domain, the agent can fall back to DNS-based C2.
This is a last resort. DNS transport is bandwidth-constrained, higher-latency, and operationally limited compared to HTTPS. But it uses a completely different network path — DNS queries go through the target’s configured DNS resolvers, not through direct HTTP connections. This means it survives scenarios that would kill all HTTP-based callbacks: an egress firewall rule blocking outbound HTTPS, a web proxy going down, or a network segmentation change that blocks direct IP connectivity.
The transport fallback threshold is deliberately high — the agent has to fail many consecutive rotation cycles before switching. This prevents premature fallback to DNS during brief outages, which would degrade the agent’s capability unnecessarily.
The Operator’s Perspective
All of this resilience logic runs autonomously on the agent. The operator doesn’t need to do anything for it to work — build the agent with backup URLs, and the agent handles the rest. But the operator can observe and influence the behavior:
The status command shows which URL an agent is currently using, how many consecutive failures it’s experienced, and whether any URLs have been abandoned. The operator can see at a glance which agents have rotated to backup infrastructure.
The abandon-url task lets the operator proactively remove a burned address from the rotation before agents discover it’s down. This is faster and cleaner than waiting for failure-based rotation, and it ensures agents don’t make even a single request to an address the operator knows is compromised.
The set-backup-url command lets the operator push new infrastructure to agents that are already running — no rebuild required. Stand up a new server, push its address, and every agent gains a new failover option within one poll cycle.
Why This Matters
In a week-long engagement against a mature SOC, infrastructure disruptions are not edge cases. Blue teams hunt C2 infrastructure. Threat intel feeds flag new domains. Cloud providers respond to abuse reports. A red team that loses all agent access every time a server goes down isn’t testing the organization’s security — it’s testing its own infrastructure management.
Resilience mechanisms don’t make agents undetectable. They make agents survivable. The agent still needs to evade EDR, still needs to blend into network traffic, still needs to avoid behavioral detections. But when the infrastructure behind it shifts — and it will — the agent adapts instead of dying.
Build agents with backup URLs. Push new ones mid-engagement with set-backup-url. Configure reasonable backoff thresholds. Use abandon-url when infrastructure is burned. And keep your DNS domain as a last-resort fallback.
Krait’s resilience features ship in every build. Configuration details at krait.red/docs/transports.