mirror of https://github.com/XTLS/Xray-core
Add UDPFilter to Socks5 server when `auth == password` (#3371)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>pull/3381/head
parent
544f7661ca
commit
9ee9a0634e
@ -0,0 +1,31 @@
|
|||||||
|
package socks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
In the sock implementation of * ray, UDP authentication is flawed and can be bypassed.
|
||||||
|
Tracking a UDP connection may be a bit troublesome.
|
||||||
|
Here is a simple solution.
|
||||||
|
We creat a filter, add remote IP to the pool when it try to establish a UDP connection with auth.
|
||||||
|
And drop UDP packets from unauthorized IP.
|
||||||
|
After discussion, we believe it is not necessary to add a timeout mechanism to this filter.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type UDPFilter struct {
|
||||||
|
ips sync.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *UDPFilter) Add(addr net.Addr) bool {
|
||||||
|
ip, _, _ := net.SplitHostPort(addr.String())
|
||||||
|
f.ips.Store(ip, true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *UDPFilter) Check(addr net.Addr) bool {
|
||||||
|
ip, _, _ := net.SplitHostPort(addr.String())
|
||||||
|
_, ok := f.ips.Load(ip)
|
||||||
|
return ok
|
||||||
|
}
|
Loading…
Reference in new issue