mwiede / jsch

fork of the popular jsch library
Other
756 stars 143 forks source link

Ruijie Switch connected failed with message 'Auth fail for methods 'publickey,password' #333

Closed zhanglinqiang closed 1 year ago

zhanglinqiang commented 1 year ago

Hi, In my case, ssh target is Ruijie Switch. Using linux ssh command can connect successful. I tried 0.1.72 and 0.2.9 and both failed. After I manually set "PreferredAuthentications" to "password,publickey", failed with 'Packet corrupt', suffix xxx is my message appending. Can anyone help?

connect testing code:

try {
                log.info("PreferredAuthentications: {}", session.getConfig("PreferredAuthentications"));
                session.connect(120000);
            } catch (JSchException e) {
                log.error(e.getMessage(), e);
                log.error("try again: ");
                session.setConfig("PreferredAuthentications", "password,publickey");
                log.info("PreferredAuthentications: {}", session.getConfig("PreferredAuthentications"));
                session.connect(120000);
            }

failed message:

13:31:36,796 [pool-1-thread-1] INFO  c.t.t.c.a.connection.JschConnection - PreferredAuthentications: gssapi-with-mic,publickey,keyboard-interactive,password (JschConnection.java:267)
13:31:37,031 [pool-1-thread-1] ERROR c.t.t.c.a.connection.JschConnection - Auth fail for methods 'publickey,password' (JschConnection.java:270)
com.jcraft.jsch.JSchException: Auth fail for methods 'publickey,password'
    at com.jcraft.jsch.Session.connect(Session.java:499) ~[jsch-0.2.9.jar:0.2.9]
    at com.topsec.tap.collector.agent.connection.JschConnection.initializeOpen(JschConnection.java:268) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.JschConnection.open(JschConnection.java:141) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.Connection$1.execute(Connection.java:68) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.Connection$1.execute(Connection.java:64) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.util.TimeoutExecution.call(TimeoutExecution.java:61) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_312]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_312]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_312]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_312]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_312]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_312]
13:31:37,032 [pool-1-thread-1] ERROR c.t.t.c.a.connection.JschConnection - try again:  (JschConnection.java:271)
13:31:37,032 [pool-1-thread-1] INFO  c.t.t.c.a.connection.JschConnection - PreferredAuthentications: password,publickey (JschConnection.java:273)
13:31:37,080 [pool-1-thread-1] ERROR c.t.t.c.a.connection.JschConnection - Packet corruptxxx:  (JschConnection.java:299)
com.jcraft.jsch.JSchException: Packet corrupt
    at com.jcraft.jsch.Session.start_discard(Session.java:1307) ~[jsch-0.2.9.jar:0.2.9]
    at com.jcraft.jsch.Session.read(Session.java:1132) ~[jsch-0.2.9.jar:0.2.9]
    at com.jcraft.jsch.Session.connect(Session.java:310) ~[jsch-0.2.9.jar:0.2.9]
    at com.topsec.tap.collector.agent.connection.JschConnection.initializeOpen(JschConnection.java:274) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.JschConnection.open(JschConnection.java:141) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.Connection$1.execute(Connection.java:68) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.connection.Connection$1.execute(Connection.java:64) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at com.topsec.tap.collector.agent.util.TimeoutExecution.call(TimeoutExecution.java:61) [tap-collector-agent-1.0.15-SNAPSHOT.jar:1.0.15-SNAPSHOT]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_312]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_312]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_312]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_312]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_312]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_312]
13:31:37,080 [pool-1-thread-1] ERROR c.t.t.c.a.connection.JschConnection - Create Connection To Host 172.16.255.254 Error:Packet corrupt (JschConnection.java:307)
13:31:37,081 [pool-1-thread-1] INFO  c.t.t.c.a.connection.JschConnection - Create Connection error172.16.255.254 Error:Packet corrupt (JschConnection.java:146)

jsch config:

static {
        //cisco switch
        appendJschConfig("kex", "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1");

        appendJschConfig("server_host_key", "ssh-dss,ssh-rsa");

        appendJschConfig("cipher.s2c", "aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc");
        appendJschConfig("cipher.c2s", "aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc");
        appendJschConfig("mac.s2c", "hmac-sha1-96,hmac-md5,hmac-md5-96");
        appendJschConfig("mac.c2s", "hmac-sha1-96,hmac-md5,hmac-md5-96");

        JSch.setConfig("StrictHostKeyChecking", "no");
        JSch.setConfig("PreferredAuthentications", "password,keyboard-interactive");
        //Solaris
        JSch.setConfig("dhgex_preferred", "1024");
        JSch.setConfig("dhgex_min", "1024");
    }

    private static void appendJschConfig(String key, String value) {
        String oldConfig = JSch.getConfig(key);
        String collect = Stream.concat(Arrays.stream(oldConfig.split(",")), Arrays.stream(value.split(",")))
                .distinct()
                .collect(Collectors.joining(","));
        JSch.setConfig(key, collect);
    }

java -version

openjdk 1.8.0_312

connect with linux command ssh -vvv:

root@localhost:/home/system# ssh -vvv admin@172.16.255.254
OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1t  7 Feb 2023
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: kex names ok: [diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1]
debug2: resolve_canonicalize: hostname 172.16.255.254 is address
debug2: ssh_connect_direct
debug1: Connecting to 172.16.255.254 [172.16.255.254] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.4
debug1: Remote protocol version 1.99, remote software version RGOS_SSH
debug1: no match: RGOS_SSH
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 172.16.255.254:22 as 'admin'
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /root/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from 172.16.255.254
debug3: order_hostkeyalgs: prefer hostkeyalgs: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,ext-info-c
1@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-dss,ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,des-cbc,aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,arcfour
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,des-cbc,aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,arcfour
debug2: MACs ctos: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
debug2: MACs stoc: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
debug2: compression ctos: none,zlib
debug2: compression stoc: none,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: diffie-hellman-group-exchange-sha1
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug3: send packet: type 34
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<7680<8192) sent
debug3: receive packet: type 31
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 1017/2048
debug3: send packet: type 32
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug3: receive packet: type 33
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:pluUo+oPC6UKrZ6tPjnoWhbubaWrn0zLDv76sZ7I9Ng
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /root/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from 172.16.255.254
debug1: Host '172.16.255.254' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:4
debug2: bits set: 1053/2048
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /root/.ssh/id_rsa 
debug1: Will attempt key: /root/.ssh/id_dsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /root/.ssh/id_ed25519 
debug1: Will attempt key: /root/.ssh/id_ed25519_sk 
debug1: Will attempt key: /root/.ssh/id_xmss 
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug3: no such identity: /root/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug3: no such identity: /root/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_xmss
debug3: no such identity: /root/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
admin@172.16.255.254's password: 
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
admin@172.16.255.254's password: 
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
admin@172.16.255.254's password: 
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (password).
Authenticated to 172.16.255.254 ([172.16.255.254]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug1: Sending environment.
debug3: Ignored env SHELL
debug3: Ignored env JAVA_HOME
debug3: Ignored env PWD
debug3: Ignored env LOGNAME
debug3: Ignored env XDG_SESSION_TYPE
debug3: Ignored env MOTD_SHOWN
debug3: Ignored env HOME
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env LS_COLORS
debug3: Ignored env SSH_CONNECTION
debug3: Ignored env LESSCLOSE
debug3: Ignored env XDG_SESSION_CLASS
debug3: Ignored env TERM
debug3: Ignored env LESSOPEN
debug3: Ignored env USER
debug3: Ignored env SHLVL
debug3: Ignored env XDG_SESSION_ID
debug3: Ignored env XDG_RUNTIME_DIR
debug3: Ignored env SSH_CLIENT
debug3: Ignored env PATH
debug3: Ignored env DBUS_SESSION_BUS_ADDRESS
debug3: Ignored env MAIL
debug3: Ignored env SSH_TTY
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
BhWater5FCore>show version
System description      : Ruijie High-density IPv6 100G Core Routing Switch(S7805C) By Ruijie Networks
System start time       : 2023-04-12 23:17:33
System uptime           : 46:13:59:44
System hardware version : 1.20
System software version : S7800C_RGOS 11.0(4)B19P3
System patch number     : NA
System serial number    : G1R31JH000733
System boot version     : 1.2.34
Module information:
  Slot 1/M1 : M7805C-CM
    Hardware version    : 1.20
    Boot version        : 1.2.34
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R31JH000733
  Slot 1/1 : M7800C-24SFP/12GT4XS-EA
    Hardware version    : 1.81
    Boot version        : 1.2.33
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R91WW00155A
  Slot 1/2 : M7800C-24SFP/12GT4XS-EA
    Hardware version    : 1.81
    Boot version        : 1.2.33
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R91WW00244B
  Slot 2/1 : M7800C-24SFP/12GT4XS-EA
    Hardware version    : 1.81
    Boot version        : 1.2.33
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R91WW000838
  Slot 2/2 : M7800C-24SFP/12GT4XS-EA
    Hardware version    : 1.81
    Boot version        : 1.2.33
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R91WW001467
  Slot 2/M1 : M7805C-CM
    Hardware version    : 1.20
    Boot version        : 1.2.34
    Software version    : S7800C_RGOS 11.0(4)B19P3
    Serial number       : G1R40B7000512

[END] 2023-05-29 13:22:05
zhanglinqiang commented 1 year ago

Sorry, Target password contains special char '&', and My front app escape to '&'