Skip to content
RCE Disclosed report Advanced

(Authenticated) RCE by bypassing of the .htaccess blacklist

The file copy function in Nextcloud/ownCloud does not check the contents of a folder against the blacklist of forbidden files. An attacker with access to an external storage containing a .htaccess file can copy it into the local data directory, and if the data directory is inside the webroot, this allows execution of a malicious PHP file.

icewind1991 Follow

Originally disclosed on HackerOne

Critical 9.0 View original
  • Triaged in under an hour
  • Fixed in 2.6 years
  • Disclosed after 2.8 years

Storage::copyFromStorage doesn't check the content of a folder it copies against the list of blacklisted files. Meaning that if a user has access to an external storage (inc. fed. shares) that contains a .htaccess file, he can move the .htaccess file to the local data directory.

The attack works on any nextcloud/owncloud since federated sharing was introduced that uses apache and has the data directory inside the webroot (as is default)

Steps to reproduce:

  • Setup an evil instance (nc1) that has the file blacklist disabled (Filesystem.php line 616)
  • create a folder 'sharefolder/attack' in nc1 with the following files
    • .htaccess configured to "allow from all"
    • attack.php with the desired attack
  • Setup a non-evil instance (nc2) (or pick an existing nc instance that you want to attack)
  • Federated share 'sharefolder' from nc1 to nc2
  • In nc2, move 'sharefolder/attack' to 'attack' (outside the share)
  • navigate to http://nc2/data/userid/files/attack/attack.php

The original report as published on HackerOne, by icewind1991. 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 copy operation bypasses the file blacklist check because it only validates the folder name, not the individual files within it.

Impact

An authenticated attacker could achieve remote code execution on the victim server if it uses Apache and stores its data directory inside the webroot, which is the default configuration.

What the attacker needed

Attacker controls a federated share; victim uses Apache; data directory inside webroot (default)

How it was found

  1. Set up an attacker-controlled Nextcloud instance with the file blacklist disabled.
  2. Create a folder containing a .htaccess file that allows access and a malicious PHP file.
  3. Federated-share that folder from the attacker instance to the victim instance.
  4. On the victim instance, move the shared subfolder outside the share into the local data directory.
  5. Access the malicious PHP file via the web to execute code.

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.

Nextcloud and ownCloud are file-sharing programs. They keep a list of file types that are not allowed, like .htaccess, because those can change how the web server behaves. The bug is that when you copy a whole folder from another server, the program does not check the files inside that folder against the list. So an attacker can sneak a .htaccess file in, and if the data folder is reachable from the web, they can run their own code on the server.

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.