Skip to content

Commit 1c1af38

Browse files
added functionality similar to what proxychains is doing
1 parent 226ef7e commit 1c1af38

File tree

10 files changed

+403
-71
lines changed

10 files changed

+403
-71
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ tls/
3131
models/**/*
3232
*.model
3333
*.vocab
34+
*.yaml
35+

README.md

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Specify http server in proxy configuration of Postman
3131

3232
## Features
3333

34+
- **Proxy Chain functionality**
35+
Supports `strict`, `dynamic`, `random` chains of SOCKS5 proxy
36+
3437
- **DNS Leak Protection**
3538
DNS resolution occurs on SOCKS5 server side.
3639

@@ -59,7 +62,7 @@ You can download the binary for your platform from [Releases](https://github.com
5962
Example:
6063

6164
```shell
62-
HPTS_RELEASE=v1.4.1; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
65+
HPTS_RELEASE=v1.5.0; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
6366
```
6467

6568
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
@@ -83,7 +86,6 @@ make build
8386

8487
```shell
8588
gohpts -h
86-
8789
_____ _ _ _____ _______ _____
8890
/ ____| | | | | __ \__ __/ ____|
8991
| | __ ___ | |__| | |__) | | | | (___
@@ -98,19 +100,21 @@ Usage: gohpts [OPTIONS]
98100
Options:
99101
-h Show this help message and exit.
100102
-c string
101-
Path to certificate PEM encoded file
102-
-d Show logs in DEBUG mode
103-
-j Show logs in JSON format
103+
Path to certificate PEM encoded file
104+
-d Show logs in DEBUG mode
105+
-f string
106+
Path to proxychain YAML configuration file
107+
-j Show logs in JSON format
104108
-k string
105-
Path to private key PEM encoded file
109+
Path to private key PEM encoded file
106110
-l value
107-
Address of HTTP proxy server (Default: localhost:8080)
108-
-p Password for SOCKS5 proxy (not echoed to terminal)
111+
Address of HTTP proxy server (Default: localhost:8080)
112+
-p Password for SOCKS5 proxy (not echoed to terminal)
109113
-s value
110-
Address of SOCKS5 proxy server (Default: localhost:1080)
114+
Address of SOCKS5 proxy server (Default: localhost:1080)
111115
-u string
112-
User for SOCKS5 proxy
113-
-v print version
116+
User for SOCKS5 proxy
117+
-v print version
114118
```
115119

116120
## Example
@@ -140,6 +144,45 @@ Run http proxy over TLS connection
140144
gohpts -s 1080 -l 8080 -c "path/to/certificate" -k "path/to/private/key"
141145
```
142146

147+
Run http proxy with chain of SOCKS5 proxy
148+
149+
```shell
150+
gohpts -f "path/to/proxychain/config" -d
151+
```
152+
153+
Config example:
154+
155+
```yaml
156+
# Explanations for chains taken from /etc/proxychains4.conf
157+
158+
# strict - Each connection will be done via chained proxies
159+
# all proxies chained in the order as they appear in the list
160+
# all proxies must be online to play in chain
161+
162+
# dynamic - Each connection will be done via chained proxies
163+
# all proxies chained in the order as they appear in the list
164+
# at least one proxy must be online to play in chain
165+
# (dead proxies are skipped)
166+
167+
# random - Each connection will be done via random proxy
168+
# (or proxy chain, see chain_len) from the list.
169+
# this option is good to test your IDS :)
170+
171+
# round_robin - Not supported
172+
173+
chain:
174+
type: strict # dynamic, strict, random
175+
length: 2 # maximum number of proxy in a chain (works only for random chain)
176+
proxy_list:
177+
- address: 127.0.0.1:1080
178+
username: username # username and password are optional
179+
password: password
180+
- address: 127.0.0.1:1081
181+
- address: :1082 # empty host means localhost
182+
```
183+
184+
To learn more about proxy chains visit [Proxychains Github](https://github.com/rofl0r/proxychains-ng)
185+
143186
## License
144187
145188
MIT

cmd/gohpts/cli.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func root(args []string) error {
6565
})
6666
flags.StringVar(&conf.CertFile, "c", "", "Path to certificate PEM encoded file ")
6767
flags.StringVar(&conf.KeyFile, "k", "", "Path to private key PEM encoded file ")
68+
flags.StringVar(&conf.ProxyChainPath, "f", "", "Path to proxychain YAML configuration file")
6869
flags.BoolFunc("d", "Show logs in DEBUG mode", func(flagValue string) error {
6970
conf.Debug = true
7071
return nil
@@ -87,6 +88,15 @@ func root(args []string) error {
8788
if err := flags.Parse(args); err != nil {
8889
return err
8990
}
91+
seen := make(map[string]bool)
92+
flags.Visit(func(f *flag.Flag) { seen[f.Name] = true })
93+
if seen["f"] {
94+
for _, da := range []string{"s", "u", "p"} {
95+
if seen[da] {
96+
return fmt.Errorf("specify either -f or -s -u -p flags")
97+
}
98+
}
99+
}
90100
p := gohpts.New(&conf)
91101
p.Run()
92102
return nil

cmd/gohpts/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func main() {
99
if err := root(os.Args[1:]); err != nil {
10-
fmt.Fprintf(os.Stderr, "%s: %v (type '%s help' for help)\n", app, err, app)
10+
fmt.Fprintf(os.Stderr, "%s: %v (type '%s -h' for help)\n", app, err, app)
1111
os.Exit(2)
1212
}
1313
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/shadowy-pycoder/go-http-proxy-to-socks
33
go 1.24.1
44

55
require (
6+
github.com/goccy/go-yaml v1.18.0
67
github.com/rs/zerolog v1.34.0
78
golang.org/x/net v0.40.0
89
golang.org/x/term v0.32.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
2+
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
3+
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
24
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
35
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
46
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=

0 commit comments

Comments
 (0)