Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions runner/ports_optimization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package runner

import (
"net"
"strconv"

"github.com/projectdiscovery/httpx/common/httpx"
sliceutil "github.com/projectdiscovery/utils/slice"
)

var commonHttpPorts = []string{
"80",
"8080",
}

// determineMostLikelySchemeOrder for the input
func determineMostLikelySchemeOrder(input string) string {
if _, port, err := net.SplitHostPort(input); err == nil {
// if input has port that is commonly used for HTTP, return http then https
if sliceutil.Contains(commonHttpPorts, port) {
return httpx.HTTP
}

// As of 10/2025 shodan shows that ports > 1024 are more likely to expose HTTP
// hence we test first http then https on higher ports
// if input has port > 1024, return http then https
if port, err := strconv.Atoi(port); err == nil && port > 1024 {
return httpx.HTTP
}
}

return httpx.HTTPS
}
2 changes: 1 addition & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ func (r *Runner) targets(hp *httpx.HTTPX, target string) chan httpx.Target {
func (r *Runner) analyze(hp *httpx.HTTPX, protocol string, target httpx.Target, method, origInput string, scanopts *ScanOptions) Result {
origProtocol := protocol
if protocol == httpx.HTTPorHTTPS || protocol == httpx.HTTPandHTTPS {
protocol = httpx.HTTPS
protocol = determineMostLikelySchemeOrder(target.Host)
}
retried := false
retry:
Expand Down
Loading