Skip to content

Commit

Permalink
add proxy dialer support
Browse files Browse the repository at this point in the history
  • Loading branch information
parrasajad committed Sep 2, 2022
1 parent d6283f7 commit 5437975
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fastdialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/projectdiscovery/networkpolicy"
retryabledns "github.com/projectdiscovery/retryabledns"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/proxy"
)

// Dialer structure containing data information
Expand All @@ -25,6 +26,7 @@ type Dialer struct {
dialerHistory *hybrid.HybridMap
dialerTLSData *hybrid.HybridMap
dialer *net.Dialer
proxyDialer *proxy.Dialer
networkpolicy *networkpolicy.NetworkPolicy
}

Expand Down Expand Up @@ -95,7 +97,7 @@ func NewDialer(options Options) (*Dialer, error) {
return nil, err
}

return &Dialer{dnsclient: dnsclient, hm: hm, dialerHistory: dialerHistory, dialerTLSData: dialerTLSData, dialer: dialer, options: &options, networkpolicy: np}, nil
return &Dialer{dnsclient: dnsclient, hm: hm, dialerHistory: dialerHistory, dialerTLSData: dialerTLSData, dialer: dialer, proxyDialer: options.ProxyDialer, options: &options, networkpolicy: np}, nil
}

// Dial function compatible with net/http
Expand Down Expand Up @@ -229,7 +231,12 @@ func (d *Dialer) dial(ctx context.Context, network, address string, shouldUseTLS
}
conn, err = ztls.DialWithDialer(d.dialer, network, hostPort, ztlsconfigCopy)
} else {
conn, err = d.dialer.DialContext(ctx, network, hostPort)
if d.proxyDialer != nil {
dialer := *d.proxyDialer
conn, err = dialer.Dial(network, hostPort)
} else {
conn, err = d.dialer.DialContext(ctx, network, hostPort)
}
}
if err == nil {
if d.options.WithDialerHistory && d.dialerHistory != nil {
Expand Down
3 changes: 3 additions & 0 deletions fastdialer/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fastdialer
import (
"net"
"time"

"golang.org/x/net/proxy"
)

// DefaultResolvers trusted
Expand Down Expand Up @@ -45,6 +47,7 @@ type Options struct {
DialerTimeout time.Duration
DialerKeepAlive time.Duration
Dialer *net.Dialer
ProxyDialer *proxy.Dialer
WithZTLS bool
SNIName string
OnDialCallback func(hostname, IP string)
Expand Down

0 comments on commit 5437975

Please sign in to comment.