Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection closed by server #1572

Open
geraudlacheny opened this issue Jan 6, 2021 · 13 comments
Open

Connection closed by server #1572

geraudlacheny opened this issue Jan 6, 2021 · 13 comments

Comments

@geraudlacheny
Copy link

I am a windows 10 user. I try to send file on a server via SFTP with username and private key (no password and no passphrase).
I try to connect the server via WinSCP and it seems all right : i have even created a directory.
But impossible to do with PHP. Here is my code :

error_reporting(E_ALL);
include 'vendor/autoload.php';
define('NET_SSH2_LOGGING', 3);
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SFTP;

$sftp = new SFTP('sftp.xxx.xxx');
$privateKey = file_get_contents('xxx.pem');
$key = PublicKeyLoader::load($privateKey);
if (!$sftp->login('xxx.xxx', $key)) {
throw new \Exception('Login failed');
}
var_dump($sftp->nlist());

I can see in the logs that after "-> NET_SSH2_MSG_USERAUTH_REQUEST", there is a "<- NET_SSH2_MSG_USERAUTH_SUCCESS", but it continues and make another request.. The result is "<- NET_SSH2_MSG_UNIMPLEMENTED" and finally "-> NET_SSH2_MSG_DISCONNECT".
Do you have an idea about the scope of the problem ?
Thanks for your help.

@terrafrost
Copy link
Member

Can you post the full logs instead of just snippets from them?

Thanks!

@geraudlacheny
Copy link
Author

geraudlacheny commented Jan 7, 2021

No problem :

<-
00000000  53:53:48:2d:32:2e:30:2d:54:77:69:73:74:65:64:5f  SSH-2.0-Twisted_
00000010  31:39:2e:31:30:2e:30:72:63:31:0d:0a              19.10.0rc1..

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

-> NET_SSH2_MSG_KEXINIT (since last: 0.1315, network: 0.0002s)
00000000  4a:d0:2f:9b:07:cc:25:54:d2:74:81:92:b9:f3:6d:43  J./...%T.t....mC
00000010  00:00:01:7c:63:75:72:76:65:32:35:35:31:39:2d:73  ...|curve25519-s
00000020  68:61:32:35:36:2c:63:75:72:76:65:32:35:35:31:39  ha256,curve25519
00000030  2d:73:68:61:32:35:36:40:6c:69:62:73:73:68:2e:6f  -sha256@libssh.o
00000040  72:67:2c:65:63:64:68:2d:73:68:61:32:2d:6e:69:73  rg,ecdh-sha2-nis
00000050  74:70:32:35:36:2c:65:63:64:68:2d:73:68:61:32:2d  tp256,ecdh-sha2-
00000060  6e:69:73:74:70:33:38:34:2c:65:63:64:68:2d:73:68  nistp384,ecdh-sh
00000070  61:32:2d:6e:69:73:74:70:35:32:31:2c:64:69:66:66  a2-nistp521,diff
00000080  69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70  ie-hellman-group
00000090  2d:65:78:63:68:61:6e:67:65:2d:73:68:61:32:35:36  -exchange-sha256
000000a0  2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d  ,diffie-hellman-
000000b0  67:72:6f:75:70:2d:65:78:63:68:61:6e:67:65:2d:73  group-exchange-s
000000c0  68:61:31:2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ha1,diffie-hellm
000000d0  61:6e:2d:67:72:6f:75:70:31:34:2d:73:68:61:32:35  an-group14-sha25
000000e0  36:2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e  6,diffie-hellman
000000f0  2d:67:72:6f:75:70:31:34:2d:73:68:61:31:2c:64:69  -group14-sha1,di
00000100  66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f  ffie-hellman-gro
00000110  75:70:31:35:2d:73:68:61:35:31:32:2c:64:69:66:66  up15-sha512,diff
00000120  69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70  ie-hellman-group
00000130  31:36:2d:73:68:61:35:31:32:2c:64:69:66:66:69:65  16-sha512,diffie
00000140  2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:31:37  -hellman-group17
00000150  2d:73:68:61:35:31:32:2c:64:69:66:66:69:65:2d:68  -sha512,diffie-h
00000160  65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:31:38:2d:73  ellman-group18-s
00000170  68:61:35:31:32:2c:64:69:66:66:69:65:2d:68:65:6c  ha512,diffie-hel
00000180  6c:6d:61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31  lman-group1-sha1
00000190  00:00:00:71:73:73:68:2d:65:64:32:35:35:31:39:2c  ...qssh-ed25519,
000001a0  65:63:64:73:61:2d:73:68:61:32:2d:6e:69:73:74:70  ecdsa-sha2-nistp
000001b0  32:35:36:2c:65:63:64:73:61:2d:73:68:61:32:2d:6e  256,ecdsa-sha2-n
000001c0  69:73:74:70:33:38:34:2c:65:63:64:73:61:2d:73:68  istp384,ecdsa-sh
000001d0  61:32:2d:6e:69:73:74:70:35:32:31:2c:72:73:61:2d  a2-nistp521,rsa-
000001e0  73:68:61:32:2d:32:35:36:2c:72:73:61:2d:73:68:61  sha2-256,rsa-sha
000001f0  32:2d:35:31:32:2c:73:73:68:2d:72:73:61:2c:73:73  2-512,ssh-rsa,ss
00000200  68:2d:64:73:73:00:00:01:01:61:65:73:31:32:38:2d  h-dss....aes128-
00000210  67:63:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c  gcm@openssh.com,
00000220  61:65:73:32:35:36:2d:67:63:6d:40:6f:70:65:6e:73  aes256-gcm@opens
00000230  73:68:2e:63:6f:6d:2c:61:65:73:31:32:38:2d:63:74  sh.com,aes128-ct
00000240  72:2c:61:65:73:31:39:32:2d:63:74:72:2c:61:65:73  r,aes192-ctr,aes
00000250  32:35:36:2d:63:74:72:2c:61:65:73:31:32:38:2d:63  256-ctr,aes128-c
00000260  62:63:2c:61:65:73:31:39:32:2d:63:62:63:2c:61:65  bc,aes192-cbc,ae
00000270  73:32:35:36:2d:63:62:63:2c:62:6c:6f:77:66:69:73  s256-cbc,blowfis
00000280  68:2d:63:74:72:2c:62:6c:6f:77:66:69:73:68:2d:63  h-ctr,blowfish-c
00000290  62:63:2c:33:64:65:73:2d:63:74:72:2c:33:64:65:73  bc,3des-ctr,3des
000002a0  2d:63:62:63:2c:74:77:6f:66:69:73:68:31:32:38:2d  -cbc,twofish128-
000002b0  63:74:72:2c:74:77:6f:66:69:73:68:31:39:32:2d:63  ctr,twofish192-c
000002c0  74:72:2c:74:77:6f:66:69:73:68:32:35:36:2d:63:74  tr,twofish256-ct
000002d0  72:2c:74:77:6f:66:69:73:68:31:32:38:2d:63:62:63  r,twofish128-cbc
000002e0  2c:74:77:6f:66:69:73:68:31:39:32:2d:63:62:63:2c  ,twofish192-cbc,
000002f0  74:77:6f:66:69:73:68:32:35:36:2d:63:62:63:2c:74  twofish256-cbc,t
00000300  77:6f:66:69:73:68:2d:63:62:63:00:00:01:01:61:65  wofish-cbc....ae
00000310  73:31:32:38:2d:67:63:6d:40:6f:70:65:6e:73:73:68  s128-gcm@openssh
00000320  2e:63:6f:6d:2c:61:65:73:32:35:36:2d:67:63:6d:40  .com,aes256-gcm@
00000330  6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:61:65:73:31  openssh.com,aes1
00000340  32:38:2d:63:74:72:2c:61:65:73:31:39:32:2d:63:74  28-ctr,aes192-ct
00000350  72:2c:61:65:73:32:35:36:2d:63:74:72:2c:61:65:73  r,aes256-ctr,aes
00000360  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
00000370  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:62:6c  bc,aes256-cbc,bl
00000380  6f:77:66:69:73:68:2d:63:74:72:2c:62:6c:6f:77:66  owfish-ctr,blowf
00000390  69:73:68:2d:63:62:63:2c:33:64:65:73:2d:63:74:72  ish-cbc,3des-ctr
000003a0  2c:33:64:65:73:2d:63:62:63:2c:74:77:6f:66:69:73  ,3des-cbc,twofis
000003b0  68:31:32:38:2d:63:74:72:2c:74:77:6f:66:69:73:68  h128-ctr,twofish
000003c0  31:39:32:2d:63:74:72:2c:74:77:6f:66:69:73:68:32  192-ctr,twofish2
000003d0  35:36:2d:63:74:72:2c:74:77:6f:66:69:73:68:31:32  56-ctr,twofish12
000003e0  38:2d:63:62:63:2c:74:77:6f:66:69:73:68:31:39:32  8-cbc,twofish192
000003f0  2d:63:62:63:2c:74:77:6f:66:69:73:68:32:35:36:2d  -cbc,twofish256-
00000400  63:62:63:2c:74:77:6f:66:69:73:68:2d:63:62:63:00  cbc,twofish-cbc.
00000410  00:00:f7:68:6d:61:63:2d:73:68:61:32:2d:32:35:36  ...hmac-sha2-256
00000420  2d:65:74:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d  -etm@openssh.com
00000430  2c:68:6d:61:63:2d:73:68:61:32:2d:35:31:32:2d:65  ,hmac-sha2-512-e
00000440  74:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:75  tm@openssh.com,u
00000450  6d:61:63:2d:36:34:2d:65:74:6d:40:6f:70:65:6e:73  mac-64-etm@opens
00000460  73:68:2e:63:6f:6d:2c:75:6d:61:63:2d:31:32:38:2d  sh.com,umac-128-
00000470  65:74:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c  etm@openssh.com,
00000480  68:6d:61:63:2d:73:68:61:31:2d:65:74:6d:40:6f:70  hmac-sha1-etm@op
00000490  65:6e:73:73:68:2e:63:6f:6d:2c:68:6d:61:63:2d:73  enssh.com,hmac-s
000004a0  68:61:32:2d:32:35:36:2c:68:6d:61:63:2d:73:68:61  ha2-256,hmac-sha
000004b0  32:2d:35:31:32:2c:75:6d:61:63:2d:36:34:40:6f:70  2-512,umac-64@op
000004c0  65:6e:73:73:68:2e:63:6f:6d:2c:75:6d:61:63:2d:31  enssh.com,umac-1
000004d0  32:38:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:68  28@openssh.com,h
000004e0  6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d:61:63  mac-sha1-96,hmac
000004f0  2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64:35:2d:39  -sha1,hmac-md5-9
00000500  36:2c:68:6d:61:63:2d:6d:64:35:00:00:00:f7:68:6d  6,hmac-md5....hm
00000510  61:63:2d:73:68:61:32:2d:32:35:36:2d:65:74:6d:40  ac-sha2-256-etm@
00000520  6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:68:6d:61:63  openssh.com,hmac
00000530  2d:73:68:61:32:2d:35:31:32:2d:65:74:6d:40:6f:70  -sha2-512-etm@op
00000540  65:6e:73:73:68:2e:63:6f:6d:2c:75:6d:61:63:2d:36  enssh.com,umac-6
00000550  34:2d:65:74:6d:40:6f:70:65:6e:73:73:68:2e:63:6f  4-etm@openssh.co
00000560  6d:2c:75:6d:61:63:2d:31:32:38:2d:65:74:6d:40:6f  m,umac-128-etm@o
00000570  70:65:6e:73:73:68:2e:63:6f:6d:2c:68:6d:61:63:2d  penssh.com,hmac-
00000580  73:68:61:31:2d:65:74:6d:40:6f:70:65:6e:73:73:68  sha1-etm@openssh
00000590  2e:63:6f:6d:2c:68:6d:61:63:2d:73:68:61:32:2d:32  .com,hmac-sha2-2
000005a0  35:36:2c:68:6d:61:63:2d:73:68:61:32:2d:35:31:32  56,hmac-sha2-512
000005b0  2c:75:6d:61:63:2d:36:34:40:6f:70:65:6e:73:73:68  ,umac-64@openssh
000005c0  2e:63:6f:6d:2c:75:6d:61:63:2d:31:32:38:40:6f:70  .com,umac-128@op
000005d0  65:6e:73:73:68:2e:63:6f:6d:2c:68:6d:61:63:2d:73  enssh.com,hmac-s
000005e0  68:61:31:2d:39:36:2c:68:6d:61:63:2d:73:68:61:31  ha1-96,hmac-sha1
000005f0  2c:68:6d:61:63:2d:6d:64:35:2d:39:36:2c:68:6d:61  ,hmac-md5-96,hma
00000600  63:2d:6d:64:35:00:00:00:04:6e:6f:6e:65:00:00:00  c-md5....none...
00000610  04:6e:6f:6e:65:00:00:00:00:00:00:00:00:00:00:00  .none...........
00000620  00:00                                            ..

<- NET_SSH2_MSG_KEXINIT (since last: 0.0127, network: 0.0002s)
00000000  18:e2:e0:9c:48:6a:9b:05:6a:77:3f:f0:c8:c9:f9:d2  ....Hj..jw?.....
00000010  00:00:00:54:65:63:64:68:2d:73:68:61:32:2d:6e:69  ...Tecdh-sha2-ni
00000020  73:74:70:32:35:36:2c:65:63:64:68:2d:73:68:61:32  stp256,ecdh-sha2
00000030  2d:6e:69:73:74:70:33:38:34:2c:65:63:64:68:2d:73  -nistp384,ecdh-s
00000040  68:61:32:2d:6e:69:73:74:70:35:32:31:2c:64:69:66  ha2-nistp521,dif
00000050  66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75  fie-hellman-grou
00000060  70:31:34:2d:73:68:61:31:00:00:00:07:73:73:68:2d  p14-sha1....ssh-
00000070  72:73:61:00:00:00:63:61:65:73:32:35:36:2d:63:74  rsa...caes256-ct
00000080  72:2c:61:65:73:32:35:36:2d:63:62:63:2c:61:65:73  r,aes256-cbc,aes
00000090  31:39:32:2d:63:74:72:2c:61:65:73:31:39:32:2d:63  192-ctr,aes192-c
000000a0  62:63:2c:61:65:73:31:32:38:2d:63:74:72:2c:61:65  bc,aes128-ctr,ae
000000b0  73:31:32:38:2d:63:62:63:2c:63:61:73:74:31:32:38  s128-cbc,cast128
000000c0  2d:63:62:63:2c:62:6c:6f:77:66:69:73:68:2d:63:62  -cbc,blowfish-cb
000000d0  63:2c:33:64:65:73:2d:63:62:63:00:00:00:63:61:65  c,3des-cbc...cae
000000e0  73:32:35:36:2d:63:74:72:2c:61:65:73:32:35:36:2d  s256-ctr,aes256-
000000f0  63:62:63:2c:61:65:73:31:39:32:2d:63:74:72:2c:61  cbc,aes192-ctr,a
00000100  65:73:31:39:32:2d:63:62:63:2c:61:65:73:31:32:38  es192-cbc,aes128
00000110  2d:63:74:72:2c:61:65:73:31:32:38:2d:63:62:63:2c  -ctr,aes128-cbc,
00000120  63:61:73:74:31:32:38:2d:63:62:63:2c:62:6c:6f:77  cast128-cbc,blow
00000130  66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d:63:62  fish-cbc,3des-cb
00000140  63:00:00:00:3c:68:6d:61:63:2d:73:68:61:32:2d:35  c....hmac-sha2-5
00000150  31:32:2c:68:6d:61:63:2d:73:68:61:32:2d:33:38:34  12,hmac-sha2-384
00000160  2c:68:6d:61:63:2d:73:68:61:32:2d:32:35:36:2c:68  ,hmac-sha2-256,h
00000170  6d:61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64  mac-sha1,hmac-md
00000180  35:00:00:00:3c:68:6d:61:63:2d:73:68:61:32:2d:35  5....hmac-sha2-5
00000190  31:32:2c:68:6d:61:63:2d:73:68:61:32:2d:33:38:34  12,hmac-sha2-384
000001a0  2c:68:6d:61:63:2d:73:68:61:32:2d:32:35:36:2c:68  ,hmac-sha2-256,h
000001b0  6d:61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64  mac-sha1,hmac-md
000001c0  35:00:00:00:09:6e:6f:6e:65:2c:7a:6c:69:62:00:00  5....none,zlib..
000001d0  00:09:6e:6f:6e:65:2c:7a:6c:69:62:00:00:00:00:00  ..none,zlib.....
000001e0  00:00:00:00:00:00:00:00                          ........

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.3494, network: 0.0002s)
00000000  00:00:00:41:04:4f:18:98:3a:dc:f1:21:a0:78:e8:db  ...A.O..:..!.x..
00000010  08:27:df:87:77:0e:13:60:6c:5c:7b:10:50:a1:39:3b  .'..w..`l\{.P.9;
00000020  bd:37:4b:85:41:7f:e7:3a:bc:1a:f2:47:44:59:75:ac  .7K.A..:...GDYu.
00000030  28:9e:f8:dc:62:49:91:89:df:66:bf:78:ed:f9:2b:52  (...bI...f.x..+R
00000040  2f:61:9b:1e:dc                                   /a...

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 0.0225, network: 0.0218s)
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:ab:7d:ca:fd:89  ............}...
00000020  85:58:8f:34:df:16:31:26:3f:72:7f:4d:7d:b8:be:b2  .X.4..1&?r.M}...
00000030  af:11:4d:12:96:8d:e6:b4:38:6b:85:cd:0e:f2:9d:00  ..M.....8k......
00000040  a3:23:d3:94:24:1b:ad:a9:0d:5e:2f:62:ea:8a:a8:58  .#..$....^/b...X
00000050  89:a4:bf:64:70:9f:3c:38:98:43:00:7a:d8:e2:49:88  ...dp..8.C.z..I.
00000060  d2:3b:16:64:dd:80:85:45:c6:60:2f:3d:00:72:c0:10  .;.d...E.`/=.r..
00000070  9e:26:0f:24:b6:0d:83:81:06:20:23:f9:c9:4a:55:11  .&.$..... #..JU.
00000080  4e:b0:2a:10:bc:4a:47:8d:a8:e0:5c:9b:68:04:87:e4  N.*..JG...\.h...
00000090  75:9a:10:19:b4:e9:f3:41:21:52:43:a7:8f:07:48:99  u......A!RC...H.
000000a0  12:5b:4e:1e:68:a3:6b:82:bb:f2:3e:41:9d:54:0b:1a  .[N.h.k...>A.T..
000000b0  aa:d4:17:e0:1b:bc:ad:af:44:d5:3c:39:a6:97:1a:5b  ........D..9...[
000000c0  be:44:71:40:86:2c:fc:c7:74:0a:10:0a:2a:b3:0c:66  .Dq@.,..t...*..f
000000d0  12:16:6c:b9:28:05:47:fd:18:62:8f:db:c1:db:1d:19  ..l.(.G..b......
000000e0  2e:81:d7:aa:f0:4e:03:d6:e6:0e:a2:d5:3e:1a:97:fa  .....N......>...
000000f0  32:cc:a8:43:3a:6a:1f:1f:3b:6d:8d:79:d1:4e:eb:ef  2..C:j..;m.y.N..
00000100  ae:b0:ca:9d:69:bd:5a:6e:ed:ba:27:de:a3:d5:b0:de  ....i.Zn..'.....
00000110  37:d6:40:6e:ce:9d:37:fe:79:a6:ad:00:00:00:41:04  7.@n..7.y.....A.
00000120  11:2e:c3:75:49:1a:5e:f5:41:94:39:21:bf:4c:ad:15  ...uI.^.A.9!.L..
00000130  a0:6c:29:f6:f4:ac:75:d9:04:7f:16:67:0d:74:db:84  .l)...u....g.t..
00000140  34:63:f8:61:87:78:83:58:e8:27:e1:95:ea:67:be:80  4c.a.x.X.'...g..
00000150  cf:94:9d:7c:b3:fb:3c:7a:6f:3c:53:e7:3f:be:9a:af  ...|...zo.S.?...
00000160  00:00:01:0f:00:00:00:07:73:73:68:2d:72:73:61:00  ........ssh-rsa.
00000170  00:01:00:3d:11:6a:55:27:4d:c1:6f:f6:c7:6c:a5:23  ...=.jU'M.o..l.#
00000180  78:c0:94:6e:15:2c:16:79:19:1c:8e:89:22:bf:32:db  x..n.,.y....".2.
00000190  f9:a7:47:1c:71:3f:63:50:62:6f:9d:38:ff:56:99:c5  ..G.q?cPbo.8.V..
000001a0  c6:bb:31:23:75:8f:d6:51:ae:1f:08:c6:88:cb:d1:d3  ..1#u..Q........
000001b0  07:7e:4d:c2:2d:a3:ed:b8:92:d7:36:e5:52:91:ad:3b  .~M.-.....6.R..;
000001c0  96:15:8c:10:63:20:1d:50:1e:bd:09:ea:da:6e:ff:94  ....c .P.....n..
000001d0  a3:fb:c8:4e:3b:bc:2f:27:d9:93:09:44:14:5e:89:20  ...N;./'...D.^. 
000001e0  05:ab:ce:31:4e:0f:39:af:80:04:7a:e3:a2:e8:2c:da  ...1N.9...z...,.
000001f0  30:e1:05:8c:e8:cf:1c:5f:44:4a:95:69:ad:1f:62:50  0......_DJ.i..bP
00000200  30:35:d0:f2:80:ff:d1:9a:38:e0:bc:a7:b1:f0:b6:39  05......8......9
00000210  7f:1b:b0:8a:17:0f:fe:7c:17:2c:46:fc:41:68:16:a3  .......|.,F.Ah..
00000220  eb:c1:e9:b0:5a:15:04:50:85:42:05:6e:96:62:30:1f  ....Z..P.B.n.b0.
00000230  55:52:65:a9:cf:d0:e9:8d:ac:ce:2a:cc:4a:dd:f8:48  URe.......*.J..H
00000240  f2:ad:06:14:d8:48:80:b5:1e:47:4d:d5:99:f3:69:ac  .....H...GM...i.
00000250  09:cf:49:75:b6:d5:ac:6a:47:9c:2a:1e:fc:c9:8f:ba  ..Iu...jG.*.....
00000260  6c:af:3b:6a:68:5a:1b:1f:75:36:c3:c8:16:8c:09:57  l.;jhZ..u6.....W
00000270  be:c3:1b                                         ...

-> NET_SSH2_MSG_NEWKEYS (since last: 0.3493, network: 0.0003s)
                                                 

<- NET_SSH2_MSG_NEWKEYS (since last: 0.0002, network: 0.0001s)
                                                 

-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0009, 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.0814, network: 0.0811s)
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.0004, network: 0.0001s)
00000000  00:00:00:13:64:6f:6d:69:6e:69:71:75:65:2e:64:75  ....xxxxxxxxx.yy
00000010  63:6f:75:72:6e:61:75:00:00:00:0e:73:73:68:2d:63  yyyyyyy....ssh-c
00000020  6f:6e:6e:65:63:74:69:6f:6e:00:00:00:04:6e:6f:6e  onnection....non
00000030  65                                               e

<- NET_SSH2_MSG_USERAUTH_FAILURE (since last: 0.0216, network: 0.0212s)
00000000  00:00:00:12:70:61:73:73:77:6f:72:64:2c:70:75:62  ....password,pub
00000010  6c:69:63:6b:65:79:00                             lickey.

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0101, network: 0.0001s)
00000000  00:00:00:13:64:6f:6d:69:6e:69:71:75:65:2e:64:75  ....xxxxxxxxx.yy
00000010  63:6f:75:72:6e:61:75:00:00:00:0e:73:73:68:2d:63  yyyyyyy....ssh-c
00000020  6f:6e:6e:65:63:74:69:6f:6e:00:00:00:09:70:75:62  onnection....pub
00000030  6c:69:63:6b:65:79:00:00:00:00:07:73:73:68:2d:72  lickey.....ssh-r
00000040  73:61:00:00:01:17:00:00:00:07:73:73:68:2d:72:73  sa........ssh-rs
00000050  61:00:00:00:03:01:00:01:00:00:01:01:00:b2:ef:79  a..............y
00000060  30:4d:91:16:2b:31:d3:8a:cf:fd:95:d6:55:be:eb:34  0M..+1......U..4
00000070  b1:3e:1c:a3:62:81:62:5d:f5:b1:52:17:25:c0:0e:db  .>..b.b]..R.%...
00000080  c3:88:e9:53:85:7d:c5:89:7e:04:f2:65:f2:0b:41:64  ...S.}..~..e..Ad
00000090  b1:0f:32:05:58:d4:2a:b3:1e:df:44:5e:b5:08:e0:b4  ..2.X.*...D^....
000000a0  ae:9e:8d:41:11:71:c5:a6:2f:78:66:71:4a:1c:15:ad  ...A.q../xfqJ...
000000b0  46:d1:ff:e6:2a:7c:1b:4c:e4:21:c6:49:3d:e3:08:79  F...*|.L.!.I=..y
000000c0  b9:37:e6:a0:e1:c1:cd:8f:de:0c:81:b5:d9:55:a8:df  .7...........U..
000000d0  88:e2:ba:96:7a:c5:6b:82:9f:8c:3c:7d:c3:36:f7:a7  ....z.k....}.6..
000000e0  c4:e2:a3:a7:bf:c6:b3:b8:3b:bf:08:d1:81:8b:36:4f  ........;.....6O
000000f0  bd:14:19:fe:a1:50:5d:1e:76:ff:77:5e:43:83:8b:2e  .....P].v.w^C...
00000100  b2:94:52:c1:99:ce:da:d0:da:0a:f9:d4:64:d9:66:39  ..R.........d.f9
00000110  69:d3:db:58:ac:ea:10:76:e1:1d:42:c4:e6:52:03:7f  i..X...v..B..R..
00000120  bb:5d:b0:1e:16:c9:ff:62:ed:84:ed:4c:66:d5:93:66  .].....b...Lf..f
00000130  1e:8a:28:65:ce:c0:6b:f8:8c:47:60:4e:e2:2a:c5:5c  ..(e..k..G`N.*.\
00000140  d0:45:a0:77:09:3f:f6:c5:3a:52:2d:fb:20:f4:43:03  .E.w.?..:R-. .C.
00000150  88:73:85:10:47:f3:c5:e3:76:ee:b0:fc:cb           .s..G...v....

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 1.5922, network: 1.5904s)
                                                 

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0057, network: 0.0001s)
00000000  00:00:00:13:64:6f:6d:69:6e:69:71:75:65:2e:64:75  ....xxxxxxxxx.yy
00000010  63:6f:75:72:6e:61:75:00:00:00:0e:73:73:68:2d:63  yyyyyyy....ssh-c
00000020  6f:6e:6e:65:63:74:69:6f:6e:00:00:00:09:70:75:62  onnection....pub
00000030  6c:69:63:6b:65:79:01:00:00:00:07:73:73:68:2d:72  lickey.....ssh-r
00000040  73:61:00:00:01:17:00:00:00:07:73:73:68:2d:72:73  sa........ssh-rs
00000050  61:00:00:00:03:01:00:01:00:00:01:01:00:b2:ef:79  a..............y
00000060  30:4d:91:16:2b:31:d3:8a:cf:fd:95:d6:55:be:eb:34  0M..+1......U..4
00000070  b1:3e:1c:a3:62:81:62:5d:f5:b1:52:17:25:c0:0e:db  .>..b.b]..R.%...
00000080  c3:88:e9:53:85:7d:c5:89:7e:04:f2:65:f2:0b:41:64  ...S.}..~..e..Ad
00000090  b1:0f:32:05:58:d4:2a:b3:1e:df:44:5e:b5:08:e0:b4  ..2.X.*...D^....
000000a0  ae:9e:8d:41:11:71:c5:a6:2f:78:66:71:4a:1c:15:ad  ...A.q../xfqJ...
000000b0  46:d1:ff:e6:2a:7c:1b:4c:e4:21:c6:49:3d:e3:08:79  F...*|.L.!.I=..y
000000c0  b9:37:e6:a0:e1:c1:cd:8f:de:0c:81:b5:d9:55:a8:df  .7...........U..
000000d0  88:e2:ba:96:7a:c5:6b:82:9f:8c:3c:7d:c3:36:f7:a7  ....z.k....}.6..
000000e0  c4:e2:a3:a7:bf:c6:b3:b8:3b:bf:08:d1:81:8b:36:4f  ........;.....6O
000000f0  bd:14:19:fe:a1:50:5d:1e:76:ff:77:5e:43:83:8b:2e  .....P].v.w^C...
00000100  b2:94:52:c1:99:ce:da:d0:da:0a:f9:d4:64:d9:66:39  ..R.........d.f9
00000110  69:d3:db:58:ac:ea:10:76:e1:1d:42:c4:e6:52:03:7f  i..X...v..B..R..
00000120  bb:5d:b0:1e:16:c9:ff:62:ed:84:ed:4c:66:d5:93:66  .].....b...Lf..f
00000130  1e:8a:28:65:ce:c0:6b:f8:8c:47:60:4e:e2:2a:c5:5c  ..(e..k..G`N.*.\
00000140  d0:45:a0:77:09:3f:f6:c5:3a:52:2d:fb:20:f4:43:03  .E.w.?..:R-. .C.
00000150  88:73:85:10:47:f3:c5:e3:76:ee:b0:fc:cb:00:00:01  .s..G...v.......
00000160  0f:00:00:00:07:73:73:68:2d:72:73:61:00:00:01:00  .....ssh-rsa....
00000170  78:ec:1b:94:9c:72:9d:ce:df:b7:3e:ce:b2:bb:08:09  x....r....>.....
00000180  ae:79:c3:2d:34:c8:0b:85:8b:53:71:4e:b3:d3:dc:ab  .y.-4....SqN....
00000190  f7:90:00:fc:7c:f2:f0:dd:61:97:d7:73:6f:ce:15:35  ....|...a..so..5
000001a0  08:6a:d5:fc:bd:f9:d9:f4:07:3c:61:58:23:ef:cc:5b  .j........aX#..[
000001b0  04:a5:b0:27:5e:d4:f2:21:c7:e9:f0:01:82:98:95:4c  ...'^..!.......L
000001c0  19:f2:f1:ea:f4:7d:09:48:5e:25:11:30:ab:84:a7:a1  .....}.H^%.0....
000001d0  8e:5f:4a:1d:1c:c1:a2:d9:eb:ff:19:bb:cf:a6:6f:ae  ._J...........o.
000001e0  ca:ac:c2:2d:89:2c:da:24:5f:de:57:36:e9:a6:9f:10  ...-.,.$_.W6....
000001f0  87:d6:22:f4:64:45:fd:61:bb:95:bf:0c:57:4c:50:31  ..".dE.a....WLP1
00000200  37:ca:6d:ea:47:ea:bc:58:9d:c4:07:ac:f4:0e:a0:6b  7.m.G..X.......k
00000210  91:cd:62:a6:75:18:87:4a:c1:46:e9:2a:6b:93:ca:88  ..b.u..J.F.*k...
00000220  3a:d8:22:a9:a5:bb:84:bc:39:20:0c:7f:c5:eb:b2:da  :.".....9 ......
00000230  78:7b:77:56:4b:f1:8f:a2:91:0e:0c:98:19:b5:b4:ce  x{wVK...........
00000240  aa:31:01:6f:2d:82:24:a8:6f:26:3f:14:91:2d:e6:a8  .1.o-.$.o&?..-..
00000250  03:3b:6d:39:2d:99:ea:e6:d7:e4:1b:2a:aa:e9:a8:d8  .;m9-......*....
00000260  ea:9f:aa:14:2e:bf:c8:96:ff:d6:14:c7:a5:dc:bf:ef  ................

<- NET_SSH2_MSG_UNIMPLEMENTED (since last: 0.0208, network: 0.0176s)
00000000  00:00:00:07                                      ....

-> NET_SSH2_MSG_DISCONNECT (since last: 0.0003, network: 0.0001s)
00000000  00:00:00:0a:00:00:00:00:00:00:00:00              ............

@terrafrost
Copy link
Member

I'm actually thinking this is a bug in the server tbh.

You're using https://twistedmatrix.com/documents/current/conch/examples/ ? If so can you share the code you're using for the SSH server? If it looks like it should work but isn't I can submit a bug report to them!

@geraudlacheny
Copy link
Author

The thing is that I have to send a file from my server (Server A) to an external server (server B) I don't manage.
What do you mean by "this is a bug in the server" ? Server a or Server B ?

@terrafrost
Copy link
Member

The thing is that I have to send a file from my server (Server A) to an external server (server B) I don't manage.
What do you mean by "this is a bug in the server" ? Server a or Server B ?

Since I guess you're running phpseclib on server A then, from phpseclib's perspective, the only server is server B. So it'd be server B - the server you don't control - that'd be the issue.

My guess is that you couldn't even connect to the server using PuTTY / RSA authentication or OpenSSH / RSA authentication. If true then that would be even stronger evidence that it's a bug on their end. If you can connect using PuTTY (in particular), using RSA authentication, then the next step would be to get me logs of what PuTTY is doing so I can compare what PuTTY is doing to what phpseclib is doing. I can walk you through how to do that if PuTTY does indeed work (don't want to overwhelm you with too much info in one post lol).

Thanks!

@geraudlacheny
Copy link
Author

geraudlacheny commented Jan 8, 2021

Indeed, lots of information ;)

I've tried to deal with the dev team which manage SSH connection. They told me that the SSH connection is doing well. They tried with Python with the following code :

# sudo pip install pysftp
import pysftp
with pysftp.Connection(host = 'sftp.xxxx.yyy', username='xxx', private_key = 'yyy.key') as sftp_c
on:
    print('Connection successfull')
    with sftp_con.cd('/mnt'):
        data=sftp_con.listdir()
print(data)

and the response was :

$ python test_sftp.py
Connection successfull
['aaa', 'bbb', 'ccc', 'ddd', 'eee']

So the connexion is successful and the directories are listed.. But with Python, I suppose that it is out of scope... unless if it gives you unexpected clue ?

Thanks

@terrafrost
Copy link
Member

terrafrost commented Jan 9, 2021

That is not a very helpful response. I'd rather know if PuTTY can connect. If so then logs could be generated by going to Session -> Logging and setting "Session logging" to "SSH packets".

Besides, PuTTY and OpenSSH are much more industry standards than pysftp. If neither of those can connect then it's immaterial if pysftp can connect.

Having to install https://twistedmatrix.com/documents/current/conch/examples/ myself, in lieu of being able to get the PuTTY SSH logs from you, is going to slow things down. None-the-less, I did try. I did pip install twisted and it seemed to install. https://twistedmatrix.com/documents/current/conch/examples/index.html has a sample SSH server so I got that script and tried to run it. But wait, per that script, I need to run ckeygen. I guess that's a CLI tool that comes with twisted. idk how to run it tho. It's not a command that's available to me on the CLI. Maybe I could do python ckeygen.py and run it from whatever directory it was installed to but I'm not a python expert by any stretch of the imagination...

@terrafrost
Copy link
Member

Looking at their sample SSH server code it doesn't even look like that provides SFTP functionality. So yah I'm going to need the PuTTY SSH logs to effectively diagnose the issue.

Thanks!

@geraudlacheny
Copy link
Author

geraudlacheny commented Jan 11, 2021

Here is the content of putty.log parametered as mentionned

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2021.01.11 10:51:01 =~=~=~=~=~=~=~=~=~=~=~=
Event Log: Writing new session log (SSH packets mode) to file: putty.log
Event Log: Connecting to 185.74.203.3 port 22
Event Log: We claim version: SSH-2.0-PuTTY_Release_0.70
Event Log: Server version: SSH-2.0-Twisted_19.10.0rc1
Event Log: Using SSH protocol version 2
Outgoing packet #0x0, type 20 / 0x14 (SSH2_MSG_KEXINIT)
  00000000  a0 00 ac 2e f7 c4 0f 62 8e 92 c3 da a1 05 9c a0  .......b........
  00000010  00 00 00 f0 63 75 72 76 65 32 35 35 31 39 2d 73  ....curve25519-s
  00000020  68 61 32 35 36 40 6c 69 62 73 73 68 2e 6f 72 67  ha256@libssh.org
  00000030  2c 65 63 64 68 2d 73 68 61 32 2d 6e 69 73 74 70  ,ecdh-sha2-nistp
  00000040  32 35 36 2c 65 63 64 68 2d 73 68 61 32 2d 6e 69  256,ecdh-sha2-ni
  00000050  73 74 70 33 38 34 2c 65 63 64 68 2d 73 68 61 32  stp384,ecdh-sha2
  00000060  2d 6e 69 73 74 70 35 32 31 2c 64 69 66 66 69 65  -nistp521,diffie
  00000070  2d 68 65 6c 6c 6d 61 6e 2d 67 72 6f 75 70 2d 65  -hellman-group-e
  00000080  78 63 68 61 6e 67 65 2d 73 68 61 32 35 36 2c 64  xchange-sha256,d
  00000090  69 66 66 69 65 2d 68 65 6c 6c 6d 61 6e 2d 67 72  iffie-hellman-gr
  000000a0  6f 75 70 2d 65 78 63 68 61 6e 67 65 2d 73 68 61  oup-exchange-sha
  000000b0  31 2c 64 69 66 66 69 65 2d 68 65 6c 6c 6d 61 6e  1,diffie-hellman
  000000c0  2d 67 72 6f 75 70 31 34 2d 73 68 61 31 2c 72 73  -group14-sha1,rs
  000000d0  61 32 30 34 38 2d 73 68 61 32 35 36 2c 72 73 61  a2048-sha256,rsa
  000000e0  31 30 32 34 2d 73 68 61 31 2c 64 69 66 66 69 65  1024-sha1,diffie
  000000f0  2d 68 65 6c 6c 6d 61 6e 2d 67 72 6f 75 70 31 2d  -hellman-group1-
  00000100  73 68 61 31 00 00 00 57 73 73 68 2d 72 73 61 2c  sha1...Wssh-rsa,
  00000110  73 73 68 2d 65 64 32 35 35 31 39 2c 65 63 64 73  ssh-ed25519,ecds
  00000120  61 2d 73 68 61 32 2d 6e 69 73 74 70 32 35 36 2c  a-sha2-nistp256,
  00000130  65 63 64 73 61 2d 73 68 61 32 2d 6e 69 73 74 70  ecdsa-sha2-nistp
  00000140  33 38 34 2c 65 63 64 73 61 2d 73 68 61 32 2d 6e  384,ecdsa-sha2-n
  00000150  69 73 74 70 35 32 31 2c 73 73 68 2d 64 73 73 00  istp521,ssh-dss.
  00000160  00 00 bd 61 65 73 32 35 36 2d 63 74 72 2c 61 65  ...aes256-ctr,ae
  00000170  73 32 35 36 2d 63 62 63 2c 72 69 6a 6e 64 61 65  s256-cbc,rijndae
  00000180  6c 2d 63 62 63 40 6c 79 73 61 74 6f 72 2e 6c 69  l-cbc@lysator.li
  00000190  75 2e 73 65 2c 61 65 73 31 39 32 2d 63 74 72 2c  u.se,aes192-ctr,
  000001a0  61 65 73 31 39 32 2d 63 62 63 2c 61 65 73 31 32  aes192-cbc,aes12
  000001b0  38 2d 63 74 72 2c 61 65 73 31 32 38 2d 63 62 63  8-ctr,aes128-cbc
  000001c0  2c 63 68 61 63 68 61 32 30 2d 70 6f 6c 79 31 33  ,chacha20-poly13
  000001d0  30 35 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 2c 62  05@openssh.com,b
  000001e0  6c 6f 77 66 69 73 68 2d 63 74 72 2c 62 6c 6f 77  lowfish-ctr,blow
  000001f0  66 69 73 68 2d 63 62 63 2c 33 64 65 73 2d 63 74  fish-cbc,3des-ct
  00000200  72 2c 33 64 65 73 2d 63 62 63 2c 61 72 63 66 6f  r,3des-cbc,arcfo
  00000210  75 72 32 35 36 2c 61 72 63 66 6f 75 72 31 32 38  ur256,arcfour128
  00000220  00 00 00 bd 61 65 73 32 35 36 2d 63 74 72 2c 61  ....aes256-ctr,a
  00000230  65 73 32 35 36 2d 63 62 63 2c 72 69 6a 6e 64 61  es256-cbc,rijnda
  00000240  65 6c 2d 63 62 63 40 6c 79 73 61 74 6f 72 2e 6c  el-cbc@lysator.l
  00000250  69 75 2e 73 65 2c 61 65 73 31 39 32 2d 63 74 72  iu.se,aes192-ctr
  00000260  2c 61 65 73 31 39 32 2d 63 62 63 2c 61 65 73 31  ,aes192-cbc,aes1
  00000270  32 38 2d 63 74 72 2c 61 65 73 31 32 38 2d 63 62  28-ctr,aes128-cb
  00000280  63 2c 63 68 61 63 68 61 32 30 2d 70 6f 6c 79 31  c,chacha20-poly1
  00000290  33 30 35 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 2c  305@openssh.com,
  000002a0  62 6c 6f 77 66 69 73 68 2d 63 74 72 2c 62 6c 6f  blowfish-ctr,blo
  000002b0  77 66 69 73 68 2d 63 62 63 2c 33 64 65 73 2d 63  wfish-cbc,3des-c
  000002c0  74 72 2c 33 64 65 73 2d 63 62 63 2c 61 72 63 66  tr,3des-cbc,arcf
  000002d0  6f 75 72 32 35 36 2c 61 72 63 66 6f 75 72 31 32  our256,arcfour12
  000002e0  38 00 00 00 9b 68 6d 61 63 2d 73 68 61 32 2d 32  8....hmac-sha2-2
  000002f0  35 36 2c 68 6d 61 63 2d 73 68 61 31 2c 68 6d 61  56,hmac-sha1,hma
  00000300  63 2d 73 68 61 31 2d 39 36 2c 68 6d 61 63 2d 6d  c-sha1-96,hmac-m
  00000310  64 35 2c 68 6d 61 63 2d 73 68 61 32 2d 32 35 36  d5,hmac-sha2-256
  00000320  2d 65 74 6d 40 6f 70 65 6e 73 73 68 2e 63 6f 6d  -etm@openssh.com
  00000330  2c 68 6d 61 63 2d 73 68 61 31 2d 65 74 6d 40 6f  ,hmac-sha1-etm@o
  00000340  70 65 6e 73 73 68 2e 63 6f 6d 2c 68 6d 61 63 2d  penssh.com,hmac-
  00000350  73 68 61 31 2d 39 36 2d 65 74 6d 40 6f 70 65 6e  sha1-96-etm@open
  00000360  73 73 68 2e 63 6f 6d 2c 68 6d 61 63 2d 6d 64 35  ssh.com,hmac-md5
  00000370  2d 65 74 6d 40 6f 70 65 6e 73 73 68 2e 63 6f 6d  -etm@openssh.com
  00000380  00 00 00 9b 68 6d 61 63 2d 73 68 61 32 2d 32 35  ....hmac-sha2-25
  00000390  36 2c 68 6d 61 63 2d 73 68 61 31 2c 68 6d 61 63  6,hmac-sha1,hmac
  000003a0  2d 73 68 61 31 2d 39 36 2c 68 6d 61 63 2d 6d 64  -sha1-96,hmac-md
  000003b0  35 2c 68 6d 61 63 2d 73 68 61 32 2d 32 35 36 2d  5,hmac-sha2-256-
  000003c0  65 74 6d 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 2c  etm@openssh.com,
  000003d0  68 6d 61 63 2d 73 68 61 31 2d 65 74 6d 40 6f 70  hmac-sha1-etm@op
  000003e0  65 6e 73 73 68 2e 63 6f 6d 2c 68 6d 61 63 2d 73  enssh.com,hmac-s
  000003f0  68 61 31 2d 39 36 2d 65 74 6d 40 6f 70 65 6e 73  ha1-96-etm@opens
  00000400  73 68 2e 63 6f 6d 2c 68 6d 61 63 2d 6d 64 35 2d  sh.com,hmac-md5-
  00000410  65 74 6d 40 6f 70 65 6e 73 73 68 2e 63 6f 6d 00  etm@openssh.com.
  00000420  00 00 09 6e 6f 6e 65 2c 7a 6c 69 62 00 00 00 09  ...none,zlib....
  00000430  6e 6f 6e 65 2c 7a 6c 69 62 00 00 00 00 00 00 00  none,zlib.......
  00000440  00 00 00 00 00 00                                ......
Incoming packet #0x0, type 20 / 0x14 (SSH2_MSG_KEXINIT)
  00000000  17 01 d3 6b 25 70 57 c5 fe 09 a5 db c9 e7 ec 90  ...k%pW.........
  00000010  00 00 00 54 65 63 64 68 2d 73 68 61 32 2d 6e 69  ...Tecdh-sha2-ni
  00000020  73 74 70 32 35 36 2c 65 63 64 68 2d 73 68 61 32  stp256,ecdh-sha2
  00000030  2d 6e 69 73 74 70 33 38 34 2c 65 63 64 68 2d 73  -nistp384,ecdh-s
  00000040  68 61 32 2d 6e 69 73 74 70 35 32 31 2c 64 69 66  ha2-nistp521,dif
  00000050  66 69 65 2d 68 65 6c 6c 6d 61 6e 2d 67 72 6f 75  fie-hellman-grou
  00000060  70 31 34 2d 73 68 61 31 00 00 00 07 73 73 68 2d  p14-sha1....ssh-
  00000070  72 73 61 00 00 00 63 61 65 73 32 35 36 2d 63 74  rsa...caes256-ct
  00000080  72 2c 61 65 73 32 35 36 2d 63 62 63 2c 61 65 73  r,aes256-cbc,aes
  00000090  31 39 32 2d 63 74 72 2c 61 65 73 31 39 32 2d 63  192-ctr,aes192-c
  000000a0  62 63 2c 61 65 73 31 32 38 2d 63 74 72 2c 61 65  bc,aes128-ctr,ae
  000000b0  73 31 32 38 2d 63 62 63 2c 63 61 73 74 31 32 38  s128-cbc,cast128
  000000c0  2d 63 62 63 2c 62 6c 6f 77 66 69 73 68 2d 63 62  -cbc,blowfish-cb
  000000d0  63 2c 33 64 65 73 2d 63 62 63 00 00 00 63 61 65  c,3des-cbc...cae
  000000e0  73 32 35 36 2d 63 74 72 2c 61 65 73 32 35 36 2d  s256-ctr,aes256-
  000000f0  63 62 63 2c 61 65 73 31 39 32 2d 63 74 72 2c 61  cbc,aes192-ctr,a
  00000100  65 73 31 39 32 2d 63 62 63 2c 61 65 73 31 32 38  es192-cbc,aes128
  00000110  2d 63 74 72 2c 61 65 73 31 32 38 2d 63 62 63 2c  -ctr,aes128-cbc,
  00000120  63 61 73 74 31 32 38 2d 63 62 63 2c 62 6c 6f 77  cast128-cbc,blow
  00000130  66 69 73 68 2d 63 62 63 2c 33 64 65 73 2d 63 62  fish-cbc,3des-cb
  00000140  63 00 00 00 3c 68 6d 61 63 2d 73 68 61 32 2d 35  c...<hmac-sha2-5
  00000150  31 32 2c 68 6d 61 63 2d 73 68 61 32 2d 33 38 34  12,hmac-sha2-384
  00000160  2c 68 6d 61 63 2d 73 68 61 32 2d 32 35 36 2c 68  ,hmac-sha2-256,h
  00000170  6d 61 63 2d 73 68 61 31 2c 68 6d 61 63 2d 6d 64  mac-sha1,hmac-md
  00000180  35 00 00 00 3c 68 6d 61 63 2d 73 68 61 32 2d 35  5...<hmac-sha2-5
  00000190  31 32 2c 68 6d 61 63 2d 73 68 61 32 2d 33 38 34  12,hmac-sha2-384
  000001a0  2c 68 6d 61 63 2d 73 68 61 32 2d 32 35 36 2c 68  ,hmac-sha2-256,h
  000001b0  6d 61 63 2d 73 68 61 31 2c 68 6d 61 63 2d 6d 64  mac-sha1,hmac-md
  000001c0  35 00 00 00 09 6e 6f 6e 65 2c 7a 6c 69 62 00 00  5....none,zlib..
  000001d0  00 09 6e 6f 6e 65 2c 7a 6c 69 62 00 00 00 00 00  ..none,zlib.....
  000001e0  00 00 00 00 00 00 00 00                          ........
Event Log: Doing ECDH key exchange with curve nistp256 and hash SHA-256
Outgoing packet #0x1, type 30 / 0x1e (SSH2_MSG_KEX_ECDH_INIT)
  00000000  00 00 00 41 04 a5 61 98 bb b1 1d f7 b9 36 36 66  ...A..a......66f
  00000010  6e 13 4e d4 d5 3b 7b a9 d7 ae dd 4b 1d 28 d0 c2  n.N..;{....K.(..
  00000020  e8 6a ac 51 86 02 e4 5d 91 2a e2 b7 d9 79 88 2c  .j.Q...].*...y.,
  00000030  bb f1 60 9d dd 54 12 e6 df d8 d1 0c cc b7 f5 6a  ..`..T.........j
  00000040  ab 7a 1e 22 99                                   .z.".
Incoming packet #0x1, type 31 / 0x1f (SSH2_MSG_KEX_ECDH_REPLY)
  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 ab 7d ca fd 89  ............}...
  00000020  85 58 8f 34 df 16 31 26 3f 72 7f 4d 7d b8 be b2  .X.4..1&?r.M}...
  00000030  af 11 4d 12 96 8d e6 b4 38 6b 85 cd 0e f2 9d 00  ..M.....8k......
  00000040  a3 23 d3 94 24 1b ad a9 0d 5e 2f 62 ea 8a a8 58  .#..$....^/b...X
  00000050  89 a4 bf 64 70 9f 3c 38 98 43 00 7a d8 e2 49 88  ...dp.<8.C.z..I.
  00000060  d2 3b 16 64 dd 80 85 45 c6 60 2f 3d 00 72 c0 10  .;.d...E.`/=.r..
  00000070  9e 26 0f 24 b6 0d 83 81 06 20 23 f9 c9 4a 55 11  .&.$..... #..JU.
  00000080  4e b0 2a 10 bc 4a 47 8d a8 e0 5c 9b 68 04 87 e4  N.*..JG...\.h...
  00000090  75 9a 10 19 b4 e9 f3 41 21 52 43 a7 8f 07 48 99  u......A!RC...H.
  000000a0  12 5b 4e 1e 68 a3 6b 82 bb f2 3e 41 9d 54 0b 1a  .[N.h.k...>A.T..
  000000b0  aa d4 17 e0 1b bc ad af 44 d5 3c 39 a6 97 1a 5b  ........D.<9...[
  000000c0  be 44 71 40 86 2c fc c7 74 0a 10 0a 2a b3 0c 66  .Dq@.,..t...*..f
  000000d0  12 16 6c b9 28 05 47 fd 18 62 8f db c1 db 1d 19  ..l.(.G..b......
  000000e0  2e 81 d7 aa f0 4e 03 d6 e6 0e a2 d5 3e 1a 97 fa  .....N......>...
  000000f0  32 cc a8 43 3a 6a 1f 1f 3b 6d 8d 79 d1 4e eb ef  2..C:j..;m.y.N..
  00000100  ae b0 ca 9d 69 bd 5a 6e ed ba 27 de a3 d5 b0 de  ....i.Zn..'.....
  00000110  37 d6 40 6e ce 9d 37 fe 79 a6 ad 00 00 00 41 04  7.@n..7.y.....A.
  00000120  f1 5c 7c b2 b7 16 94 94 2c 81 38 c2 38 63 da fd  .\|.....,.8.8c..
  00000130  e1 4b 7e b8 92 b2 00 cb df ae 7a 0a f9 9d 6c 2a  .K~.......z...l*
  00000140  46 bc 76 c1 22 b5 e5 a7 7c 86 b2 03 06 61 4a 2a  F.v."...|....aJ*
  00000150  93 97 7a aa b4 e2 5d 99 6c 27 da 80 f8 fa e5 0e  ..z...].l'......
  00000160  00 00 01 0f 00 00 00 07 73 73 68 2d 72 73 61 00  ........ssh-rsa.
  00000170  00 01 00 43 43 b9 6f ac 02 01 22 4b d3 be 4a e7  ...CC.o..."K..J.
  00000180  5e 1d 0f 55 d8 4d e6 79 2f 6f 3c 65 98 ed 3e c8  ^..U.M.y/o<e..>.
  00000190  3e c6 8c fb 59 8b cc af bd 75 cc ce ff 44 1e 27  >...Y....u...D.'
  000001a0  de f6 55 43 8e 63 1e 71 cb a1 0a 83 a3 64 03 ad  ..UC.c.q.....d..
  000001b0  57 90 d4 0c 89 5b 25 45 f7 30 9e ba 35 87 cd f7  W....[%E.0..5...
  000001c0  82 e0 6a 4a 7d b3 b8 68 7f 70 3c 42 58 85 40 3f  ..jJ}..h.p<BX.@?
  000001d0  22 5e 06 b8 6b 2b 6d 76 1e 0c 9d e3 d6 9e 69 cd  "^..k+mv......i.
  000001e0  e8 52 64 24 8e b4 57 3f 9f 8e f8 1c f6 49 10 14  .Rd$..W?.....I..
  000001f0  c4 2e b7 62 3a 29 50 af 8e ec a9 35 6b ec e6 f8  ...b:)P....5k...
  00000200  d7 12 fc 25 b2 f4 c9 54 66 cc d7 fe 18 cd a9 25  ...%...Tf......%
  00000210  1c c5 8d 43 8c 2b fb 89 1e ad e1 9a 0a 62 2b 08  ...C.+.......b+.
  00000220  6e ec 6a 04 5d 4e 22 cd 23 9b b2 3a 8e d4 67 09  n.j.]N".#..:..g.
  00000230  4d a8 6f ef 71 a6 eb 9b 02 df a1 3e 0f 03 46 d2  M.o.q......>..F.
  00000240  ef 33 61 39 de b0 03 94 9b 19 5e c3 9a b9 bb be  .3a9......^.....
  00000250  82 0c 3d e4 8c 57 5f fe 8d db fd 60 08 da fc b1  ..=..W_....`....
  00000260  14 e3 99 eb 7d cb 5d 46 a3 ab 11 17 12 2e f6 15  ....}.]F........
  00000270  1c e9 d7                                         ...
Event Log: Host key fingerprint is:
Event Log: ssh-rsa 2048 93:4f:75:f2:78:b2:2f:ba:71:f7:08:d2:9e:b8:77:18
Outgoing packet #0x2, type 21 / 0x15 (SSH2_MSG_NEWKEYS)
Event Log: Initialised AES-256 SDCTR client->server encryption
Event Log: Initialised HMAC-SHA-256 client->server MAC algorithm
Incoming packet #0x2, type 21 / 0x15 (SSH2_MSG_NEWKEYS)
Event Log: Initialised AES-256 SDCTR server->client encryption
Event Log: Initialised HMAC-SHA-256 server->client MAC algorithm
Outgoing packet #0x3, type 5 / 0x05 (SSH2_MSG_SERVICE_REQUEST)
  00000000  00 00 00 0c 73 73 68 2d 75 73 65 72 61 75 74 68  ....ssh-userauth
Incoming packet #0x3, type 6 / 0x06 (SSH2_MSG_SERVICE_ACCEPT)
  00000000  00 00 00 0c 73 73 68 2d 75 73 65 72 61 75 74 68  ....ssh-userauth
Event Log: Reading key file "C:\Users\***\key-ssh.ppk"
Outgoing packet #0x4, type 50 / 0x32 (SSH2_MSG_USERAUTH_REQUEST)
  00000000  00 00 00 13 64 6f 6d 69 6e 69 71 75 65 2e 64 75  ....xxx.yyyyyyyy
  00000010  63 6f 75 72 6e 61 75 00 00 00 0e 73 73 68 2d 63  yyyyyyy....ssh-c
  00000020  6f 6e 6e 65 63 74 69 6f 6e 00 00 00 04 6e 6f 6e  onnection....non
  00000030  65                                               e
Incoming packet #0x4, type 51 / 0x33 (SSH2_MSG_USERAUTH_FAILURE)
  00000000  00 00 00 12 70 61 73 73 77 6f 72 64 2c 70 75 62  ....password,pub
  00000010  6c 69 63 6b 65 79 00                             lickey.
Outgoing packet #0x5, type 50 / 0x32 (SSH2_MSG_USERAUTH_REQUEST)
  00000000  00 00 00 13 64 6f 6d 69 6e 69 71 75 65 2e 64 75  ....xxx.yyyyyyy
  00000010  63 6f 75 72 6e 61 75 00 00 00 0e 73 73 68 2d 63  yyyyyy....ssh-c
  00000020  6f 6e 6e 65 63 74 69 6f 6e 00 00 00 09 70 75 62  onnection....pub
  00000030  6c 69 63 6b 65 79 00 00 00 00 07 73 73 68 2d 72  lickey.....ssh-r
  00000040  73 61 00 00 01 17 00 00 00 07 73 73 68 2d 72 73  sa........ssh-rs
  00000050  61 00 00 00 03 01 00 01 00 00 01 01 00 b2 ef 79  a..............y
  00000060  30 4d 91 16 2b 31 d3 8a cf fd 95 d6 55 be eb 34  0M..+1......U..4
  00000070  b1 3e 1c a3 62 81 62 5d f5 b1 52 17 25 c0 0e db  .>..b.b]..R.%...
  00000080  c3 88 e9 53 85 7d c5 89 7e 04 f2 65 f2 0b 41 64  ...S.}..~..e..Ad
  00000090  b1 0f 32 05 58 d4 2a b3 1e df 44 5e b5 08 e0 b4  ..2.X.*...D^....
  000000a0  ae 9e 8d 41 11 71 c5 a6 2f 78 66 71 4a 1c 15 ad  ...A.q../xfqJ...
  000000b0  46 d1 ff e6 2a 7c 1b 4c e4 21 c6 49 3d e3 08 79  F...*|.L.!.I=..y
  000000c0  b9 37 e6 a0 e1 c1 cd 8f de 0c 81 b5 d9 55 a8 df  .7...........U..
  000000d0  88 e2 ba 96 7a c5 6b 82 9f 8c 3c 7d c3 36 f7 a7  ....z.k...<}.6..
  000000e0  c4 e2 a3 a7 bf c6 b3 b8 3b bf 08 d1 81 8b 36 4f  ........;.....6O
  000000f0  bd 14 19 fe a1 50 5d 1e 76 ff 77 5e 43 83 8b 2e  .....P].v.w^C...
  00000100  b2 94 52 c1 99 ce da d0 da 0a f9 d4 64 d9 66 39  ..R.........d.f9
  00000110  69 d3 db 58 ac ea 10 76 e1 1d 42 c4 e6 52 03 7f  i..X...v..B..R..
  00000120  bb 5d b0 1e 16 c9 ff 62 ed 84 ed 4c 66 d5 93 66  .].....b...Lf..f
  00000130  1e 8a 28 65 ce c0 6b f8 8c 47 60 4e e2 2a c5 5c  ..(e..k..G`N.*.\
  00000140  d0 45 a0 77 09 3f f6 c5 3a 52 2d fb 20 f4 43 03  .E.w.?..:R-. .C.
  00000150  88 73 85 10 47 f3 c5 e3 76 ee b0 fc cb           .s..G...v....
Event Log: Offered public key
Incoming packet #0x5, type 52 / 0x34 (SSH2_MSG_USERAUTH_SUCCESS)
Event Log: Access granted
Event Log: Opening session as main channel
Outgoing packet #0x6, type 90 / 0x5a (SSH2_MSG_CHANNEL_OPEN)
  00000000  00 00 00 07 73 65 73 73 69 6f 6e 00 00 01 00 00  ....session.....
  00000010  00 40 00 00 00 40 00                             .@...@.
Incoming packet #0x6, type 91 / 0x5b (SSH2_MSG_CHANNEL_OPEN_CONFIRMATION)
  00000000  00 00 01 00 00 00 00 00 00 02 00 00 00 00 80 00  ................
Event Log: Opened main channel
Outgoing packet #0x7, type 98 / 0x62 (SSH2_MSG_CHANNEL_REQUEST)
  00000000  00 00 00 00 00 00 00 07 70 74 79 2d 72 65 71 01  ........pty-req.
  00000010  00 00 00 05 78 74 65 72 6d 00 00 00 50 00 00 00  ....xterm...P...
  00000020  18 00 00 00 00 00 00 00 00 00 00 00 15 03 00 00  ................
  00000030  00 7f 2a 00 00 00 01 80 00 00 96 00 81 00 00 96  ..*.............
  00000040  00 00                                            ..
Outgoing packet #0x8, type 98 / 0x62 (SSH2_MSG_CHANNEL_REQUEST)
  00000000  00 00 00 00 00 00 00 05 73 68 65 6c 6c 01        ........shell.
Incoming packet #0x7, type 100 / 0x64 (SSH2_MSG_CHANNEL_FAILURE)
  00000000  00 00 01 00                                      ....
Incoming packet #0x8, type 100 / 0x64 (SSH2_MSG_CHANNEL_FAILURE)
  00000000  00 00 01 00                                      ....
Event Log: Server refused to start a shell/command
Outgoing packet #0x9, type 97 / 0x61 (SSH2_MSG_CHANNEL_CLOSE)
  00000000  00 00 00 00                                      ....

@terrafrost
Copy link
Member

I see the issue and it is a bug in your server. Actually, it's more of a security vulnerability.

So https://tools.ietf.org/html/rfc4252#page-9 talks about how public key authentication in SSH works.

So in public key crypto you have the public and private key. The way public key auth works in SSH is... you send the public key (but not the private key) and the server says whether or not it'll accept it. It's supposed to be respond with either SSH_MSG_USERAUTH_FAILURE or SSH_MSG_USERAUTH_PK_OK. Your SSH server is responding with SSH_MSG_USERAUTH_SUCCESS. Not only is that in violation of the specs - it's a security vulnerability.

So let's say the server did respond with SSH_MSG_USERAUTH_PK_OK. At this point the client is then supposed to use the private key to sign a string that contains, among other things, the session hash. This way the server sees the public key but never sees the private key. Your SSH server isn't doing that. It's just accepting the server key prima facie. At best, that makes it analogous to password authentication instead of public key authentication. At worst, it completely compromises the integrety of your server (ultimately, this depends on whether or not anyone has access to your public key; normally, it isn't an issue because public keys are kinda supposed to be public, but in your case, the public key is being treated like a password, so it is more of an issue).

I'll try to work on a change to make phpseclib behave in a manner that's more consistent with PuTTY, but I do think an argument could be made for why I'd be better off not doing that and I also think the server needs to fix its stuff..

@terrafrost
Copy link
Member

Should work better with 7f1b53f

@geraudlacheny
Copy link
Author

So, if I try to reformulate your answer :
According to you, the server B (on which I have to send file via SFTP) has problem to deal with authentication with private key ?
So my private key i give to the "$sftp->login(xxx, $privateKey)" method is ok, the PHPSECLIB process is ok. The only actor who makes it possible to work is the dev team of the server. Only them could solve the vulnerability issue ?

@terrafrost
Copy link
Member

According to you, the server B (on which I have to send file via SFTP) has problem to deal with authentication with private key ?

Correct.

So my private key i give to the "$sftp->login(xxx, $privateKey)" method is ok, the PHPSECLIB process is ok.

Yes.

The only actor who makes it possible to work is the dev team of the server.

I wouldn't say that. There are changes phpseclib could make (and indeed, they were made with 7f1b53f) to make phpseclib behave in a manner more consistent with PuTTY, but that doesn't change the fact that their software has a vulnerability. It's kinda like... you can physically drive a car with an expired registration or inspection.... but it doesn't mean you should - what you should do is get an up-to-date registration and inspection.

Only them could solve the vulnerability issue ?

Yes. phpseclib can accommodate the way the server is behaving but it doesn't change the fact that it's still a vulnerability and is off spec. And to be clear, even with the workaround that I've implemented, this isn't a client side vulnerability - it's a server side one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants