phpseclib SSH2 HMAC Verification Vulnerability Leading to Timing Attack

Vulnerability

A vulnerability exists in the phpseclib library's SSH2 component, specifically in the HMAC verification process of the 'get_binary_packet' method'. This issue is present in versions prior to 3.0.51, 2.0.53, and 1.0.28. The vulnerability arises because the library uses PHP's '!=' operator to compare HMACs, which introduces a variable-time comparison flaw. This behavior can be exploited to create a timing attack, although such exploitation is impractical in a real-world SSH context due to the protocol's inherent protections.

Impact

Exploitation of this vulnerability creates a timing side-channel that could theoretically allow an attacker to recover HMAC values byte-by-byte. However, this attack is not feasible in practice, as each SSH connection uses a fresh HMAC key and the protocol disconnects on MAC verification failures, preventing the accumulation of timing information across packets.

Reproduction

The vulnerability can be reproduced by sending SSH packets over a connection that negotiates a non-AEAD cipher and a non-AEAD MAC. This will trigger the vulnerable HMAC verification code, where the '!=' operator introduces a timing leak. The vulnerability can be demonstrated using a proof-of-concept script that measures the timing differences caused by the variable-time comparison.

Remediation

Users can upgrade to phpseclib versions 3.0.51, 2.0.53, or 1.0.28, where this vulnerability has been fixed.

Added: Apr 10, 2026, 9:24 PM
Updated: Apr 10, 2026, 9:24 PM

Vulnerability Rating

Custom Algorithm
spread
4.2
impact
0.6
exploitability
5.6
remediation
7.7
relevance
5.6
threat
6.4
urgency
2.9
incentive
0.0

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.