log challenge requests

This commit is contained in:
onyx-and-iris 2024-09-28 15:36:04 +01:00
parent 6cd90ae1dd
commit 2fc0f7a74f
3 changed files with 41 additions and 28 deletions

View File

@ -2,6 +2,7 @@ package udpproxy
import (
"errors"
"fmt"
"net"
"strings"
"time"
@ -68,7 +69,7 @@ func (s *session) proxyFrom(buf []byte) error {
if s.isBadRconResponse(buf) {
log.Infof("Response: Bad rcon from %s", s.caddr.IP)
} else {
log.Debugf("Response: %s", string(buf[10:]))
log.Debugf("Response: %s", string(buf[len(s.rconResponseHeader):]))
}
}
@ -77,7 +78,13 @@ func (s *session) proxyFrom(buf []byte) error {
func (s *session) proxyTo(buf []byte) error {
if !s.isValidRequestPacket(buf) {
err := errors.New("not a rcon or query request packet")
var err error
if s.isChallengeRequestPacket(buf) {
parts := strings.SplitN(string(buf), " ", 3)
err = fmt.Errorf("invalid challenge from %s with GUID: %s", s.caddr.IP, parts[len(parts)-1])
} else {
err = errors.New("not a rcon or query request packet")
}
log.Error(err.Error())
return err
}

View File

@ -53,8 +53,8 @@ func (c *Client) ListenAndServe() error {
log.Error(err)
}
session, found := c.sessions[caddr.String()]
if !found {
session, ok := c.sessions[caddr.String()]
if !ok {
session, err = newSession(caddr, c.raddr, c.proxyConn)
if err != nil {
log.Error(err)

View File

@ -3,57 +3,63 @@ package udpproxy
import "bytes"
type validator struct {
rconRequestHeader []byte
getstatusRequestHeader []byte
getinfoRequestHeader []byte
rconResponseHeader []byte
getstatusResponseHeader []byte
getinfoResponseHeader []byte
badRconIdentifier []byte
rconRequestHeader []byte
getstatusRequestHeader []byte
getinfoRequestHeader []byte
getchallengeRequestHeader []byte
rconResponseHeader []byte
getstatusResponseHeader []byte
getinfoResponseHeader []byte
badRconIdentifier []byte
}
func newValidator() validator {
v := validator{}
v.rconRequestHeader = []byte("\xff\xff\xff\xffrcon")
v.getstatusRequestHeader = []byte("\xff\xff\xff\xffgetstatus")
v.getinfoRequestHeader = []byte("\xff\xff\xff\xffgetinfo")
v.rconResponseHeader = []byte("\xff\xff\xff\xffprint\n")
v.getstatusResponseHeader = []byte("\xff\xff\xff\xffstatusResponse\n")
v.getinfoResponseHeader = []byte("\xff\xff\xff\xffinfoResponse\n")
v.badRconIdentifier = []byte("Bad rcon")
return v
return validator{
rconRequestHeader: []byte("\xff\xff\xff\xffrcon"),
getstatusRequestHeader: []byte("\xff\xff\xff\xffgetstatus"),
getinfoRequestHeader: []byte("\xff\xff\xff\xffgetinfo"),
getchallengeRequestHeader: []byte("\xff\xff\xff\xffgetchallenge"),
rconResponseHeader: []byte("\xff\xff\xff\xffprint\n"),
getstatusResponseHeader: []byte("\xff\xff\xff\xffstatusResponse\n"),
getinfoResponseHeader: []byte("\xff\xff\xff\xffinfoResponse\n"),
badRconIdentifier: []byte("Bad rcon"),
}
}
func (v *validator) compare(buf, c []byte) bool {
func (v validator) compare(buf, c []byte) bool {
return bytes.Equal(buf[:len(c)], c)
}
func (v *validator) isRconRequestPacket(buf []byte) bool {
func (v validator) isRconRequestPacket(buf []byte) bool {
return v.compare(buf, v.rconRequestHeader)
}
func (v *validator) isQueryRequestPacket(buf []byte) bool {
func (v validator) isQueryRequestPacket(buf []byte) bool {
return v.compare(buf, v.getstatusRequestHeader) ||
v.compare(buf, v.getinfoRequestHeader)
}
func (v *validator) isValidRequestPacket(buf []byte) bool {
func (v validator) isValidRequestPacket(buf []byte) bool {
return v.isRconRequestPacket(buf) || v.isQueryRequestPacket(buf)
}
func (v *validator) isRconResponsePacket(buf []byte) bool {
func (v validator) isChallengeRequestPacket(buf []byte) bool {
return v.compare(buf, v.getchallengeRequestHeader)
}
func (v validator) isRconResponsePacket(buf []byte) bool {
return v.compare(buf, v.rconResponseHeader)
}
func (v *validator) isQueryResponsePacket(buf []byte) bool {
func (v validator) isQueryResponsePacket(buf []byte) bool {
return v.compare(buf, v.getstatusResponseHeader) ||
v.compare(buf, v.getinfoResponseHeader)
}
func (v *validator) isValidResponsePacket(buf []byte) bool {
func (v validator) isValidResponsePacket(buf []byte) bool {
return v.isRconResponsePacket(buf) || v.isQueryResponsePacket(buf)
}
func (v *validator) isBadRconResponse(buf []byte) bool {
func (v validator) isBadRconResponse(buf []byte) bool {
return v.compare(buf[len(v.rconResponseHeader):], v.badRconIdentifier)
}