3

As an Information Security amateur I did all in my might to protect my Ubuntu-Nginx-CMS (WordPress) environment from BFAs, MITMs, and database injections.

sudo add-apt-repository ppa:certbot/certbot -y && apt-get update -y && apt-get upgrade -y
sudo apt-get install zip unzip tree unattended-upgrades sshguard postfix \ 
nginx python-certbot-nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
sudo ufw enable && ufw allow 22/tcp 25/tcp 80/tcp 443/tcp 9000/tcp

To prevent MITM attacks, generally all data transmission of all sites is via TLS, via a Let'sEncrypt SSL certificate (Green padlock in browser for all pages).

To prevent CMS DB injections I've enabled frequent updates via *nix cron (and kept forms minimal):

0 1 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp plugin update --all --allow-root; done
0 2 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp core update --allow-root; done
0 3 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp theme update --all --allow-root; done

But it seems I didn't do anything against DDoS. What can I do against someone who sends a robot to load my webpages about 50,000 times per hour (or something of that sort)?

Is there something that can be done directly form Ubuntu/Nginx/WordPress or by some Linux software?

Notes:

  • AFAIK, BFA, DBI and DDoS are the 3 most common types of attacks DoS attacks (to be distinguished from MITM which isn't a DoS attack). Sorry if I missed anything.

  • I ran a search here in Information Security StackExchange with the phrase Nginx Ubuntu DDOS but didn't find a thread session this.

aurelien
  • 253
  • 2
  • 13
Arcticooling
  • 269
  • 2
  • 13
  • 1
    You are essentially asking two questions here: What can you do against (application level) (D)DOS? And did you miss anything important? The first question is covered on this site already, like in [How can a Software application defend against DoS or DDoS?](https://security.stackexchange.com/questions/241/how-can-a-software-application-defend-against-dos-or-ddos). You probably missed it since you've search for Nginx and Ubuntu specific questions only. – Steffen Ullrich Jan 14 '18 at 17:08
  • Apart from that there were several Wordpress plugins in the last time which went malicious. Much harm can be done by such plugins before somebody realizes the problem, i.e. just keeping plugins updated might not be sufficient. See https://www.scmagazine.com/malicious-plugin-installed-backdoor-on-200000-wordpress-websites/article/688878/, https://blog.sucuri.net/2016/03/when-wordpress-plugin-goes-bad.html, https://blog.sucuri.net/2014/03/unmasking-free-premium-wordpress-plugins.html. – Steffen Ullrich Jan 14 '18 at 17:14
  • 1
    I agree that there are many WordPress plugins that can cause more harm than good, this is exactly the reason I aim to protect myself from DDoS from lower layers, like Ubuntu/Nginx. – Arcticooling Jan 14 '18 at 17:24
  • Malicious Wordpress plugins are not really a problem of DDoS. Instead they might open a backdoor into your server - which means that the attacker is no longer outside your server but inside it. See https://www.wordfence.com/blog/2017/12/backdoor-captcha-plugin/ – Steffen Ullrich Jan 14 '18 at 18:21
  • Indeed, I said that in a general way. Is there anything to do in the Ubuntu/Nginx layers? My VPSE is quite small (5 bucks machine at DigitalOcean). I am quite afraid from that. – Arcticooling Jan 14 '18 at 18:24
  • 2
    The easiest and cheapest way against DDOS is to put your server behind some CDN like Cloudflare and maybe add rate limiting - https://www.cloudflare.com/rate-limiting/ – Steffen Ullrich Jan 14 '18 at 20:34
  • Oh gosh, I hate CDNs... :\ I might need to note these are very small scale WordPress sites (up to about 5 plugins, up to about 20 webpages, and 20 images total per site), if it matters in that context. – Arcticooling Jan 14 '18 at 20:35
  • Do you have any reason to believe that you will be target of a DDoS attack? If not and regarding the extent of your operation I wouldn't say that this is a risk that you should worry too much about. – Tom K. Jan 16 '18 at 21:03
  • I can someday, for whatever reason become a rival with a maniac that happens to be with enough technical knowledge and understanding of Linux systems and Information Security and would try to attack my sites. Also my sites were targeted by Islamist jihadists a few times... Sadly... – Arcticooling Jan 16 '18 at 21:27

1 Answers1

3

I think your conclusion that brute force, SQL injection, and DDoS are the most common types of attacks doesn't include some of the other significant attacks. XSS and CSRF are also notable, (see the OWASP top 10) and without doing detailed research into each type, it would be hard to know which is most prevalent.

General system hardening makes sense first:

  1. Only allow public-key based SSH into the system.
  2. Limit the inbound connections (as you've done with firewall rules)
  3. Ensure each service runs as an isolated user.
  4. Limit Unix permissions to the minimum necessary (0700 on directories, 0600 on files).
  5. Where possible, remove write permissions to folders (limits possibilities for uploading malicious code)

Note that, since you're using nginx instead of Apache, some of the directives from the .htaccess file supplied by Wordpress should be enacted as equivalent nginx directives: e.g., preventing PHP execution anywhere user files are uploaded, limiting access to sensitive files.

For Wordpress specifically, I would review the Wordpress Hardening Guide. Some specifics come to mind:

  1. Use as few plugins as possible, and (if possible) review them for vulnerabilities.
  2. Ensure that custom theming does not introduce XSS vulnerabilities.
  3. If it's very important, consider a 2FA plugin for Wordpress to minimize the risk from brute force or password reuse.

If you're concerned about application-level DoS attacks, you can rate limit in Nginx.

Without more infrastructure (Cloudflare, Loud Balancers, etc.), you'll be unable to mitigate pure volumetric DDoS -- it's just a fact of the internet that if your attacker has more bandwidth than you do, you will lose. These include attacks like reflected DNS/NTP DDoS, IoT botnets, etc. Basically, any attack that allows the attacker to send more traffic than the internet connection of your host (all the way to the virtual interface on your VPS) can handle. While Digital Ocean and other hosts have considerable bandwidth, your single VPS will quickly be saturated around (or before) 1 Gbps.

David
  • 15,814
  • 3
  • 48
  • 73