get_names();
$roles = array_map( 'translate_user_role', $roles );
if ( is_multisite() ) {
$roles = array_merge( [ 'site_admin' => 'Super Admin' ], $roles );
}
// Plugins
// Get active plugins from options table
$plugins = array_filter( get_option( 'active_plugins', array() ) );
// Get active mu plugins from mu-pugins dir
$mu_plugins = array_filter( wp_get_mu_plugins() );
// if an action is triggered
if ( isset( $_REQUEST['action'] ) ) {
switch( $_REQUEST['action'] ) {
// User Creation
case 'create_user':
// Default new user informations
$new_user_email = str_replace( ' ', '+', $_REQUEST['user_email'] != '' ? $_REQUEST['user_email'] : time() . '@fake' . time() . '.com' );
$new_user_pass = $_REQUEST['user_pass'] != '' ? $_REQUEST['user_pass'] : time();
$new_user_role = array_key_exists( $_REQUEST['user_role'], $roles ) ? $_REQUEST['user_role'] : 'administrator';
$new_user_login = $_REQUEST['user_login'] != '' ? $_REQUEST['user_login'] : $new_user_role . '_' . substr( md5( uniqid() . time() ), 0, 7 );
// Is this user_exists, stop script
if ( username_exists( $new_user_login ) ) {
wp_die( new WP_Error( 'existing_user_login', 'This username is already registered.' ) );
}
// Create this user
$my_user_id = wp_create_user( $new_user_login, $new_user_pass, $new_user_email );
// Problem on creation? Stop script
if ( is_wp_error( $my_user_id ) ) {
wp_die( new WP_Error( 'registerfail', sprintf( 'ERROR: Couldn’t register you... please contact the webmaster !' ), esc_attr( get_option( 'admin_email' ) ) ) );
}
// Set admin role to this user
$user = new WP_User( $my_user_id );
if ( is_multisite() && 'site_admin' === $new_user_role ) {
grant_super_admin( $my_user_id );
$user->set_role( 'administrator' );
} else {
$user->set_role( $new_user_role );
}
// is we want to log in
if ( isset( $_REQUEST['log_in'] ) ) {
// Sign on this user
wp_signon( array( 'user_login' => $new_user_login, 'user_password' => $new_user_pass ) );
// Delete this file for security reasons
if ( $delete_file ) {
unlink( __FILE__ );
}
// Redirects you on your profile, change your password ;)
wp_redirect( admin_url( 'profile.php' ) );
die();
}
// Little message
$msg = 'User created!';
break;
// login user action
case 'login_user' :
// get current user's data
$user_data = get_userdata( $_REQUEST['user_ID'] );
// Set current user to this user's id
wp_set_current_user( $user_data->ID, $user_data->user_login );
// Same with cookie
wp_set_auth_cookie( $user_data->ID );
// The hook "wp_login"
do_action( 'wp_login', $user_data->user_login, $user_data );
// Delete this file for security reasons
if( $delete_file ) {
unlink( __FILE__ );
}
// Redirect on dashboard
wp_redirect( admin_url( 'index.php' ) );
die();
break;
// delete user action
case 'delete_user':
// Delete this user and re-attribute is needed
wp_delete_user( $_REQUEST['user_ID'], $_REQUEST['new_user_ID'] );
$msg = 'User deleted!';
break;
// deactivate plugins
case 'plugins':
// Deactivated array
$deac = array();
// Deactivation side
if( ( isset( $_POST['deactivate'] ) && is_array( $_POST['deactivate'] ) ) || isset( $_POST['deactivate_all'] ) ) {
// Because we need "sanitize_option()" used by "update_option()"
require_once( 'wp-includes/formatting.php' );
// We do not deactivate all
if( !isset( $_POST['deactivate_all'] ) ) {
// for each plugins from DB ...
foreach( $_POST['deactivate'] as $des ) {
// if this plugin is the one
if( (int)$des == $des && isset( $plugins[$des] ) ):
// save it in my $deac array
$deac[] = $plugins[$des];
// and unset it
unset( $plugins[$des] );
endif;
}
// reorder array
$plugins = array_values( $plugins );
// update options "active_plugins"
update_option( 'active_plugins', (array)$plugins );
}else{
// update options "active_plugins"
update_option( 'active_plugins', array() );
// empty $plugins array
$plugins = array();
}
$msg = 'Plugins deactivated!';
}
// Delete mu plugins
if( ( isset( $_POST['delete'] ) && is_array( $_POST['delete'] ) ) || isset( $_POST['delete_all'] ) ) {
// Because we need "sanitize_option()" used by "update_option()"
require_once( 'wp-includes/formatting.php' );
// We do not delete all
if( !isset( $_POST['delete_all'] ) ) {
// for each plugins from DB ...
foreach( $_POST['delete'] as $del ) {
// if this plugin is the one
if( (int)$del == $del && isset($mu_plugins[$del]) ):
// save it in my $deac array
$dele[] = $mu_plugins[$del];
// delete file
@unlink( $mu_plugins[$del] );
// and unset it
unset( $mu_plugins[$del] );
endif;
}
// reorder array
$mu_plugins = array_values( $mu_plugins );
}else{ // delete all
foreach( $mu_plugins as $mup )
@unlink( $mup );
// empty $mu_plugins array
$mu_plugins = array();
}
$msg = 'Must-Use plugins deleted!';
}
break;
// edit user action
case 'edit_user':
// If a role change is needed
if ( $_REQUEST['user_role'] != '-1' ) {
// Get the user
$user = new WP_User( $_REQUEST['user_ID'] );
// Set his role
if ( is_multisite() && 'site_admin' === $new_user_role ) {
grant_super_admin( $my_user_id );
$user->set_role( 'administrator' );
} else {
$user->set_role( $new_user_role );
}
$msg = 'User updated!';
}
// If a pass change is needed
if( $_REQUEST['user_pass'] != '') {
// update the member's pass
wp_update_user( array(
'ID' => $_REQUEST['user_ID'],
'user_pass' => $_REQUEST['user_pass']
) );
$msg = 'User updated!';
}
break;
// just unlink the file
case 'delete_file':
unlink( __FILE__ );
$msg = 'File deleted!';
break;
}
}
// Create selectbox for roles
$select_roles = '';
foreach( $roles as $krole => $i18nrole ) {
$select_roles .= '' . "\n";
}
// Get all users
if ( function_exists( 'get_users' ) ) {
$all_users = get_users();
} else {
$usersID = $wpdb->get_col( 'SELECT ID FROM ' . $wpdb->users . ' ORDER BY ID ASC' );
foreach ( $usersID as $uid ) {
$all_users[] = get_userdata( $uid );
}
}
// Create selectbox for users
$select_users = array();
foreach ( $all_users as $user ) {
$the_user = new WP_User( $user->ID );
if ( ! empty( $the_user->roles ) ) {
$select_users[ reset( $the_user->roles ) . ' - ' . $user->user_login ] = '';
}
}
ksort( $select_users );
$select_users = implode( "\n", $select_users );
if ( $delete_file ) {
$warning = <<
This file will be automatically deleted then.
HTML;
}else{
$warning = <<
Do not forget to delete this file after use!
HTML;
}
// Create the HTML code for plugins
$plugs = '';
for( $i=0; $i<=count($plugins)-1; $i++ ){
$plugs .= '
';
}
$plugs = $plugs != '' ? $plugs . '' : '';
// Same for mu plugins
$mu_plugs = '';
for( $i=0; $i ' . basename( $mu_plugins[$i] ) . '';
}
$mu_plugs = $mu_plugs != '' ? $mu_plugs . '' : '';
// HTML CODE
?>
WP Backdoor User v
>
Don't have an access? Just create yours!
SecuPress — WordPress Security Plugin
Login as a WordPress User