← Course Index

4.1 Command & Control (C2) Behavioral Detection:
Resilient Channels, Malleable Profiles & Hunting

Detecting Covert Communication Patterns, Beaconing Cadence, Egress Anomalies & Process-Network Mismatches Across Defensive Telemetry

Module 4: Adversary Emulation & Hunting C2 Behavioral Detection Network & Endpoint Hunting

1. Behavioral Hunting Against Resilient C2 Channels

Adversaries adapt command-and-control (C2) channels to blend into routine enterprise traffic—using HTTPS, DNS, cloud APIs, or customizable HTTP headers/body shapes and jittered polling intervals. Because static signatures easily break when domains or traffic templates change, defenders focus on behavioral and contextual anomalies: unexpected processes initiating external sockets, periodic check-in intervals, mismatched client/user-agent stacks, and unusual egress destinations.

Process-to-Network Correlation: A recurring HTTPS connection is far more suspicious when initiated by an office document reader, script interpreter, or temporary binary than by a browser or legitimate updater with matching certificate and DNS history.
C2 BEHAVIORAL SIGNALS • Jittered / Periodic Polling • Custom / Mismatched Headers • Rare Domains / Direct IPs • Non-Browser Calling Binary • DNS / Tunneling Artifacts MULTI-SOURCE HUNTING ENGINE Endpoint Process & Socket Logs Parent Chain • Binary Path • Remote IP/Port NSM & Flow Telemetry conn.log • dns.log • ssl.log • http.log Containment & Hunt Expansion Isolate host • Block C2 indicators Sweep fleet for sibling implants DEFENSIVE CONTROLS • Strict Egress Allowlisting • Proxy / DNS Policy Enforcement • Script & Process Guardrails • EDR Memory & Behavioral Rules
Figure 4.1: Correlating C2 Behavioral Indicators Across Endpoint, Network, and Containment Workflows.

2. High-Signal C2 Hunting Dimensions & Defensive Mitigations

Hunting Dimension Anomalous Behavior to Look For Defensive Mitigation
Initiating Process Scripting engines, office apps, or binaries in temp/user directories opening external network connections. Harden script/execution policies, restrict outbound access from non-approved binaries, and monitor anomalous parent-child chains.
Cadence & Timing Repeated outbound connections with steady or slightly jittered intervals to uncommon external endpoints. Baseline host egress cadence, investigate recurring low-volume external sessions, and correlate with host/DNS activity.
HTTP / TLS / DNS Profile Unusual user-agents, missing/anomalous SNI or certificates, or high-entropy/TXT DNS query bursts. Enforce proxy/WAF controls, inspect TLS/DNS metadata in NSM logs, and block known-bad or newly observed high-risk destinations.
Egress & Lateral Pivots Internal hosts reaching external IPs directly without proxy/DNS resolution or pivoting internally after initial contact. Enforce network segmentation, route egress through controlled proxies/firewalls, and hunt for lateral movement after C2 hits.
Hunt Across the Fleet After a Hit: Finding a C2 connection on one workstation is only step one. Immediately sweep logs and endpoint telemetry across the broader fleet for the same destination IP/domain, parent/child process lineage, user account, or file hash to rule out multi-host staging.

3. Practical C2 Behavioral Hunting & Detection Examples (10 Scenarios)

Example 1: Hunting Outbound Connections from Non-Browser Processes (KQL)

KQL (Microsoft Defender) — Spotting External Sockets Opened by Script or Temp Binaries
DeviceNetworkEvents
| where Timestamp > ago(24h)
| where ActionType == "ConnectionSuccess"
| where RemoteIPType == "Public"
| where InitiatingProcessFileName !in~ ("chrome.exe", "msedge.exe", "firefox.exe", "Teams.exe", "OneDrive.exe")
| where InitiatingProcessFolderPath has_any ("\\Temp\\", "\\AppData\\", "\\Users\\Public\\")
     or InitiatingProcessFileName in~ ("powershell.exe", "pwsh.exe", "cmd.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe")
| summarize
    ConnCount = count(),
    RemoteIPs = make_set(RemoteIP, 10),
    RemotePorts = make_set(RemotePort, 10)
  by DeviceName, InitiatingProcessFileName, InitiatingProcessFolderPath, InitiatingProcessCommandLine
| order by ConnCount desc
SAMPLE OUTPUT
DeviceName   InitiatingProcessFileName InitiatingProcessFolderPath            InitiatingProcessCommandLine           ConnCount RemoteIPs         RemotePorts
----------   ------------------------- ---------------------------            ----------------------------           --------- ---------         -----------
wkstn-eng-19 rundll32.exe              C:\Windows\System32                    rundll32.exe C:\Users\Public\pkg.dll,Run        48 ["198.51.100.72"] [443]

Example 2: Hunting Repeated Outbound Sessions to a Single External IP in Zeek conn.log

Shell (jq / sort) — Ranking Frequent External Destinations per Internal Host
jq -r 'select(."id.resp_p" == 443 or ."id.resp_p" == 80 or ."id.resp_p" == 8443) |
  [."id.orig_h", ."id.resp_h", (."id.resp_p" | tostring), (.service // "-")] | @tsv' conn.log | \
  sort | uniq -c | sort -nr | head -n 20
SAMPLE OUTPUT
    184 10.10.24.55	198.51.100.72	443	ssl
     72 10.10.14.22	93.184.216.34	443	ssl
     15 10.10.19.08	203.0.113.99	8443	ssl

Example 3: Computing Connection Inter-Arrival Statistics in Python

Python — Checking Mean and Min/Max Intervals Between Outbound Flows
import json
import statistics

ts_list = []
with open("conn.log", encoding="utf-8") as f:
    for line in f:
        row = json.loads(line)
        if row.get("id.orig_h") == "10.10.24.55" and row.get("id.resp_h") == "198.51.100.72":
            ts_list.append(float(row["ts"]))

ts_list.sort()
intervals = [ts_list[i] - ts_list[i - 1] for i in range(1, len(ts_list))]
if intervals:
    print("Samples:", len(intervals))
    print("Mean interval (s):", round(statistics.mean(intervals), 2))
    print("Min / Max (s):", round(min(intervals), 2), "/", round(max(intervals), 2))
SAMPLE OUTPUT
Samples: 183
Mean interval (s): 60.14
Min / Max (s): 48.2 / 71.85

Example 4: Hunting Unusual HTTP User-Agents in Zeek http.log

Shell (jq) — Listing Distinct User-Agents and Request Counts
jq -r '[(.user_agent // "(empty)"), ."id.resp_h", (.host // "-")] | @tsv' http.log | \
  sort | uniq -c | sort -nr | head -n 20
SAMPLE OUTPUT
    112 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36	93.184.216.34	www.example.com
     36 python-requests/2.31.0	203.0.113.99	sync-endpoint.example
      9 (empty)	198.51.100.72	-

Example 5: Sigma Rule — Suspicious Script / LOLBin Making Outbound Network Connections

YAML (Sigma Rule) — Behavioral Rule for Script Interpreter Outbound Socket
title: Script Interpreter Outbound Network Connection
id: 3c91a4e2-7b58-4d19-a612-8e4f2c901b77
status: experimental
description: Detects scripting or utility binaries initiating external network connections.
logsource:
    product: windows
    category: network_connection
detection:
    selection:
        Image|endswith:
            - '\powershell.exe'
            - '\pwsh.exe'
            - '\wscript.exe'
            - '\cscript.exe'
            - '\mshta.exe'
            - '\rundll32.exe'
    condition: selection
falsepositives:
    - Legitimate administrative scripts or software installers
level: medium
SAMPLE OUTPUT
# Sigma / SIEM rule match:
Rule Title : Script Interpreter Outbound Network Connection (3c91a4e2-7b58-4d19-a612-8e4f2c901b77)
Host       : wkstn-eng-19
Image      : C:\Windows\System32\rundll32.exe
DestIP     : 198.51.100.72:443
Severity   : medium

Example 6: Hunting High-Volume or Long-Label DNS Queries (KQL)

KQL (Microsoft Sentinel) — Spotting Long Subdomains or High Query Counts per Domain
DnsEvents
| where TimeGenerated > ago(24h)
| where strlen(Name) >= 45
| summarize
    QueryCount = count(),
    UniqueSubdomains = dcount(Name),
    SampleQueries = make_set(Name, 5)
  by ClientIP, Substring(Name, indexof(Name, ".") + 1)
| where QueryCount >= 20
| order by QueryCount desc
SAMPLE OUTPUT
ClientIP    DomainSuffix             QueryCount UniqueSubdomains SampleQueries
--------    ------------             ---------- ---------------- -------------
10.10.15.88 sub.tunnel-test.example        94               94 ["7f8a9c2e4b6d1035a8c7e9b1d3f5a7c9.sub.tunnel-test.example"]

Example 7: Velociraptor VQL — Correlating Active TCP Connections with Process Paths

VQL (Velociraptor) — Listing Established External Connections & Owning Binaries
SELECT
  Laddr.IP AS LocalIP,
  Laddr.Port AS LocalPort,
  Raddr.IP AS RemoteIP,
  Raddr.Port AS RemotePort,
  Status,
  Pid,
  ProcessName,
  Exe
FROM artifact_call(artifact="Windows.Network.NetstatEnriched")
WHERE Status = "ESTABLISHED"
  AND NOT Raddr.IP =~ "^(10\\.|172\\.(1[6-9]|2[0-9]|3[01])\\.|192\\.168\\.|127\\.)"
SAMPLE OUTPUT
LocalIP     LocalPort RemoteIP      RemotePort Status      Pid  ProcessName  Exe
-------     --------- --------      ---------- ------      ---  -----------  ---
10.10.24.55 51422     198.51.100.72 443        ESTABLISHED 6844 rundll32.exe C:\Windows\System32\rundll32.exe

Example 8: Wazuh Rule — Alerting on Repeated Outbound Connections to Suspicious Ports

XML (Wazuh Rule) — Correlating Firewall / Network Telemetry Events

  
    100700
    
    Repeated outbound network events from $(srcip) within 5 minutes
    
      T1071
    
  
SAMPLE OUTPUT
** Alert 1795684102.31890: - local,c2_hunting,network_egress
2026 Nov 26 09:50:12 (wkstn-eng-19) 10.10.24.55->firewall
Rule: 100701 (level 10) -> 'Repeated outbound network events from 10.10.24.55 within 5 minutes'

Example 9: Checking Active Outbound Connections on a Linux Host

Bash (ss) — Inspecting Established External Sockets & Processes
ss -tupn state established
SAMPLE OUTPUT
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:Port  Process
tcp   ESTAB  0      0      10.20.4.18:49210    198.51.100.72:443  users:(("python3",pid=8812,fd=4))

Example 10: Querying Threat Intel / Indicators via Python Before Block/Sweep

Python — Normalizing and Deduplicating Candidate C2 Domains & IPs
candidates = [
    "198.51.100.72",
    "198.51.100.72",
    "sync-endpoint.example",
    "  SUB.TUNNEL-TEST.EXAMPLE  "
]

cleaned = sorted({item.strip().lower() for item in candidates if item.strip()})
for indicator in cleaned:
    print("Indicator:", indicator)
SAMPLE OUTPUT
Indicator: 198.51.100.72
Indicator: sub.tunnel-test.example
Indicator: sync-endpoint.example

4. Interactive C2 Behavioral Triage Simulator

Select a C2 behavioral indicator below to review the telemetry signal, containment workflow, and fleet hunt steps:

← Previous: 3.5 Continuous Identity Posture Auditing Next: 4.2 Edge Relay & Host-Header Anomalies →