Lesson 9 of 12 · 18 min · Intermediate

Windows Server: firewall, Defender, ASR, Credential Guard and WDAC

Turn the host firewall into a default-block control, harden Microsoft Defender, deploy Attack Surface Reduction rules in audit then block mode, protect credentials with LSA protection and Credential Guard, and begin application control with WDAC.

In this lesson you will

  • Set the Windows firewall to block inbound by default and log drops
  • Configure Defender and roll out ASR rules safely
  • Enable LSA protection and check Credential Guard
  • Start WDAC in audit mode and read its events

This lesson builds the defence stack on a Windows server: the firewall, antivirus and exploit mitigations, credential protection and application control. Each layer assumes another has failed.

Windows Server defence stack

Audit first, block later. ASR, WDAC and AppLocker can stop legitimate software. Start every one in audit mode, read the logs, fix what would break, then enforce.

Windows Defender Firewall

The firewall should be on for all profiles, block inbound by default, and log drops.

powershell
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True -DefaultInboundAction Block -DefaultOutboundAction Allow -LogBlocked True -LogAllowed False -LogMaxSizeKilobytes 16384 -LogFileName '%systemroot%\system32\LogFiles\Firewall\pfirewall.log'

Get-NetFirewallRule -Enabled True -Direction Inbound | Select-Object DisplayName,Profile,Action | Sort-Object DisplayName

Review every enabled inbound rule. Disable the ones you do not need (Disable-NetFirewallRule -DisplayName "...") and scope the rest to the networks that need them (Set-NetFirewallRule -RemoteAddress ...). On high-value servers, consider restricting outbound traffic too, so malware cannot freely call home.

Microsoft Defender Antivirus

powershell
Get-MpComputerStatus | Select-Object AMServiceEnabled,RealTimeProtectionEnabled,IsTamperProtected,AntivirusSignatureLastUpdated
Update-MpSignature
Set-MpPreference -PUAProtection Enabled -EnableNetworkProtection Enabled -MAPSReporting Advanced -SubmitSamplesConsent SendSafeSamples
  • Real-time protection and cloud-delivered protection should be on.
  • Tamper protection stops malware from switching Defender off. It is managed from the Windows Security app, Intune or Microsoft Defender for Endpoint, not from this PowerShell.
  • If you run a third-party EDR, Defender goes passive by design. Make sure something is actively protecting every server.

Attack Surface Reduction (ASR) rules

ASR rules block behaviours that malware relies on. Roll out in audit mode, check the events, then block.

powershell
# Audit mode first (2 = audit, 1 = block). Rule GUIDs below are Microsoft's published IDs.
$rules = @{
  '9e6c4e1f-7d60-472f-ba1a-a39ef669e4b2' = 'Block credential stealing from LSASS'
  'd1e49aac-8f56-4280-b9ba-993a6d77406c' = 'Block process creations from PsExec and WMI commands'
  'a8f5898e-1dc8-49a9-9878-85004b8a61e6' = 'Block web shell creation for servers'
}
foreach ($id in $rules.Keys) {
  Add-MpPreference -AttackSurfaceReductionRules_Ids $id -AttackSurfaceReductionRules_Actions AuditMode
}
Get-MpPreference | Select-Object -ExpandProperty AttackSurfaceReductionRules_Ids

Read what would have been blocked:

powershell
Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-Windows Defender/Operational'; Id=1122 } -MaxEvents 20 |
  Select-Object TimeCreated,Message

Event 1122 is audit (would have blocked) and 1121 is a real block. After a couple of weeks with no legitimate hits, switch to block:

powershell
Add-MpPreference -AttackSurfaceReductionRules_Ids 9e6c4e1f-7d60-472f-ba1a-a39ef669e4b2 -AttackSurfaceReductionRules_Actions Enabled

The PsExec/WMI rule can interfere with admin tooling and some management products. Add exclusions deliberately, never broad ones.

Protect credentials in memory

Attackers who get onto a server try to read credentials from LSASS memory. Two controls make that much harder.

LSA protection runs LSASS as a protected process:

powershell
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /v RunAsPPL /t REG_DWORD /d 1 /f
# Reboot to apply

Credential Guard isolates secrets using virtualisation-based security. Windows Server 2025 enables it by default on hardware that meets the requirements (domain controllers are excluded). Check it:

powershell
Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard |
  Select-Object SecurityServicesRunning,VirtualizationBasedSecurityStatus

A value of 1 in SecurityServicesRunning means Credential Guard is running. It can break unconstrained Kerberos delegation and NTLMv1, so test applications that depend on those.

Application control: WDAC (App Control for Business) and AppLocker

The strongest control against unknown malware is to only allow approved code to run. Windows has two tools: WDAC (stronger, kernel-enforced) and AppLocker (simpler, older). Start in audit mode on a reference server.

powershell
# Build a policy that trusts what is installed now (example), then set it to audit mode
New-CIPolicy -FilePath .\Baseline.xml -Level Publisher -Fallback Hash -UserPEs -ScanPath "C:\Program Files"
Set-RuleOption -FilePath .\Baseline.xml -Option 3          # option 3 = Audit Mode
ConvertFrom-CIPolicy -XmlFilePath .\Baseline.xml -BinaryFilePath .\Baseline.cip

Deploy the .cip with Group Policy, Intune or Microsoft's tooling (the App Control Policy Wizard is friendlier than raw PowerShell). Then read the events in Applications and Services Logs, Microsoft, Windows, CodeIntegrity, Operational: event 3076 is an audit hit and 3077 is a block. Add the legitimate items to the policy, and only switch to enforced mode when the audit log is quiet.

Also remove the old PowerShell engine if it is still present, since it bypasses modern logging:

powershell
Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root

Event IDs to remember

Event Source Meaning
1121 / 1122 Defender Operational ASR block / ASR audit
5007 Defender Operational Defender configuration changed
5001 Defender Operational Real-time protection disabled
3076 / 3077 CodeIntegrity Operational WDAC audit / block

🧪 Lab

  1. Set the firewall profiles as above and review the enabled inbound rules.
  2. Run Get-MpComputerStatus and fix anything disabled.
  3. Add the three ASR rules in audit mode, run a normal workload for a day, then read events 1122.
  4. Enable LSA protection, reboot, and check Credential Guard status.
  5. Create a WDAC audit policy for a test server and read the 3076 events.

Checkpoint

  1. Why start ASR and WDAC in audit mode?
  2. What is the difference between Defender events 1121 and 1122?
  3. What attack do LSA protection and Credential Guard defend against?
  4. How do you check whether Credential Guard is running?
  5. Why remove PowerShell v2?