1

During a pentest, I was able to get the contents of authorized_keys file which has a single client's entry. So, can I generate a private key using the public key from this file, and login to the server using this pair? If yes, how to do that? As this public key in the file is encrypted using a passphrase, I will have to use John the ripper (JTR) to extract the pass first. Is my thought flow correct? Could you please let me know how to use JTR for this?

1
  • 6
    I don't mean this to come across as snarky, but I think you should take a moment to think about what "public" means in "public key." Then you will have your answer.
    – tlng05
    Jul 24, 2017 at 4:40

2 Answers 2

9

You cannot generate a private key from a public key. That's the whole point of public-key cryptography.

The public key is not encrypted. Even if you don't understand what the numbers do, they're in a form that's ready to use. No password is involved. (Private keys are often encrypted with a password, but you don't have a private key.)

Having the contents of authorized_keys will not help you log into the machine. The only consequence it might have is on the user's privacy, since it tells you something about who is allowed to log into this acccount.

2
  • Maybe you can change your sentence to include the case where the cryptographic primitives are not met. Indeed in some specific case when the crypto is wrong/weak you can actually recover private key from public key (e.g. for rsa if you use too small primes p & q) Jul 24, 2017 at 13:28
  • @Whysmerhill Any crypto can be broken if you do it wrong. As breakable keys are not a common occurrence with SSH today, I don't think it's relevant to mention it in my answer. Jul 24, 2017 at 22:04
0

If anyone comes across this situation, it is actually possible to brute force and find the keys with the help of authorized_keys file, but the system should be using very old ssh library. Refer (CVE-2008-0166) https://github.com/g0tmi1k/debian-ssh for more details.

2
  • That is ONLY for Debian based system generated keys that have been generated by one of the affected versions of ssh-keygen. Basically the keygen was broken by only having a small number of possible settings for the PRNG. You can test if your keys are affected by this and reissue them if needed!
    – LvB
    Jul 24, 2017 at 11:32
  • What matters is where the keys were generated, not what the system is using. Keys generated by the broken Debian ssh have pretty much disappeared nowadays. Jul 24, 2017 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .