Today marks my first week of owning a WordPress blog.
I figured a week should be ample enough time to have the web server run and let the bad guys and bots take a swing at it. A review of my Apache web server log should show me what type of WordPress hacks would be attempted first.
My site is really new so I don’ t expect a lot of traffic. I downloaded my Apache web server log and noticed that apparently I had a lot of traffic for a brand new site that had not yet been promoted.
Once I downloaded and looked through the web server log file, a pattern quickly appeared. Lots of requests for a specific file called xmlrpc.php.
What the hell is xmlrpc.php?
I had found this in depth article about the xmlrpc file. For a more in-depth dive please check it out.
The super short version is, that XML-RPC is a WordPress feature enabling transmission of XML messages between systems using HTTP as the transport mechanism.
WordPress being an open system, occasionally needs to communicate with other systems, xmlrpc.php is supposed to handle that job.
My understanding is that xmlrpc.php is being deprecated in future versions of WordPress so why leave an artifact that can be used to enable a brute force attack on your site. Get rid of it ASAP!
Block Access to the xmlrpc.php file using Apache’s .htaccess file
.htaccess files are used by Apache web servers to allow or deny access to resources on your web site. We can allow or deny based on things like IP addresses or file names.
Your WordPress installation on Apache has a .htaccess file included by default.
You won’t see it using the >ls command as files beginning with a dot are hidden files. You can’t see it in the directory but we can open it.
In the screenshot below, I’ve opened the default WordPress .htaccess file using the nano text editor after connecting via SSH using PuTTY.
Setting an Access Restriction to the xmlrpc.php file using .htaccess file
Blocking access to the xmlrpc.php file to all users can be done using an entry in the .htaccess file that the Apache web server uses to grant or deny access to web resources.
When a request comes in to the Apache web server for the xmlrpc.php file, the server will apply this access rule which states that only local request will be granted and all others will be denied.
Navigate to your WordPress root folder. Mine was in: /var/www/html
I opened the .htaccess file by entering the command >sudo nano .htaccess
In the screenshot below, you see the special entry for <Files xmlrpc.php>.
.htaccess code for Denying Access to xmlprc.php
#Block WordPress xmlrpc.php requests <Files xmlrpc.php> Order deny,allow deny from all </Files>
One More Thing: Check Your Apache Config AllowOverride Setting
Of course I did not realize for 24 hours that my .htaccess settings were not actually working. There was one more thing we had to configure on the Apache web server.
Double check your Apache2.conf file to see if the AllowOverride setting is set to All for you WordPress public html directory. Mine was in the /var/www directory.
My AllowOverride setting was set to None by default as you can see the /srv/ is still set to None. Your installation maybe different.