feat: add Fail2ban security detection console
This commit is contained in:
@@ -37,10 +37,12 @@ func (s Server) handleLogin(response *cmpp.Response, packet *cmpp.Packet, logger
|
||||
}
|
||||
account := strings.TrimRight(req.SrcAddr, "\x00")
|
||||
if account == "" {
|
||||
go s.reportSecurityEvent("cmpp_protocol_abuse", remoteIP(packet.Conn.Conn.RemoteAddr()), "EMPTY_SOURCE_ADDRESS", cmppVersionName(req.Version))
|
||||
setInboundConnectResponse(response.Packer, cmpp.ErrnoConnInvalidSrcAddr, req.AuthSrc, "", req.Version)
|
||||
return false, cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnInvalidSrcAddr]
|
||||
}
|
||||
if req.Version != cmpp.V20 && req.Version != cmpp.V21 && req.Version != cmpp.V30 {
|
||||
go s.reportSecurityEvent("cmpp_protocol_abuse", remoteIP(packet.Conn.Conn.RemoteAddr()), "UNSUPPORTED_VERSION", cmppVersionName(req.Version))
|
||||
setInboundConnectResponse(response.Packer, cmpp.ErrnoConnVerTooHigh, req.AuthSrc, "", cmpp.V30)
|
||||
return false, cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnVerTooHigh]
|
||||
}
|
||||
@@ -129,3 +131,18 @@ func (s Server) authenticate(remote net.Addr, account string, authSource string,
|
||||
err := s.post(context.Background(), "/gateway/events/inbound/authenticate", payload, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s Server) reportSecurityEvent(ruleCode, sourceIP, resultCode, protocol string) {
|
||||
if net.ParseIP(sourceIP) == nil {
|
||||
return
|
||||
}
|
||||
payload := map[string]any{
|
||||
"ruleCode": ruleCode, "sourceIp": sourceIP, "resultCode": resultCode, "protocol": protocol,
|
||||
}
|
||||
var result struct {
|
||||
Accepted bool `json:"accepted"`
|
||||
}
|
||||
if err := s.post(context.Background(), "/gateway/events/security-detection", payload, &result); err != nil {
|
||||
log.Printf("security event report failed rule=%s remote=%s err=%v", ruleCode, sourceIP, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user