2017-06-27 68 views
0

我有一個項目使用phpseclib connect cisco和H3C Swtich設備。我如何測試登錄密碼

這些設備的passowrd並沒有不同,所以我必須嘗試測試這些密碼,當我第一次登錄這些設備時。

我寫了一些代碼來找到密碼列表中的正確密碼,但正確的密碼只有當它第一次用於登錄時纔有效。

function loginssh_keybo(){ 
    $user = user::find()->all(); 
    $ssh = new SSH2($this->ip); 
    if (@$ssh->login($user[$this->i]->username, $user[$this->i]->password)) { 
     return $ssh; 
    }else{ 
     return false; 
    } 

} 

function loginssh_pass(){ 
    $user = user::find()->all(); 
    $ssh = new SSH2($this->ip); 
    if (@$ssh->login($user[$this->i]->username, $user[$this->i]->password, $user[$this->i]->password)) { 
     return $ssh; 
    }else{ 
     return false; 
    } 

} 
function loginssh() 
{ 
    $user = user::find()->all(); 
    $max = 3; 
    $this->i = 0; 
    do { 
     if (@$ssh=$this->loginssh_keybo()) { 
      $this->islogin = True; 
      break; 
     } elseif (@$ssh=$this->loginssh_pass()) { 
      $this->islogin = True; 
      break; 
     } elseif 
     ($this->i > $max) { 
      return false; 
     } 
     $this->i += 1; 
    } while (!$this->islogin); 
    $this->user = $user[$this->i]->username; 
    $this->password = $user[$this->i]->password; 
    return $ssh; 
} 
+0

貌似這已經交叉張貼了這個在https://github.com/phpseclib/phpseclib/issues/1144。 – neubert

回答