Skip to content
File upload Write-up Intermediate

RCE by uploading a web config

The file upload feature blocked executable extensions like .asp and .aspx but allowed uploading a web.config file. By uploading a crafted web.config that added a handler granting script execution rights to .config files, the attacker could execute arbitrary commands on the server.

003random Follow

Published on poc-server.com

By uploading a web.config I was able to bypass the blacklist, which blocks files with an executable extension (such as ‘.asp’ and ‘.aspx’). After setting execution rights to ‘.config’ and then adding asp code in the web.config I was able to execute code.

003random (@rub003), on poc-server.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

During an internship, with permission from the school, the researcher tested the school's digital environment. Simple reconnaissance turned up a file upload feature that let students upload documents. The server behind it was Microsoft IIS, and the upload was meant to accept documents only, with a blacklist blocking executable extensions such as .asp and .aspx.

The write-up describes how a web.config file was uploaded instead, given execution rights, and used to run ASP code, resulting in remote code execution.

Setup

The testing was done against the school environment after gaining permission. No specific accounts, roles or tools are named beyond a browser and the upload form itself. The relevant precondition was that the upload feature was reachable and that the researcher could attempt uploads as a student.

Finding it

The researcher first confirmed the platform. Browsing to a path containing < produced an ASP.NET error page, because ASP.NET detected a dangerous Request.Path value:

Text
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (<).

The report notes that the bottom of such a page usually shows the Microsoft .NET Framework Version and the ASP.NET Version. The response header also gave the server away:

HTTP
Server: Microsoft-IIS/8.5

That identified a Microsoft IIS server and justified platform specific testing.

Exploitation

Step 1: try executable extensions

The upload was tested for unrestricted file upload. Test files with basic extensions such as .aspx, .asp and .asmx were rejected with:

Text
Description: Upload failed - Access Denied. User {{user_id}} does not have permissions to add content package to folder with ID {{folder_id}}

Many other extensions that carry execution rights were tried as well, without success. The blacklist was doing its job for the obvious cases.

Step 2: think about configuration files

The researcher considered uploading a file that normally holds metadata and other information about the application. .htaccess came to mind first, but on a Windows server the equivalent is web.config.

A web.config file customises how a site, or a specific directory, behaves. Placed in the root it affects the whole site; placed in a /content directory it affects only that directory. It can control database connection strings, error behaviour and security. web.config files are XML documents, and .config is not an extension in the same sense as .html or .txt.

Step 3: upload the web.config

The web.config upload produced no error and the file appeared in the directory. The researcher then adapted example code from Soroush's article on uploading a web.config for fun and profit, modifying it to execute a cmd command. The payload adds a handler that gives the web.config read, script and write permissions, then places ASP code inside <% %> inside a comment so the file remains valid XML.

Step 4: trigger execution

Browsing to the uploaded file executed the whoami command, which returned:

Text
nt authority\system

That confirmed remote code execution as the SYSTEM account.

Step 5: clean up and report

The other test uploads were removed and the issue was reported to the director of the school, who contacted the third party behind the digital school environment. The researcher later received a laptop from them as a bounty, covering this bug and some others.

Root cause

The upload blacklist blocked files with executable extensions such as .asp and .aspx, but did not block .config. On IIS, a web.config file is not inert content: it is configuration that the server reads and acts on. Because the uploaded file was served from a directory where it took effect, its handler definition granted the file read, script and write permissions, and the ASP code embedded in an XML comment was executed when the file was requested. The blacklist approach, which enumerates dangerous extensions rather than allowing only known safe ones, left the configuration file path open.

Impact

An attacker able to reach the upload feature could upload a web.config and obtain code execution on the server. In this case the command ran as nt authority\system, the highest local privilege on Windows. The report does not describe what else was reachable from that position.

Fix

The report does not state what the third party changed. The general lesson it draws is to test platform specific files when a file upload is found, and to prefer uploading a file that echoes your username rather than a shell.

Variants to test

  1. Upload a web.config to a directory where configuration is honoured, then request the file and check whether an embedded command runs. A positive result is command output in the response, such as a username.
  2. Try other platform specific configuration files, for example .htaccess on Apache or .user.ini on PHP, where the upload directory is served by that stack. A positive result is a change in how files in that directory are handled.
  3. Test extensions that carry execution rights but are less commonly blacklisted, and observe whether the error message differs from the one returned for .aspx, .asp and .asmx. A positive result is a successful upload where the executable extensions were rejected.
  4. Check whether the upload directory serves uploaded files with script permissions at all. A positive result is a request to the uploaded file being processed by the server rather than returned as static content.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

A student, during an internship, was allowed to test the security of their school's digital environment. They found a file upload feature that students use to submit documents. The server was a Microsoft IIS web server, and the upload was supposed to accept only documents. It blocked files with executable extensions like .asp and .aspx.

The student uploaded a different file, called web.config, which is a configuration file for IIS. The upload was not blocked. Then they made that file run code, and the server executed a command. That is remote code execution (RCE): running your own commands on someone else's server.

This article explains every step in beginner terms, including what a web server is, what a file extension is, what a blacklist is, and why a configuration file can be dangerous.

Background: the pieces you need to know

Before walking through the steps, here are the basic ideas. You can skim this and come back when a term appears.

  • Web server: a program that listens for requests from browsers and sends back web pages, files or errors. Microsoft IIS (Internet Information Services) is one web server, commonly used on Windows. Apache and Nginx are others.
  • File extension: the part after the last dot in a filename, like .txt or .jpg. It hints at what kind of file it is. Servers often decide how to treat a file based on its extension.
  • Executable extension: an extension that tells the server to run the file as a program instead of just sending it to the browser. On IIS, .asp and .aspx are examples: the server processes the code inside and returns the result.
  • Blacklist: a list of things that are forbidden. Here, the upload feature had a blacklist of executable extensions: it refused files ending in .asp, .aspx, and similar. A blacklist only blocks what someone thought of; anything not on the list gets through.
  • Whitelist: the opposite: only allow things on a list of safe items. A whitelist is usually safer because unknown items are rejected by default.
  • Reconnaissance (recon): the early phase of testing where you look around, without attacking, to learn what software and features are in use. Like reading the labels on a building's doors before trying to open them.
  • HTTP response header: extra information a server sends along with a web page. Headers are not visible in the page itself; you see them with browser developer tools or a tool like curl. They can reveal the server software and version.
  • ASP.NET: Microsoft's framework for building web applications. It runs on IIS and processes .aspx files (and others).
  • web.config: an XML configuration file used by IIS and ASP.NET. It tells the server how to behave for a site or a folder: things like database connection strings, error pages, and security settings. It is not a normal document; the server reads it and obeys it.
  • XML: a text format for structured data, using tags like <name>value</name>. web.config is written in XML.
  • Handler: in IIS, a handler is a rule that says which program processes which kind of file. For example, a handler might say that .aspx files are processed by ASP.NET.
  • Remote code execution (RCE): a vulnerability where an attacker can make the server run commands or code of their choosing. It is one of the most serious kinds of bugs because the attacker can then do whatever the server's user account is allowed to do.
  • SYSTEM account: on Windows, the SYSTEM account is the most powerful local account. A program running as SYSTEM can control the machine.
  • whoami: a command that prints the name of the user account the command is running as. It is a safe way to prove code execution without causing damage.
  • Bounty: a reward, often money or a gift, given for reporting a security problem responsibly.

Finding the server type

The tester first did simple reconnaissance. They browsed to a path containing the < character. Why? Because many servers react in a telling way to unexpected input. On an ASP.NET site, a < in the URL path is considered dangerous, and ASP.NET returns an error page instead of the normal page.

The error looked like this:

Text
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (<).

This is an error page from ASP.NET. It says that the value in the request path contained <, which ASP.NET treats as potentially dangerous. The report notes that the bottom of such a page usually shows the Microsoft .NET Framework Version and the ASP.NET Version. Those version numbers are useful because they tell you which software family you are dealing with.

The response also included this header:

HTTP
Server: Microsoft-IIS/8.5

That header is the server introducing itself: it is Microsoft IIS, version 8.5. With that knowledge, the tester could focus on IIS-specific behaviour. Different servers have different features and different files they care about, so knowing the platform saves time.

Testing the upload

The tester found a file upload feature that students use to submit documents. They tried to upload test files with basic executable extensions: .aspx, .asp and .asmx. These are file types that IIS would normally process as code. The upload was rejected with this message:

Text
Description: Upload failed - Access Denied. User {{user_id}} does not have permissions to add content package to folder with ID {{folder_id}}

In plain words: the upload failed, access denied, because the user does not have permission to add a content package to that folder. The message is a bit generic, but the result was clear: those extensions were blocked. The tester also tried many other extensions that can carry execution rights, without success. The blacklist was catching the obvious dangerous extensions.

At this point, the tester had to think differently. If the upload only blocks a list of bad extensions, what file type is not on that list but still matters to the server? The answer came from experience with ASP.NET: configuration files.

The idea: upload a configuration file

The tester first thought of .htaccess, which is a configuration file used by Apache web servers. But this was a Windows server running IIS, so the equivalent is web.config. Both are files that change how the server treats a folder. If you can upload one and the server reads it, you can change the server's behaviour.

What is a web.config file? It lets you customise how your site, or a specific directory, behaves. For example, if you place a web.config in your root directory, it affects your entire site. If you place it in a /content directory, it only affects that directory. With a web.config, you can control:

  • Database connection strings.
  • Error behaviour.
  • Security.

web.config files are XML documents. The report points out that .config is not an extension like .html or .txt. That is an important detail: .config is not just a label; it is a file the server recognises and acts on.

Uploading the web.config

The tester uploaded a web.config file. To their surprise, no error appeared and the file was shown in the directory. The upload went through.

Now the file was on the server, but it was just sitting there. The next step was to make it do something. The tester found an article by Soroush about uploading a web.config file for fun and profit. That article contained example code to execute code from a web.config. The tester modified it to execute a cmd command. The report does not include the exact payload code, but it describes what the payload does: it adds a handler that gives the web.config read, script and write permissions, and then places ASP code inside <% %> inside a comment so the file remains valid XML.

Let us unpack that. A handler is a rule that tells IIS which program processes which file. By adding a handler, the tester gave the web.config file read, script and write permissions. The handler grants read, script and write permissions, meaning the file can be read, executed as a script, and written to. Then the ASP code is placed inside <% %> tags, which is how ASP code is marked. But because the file must remain valid XML, the ASP code is put inside an XML comment. The ASP code is placed inside a comment so the file is still valid XML. This is a clever trick: the file is valid XML for the configuration system, and also contains executable code for the ASP handler.

Triggering the code

With the web.config uploaded and modified, the tester browsed to the file. The server processed it, and the whoami command ran. The output was:

Text
nt authority\system

That means the command ran as the SYSTEM account, the highest privilege level on Windows. The tester had achieved remote code execution. They could run commands on the server.

Cleaning up and reporting

The tester removed all the other test uploads and reported the issue to the director of the school. The director contacted the third party that runs the digital school environment. Later, the tester received a laptop from them as a bounty, covering this bug and some others, and they thanked him.

What went wrong (root cause)

The upload feature used a blacklist: it blocked files with executable extensions such as .asp and .aspx. But it did not block .config. On IIS, a web.config file is not inert content; it is configuration that the server reads and acts on. Because the uploaded file was served from a directory where it took effect, its handler definition granted the file read, script and write permissions, and the ASP code embedded in an XML comment was executed when the file was requested. The blacklist approach, which lists dangerous extensions instead of allowing only known safe ones, left the configuration file path open.

Impact

An attacker who can reach the upload feature could upload a web.config and obtain code execution on the server. In this case the command ran as nt authority\system, the highest local privilege on Windows. The report does not describe what else was reachable from that position.

Fix

The report does not state what the third party changed. The general lesson it draws is to test platform specific files when a file upload is found, and to prefer uploading a file that echoes your username rather than a shell.

Variants to test

If you are learning, here are safe ways to practise similar checks in a lab you own:

  1. Upload a web.config to a directory where configuration is honoured, then request the file and check whether an embedded command runs. A positive result is command output in the response, such as a username.
  2. Try other platform specific configuration files, for example .htaccess on Apache or .user.ini on PHP, where the upload directory is served by that stack. A positive result is a change in how files in that directory are handled.
  3. Test extensions that carry execution rights but are less commonly blacklisted, and observe whether the error message differs from the one returned for .aspx, .asp and .asmx. A positive result is a successful upload where the executable extensions were rejected.
  4. Check whether the upload directory serves uploaded files with script permissions at all. A positive result is a request to the uploaded file being processed by the server rather than returned as static content.

Lessons for beginners

When you come across a file upload:

  • Try to upload platform specific files.
  • Do not give up.
  • Do not upload shells; instead upload a file that echoes your username.

A shell is a program that gives an attacker a command prompt on the server. Uploading one is risky and unnecessary for proving a bug. A simple command like whoami is enough to show that code execution is possible, and it is much less harmful.

Glossary

  • ASP.NET: Microsoft's framework for building web applications, running on IIS.
  • Blacklist: a list of forbidden items; anything not on the list is allowed.
  • Bounty: a reward given for reporting a security issue.
  • Configuration file: a file that changes how software behaves, such as web.config.
  • web.config: an XML configuration file used by IIS and ASP.NET to control site or directory behaviour.
  • Executable extension: a file extension that causes the server to run the file as code, like .asp or .aspx.
  • File extension: the suffix after the last dot in a filename, indicating the file type.
  • Handler: in IIS, a rule that maps a file type to the program that processes it.
  • HTTP response header: extra information sent by a server alongside a response, such as Server: Microsoft-IIS/8.5.
  • IIS (Internet Information Services): Microsoft's web server software.
  • Remote code execution (RCE): a vulnerability that lets an attacker run their own commands on a server.
  • Reconnaissance (recon): the information-gathering phase of security testing.
  • SYSTEM account: the most powerful local account on Windows.
  • whoami: a command that prints the current user name.
  • Whitelist: a list of allowed items; anything not on the list is rejected.
  • XML: a text format for structured data using tags.
  • .htaccess: a configuration file used by Apache web servers.
  • .user.ini: a configuration file used by PHP.
  • Shell: a program that provides a command-line interface on a server.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.