Agent Foskett Academy • Microsoft Sentinel • Module 7 • Lesson 67

Lesson 67 — Detecting Command-and-Control Activity

Hunt for possible command-and-control (C2) communications by examining outbound network connections, recurring contact patterns and DNS evidence in Microsoft Sentinel.

Module 7 — Advanced Threat Hunting and Investigation • Command and Control
Agent Foskett Microsoft Sentinel command-and-control threat hunting
What you will learn

Build a network hypothesis, measure recurring connections and validate suspicious destinations before escalating.

✓ Verify firewall and DNS telemetry
✓ Identify uncommon outbound destinations
✓ Hunt recurring network beacon patterns
✓ Correlate DNS and endpoint evidence

Agent Foskett case file — The heartbeat after midnight

Every few minutes, a workstation reaches the same external address, including overnight when its owner is away. A threat intelligence feed has not flagged the destination. Is this a malicious C2 beacon, a cloud management agent, or an ordinary application keepalive? Agent Foskett examines the connection pattern, destination ownership, associated DNS lookups and host process evidence before making a finding.

Learning objectives

  • Explain command-and-control communication and common network indicators.
  • Verify the availability and limitations of firewall and DNS telemetry.
  • Use KQL to identify unusual outbound destinations and periodic contact.
  • Measure beaconing regularity without treating periodicity as proof.
  • Correlate DNS, network and endpoint evidence with defensible identifiers.
  • Record alternative explanations, confidence and escalation criteria.

What is command and control?

Command and control describes communication used by an adversary to manage compromised systems, issue instructions or receive information. Traffic may use HTTP(S), DNS or other protocols, but those same protocols are essential to legitimate business applications. A network pattern is an investigative lead, not a malware verdict.

Start with a testable hypothesis

Hypothesis: a workstation is periodically contacting an unauthorized external service to receive instructions. Alternatives: endpoint management, telemetry upload, software licensing, health checks, scheduled sync or a corporate proxy. Define what evidence would support or refute each explanation.

Telemetry and schema boundaries

The firewall examples below assume normalized firewall or network appliance events in the Microsoft Sentinel CommonSecurityLog table, with SourceIP, DestinationIP, DestinationPort and DeviceAction. These fields depend on your connector and CEF mapping. The DNS example uses DnsEvents, which exists only when that data source is collected. Microsoft Defender XDR DeviceNetworkEvents is an advanced-hunting table and is not automatically available in Sentinel Logs. Inspect your actual schema before adapting these hunts.

Network signals and what they mean

SignalWhy investigateWhy it may be benign
Repeated contact to one destinationPossible beaconing or pollingMonitoring, cloud agents and keepalives
Rare external destinationUnfamiliar infrastructure may warrant reviewNew SaaS service or CDN endpoint
Unusual destination portUnexpected protocol or application behaviorApproved custom business software
DNS queries to unfamiliar domainsPossible C2 discovery or domain rotationAdvertising, tracking, CDNs and updates
Traffic after unusual sign-inPotential post-compromise sequenceUnrelated background application traffic

Encrypted HTTPS limits what network metadata can establish. Do not infer payload content or exfiltration from connection counts alone.

Validate ingestion before hunting

Confirm which firewalls, proxies and DNS resolvers feed the workspace, whether source addresses are pre- or post-NAT, and whether your logs include allowed, denied or both action types. Account for retention, clock skew and missing endpoint coverage.

KQL hunt 1 — Check network log coverage

Sentinel Logs — CommonSecurityLog coverage
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
CommonSecurityLog
| where TimeGenerated >= ago(7d)
| summarize Events = count(),
            SourceHosts = dcount(SourceIP),
            Destinations = dcount(DestinationIP),
            LastSeen = max(TimeGenerated)
    by DeviceVendor, DeviceProduct, bin(TimeGenerated, 1d)
| order by TimeGenerated asc

This is an ingestion inventory, not a completeness guarantee. Confirm expected firewall devices and compare with your network architecture.

Scope the hunt to outbound traffic

Use your organization’s actual internal address ranges and network zones. The examples below use RFC 1918 private IPv4 ranges as a starting point; they do not cover all enterprise networks, IPv6 or every NAT arrangement. Validate whether the recorded source is an endpoint, gateway or proxy.

KQL hunt 2 — Find recurring external destinations

Sentinel Logs — recurring outbound contacts
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
CommonSecurityLog
| where TimeGenerated >= ago(24h)
| where isnotempty(SourceIP) and isnotempty(DestinationIP)
| where ipv4_is_private(SourceIP) == true
| where ipv4_is_private(DestinationIP) == false
| summarize Connections = count(),
            ActiveHours = dcount(bin(TimeGenerated, 1h)),
            FirstSeen = min(TimeGenerated),
            LastSeen = max(TimeGenerated)
    by SourceIP, DestinationIP, DestinationPort
| where Connections >= 20 and ActiveHours >= 4
| order by ActiveHours desc, Connections desc
| take 100

Review the thresholds against your environment. This deliberately identifies persistent contacts; legitimate monitoring and cloud software will often appear.

Beaconing is about timing, not just volume

C2 software may contact a server at regular intervals, but many legitimate applications do the same. Conversely, an attacker can introduce jitter, change destinations or use event-driven communications. A low timing variance is one clue; process ownership and destination context are still essential.

KQL hunt 3 — Measure candidate beacon intervals

Sentinel Logs — interval consistency
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
let candidateSource = "10.0.0.25";
let candidateDestination = "203.0.113.25";
CommonSecurityLog
| where TimeGenerated >= ago(24h)
| where SourceIP == candidateSource
    and DestinationIP == candidateDestination
| project TimeGenerated, SourceIP, DestinationIP
| order by TimeGenerated asc
| serialize
| extend PreviousTime = prev(TimeGenerated)
| extend GapSeconds = datetime_diff('second', TimeGenerated, PreviousTime)
| where isnotnull(PreviousTime) and GapSeconds > 0
| summarize Samples = count(),
            AverageGapSeconds = avg(GapSeconds),
            GapStdDevSeconds = stdev(GapSeconds),
            MinGapSeconds = min(GapSeconds),
            MaxGapSeconds = max(GapSeconds)
    by SourceIP, DestinationIP

Replace both illustrative IP addresses with a real candidate from Hunt 2. The documentation-only destination 203.0.113.25 is not a live indicator. Multiple log entries per connection, dropped events and proxies can distort interval statistics.

Interpret timing cautiously

A low standard deviation may indicate a timer-driven application, not necessarily C2. A high deviation does not rule out C2. Compare the observed intervals with known agent schedules, firewall session logging behavior, maintenance windows and host uptime.

DNS as supporting evidence

DNS logs may show the queried name, requester and time before a connection. Correlation is strongest when the same endpoint or resolver context is available. Shared DNS resolvers, caching, CDN address changes and NAT can weaken direct IP-to-domain attribution.

KQL hunt 4 — Inspect DNS query patterns

Sentinel Logs — DnsEvents (optional source)
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
DnsEvents
| where TimeGenerated >= ago(24h)
| where isnotempty(Name)
| summarize Queries = count(),
            FirstSeen = min(TimeGenerated),
            LastSeen = max(TimeGenerated)
    by Name
| where Queries >= 10
| order by Queries desc
| take 100

Run only if DnsEvents is present and populated. Inspect your DNS schema and client-identification fields before attributing a query to a particular workstation. High query volume alone is not malicious.

Correlate network and host behavior

If Microsoft Defender for Endpoint is connected, inspect the corresponding device in Defender XDR advanced hunting for the initiating process, command line, file reputation, signer and network events. Use the appropriate product’s query surface rather than assuming DeviceNetworkEvents exists in Sentinel Logs. Correlate by host, destination and timestamp with clear uncertainty.

KQL hunt 5 — Build a connection timeline

Sentinel Logs — candidate network timeline
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
let candidateSource = "10.0.0.25";
CommonSecurityLog
| where TimeGenerated >= ago(48h)
| where SourceIP == candidateSource
| project TimeGenerated, SourceIP, DestinationIP,
          DestinationPort, Protocol, DeviceAction,
          DeviceVendor, DeviceProduct
| order by TimeGenerated asc
| take 500

Replace the illustrative source IP with your investigation host. Review any proxy or NAT mappings and note that the result cap can omit events.

MITRE ATT&CK mapping

The investigation may relate to Application Layer Protocol (T1071), Web Protocols (T1071.001) or DNS (T1071.004) when the evidence supports those communication methods. Periodicity or a destination port alone does not establish an ATT&CK technique or malicious intent.

Threat intelligence and reputation

Check destination reputation, registration and ownership, observed prevalence, approved service inventories and known cloud provider ranges. Intelligence can be stale or incomplete; a clean reputation score is not proof of safety, and a shared IP can host many unrelated services.

False positives and investigative pitfalls

  • Security agents and software updaters often beacon on schedules.
  • CDNs and SaaS endpoints may be unfamiliar but legitimate.
  • Proxy logs may hide the originating device unless enriched.
  • NAT and dynamic addressing can complicate host attribution.
  • A connection event does not prove commands were received or data was stolen.
  • Sampling, deduplication and log retention can distort timing analysis.

Agent Foskett investigation workflow

HYPOTHESIS: UNAUTHORIZED C2 COMMUNICATION ↓ VERIFY NETWORK AND DNS LOG COVERAGE ↓ IDENTIFY RECURRING EXTERNAL CONTACTS ↓ MEASURE TIMING AND DESTINATION CONTEXT ↓ CORRELATE DNS, HOST AND PROCESS EVIDENCE ↓ CHECK APPROVED SOFTWARE AND OWNERSHIP ↓ DOCUMENT FINDINGS / GAPS / ESCALATION

When should the analyst escalate?

Escalate through the incident process when suspicious network patterns are supported by unauthorized process execution, known malicious infrastructure, compromised credentials or other independent evidence. Preserve relevant logs and follow approved containment procedures; do not block a production destination based solely on a beaconing score.

Case file resolution — The heartbeat after midnight

The recurring connection is traced to an approved endpoint management agent. Its scheduled check-in interval matches the network pattern, the executable is signed by the expected publisher and the destination belongs to the organization’s management service. Agent Foskett records the validation and recommends documenting the agent’s expected destinations for future hunts.

Finding and remaining uncertainty

Finding: recurring outbound communication was confirmed, but malicious C2 was not established. The case is closed as a benign, documented agent check-in, subject to the organization’s normal evidence review and retention policy.

Hands-on lab — Investigate a possible beacon

  1. Verify your firewall and DNS table coverage.
  2. Run the outbound destination hunt and select a recurring contact.
  3. Replace the illustrative IPs in the interval query with your candidate.
  4. Compare interval consistency with expected application schedules.
  5. Inspect DNS evidence if your environment collects it.
  6. Correlate with host process evidence where available.
  7. Document a conclusion, two benign alternatives and one evidence gap.

Knowledge check

  1. Why is a periodic outbound connection not automatically C2?
  2. What can a firewall log prove, and what can it not prove?
  3. How can NAT or a proxy complicate source attribution?
  4. Why is DNS evidence sometimes ambiguous?
  5. What additional evidence would justify escalation?

Operational quality checklist

  • Validate connector mappings and network boundaries.
  • Keep searches time bounded and read-only.
  • Treat candidate IP addresses as examples, not indicators.
  • Do not assume DNS or Defender tables are present.
  • Record process ownership and authorized software checks.
  • Do not link to unpublished Lesson 68.

Agent Foskett takeaway

A regular heartbeat is a clue, not a confession. Follow the connection, verify the process and prove the context before declaring command and control.

The Logs Already Knew.

Lesson 67 complete — follow the heartbeat, verify the source!
You can now investigate suspected command-and-control activity using Sentinel network telemetry and evidence-based KQL hunts.
Sentinel Academy Home

Related Agent Foskett learning

Build on privilege escalation and persistence hunting to investigate potential external communications.