IIS web.config Upload Attacks and How to Block Them

7 min read188 courses on OnlySecurity

On IIS, a configuration file is not only something an administrator edits. By default, any web.config that sits in a served folder is read and applied to that folder, which means a file upload feature that can write one has quietly become a configuration feature. This article covers how that works, what an attacker can change, how to test it in a lab and how to close it. Test only networks and systems you own or are authorised to assess.

How IIS reads configuration

IIS builds the effective settings for a URL by layering files. applicationHost.config, in %windir%\system32\inetsrv\config, holds the server-wide defaults and, Microsoft says, locks most IIS sections so that web.config files cannot override them. The sections that matter here are not locked: Microsoft’s feature delegation overview says site owners can set handlers in web.config by default, and its request filtering guide overrides a server setting from an application’s web.config. IIS reads web.config files in a virtual directory’s physical folder and in its child directories, and the allowSubDirConfig attribute switches the child directories off.

What a hostile web.config can change

Three settings matter most.

  1. system.webServer/handlers maps a path or extension to the component that processes it, such as the static file, CGI, FastCGI, ISAPI or ASP.NET handlers. A mapping that makes an unexpected file name run as script is the heart of the problem.
  2. security/requestFiltering is the allow and deny layer. Its fileExtensions collection permits or refuses extensions, and hiddenSegments makes segments such as web.config, bin and App_Code unreachable. Both take add, remove and clear, so a lower-level file can lift an inherited rule.
  3. accessPolicy on handlers filters handlers by the rights they require. Microsoft calls it a filtering mechanism, not an enforceable security policy.

Soroush Dalili published the technique in 2014 and extended it in Uploading web.config for Fun and Profit 2 (2019), the primary research here. He splits the cases by where the file lands. In an application root it has wide influence over ASP.NET, and he warns that replacing an existing web.config there can break the application. In a subfolder or virtual directory, which he calls the most common case, some ASP.NET settings cannot be defined, but handler and request filtering changes still apply when the server allows them.

On ASP.NET Core, Microsoft says the ASP.NET 4.x sections such as <system.web> are not used and the IIS static file module is not functional for the app, but request filtering still works and IIS still applies <system.webServer> settings where the feature functions.

Related upload problems

web.config is one case of a general rule. The OWASP File Upload Cheat Sheet lists the others: double extensions, null bytes, case tricks, alternative extensions mapped to a server-side interpreter, a client-controlled Content-Type header and special characters in filenames. MITRE tracks the outcome as T1505.003, Web Shell and the way in as T1190, Exploit Public-Facing Application. For script that reaches browsers, see XSS and Content Security Policy. For scanning that may surface an upload form, see Nikto and sqlmap.

A benign test in your own lab

Use a Windows Server VM you own with a sample site and an upload folder. Map where uploads land, then place the harmless test web.config below in that folder and request a .txt file. A 404.7 means the folder honours configuration from a file sitting in content, and any section not locked there, handlers included on a default install, would apply the same way. Add the location block below to applicationHost.config and repeat: the request should now fail with HTTP 500.19, the error Microsoft documents for a lower-level file setting a locked section. The Web Security Fundamentals: OWASP Top 10:2025 and ASVS 5.0 course covers security misconfiguration and verifying file handling against the ASVS.

Defensive configuration

Checked against IIS 10.0 in the Microsoft Learn IIS configuration reference, whose handlers, fileExtensions and hiddenSegments pages say the element was not modified in IIS 10.0. Test each snippet in a lab before production.

<!-- Lab test file: place in the upload folder, then request a .txt file -->
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension=".txt" allowed="false" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
<!-- applicationHost.config: lock the upload path and allow only what it serves -->
<location path="Default Web Site/uploads" overrideMode="Deny">
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions allowUnlisted="false">
          <clear />
          <add fileExtension=".jpg" allowed="true" />
          <add fileExtension=".png" allowed="true" />
          <add fileExtension=".pdf" allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
    <staticContent />
    <handlers accessPolicy="Read">
      <clear />
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
  </system.webServer>
</location>
%systemroot%\system32\inetsrv\appcmd search config "Default Web Site/" /section:system.webServer/handlers
%systemroot%\system32\inetsrv\appcmd lock config /section:system.webServer/handlers
%systemroot%\system32\inetsrv\appcmd lock config /section:system.webServer/security/requestFiltering
Get-ChildItem -Path 'D:\inetpub\wwwroot' -Recurse -Force -Filter 'web.config' | Sort-Object LastWriteTime -Descending | Select-Object FullName, LastWriteTime
  1. The first file is the lab test. Request filtering acts on the URL, verb, headers, query string and request size, not on uploaded content, so it cannot stop a web.config upload; that check belongs in the application.
  2. The location block clears the handlers for the upload folder and adds back only the static file handler, copied from the stock applicationHost.config entry in Microsoft’s Web API troubleshooting guide; compare it with your own file. accessPolicy="Read" drops the Script right the stock collection grants, but it is only a filter. overrideMode="Deny" locks the sections inside the block from that path downwards, as Microsoft’s locking guide describes, so a web.config there that sets them causes an error instead of taking effect. Only named sections are locked: staticContent is included because Dalili’s research remaps MIME types through it, but directoryBrowse, defaultDocument and httpProtocol stay open unless you lock them too. The handler part covers files IIS serves itself, not ASP.NET Core static file middleware.
  3. appcmd search config lists every location under the site that configures handlers. The two lock config commands follow Microsoft’s documented syntax (its example is /section:asp) but lock server wide, so applications that configure those sections lower down will hit lock violation errors. Prefer the path lock.
  4. The PowerShell lists web.config files under the content root, hidden ones too, newest first, to compare with a baseline.

Detection and defence

The strongest control is keeping uploads away from configuration-reading folders: outside the web root or on another server, as OWASP recommends, or in Microsoft’s ASP.NET Core guidance, a dedicated upload area outside the app’s directory tree with execute permissions disabled. Serve public files through an application handler mapping an identifier to a file. Generate the filename, allow-list extensions after decoding, check content type and file signature too, and give the application identity write access only to the upload store, as MITRE’s M1018 advises on limiting who can modify the web directory.

Then lock the server. OWASP’s cheat sheet names web.config directly and recommends disabling per-directory overrides on upload folders, such as locked IIS handler mappings. Lock handlers, request filtering and static content for the upload path as above, and consider allowSubDirConfig="false", which Dalili also recommends. Microsoft’s IIS Support blog says it can be set only in applicationHost.config, and Microsoft describes it as covering child directories of the virtual directory’s folder, not that folder itself. Set it on the virtual directory above the upload folder and retest, because legitimate web.config files in its subfolders stop applying too.

For detection, new or changed web.config files under content folders are the clearest signal: compare the listing above on a schedule, use file integrity monitoring, or watch Sysmon event ID 11 for web.config creation, which MITRE’s DET0394 uses, alongside w3wp.exe spawning cmd.exe or powershell.exe. IIS logs request filtering denials as 404 with a substatus, 404.7 for a denied extension and 404.8 for a hidden segment, so a run of them against an upload path shows probing. Once the path is locked, HTTP 500.19 responses there are a supplementary alert, since a file that sets only an unlocked section raises none; the appcmd search config output covers handlers only.

Where to go next

The Web Security Fundamentals: OWASP Top 10:2025 and ASVS 5.0 course places checks like these within the OWASP Top 10:2025 Security Misconfiguration category and ASVS 5.0 verification. For the wider path from first scan to report, see Penetration Testing Field Notes.

This article replaces the KSEC ARK notes first published in 2019.

More from this author