Question

Recently got hacked. How should I prevent it from happening again? (Django / Ubuntu / Postgres / Gunicorn / Nginx)

So our website (clothing e-commerce startup) was recently attacked by an SYN flood initiated by a Chinese IP. It took almost a full day getting everything back up, reloading the database, copying images etc. - Needless to say, not a very pleasant experience and lost a lot of precious time.

Tech stack: Django 1.6.7/ Postgres / Nginx / Gunicorn / Elasticsearch

I want to know what all I can do to prevent something like this from happening again. Have already done the following steps, following the DO tutorials (they are great btw) at https://www.digitalocean.com/community/tutorial_series/new-ubuntu-14-04-server-checklist

  1. Updated all packages and downloaded security updates
  2. Set up SSH keys
  3. Disabled root login
  4. Changed SSH port to a random large number
  5. Setup UFW with disabling all incoming and outgoing connections except for the ports on which services are running (For Nginx, Gunicorn, Elasticsearch, Postgres and Redis)

Anything else I can do to prevent such a hack from happening again? Also do I need to install fail2ban given that root login is disabled and UFW rules are setup?

Show comments

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.

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.

Hi there,

You can install malware detection software like Linux Malware Detect, also known as Maldet or LMD. It will help you to locate any malicious files on your droplet.

If you’re interested in securing your droplet (everyone should be in general) you can double-check our tutorial - An Introduction to Securing your Linux VPS.

The article will cover the basic and some more advanced steps in website and server security.

You can check the article here:

https://www.digitalocean.com/community/tutorials/an-introduction-to-securing-your-linux-vps

Hope that this helps!

Hii, MicroPyramid sponsored Django-mfa is a simple package to add extra layer of security to your django web application. It gives web app a randomly changing password as an extra protection. Follow documentation and raise issues if you want further support, features.

Read more about multifactor authentication: https://micropyramid.com/blog/securing-django-with-multi-factor-authentication-using-django-mfa/ Get the code in our git repository, https://github.com/MicroPyramid/django-mfa For detail documentation visit http://django-mfa.readthedocs.io/en/latest/index.html

I agree with hunky, but there are many tools that may help you out a bit. I would highly recommend OSSEC Great write up on DO here It is an intrusion detection system, but has a couple of ips features like iptables dropping. This should stop brute force attacks. Also is you limit your root login to Digital Ocean to ssh keys that would almost certainly reduce the risk of hacking. That said make sure file and folder permissions are all good and search the web for other things to do. Web applications are usually the weak point in a hacking attempt as their surface area is much greater. Hope this helps! And good luck!