Security / ARTICLE

Alpine Linux Security Advisory: OpenSSH Password Authentication Bypass

Alpine Linux has published a security advisory for a password authentication bypass in openssh-server. Attackers can log in to accounts with no password set if another account has a $5$ or $6$ hash. Update and restart sshd, or disable password authentication.

Alpine Linux has published a security advisory for a password authentication bypass in its openssh-server package. Systems running sshd should update openssh immediately and restart the daemon. If updating is not possible, setting PasswordAuthentication no and restarting sshd closes the hole.

How the bypass works

An attacker who can reach the SSH port can log in without a password. The process takes one connection, succeeds every time, and requires no retries. The attacker needs the name of an account whose password field is * — an account with no password set, typical for key-only accounts — and the machine must have at least one other account with a $5$ or $6$ password hash. Sending a very long password (257 to 1024 bytes) allows login to any account without a password.

The root cause lies in how sshd verifies passwords when built without PAM. It hashes the attempted password using crypt() and compares the result to the stored password field. If the stored field for an account is too short to contain a salt, sshd borrows the salt of another account. musl’s crypt() returns the string * as an error indicator when the key exceeds 256 bytes. Since * is exactly the stored field for accounts with no password, the hash appears to match and authentication succeeds. OpenSSH 10.6p2 fixes the issue in sshd, and Alpine’s stable-branch packages include a patch.

Affected configurations and releases

A system is affected when all of the following are true: it runs the Alpine openssh-server package (built without PAM) or openssh-server-pam with UsePAM no; PasswordAuthentication is yes (the OpenSSH default); the machine has an account with a password field of *; and at least one local account has a $5$ or $6$ password hash.

Accounts with a * password field include root in the base image (root:* has shipped since approximately Alpine 3.16), but OpenSSH’s default PermitRootLogin prohibit-password protects root unless PermitRootLogin yes is set. That protection does not help if another account can escalate to root through doas. Other affected accounts include key-only users created with adduser without a password, users set with usermod -p ‘*’, and users from directory services via musl-nscd. The alpine user in official tiny-cloud images is also affected.

Every Alpine release checked is vulnerable: 3.21 through 3.24, edge, and older releases 3.16 through 3.20. Systems not affected include containers that do not run sshd, setups with PasswordAuthentication no, openssh-server-pam with UsePAM yes, locked accounts with a ! password field, systems with no $-style password hash, and cloud images configured through cloud-init (which writes PasswordAuthentication no).

Fixes and detection

To fix, run apk upgrade -U -a and then rc-service sshd restart. Upgrading the package does not restart the running daemon, so the restart step is mandatory. Fixed package versions are available for edge and all branches from 3.16 to 3.24; specific versions are listed in the advisory. Alpine 3.21.10, 3.22.8, 3.23.8, 3.24.4 and later include the fix. Older point releases do not, so running instances must update or disable password authentication.

For systems that cannot update immediately, disable password authentication. Before proceeding, verify that SSH key login works and keep the current session open until a new login is tested. Run as root:

mkdir -p /etc/ssh/sshd_config.d echo ‘PasswordAuthentication no’ > /etc/ssh/sshd_config.d/00-no-passwords.conf sed -i.bak -e ‘1i PasswordAuthentication no’ -e ‘s/^(\sPasswordAuthentication[^y#])yes/\1no/i’ /etc/ssh/sshd_config sshd -t && rc-service sshd restart sshd -T | grep -i passwordauthentication

The last command should print passwordauthentication no. To undo, delete the drop-in file and restore the original sshd_config from the .bak file.

Official tiny-cloud images from 3.18.11 through 3.24.3 ship an alpine user with a * password field and passwordless doas. They are safe on first boot but become exploitable as soon as any $6$ hash exists on the machine, for example when an admin sets a console password or user-data adds a user with hashed_passwd. An attacker can then get a shell as alpine and use doas to become root. Images built from 3.21.10, 3.22.8, 3.23.8, 3.24.4 and later include the fixed package. Earlier images require manual updates or disabling password authentication.

To check for attacks, look in /var/log/messages for sshd lines reading “Accepted password for” an account with no password (such as alpine, root, or a key-only user). Review doas usage and recently created users, files, and authorized keys on exposed machines. If a login cannot be ruled out, treat the machine as compromised.

END
Feedback