mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-07 15:53:29 +00:00
Compare commits
7 Commits
log-badrco
...
v1.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cd90ae1dd | |||
| 826756eb6e | |||
| 05fb7bdd0f | |||
| e8f213fded | |||
| 3a8758a4d7 | |||
| 2c8ae43303 | |||
| 0935fc1190 |
@@ -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()
|
||||||
@@ -37,8 +38,8 @@ func newSession(caddr *net.UDPAddr, raddr *net.UDPAddr, proxyConn *net.UDPConn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) listen() error {
|
func (s *session) listen() error {
|
||||||
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 2048)
|
|
||||||
n, err := s.serverConn.Read(buf)
|
n, err := s.serverConn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@@ -64,7 +65,7 @@ func (s *session) proxyFrom(buf []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.isRconResponsePacket(buf) {
|
if s.isRconResponsePacket(buf) {
|
||||||
if s.isBadRconRequest(buf) {
|
if s.isBadRconResponse(buf) {
|
||||||
log.Infof("Response: Bad rcon from %s", s.caddr.IP)
|
log.Infof("Response: Bad rcon from %s", s.caddr.IP)
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("Response: %s", string(buf[10:]))
|
log.Debugf("Response: %s", string(buf[10:]))
|
||||||
@@ -89,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
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ func (c *Client) ListenAndServe() error {
|
|||||||
|
|
||||||
go c.pruneSessions()
|
go c.pruneSessions()
|
||||||
|
|
||||||
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 2048)
|
|
||||||
n, caddr, err := c.proxyConn.ReadFromUDP(buf)
|
n, caddr, err := c.proxyConn.ReadFromUDP(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
@@ -1,14 +1,40 @@
|
|||||||
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 {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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 string(buf[:8]) == "\xff\xff\xff\xffrcon"
|
return v.compare(buf, 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 v.compare(buf, v.getstatusRequestHeader) ||
|
||||||
|
v.compare(buf, v.getinfoRequestHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isValidRequestPacket(buf []byte) bool {
|
func (v *validator) isValidRequestPacket(buf []byte) bool {
|
||||||
@@ -16,17 +42,18 @@ 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 v.compare(buf, 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 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)
|
return v.isRconResponsePacket(buf) || v.isQueryResponsePacket(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) isBadRconRequest(buf []byte) bool {
|
func (v *validator) isBadRconResponse(buf []byte) bool {
|
||||||
return string(buf[10:18]) == "Bad rcon"
|
return v.compare(buf[len(v.rconResponseHeader):], v.badRconIdentifier)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user