Device Isolation

Pre-Incident Preparation

Environment Familiarisation

Get-CimInstance Win32_OperatingSystem | Select-Object @{N='Name';E={$_.CSName}},@{N='OS';E={$_.Caption}},@{N='Version';E={$_.Version}},@{N='Build';E={$_.BuildNumber}},@{N='InstallDate';E={$_.InstallDate}},@{N='LastBoot';E={$_.LastBootUpTime}},@{N='FreeMemoryMB';E={[math]::Round($_.FreePhysicalMemory/1024,2)}} | Export-Csv "C:\Inventory\device_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv" -NoTypeInformation

Incident Detection and Initial Assessment

Detection Triggers

SecurityEvent
| where EventID in (4624, 4625, 4672, 4688) // Common security-related Event IDs
| project TimeGenerated, Account, EventID, Activity, Computer, IpAddress
| order by TimeGenerated desc

Scope Assessment

DeviceProcessEvents
| where FileName == "svch0st.exe"
| summarize AffectedHosts = dcount(DeviceName), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), ProcessCount = count(), AffectedHostsList = make_set(DeviceName) by FileName

Containment (Short-Term)

Network-Level Containment

Isolate a Device Using the Defender Live Response Console

  1. Initiate Live Response Session

    Click Go Hunt → Initiate Live Response session.

  2. Isolate the Device

    In the Live Response console, enter:

    isolate

    To verify isolation status:

    isolationstatus
  3. (Optional) Release Isolation

    To reconnect the device:

    release

System-Level Containment

This method assumes remote or local execution capability.

Script: Comprehensive Containment

# Check for admin privileges
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Warning "Run as Administrator required."
    exit
}

# Disable all active network adapters
$adapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }
if ($adapters) {
    $adapterNames = $adapters | ForEach-Object { $_.Name }
    Disable-NetAdapter -Name $adapterNames -Confirm:$false -ErrorAction SilentlyContinue
    Write-Host "Network adapters disabled: $adapterNames"
} else {
    Write-Host "No active adapters found."
}

# Block all outbound and inbound traffic with Windows Firewall
New-NetFirewallRule -DisplayName "Block All Outbound" -Direction Outbound -Action Block -Enabled True
New-NetFirewallRule -DisplayName "Block All Inbound" -Direction Inbound -Action Block -Enabled True
Write-Host "Firewall rules applied to block all traffic."

# Optional: Stop non-essential services (e.g., file sharing)
Stop-Service -Name "Server" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "Workstation" -Force -ErrorAction SilentlyContinue
Write-Host "Stopped non-essential services."

How It Works:

  • Network Adapters: Disables all active adapters, cutting physical network access.

  • Firewall Rules: Blocks all inbound and outbound traffic as a secondary layer, even if adapters are re-enabled.

  • Services: Stops services like "Server" (SMB sharing) and "Workstation" (SMB client) to limit local network interactions.

Usage:

  • Run locally: Save as Contain-System.ps1 and execute in an elevated PowerShell session.

  • Run remotely: Use Invoke-Command -ComputerName "TargetDevice" -ScriptBlock { <script above> } if remoting is still available.

Reversal:

# Re-enable adapters
Enable-NetAdapter -Name (Get-NetAdapter | Where-Object { $_.Status -ne 'Up' } | ForEach-Object { $_.Name }) -Confirm:$false
# Remove firewall rules
Remove-NetFirewallRule -DisplayName "Block All Outbound"
Remove-NetFirewallRule -DisplayName "Block All Inbound"
# Restart services
Start-Service -Name "Server"
Start-Service -Name "Workstation"

3. Windows Firewall for Network ContainmentIf physical adapter control isn’t desired, you can use the Windows Firewall to block all network traffic at the system level.

Steps (via PowerShell):

# Block all traffic
New-NetFirewallRule -DisplayName "Containment Outbound" -Direction Outbound -Action Block -Enabled True
New-NetFirewallRule -DisplayName "Containment Inbound" -Direction Inbound -Action Block -Enabled True

Why This Works:

  • Firewall rules apply system-wide, preventing all network communication regardless of adapter state.

  • Easier to reverse than disabling adapters, as it doesn’t require physical access if remoting is lost.

Reversal:

Remove-NetFirewallRule -DisplayName "Containment Outbound"
Remove-NetFirewallRule -DisplayName "Containment Inbound"

4. Defender Live Response for Containment

You can manually execute commands to isolate a device.

Steps:

  1. Start Live Response:

    Go to the device page in the Defender portal and select Initiate Live Response Session.

  2. Disable Adapters:

    Run:

    run cmd.exe -Command "for /f \"skip=1\" %%a in ('wmic path Win32_NetworkAdapter where \"DeviceEnabled=true\" get DeviceID') do (wmic path Win32_NetworkAdapter where \"DeviceID='%%a'\" call Disable)"
  3. Verify:

    Check status:

    run cmd.exe -Command "wmic path Win32_NetworkAdapter get DeviceID, DeviceEnabled"

Reversal:

Re-enable adapters:

run cmd.exe -Command "for /f \"skip=1\" %%a in ('wmic path Win32_NetworkAdapter get DeviceID') do (wmic path Win32_NetworkAdapter where \"DeviceID='%%a'\" call Enable)"

Enterprise-Wide Checks

Basic Check:

DeviceFileEvents
| where FileName contains "ransom"

Last updated