0

I have an SFTP server. My ServerA wants to send a file to SFTP server, and i was told that ServerA public key needs to stored on SFTP server for Authentication purposes.

My question is, if the public key of ServerA gets installed into another server by an internal attacker, and if somehow he also points ServerA to another hacked SFTPServer- the file would potentially land into the hacked SFTPserver.

Is this not a security risk?

ZEE
  • 157
  • 3

1 Answers1

1

Underneath the hood SFTP uses SSH but the same principles apply.

Generally, it is impossible to derive the public key from the private key. Hence we're allowed to share/publish the public key without any fear of the private key being compromised. You will use your Private Key to authenticate yourself to ServerA, and ServerA uses your pre-loaded publickey to ensure it really is you.

However, to answer your question, You will also authenticate serverA by checking its SSH key fingerprint. Basically the first time you connect to ServerA, you'll be prompted to save its SSH key fingerprint (which is a hash of serverA's public key). This will be saved locally on whatever client application you're using.

If someone managed to copy your public key -- and someone manage to hijack the dns/ip of serverA, and route all traffic from you to it -- you'd still be warned that the servers underlying public key has changed, and you should proceed cautiously. You might think "well what if the hacked serverA and got it's public key as well"

If they hacked serverA to the point where they could get the public/private key pair of the server -- they most probably already have access to your files as well :)

keithRozario
  • 3,571
  • 2
  • 12
  • 24
  • if we encrypt the file with SFTP servers Public Key, then only the SFTP server will be able to decrypt it. Will this address the risk that if the file lands on a hacked SFTP server, the file would still be of no use? – ZEE Sep 18 '19 at 06:16
  • 2
    @ZEE No, the encryption SSH uses is all symmetric, the private and public keys are just used to create and verify signatures to prove identity. If you chose to ignore the warning that the server's key had changed, you would be giving the file to the attacker. – AndrolGenhald Sep 18 '19 at 06:40
  • @AndrolGenhald I read ZEE as meaning encrypt it with the server's public key _before_ sending it over SFTP (so only serverA, with its private key, could decrypt it after reception), although I don't think this would gain anything over properly verifying that they are, in fact, talking to serverA. – TripeHound Sep 18 '19 at 09:11
  • 1
    @TripeHound I hadn't considered that interpretation of the comment, that might not be totally broken. It'd be very weird to use the server's host key for file encryption though, it makes a lot more sense to just verify it when starting the SSH connection. – AndrolGenhald Sep 18 '19 at 20:29