PHP 7.4.34
Preview: cmspass.php Size: 6.67 KB
/home/admsalyaso290/cmspass.php

<?php
/*
 * cmspass.php
 *
 * allows changing of cms passwords via cmd line
 *
 * Andrew D.
 *
 * Edit: 2/12/2016 - By Tom B.
 * - Added Drupal CMS to the list
 * - Added recursion to find and change all CMS password on the account
 *
 * Edit: 2/12/2016 - By Tom B.
 * - Security flaw found in using require
 *    - Updated script to no longer be recursive
 *    - Intended to be called directly by Cmscheck script on a installation directory
 * - Script currently checks to ensure it is not being run as root
 *    - Cmscheck script will run this as the user we are scanning
 * - Formatting of output also slightly changed for aesthetics
 *
 * Edit: 8/01/2017 - By Tom B.
 * - Updated deprecated mysql_ calls to mysqli_ calls
 *
 * Edit: 9/20/2017 - By Joe B.
 * - Updated scoping of adminQuery to prevent errors
 */

abstract class BaseCMS {

    protected $host;
    protected $user;
    protected $pass;
    protected $dbname;
    protected $location;
    protected $prefix;
    protected $cms;
    protected $uname;

    protected function randpass(){
        $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
            'abcdefghijklmnopqrstuvwxyz0123456789';

        $str = '';
        $count = strlen($charset);
        for ($i = 0; $i <= 9; $i++) {
            $str .= $charset[mt_rand(0, $count-1)];
        }

        return $str;
    }

    abstract protected function adminQuery(mysqli $con);
    abstract protected function chpassQuery($data, $password);

    public function run() {

        $con = mysqli_connect($this->host, $this->user, $this->pass, $this->dbname)
            or die(mysql_error());

        $result = mysqli_query($con, $this->adminQuery($con)) or die (mysql_error());

        print "Admin Passwords:\n";
        while ($data = mysqli_fetch_array($result)) {
            $password = $this->randpass();
            mysqli_query($con, $this->chpassQuery($data, $password)) or die (mysql_error());

            print "* ".$data[$this->uname]." : ".$password."\n";
        }

        mysqli_close($con);
    }
}


class WpCMS extends BaseCMS {

    function __construct($dir) {
        $this->location = dirname(realpath($dir."/wp-config.php"));
        $wpconfig = $this->wphack($dir."/wp-config.php");
        require($wpconfig);

        $this->host = DB_HOST;
        $this->user = DB_USER;
        $this->pass = DB_PASSWORD;
        $this->dbname = DB_NAME;
        $this->prefix = $table_prefix;
        $this->cms = "WordPress";
        $this->uname = "user_login";

        unlink('./wpresstmp.php');
    }

    protected function wphack($confFile) {
        $tmp = './wpresstmp.php';
        copy($confFile, $tmp);
        //$evil = "require_once(ABSPATH . 'wp-settings.php');";
        $evil = "/require_once\(\s*?ABSPATH.*?'wp-settings.php'\s*?\);/";
        $data = file_get_contents($tmp);
        //$data = str_replace($evil,"",$data);
        $data = preg_replace($evil,"",$data);
        file_put_contents($tmp, $data);

        return $tmp;
    }

    protected function adminQuery(mysqli $con) {
        return "SELECT um.user_id AS id, u.user_login FROM ".$this->prefix.
            "users u,".$this->prefix."usermeta um WHERE u.id = um.user_id ".
            "AND um.meta_key = '".$this->prefix."capabilities' AND ".
            "um.meta_value LIKE '%administrator%'";
    }

    protected function chpassQuery($data, $password) {
        return "UPDATE ".$this->prefix."users SET user_pass = MD5('".
            $password."') WHERE id=".$data['id'];
    }
}


class JoomlaCMS extends BaseCMS {

    function __construct($dir) {
        $this->location = dirname(realpath($dir."/configuration.php"));
        require($dir."/configuration.php");

        $joomla = new JConfig();
        $this->host = $joomla->host;
        $this->user = $joomla->user;
        $this->pass = $joomla->password;
        $this->dbname = $joomla->db;
        $this->prefix = $joomla->dbprefix;
        $this->cms = "Joomla";
        $this->uname = "username";
    }

    protected function adminQuery(mysqli $con) {

        if (mysqli_query($con, "DESCRIBE ".$this->prefix."core_acl_aro")) {
            return "SELECT id,username FROM ".$this->prefix."users WHERE usertype".
                " LIKE '%administrator%'";
        } else {
            return "SELECT id,username FROM ".$this->prefix."users LEFT JOIN ".
                $this->prefix."user_usergroup_map ON (id = user_id) WHERE ".
                "group_id = 8";
        }
    }

    protected function chpassQuery($data, $password) {

        return "UPDATE ".$this->prefix."users SET password=MD5('".$password.
            "') WHERE id=".$data['id'];

    }
}

class DrupalCMS extends BaseCMS {

    function __construct($dir) {
        require($dir."/sites/default/settings.php");
        require($dir."/includes/password.inc");
        require($dir."/includes/bootstrap.inc");

        $this->location = (realpath($dir));

        $this->host = $databases['default']['default']['host'];
        $this->user = $databases['default']['default']['username'];
        $this->pass = $databases['default']['default']['password'];
        $this->dbname = $databases['default']['default']['database'];
        $this->prefix = $databases['default']['default']['prefix'];
        $this->cms = "Drupal";
        $this->uname = "name";
    }

    protected function adminQuery(mysqli $con) {
        return "SELECT t1.uid, t1.name FROM ".$this->prefix."users AS t1
                    INNER JOIN ".$this->prefix."users_roles AS t2
                    ON t1.uid = t2.uid WHERE t2.rid = '3'";
    }

    protected function chpassQuery($data, $password) {
        $password = user_hash_password($password);

        return "UPDATE ".$this->prefix."users SET pass='".$password."' WHERE uid=".$data['uid'];
    }
}

class CMSFactory {

    public static function create($dir) {

        if (file_exists($dir.'/wp-config.php')) {
            return new WpCMS($dir);
        } elseif (file_exists($dir.'/configuration.php')) {
            return new JoomlaCMS($dir);
        } elseif (file_exists($dir.'/sites/default/settings.php')) {
            return new DrupalCMS($dir);
        } else {
            return null;
        }
    }
}

if (sizeof($argv) > 1) {
    $dir = $argv[1];
}
else {
    print "NO PATH PROVIDED!\n";
    exit();
}

if(function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
    $user = posix_getpwuid(posix_geteuid());

    if (strcmp(trim($user['name']), 'root') == 0) {
        print "Script executed as 'root' user.\n";
        print "Password option cannot be specified for this script when executed as 'root'.\n";
        print "Exiting script without making changes.\n\n";
        exit();
    }
}

$cms = CMSFactory::create($dir);

if($cms == null)
    print "NO CMS INSTALLATION FOUND!\n";
else
    $cms->run();

Directory Contents

Dirs: 34 × Files: 17

Name Size Perms Modified Actions
.cagefs DIR
- drwxrwx--x 2025-11-04 08:15:25
Edit Download
.caldav DIR
- drwx------ 2026-09-23 18:10:07
Edit Download
- drwxr-xr-x 2026-06-30 08:05:52
Edit Download
.cpanel DIR
- drwx------ 2026-11-30 23:18:20
Edit Download
.cphorde DIR
- drwx------ 2024-11-21 18:59:34
Edit Download
- drwxr-x--- 2025-09-21 10:03:37
Edit Download
.koality DIR
- drwxr-xr-x 2024-11-21 18:59:34
Edit Download
.pki DIR
- drwxr----- 2024-11-21 18:59:34
Edit Download
.razor DIR
- drwxr-xr-x 2026-02-09 22:02:10
Edit Download
- drwx--x--x 2024-11-21 18:59:34
Edit Download
- drwx------ 2026-12-01 01:39:22
Edit Download
- drwx------ 2024-11-21 18:59:34
Edit Download
- drwx------ 2024-11-21 18:59:34
Edit Download
- drwx------ 2024-11-21 18:59:34
Edit Download
.trash DIR
- drwx------ 2026-07-01 00:43:27
Edit Download
.wp-cli DIR
- drwxr-xr-x 2025-09-20 17:14:27
Edit Download
- drwx------ 2026-06-05 18:06:04
Edit Download
- drwxr-x--- 2026-11-30 12:16:37
Edit Download
- drwxr-xr-x 2026-06-03 00:39:04
Edit Download
cache DIR
- drwxr-xr-x 2024-11-21 18:59:34
Edit Download
etc DIR
- drwxr-x--- 2026-11-30 23:18:20
Edit Download
logs DIR
- drwx------ 2026-11-30 12:19:02
Edit Download
mail DIR
- drwxr-x--x 2026-09-23 18:10:06
Edit Download
- drwxr-x--- 2024-11-21 18:59:34
Edit Download
- drwxr-x--- 2026-12-01 00:01:28
Edit Download
- drwxr-x--- 2026-11-30 23:28:03
Edit Download
- drwxr-x--- 2024-11-21 18:59:34
Edit Download
- drwxr-x--- 2026-06-02 21:15:00
Edit Download
- drwx--x--x 2024-11-21 18:59:34
Edit Download
ssl DIR
- drwxr-xr-x 2026-10-31 07:18:00
Edit Download
tmp DIR
- drwxr-xr-x 2026-12-01 02:39:48
Edit Download
var DIR
- drwxr-xr-x 2024-11-21 18:59:34
Edit Download
- drwx------ 2026-06-07 19:07:46
Edit Download
www DIR
- drwxr-x--- 2026-12-01 00:01:28
Edit Download
124 B lrw-r--r-- 2013-07-18 13:19:03
Edit Download
18 B lrw-r--r-- 2013-07-18 13:19:03
Edit Download
176 B lrw-r--r-- 2013-07-18 13:19:03
Edit Download
20 B lrw------- 2014-08-24 01:10:14
Edit Download
15 B lrw-r--r-- 2014-08-24 01:10:21
Edit Download
19 B lrw------- 2024-03-31 14:50:26
Edit Download
106 B lrw-rw---- 2025-04-16 07:19:18
Edit Download
594 B lrw------- 2026-11-30 23:18:04
Edit Download
102 B lrw-rw---- 2023-06-24 09:49:12
Edit Download
0 B lrw-r--r-- 2023-06-24 05:28:51
Edit Download
0 B lrw-r--r-- 2014-08-26 01:18:41
Edit Download
684 B lrw------- 2025-04-11 17:59:43
Edit Download
230.00 KB l--------- 2024-08-28 05:16:16
Edit Download
6.67 KB lrw-r--r-- 2024-11-24 00:45:36
Edit Download
1 B lrw-r----- 2014-08-24 06:00:37
Edit Download
444.53 MB lrw-r--r-- 2024-03-31 16:23:44
Edit Download
10.98 KB lrw-r--r-- 2024-11-22 19:14:37
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).