> For the complete documentation index, see [llms.txt](https://dev-angelist.gitbook.io/writeups-and-walkthroughs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-angelist.gitbook.io/writeups-and-walkthroughs/portswigger-web-security-academy/server-side-vulnerabilities/file-upload-vulnerabilities/web-shell-upload-via-content-type-restriction-bypass.md).

# Web shell upload via Content-Type restriction bypass

## Description

This lab contains a vulnerable image upload function. It attempts to prevent users from uploading unexpected file types, but relies on checking user-controllable input to verify this.

To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file `/home/carlos/secret`. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: `wiener:peter`

## Solution

<figure><img src="/files/CbBIkaCPK0h9SVzkx2GO" alt=""><figcaption></figcaption></figure>

After login as Wiener user there's an upload option to upload avatar image:

<figure><img src="/files/dPO6MPaLmSDcNOjcPggE" alt=""><figcaption></figcaption></figure>

with the avatar image at this path/location:

[https://0a890067048524a181330c1d0073004e.web-security-academy.net](https://0a890067048524a181330c1d0073004e.web-security-academy.net/my-account?id=wiener)[/resources/images/avatarDefault.svg](https://0ab300990381641d80b5b7de005e0030.web-security-academy.net/resources/images/avatarDefault.svg)

We need to obtain Carlos's secret, we can do it upload a php shell (`php_web_shell.php`) that get secret file content

```php
<?php echo file_get_contents('/home/carlos/secret'); ?>
```

<figure><img src="/files/FBWLbseNhPk2vqDbaZ2K" alt=""><figcaption></figcaption></figure>

there's a filtering and we can't upload php shell, seeing the output message file types allowed are: image/jpeg and image/png, so we can use the Burp Repeater to modify request updating Content-Type

<figure><img src="/files/kNhOeeRFJRytN32H2oK3" alt=""><figcaption></figcaption></figure>

Infact, inserting: image/jpeg we're able to upload our php web shell bypassing controls:

<figure><img src="/files/CXO84GlnSLdDTHC6eIA0" alt=""><figcaption></figcaption></figure>

We know the file location and we can open it going to: [https://0a890067048524a181330c1d0073004e.web-security-academy.net](https://0a890067048524a181330c1d0073004e.web-security-academy.net/my-account?id=wiener)[/files/avatars/php\_web\_shell.php](https://0ab300990381641d80b5b7de005e0030.web-security-academy.net/files/avatars/php_web_shell.php)

<figure><img src="/files/CpbF1yCKYLhjuIPv27z0" alt=""><figcaption></figcaption></figure>

<details>

<summary>Carlos's Secret</summary>

FYw9wjdc53Z6eePuSDiWMPkmrVT6kzvF

</details>

Obtaining Carlos's secret and solving the lab.

<figure><img src="/files/2W4VsaSyCQWCg2G4h0bV" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dev-angelist.gitbook.io/writeups-and-walkthroughs/portswigger-web-security-academy/server-side-vulnerabilities/file-upload-vulnerabilities/web-shell-upload-via-content-type-restriction-bypass.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
