<# .SYNOPSIS Lab 08.2 — Endpoint Protection (Defender AV EICAR & ASR) Validation .DESCRIPTION Runs Pre-Flight checks on Microsoft Defender Antivirus and Attack Surface Reduction (ASR), executes the benign EICAR real-time quarantine test in C:\Temp\ValidationTest, verifies Defender Operational Event IDs 1116/1117/1121/1122, and cleans up automatically. Classification : Validation preview & cleanup (Isolated Lab Endpoint) Required Roles : Local Administrator (for Event Log & Remove-MpThreat cleanup) Run On : WIN11-01 or WIN11-02 (Never run on production servers) .NOTES Author : Caner Cetinkaya (canercetinkaya.com/labs/08-attack-and-validate/) Safety : SAFE · VENDOR TEST (EICAR proves AV quarantine only, NOT full EDR/XDR) #> [CmdletBinding()] param( [string]$TestDir = 'C:\Temp\ValidationTest', [switch]$SkipCleanup ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' Write-Host '[1/4] Pre-Flight: Checking Defender AV & ASR configuration...' -ForegroundColor Cyan $mp = Get-MpComputerStatus $pref = Get-MpPreference $asrBlock = @($pref.AttackSurfaceReductionRules_Actions | Where-Object { $_ -eq 1 }).Count $asrAudit = @($pref.AttackSurfaceReductionRules_Actions | Where-Object { $_ -eq 2 }).Count [pscustomobject]@{ Host = $env:COMPUTERNAME AMServiceEnabled = $mp.AMServiceEnabled RealTimeProtectionEnabled = $mp.RealTimeProtectionEnabled AVSignatureVersion = $mp.AntivirusSignatureVersion ASR_Rules_Total = @($pref.AttackSurfaceReductionRules_Ids).Count ASR_Block_Count = $asrBlock ASR_Audit_Count = $asrAudit } | Format-List if (-not $mp.RealTimeProtectionEnabled) { throw 'Pre-Flight FAILED: Defender Real-Time Protection is disabled. Enable before validating.' } Write-Host '[2/4] Triggering benign EICAR test string in isolated folder...' -ForegroundColor Cyan New-Item -ItemType Directory -Force -Path $TestDir | Out-Null $eicarPath = Join-Path $TestDir 'eicar.com.txt' $bytes = [System.Text.Encoding]::ASCII.GetBytes('X5O!P%@AP[4\PZX54(P^)7CC)7}$' + 'EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*') try { [System.IO.File]::WriteAllBytes($eicarPath, $bytes) } catch { Write-Host "Write blocked immediately by Defender AV: $($_.Exception.Message)" -ForegroundColor Green } Start-Sleep -Seconds 5 Write-Host "FileExistsAfter5s: $(Test-Path $eicarPath)" Write-Host '[3/4] Verifying Defender Operational Event Log (1116, 1117, 1121, 1122)...' -ForegroundColor Cyan Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-Windows Defender/Operational' Id = 1116, 1117, 1121, 1122 StartTime = (Get-Date).AddMinutes(-10) } -MaxEvents 10 -ErrorAction SilentlyContinue | Select-Object TimeCreated, Id, @{ Name = 'Summary'; Expression = { ($_.Message -split "`n")[0] } } | Format-Table -AutoSize Get-MpThreatDetection | Select-Object -First 3 ThreatID, InitialDetectionTime, ActionSuccess, Resources | Format-List if (-not $SkipCleanup) { Write-Host '[4/4] Cleaning up temporary test artifacts...' -ForegroundColor Cyan Remove-Item -Path $TestDir -Recurse -Force -ErrorAction SilentlyContinue Remove-MpThreat -ErrorAction SilentlyContinue Write-Host "CleanupVerified (FolderExists=False): $(Test-Path $TestDir)" -ForegroundColor Green }