Phase 8: Hosts File Watchdog (Optional but Recommended)¶
Overview¶
You've hardened your device with seven layers of defense. But Windows is persistent. During major updates or security patches, Windows might detect the hosts file modifications as "suspicious" and automatically restore it to default – which would nullify your Phase 6 blocking.
Phase 8 adds an automatic watchdog that continuously monitors your hosts file. If Windows or any process removes your blocking entries, the watchdog automatically restores them within minutes. It's like having a security guard that patrols your hosts file 24/7.
What is a Watchdog?
A watchdog is a background process that monitors critical files and automatically repairs them if they're damaged or altered. In this case, it watches for deleted or modified blocking entries and restores them automatically.
Time required: 5 minutes
Status: Device already hardened from Phases 1-7
Why Phase 8 Might Be Necessary
- Windows 11 updates sometimes "repair" the hosts file if it detects anomalies
- Antivirus software might see the hosts file entries as "blocking legitimate Microsoft services"
- If you reinstall a Windows Update that includes device management components, it might try to restore the hosts file
- Phase 8 is insurance against these scenarios
How the Watchdog Works¶
The watchdog script:
- Runs every hour (automatically, invisible in background)
- Checks if your 9 blocking entries exist in the hosts file
- If any are missing:
- Instantly restores them
- Logs the restoration event with timestamp
- Re-applies read-only protection
- If all entries are intact: Does nothing (no log entry, zero resource usage)
The entire process takes less than 100ms and consumes negligible CPU/memory.
The 9 Entries Monitored¶
The watchdog monitors these exact entries:
0.0.0.0 ztd.desktop.microsoft.com
0.0.0.0 cs.dds.microsoft.com
0.0.0.0 enterpriseregistration.windows.net
0.0.0.0 enrollment.manage.microsoft.com
0.0.0.0 api.intune.microsoft.com
0.0.0.0 portal.manage.microsoft.com
0.0.0.0 dsirnpus.microsoft.com
0.0.0.0 dc.services.visualstudio.com
0.0.0.0 management.azure.com
Automated Installation¶
The script automatically:
- Creates a hidden directory:
C:\ProgramData\AutopilotBlock - Installs a PowerShell watchdog script
- Creates a Windows Scheduled Task that runs every hour
- Runs with NT AUTHORITY\SYSTEM (highest privilege, language-independent)
- Operates silently in background with zero user interaction
📥 Download phase8-hosts-watchdog.ps1
To install the watchdog:
- Download the file above
- Right-click on it and select Properties
- Check the "Unblock" checkbox at the bottom and click OK
- Right-click on the script file and select Run with PowerShell
- Click "Yes" when Windows asks for Administrator permission (UAC dialog)
- The watchdog is now installed and will monitor your hosts file continuously
Installation Complete
The watchdog is now running. You'll never see it (it runs silently every hour), but if Windows ever removes your blocking entries, they'll be automatically restored within 60 minutes.
How to Verify the Watchdog is Working¶
Check if the Scheduled Task Exists¶
- Press Windows + R
- Type
taskschd.mscand press Enter - Navigate to: Task Scheduler Library
- Search for:
Autopilot-Hosts-Watchdog - If you see it listed with Status: Running, the watchdog is active
Check the Watchdog Log¶
The watchdog keeps a log of all restoration events:
- Press Windows + R
- Type
%ProgramData%\AutopilotBlockand press Enter - Look for:
watchdog.log - If the log is empty, your hosts file hasn't been tampered with (good!)
- If there are entries with timestamps, those are times Windows tried to restore the hosts file and the watchdog restored your blocking entries
Example log entry:
2026-03-09 14:37:22 - ALERT: Hosts file modified. Restored entries: enterpriseregistration.windows.net, enrollment.manage.microsoft.com
Manual Scheduled Task Creation (If Needed)¶
If you prefer to create the task manually instead of using the script:
Step 1: Create the Watchdog Script Manually¶
- Press Windows + R
- Type
notepadand press Enter - Copy the following code:
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$logPath = "$env:ProgramData\AutopilotBlock\watchdog.log"
$requiredEntries = @(
"ztd.desktop.microsoft.com", "cs.dds.microsoft.com",
"enterpriseregistration.windows.net", "enrollment.manage.microsoft.com",
"api.intune.microsoft.com", "portal.manage.microsoft.com",
"dsirnpus.microsoft.com", "dc.services.visualstudio.com",
"management.azure.com"
)
# Recreate hosts file if completely deleted
if (-not (Test-Path $hostsPath)) {
New-Item -Path $hostsPath -ItemType File -Force | Out-Null
}
$hostsContent = Get-Content $hostsPath -Raw -ErrorAction SilentlyContinue
$missing = @()
# Check each blocking entry
foreach ($entry in $requiredEntries) {
if (-not ($hostsContent -match [regex]::Escape($entry))) {
$missing += $entry
}
}
# Restore if any entries are missing
if ($missing.Count -gt 0) {
try {
$hostsFile = Get-Item $hostsPath
if ($hostsFile.IsReadOnly) {
$hostsFile.IsReadOnly = $false
}
Add-Content -Path $hostsPath -Value "`n# Autopilot/MDM Block (Restored by Watchdog)" -Encoding ASCII
foreach ($entry in $missing) {
Add-Content -Path $hostsPath -Value "0.0.0.0 $entry" -Encoding ASCII
}
$hostsFile.IsReadOnly = $true
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - ALERT: Hosts modified. Restored entries: $($missing -join ', ')"
} catch {
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - CRITICAL ERROR: $_"
}
}
- Save as:
C:\ProgramData\AutopilotBlock\hosts-watchdog.ps1
Step 2: Create the Scheduled Task¶
- Press Windows + R
- Type
taskschd.mscand press Enter - In the right panel, click Create Basic Task...
- Name:
Autopilot-Hosts-Watchdog - Description:
Monitors and restores Autopilot/MDM blocking entries in the hosts file - Triggers:
- Repeat every 1 hour
- Duration: Indefinitely (or 10 years minimum)
- Action:
- Program:
powershell.exe - Arguments:
-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File "C:\ProgramData\AutopilotBlock\hosts-watchdog.ps1" - Advanced Settings:
- Run with highest privilege: Yes
- Run user: NT AUTHORITY\SYSTEM
What Happens If You Uninstall the Watchdog¶
If you ever want to remove the watchdog:
Via PowerShell (Admin):¶
Unregister-ScheduledTask -TaskName "Autopilot-Hosts-Watchdog" -Confirm:$false
Remove-Item -Path "$env:ProgramData\AutopilotBlock" -Recurse -Force
Via GUI:¶
- Open Task Scheduler (
taskschd.msc) - Find Autopilot-Hosts-Watchdog
- Right-click and select Delete
Why Keep the Watchdog?
We recommend keeping the watchdog permanently. It uses negligible resources (<0.1% CPU, <5MB memory) and provides insurance against accidental hosts file restoration during Windows updates. The cost of keeping it is zero; the benefit is significant protection.
Technical Details: Why This Works¶
Failure Scenario 1: Windows Detects "Suspicious" Hosts File¶
- Old defense: Hosts file gets overwritten by Windows repair
- Watchdog response: Detects missing entries within 60 minutes and restores them
Failure Scenario 2: Antivirus Quarantines Hosts Entries¶
- Old defense: AV removes the blocking entries thinking they're harmful
- Watchdog response: Detects missing entries and restores them even from AV quarantine
Failure Scenario 3: Windows Update Modifies Hosts¶
- Old defense: Update replaces your hosts file with default
- Watchdog response: Restores your blocking entries automatically post-update
Failure Scenario 4: Multiple Restoration Attempts¶
- Old defense: If Windows keeps trying to restore, you have to fix it manually
- Watchdog response: Automatically re-restores entries every hour, 24/7, indefinitely
The Complete Defense Stack (All 9 Phases)¶
| Phase | Defense Layer | Mechanism |
|---|---|---|
| 1 | Hardware Isolation | TPM cleared, Computrace disabled |
| 2 | Edition Selection | Windows 11 edition choice (Home recommended), offline preparation |
| 3 | Clean Installation | Fresh OS, offline setup, no enrollment |
| 4 | Licensing Lock | Corporate keys purged, edition locked down |
| 5 | Service Isolation | MDM services disabled at OS level |
| 6 | DNS Blocking | Enrollment domains blocked at network layer |
| 7 | Application Blocking | MDM executables blocked at firewall |
| 8 | Automatic Restoration | Hosts file continuously monitored and restored (optional) |
| 9 | Account Control | Personal account, policy refusal, Windows Hello security |
This 9-layer defense stack is enterprise-grade security (with Phase 8 being optional). Even a determined attacker would need to bypass all independent layers, most of which operate at different system levels and have no single point of failure.
Performance Impact¶
The watchdog has been designed for zero performance impact:
- CPU Usage: <0.1% (runs for <100ms every hour)
- Memory: <5MB resident, no memory leaks
- Disk I/O: Minimal (only reads hosts file, writes only if changes detected)
- Network: Zero (completely local operation)
- Logging: Only logs when actual restoration occurs (not every hour)
Proof That It's Invisible¶
You can verify the watchdog isn't slowing you down:
- Open Task Manager (Ctrl + Shift + Esc)
- Go to the Performance tab
- Watch during the scheduled time (every hour on the hour)
- CPU and disk activity remain flat – the watchdog is imperceptible
Recommended: Keep All 9 Phases Active¶
We recommend keeping all defenses from Phases 1-9 active permanently:
- No performance penalty – all defenses are passive or scheduled
- Maximum protection – defense-in-depth means losing one layer still leaves eight
- Automatic operation – Phase 8 runs invisibly; you never have to touch it
- Insurance policy – the cost of maintenance is zero; the benefit is priceless
Your device is now a secure personal computer that refuses corporate control, even in the face of aggressive Windows updates and enrollment systems.
Phase 8 Complete – Your Device is Locked Down
You now have 8 independent layers of protection, including automatic restoration of critical defenses. Your device is hardened against virtually any attempt at corporate re-enrollment or forced management. Congratulations – this is enterprise-grade security on a personal device.