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

View File

@@ -360,6 +360,9 @@ func canAcceptConnection(ip string) bool {
logger.Log(logger.LevelDebug, common.ProtocolSSH, "", "connection refused, configured limit reached") logger.Log(logger.LevelDebug, common.ProtocolSSH, "", "connection refused, configured limit reached")
return false return false
} }
if err := common.Config.ExecutePostConnectHook(ip, common.ProtocolSSH); err != nil {
return false
}
return true 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 // 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 // we'll set a Deadline for handshake to complete, the default is 2 minutes as OpenSSH
conn.SetDeadline(time.Now().Add(handshakeTimeout)) //nolint:errcheck 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) sconn, chans, reqs, err := ssh.NewServerConn(conn, config)
if err != nil { if err != nil {
logger.Debug(logSender, "", "failed to accept an incoming connection: %v", err) 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) ok = processSSHCommand(req.Payload, &connection, c.EnabledSSHCommands)
} }
} }
if req.WantReply {
req.Reply(ok, nil) //nolint:errcheck req.Reply(ok, nil) //nolint:errcheck
} }
}
}(requests, channelCounter) }(requests, channelCounter)
} }
} }