Question

My Sites Have Been Hacked - Whats the Best Security Prevention

Hi Guys

I have several wordpress sites hosted on an Ubuntu server driven by Nginx. Ive had to clean out many bogus php files and clean up my sites following an obvious hack

I have fail2ban installed and ssl Hardening, I have disabled root login and password access so only access should be via ssh.

I’m guessing this is a Cross Site Scripting attack so I’m wondering what else I can do to prevent a repeat of this in the future?

Any advice would be greatly appreciated

Thanks in advance

Matt


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
March 8, 2020
Accepted Answer

Hello, @thinknew

I will recommend you to check the folder’s structure and make sure that the permissions are not set too high. This should prevent people from accessing certain directories and also prevent them from uploading files.

Another thing is to disable shell_exec . The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. When it’s usually enabled people can use it to execute malicious scripts. In order to disable it open the PHP.ini file and add the shell_exec to the disable_functions row/line:

disable_functions=shell_exec

You’ve mentioned that the sites are based on WordPress so there are several things you need to do:

  1. Always make sure that your WordPress installations are up to date. When there is a new update you can take a backup (in case something goes wrong) for the site and then update the WordPress version.

  2. Keep you plugins updated. When there is a new version of a plugin that you use, update it. You can again first take backup for the site in question.

  3. Remove any plugin which is not active. If you have any plugins which are currently inactive and you’re not using it will be better to have this removed.

  4. Install a security plugin like Wordfence, iThemes Security or Sucuri Security to keep everything protected.

  5. Occasionally checking through the site files for the sites, making sure nothing is out of place

You can also check the status of your sites site checking them through hack scanners such as http://sitecheck.sucuri.net/ http://isithacked.com/ http://www.unmaskparasites.com/

Hope this helps!

Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.