Skip to content
File upload Disclosed report Intermediate CVE-2021-32679

Download of file with arbitrary extension via injection into attachment header

The Nextcloud Mail app failed to escape quotes in the Content-Disposition header when downloading attachments, allowing an attacker to send a file with a benign-looking extension that is saved with a malicious extension. An attacker could bypass email attachment filtering and trick a user into downloading and opening a malicious file, potentially leading to code execution.

foobar7 Follow

Originally disclosed on HackerOne

Bounty$125 Medium 4.7 View original
  • Triaged in 6 hours
  • Fixed in 7 days
  • Paid in 7 days
  • Disclosed after 2 months

Description

When downloading mail attachments, the app fails to properly escape quotes in the content disposition header. Because of this, an attacker can send a victim a file with a benign extension such as .txt or .png which when downloaded will be stored with a malicious extension such as .bat or .docm.

This vulnerability can for example be exploited in the following scenarios:

  • It allows bypassing of extension-based attachment filtering by email providers (or other intermediate email systems), as is common in many networks.
  • As the attachment is displayed as a benign file in Nextcloud, a user may incorrectly trust it to be a benign file.

POC

  • Send a mail to an email address that is connected to Nextcloud Mail with an attached file called test.bat".png.
  • open the mail -> click on the attachment icon -> click on the download icon. While Nextcloud correctly displays the file as a benign .png file, it will be downloaded as test.bat instead.

Tested with Firefox under Windows.

As alternative to .bat files (which may be prevented from executing by Microsoft Defender SmartScreen), an attacker can also send other malicious files such as for example .vbs files, as well as .docm files containing macro viruses.

Request

    GET /nextcloud/index.php/apps/mail/api/messages/26/attachment/2 HTTP/1.1
    Host: 192.168.0.101

    HTTP/1.1 200 OK
    [...]
    Content-Disposition: attachment; filename="test.bat".png"
    [...]
    Content-Type: application/octet-stream

    C:\Windows\system32\calc.exe

Solution

Quotes should be properly escaped before being inserted into the Content-Disposition header.

Impact

Offering malicious files for download, leading to code execution on the computer of the victim if they download and open the file.

The original report as published on HackerOne, by foobar7. 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 application did not properly escape double quotes in the filename before inserting it into the Content-Disposition header, allowing an attacker to inject additional characters that alter the saved filename.

Impact

An attacker could offer malicious files for download, leading to code execution on the victim's computer if they download and open the file; the report notes that Microsoft Defender SmartScreen may prevent execution of .bat files, but other file types like .vbs or .docm could be used.

What the attacker needed

Victim uses Nextcloud Mail; attacker can send email to victim; victim downloads and opens attachment

How it was found

  1. Send an email with an attachment named to include a quote and a benign extension.
  2. Open the email in Nextcloud Mail and click the attachment icon.
  3. Click the download icon; the file is displayed as benign but downloaded with a malicious extension.

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.

When you download a file, the server tells your browser what to name it using a special header. If the server doesn't handle quotes correctly, an attacker can make a file look harmless (like a picture) but save it with a dangerous extension (like a program). This could trick you into running malicious software.

What is File upload?

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

More by foobar7

View all

17 more disclosed reports, best first.

More from Nextcloud

View all

The newest disclosed reports for this program.

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.