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.
SSH2: ignore [email protected] in key re-exchanges
- Loading branch information
1 parent
8de7a89
commit 2fe0eab
Showing
1 changed file
with
22 additions
and
4 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 |
---|---|---|
|
@@ -1143,6 +1143,19 @@ class Net_SSH2 | |
*/ | ||
var $kex_buffer = array(); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
var $strict_kex_flag = false; | ||
|
||
/** | ||
* Default Constructor. | ||
* | ||
|
@@ -1658,9 +1671,14 @@ function _key_exchange($kexinit_payload_server = false) | |
$temp = unpack('Nlength', $this->_string_shift($response, 4)); | ||
$this->kex_algorithms = explode(',', $this->_string_shift($response, $temp['length'])); | ||
if (in_array('[email protected]', $this->kex_algorithms)) { | ||
if ($this->session_id === false && count($this->kex_buffer)) { | ||
user_error('Possible Terrapin Attack detected'); | ||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); | ||
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)) { | ||
user_error('Possible Terrapin Attack detected'); | ||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -2051,7 +2069,7 @@ function _key_exchange($kexinit_payload_server = false) | |
|
||
$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; | ||
} | ||
|
||
|