forked from phpseclib/phpseclib
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -991,6 +991,19 @@ class SSH2 | |
*/ | ||
private $kex_buffer = []; | ||
|
||
/** | ||
* Strict KEX Flag | ||
* | ||
* If [email protected] is present in the first KEX packet it need not | ||
* be present in subsequent packet | ||
* | ||
* @see self::_key_exchange() | ||
* @see self::exec() | ||
* @var array | ||
* @access private | ||
*/ | ||
private $strict_kex_flag = false; | ||
|
||
/** | ||
* Default Constructor. | ||
* | ||
|
@@ -1413,8 +1426,13 @@ private function key_exchange($kexinit_payload_server = false): bool | |
$first_kex_packet_follows | ||
] = Strings::unpackSSH2('L10C', $response); | ||
if (in_array('[email protected]', $this->kex_algorithms)) { | ||
if ($this->session_id === false && count($this->kex_buffer)) { | ||
throw new \UnexpectedValueException('Possible Terrapin Attack detected'); | ||
if ($this->session_id === false) { | ||
// [[email protected] is] only valid in the initial SSH2_MSG_KEXINIT and MUST be ignored | ||
// if [it is] present in subsequent SSH2_MSG_KEXINIT packets | ||
$this->strict_kex_flag = true; | ||
if (count($this->kex_buffer)) { | ||
throw new \UnexpectedValueException('Possible Terrapin Attack detected'); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1651,12 +1669,11 @@ private function key_exchange($kexinit_payload_server = false): bool | |
|
||
$packet = pack('C', MessageType::NEWKEYS); | ||
$this->send_binary_packet($packet); | ||
|
||
$response = $this->get_binary_packet_or_close(MessageType::NEWKEYS); | ||
$this->get_binary_packet_or_close(MessageType::NEWKEYS); | ||
|
||
$this->keyExchangeInProgress = false; | ||
|
||
if (in_array('[email protected]', $this->kex_algorithms)) { | ||
if ($this->strict_kex_flag) { | ||
$this->get_seq_no = $this->send_seq_no = 0; | ||
} | ||
|
||
|