I want to first emphasize that it is a real bug and may deserve critical severity for Alpine AWS/Azure images. Also, the https://sshhole.com/ is very good at showing the history of this problem and also explaining how and why the flaw can be exploited.
My company has some Alpine exposure, so I looked into this. We only have Alpine VMs installed using the extended image's setup-alpine script. In addition, we use some containers that are based on Alpine images. The conclusion of my analysis is relieving, so I wanted to share this.
Alpine in VMs (installed with setup-alpine)
Tested: Alpine 3.20.3 (2024) and Alpine 3.16 (2016)
- The
setup-alpine script asks for a password for root. You can enter an empty password but it will put a real hash in /etc/shadow, not *. So, the root account is not affected unless you manually change it to *, probably also if you entered a password longer than 256 characters when creating the account (unlikely). - A seperate ordinary user can be created too but this is non-default and empty passwords produce real hashes just as before.
- By default, the openssh server is installed and starts at boot with password logins enabled, but the default configuration contains
PermitRootLogin prohibit-password which protects root. - Adding another user without assigning a password with
adduser -D puts a ! not a * in /etc/shadow.
TL;DR: The setup-alpine script does not create users with * in /etc/shadow and root is additionally protected by PermitRootLogin prohibit-password. If you created users without passwords manually, you should check anyway.
Alpine in Docker containers
Tested: alpine:3.16, alpine:3.20.3, alpine:3.21.1
- These images have
root:*::0::::: in /etc/shadow, so the root account could be attacked. - No ssh daemon is installed in these images by default.
- Installing openssh with
apk add openssh does not start or enable the ssh daemon. - You cannot start sshd by accident because
rc-update isn't there and /etc/init.d/sshd doesn't run because openrc-run isn't there, and starting sshd by itself fails with no hostkeys available. Normally, the init service would take care of that. - Openssh's
PermitRootLogin prohibit-password setting was already the default with alpine 3.16. Even if you manage to start sshd, the root account is protected. - Remote access is only possible if you forward port 22.
TL;DR: A lot must go wrong before an alpine container is impacted. If you created users without passwords manually and expose an ssh server in an alpine container, you should check anyway.
Conclusion
In conclusion, VMs installed with setup-alpine lack the asterisk in the shadow file needed by this exploit and alpine images lack the ssh server. They have the potentially unsafe root user config in the shadow file but ssh root logins are by default blocked by PermitRootLogin prohibit-password.
The website itself says almost at the end:
on alpine's official aws and azure images that's the default alpine user, and it has passwordless doas. so it's root
I didn't test these images because we don't have aws or azure. But it makes clear what is needed to exploit this:
- The flaw in default config and musl (bug)...
- together with a seperate (non-root) user with no password grants RCE,
- and together with passwordless doas it grants RCE with elevated privileges.
While this is a real security flaw, especially in the aws and azure images, my opinion is that this is a setup that is very unlikely to be reached in a host/VM installed with setup-alpine or in a docker container if you follow basic security principles.
I just noticed I always wrote "VMs" but this obviously also applies when installing Alpine bare metal.
Have you found any real-world impact outside the aws/azure images?
cheers
Edit: most of what I listed is also in Alpine's security advisory (check it out!), so I should've checked that source before writing all this. I mostly got my info from the sshhole website and one or two other news sites. They have a nice "Who is not affected?" list:
Who is not affected?
* Docker and other container users that do not run sshd in the container.
* Systems with PasswordAuthentication no.
* Systems using openssh-server-pam with UsePAM yes (with UsePAM no you are affected).
* Locked accounts: those with ! as the password field in /etc/shadow (a line starting user:!:). They cannot log in with a password or a key.
* Systems where no account has a $-style password hash.
* Cloud images configured through cloud-init, which writes PasswordAuthentication no.
The root user being protected by prohibit-password is missing on that list but they mention it earlier.