From eb909fac1ab51b37061c4d12b1cf25dd6c6e4b9c Mon Sep 17 00:00:00 2001 From: Mark Zhou Date: Wed, 9 Oct 2024 12:24:51 +0800 Subject: [PATCH] mod: improve compatibility for Xshell Tested-by: Xshell 5(1339),Xshell 7(0164), Xshell 8(0057) --- app/xshell.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/xshell.go b/app/xshell.go index f4a3de2..555d15c 100644 --- a/app/xshell.go +++ b/app/xshell.go @@ -163,10 +163,26 @@ func (s *xshellProxy) Read(p []byte) (n int, err error) { } // sign if s.buf[4] == agentSignRequest { + data := s.buf[4:] + + // 计算实际长度,仅保留协议报文标准的数据 + totalLen := uint32(1) // pass sshtype byte + totalLen += binary.BigEndian.Uint32(data[totalLen:]) // get KeyBlob data len + totalLen += 4 // KeyBlob len byte + totalLen += binary.BigEndian.Uint32(data[totalLen:]) // get Data data len + totalLen += 4 // Data len byte + totalLen += 4 // Flags byte + + // xshell 低版本没有 Flags,直接填充处理 + out := s.buf[:totalLen+4] + var req signRequestAgentMsg - if err := ssh.Unmarshal(s.buf[4:], &req); err != nil { - l += 4 - s.buf = append(s.buf, []byte{0, 0, 0, 0}...) + err := ssh.Unmarshal(out[4:], &req) + if err != nil { + return 0, err + } else { + l = totalLen + s.buf = out } } binary.BigEndian.PutUint32(s.buf, l)