MACHINE LEARNING
2026-04-13

C2 Beaconing Detection with Machine Learning

C2 beaconing still gets caught the same way it did ten years ago in most environments - static thresholds, known IOCs, signature matches. That approach works right up until it doesn't, and modern C2 frameworks are specifically built to make sure it doesn't. Jitter, sleep obfuscation, traffic shaping, cloud fronting. Catching this kind of traffic has moved from a rules problem to a behavior problem, and that's where machine learning earns its place.

Command and control is one of the most important phases of an intrusion. Once an attacker has a foothold, holding reliable communication with their infrastructure is what makes everything else possible - lateral movement, staging, exfiltration, long-term persistence. Pull that channel and the rest of the operation starves.

Beaconing - the periodic callback from a compromised host to a C2 server - is the most common pattern behind that communication. For defenders, it should be one of the more detectable things in the attack lifecycle.

In practice, it usually isn't.

Why traditional C2 detection struggles

Most detection for C2 beaconing still leans on known indicators and static rules. Blocklists of malicious domains and IPs. Signature detection for documented frameworks. Threshold rules that flag connections repeating at suspiciously regular intervals.

These catch known threats. They don't catch anyone who's bothered to read a defender's playbook.

Cobalt Strike, Sliver, Brute Ratel, Nighthawk, Mythic - they all support configurable jitter, which randomizes callback intervals enough to break strict periodicity. Nighthawk in particular was built for evasion from the ground up. Sleep obfuscation, advanced traffic shaping, callback patterns that don't look like callbacks. Sleep timers get set to hours or days. Traffic gets routed through legitimate cloud services, CDNs, or domain-fronted through services nobody can reasonably block.

When the C2 traffic looks like a user checking a SaaS dashboard every six or seven minutes with some natural variation in timing, a threshold rule has nothing to latch onto. I've watched red teams run Cobalt Strike beacons through trusted CDNs for weeks in enterprise environments with a full stack of commercial detection in place. Nothing fired. The traffic pattern was just close enough to real that no static rule could distinguish it.

The gap is behavioral, not signature-based

This is the real limitation of traditional detection. Static rules work when the pattern is predictable and consistent. C2 beaconing is designed to be neither.

The signal is still there. It just doesn't live in signatures anymore - it lives in behavior. A compromised host reaching out to the same external endpoint with a semi-regular cadence, even with jitter, still produces a communication pattern that's different from normal user-driven traffic. The challenge is pulling that pattern out of the noise at scale.

Which is the kind of problem ML is actually good at.

What ML brings to beaconing detection

Machine learning doesn't replace traditional detection. It fills the gap static rules can't cover, by analyzing communication patterns across dimensions that are awkward or impossible to express as rule logic.

Frequency analysis is usually the strongest starting point. Even with jitter applied, beaconing still tends to show detectable periodicity when you look at it over time. Techniques based on frequency decomposition - FFT, autocorrelation, spectral analysis - surface repeating patterns that are invisible at the individual-connection level but obvious when you treat the traffic as a time series.

Beyond timing, there's a pile of behavioral features that matter. Consistency of payload sizes across sessions. Entropy of request and response content. Outbound-to-inbound byte ratio. Regularity of session duration. Whether the pattern tracks with user activity or keeps going during nights, weekends, and holidays - that last one has broken so many red-team engagements I've seen.

None of these is definitive on its own. But combined into a feature set and evaluated against a baseline of normal behavior for a given host or network segment, you end up with a detection surface that's much harder to evade than any single rule. The attacker has to fool not one signal but a combination, and the more dimensions you include, the harder that gets.

Unsupervised learning and the baseline problem

One of the practical reasons ML works here is that it doesn't need labeled attack data. In most environments, you don't have a clean dataset of confirmed C2 beaconing to train against. What you have is a lot of network telemetry, most of it legitimate.

Unsupervised methods - clustering, anomaly detection, density-based outlier analysis - let you model what normal communication looks like and then flag deviations. A host that suddenly starts talking to a new external endpoint at semi-regular intervals, with low payload variance and no correlation to user activity, stands out even if the C2 framework behind it is entirely novel.

That's a completely different question. Instead of "does this match a known bad pattern?" the model asks "does this look like anything we normally see?" It's the shift that makes ML-based detection hold up against evasion techniques that eat static rules for breakfast.

Choosing the right data source

The effectiveness of any beaconing model depends heavily on what data it sees. In most enterprise environments, web proxy logs are the strongest starting point. They give structured visibility into outbound HTTP/HTTPS traffic - destination domains, URLs, user agents, response codes, byte counts, timing. Exactly the fields you need to build beaconing features, already parsed.

Proxy data has a second advantage - it filters out a lot of internal and infrastructure noise before it reaches the model. Raw NetFlow or PCAP is technically richer, but you spend a lot of time on cleanup before you can do anything useful with it.

Proxy alone isn't everything. Firewall logs catch non-HTTP protocols and connections that skip the proxy entirely. EDR telemetry links network activity back to the process that made it, which is often the difference between a legitimate browser session and a beacon from an injected thread. DNS logs (more on this below) cover channels that never touch HTTP at all.

Mature pipelines combine sources. But if you're starting from zero, proxy is where you get the most detection value per unit of engineering effort - and HTTP-based beaconing still accounts for most of what's actually out there.

Where it gets harder - and why context matters

ML-based beaconing detection isn't clean. False positives are a real problem, because legitimate software beacons all the time. Update checks. Telemetry. Heartbeat connections. API polling from background services. Without context, a model will happily flag all of them.

This is where feature engineering and enrichment earn their keep. The difference between a legitimate heartbeat and a malicious beacon often isn't in the timing at all. It's in the combination of timing plus destination reputation plus TLS certificate characteristics plus payload behavior plus historical prevalence of that destination plus whether the process making the connection is expected to talk to the internet at all.

A practical lesson I keep relearning: not every model output should be an alert. In production, ML-based beaconing detection works best as a scoring mechanism that feeds a broader risk model, not a standalone rule. A moderate beaconing score combined with suspicious process execution or credential access activity on the same host - that's a high-confidence detection. The beaconing score on its own, without other context? That's a ticket to alert fatigue.

DNS - the underused detection surface

Most C2 detection focuses on HTTP and HTTPS. DNS stays underused, and it shouldn't.

A lot of C2 frameworks support DNS-based channels directly. And even the HTTP-based ones leave traces in DNS resolution patterns before the actual traffic starts. Repeated lookups to low-reputation domains, DGA-generated names, unusual query types, or DNS tunneling through oversized TXT or NULL records - all detectable behaviors, all things static rules handle poorly.

ML on DNS telemetry is particularly effective against DGA-based C2, where the domain changes every callback but the generation pattern underneath it is consistent enough to model. A few years back I spent a frustrating week chasing what turned out to be DGA traffic that a signature-based tool was missing entirely, because every individual domain was technically "unknown" rather than known-bad. An ML classifier on lexical features would have caught it in an afternoon.

The real value - catching what you've never seen before

The biggest advantage of ML-based C2 detection isn't that it catches known threats faster. It's that it picks up communication patterns associated with C2 activity even when the framework, infrastructure, and evasion techniques are all new.

In a world where C2 tooling is cheap, customizable, and built to evade, detection strategies that depend on prior knowledge of the threat are fighting a losing fight. Behavioral analysis pushes the advantage back toward defenders by focusing on what the attacker can't easily change - the basic need to keep a reliable channel open to compromised systems.

None of this makes traditional detection obsolete. Known IOCs, signatures, static rules - they still catch real volume and should stay in the stack. But for the threats specifically built to get around those controls, behavior is where the detection surface actually lives now. ML is how you look at it.

That's the gap. And that's where it closes.

< Back to Defense Labs