Moving armon/go-socks5 to forked repo with additional changes

This commit is contained in:
serj
2025-09-23 21:39:33 +03:00
parent 4298d972a9
commit f0eb61962e
5 changed files with 42 additions and 6 deletions
+2
View File
@@ -8,3 +8,5 @@ require (
)
require golang.org/x/net v0.38.0
replace github.com/armon/go-socks5 => github.com/serjs/go-socks5 v0.0.0-20250923183437-3920b97ee0d2
+4 -2
View File
@@ -1,6 +1,8 @@
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II=
github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
github.com/serjs/go-socks5 v0.0.0-20250923182028-346d18438915 h1:fgMfP6jRY4Dq+CFFNpC0hu/tyJj35tlcJphNkutvO98=
github.com/serjs/go-socks5 v0.0.0-20250923182028-346d18438915/go.mod h1:N2PhU16m3olAb71DduLys4mYR3oQboD4uLJmSXCSuMA=
github.com/serjs/go-socks5 v0.0.0-20250923183437-3920b97ee0d2 h1:dIXY/Lrkd1rGXcN60Fc0M2x0p5/C2XcbBbtPCvVvAa4=
github.com/serjs/go-socks5 v0.0.0-20250923183437-3920b97ee0d2/go.mod h1:N2PhU16m3olAb71DduLys4mYR3oQboD4uLJmSXCSuMA=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
+2 -3
View File
@@ -2,8 +2,8 @@ package main
import (
"log"
"net"
"os"
"github.com/armon/go-socks5"
"github.com/caarlos0/env/v6"
)
@@ -45,7 +45,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
{{/*
// Set IP whitelist
if len(cfg.AllowedIPs) > 0 {
whitelist := make([]net.IP, len(cfg.AllowedIPs))
@@ -54,7 +54,6 @@ func main() {
}
server.SetIPWhitelist(whitelist)
}
*/}}
log.Printf("Start listening proxy service on port %s\n", cfg.Port)
if err := server.ListenAndServe("tcp", ":"+cfg.Port); err != nil {
+32
View File
@@ -55,6 +55,7 @@ type Config struct {
type Server struct {
config *Config
authMethods map[uint8]Authenticator
isIPAllowed func(net.IP) bool
}
// New creates a new Server and potentially returns an error
@@ -93,6 +94,11 @@ func New(conf *Config) (*Server, error) {
server.authMethods[a.GetCode()] = a
}
// Set default IP whitelist function
server.isIPAllowed = func(ip net.IP) bool {
return true // default allow all IPs
}
return server, nil
}
@@ -117,11 +123,37 @@ func (s *Server) Serve(l net.Listener) error {
return nil
}
// SetIPWhitelist sets the function to check if a given IP is allowed
func (s *Server) SetIPWhitelist(allowedIPs []net.IP) {
s.isIPAllowed = func(ip net.IP) bool {
for _, allowedIP := range allowedIPs {
if ip.Equal(allowedIP) {
return true
}
}
return false
}
}
// ServeConn is used to serve a single connection.
func (s *Server) ServeConn(conn net.Conn) error {
defer conn.Close()
bufConn := bufio.NewReader(conn)
// Check client IP against whitelist
clientIP, _, err := net.SplitHostPort(conn.RemoteAddr().String())
if err != nil {
s.config.Logger.Printf("[ERR] socks: Failed to get client IP address: %v", err)
return err
}
ip := net.ParseIP(clientIP)
if s.isIPAllowed(ip) {
s.config.Logger.Printf("[INFO] socks: Connection from allowed IP address: %s", clientIP)
} else {
s.config.Logger.Printf("[WARN] socks: Connection from not allowed IP address: %s", clientIP)
return fmt.Errorf("connection from not allowed IP address")
}
// Read the version byte
version := []byte{0}
if _, err := bufConn.Read(version); err != nil {
+2 -1
View File
@@ -1,4 +1,4 @@
# github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
# github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 => github.com/serjs/go-socks5 v0.0.0-20250923183437-3920b97ee0d2
## explicit
github.com/armon/go-socks5
# github.com/caarlos0/env/v6 v6.10.1
@@ -7,3 +7,4 @@ github.com/caarlos0/env/v6
# golang.org/x/net v0.38.0
## explicit; go 1.23.0
golang.org/x/net/context
# github.com/armon/go-socks5 => github.com/serjs/go-socks5 v0.0.0-20250923183437-3920b97ee0d2