-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from projectdiscovery/issue-131-resolvedIp
fix resolved ip and other minor improvements
- Loading branch information
Showing
6 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package tlsx_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/projectdiscovery/fastdialer/fastdialer" | ||
"github.com/projectdiscovery/tlsx/pkg/tlsx" | ||
"github.com/projectdiscovery/tlsx/pkg/tlsx/clients" | ||
"github.com/projectdiscovery/tlsx/pkg/tlsx/openssl" | ||
iputil "github.com/projectdiscovery/utils/ip" | ||
) | ||
|
||
func TestResolvedIP(t *testing.T) { | ||
allmodes := []string{"ctls", "ztls", "openssl", "auto"} | ||
targethostname := "scanme.sh" | ||
targets, err := getDNSdata(targethostname) | ||
if err != nil { | ||
t.Fatalf("failed to get dns data: %v", err) | ||
} | ||
|
||
for _, mode := range allmodes { | ||
client, err := tlsx.New(&clients.Options{ | ||
ScanMode: mode, | ||
Retries: 3, | ||
}) | ||
if errors.Is(err, openssl.ErrNotSupported) { | ||
t.Logf("openssl not available skipping..") | ||
continue | ||
} | ||
if err != nil { | ||
t.Fatalf("failed to create new client for %v mode: %v", mode, err) | ||
} | ||
for _, target := range targets { | ||
resp, err := client.ConnectWithOptions(targethostname, target, "443", clients.ConnectOptions{}) | ||
if err != nil { | ||
if iputil.IsIPv6(target) { | ||
t.Logf("ipv6 potentially not supported skipping..") | ||
continue | ||
} | ||
t.Fatalf("failed to get response from tlsx client: %v", err) | ||
} | ||
if !iputil.IsIP(resp.IP) { | ||
t.Fatalf("expected ip address for %v but got %v for mode %v", target, resp.IP, mode) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
func getDNSdata(hostname string) ([]string, error) { | ||
targets := []string{} | ||
fd, err := fastdialer.NewDialer(fastdialer.DefaultOptions) | ||
if err != nil { | ||
return targets, err | ||
} | ||
dnsData, err := fd.GetDNSData(hostname) | ||
if err != nil { | ||
return targets, err | ||
} | ||
targets = append(targets, hostname) | ||
targets = append(targets, dnsData.A...) | ||
targets = append(targets, dnsData.AAAA...) | ||
|
||
return targets, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters