@@ -23,6 +23,7 @@ import (
23
23
24
24
"crypto/x509"
25
25
26
+ "golang.org/x/net/proxy"
26
27
"golang.org/x/time/rate"
27
28
)
28
29
@@ -48,6 +49,7 @@ type Client struct {
48
49
writeBufferSize int
49
50
pollInterval time.Duration
50
51
batchSize int
52
+ proxyURL string
51
53
}
52
54
53
55
func generateSessionID () string {
@@ -59,7 +61,7 @@ func generateSessionID() string {
59
61
return hex .EncodeToString (b )
60
62
}
61
63
62
- func NewClient (cloudflareHost string , destPort int , scheme string , destAddr string , debug bool ) * Client {
64
+ func NewClient (cloudflareHost string , destPort int , scheme string , destAddr string , debug bool , proxyURL string ) * Client {
63
65
rand .Seed (time .Now ().UnixNano ())
64
66
65
67
if scheme == "" {
@@ -86,9 +88,10 @@ func NewClient(cloudflareHost string, destPort int, scheme string, destAddr stri
86
88
writeBufferSize : 32 * 1024 ,
87
89
pollInterval : 50 * time .Millisecond ,
88
90
batchSize : 32 * 1024 ,
91
+ proxyURL : proxyURL ,
89
92
bufferPool : sync.Pool {
90
93
New : func () interface {} {
91
- return make ([]byte , 64 * 1024 ) // Increase to 64KB
94
+ return make ([]byte , 64 * 1024 )
92
95
},
93
96
},
94
97
}
@@ -132,6 +135,29 @@ func NewClient(cloudflareHost string, destPort int, scheme string, destAddr stri
132
135
ExpectContinueTimeout : 1 * time .Second ,
133
136
}
134
137
138
+ // Configure proxy support
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 )
148
+ }
149
+ }
150
+ } else {
151
+ // Handle HTTP/HTTPS proxy
152
+ proxyURLParsed , err := url .Parse (proxyURL )
153
+ if err != nil {
154
+ log .Printf ("Error parsing proxy URL: %v" , err )
155
+ } else {
156
+ transport .Proxy = http .ProxyURL (proxyURLParsed )
157
+ }
158
+ }
159
+ }
160
+
135
161
client .httpClient = & http.Client {
136
162
Transport : transport ,
137
163
Timeout : 30 * time .Second ,
@@ -448,6 +474,7 @@ func main() {
448
474
var targetURL string
449
475
var destAddr string
450
476
var debug bool
477
+ var proxyURL string
451
478
452
479
flag .Usage = func () {
453
480
fmt .Fprintf (os .Stderr , "DarkFlare Client - TCP-over-CDN tunnel client component\n " )
@@ -466,6 +493,8 @@ func main() {
466
493
fmt .Fprintf (os .Stderr , " This is where your traffic will ultimately be sent\n \n " )
467
494
fmt .Fprintf (os .Stderr , " -debug Enable detailed debug logging\n " )
468
495
fmt .Fprintf (os .Stderr , " Shows connection details, data transfer, and errors\n \n " )
496
+ 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 " )
469
498
fmt .Fprintf (os .Stderr , "Examples:\n " )
470
499
fmt .Fprintf (os .Stderr , " Basic SSH tunnel:\n " )
471
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 ])
@@ -483,6 +512,7 @@ func main() {
483
512
flag .StringVar (& targetURL , "t" , "" , "" )
484
513
flag .StringVar (& destAddr , "d" , "" , "" )
485
514
flag .BoolVar (& debug , "debug" , false , "" )
515
+ flag .StringVar (& proxyURL , "p" , "" , "Proxy URL (http://host:port or socks5://host:port)" )
486
516
flag .Parse ()
487
517
488
518
if len (os .Args ) == 1 {
@@ -544,7 +574,7 @@ func main() {
544
574
continue
545
575
}
546
576
547
- client := NewClient (host , destPort , scheme , destAddr , debug )
577
+ client := NewClient (host , destPort , scheme , destAddr , debug , proxyURL )
548
578
go client .handleConnection (conn )
549
579
}
550
580
}
0 commit comments