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.

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

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.