Network-Level Containment
Network-level containment works where EDR cannot — on hosts without agents, during active spreading, and when identity-based controls need support from infrastructure controls.
Ransomware has encrypted 300 servers. The IR team has EDR on 60% of endpoints. The remaining 40% — legacy systems, OT devices, medical imaging equipment, servers with incompatible OS versions — have no EDR agent. The ransomware is spreading via SMB, exploiting unpatched EternalBlue-variant vulnerabilities, traversing the flat network freely. EDR isolation handles the 60%. For the 40%, the only option is network-level containment: firewall rules, VLAN reassignment, switch port ACLs. This is where network containment capability — built during Preparation and not improvised during an incident — makes the difference between a 300-server incident and a 3,000-server incident.
Firewall Segmentation During IR
Firewall-based segmentation is the primary network-level containment tool. It works by modifying access control rules to restrict traffic between network segments, stopping an attacker from moving laterally across segment boundaries or communicating with external C2 infrastructure.
Firewall Containment Patterns
══════════════════════════════════════════════════════════════════════
PATTERN 1: Block specific host at perimeter
─────────────────────────────────────────────────────────────────
Rule: deny all outbound traffic from 10.10.1.45 to any
Effect: the specific host cannot communicate outside its subnet
Use when: single host confirmed compromised, EDR not available,
cannot take entire segment offline
Risk: lateral movement within the same subnet still possible
PATTERN 2: Block entire subnet from internet
─────────────────────────────────────────────────────────────────
Rule: deny outbound from 10.10.1.0/24 to internet
Effect: C2 callbacks from entire subnet are blocked
Use when: multiple hosts in same subnet confirmed compromised,
or subnet shows widespread infection indicators
Risk: blocks all internet access for business applications in subnet
PATTERN 3: East-west microsegmentation
─────────────────────────────────────────────────────────────────
Rule: deny traffic between workstation subnet and server subnet
except on explicitly required ports (e.g., allow 10.10.0.0/16
to 10.20.0.0/16 only on TCP 443, 80; deny all else)
Effect: stops lateral movement from workstations to servers via
SMB (445), RDP (3389), WMI (135/dcom), PSRemoting (5985)
Use when: attacker is moving laterally from workstations to servers
Risk: may break legitimate business applications that use
non-standard ports between segments; requires testing
PATTERN 4: Quarantine VLAN
─────────────────────────────────────────────────────────────────
Move host's switch port to a "quarantine VLAN" that has no
routing to any other network segment but allows SIEM/EDR traffic
Effect: equivalent to host isolation but at the network level
Use when: host has no EDR, physical access not immediately available
Requires: managed switches with VLAN assignment capability per port,
and IT access to manage them
During an active ransomware spread, every minute of containment delay means additional hosts encrypted. Building firewall rules from scratch during an incident — figuring out which subnets need which rules, testing for false positives, getting change approval — takes hours. Pre-built segmentation templates: a "quarantine VLAN" that already exists and can be assigned to switch ports in seconds, firewall rule groups that can be activated as a block with one command, and pre-tested "east-west block" rules that have been validated to not break critical business applications — these reduce containment time from hours to minutes. Organizations that do not build these templates during Preparation pay for it during incidents. The IR team's job during Preparation is to pre-position these capabilities, not to design them under pressure.
DNS Sinkholing
DNS sinkholing redirects DNS queries for known malicious domains to a controlled IP address (the "sinkhole"), preventing compromised hosts from resolving attacker-controlled infrastructure. It is particularly effective against malware that uses domain names for C2 rather than hardcoded IPs — which is most modern malware, because domain names allow C2 infrastructure rotation without updating the malware binary.
DNS Sinkhole: How It Works
══════════════════════════════════════════════════════════════════════
NORMAL DNS RESOLUTION (without sinkhole):
Compromised host → DNS query for "evil-c2.attacker.com"
→ Corporate DNS resolver → upstream resolver → attacker's authoritative DNS
→ Returns: 185.x.x.x (attacker's C2 server)
→ Host connects to attacker's C2 on 185.x.x.x
WITH DNS SINKHOLE:
Compromised host → DNS query for "evil-c2.attacker.com"
→ Corporate DNS resolver → sinkhole rule matches domain
→ Returns: 10.0.0.1 (internal sinkhole IP, controlled by IR team)
→ Host attempts to connect to 10.0.0.1 (IR-controlled sinkhole server)
→ Connection fails or is logged; C2 beacon does not complete
→ Sinkhole server logs: "host 10.10.1.45 attempted C2 connection at [time]"
WHAT THE SINKHOLE GIVES YOU:
─────────────────────────────────────────────────────────────────
1. Prevention: infected hosts cannot communicate with known C2
2. Detection: the sinkhole log identifies hosts that are infected
(they're the ones querying the sinkholed domain)
3. Scope mapping: how many hosts queried this domain, and when?
Answers scope questions that EDR telemetry may miss (especially
for hosts where EDR is not deployed)
WHAT IT DOES NOT GIVE YOU:
─────────────────────────────────────────────────────────────────
1. Does not block C2 via hardcoded IP (attacker bypasses DNS entirely)
2. Does not block C2 domains you haven't identified yet (IOC coverage)
3. Does not prevent local DNS cache from serving attacker domain
if DNS cache was populated before sinkhole was applied
Proxy-Based Blocking
A web proxy (or secure web gateway) sits between corporate hosts and the internet, inspecting and controlling HTTP/HTTPS traffic. During an IR engagement, it can be used to block outbound C2 communication that uses HTTP or HTTPS, which is the majority of modern C2 traffic.
| Proxy blocking action | What it stops | What it doesn't stop |
|---|---|---|
| Block specific domain/URL | HTTP/HTTPS traffic to a specific C2 domain | C2 using IP addresses directly (no DNS); C2 over non-HTTP protocols; C2 tunneling through allowed domains |
| Block IP range associated with C2 hosting provider | Connections to known attacker infrastructure | C2 hosted on major cloud providers (AWS, Azure, Cloudflare) whose IPs you cannot block broadly without disrupting legitimate traffic |
| Block all uncategorized domains | C2 to newly-registered or uncategorized attacker domains | C2 using categorized domains (domain fronting via legitimate CDN) — this will block legitimate traffic too |
| SSL inspection of HTTPS traffic | Allows inspection and blocking of C2 over HTTPS, even to categorized domains | C2 using certificate pinning (explicitly rejects proxy's cert); may break legitimate applications that do pinning |
Domain fronting is a technique where the attacker's C2 beacon sends an HTTPS request to a legitimate, allowed domain (e.g., a Google, Azure, or Cloudflare domain) but includes an HTTP Host header pointing to the actual C2 endpoint. To the proxy/firewall, the connection looks like HTTPS traffic to google.com. The actual encrypted payload is delivered to the attacker's server. Blocking this requires SSL inspection (breaking and re-inspecting the TLS connection) or blocking the specific SNI extension value in the TLS ClientHello. Both have tradeoffs — SSL inspection is expensive and breaks certificate pinning; SNI-based blocking requires visibility into TLS metadata that not all network appliances provide. For Cobalt Strike specifically, domain fronting is a common technique in engagements and real-world APT activity. The countermeasure is EDR-based C2 detection (detecting the beacon process behavior) rather than trying to block it at the network layer.
Cloud Security Group and NSG Containment
Cloud environments use "security groups" (AWS) and "network security groups" (Azure) as the network-level firewall for cloud workloads. Modifying these during IR is the cloud-native equivalent of firewall rule modification for on-premises environments.
AWS and Azure Network Isolation Actions
══════════════════════════════════════════════════════════════════════
AWS: MODIFY SECURITY GROUP
─────────────────────────────────────────────────────────────────
To isolate a specific EC2 instance:
1. Identify the instance's current security group(s)
2. Create a new "quarantine" security group with no inbound or
outbound rules (deny all)
3. Replace the instance's security group assignment with the
quarantine security group
Effect: all network traffic blocked; instance is network-isolated
Note: The AWS Systems Manager (SSM) agent bypasses security groups
and VPC networking entirely — SSM access to the instance is
preserved even with deny-all security group.
This makes SSM the AWS equivalent of the EDR management channel:
you can still run SSM Session Manager on a network-isolated instance.
AZURE: MODIFY NSG
─────────────────────────────────────────────────────────────────
To isolate a specific Azure VM:
1. Identify the VM's network interface and associated NSG
2. Add a high-priority deny rule for all inbound and outbound traffic
(or assign a deny-all NSG to the interface directly)
Effect: all network traffic blocked at the Azure network layer
Note: Azure Bastion (if configured) may bypass the NSG —
check whether the Bastion subnet has its own NSG rules allowing access.
CLOUD-WIDE CONTAINMENT (for compromised IAM)
─────────────────────────────────────────────────────────────────
If the attacker has IAM access (not just host access), modifying
security groups and NSGs does not contain them — they can
modify those rules themselves. IAM containment (key revocation,
session termination) must happen first or simultaneously.
Network-level containment in cloud is secondary to identity
containment when both IAM and host access are compromised.
BGP Blackholing
BGP blackholing is an ISP-level technique where traffic destined for a specific IP or IP range is "blackholed" — dropped before it reaches your network. It is primarily a DDoS mitigation technique, but it can also be used to prevent a compromised host from reaching an attacker's C2 when the attacker's C2 IP range is known and the attack path is inbound from that IP range. In most IR scenarios, it is not the primary tool — firewall and DNS controls are more precise. Its main IR relevance is in understanding that this option exists when dealing with high-volume C2 traffic that is overwhelming firewall logging capabilities.
Network Forensics During Containment
Network forensics — capturing and analyzing network traffic during the incident — provides evidence types that host-based forensics cannot: what data left the network, what C2 traffic looked like before it was blocked, what hosts the attacker communicated between. Done during or just before containment, it can provide the clearest picture of attacker activity.
| Network data source | What it contains | IR use |
|---|---|---|
| NetFlow / IPFIX | Connection metadata: source/dest IP, port, protocol, byte count, packet count, start/end time. No payload. | Map lateral movement (which hosts talked to which), identify data exfiltration (large outbound byte counts), correlate with attacker IOC IPs |
| Full packet capture (PCAP) | Complete packet payload for all captured traffic | Reconstruct data exfiltration (if unencrypted); capture C2 protocol patterns; decode attacker tool communications; capture credentials passed in cleartext |
| DNS logs (recursive resolver) | All DNS queries made by hosts on the network: domain, query type, response, source host | Identify C2 domains queried before they were blocked; find DGA (domain generation algorithm) traffic by analyzing query patterns; map which hosts queried attacker domains |
| Proxy logs | URL, HTTP headers, response codes, user-agent strings for all proxied HTTP/HTTPS traffic | Identify C2 user-agent patterns; find data exfiltration via HTTP POST; correlate timing of attacker tool callbacks with other events |
| Email gateway logs | Sender, recipient, subject, attachment hashes, delivery status for all email | Identify initial phishing delivery; find lateral phishing (attacker using compromised mailbox to phish internal users); correlate BEC activity |
Full packet capture (PCAP) requires pre-positioned network taps or SPAN ports on the relevant network segments. You cannot retroactively capture traffic that has already passed through the network. NetFlow data requires NetFlow collection to be configured on routers and switches before the incident. DNS logging requires the recursive resolver to be configured to log queries. Organizations that arrive at an IR engagement and discover they have none of these — no PCAP capability, no NetFlow, minimal DNS logging — have a significantly degraded investigation capability for anything that happened before logging was enhanced. The irony is that all of these are relatively inexpensive to implement. The cost is not in the tooling — it is in the deliberate act of planning for the forensic investigation you might need to conduct.
Q & A
How do you contain a host that is actively spreading via SMB without taking down the entire network?
A host spreading via SMB (port 445) can be stopped at multiple layers. Most targeted: apply an access control list (ACL) on the managed switch port the host is connected to, blocking all traffic — or reassign the port to the quarantine VLAN. This takes effect at the switch level immediately and requires no changes to the host itself. If managed switch access is not available quickly: apply a firewall rule blocking the host's IP from making outbound connections on port 445. This stops the SMB spread while preserving the host's other network connectivity (DNS, HTTP, etc.), which may be acceptable during the initial containment phase. If the host is a file server that cannot be easily isolated: use firewall segmentation to block inbound SMB connections from the workstation subnets to the server subnet — this stops workstations from spreading to servers, which is the higher-value target, while not necessarily isolating the initially compromised workstations fully.
If the attacker's C2 server is hosted on AWS or Cloudflare, can you block it without blocking all AWS/Cloudflare traffic?
Blocking a C2 that uses legitimate cloud infrastructure is a precision problem: the attacker's C2 IP may share a /24 or even a /32 with legitimate services that other parts of the business depend on. The options: (1) Block the specific IP (not the range) if you've confirmed the exact C2 IP. AWS and Cloudflare IPs are shared but each IP at any given time is assigned to one tenant — blocking a specific /32 is feasible. (2) DNS sinkhole the specific domain, which prevents resolution regardless of what IP the domain resolves to. (3) If the C2 is using domain fronting through a CDN, the approach shifts to host-based detection (EDR catching the process) rather than network blocking — you cannot block the CDN domain without breaking legitimate traffic. (4) In severe cases, the proxy can block based on SNI (TLS server name indicator), which is visible in the ClientHello even for HTTPS — more precise than IP-based blocking when the attacker uses a unique domain.
What does a network-level containment operation look like for a 1,000-endpoint environment actively being hit with ransomware?
The priority in active ransomware spread is stopping the spread first, then investigating. The sequence: (1) Apply the pre-built east-west firewall block: deny SMB (445), RDP (3389), WinRM (5985/5986) between the workstation VLAN and the server VLAN. This stops the most common ransomware lateral movement paths immediately and is one rule change. (2) Block the identified ransomware C2 domain(s) via DNS sinkhole. (3) While network containment is in effect, use EDR console to identify actively-encrypting hosts and contain them individually. (4) Begin triage: which servers are confirmed encrypted (lost), which are still clean (protect). (5) If ransomware is also spreading via domain GPO (some ransomware families): take DCs offline immediately after confirming GPO-based spread. The order matters — one firewall rule change to block SMB east-west takes 5 minutes and stops the spread across segment boundaries; individual host containment takes longer but is then done in a more controlled environment after the spread is slowed.
How do you use network forensics to determine if data was exfiltrated, and how much?
NetFlow data provides the clearest quantitative picture of data exfiltration: look for outbound connections from confirmed compromised hosts to attacker-controlled IPs, note the byte counts. A connection carrying 50MB of outbound traffic to an attacker C2 IP at 3 AM is strong evidence of exfiltration. The limitation: byte counts tell you how much data left, but not what data — for that you need PCAP (if the traffic was unencrypted) or file system artifacts (which files were opened and at what times relative to the exfiltration). Proxy logs give the most complete HTTP-based exfiltration picture: they record HTTP POST body sizes, which is the most common exfiltration mechanism for web-based C2. DNS logs can reveal DNS-based exfiltration: attacker encodes data into DNS query names and sends it to an attacker-controlled DNS server — the data exfiltration looks like unusual DNS queries with very long, encoded hostnames. The combination of NetFlow (volume), DNS logs (scope), and proxy logs (method) usually provides a satisfactory answer to "what was exfiltrated and how much" in well-logged environments.
How do you contain a compromised cloud environment where the attacker has stolen IAM keys but has no host presence?
When the attacker has only IAM access (stolen API keys or OAuth tokens, not host code execution), network-level containment does not apply — the attacker is authenticating via the cloud provider's API, not from a specific IP that can be blocked. The containment is entirely identity-based: (1) Immediately revoke all access keys and tokens for the compromised IAM identity. For AWS: deactivate and delete the access keys in IAM. For Azure: revoke the service principal's credentials. (2) Revoke active sessions — revoking the key stops future authentication, but active sessions may have cached tokens that remain valid for their lifetime (typically 1 hour for AWS STS tokens). For AWS: attach an explicit deny policy to the compromised IAM identity that denies all actions — this terminates active sessions immediately. (3) Audit what the key accessed: CloudTrail/Azure Activity Logs for all API calls made by the compromised identity. (4) Check for attacker persistence mechanisms: new IAM users created, new access keys on existing users, Lambda functions created, new EC2 instances launched — these are identity-based persistence, not host-based.