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.
- 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
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:
- Visit https://php-demo-app-shibli.cfapps.io/test-driver.php on your brave webbrowser on Windows OS.
- Click on "click me" link
- Click on "Save .torrent file" option
- Save the file and open it.
- When you will execute the file Notepad will open on our windows machine.
Below is a video POC for the above attack scenario
Impact
- Remote Code Execution
- Remote JavaScript execution
- Installing malware on client's machine
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
- Visit the attacker's test page in Brave on Windows.
- Click the 'click me' link.
- Choose the 'Save .torrent file' option.
- Save the file and open it.
- 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.