Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the support of multiple users #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .env

This file was deleted.

76 changes: 59 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,83 @@

Simple socks5 server using go-socks5 with authentication options

## Start container with proxy
## How to use

```docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=<PROXY_USER> -e PROXY_PASSWORD=<PROXY_PASSWORD> serjs/go-socks5-proxy```
### Docker (recommended)

Leave `PROXY_USER` and `PROXY_PASSWORD` empty for skip authentication options while running socks5 server.
```bash
docker run -d \
-p '1080:1080' \
serjs/go-socks5-proxy \
--user 'someuser=somepass' \
--user 'someuser2=somepass2'
```

## List of all supported config parameters
Remove `--user` parameters to disable authentication on your socks5 server.

|ENV variable|Type|Default|Description|
|------------|----|-------|-----------|
|PROXY_USER|String|EMPTY|Set proxy user (also required existed PROXY_PASS)|
|PROXY_PASSWORD|String|EMPTY|Set proxy password for auth, used with PROXY_USER|
|PROXY_PORT|String|1080|Set listen port for application inside docker container|
|TZ|String|UTC|Set Timezone like in many common Operation Systems|
or

```yaml
version: '3'
services:
socks5:
image: serjs/go-socks5-proxy
ports:
- '1080:1080'
command: |
--user 'someuser=somepass'
--user 'someuser2=somepass2'
```

Remove `command` field to disable authentication on your socks5 server.

## Usage

```bash
usage: socks5 [-h|--help] [-u|--user "<value>" [-u|--user "<value>" ...]]
[-p|--port <integer>]

socks5 is a simple socks5 server written in go

Arguments:

-h --help Print help information
-u --user Add proxy user (format: username=password)
-p --port Proxy port. Default: 1080
```

## Test running service

Without authentication
### Without authentication

```curl --socks5 <docker host ip>:1080 http://ifcfg.co``` - result must show docker host ip (for bridged network)
Result must show docker host ip (for bridged network)

```bash
curl --socks5 <docker host ip>:1080 http://ifcfg.co
```

or

```docker run --rm curlimages/curl:7.65.3 -s --socks5 <docker host ip>:1080 http://ifcfg.co```
```bash
docker run --rm curlimages/curl:7.65.3 -s --socks5 <docker host ip>:1080 http://ifcfg.co
```

### With authentication

With authentication - result must show docker host ip (for bridged network)
Result must show docker host ip (for bridged network)

```curl --socks5 <docker host ip>:1080 -U <PROXY_USER>:<PROXY_PASSWORD> http://ifcfg.co```
```bash
curl --socks5 <docker host ip>:1080 -U <PROXY_USER>:<PROXY_PASSWORD> http://ifcfg.co
```

or

```docker run --rm curlimages/curl:7.65.3 -s --socks5 <PROXY_USER>:<PROXY_PASSWORD>@<docker host ip>:1080 http://ifcfg.co```
```bash
docker run --rm curlimages/curl:7.65.3 -s --socks5 <PROXY_USER>:<PROXY_PASSWORD>@<docker host ip>:1080 http://ifcfg.co
```

## Authors

* **Sergey Bogayrets**
- **Sergey Bogayrets**

See also the list of [contributors](https://github.com/serjs/socks5-server/graphs/contributors) who participated in this project.
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
version: '3'
services:

socks5:
restart: always
build: .
image: serjs/go-socks5-proxy
env_file: .env
ports:
- "1080:1080"
- '1080:1080'
command: |
--port 1080
--user someuser=somepass
--user someuser2=somepass2
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/serjs/socks5-server
go 1.16

require (
github.com/akamensky/argparse v1.3.1
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/caarlos0/env v3.3.1-0.20180521112546-3e0f30cbf50b+incompatible
github.com/sirupsen/logrus v1.8.1
golang.org/x/net v0.0.0-20180406214816-61147c48b25b // indirect
)
14 changes: 12 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g=
github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
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 v3.3.1-0.20180521112546-3e0f30cbf50b+incompatible h1:FjzBjKb2W4ggJbyACel2jbTWSGqCpmu9YqXwcpUp+3M=
github.com/caarlos0/env v3.3.1-0.20180521112546-3e0f30cbf50b+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/net v0.0.0-20180406214816-61147c48b25b h1:7rskAFQwNXGW6AD8E/6y0LDHW5mT9rsLD7ViLVFfh5w=
golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
89 changes: 65 additions & 24 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,88 @@
package main

import (
"errors"
"log"
"net"
"os"
"strconv"
"strings"

opt "github.com/akamensky/argparse"
"github.com/armon/go-socks5"
"github.com/caarlos0/env"
"github.com/sirupsen/logrus"
)

type params struct {
User string `env:"PROXY_USER" envDefault:""`
Password string `env:"PROXY_PASSWORD" envDefault:""`
Port string `env:"PROXY_PORT" envDefault:"1080"`
}
const USER_PASSWORD_SEPARATOR = "="

var (
args = opt.NewParser("socks5",
"socks5 is a simple socks5 server written in go")

users = args.StringList("u", "user",
&opt.Options{
Help: "Add proxy user (format: username" + USER_PASSWORD_SEPARATOR + "password)",
Validate: func(users []string) error {
for _, user := range users {
if len(strings.Split(user, USER_PASSWORD_SEPARATOR)) != 2 {
return errors.New("wrong user format")
}
}
return nil
},
Required: false,
})

port = args.Int("p", "port",
&opt.Options{
Help: "Proxy port",
Default: 1080,
})

network = "tcp"
)

func main() {
// Working with app params
cfg := params{}
err := env.Parse(&cfg)
// Load configuration
err := args.Parse(os.Args)
if err != nil {
log.Printf("%+v\n", err)
logrus.Fatal(args.Usage(err))
}

//Initialize socks5 config
socsk5conf := &socks5.Config{
Logger: log.New(os.Stdout, "", log.LstdFlags),
extractedUsers := make(map[string]string, 0)
for _, u := range *users {
values := strings.Split(u, USER_PASSWORD_SEPARATOR)
extractedUsers[values[0]] = values[1]
}

if cfg.User+cfg.Password != "" {
creds := socks5.StaticCredentials{
os.Getenv("PROXY_USER"): os.Getenv("PROXY_PASSWORD"),
}
cator := socks5.UserPassAuthenticator{Credentials: creds}
socsk5conf.AuthMethods = []socks5.Authenticator{cator}
// Socks5 configuration
conf := &socks5.Config{
Logger: log.New(logrus.New().Out, "[server]", log.Lmsgprefix),
}

server, err := socks5.New(socsk5conf)
credentials := socks5.StaticCredentials{}
for user, password := range extractedUsers {
logrus.WithField("user", user).Info("Adding user")
credentials[user] = password
}

if len(credentials) > 0 {
conf.Credentials = credentials
}

// Start server
server, err := socks5.New(conf)
if err != nil {
log.Fatal(err)
logrus.Fatal(err)
}

log.Printf("Start listening proxy service on port %s\n", cfg.Port)
if err := server.ListenAndServe("tcp", ":"+cfg.Port); err != nil {
log.Fatal(err)
logrus.WithField("port", *port).
WithField("network", "tcp").
Infof("Start listening proxy service")

addr := net.JoinHostPort("", strconv.Itoa(*port))
err = server.ListenAndServe(network, addr)
if err != nil {
logrus.Fatal(err)
}
}
16 changes: 16 additions & 0 deletions vendor/github.com/akamensky/argparse/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/akamensky/argparse/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading