Kurs Wordpress: Ochrona przed Spamem i hakerami
Kurs WordPress: Ochrona przed Spamem i hakerami
9 maja 2015

PROCEDURA: SN Checklist for WPExperts

Źródło Procedury i wskazówek: Wtyczka Security Ninja

TEST DETAILED EXPLANATION & HELP
Check if WordPress core is up to date. Keeping the WordPress core up to date is one of the most important aspects of keeping your site secure. If vulnerabilities are discovered in WordPress and a new version is released to address the issue, the information required to exploit the vulnerability is almost certainly in the public domain. This makes old versions more open to attacks, and is one of the primary reasons you should always keep WordPress up to date.

Thanks to automatic updates updating is very easy. Just go to Dashboard – Updates and click “Upgrade”. Remember – always backup your files and database before upgrading!

Check if automatic core updates are enabled. Unless you’re running a highly customized WordPress site wich requires rigorous testing of all updates we recommend having automatic minor core updates enabled. These are usually security fixes that don’t alter WP in any significant way and should be applied as soon as WP releases them.

Updates can be disabled via constants in wp-config.php or by a plugin. For details please see WP Codex.

Check if plugins are up to date. As with the WordPress core, keeping plugins up to date is one of the most important and easier way to keep your site secure. Since most plugins are free and therefore their code is available to anyone having the latest version will ensure you’re not prone to attacks based on known vulnerabilities.

If you downloaded a plugin from the official WP repository you can easily check if there are any upgrades available, and upgrade it by opening Dashboard – Updates. If you bought the plugin from CodeCanyon be sure to check the item’s page and upgrade manually. Remember – always backup your files and database before upgrading!

Check if there are any deactivated plugins. If you’re not using a plugin remove it from the WP plugins folder. It’s that simple. There’s no reason to keep it there and in case the code is malicious or it has some vulnerabilities it can still be exploited by a hacker regardless of the fact the plugin is not active.

Open plugins and simply delete all plugins that are not active. Or login via FTP and move them to some folder that’s not /wp-content/plugins/.

Check if themes are up to date. As with the WordPress core, keeping the themes up to date is one of the most important and easier way to keep your site secure. Since most themes are free and therefore their code is available to anyone having the latest version will ensure you’re not prone to attacks based on known vulnerabilities. Also, having the latest version will ensure your theme is compatible with the latest version of WP.

If you downloaded a theme from the official WP repository you can easily check if there are any upgrades available, and upgrade it by opening Appearance – Themes. If you bought the theme from ThemeForest be sure to check the theme’s page and upgrade manually. Remember – always backup your files and database before upgrading!

Check if there are any deactivated themes. If you’re not using a theme remove it from the WP themes folder. It’s that simple. There’s no reason to keep it there and in case the code is malicious or it has some vulnerabilities it can still be exploited by a hacker regardless of the fact the theme is not active.

Open Appearance – Themes and simply delete all themes that are not active. Or login via FTP and move them to some folder that’s not /wp-content/themes/.

Check if full WP version info is revealed in page’s meta data. You should be proud that your site is powered by WordPress and there’s no need to hide that information. However disclosing the full WP version info in the default location (page header meta) is not wise. People with bad intentions can easily use Google to find site’s that use a specific version of WordPress and target them with 0-day exploits.

Place the following code in your theme’s functions.php file in order to remove the header meta version info:

function remove_version() {
  return '';
}
add_filter('the_generator', 'remove_version');
Check if WordPress readme.htmlfile is accessible via HTTP on the default location. As mentioned in the previous test – you should be proud that your site is powered by WordPress but also hide the exact version you’re using.readme.html contains WP version info and if left on the default location (WP root) attackers can easily find out your WP version.

This is a very easy problem to solve. Rename the file to something more unique like “readme-876.html”; delete it; move it to another location or chmod it so that it’s not accessible via HTTP.

Check if server response headers contain detailed PHP version info. As with the WordPress version it’s not wise to disclose the exact PHP version you’re using because it makes the job of attacking your site much easier. This issue is not directly WP related but it definitely affects your site.

You’ll most probably have to ask your hosting company to configure the HTTP server not to show PHP version info but you can also try adding these directives to the .htacces file:

<IfModule mod_headers.c>
  Header unset X-Powered-By
  Header unset Server
</IfModule>
Check if user with username “admin” exists. If someone tries to guess your username and password or tries a brute-force attack they’ll most probably start with username “admin”. This is the default username used by too many sites and should be removed.

Create a new user and assign him the “administrator” role. Try not to use usernames like: “root”, “god”, “null” or similar ones. Once you have the new user created delete the “admin” one and assign all post/pages he may have created to the new user.

Check for display of unnecessary information on failed login attempts. By default on failed login attempts WordPress will tell you whether username or password is wrong. An attacker can use that to find out which usernames are active on your system and then use brute-force methods to hack the password.

Solution to this problem is simple. Whether user enters wrong username or wrong password we always tell him “wrong username or password” so that he doesn’t know which of two is wrong. Open your theme’s functions.php file and copy/paste the following code:

function wrong_login() {
  return 'Wrong username or password.';
}
add_filter('login_errors', 'wrong_login');
Check if all security keys and salts have proper values. Security keys are used to ensure better encryption of information stored in the user’s cookies and hashed passwords. You don’t have to remember these keys. In fact once you set them you’ll never see them again. Therefore there’s no excuse for not setting them properly.

Security keys (there are eight) are defined in wp-config.php as constants on lines #45-52. They should be as unique and as long as possible. WordPress made a great script which helps you generate those strings. Please use it! After the script generates strings those 8 lines of code should look something like this:

define('AUTH_KEY',         [email protected]<0VFKb*pdhM8c<bb:qB%Fr8:- dc}U(,[K?hobrzsn*:r?,e^/eHsm6nHls');
define('SECURE_AUTH_KEY',  'M2wEPuf7.%FWW1xvy]ar&vy3gj,:1Go>qs7d_N)nX}O[-(+AaDsiPbvAOdLG~dt}');
define('LOGGED_IN_KEY',    'iA#+3)Xhf0E*oyN1A4#:0wVp|d<F-rQQ Sf_HNMk,rVj,F,GdKF|b-:xBEM,y(,f');
define('NONCE_KEY',        'ctGmyOSSfm1-WR/V:J6[;Zh|?a$slsWs_9BIKcM[}uh~+C|R}ylW4cU%D tIOG=d');
define('AUTH_SALT',        [email protected] .T&-{wMmP>ggj4p{,HKs!>vsUXz/aPDlZ=1.D54m+#1xyt+%w)3r&j]r?:');
define('SECURE_AUTH_SALT', '`^mxb~AvK*Agn+h>U!0GL2*2|R+HHyY%h1b%Aoo,Jy|M{}TP`mSTt<fcm=O9`=bA');
define('LOGGED_IN_SALT',   'Ow||n$:: HWM5%H7k+MW7{!Z[Z|G-UJZ6Pp8;Id^<lK-&W+}Q?wHw!xlp2g(1% w');
define('NONCE_SALT',       'IoLWhDF-d<>`u}R4oEe5kXf+)<.}Ib?BPE<[email protected]');
Test the strength of WordPress database password. There is no such thing as an “unimportant password”! The same goes for WordPress database password. Although most servers are configured so that the database can’t be accessed from other hosts that doesn’t mean your database passsword should be “12345”. Choose a proper password, at least 8 characters long with a combination of letters, numbers and special characters.

To change the database password open cPanel, Plesk or some other hosting control panel you have. Find the option to change the database password and be sure you make the new password strong enough. If you can’t find that option or you’re uncomfortable changing it contact your hosting provider. After the password is changed open wp-config.php and change the password on line #25:

/** MySQL database password */
define('DB_PASSWORD', 'YOUR_NEW_DB_PASSWORD_GOES_HERE');
Check if database table prefix is the default one (wp_). Knowing the names of your database tables can help an attacker dump the table’s data and get to sensitive information like password hashes. Since WP table names are predefined the only way you can change table names is by using a unique prefix. One that’s different from “wp_” or any similar variation such as “wordpress_”.

If you’re doing a fresh installation defining a unique table prefix is easy. Open wp-config.php and go to line #61 where the table prefix is defined. Enter something unique like “frog99_” and install WP.

If you already have WP site running and want to change the table prefix things are a bit more complicated and you should only do the change if you’re comfortable doing some changes to your DB data via phpMyAdmin or a similar GUI. Detailed 6-step instruction can be found on Tdot blog.Remember – always backup your files and database before making any changes to the database!

Check if site debug mode is enabled. Having any kind of debug mode (general WP debug mode in this case) or error reporting mode enabled on a production server is extremely bad. Not only will it slow down your site, confuse your visitors with weird messages it will also give the potential attacker valuable information about your system.

General WordPress debugging mode is enabled/disabled by a constant defined in wp-config.php. Open that file and look for a line similar to:

define('WP_DEBUG', true);

Comment it out, delete it or replace with the following to disable debugging:

define('WP_DEBUG', false);

If your blog still fails on this test after you made the changes it means some plugin is enabling debug mode. Disable plugins one by one to find out which one is doing it.

Check if database debug mode is enabled. Having any kind of debug mode (WP DB debug mode in this case) or error reporting mode enabled on a production server is extremely bad. Not only will it slow down your site, confuse your visitors with weird messages it will also give the potential attacker valuable information about your system.

WordPress DB debugging mode is enabled with the following command:

$wpdb->show_errors();

In most cases this debugging mode is enabled by plugins so the only way to solve the problem is to disable plugins one by one and find out which one enabled debugging.

Check if JavaScript debug mode is enabled Having any kind of debug mode (WP JavaScript debug mode in this case) or error reporting mode enabled on a production server is extremely bad. Not only will it slow down your site, confuse your visitors with weird messages it will also give the potential attacker valuable information about your system.

WordPress JavaScript debugging mode is enabled/disabled by a constant defined in wp-config.php open your config file and look for a line similar to:

define('SCRIPT_DEBUG', true);

Comment it out, delete it or replace with the following to disable debugging:

define('SCRIPT_DEBUG', false);

If your blog still fails on this test after you made the change it means some plugin is enabling debug mode. Disable plugins one by one to find out which one is doing it.

Check if display_errors PHP directive is turned off. Displaying any kind of debug info or similar information is extremely bad. If any PHP errors happen on your site they should be logged in a safe place and not displayed to visitors or potential attackers.

Open wp-config.php and place the following code just above the require_once function at the end of the file:

ini_set('display_errors', 0);

If that doesn’t work add the following line to your .htaccess file:

php_flag display_errors Off
Check if WordPress installation address is the same as the site address. Moving WP core files to any non-standard folder will make your site less vulnerable to automated attacks. Most scripts that script kiddies use rely on default file paths. If your blog is setup on www.site.com you can put WP files in ie: /var/www/vhosts/site.com/www/wp-core/ instead of the obvious/var/www/vhosts/site.com/www/.

Site and WP address can easily be changed in Options – General. Before doing so please watch this detailed video tutorial which describes what other steps are necessary to move your WP core files to another location.

Check if wp-config.php file has the right permissions (chmod) set. wp-config.php file contains sensitive information (database username and password) in plain text and should not be accessible to anyone except you and WP (or the web server to be more precise).

What’s the best chmod for your wp-config.php depends on the way your server is configured but there are some general guidelines you can follow. If you’re hosting on a Windows based server ignore all of the following.

  • try setting chmod to 0400 or 0440 and if the site works normally that’s the best one to use
  • “other” users should have no privileges on the file so set the last octal digit to zero
  • “group” users shouldn’t have any access right as well unless Apache falls under that category, so set group rights to 0 or 4
Check if install.php file is accessible via HTTP on the default location There have already been a couple of security issues regarding the install.php file. Once you install WP this file becomes useless and there’s no reason to keep it in the default location and accessible via HTTP.

This is a very easy problem to solve. Rename install.php (you’ll find it in the wp-admin folder) to something more unique like “install-876.php”; delete it; move it to another location or chmod it so it’s not accessible via HTTP.

Check if upgrade.php file is accessible via HTTP on the default location There have already been a couple of security issues regarding this file. Besides the security issue it’s never a good idea to let people run any database upgrade scripts without your knowledge. This is a useful file but it should not be accessible on the default location.

This is a very easy problem to solve. Rename upgrade.php (you’ll find it in the wp-admin folder) to something more unique like “upgrade-876.php”; move it to another location or chmod it so it’s not accessible via HTTP. Don’t delete it! You may need it later on.

Check users password strength with a brute-force attack. By using a dictionary of 600 most commonly used passwords Security Ninja does a brute-force attach on your site’s user accounts. Any accounts that fail this test pose a serious security issue for the site because they are using passwords like “12345”, “qwerty” or “god” which anyone can guess within minutes. Alert those users or change their passwords immediately.

Please note that Security Ninja (by default) tests only the first 25 users (starting from administrators). This limit is imposed to be sure we don’t kill the DB while doing the brute-force attack.
If you want to test more or all users open securit-ninja.php and change the line #20 which defines this limit.

// maximum number of user accounts that are brute-force tested for weak passwords
define('WF_SN_MAX_USERS_ATTACK', 25);
Check if “anyone can register” option is enabled. Unless you’re running some kind of community based site this option needs to be disabled. Although it only provides the attacker limited access to your backend it’s enough to start exploiting other security issues.

Go to Options – General and uncheck the “Membership – anyone can register” checkbox.

Check if register_globals PHP directive is turned off. This is one of the biggest security issues you can have on your site! If your hosting company has this this directive enabled by default switch to another company immediately! PHP manual has more info why this is so dangerous.

If you have access to php.ini file locate

register_globals = on

and change it to:

register_globals = off

Alternatively open .htaccess and put this directive into it:

php_flag register_globals off

If you’re still unable to disable register_globals contact a security professional immediately!

Check if safe mode is disabled. PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren’t very realistic, many people, especially ISP’s, use safe mode for now. If your hosting company still uses safe mode it might be a good idea to switch. This feature is deprecated in new version of PHP (5.3).

If you have access to php.ini file locate

safe_mode = on

and change it to:

safe_mode = off
Check if expose_php PHP directive is turned off. It’s not wise to disclose the exact PHP version you’re using because it makes the job of attacking your site much easier.

If you have access to php.ini file locate

expose_php = on

and change it to:

expose_php = off
Check if allow_url_include PHP directive is turned off. Having this PHP directive will leave your site exposed to cross-site attacks (XSS). There’s absolutely no valid reason to enable this directive and using any PHP code that requires it is very risky.

If you have access to php.ini file locate

allow_url_include = on

and change it to:

allow_url_include = off

If you’re still unable to disable allow_url_include contact a security professional immediately!

Check if plugins/themes file editor is enabled. Plugins and themes file editor is a very convenient tool because it enables you to make quick changes without the need to use FTP. Unfortunately it’s also a security issue because it not only shows PHP source but it also enables the attacker to inject malicious code in your site if he manages to gain access to the admin.

Editor can easily be disabled by placing the following code in theme’s functions.php file.

define('DISALLOW_FILE_EDIT', true);
Check if uploads folder is browsable. Allowing anyone to view all files in the uploads folder just by point the brower to it will allow them to easily download all your uploaded files. It’s a security and a copyright issue.

To fix the problem open .htaccess and add this directive into it:

Options -Indexes
Check if user with ID “1” exists. Although technically not a security issue having a user (which is in 99% cases an admin) with the ID 1 can help an attacker in some circumstances.

Fixing is easy; create a new user with the same privileges. Then delete the old one with ID 1 and tell WP to transfer all of his content to the new user.

Check if Windows Live Writer link is present in pages’ header data. If you’re not using Windows Live Writer there’s really no valid reason to have it’s link in the page header thus telling the whole world you’re using WordPress.

Fixing is very easy. Open your theme’s functions.php file and add the following line:

remove_action('wp_head', 'wlwmanifest_link');
Check if wp-config.php is present on the default location. If someone gains FTP access to your server this will not save you but it certainly can’t hurt to obfuscate your installation a bit.

In order to fix this issue you have to move wp-config.php one level up in the folder structure. If the original location was:

/home/www/wp-config.php

move the file to:

/home/wp-config.php

Or for instance from

/home/www/my-blog/wp-config.php

to:

/home/www/wp-config.php
Check if MySQL server is connectable from outside with the WP user. Since MySQL username and password are written in plain-text in wp-config.php it’s advisable not to allow any client to use that account unless he’s connecting to MySQL from your server (localhost). Allowing him to connect from any host will make some attacks easier to bad people.

Fixing this issue involves changing the MySQL user or server config and it’s not something that can be described in a few words so we advise asking someone to fix it for you. If you’re really eager to do it we suggest creating a new MySQL user and under “hostname” enter “localhost”. Set other properties such as username and password to your own liking and, of course, update wp-config.php with the new user details.

Check if EditURI (XML-RPC) link is present in pages’ header data. If you’re not using any Really Simple Discovery services such as pingbacks there’s no need to advertise that endpoint (link) in the header. Please note that for most sites this is not a security issue because they “want to be discovered” but if you want to hide the fact that you’re using WP this is the way to go.

Open your theme’s functions.php file and add the following line:

remove_action('wp_head', 'rsd_link');

Additionally, to completely disable XML-RPC functions put the following code in wp-config.php just below the require_once(ABSPATH . ‘wp-settings.php’); line:

add_filter('xmlrpc_enabled', '__return_false');

And also add this code to .htaccess to prevent DDoS attacks:

<Files xmlrpc.php>
  Order Deny,Allow
  Deny from all
</Files>
Check if Timthumb script is used in the active theme. We don’t recommend using the Timthumb script to manipulate images. Apart from the security issues some versions had, WordPress has its own built-in functions for manipulating images that should be used instead.
Contact the theme developer and have him update the theme. It’s unlikely you’ll be able to fix this issue yourself.
Check if the server is vulnerable to the Shellshock bug #6271. Shellshock, also known as Bashdoor, is a family of security bugs in the widely used Unix Bash shell. Web servers use Bash to process certain commands, allowing an attacker to cause vulnerable versions of Bash to execute arbitrary commands. This can allow an attacker to gain unauthorized access to the system. Although this bug is not related to WordPress directly it’s very problematic. More details.
Contact your server administrator and update the server’s Bash shell immediately.
Check if the server is vulnerable to the Shellshock bug #7169. Shellshock, also known as Bashdoor, is a family of security bugs in the widely used Unix Bash shell. Web servers use Bash to process certain commands, allowing an attacker to cause vulnerable versions of Bash to execute arbitrary commands. This can allow an attacker to gain unauthorized access to the system. Although this bug is not related to WordPress directly it’s very problematic. More details.
Contact your server administrator and update the server’s Bash shell immediately.
TEST DETAILED EXPLANATION & HELP
Jakub Jaworowicz
Jakub Jaworowicz
Marketingiem zajmuję się od 15 roku życia, zacząłem od brzydkich stron w kreatorze stron usługi Republika serwisu Onet - obecnie obsługuje ponad 200 klientów i 450 serwisów WWW rocznie, które tworzyłem lub mam je pod swoją opieką (w zakresie wsparcia i utrzymania). Ostatnio etatowo pracowałem jako Specjalista ds Marketingu w największym ogrodniczym sklepie internetowym (SADOWNICZY.PL) oraz jako kierownik działu wsparcia sprzedaży dla tego sklepu.

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

Mam Cie!

Jeżeli udało mi się Ciebie przekonać do kliknięcia tutaj - to znak, że mamy między sobą nić porozumienia - utrzymajmy ją - zapisz się do newslettera, a otrzymasz tylko dobrą, wartościową wiedzę, która pozwoli ci się rozwijać!

Nigdy nie udostępniam danych osób trzecich, otrzymasz maksymalnie 2 wiadomości w miesiącu.

Dziękuję!

Nić porozumienia została poprawnie nawiązana!