PHPSecLib拆分命令

时间:2014-10-11 17:48:17

标签: php ssh phpseclib libssh2

我正在使用PHPSecLib通过SSH将命令发送到网络交换机,这在大多数情况下都能正常工作。我不得不做一些修改来支持一个不同的品牌,但似乎通过write()发送命令导致这些被拆分。

我从来没有见过这样的事情,而且我对于导致它的原因感到非常难过。 PHPSecLib / SSH中是否存在强制命令行字符串达到一定长度的任何内容?

命令行输出:

configure Entering configuration mode
{master:0}[edit]
LHBR@EVO-HN11-1# set policy-options prefix-list ddosHost 183.24.48.7 255. 
LHBR@EVO-HN11-1# ...ix-list ddosHost 183.24.48.7 255.2 55.255.255 ^ syntax error. 
{master:0}[edit]
LHBR@EVO-HN11-1# commit configuration check succeeds commit complete 
{master:0}[edit] 
LHBR@EVO-HN11-1# exit Exiting configuration mode 
{master:0} 
LHBR@EVO-HN11-1>

功能:

public function write_msg($msg)
{
    for ($i = 0; $i < strlen($msg); $i++)
    {
        $this->conn->write($msg[$i]);
    }
}

public function create_nullroute($ip, $netmask = "255.255.255.255")
{

    $this->write_msg("configure\n");
    $this->write_msg("set policy-options prefix-list ddosHost " . $ip . " " . $netmask . "\n");
    $this->write_msg("commit\n");

    // Escape the config mode
    $this->conn->write("exit\n");

    echo "</br><pre>" . $this->conn->getLog() . "</pre>";

    echo $this->conn->read($this->_bashshell);
}

PHPSecLib日志:

-> NET_SSH2_MSG_NEWKEYS (since last: 0.005, network: 0s)


<- NET_SSH2_MSG_NEWKEYS (since last: 0, network: 0s)


-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0028, network: 0s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

<- NET_SSH2_MSG_SERVICE_ACCEPT (since last: 0.5057, network: 0.5056s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0001, network: 0s)
00000000  00:00:00:08:75:73:65:72:6e:61:6d:65:00:00:00:0e  ....username....
00000010  73:73:68:2d:63:6f:6e:6e:65:63:74:69:6f:6e:00:00  ssh-connection..
00000020  00:08:70:61:73:73:77:6f:72:64:00:00:00:00:08:70  ..password.....p
00000030  61:73:73:77:6f:72:64                             assword

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 0.2388, network: 0.2387s)


-> NET_SSH2_MSG_CHANNEL_OPEN (since last: 0.0001, network: 0s)
00000000  00:00:00:07:73:65:73:73:69:6f:6e:00:00:00:01:7f  ....session.....
00000010  ff:ff:ff:00:00:40:00                             .....@.

<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.2093, network: 0.2092s)
00000000  00:00:00:01:00:00:00:00:00:00:00:00:00:00:80:00  ................

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:07:70:74:79:2d:72:65:71:01  ........pty-req.
00000010  00:00:00:05:76:74:31:30:30:00:00:00:50:00:00:00  ....vt100...P...
00000020  18:00:00:00:00:00:00:00:00:00:00:00:01:00        ..............

<- NET_SSH2_MSG_CHANNEL_SUCCESS (since last: 0.2233, network: 0.2232s)
00000000  00:00:00:01                                      ....

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:05:73:68:65:6c:6c:01        ........shell.

<- NET_SSH2_MSG_CHANNEL_WINDOW_ADJUST (since last: 0.2153, network: 0.2153s)
00000000  00:00:00:01:00:20:00:00                          ..... ..

<- NET_SSH2_MSG_CHANNEL_SUCCESS (since last: 0.0001, network: 0s)
00000000  00:00:00:01                                      ....

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0158, network: 0.0157s)
00000000  00:00:00:01:00:00:00:32:2d:2d:2d:20:4a:55:4e:4f  .......2--- JUNO
00000010  53:20:31:32:2e:33:52:33:2e:34:20:62:75:69:6c:74  S 12.3R3.4 built
00000020  20:32:30:31:33:2d:30:36:2d:31:34:20:30:30:3a:30   2013-06-14 00:0
00000030  36:3a:33:34:20:55:54:43:0d:0a                    6:34 UTC..

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.6052, network: 0.6051s)
00000000  00:00:00:01:00:00:00:0c:7b:6d:61:73:74:65:72:3a  ........{master:
00000010  30:7d:0d:0a                                      0}..

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0015s)
00000000  00:00:00:01:00:00:00:11:4c:48:42:52:40:45:56:4f  ........LHBR@EVO
00000010  2d:48:4e:31:31:2d:31:3e:20                       -HN11-1> 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:18:73:65:74:20:63:6c:69:20  ........set cli 
00000010  73:63:72:65:65:6e:2d:6c:65:6e:67:74:68:20:30:0a  screen-length 0.

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.207, network: 0.207s)
00000000  00:00:00:01:00:00:00:01:73                       ........s

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0015, network: 0.0014s)
00000000  00:00:00:01:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0015, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:74                       ........t

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0047, network: 0.0046s)
00000000  00:00:00:01:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0014, network: 0.0014s)
00000000  00:00:00:01:00:00:00:01:63                       ........c

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0025, network: 0.0024s)
00000000  00:00:00:01:00:00:00:01:6c                       ........l

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0015, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:69                       ........i

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0039, network: 0.0039s)
00000000  00:00:00:01:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:73                       ........s

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0021, network: 0.002s)
00000000  00:00:00:01:00:00:00:01:63                       ........c

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:72                       ........r

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0014, network: 0.0014s)
00000000  00:00:00:01:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0017, network: 0.0017s)
00000000  00:00:00:01:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0047, network: 0.0046s)
00000000  00:00:00:01:00:00:00:01:6e                       ........n

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0001s)
00000000  00:00:00:01:00:00:00:01:2d                       ........-

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:01:00:00:00:01:6c                       ........l

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:01:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0009, network: 0.0009s)
00000000  00:00:00:01:00:00:00:01:6e                       ........n

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0016s)
00000000  00:00:00:01:00:00:00:01:67                       ........g

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0022, network: 0.0021s)
00000000  00:00:00:01:00:00:00:01:74                       ........t

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:68                       ........h

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0041, network: 0.004s)
00000000  00:00:00:01:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0016, network: 0.0015s)
00000000  00:00:00:01:00:00:00:01:30                       ........0

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0048, network: 0.0047s)
00000000  00:00:00:01:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0023, network: 0.0022s)
00000000  00:00:00:01:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0048, network: 0.0048s)
00000000  00:00:00:01:00:00:00:18:53:63:72:65:65:6e:20:6c  ........Screen l
00000010  65:6e:67:74:68:20:73:65:74:20:74:6f:20:30:0d:0a  ength set to 0..

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0021, network: 0.002s)
00000000  00:00:00:01:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0043, network: 0.0043s)
00000000  00:00:00:01:00:00:00:0c:7b:6d:61:73:74:65:72:3a  ........{master:
00000010  30:7d:0d:0a                                      0}..

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:01:00:00:00:11:4c:48:42:52:40:45:56:4f  ........LHBR@EVO
00000010  2d:48:4e:31:31:2d:31:3e:20                       -HN11-1> 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:01:63                       ........c

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6e                       ........n

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:66                       ........f

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:67                       ........g

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:75                       ........u

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:72                       ........r

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:65                       ........e

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:0a                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:73                       ........s

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:65                       ........e

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:74                       ........t

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:20                       ........ 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:70                       ........p

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6c                       ........l

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:63                       ........c

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:79                       ........y

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2d                       ........-

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:70                       ........p

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:74                       ........t

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6e                       ........n

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:73                       ........s

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:20                       ........ 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:70                       ........p

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:72                       ........r

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:65                       ........e

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:66                       ........f

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:78                       ........x

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2d                       ........-

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6c                       ........l

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:73                       ........s

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:74                       ........t

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:20                       ........ 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:64                       ........d

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:64                       ........d

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:73                       ........s

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:48                       ........H

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:73                       ........s

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:74                       ........t

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:20                       ........ 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:31                       ........1

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:38                       ........8

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:31                       ........1

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:36                       ........6

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:38                       ........8

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:34                       ........4

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:37                       ........7

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:30                       ........0

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:20                       ........ 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:32                       ........2

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:32                       ........2

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:32                       ........2

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:2e                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:32                       ........2

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:35                       ........5

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:0a                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:63                       ........c

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6f                       ........o

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6d                       ........m

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:6d                       ........m

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:69                       ........i

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:74                       ........t

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:01:0a                       .........

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:05:65:78:69:74:0a           ........exit.

2 个答案:

答案 0 :(得分:1)

你可能想尝试在那里抛出一些$ssh->read()。根据我的经验,如果您只是发送命令而不执行任何read(),那么在上一个命令有机会运行之前,您可能发送的速度太快。

答案 1 :(得分:0)

简答:

这只是一个猜测,但不是做$this->conn->write("configure\n");尝试一次写一个字符。例如

$cmd = "configure\n";
for ($i = 0; $i < strlen($cmd); $i++) {
    $this->conn->write($cmd[$i]);
}

长答案:

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:0a:63:6f:6e:66:69:67:75:72  ........configur
00000010  65:0a                                            e.

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.1027, network: 0.1026s)
00000000  00:00:00:01:00:00:00:01:63                       ........c

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0012, network: 0.0011s)
00000000  00:00:00:01:00:00:00:08:6f:6e:66:69:67:75:72:65  ........onfigure

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0047, network: 0.0046s)
00000000  00:00:00:01:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0118, network: 0.0118s)
00000000  00:00:00:01:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0015, network: 0.0015s)
00000000  00:00:00:01:00:00:00:1d:45:6e:74:65:72:69:6e:67  ........Entering
00000010  20:63:6f:6e:66:69:67:75:72:61:74:69:6f:6e:20:6d   configuration m
00000020  6f:64:65:0d:0a                                   ode..

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0019, network: 0.0018s)
00000000  00:00:00:01:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0013, network: 0.0013s)
00000000  00:00:00:01:00:00:00:23:7b:6d:61:73:74:65:72:3a  .......#{master:
00000010  30:7d:5b:65:64:69:74:5d:0d:0a:4c:48:42:52:40:45  0}[edit]..LHBR@E
00000020  56:4f:2d:48:4e:31:31:2d:31:23:20                 VO-HN11-1# 

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:00:00:00:00:45:73:65:74:20:70:6f:6c:69  .......Eset poli
00000010  63:79:2d:6f:70:74:69:6f:6e:73:20:70:72:65:66:69  cy-options prefi
00000020  78:2d:6c:69:73:74:20:64:64:6f:73:48:6f:73:74:20  x-list ddosHost 
00000030  31:38:35:2e:31:36:2e:38:34:2e:37:30:20:32:35:35  186.26.81.23 255
00000040  2e:32:35:35:2e:32:35:35:2e:32:35:35:0a           .255.255.255.

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0, network: 0s)
00000000  00:00:00:00:00:00:00:07:63:6f:6d:6d:69:74:0a     ........commit.

因此,服务器在发送后回显每个命令。有趣的是它有点随意地做这件事。就像在一个数据包上发送的配置一样,你要回复的响应就是把它分成两个数据包。

之后,您将通过接下来的两个命令发送服务器并不对它们做任何事情。它不会回应它们或任何东西。然后连接才被关闭。

这提出了几个问题。

  1. 除非您在这些命令后调用$this->conn->read(),否则您不应该收到回复。你是?如果是这样,那么原始帖子中的代码不是最新的。
  2. 您发布的CLI输出与您在phpseclib日志中获得的输出不匹配。 phpseclibs产生的输出如下:

    2--- JUNOS 12.3R3.4 built 2013-06-14 00:06:34 UTC
    {master:0}
    biss@EVO-HN11-1> set cli screen-length 0
    Screen length set to 0
    {master:0}
    LHBR@EVO-HN1-1> configure
    Entering configuration mode
    #{master:0}[edit]
    LHBR@EVO-HN11-1#
    
  3. 因此,您的帖子中存在某些差异,但是,不过,我确实根据您目前发布的内容有一个想法。

    而不是$this->conn->write("configure\n");尝试一次写一个字符。例如

    $cmd = "configure\n";
    for ($i = 0; $i < strlen($cmd); $i++) {
        $this->conn->write($cmd[$i]);
    }