mirror of
https://github.com/projectdiscovery/httpx
synced 2026-06-08 16:50:17 +00:00
fix: probe-all-ips now works correctly when URL contains port
Use URL.Hostname() instead of URL.Host to extract the hostname for DNS resolution. This ensures the port number is not included in the DNS query when probing all IPs for a URL like http://example.com:8080. Fixes #2346 Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
+1
-1
@@ -1562,7 +1562,7 @@ func (r *Runner) targets(hp *httpx.HTTPX, target string) chan httpx.Target {
|
||||
results <- httpx.Target{Host: target}
|
||||
return
|
||||
}
|
||||
ips, _, _, err := getDNSData(hp, URL.Host)
|
||||
ips, _, _, err := getDNSData(hp, URL.Hostname())
|
||||
if err != nil || len(ips) == 0 {
|
||||
results <- httpx.Target{Host: target}
|
||||
return
|
||||
|
||||
+34
-4
@@ -67,6 +67,36 @@ func TestRunner_probeall_targets(t *testing.T) {
|
||||
require.ElementsMatch(t, expected, got, "could not expected output")
|
||||
}
|
||||
|
||||
func TestRunner_probeall_targets_with_port(t *testing.T) {
|
||||
options := &Options{
|
||||
ProbeAllIPS: true,
|
||||
}
|
||||
r, err := New(options)
|
||||
require.Nil(t, err, "could not create httpx runner")
|
||||
|
||||
inputWithPort := "http://one.one.one.one:8080"
|
||||
inputWithoutPort := "one.one.one.one"
|
||||
|
||||
gotWithPort := []httpx.Target{}
|
||||
for target := range r.targets(r.hp, inputWithPort) {
|
||||
gotWithPort = append(gotWithPort, target)
|
||||
}
|
||||
|
||||
gotWithoutPort := []httpx.Target{}
|
||||
for target := range r.targets(r.hp, inputWithoutPort) {
|
||||
gotWithoutPort = append(gotWithoutPort, target)
|
||||
}
|
||||
|
||||
require.True(t, len(gotWithPort) > 0, "probe-all-ips with port should return at least one target")
|
||||
require.True(t, len(gotWithoutPort) > 0, "probe-all-ips without port should return at least one target")
|
||||
require.Equal(t, len(gotWithPort), len(gotWithoutPort), "probe-all-ips should return same number of IPs with or without port")
|
||||
|
||||
for _, target := range gotWithPort {
|
||||
require.Equal(t, inputWithPort, target.Host, "Host should be preserved with port")
|
||||
require.NotEmpty(t, target.CustomIP, "CustomIP should be populated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunner_cidr_targets(t *testing.T) {
|
||||
options := &Options{}
|
||||
r, err := New(options)
|
||||
@@ -227,10 +257,10 @@ func TestCreateNetworkpolicyInstance_AllowDenyFlags(t *testing.T) {
|
||||
runner := &Runner{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
allow []string
|
||||
deny []string
|
||||
testCases []struct {
|
||||
name string
|
||||
allow []string
|
||||
deny []string
|
||||
testCases []struct {
|
||||
ip string
|
||||
expected bool
|
||||
reason string
|
||||
|
||||
Reference in New Issue
Block a user