@@ -137,24 +137,58 @@ func NewClient(cloudflareHost string, destPort int, scheme string, destAddr stri
137
137
138
138
// Configure proxy support
139
139
if proxyURL != "" {
140
- if strings .HasPrefix (proxyURL , "socks" ) {
141
- // Handle SOCKS proxy
142
- dialer , err := proxy .SOCKS5 ("tcp" , proxyURL [strings .Index (proxyURL , "//" )+ 2 :], nil , proxy .Direct )
143
- if err != nil {
144
- log .Printf ("Error creating SOCKS5 dialer: %v" , err )
145
- } else {
146
- transport .DialContext = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
147
- return dialer .Dial (network , addr )
140
+ if client .debug {
141
+ client .debugLog ("Configuring proxy: %s" , proxyURL )
142
+ }
143
+
144
+ proxyURLParsed , err := url .Parse (proxyURL )
145
+ if err != nil {
146
+ log .Printf ("Invalid proxy URL: %v" , err )
147
+ return nil
148
+ }
149
+
150
+ switch proxyURLParsed .Scheme {
151
+ case "socks5" , "socks5h" :
152
+ // Extract auth if present
153
+ var auth * proxy.Auth
154
+ if proxyURLParsed .User != nil {
155
+ auth = & proxy.Auth {
156
+ User : proxyURLParsed .User .Username (),
157
+ }
158
+ if password , ok := proxyURLParsed .User .Password (); ok {
159
+ auth .Password = password
148
160
}
149
161
}
150
- } else {
151
- // Handle HTTP/HTTPS proxy
152
- proxyURLParsed , err := url . Parse ( proxyURL )
162
+
163
+ // Create SOCKS5 dialer
164
+ dialer , err := proxy . SOCKS5 ( "tcp" , proxyURLParsed . Host , auth , proxy . Direct )
153
165
if err != nil {
154
- log .Printf ("Error parsing proxy URL: %v" , err )
155
- } else {
156
- transport .Proxy = http .ProxyURL (proxyURLParsed )
166
+ log .Printf ("Failed to create SOCKS5 dialer: %v" , err )
167
+ return nil
157
168
}
169
+
170
+ transport .DialContext = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
171
+ if client .debug {
172
+ client .debugLog ("SOCKS5 dialing %s via %s" , addr , proxyURLParsed .Host )
173
+ }
174
+ return dialer .Dial (network , addr )
175
+ }
176
+
177
+ case "http" , "https" :
178
+ transport .Proxy = http .ProxyURL (proxyURLParsed )
179
+
180
+ // Add proxy authentication if present
181
+ if proxyURLParsed .User != nil {
182
+ basicAuth := "Basic " + base64 .StdEncoding .EncodeToString (
183
+ []byte (proxyURLParsed .User .String ()))
184
+ transport .ProxyConnectHeader = http.Header {
185
+ "Proxy-Authorization" : []string {basicAuth },
186
+ }
187
+ }
188
+
189
+ default :
190
+ log .Printf ("Unsupported proxy scheme: %s" , proxyURLParsed .Scheme )
191
+ return nil
158
192
}
159
193
}
160
194
@@ -494,17 +528,27 @@ func main() {
494
528
fmt .Fprintf (os .Stderr , " -debug Enable detailed debug logging\n " )
495
529
fmt .Fprintf (os .Stderr , " Shows connection details, data transfer, and errors\n \n " )
496
530
fmt .Fprintf (os .Stderr , " -p Proxy URL for outbound connections\n " )
497
- fmt .Fprintf (os .Stderr , " Format: http://host:port or socks5://host:port\n \n " )
531
+ fmt .Fprintf (os .Stderr , " Format: scheme://[user:pass@]host:port\n " )
532
+ fmt .Fprintf (os .Stderr , " Supported schemes: http, https, socks5, socks5h\n \n " )
498
533
fmt .Fprintf (os .Stderr , "Examples:\n " )
499
534
fmt .Fprintf (os .Stderr , " Basic SSH tunnel:\n " )
500
- fmt .Fprintf (os .Stderr , " %s -l 2222 -t https://cdn.miami.us.doxx.net -d ssh.destination.com:22\n \n " , os .Args [0 ])
501
- fmt .Fprintf (os .Stderr , " Custom port with debugging:\n " )
502
- fmt .Fprintf (os .Stderr , " %s -l 8080 -t https://tunnel.example.com:8443 -d internal.service:80 -debug\n \n " , os .Args [0 ])
503
- fmt .Fprintf (os .Stderr , " HTTP proxy tunnel:\n " )
504
- fmt .Fprintf (os .Stderr , " %s -l 8080 -t http://proxy.example.com -d target.site.com:80\n \n " , os .Args [0 ])
535
+ fmt .Fprintf (os .Stderr , " %s -l 2222 -t cdn.example.com -d ssh.target.com:22\n \n " , os .Args [0 ])
536
+ fmt .Fprintf (os .Stderr , " With HTTP proxy:\n " )
537
+ fmt .Fprintf (os .Stderr , " %s -l 2222 -t cdn.example.com -d ssh.target.com:22 \\ \n " , os .Args [0 ])
538
+ fmt .Fprintf (os .Stderr , " -p http://proxy.example.com:8080\n \n " )
539
+ fmt .Fprintf (os .Stderr , " With authenticated SOCKS5 proxy:\n " )
540
+ fmt .Fprintf (os .Stderr , " %s -l 2222 -t cdn.example.com -d ssh.target.com:22 \\ \n " , os .Args [0 ])
541
+ fmt .Fprintf (os .Stderr , " -p socks5://user:pass@proxy.example.com:1080\n \n " )
542
+ fmt .Fprintf (os .Stderr , " Debug mode with HTTPS proxy:\n " )
543
+ fmt .Fprintf (os .Stderr , " %s -l 8080 -t cdn.example.com -d internal.service:80 \\ \n " , os .Args [0 ])
544
+ fmt .Fprintf (os .Stderr , " -p https://proxy.company.com:443 -debug\n \n " )
505
545
fmt .Fprintf (os .Stderr , "Usage with SSH:\n " )
506
- fmt .Fprintf (os .Stderr , " 1. Start the client: %s -l 2222 -t tunnel .example.com -d ssh.target.com:22\n " , os .Args [0 ])
546
+ fmt .Fprintf (os .Stderr , " 1. Start the client: %s -l 2222 -t cdn .example.com -d ssh.target.com:22\n " , os .Args [0 ])
507
547
fmt .Fprintf (os .Stderr , " 2. Connect via: ssh -p 2222 user@localhost\n \n " )
548
+ fmt .Fprintf (os .Stderr , "Notes:\n " )
549
+ fmt .Fprintf (os .Stderr , " - Proxy authentication is supported via URL format user:pass@host\n " )
550
+ fmt .Fprintf (os .Stderr , " - SOCKS5h variant will resolve hostnames through the proxy\n " )
551
+ fmt .Fprintf (os .Stderr , " - Debug mode will show proxy connection details and errors\n \n " )
508
552
fmt .Fprintf (os .Stderr , "For more information: https://github.com/blyon/darkflare\n " )
509
553
}
510
554
0 commit comments