From 89af738d2d42bc953abed63c9180f36f3e39775b Mon Sep 17 00:00:00 2001 From: shadowy-pycoder <35629483+shadowy-pycoder@users.noreply.github.com> Date: Fri, 30 May 2025 18:00:54 +0300 Subject: [PATCH] Added auth for SOCKS5 proxy, bumped to v1.3.0 --- README.md | 21 +++++++++++++++------ cmd/gohpts/cli.go | 12 ++++++++++++ go.mod | 1 + go.sum | 2 ++ gohpts.go | 8 +++++++- version.go | 2 +- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f3994ac..e31f3d9 100644 --- a/README.md +++ b/README.md @@ -68,14 +68,16 @@ GitHub: https://github.com/shadowy-pycoder/go-http-proxy-to-socks Usage: gohpts [OPTIONS] Options: -h Show this help message and exit. - -d Show logs in DEBUG mode - -j Show logs in JSON format + -d Show logs in DEBUG mode + -j Show logs in JSON format -l value - Address of HTTP proxy server (Default: localhost:8080) + Address of HTTP proxy server (Default: localhost:8080) + -p Password for SOCKS5 proxy (not echoed to terminal) -s value - Address of SOCKS5 proxy server (Default: localhost:1080) - -v print version - + Address of SOCKS5 proxy server (Default: localhost:1080) + -u string + User for SOCKS5 proxy + -v print version ``` ## Example @@ -92,6 +94,13 @@ Output: {"level":"debug","time":"2025-05-28T06:15:22+00:00","message":"HTTP/1.1 - CONNECT - www.google.com:443"} ``` +Specify username and password fo SOCKS5 proxy server: + +```shell +gohpts -s 1080 -l 8080 -d -j -u user -p +SOCKS5 Password: #you will be prompted for password input here +``` + ## License MIT diff --git a/cmd/gohpts/cli.go b/cmd/gohpts/cli.go index 23692fa..fc5ace1 100644 --- a/cmd/gohpts/cli.go +++ b/cmd/gohpts/cli.go @@ -7,6 +7,7 @@ import ( "strconv" gohpts "github.com/shadowy-pycoder/go-http-proxy-to-socks" + "golang.org/x/term" ) const ( @@ -42,6 +43,17 @@ func root(args []string) error { } return nil }) + flags.StringVar(&conf.User, "u", "", "User for SOCKS5 proxy") + flags.BoolFunc("p", "Password for SOCKS5 proxy (not echoed to terminal)", func(flagValue string) error { + fmt.Print("SOCKS5 Password: ") + bytepw, err := term.ReadPassword(int(os.Stdin.Fd())) + if err != nil { + os.Exit(1) + } + conf.Pass = string(bytepw) + fmt.Println() + return nil + }) flags.Func("l", "Address of HTTP proxy server (Default: localhost:8080)", func(flagValue string) error { i, err := strconv.Atoi(flagValue) if err == nil { diff --git a/go.mod b/go.mod index 4eb8bdb..197a9e4 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.24.1 require ( github.com/rs/zerolog v1.34.0 golang.org/x/net v0.40.0 + golang.org/x/term v0.32.0 ) require ( diff --git a/go.sum b/go.sum index 93c5bc1..faa9e2f 100644 --- a/go.sum +++ b/go.sum @@ -16,3 +16,5 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= +golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= diff --git a/gohpts.go b/gohpts.go index c992e8e..b6c2173 100644 --- a/gohpts.go +++ b/gohpts.go @@ -210,6 +210,8 @@ type Config struct { AddrSOCKS string Debug bool Json bool + User string + Pass string } func New(conf *Config) *app { @@ -228,7 +230,11 @@ func New(conf *Config) *app { if conf.Debug { zerolog.SetGlobalLevel(zerolog.DebugLevel) } - dialer, err := proxy.SOCKS5("tcp", conf.AddrSOCKS, nil, nil) + auth := proxy.Auth{ + User: conf.User, + Password: conf.Pass, + } + dialer, err := proxy.SOCKS5("tcp", conf.AddrSOCKS, &auth, nil) if err != nil { logger.Fatal().Err(err).Msg("Unable to create SOCKS5 client") } diff --git a/version.go b/version.go index e5c57d7..a8a116b 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package gohpts -const Version string = "gohpts v1.2.1" +const Version string = "gohpts v1.3.0"