Skip to content

Commit

Permalink
Merge pull request #37 from projectdiscovery/idna-lookup-issue
Browse files Browse the repository at this point in the history
Generalizing ascii conversion
  • Loading branch information
ehsandeep committed May 16, 2022
2 parents dde30ef + d9a09aa commit 7b8c9c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fastdialer/dialer.go
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/projectdiscovery/networkpolicy"
retryabledns "github.com/projectdiscovery/retryabledns"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/idna"
)

// Dialer structure containing data information
Expand Down Expand Up @@ -171,6 +170,7 @@ func (d *Dialer) dial(ctx context.Context, network, address string, shouldUseTLS
}

// check if data is in cache
hostname = asAscii(hostname)
data, err := d.GetDNSData(hostname)
if err != nil {
// otherwise attempt to retrieve it
Expand Down Expand Up @@ -282,6 +282,7 @@ func (d *Dialer) GetDialedIP(hostname string) string {
if !d.options.WithDialerHistory || d.dialerHistory == nil {
return ""
}
hostname = asAscii(hostname)
v, ok := d.dialerHistory.Get(hostname)
if ok {
return string(v)
Expand All @@ -292,6 +293,7 @@ func (d *Dialer) GetDialedIP(hostname string) string {

// GetTLSData returns the tls data for a hostname
func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error) {
hostname = asAscii(hostname)
if !d.options.WithTLSData {
return nil, NoTLSHistoryError
}
Expand All @@ -311,6 +313,7 @@ func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error) {

// GetDNSDataFromCache cached by the resolver
func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, error) {
hostname = asAscii(hostname)
var data retryabledns.DNSData
dataBytes, ok := d.hm.Get(hostname)
if !ok {
Expand All @@ -323,6 +326,7 @@ func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, er

// GetDNSData for the given hostname
func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error) {
hostname = asAscii(hostname)
// support http://[::1] http://[::1]:8080
// https://datatracker.ietf.org/doc/html/rfc2732
// It defines a syntax
Expand Down Expand Up @@ -350,13 +354,9 @@ func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error) {
)
data, err = d.GetDNSDataFromCache(hostname)
if err != nil {
hostnameAscii, err := idna.ToASCII(hostname)
if err != nil {
return nil, AsciiConversionError
}
data, err = d.dnsclient.Resolve(hostnameAscii)
data, err = d.dnsclient.Resolve(hostname)
if err != nil && d.options.EnableFallback {
data, err = d.dnsclient.ResolveWithSyscall(hostnameAscii)
data, err = d.dnsclient.ResolveWithSyscall(hostname)
}
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions fastdialer/util.go
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ulule/deepcopier"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/idna"
)

func AsTLSConfig(ztlsConfig *ztls.Config) (*tls.Config, error) {
Expand All @@ -29,3 +30,8 @@ func IsTLS13(config interface{}) bool {

return false
}

func asAscii(hostname string) string {
hostnameAscii, _ := idna.ToASCII(hostname)
return hostnameAscii
}

0 comments on commit 7b8c9c7

Please sign in to comment.