phpseclib / phpseclib

PHP Secure Communications Library
http://phpseclib.com/
MIT License
5.35k stars 888 forks source link

Connection closed prematurely #1244

Closed dcortez closed 6 years ago

dcortez commented 6 years ago

I am trying to use this library (version 2.0.9) in a Laravel project to connect to a Cisco CMTS in order to get data about modems on our system. I have successfully used this code in the past on a Codeigniter project (in fact, running on the same server). The only difference I can see is I am using an older version (not sure which) of the library in my Codeigniter project vs my Laravel project.

The test code I am running is exactly the same between the two frameworks and is as follows:


// I have replaced the var $cmts_ip with a hardcoded value for testing but have the same results
    $ssh = new \phpseclib\Net\SSH2($cmts_ip);

    // Have tried with different timeouts, 0 causes cannot login
    // Less than 10 causes incomplete data (based on logging)
    // more than 30 seems to work fine (based on logging), 
    // but I have it set to 60 for the hell of it
    $ssh->setTimeout(60); 

        if ( ! $ssh->login($cmts_username, $cmts_password))
        {
            return response()->json([
                'error' => [
                    'message' => 'Cannot login to SSH Host',
                    'status_code' => 500
                ]
            ], 500);
        }

        $results = $ssh->exec("show cable modem");
        dd($results);
                //$ssh->disconnect();

In my testing, if I remove the $ssh->exec line, the script does not error out and the logs show it logs in and out perfectly. Once I add the exec in is where I get the connection closed error.

We are testing this on a lab cmts on a private IP so won't be able to give that information, but I am hoping that with the log you will see something I am missing.

Error Stack:

{
    "message": "Connection closed prematurely",
    "exception": "ErrorException",
    "file": "/home/dustin/apiv2/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php",
    "line": 3818,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php",
            "line": 3818,
            "function": "user_error"
        },
        {
            "file": "/home/dustin/apiv2/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php",
            "line": 4036,
            "function": "_send_binary_packet",
            "class": "phpseclib\\Net\\SSH2",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php",
            "line": 3146,
            "function": "_disconnect",
            "class": "phpseclib\\Net\\SSH2",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php",
            "line": 3162,
            "function": "disconnect",
            "class": "phpseclib\\Net\\SSH2",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/app/Http/Controllers/NetworkToolsController.php",
            "line": 397,
            "function": "__destruct",
            "class": "phpseclib\\Net\\SSH2",
            "type": "->"
        },
        {
            "function": "test",
            "class": "App\\Http\\Controllers\\NetworkToolsController",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 212,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 169,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 658,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 57,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 102,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 660,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 635,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 601,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 590,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 176,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 56,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 30,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 30,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 46,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 149,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 102,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 151,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 116,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/dustin/apiv2/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}

Log:

<-
00000000  53:53:48:2d:32:2e:30:2d:43:69:73:63:6f:2d:31:2e  SSH-2.0-Cisco-1.
00000010  32:35:0a                                         25.

->
00000000  53:53:48:2d:32:2e:30:2d:70:68:70:73:65:63:6c:69  SSH-2.0-phpsecli
00000010  62:5f:32:2e:30:20:28:6f:70:65:6e:73:73:6c:2c:20  b_2.0 (openssl, 
00000020  67:6d:70:29:0d:0a                                gmp)..

-> NET_SSH2_MSG_KEXINIT (since last: 0.0342, network: 0.0001s)
00000000  aa:24:30:c7:0b:e3:b6:54:af:26:cd:08:ed:91:89:8b  .$0....T.&......
00000010  00:00:00:7e:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ...~diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:2c:64  an-group1-sha1,d
00000030  69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72  iffie-hellman-gr
00000040  6f:75:70:31:34:2d:73:68:61:31:2c:64:69:66:66:69  oup14-sha1,diffi
00000050  65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:2d  e-hellman-group-
00000060  65:78:63:68:61:6e:67:65:2d:73:68:61:31:2c:64:69  exchange-sha1,di
00000070  66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f  ffie-hellman-gro
00000080  75:70:2d:65:78:63:68:61:6e:67:65:2d:73:68:61:32  up-exchange-sha2
00000090  35:36:00:00:00:0f:73:73:68:2d:72:73:61:2c:73:73  56....ssh-rsa,ss
000000a0  68:2d:64:73:73:00:00:00:d3:61:65:73:31:32:38:2d  h-dss....aes128-
000000b0  63:74:72:2c:61:65:73:31:39:32:2d:63:74:72:2c:61  ctr,aes192-ctr,a
000000c0  65:73:32:35:36:2d:63:74:72:2c:74:77:6f:66:69:73  es256-ctr,twofis
000000d0  68:31:32:38:2d:63:74:72:2c:74:77:6f:66:69:73:68  h128-ctr,twofish
000000e0  31:39:32:2d:63:74:72:2c:74:77:6f:66:69:73:68:32  192-ctr,twofish2
000000f0  35:36:2d:63:74:72:2c:61:65:73:31:32:38:2d:63:62  56-ctr,aes128-cb
00000100  63:2c:61:65:73:31:39:32:2d:63:62:63:2c:61:65:73  c,aes192-cbc,aes
00000110  32:35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:31  256-cbc,twofish1
00000120  32:38:2d:63:62:63:2c:74:77:6f:66:69:73:68:31:39  28-cbc,twofish19
00000130  32:2d:63:62:63:2c:74:77:6f:66:69:73:68:32:35:36  2-cbc,twofish256
00000140  2d:63:62:63:2c:74:77:6f:66:69:73:68:2d:63:62:63  -cbc,twofish-cbc
00000150  2c:62:6c:6f:77:66:69:73:68:2d:63:74:72:2c:62:6c  ,blowfish-ctr,bl
00000160  6f:77:66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d  owfish-cbc,3des-
00000170  63:74:72:2c:33:64:65:73:2d:63:62:63:00:00:00:d3  ctr,3des-cbc....
00000180  61:65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39  aes128-ctr,aes19
00000190  32:2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72  2-ctr,aes256-ctr
000001a0  2c:74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c  ,twofish128-ctr,
000001b0  74:77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74  twofish192-ctr,t
000001c0  77:6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65  wofish256-ctr,ae
000001d0  73:31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d  s128-cbc,aes192-
000001e0  63:62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74  cbc,aes256-cbc,t
000001f0  77:6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77  wofish128-cbc,tw
00000200  6f:66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f  ofish192-cbc,two
00000210  66:69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66  fish256-cbc,twof
00000220  69:73:68:2d:63:62:63:2c:62:6c:6f:77:66:69:73:68  ish-cbc,blowfish
00000230  2d:63:74:72:2c:62:6c:6f:77:66:69:73:68:2d:63:62  -ctr,blowfish-cb
00000240  63:2c:33:64:65:73:2d:63:74:72:2c:33:64:65:73:2d  c,3des-ctr,3des-
00000250  63:62:63:00:00:00:39:68:6d:61:63:2d:73:68:61:32  cbc...9hmac-sha2
00000260  2d:32:35:36:2c:68:6d:61:63:2d:73:68:61:31:2d:39  -256,hmac-sha1-9
00000270  36:2c:68:6d:61:63:2d:73:68:61:31:2c:68:6d:61:63  6,hmac-sha1,hmac
00000280  2d:6d:64:35:2d:39:36:2c:68:6d:61:63:2d:6d:64:35  -md5-96,hmac-md5
00000290  00:00:00:39:68:6d:61:63:2d:73:68:61:32:2d:32:35  ...9hmac-sha2-25
000002a0  36:2c:68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68  6,hmac-sha1-96,h
000002b0  6d:61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64  mac-sha1,hmac-md
000002c0  35:2d:39:36:2c:68:6d:61:63:2d:6d:64:35:00:00:00  5-96,hmac-md5...
000002d0  04:6e:6f:6e:65:00:00:00:04:6e:6f:6e:65:00:00:00  .none....none...
000002e0  00:00:00:00:00:00:00:00:00:00                    ..........

<- NET_SSH2_MSG_KEXINIT (since last: 0.0017, network: 0s)
00000000  5c:40:a8:dc:2d:3b:95:f9:bd:77:cc:b9:78:3d:a0:b1  \@..-;...w..x=..
00000010  00:00:00:1a:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ....diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:00:00  an-group1-sha1..
00000030  00:07:73:73:68:2d:72:73:61:00:00:00:29:61:65:73  ..ssh-rsa...)aes
00000040  31:32:38:2d:63:62:63:2c:33:64:65:73:2d:63:62:63  128-cbc,3des-cbc
00000050  2c:61:65:73:31:39:32:2d:63:62:63:2c:61:65:73:32  ,aes192-cbc,aes2
00000060  35:36:2d:63:62:63:00:00:00:29:61:65:73:31:32:38  56-cbc...)aes128
00000070  2d:63:62:63:2c:33:64:65:73:2d:63:62:63:2c:61:65  -cbc,3des-cbc,ae
00000080  73:31:39:32:2d:63:62:63:2c:61:65:73:32:35:36:2d  s192-cbc,aes256-
00000090  63:62:63:00:00:00:2b:68:6d:61:63:2d:73:68:61:31  cbc...+hmac-sha1
000000a0  2c:68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d  ,hmac-sha1-96,hm
000000b0  61:63:2d:6d:64:35:2c:68:6d:61:63:2d:6d:64:35:2d  ac-md5,hmac-md5-
000000c0  39:36:00:00:00:2b:68:6d:61:63:2d:73:68:61:31:2c  96...+hmac-sha1,
000000d0  68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d:61  hmac-sha1-96,hma
000000e0  63:2d:6d:64:35:2c:68:6d:61:63:2d:6d:64:35:2d:39  c-md5,hmac-md5-9
000000f0  36:00:00:00:04:6e:6f:6e:65:00:00:00:04:6e:6f:6e  6....none....non
00000100  65:00:00:00:00:00:00:00:00:00:00:00:00:00        e.............

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.1343, network: 0s)
00000000  00:00:00:81:00:dd:6e:82:ae:cc:41:bc:76:b1:c2:65  ......n...A.v..e
00000010  17:45:87:e2:a2:66:12:23:ed:d3:bd:b5:0a:a6:21:fa  .E...f.#......!.
00000020  f2:47:73:dd:df:54:35:e6:db:14:31:06:8d:df:ed:19  .Gs..T5...1.....
00000030  d9:8d:91:e4:52:74:fe:5c:15:11:61:8f:5c:83:7c:54  ....Rt.\..a.\.|T
00000040  69:ce:ea:41:fd:9e:a6:4e:cd:53:98:47:b0:24:ca:c4  i..A...N.S.G.$..
00000050  d2:dd:53:91:64:b2:0b:35:bb:35:6b:eb:6b:2a:c9:23  ..S.d..5.5k.k*.#
00000060  ee:34:3d:5a:8a:e2:30:45:66:15:58:30:55:4f:65:bf  .4=Z..0Ef.X0UOe.
00000070  eb:db:33:51:65:78:12:71:74:65:c7:ba:bf:7a:62:15  ..3Qex.qte...zb.
00000080  e6:7d:7b:d2:a5                                   .}{..

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 0.165, network: 0.1642s)
00000000  00:00:01:17:00:00:00:07:73:73:68:2d:72:73:61:00  ........ssh-rsa.
00000010  00:00:03:01:00:01:00:00:01:01:00:b2:85:72:b8:44  .............r.D
00000020  de:d1:42:ae:8c:5d:28:03:55:06:6a:03:9a:32:65:17  ..B..](.U.j..2e.
00000030  fd:5d:e9:f8:53:9d:85:1b:29:a5:7c:88:b8:89:62:76  .]..S...).|...bv
00000040  46:27:0f:76:da:9a:79:b1:37:bc:d6:23:93:b0:82:50  F'.v..y.7..#...P
00000050  3c:21:c0:70:c6:d5:63:a3:f5:a5:7f:47:93:a5:2d:14  .!.p..c....G..-.
00000060  b3:56:1c:3f:c0:1b:fb:87:43:75:7b:cb:05:e1:9b:ef  .V.?....Cu{.....
00000070  1b:6f:88:1a:9c:3c:78:55:ef:4d:94:9f:27:7e:81:65  .o....xU.M..'~.e
00000080  48:de:37:60:6b:25:96:1d:9b:41:2d:3c:0a:7f:e7:95  H.7`k%...A-.....
00000090  f9:bd:b7:d3:50:18:53:de:90:8f:c1:94:f2:b9:87:04  ....P.S.........
000000a0  1f:4a:6e:c6:1f:6d:bd:89:73:20:14:13:d6:0c:11:26  .Jn..m..s .....&
000000b0  01:e8:7c:8c:be:8e:48:6a:d8:d2:e8:4c:de:d0:f4:db  ..|...Hj...L....
000000c0  f4:e5:cc:2f:88:36:ec:d8:fc:68:fe:89:63:84:2c:56  .../.6...h..c.,V
000000d0  97:75:50:b2:02:44:72:b6:25:27:8e:6a:9c:0c:ed:dc  .uP..Dr.%'.j....
000000e0  f2:25:d7:ea:2f:90:e4:7f:43:94:d0:e8:39:3e:01:c8  .%../...C...9>..
000000f0  18:4b:13:c3:cf:a4:c1:5e:2a:89:ad:8b:f3:ff:00:a9  .K.....^*.......
00000100  9d:84:22:51:c7:d8:86:57:35:90:42:32:b8:57:15:a6  .."Q...W5.B2.W..
00000110  3e:36:52:e7:25:8f:3b:97:ca:8f:41:00:00:00:80:6d  >6R.%.;...A....m
00000120  3f:3f:cd:37:f6:47:b8:38:21:64:aa:09:de:d4:72:3c  ??.7.G.8!d....r.
00000130  2f:10:b1:91:c2:67:44:68:6d:81:b2:d9:7f:96:27:83  /....gDhm.....'.
00000140  7f:60:57:cd:60:cf:6c:13:66:ae:a8:0f:64:16:44:e4  .`W.`.l.f...d.D.
00000150  19:2b:f8:cd:5e:c3:16:3b:4a:cc:de:14:a5:b9:87:01  .+..^..;J.......
00000160  75:3f:8e:c3:0a:c9:0d:9d:c0:9b:8b:76:c0:9a:84:63  u?.........v...c
00000170  27:08:e0:b7:f9:7f:6a:3d:7b:1c:9d:a5:bc:86:8b:8d  '.....j={.......
00000180  81:7b:1e:ab:a9:23:a9:2c:87:76:69:c4:b2:79:5e:0b  .{...#.,.vi..y^.
00000190  f7:68:d8:0d:dc:cc:4c:0c:ad:d2:dd:3a:87:2b:d6:00  .h....L....:.+..
000001a0  00:01:0f:00:00:00:07:73:73:68:2d:72:73:61:00:00  .......ssh-rsa..
000001b0  01:00:4e:35:69:d0:91:f5:b3:c4:4a:c9:57:7d:df:d3  ..N5i.....J.W}..
000001c0  b0:a9:11:ba:78:4c:09:b7:b2:ff:71:9f:b2:f2:ea:ab  ....xL....q.....
000001d0  ef:26:eb:b8:a2:72:28:c8:78:94:fd:d0:fc:9a:4c:b7  .&...r(.x.....L.
000001e0  9e:53:69:e4:e1:74:43:25:99:82:c4:66:45:f0:88:39  .Si..tC%...fE..9
000001f0  d7:9c:9b:2f:42:c7:d6:d3:01:6a:de:7d:a4:b9:2f:ba  .../B....j.}../.
00000200  6f:bb:cf:57:eb:ab:e3:7c:2b:f6:f9:a3:ab:26:2a:be  o..W...|+....&*.
00000210  d9:d0:10:8e:b3:6a:54:da:2d:fc:3f:55:9a:b3:55:60  .....jT.-.?U..U`
00000220  4f:0e:8c:82:5c:c3:59:ec:c7:da:88:e6:03:ad:2b:a9  O...\.Y.......+.
00000230  cb:c1:15:bc:eb:42:7e:e9:16:78:3b:40:c1:bc:86:7d  .....B~..x;@...}
00000240  1a:d4:36:8f:23:63:5e:b5:06:19:88:bc:29:9b:c1:b5  ..6.#c^.....)...
00000250  d8:ba:a9:c8:25:3a:b5:e3:01:09:5f:95:23:67:08:48  ....%:...._.#g.H
00000260  f7:6a:a7:47:1a:0c:f5:26:38:37:78:68:9d:80:d6:82  .j.G...&87xh....
00000270  38:5d:2e:fb:1f:b6:6f:a8:97:6a:05:11:54:78:b6:11  8]....o..j..Tx..
00000280  df:29:3f:88:04:b7:d1:c5:1d:be:5e:a5:cf:67:8b:43  .)?.......^..g.C
00000290  1e:97:5a:c9:f1:2b:29:06:ee:84:c0:83:92:2b:a3:cf  ..Z..+)......+..
000002a0  49:49:9b:d0:28:3e:23:7b:0b:ab:fb:1e:f4:07:6d:9a  II..(>#{......m.
000002b0  bc:4b                                            .K

-> NET_SSH2_MSG_NEWKEYS (since last: 0.0027, network: 0.0001s)

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

-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0014, 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.1993, network: 0.199s)
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.0005, 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_BANNER (since last: 0.0003, network: 0s)
00000000  00:00:00:ef:0d:0a:23:23:23:23:23:23:23:23:23:23  ......##########
00000010  23:23:23:23:23:23:23:23:23:23:23:23:23:23:23:23  ################
00000020  23:23:23:23:23:23:23:23:23:23:23:23:23:23:23:23  ################
00000030  23:23:23:0d:0a:23:20:20:20:20:20:20:20:20:41:57  ###..#        AW
00000040  49:20:4e:65:74:77:6f:72:6b:73:20:45:6d:70:6c:6f  I Networks Emplo
00000050  79:65:65:73:20:4f:6e:6c:79:20:20:20:20:20:20:20  yees Only       
00000060  20:23:0d:0a:23:20:20:20:20:20:20:20:20:20:20:41   #..#          A
00000070  6c:6c:20:41:63:63:65:73:73:20:69:73:20:4d:6f:6e  ll Access is Mon
00000080  69:74:6f:72:65:64:20:20:20:20:20:20:20:20:20:20  itored          
00000090  23:0d:0a:23:20:20:20:20:20:20:20:55:6e:61:75:74  #..#       Unaut
000000a0  68:6f:72:69:7a:65:64:20:41:63:63:65:73:73:20:50  horized Access P
000000b0  72:6f:68:69:62:69:74:65:64:20:20:20:20:20:20:23  rohibited      #
000000c0  0d:0a:23:23:23:23:23:23:23:23:23:23:23:23:23:23  ..##############
000000d0  23:23:23:23:23:23:23:23:23:23:23:23:23:23:23:23  ################
000000e0  23:23:23:23:23:23:23:23:23:23:23:23:23:23:23:0d  ###############.
000000f0  0a:0d:0a:00:00:00:00                             .......

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 0.0022, network: 0.0014s)

-> NET_SSH2_MSG_CHANNEL_OPEN (since last: 0.0005, 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.9991, network: 0.0001s)
00000000  00:00:00:01:00:00:00:03:00:00:04:00:00:00:10:00  ................

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0007, network: 0s)
00000000  00:00:00:03:00:00:00:04:65:78:65:63:01:00:00:00  ........exec....
00000010  10:73:68:6f:77:20:63:61:62:6c:65:20:6d:6f:64:65  .show cable mode
00000020  6d                                               m

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

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.007, network: 0.0001s)
00000000  00:00:00:01:00:00:01:0e:20:20:20:20:20:20:20:20  ........        
00000010  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
00000020  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
00000030  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
00000040  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
00000050  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:44                 D
00000060  0d:0a:4d:41:43:20:41:64:64:72:65:73:73:20:20:20  ..MAC Address   
00000070  20:49:50:20:41:64:64:72:65:73:73:20:20:20:20:20   IP Address     
00000080  20:49:2f:46:20:20:20:20:20:20:20:20:20:20:20:4d   I/F           M
00000090  41:43:20:20:20:20:20:20:20:20:20:20:20:20:20:20  AC              
000000a0  20:50:72:69:6d:20:20:52:78:50:77:72:20:20:54:69   Prim  RxPwr  Ti
000000b0  6d:69:6e:67:20:4e:75:6d:20:49:0d:0a:20:20:20:20  ming Num I..    
000000c0  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
000000d0  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:20                  
000000e0  20:20:20:20:20:20:20:20:20:53:74:61:74:65:20:20           State  
000000f0  20:20:20:20:20:20:20:20:20:20:20:53:69:64:20:20             Sid  
00000100  20:28:64:42:6d:76:29:20:4f:66:66:73:65:74:20:43   (dBmv) Offset C
00000110  50:45:20:50:0d:0a                                PE P..

<- NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.1029, network: 0.0002s)
00000000  00:00:00:01:00:00:00:0b:65:78:69:74:2d:73:74:61  ........exit-sta
00000010  74:75:73:00:00:00:00:00                          tus.....

<- NET_SSH2_MSG_CHANNEL_EOF (since last: 0.0007, network: 0s)
00000000  00:00:00:01                                      ....

<- NET_SSH2_MSG_CHANNEL_CLOSE (since last: 0.0002, network: 0s)
00000000  00:00:00:01                                      ....

metaclassing commented 6 years ago

The reason it is hanging is likely you executing a command and getting stuck at the ---more--- prompt.

If you want to get around that and continue using the ->exec() function you will have to send multiple lines in the command such as "terminal length 0\nshow cable modem".

Alternately you can write a wrapper that uses ->read() and ->write() combined with prompt detection to interactively send and parse multiple commands in a single ssh session. I have an example at https://github.com/metaclassing/PHP7-SSHWrapper used for exactly this purpose.

dcortez commented 6 years ago

Thanks for posting your SSHWrapper example. It seems I must have been missing something and your code seems to resolve my issue.

terrafrost commented 6 years ago

So in the stacktrace we can see that the destructor is called but then when the destructor tries to send what is presumably a NET_SSH2_MSG_DISCONNECT packet but it can't because the server is closed and thus you're encountering that error.

Anyway, I think the issue is that some servers - routers in particular - just don't support multiple exec's. http://www.frostjedi.com/phpbb3/viewtopic.php?p=117471#p117471 talks about this issue some.

metaclassing's suggestion should work since I guess his lib uses approaches that may well only work on routers to kinda emulate multiple exec()'s.