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

SFTP: Connection closed by server (TurboFTP) but works fine with WinSCP + Login PUTTY ok #1957

Closed
weha opened this issue Nov 3, 2023 · 6 comments

Comments

@weha
Copy link

weha commented Nov 3, 2023

I'm trying to connect to an SFTP server but it says "connection closed by server"
When I go deeper in the code it fails at "Invalid size" in SSH2.php
I can connect just fine with WinSCP and browser / download files.
When I try to connect with putty it gives me a succesful login but of course no SSH TTY possible
Phpseclib seems to stop at the user entry or just before password entry.

login as: user
user@server's password:
Server refused to allocate pty

phpseclib log:

<-
00000000  53:53:48:2d:32:2e:30:2d:54:75:72:62:6f:46:54:50  SSH-2.0-TurboFTP
00000010  5f:53:45:52:56:45:52:5f:33:2e:39:37:2e:32:33:33  _SERVER_3.97.233
00000020  36:0d:0a                                         6..

->
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:6c:69:62:73:6f:64:69:75:6d  b_3.0 (libsodium
00000020  2c:20:6f:70:65:6e:73:73:6c:2c:20:62:63:6d:61:74  , openssl, bcmat
00000030  68:29:0d:0a                                      h)..

-> NET_SSH2_MSG_KEXINIT (since last: 0.0394, network: 0s)
00000000  f1:a0:0a:d9:4e:de:a8:f1:33:2e:c3:82:70:5a:fe:9c  ....N...3...pZ..
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:32:35:36:2d  h-dss....aes256-
00000210  67:63:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c  gcm@openssh.com,
00000220  61:65:73:31:32:38:2d:67:63:6d:40:6f:70:65:6e:73  aes128-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:32:35:36:2d:67:63:6d:40:6f:70:65:6e:73:73:68  s256-gcm@openssh
00000320  2e:63:6f:6d:2c:61:65:73:31:32:38:2d:67:63:6d:40  .com,aes128-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:1a:6e:6f:6e:65:2c:7a:6c  c-md5....none,zl
00000610  69:62:40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:7a  ib@openssh.com,z
00000620  6c:69:62:00:00:00:1a:6e:6f:6e:65:2c:7a:6c:69:62  lib....none,zlib
00000630  40:6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:7a:6c:69  @openssh.com,zli
00000640  62:00:00:00:00:00:00:00:00:00:00:00:00:00        b.............

<- NET_SSH2_MSG_KEXINIT (since last: 0.0041, network: 0.0041s)
00000000  83:a4:22:2c:68:d6:f2:10:b6:d2:80:ee:34:7a:40:4d  ..",h.......4z@M
00000010  00:00:00:b7:65:63:64:68:2d:73:68:61:32:2d:6e:69  ....ecdh-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:2d:73:68:61:31:2c:64:69:66:66:69:65:2d:68  p1-sha1,diffie-h
00000070  65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:31:34:2d:73  ellman-group14-s
00000080  68:61:31:2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ha1,diffie-hellm
00000090  61:6e:2d:67:72:6f:75:70:2d:65:78:63:68:61:6e:67  an-group-exchang
000000a0  65:2d:73:68:61:31:2c:64:69:66:66:69:65:2d:68:65  e-sha1,diffie-he
000000b0  6c:6c:6d:61:6e:2d:67:72:6f:75:70:2d:65:78:63:68  llman-group-exch
000000c0  61:6e:67:65:2d:73:68:61:32:35:36:00:00:00:21:72  ange-sha256...!r
000000d0  73:61:2d:73:68:61:32:2d:35:31:32:2c:72:73:61:2d  sa-sha2-512,rsa-
000000e0  73:68:61:32:2d:32:35:36:2c:73:73:68:2d:72:73:61  sha2-256,ssh-rsa
000000f0  00:00:00:9a:61:65:73:31:32:38:2d:63:74:72:2c:61  ....aes128-ctr,a
00000100  65:73:31:39:32:2d:63:74:72:2c:61:65:73:32:35:36  es192-ctr,aes256
00000110  2d:63:74:72:2c:61:65:73:31:32:38:2d:67:63:6d:40  -ctr,aes128-gcm@
00000120  6f:70:65:6e:73:73:68:2e:63:6f:6d:2c:61:65:73:32  openssh.com,aes2
00000130  35:36:2d:67:63:6d:40:6f:70:65:6e:73:73:68:2e:63  56-gcm@openssh.c
00000140  6f:6d:2c:61:72:63:66:6f:75:72:31:32:38:2c:61:72  om,arcfour128,ar
00000150  63:66:6f:75:72:32:35:36:2c:61:65:73:31:32:38:2d  cfour256,aes128-
00000160  63:62:63:2c:61:65:73:31:39:32:2d:63:62:63:2c:61  cbc,aes192-cbc,a
00000170  65:73:32:35:36:2d:63:62:63:2c:33:64:65:73:2d:63  es256-cbc,3des-c
00000180  62:63:2c:63:61:73:74:31:32:38:2d:63:62:63:00:00  bc,cast128-cbc..
00000190  00:9a:61:65:73:31:32:38:2d:63:74:72:2c:61:65:73  ..aes128-ctr,aes
000001a0  31:39:32:2d:63:74:72:2c:61:65:73:32:35:36:2d:63  192-ctr,aes256-c
000001b0  74:72:2c:61:65:73:31:32:38:2d:67:63:6d:40:6f:70  tr,aes128-gcm@op
000001c0  65:6e:73:73:68:2e:63:6f:6d:2c:61:65:73:32:35:36  enssh.com,aes256
000001d0  2d:67:63:6d:40:6f:70:65:6e:73:73:68:2e:63:6f:6d  -gcm@openssh.com
000001e0  2c:61:72:63:66:6f:75:72:31:32:38:2c:61:72:63:66  ,arcfour128,arcf
000001f0  6f:75:72:32:35:36:2c:61:65:73:31:32:38:2d:63:62  our256,aes128-cb
00000200  63:2c:61:65:73:31:39:32:2d:63:62:63:2c:61:65:73  c,aes192-cbc,aes
00000210  32:35:36:2d:63:62:63:2c:33:64:65:73:2d:63:62:63  256-cbc,3des-cbc
00000220  2c:63:61:73:74:31:32:38:2d:63:62:63:00:00:00:32  ,cast128-cbc...2
00000230  68:6d:61:63:2d:73:68:61:32:2d:32:35:36:2c:68:6d  hmac-sha2-256,hm
00000240  61:63:2d:73:68:61:32:2d:35:31:32:2c:68:6d:61:63  ac-sha2-512,hmac
00000250  2d:73:68:61:31:2c:68:6d:61:63:2d:73:68:61:31:2d  -sha1,hmac-sha1-
00000260  39:36:00:00:00:32:68:6d:61:63:2d:73:68:61:32:2d  96...2hmac-sha2-
00000270  32:35:36:2c:68:6d:61:63:2d:73:68:61:32:2d:35:31  256,hmac-sha2-51
00000280  32:2c:68:6d:61:63:2d:73:68:61:31:2c:68:6d:61:63  2,hmac-sha1,hmac
00000290  2d:73:68:61:31:2d:39:36:00:00:00:1a:6e:6f:6e:65  -sha1-96....none
000002a0  2c:7a:6c:69:62:2c:7a:6c:69:62:40:6f:70:65:6e:73  ,zlib,zlib@opens
000002b0  73:68:2e:63:6f:6d:00:00:00:1a:6e:6f:6e:65:2c:7a  sh.com....none,z
000002c0  6c:69:62:2c:7a:6c:69:62:40:6f:70:65:6e:73:73:68  lib,zlib@openssh
000002d0  2e:63:6f:6d:00:00:00:00:00:00:00:00:00:00:00:00  .com............
000002e0  00                                               .

-> NET_SSH2_MSG_KEX_ECDH_INIT (since last: 0.1336, network: 0s)
00000000  00:00:00:41:04:0f:c3:62:de:54:4f:47:f3:2a:4d:7b  ...A...b.TOG.*M{
00000010  7e:6d:0f:1d:d5:31:ed:99:be:8a:3f:76:fd:c3:8b:42  ~m...1....?v...B
00000020  5e:4d:1b:99:cb:e7:1d:3c:49:3d:2a:15:e5:6b:b5:1e  ^M......I=*..k..
00000030  4a:d7:5e:19:a1:96:47:77:f8:ea:c8:38:f4:f0:45:6d  J.^...Gw...8..Em
00000040  5a:88:bc:7d:d0                                   Z..}.

<- NET_SSH2_MSG_KEX_ECDH_REPLY (since last: 0.0171, network: 0.0171s)
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:cd:5d:60:7b:89  ............]`{.
00000020  1c:7e:7a:de:fb:5d:3b:2f:74:99:87:c2:23:9a:42:cf  .~z..];/t...#.B.
00000030  be:8a:36:15:d2:d5:76:2c:ce:c6:4c:d6:9d:93:e2:e1  ..6...v,..L.....
00000040  ba:ea:af:8e:a7:d5:39:95:f6:8b:39:e6:7b:49:cd:32  ......9...9.{I.2
00000050  23:30:d2:d4:90:05:9a:2f:a8:a1:f6:26:2d:61:6a:79  #0...../...&-ajy
00000060  53:3f:31:eb:fc:78:35:e1:90:1f:73:94:5c:1c:e3:f0  S?1..x5...s.\\...
00000070  6e:22:8b:78:a3:19:33:1c:8b:0b:f6:fa:a3:3b:8f:0f  n".x..3......;..
00000080  1d:2e:a5:09:0a:0b:60:d2:89:5a:e5:31:89:82:77:8a  ......`..Z.1..w.
00000090  01:9d:75:23:8a:0c:73:d0:47:36:4e:92:6a:80:a7:fe  ..u#..s.G6N.j...
000000a0  34:5d:5d:eb:58:e0:f4:e9:b8:45:04:17:53:5d:6e:f5  4]].X....E..S]n.
000000b0  c7:46:bf:22:f9:af:8f:5e:b6:71:c8:e8:6f:4b:67:4b  .F."...^.q..oKgK
000000c0  92:42:88:1d:9a:f1:b2:a8:5e:c4:a6:dd:e6:3d:f9:d1  .B......^....=..
000000d0  89:11:c8:0c:40:53:ce:b1:d6:17:be:4d:23:63:83:70  ....@S.....M#c.p
000000e0  7b:db:64:c6:45:2b:5c:f4:fb:5c:67:e4:c9:84:33:1c  {.d.E+\\..\\g...3.
000000f0  cf:c1:4b:54:76:e3:5b:82:b4:4a:cd:ef:a8:17:b6:c4  ..KTv.[..J......
00000100  23:01:c0:34:07:49:75:49:a3:42:a3:70:5f:20:ab:e0  #..4.IuI.B.p_ ..
00000110  87:89:83:37:d2:39:34:2e:a6:0b:23:00:00:00:41:04  ...7.94...#...A.
00000120  ef:e9:cd:fc:19:dc:ec:df:5d:41:e5:d7:a8:80:d6:1d  ........]A......
00000130  aa:df:60:11:d1:dc:1b:30:a0:a5:a0:13:51:24:2a:f5  ..`....0....Q$*.
00000140  1b:08:10:8e:02:12:f1:d9:0d:67:d1:0b:fc:29:47:e7  .........g...)G.
00000150  40:06:6b:4c:e6:8d:42:55:e9:42:a4:f4:aa:28:a8:d7  @.kL..BU.B...(..
00000160  00:00:01:14:00:00:00:0c:72:73:61:2d:73:68:61:32  ........rsa-sha2
00000170  2d:32:35:36:00:00:01:00:a3:93:78:e8:0f:67:0b:f7  -256......x..g..
00000180  18:c4:b0:fe:25:69:d9:15:bf:d7:2b:4e:52:20:a4:82  ....%i....+NR ..
00000190  b8:bc:b3:13:e9:f2:b5:0b:7e:23:3d:23:ec:47:df:87  ........~#=#.G..
000001a0  21:9b:1a:a7:94:c4:83:4f:2a:ae:17:9a:e5:a5:4b:a1  !......O*.....K.
000001b0  a0:b2:8d:e9:46:af:d1:5b:54:19:09:cb:4b:e9:e6:57  ....F..[T...K..W
000001c0  c3:e1:66:76:ab:23:4b:44:b0:50:68:a5:d1:3e:37:c2  ..fv.#KD.Ph..>7.
000001d0  37:c3:29:e3:c0:97:6e:10:1e:69:c2:01:6d:41:09:3e  7.)...n..i..mA.>
000001e0  f7:56:3c:c2:c5:78:3e:a9:b2:05:4b:34:10:dc:ca:4c  .V...x>...K4...L
000001f0  f1:ec:c1:de:63:af:7e:8a:be:53:7b:23:83:e8:11:d7  ....c.~..S{#....
00000200  f4:94:81:41:68:06:7e:46:35:be:3c:f2:df:fd:49:80  ...Ah.~F5.....I.
00000210  3a:58:36:64:61:4f:80:8c:ae:53:dc:32:aa:23:1a:bf  :X6daO...S.2.#..
00000220  4b:79:21:82:2b:bb:f6:9e:9b:3d:73:57:b0:63:65:75  Ky!.+....=sW.ceu
00000230  0f:7b:78:26:14:84:9d:8a:29:fb:6f:e8:60:35:8c:4f  .{x&....).o.`5.O
00000240  08:39:3d:4f:85:6d:63:70:07:bf:87:26:aa:2f:38:87  .9=O.mcp...&./8.
00000250  a8:b4:0c:37:3a:a2:0f:13:29:c9:fd:79:02:7e:27:37  ...7:...)..y.~\'7
00000260  e2:b7:6a:8e:a1:ad:70:02:7d:13:db:b0:40:f9:4c:4a  ..j...p.}...@.LJ
00000270  2b:4b:64:2c:12:56:60:b9                          +Kd,.V`.

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


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


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

-> NET_SSH2_MSG_DISCONNECT (since last: 0.0145, network: 0s)
00000000  00:00:00:0a:00:00:00:00:00:00:00:00              ............
@terrafrost
Copy link
Member

Looks like it's happening here:

            $packet = Strings::packSSH2('Cs', NET_SSH2_MSG_SERVICE_REQUEST, 'ssh-userauth');
            $this->send_binary_packet($packet);

            try {
                $response = $this->get_binary_packet();
            } catch (\Exception $e) {
                if ($this->retry_connect) {
                    $this->retry_connect = false;
                    $this->connect();
                    return $this->login_helper($username, $password);
                }
                $this->disconnect_helper(NET_SSH2_DISCONNECT_CONNECTION_LOST);
                throw new ConnectionClosedException('Connection closed by server');
            }

It'd be cool if you could post the exact exception that you're getting, complete with line numbers, so that I can be sure but in lieu of that I guess that we can just assume that it is. So in lieu of that I think that what'd be helpful is if you can modify that line of code to replace throw new ConnectionClosedException('Connection closed by server'); with throw $e;.

Also, if you could enable logging in WinSCP as described at https://winscp.net/eng/docs/logging and set the Logging level to Debug 2 that'd be helpful.

What I'm interested in seeing is the cipher suite that WinSCP is using. My guess is that WinSCP is using a different cipher suite than phpseclib and that the server just has buggy implementations of one algorithm or another.

@terrafrost
Copy link
Member

terrafrost commented Nov 4, 2023

Like in my WinSCP instance it's prioritizing aes256-ctr over aes256-gcm@openssh.com (which is what phpseclib preferentially uses). So based on that I wonder if this might work:

$ssh->setPreferredAlgorithms(['client_to_server' => ['crypt' => ['aes256-ctr']], 'server_to_client' => ['crypt' => ['aes256-ctr']]]);

You'd want to do that right after the constructor before you actually try to login.

Is https://turboftp.com/ftp-sftp-server-faq what you're connecting to?

@weha
Copy link
Author

weha commented Nov 4, 2023

@terrafrost I'm not sure how I was able to get it from "connection closed by server" to "invalid size" (actually catching the exception?)
Stack below.

Your suggestion works, maybe there should be a fallback if something like this happens?
Or is this already possible?

I believe it is Turbo FTP as that's what it says in the logs, It's not my server.

RuntimeException: Invalid size in /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:3713
Stack trace:
#0 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(3514): phpseclib3\Net\SSH2->read_remaining_bytes(1996473778)
#1 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2319): phpseclib3\Net\SSH2->get_binary_packet()
#2 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2212): phpseclib3\Net\SSH2->login_helper('user')
#3 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2185): phpseclib3\Net\SSH2->sublogin('user')
#4 /home/wehaadmi/public_html/includes/functions_global.php(2378): phpseclib3\Net\SSH2->login('user', 'password')

@terrafrost
Copy link
Member

terrafrost commented Nov 4, 2023 via email

@terrafrost
Copy link
Member

3ecde6b should fix this.

Thanks!

@weha
Copy link
Author

weha commented Nov 6, 2023

@terrafrost that works!, thanks!

@weha weha closed this as completed Nov 6, 2023
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