Skip to content

Commit a8075a0

Browse files
committed
merge PRs
2 parents 6d83df3 + fc1a0c0 commit a8075a0

File tree

11 files changed

+861
-16
lines changed

11 files changed

+861
-16
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ $ chisel client --help
212212
--max-retry-interval, Maximum wait time before retrying after a
213213
disconnection. Defaults to 5 minutes.
214214
215-
--proxy, An optional HTTP CONNECT proxy which will be used reach
216-
the chisel server. Authentication can be specified inside the URL.
215+
--proxy, An optional HTTP CONNECT or SOCKS5 proxy which will be
216+
used to reach the chisel server. Authentication can be specified
217+
inside the URL.
217218
For example, http://admin:[email protected]:8081
219+
or: socks://admin:[email protected]:1080
218220
219221
--hostname, Optionally set the 'Host' header (defaults to the host
220222
defined in the endpoint url).

client/client.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
"time"
1313

1414
"github.com/armon/go-socks5"
15+
chshare "github.com/aus/chisel/share"
1516
"github.com/gorilla/websocket"
1617
"github.com/jpillora/backoff"
17-
"github.com/aus/chisel/share"
1818
"golang.org/x/crypto/ssh"
19+
"golang.org/x/net/proxy"
1920
)
2021

2122
//Config represents a client configuration
@@ -27,7 +28,7 @@ type Config struct {
2728
MaxRetryCount int
2829
MaxRetryInterval time.Duration
2930
Server string
30-
HTTPProxy string
31+
Proxy string
3132
Remotes []string
3233
HostHeader string
3334
}
@@ -91,8 +92,8 @@ func NewClient(config *Config) (*Client, error) {
9192
}
9293
client.Info = true
9394

94-
if p := config.HTTPProxy; p != "" {
95-
client.httpProxyURL, err = url.Parse(p)
95+
if p := config.Proxy; p != "" {
96+
client.proxyURL, err = url.Parse(p)
9697
if err != nil {
9798
return nil, fmt.Errorf("Invalid proxy URL (%s)", err)
9899
}
@@ -143,8 +144,8 @@ func (c *Client) verifyServer(hostname string, remote net.Addr, key ssh.PublicKe
143144
//Start client and does not block
144145
func (c *Client) Start(ctx context.Context) error {
145146
via := ""
146-
if c.httpProxyURL != nil {
147-
via = " via " + c.httpProxyURL.String()
147+
if c.proxyURL != nil {
148+
via = " via " + c.proxyURL.String()
148149
}
149150
//prepare non-reverse proxies
150151
for i, r := range c.config.shared.Remotes {
@@ -207,10 +208,35 @@ func (c *Client) connectionLoop() {
207208
HandshakeTimeout: 45 * time.Second,
208209
Subprotocols: []string{chshare.ProtocolVersion},
209210
}
210-
//optionally CONNECT proxy
211-
if c.httpProxyURL != nil {
212-
d.Proxy = func(*http.Request) (*url.URL, error) {
213-
return c.httpProxyURL, nil
211+
//optionally proxy
212+
if c.proxyURL != nil {
213+
if strings.HasPrefix(c.proxyURL.Scheme, "socks") {
214+
// SOCKS5 proxy
215+
if c.proxyURL.Scheme != "socks" && c.proxyURL.Scheme != "socks5h" {
216+
c.Infof(
217+
"unsupported socks proxy type: %s:// (only socks5h:// or socks:// is supported)",
218+
c.proxyURL.Scheme)
219+
break
220+
}
221+
var auth *proxy.Auth = nil
222+
if c.proxyURL.User != nil {
223+
pass, _ := c.proxyURL.User.Password()
224+
auth = &proxy.Auth{
225+
User: c.proxyURL.User.Username(),
226+
Password: pass,
227+
}
228+
}
229+
socksDialer, err := proxy.SOCKS5("tcp", c.proxyURL.Host, auth, proxy.Direct)
230+
if err != nil {
231+
connerr = err
232+
continue
233+
}
234+
d.NetDial = socksDialer.Dial
235+
} else {
236+
// CONNECT proxy
237+
d.Proxy = func(*http.Request) (*url.URL, error) {
238+
return c.proxyURL, nil
239+
}
214240
}
215241
}
216242
wsHeaders := http.Header{}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ require (
1111
github.com/jpillora/sizestr v0.0.0-20160130011556-e2ea2fa42fb9
1212
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
1313
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e
14-
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f // indirect
14+
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f
1515
golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8 // indirect
1616
)

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ var clientHelp = `
264264
--max-retry-interval, Maximum wait time before retrying after a
265265
disconnection. Defaults to 5 minutes.
266266
267-
--proxy, An optional HTTP CONNECT proxy which will be used reach
268-
the chisel server. Authentication can be specified inside the URL.
267+
--proxy, An optional HTTP CONNECT or SOCKS5 proxy which will be
268+
used to reach the chisel server. Authentication can be specified
269+
inside the URL.
269270
For example, http://admin:[email protected]:8081
271+
or: socks://admin:[email protected]:1080
270272
271273
--hostname, Optionally set the 'Host' header (defaults to the host
272274
found in the server url).
@@ -304,7 +306,7 @@ func client(args []string) {
304306
KeepAlive: *keepalive,
305307
MaxRetryCount: *maxRetryCount,
306308
MaxRetryInterval: *maxRetryInterval,
307-
HTTPProxy: *proxy,
309+
Proxy: *proxy,
308310
Server: args[0],
309311
Remotes: args[1:],
310312
HostHeader: *hostname,

vendor/golang.org/x/net/internal/socks/client.go

Lines changed: 168 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)