2

I am planning to host a flask application on EC2 instance, which connects to a database. The database credentials are inside a folder on the server.

EC2 login can be done only via ssh private key. The flask API itself is not ssl secured but when it talks to database its over a secure connection.

Is it possible to login into the EC2 via ssh brute force or any other way & acquire database credentials. I have not enabled username & password login to ec2, login is only via private key.

keithRozario
  • 3,571
  • 2
  • 12
  • 24

2 Answers2

2

If you disabled password based login via SSH, then it is very hard to brute force an SSH login using a private key (especially if that private key follows current best practice for algorithm selection.

But here's a few extra steps to ensure your EC2 is secured from login:

  • Ensure your Security Groups allows only the SSH + Whatever ports flask is exposing for ingress traffic
  • Ensure your Security Groups allows only database server security group as egress traffic
  • Protect your flask app (this is harder to do) and as the answer above suggest, is the most probable entry point for an attacker.

If we're focusing on SSH access -- then my suggestion is to disable SSH access entirely and instead of AWS System Manager Session Manager. It installs an agent on your EC2, that then allows you to connect to your server via the console. All console based logins are then recorded for audit purpose. Hence in order to access your EC2, attackers would first need to compromise your entire AWS account.

keithRozario
  • 3,571
  • 2
  • 12
  • 24
  • Even though only port 22 via ssh is enabled AWS prints a warning " Your security group, ssh-only, is open to the world." Is that being paranoid? https://security.stackexchange.com/questions/233785/is-starting-an-aws-instance-with-only-ssh-to-port-22-insecure – WestCoastProjects Jun 25 '20 at 20:59
  • Is it harder or easier to compromise an SSH server or an AWS account? I have no idea. – Paul Draper May 16 '21 at 15:53
1

If SSH password authentication is disabled, an attacker should not be able to log in over SSH without possessing the correct private key.

Besides SSH, if there are any vulnerabilities in any other exposed services (e.g. your Flask app), those could potentially be exploited to gain access to your server.

multithr3at3d
  • 12,355
  • 3
  • 29
  • 42