Windows

Hardening a Windows Server that runs IIS: the checklist I work through

In this article14 sections

A Windows Server running IIS is a perfectly good way to host .NET applications, classic ASP and many business systems. It is also, by default, a server with far more switched on than a website needs: a long list of roles and features, a remote desktop listening on the internet, response headers that announce the exact software version, and an application pool configuration that has not been looked at since installation.

This checklist is the order I work through when I take over or build an IIS server. Each item says what it protects and how to check it. Commands are PowerShell, run in an elevated window. Change one thing at a time, test the site after each, and take a snapshot or backup before you begin.

1. Patch first, on a schedule

An unpatched server is the single biggest risk. Check what is installed and what is pending:

Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 10
(Get-ComputerInfo).OsName
(Get-ComputerInfo).OsVersion

Make sure the operating system is still in support, because an out-of-support Windows Server receives no security updates and cannot be made safe by any other setting. Set a patch day (monthly, after the Microsoft release) and a reboot window, and tell the people who use the site. The same goes for the .NET runtime or hosting bundle, and for SQL Server if it runs on the machine.

2. Install only the IIS features you use

Every installed feature is surface area. List what is there:

Get-WindowsFeature Web-* | Where-Object Installed | Select-Object Name, DisplayName

Compare it with what the site needs. A typical .NET site needs the core web server, static content, default document, request filtering, the right ASP.NET or .NET Core hosting module, HTTP errors, logging, and compression. It rarely needs directory browsing, WebDAV, FTP server (use SFTP elsewhere) or the legacy management scripts. Remove what you do not use, one at a time:

Uninstall-WindowsFeature Web-Dir-Browsing, Web-DAV-Publishing

Check the site afterwards; a feature you removed may have been used by something unexpected.

3. One application pool per site, with its own identity

Application pools isolate sites from each other. Give every site its own pool running as the default ApplicationPoolIdentity, a low-privilege virtual account created for that pool. List pools and identities:

Import-Module WebAdministration
Get-ChildItem IIS:\AppPools | Select-Object Name, @{n='Identity';e={$_.processModel.identityType}}, managedRuntimeVersion

Never run a site as LocalSystem or an administrator account to “make a permission error go away”. Fix the permission instead (next step).

4. Tight file permissions

The pool identity needs to read the site files and write only where the application truly writes (uploads, logs, a cache folder). Everything else should be read-only to it. For a site called example with a pool named example:

icacls "C:\inetpub\example" /inheritance:r /grant "Administrators:(OI)(CI)F" /grant "SYSTEM:(OI)(CI)F" /grant "IIS AppPool\example:(OI)(CI)RX"
icacls "C:\inetpub\example\App_Data" /grant "IIS AppPool\example:(OI)(CI)M"

Read the first line carefully: it removes inherited permissions and sets an explicit list (administrators and the system get full control, the pool may read and run). The second line then lets the pool modify one folder where the application writes. Run these only when you know who else needs access (for example the user that deploys files), save the current permissions first with icacls "C:\inetpub\example" /save acl-backup.txt /t, and test the site afterwards. Keep configuration files with connection strings out of the web root where the framework allows, and never store secrets in files that IIS would serve as downloads.

5. Stop announcing the software and its version

Browsers and scanners do not need to know that you run IIS and which version of ASP.NET. Remove the X-Powered-By header:

Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter "system.webServer/httpProtocol/customHeaders" -Name "." -AtElement @{name='X-Powered-By'}

Remove the Server header on IIS 10 and later:

& "$env:windir\system32\inetsrv\appcmd.exe" set config /section:requestFiltering /removeServerHeader:true

Hiding headers is not security by itself, but it denies automated scanners an easy fingerprint and costs nothing.

6. Errors that do not leak

A detailed error page can show file paths, stack traces and connection strings to anyone who triggers it. In web.config:

<system.webServer>
  <httpErrors errorMode="DetailedLocalOnly" />
</system.webServer>
<system.web>
  <customErrors mode="RemoteOnly" />
</system.web>

DetailedLocalOnly shows detail only when browsing from the server itself. For ASP.NET Core, make sure the environment is Production (the ASPNETCORE_ENVIRONMENT variable), so the developer exception page is not enabled. Turn directory browsing off, which is the default but worth confirming in the site’s settings.

7. HTTPS and security headers

Install a valid certificate, bind it to port 443, and redirect port 80 to HTTPS (the URL Rewrite module does this cleanly). Then set the response headers that protect browsers, in web.config or in the IIS Manager’s HTTP Response Headers:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Strict-Transport-Security" value="max-age=300" />
      <add name="X-Content-Type-Options" value="nosniff" />
      <add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
      <add name="X-Frame-Options" value="SAMEORIGIN" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

Start HSTS at a short max-age and raise it over weeks once you are sure everything works over HTTPS. A Content-Security-Policy is worth adding and should be introduced in report-only mode first; the principles are the same as on any web server.

Do not trust a registry setting for TLS. Which protocol versions and cipher suites are enabled depends on the Windows Server version and its update level, and it is easy to get wrong. Verify what the server really offers from the outside, with an independent scanner (SSL Labs) or nmap --script ssl-enum-ciphers -p 443 yourserver. You want TLS 1.2 and 1.3 only (1.3 where the version supports it), no old protocol versions and no weak cipher suites. A tool such as IIS Crypto can apply a vetted template, but always test the result from outside.

8. Remote Desktop: the way most Windows servers are breached

An RDP port open to the whole internet is attacked constantly. Do at least these:

  • Do not expose port 3389 to everyone. Allow it only from your office or a VPN address, with the Windows Firewall or the provider’s firewall:
New-NetFirewallRule -DisplayName "RDP from office" -Direction Inbound -Protocol TCP -LocalPort 3389 -RemoteAddress 203.0.113.10 -Action Allow
Disable-NetFirewallRule -DisplayName "Remote Desktop - User Mode (TCP-In)"

(Use your own address, and keep another way in until you have tested the new rule. Disabling the built-in rule while the new one is wrong would lock you out.)

  • Require Network Level Authentication (the default on current versions).
  • Use unique named accounts, not a shared “Administrator”. Rename or disable the built-in Administrator account where practical, and use strong, unique passwords.
  • Set an account lockout policy so that repeated guessing locks the account for a while.
  • Better still, put RDP behind a VPN and close it to the internet completely.

9. The Windows Firewall

Only the ports the server serves should be reachable. For a web server that is usually 80 and 443 plus a restricted management path:

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

Read the list of enabled inbound rules and disable what you do not recognise or need (file sharing, remote management, old applications). SQL Server, if installed, must not be reachable from the internet: allow its port only from the application server, or bind it to the local machine.

10. Accounts and Defender

Get-LocalUser | Select-Object Name, Enabled, LastLogon
Get-LocalGroupMember Administrators
Get-MpComputerStatus | Select-Object AntivirusEnabled, RealTimeProtectionEnabled, AntivirusSignatureLastUpdated

Every enabled local user should have a person attached to it. Every member of Administrators should be there on purpose. Microsoft Defender should be on, real-time protection enabled and signatures current; if you run another endpoint product, confirm it is the one that is actually active and updated.

11. Logging that you will actually read

IIS writes a W3C log for each site, and Windows writes security events. Make sure they exist and do not fill the disk:

Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter "system.applicationHost/sites/siteDefaults/logFile" -Name "directory"
Get-ChildItem C:\inetpub\logs\LogFiles -Recurse | Measure-Object Length -Sum

Move the log folder off the system drive if space is tight, and set a clean-up task (delete logs older than your retention period, for example 90 days). Look at failed logons occasionally:

Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 20 | Select-Object TimeCreated, @{n='Account';e={$_.Properties[5].Value}}, @{n='Source';e={$_.Properties[19].Value}}

A long run of failures from one address means someone is guessing your password. If you see successful logons (event 4624) from places you do not expect, that is the more important finding.

12. Backups, and a restore you have tried

Back up the site files, the IIS configuration (C:\Windows\System32\inetsrv\config, or export with appcmd add backup), the databases, and the certificates and their private keys. Keep at least one copy off the server and off the same account. Windows Server Backup or the provider’s snapshots are fine as one layer, but a snapshot taken while the database is mid-write is not a reliable restore: use SQL Server’s own backups for the database. Then do the part most people skip: restore to a test machine and open the site.

A rollout order that keeps the site up

  1. Snapshot, and confirm you can restore it.
  2. Patch and reboot in a window.
  3. Remove unused features; test.
  4. App pool identities and permissions; test.
  5. Headers and error handling; test.
  6. RDP restriction (with a second way in); test.
  7. Firewall review.
  8. Logging and backups; run a restore.

When it is worth getting help

Windows servers behind small businesses are often built by whoever was available and left alone for years. If yours has not been reviewed, a structured hardening pass with a written before and after is a good investment: nothing exotic, just the items above done carefully, with rollback.

I work on Windows Server, IIS and SQL Server alongside Linux. You can see my profile on Upwork or read about Windows server administration. If you want a managed Windows plan with an IIS stack, SiteHarbour’s hosting pages are at siteharbour.com/hosting.