mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-07 15:53:29 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a8758a4d7 | |||
| 2c8ae43303 | |||
| 0935fc1190 | |||
| 3e039824de |
@@ -29,6 +29,7 @@ func newSession(caddr *net.UDPAddr, raddr *net.UDPAddr, proxyConn *net.UDPConn)
|
|||||||
proxyConn: proxyConn,
|
proxyConn: proxyConn,
|
||||||
caddr: caddr,
|
caddr: caddr,
|
||||||
updateTime: time.Now(),
|
updateTime: time.Now(),
|
||||||
|
validator: newValidator(),
|
||||||
}
|
}
|
||||||
|
|
||||||
go session.listen()
|
go session.listen()
|
||||||
@@ -64,7 +65,11 @@ func (s *session) proxyFrom(buf []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.isRconResponsePacket(buf) {
|
if s.isRconResponsePacket(buf) {
|
||||||
log.Debugf("Response: %s", string(buf[10:]))
|
if s.isBadRconResponse(buf) {
|
||||||
|
log.Infof("Response: Bad rcon from %s", s.caddr.IP)
|
||||||
|
} else {
|
||||||
|
log.Debugf("Response: %s", string(buf[10:]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -85,8 +90,8 @@ func (s *session) proxyTo(buf []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.isRconRequestPacket(buf) {
|
if s.isRconRequestPacket(buf) {
|
||||||
parts := strings.Split(string(buf), " ")
|
parts := strings.SplitN(string(buf), " ", 3)
|
||||||
log.Infof("From [%s] To [%s] Command: %s", s.caddr.IP, s.serverConn.RemoteAddr(), strings.Join(parts[2:], " "))
|
log.Infof("From [%s] To [%s] Command: %s", s.caddr.IP, s.serverConn.RemoteAddr(), parts[len(parts)-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,14 +1,35 @@
|
|||||||
package udpproxy
|
package udpproxy
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
type validator struct {
|
type validator struct {
|
||||||
|
rconRequestHeader []byte
|
||||||
|
getstatusRequestHeader []byte
|
||||||
|
getinfoRequestHeader []byte
|
||||||
|
rconResponseHeader []byte
|
||||||
|
getstatusResponseHeader []byte
|
||||||
|
getinfoResponseHeader []byte
|
||||||
|
badRconIdentifier []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func newValidator() validator {
|
||||||
|
return validator{
|
||||||
|
rconRequestHeader: []byte("\xff\xff\xff\xffrcon"),
|
||||||
|
getstatusRequestHeader: []byte("\xff\xff\xff\xffgetstatus"),
|
||||||
|
getinfoRequestHeader: []byte("\xff\xff\xff\xffgetinfo"),
|
||||||
|
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) isRconRequestPacket(buf []byte) bool {
|
func (v *validator) isRconRequestPacket(buf []byte) bool {
|
||||||
return string(buf[:8]) == "\xff\xff\xff\xffrcon"
|
return bytes.Equal(buf[:len(v.rconRequestHeader)], v.rconRequestHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isQueryRequestPacket(buf []byte) bool {
|
func (v *validator) isQueryRequestPacket(buf []byte) bool {
|
||||||
return string(buf[:13]) == "\xff\xff\xff\xffgetstatus" || string(buf[:11]) == "\xff\xff\xff\xffgetinfo"
|
return bytes.Equal(buf[:len(v.getstatusRequestHeader)], v.getstatusRequestHeader) || bytes.Equal(buf[:len(v.getinfoRequestHeader)], v.getinfoRequestHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isValidRequestPacket(buf []byte) bool {
|
func (v *validator) isValidRequestPacket(buf []byte) bool {
|
||||||
@@ -16,13 +37,17 @@ func (v *validator) isValidRequestPacket(buf []byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isRconResponsePacket(buf []byte) bool {
|
func (v *validator) isRconResponsePacket(buf []byte) bool {
|
||||||
return string(buf[:9]) == "\xff\xff\xff\xffprint"
|
return bytes.Equal(buf[:len(v.rconResponseHeader)], v.rconResponseHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isQueryResponsePacket(buf []byte) bool {
|
func (v *validator) isQueryResponsePacket(buf []byte) bool {
|
||||||
return string(buf[:18]) == "\xff\xff\xff\xffstatusResponse" || string(buf[:16]) == "\xff\xff\xff\xffinfoResponse"
|
return bytes.Equal(buf[:len(v.getstatusResponseHeader)], v.getstatusResponseHeader) || bytes.Equal(buf[:len(v.getinfoResponseHeader)], v.getinfoResponseHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isValidResponsePacket(buf []byte) bool {
|
func (v *validator) isValidResponsePacket(buf []byte) bool {
|
||||||
return v.isRconResponsePacket(buf) || v.isQueryResponsePacket(buf)
|
return v.isRconResponsePacket(buf) || v.isQueryResponsePacket(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *validator) isBadRconResponse(buf []byte) bool {
|
||||||
|
return bytes.Equal(buf[len(v.rconResponseHeader):len(v.rconResponseHeader)+len(v.badRconIdentifier)], v.badRconIdentifier)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user