Skip to content
RCE Disclosed report Intermediate

potential RCE and XSS via file upload requiring user account and default settings

Uploaded PHP files are normally only shown in a text editor, but if the data directory sits inside the web root and the username is known, the direct path to the uploaded script can be requested and executed. An attacker with a normal account could therefore run code on the server, and uploaded HTML could also be used for XSS.

rcejules Follow

Originally disclosed on HackerOne

High 8.8 View original
  • Triaged in 41 hours
  • Fixed in 3 months
  • Disclosed after 7 months

#potential RCE and XSS via file upload requiring user account and default settings

##Requirements

  1. User account that can upload files (NO admin)
  2. User account name on creation (usually the same as on creation/displayed name)
  3. data directory inside of nextcloud server folder (suggested by /var/www/nextcloud/config/config.sample.php)

##Tested on current release Version 16.0.4.1 stable Build: '2019-08-14T18:57:27+00:00 a1a245e88202d834f08f4c2e4451dcbe9baee3aa'

##Basic idea On nextcloud php files can be uploaded, but when clicked they are only shown in a text editor. If the URL to our skript is known, we get code execution. A RCE will work if the server has set it's data directory inside the nextcloud server folder and the username is known.

##config example The following is located in /var/www/nextcloud/config/config.sample.php: [https://github.com/nextcloud/server/blob/master/config/config.sample.php]

 *
 * Default to ``data/`` in the Nextcloud directory.
 */
'datadirectory' => '/var/www/nextcloud/data',

If this config is used, RCE is possible.

##Attack scenario: Short video attached. (To reproduce use a nextcloud instance and setup a user named attacker. Use any php script called shell.php, and set the datadirectory to /var/www/nextcloud/data)

  1. Login to obtained user account (assume his name is "attacker")
  2. upload malicious php script. (assume it is called "shell.php")
  3. navigate to https://www.ournextclouddomain.com/data/attacker/files/shell.php
  4. see some shells poppin

This is possible since we know the direct path to our php script.

Note: This can also be used for XSS since we can upload any html file!

##Prevention

  1. user accounts could extend a seed on their foldername like attacker-19320143158015
  2. usage of a custom seed inside the data directory.
  3. different config than on the example

Impact

RCE, extract ser data or modify config file (if no special permissions are set), take over the server, also XSS is possible

Attachments

The original report as published on HackerOne, by rcejules. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the data directory is placed inside the web root, so uploaded files are served and executed directly rather than only through the application.

Impact

An attacker with a normal account could achieve remote code execution, read user data, modify the config file if permissions allow, take over the server, and also perform XSS; this depends on the non-default data directory placement and knowing the username.

What the attacker needed

A normal user account; username known to attacker; data directory inside web root

The fix

The data directory should not be placed inside the web root, and user folder names should not be predictable.

How it was found

  1. Log in to the user account whose name is known.
  2. Upload a malicious PHP script.
  3. Navigate to the direct URL under the data directory for that user's files.
  4. The script executes on the server.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A user can upload a .php file. Normally it is only shown as text, but if the data directory is inside the server folder and the username is known, requesting the direct path runs the script, giving code execution.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Nextcloud

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.