Skip to content

Commit

Permalink
fix(ssh-server): discard new channel and user request on error
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeguo committed Jul 23, 2024
1 parent 7650b49 commit 63f6685
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *SSHServer) PublicKeyCallback(conn ssh.ConnMetadata, _key ssh.PublicKey)
}

func (s *SSHServer) BannerCallback(conn ssh.ConnMetadata) string {
return "[bunker] "
return "[bunker] welcome " + conn.User() + " from " + conn.RemoteAddr().String() + ", session: " + hex.EncodeToString(conn.SessionID())
}

func (s *SSHServer) createServerConfig() *ssh.ServerConfig {
Expand Down Expand Up @@ -234,10 +234,26 @@ func (s *SSHServer) HandleServerConn(conn net.Conn) {
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}); err != nil {
log.With("error", err).Error("ssh dial")
go func() {
for nc := range chUserNewChannel {
//discard all new channels
nc.Reject(ssh.ConnectionFailed, err.Error())
}
}()
go func() {
for req := range chUserRequest {
//discard all requests
if req.WantReply {
req.Reply(false, nil)
}
}
}()
return
}
defer client.Close()

log.Info("ssh connection established")

PipeSSH(log, client, userConn, chUserNewChannel, chUserRequest)
}

Expand Down

0 comments on commit 63f6685

Please sign in to comment.