ssh requests: send a reply only if the client requested it

This commit is contained in:
Nicola Murino 2021-01-21 09:28:41 +01:00
parent c0e09374a8
commit aff75953e3
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB

View file

@ -360,6 +360,9 @@ func canAcceptConnection(ip string) bool {
logger.Log(logger.LevelDebug, common.ProtocolSSH, "", "connection refused, configured limit reached")
return false
}
if err := common.Config.ExecutePostConnectHook(ip, common.ProtocolSSH); err != nil {
return false
}
return true
}
@ -378,10 +381,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
// Before beginning a handshake must be performed on the incoming net.Conn
// we'll set a Deadline for handshake to complete, the default is 2 minutes as OpenSSH
conn.SetDeadline(time.Now().Add(handshakeTimeout)) //nolint:errcheck
if err := common.Config.ExecutePostConnectHook(ipAddr, common.ProtocolSSH); err != nil {
conn.Close()
return
}
sconn, chans, reqs, err := ssh.NewServerConn(conn, config)
if err != nil {
logger.Debug(logSender, "", "failed to accept an incoming connection: %v", err)
@ -471,8 +471,10 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
ok = processSSHCommand(req.Payload, &connection, c.EnabledSSHCommands)
}
}
if req.WantReply {
req.Reply(ok, nil) //nolint:errcheck
}
}
}(requests, channelCounter)
}
}