@@ -2,22 +2,46 @@ package utils
22
33import (
44 "fmt"
5+ "net"
56 "net/http"
67
78 "github.com/projectdiscovery/httpx/common/httpx"
89 "github.com/projectdiscovery/nuclei/v3/pkg/input/types"
910 "github.com/projectdiscovery/useragent"
11+ sliceutil "github.com/projectdiscovery/utils/slice"
1012)
1113
12- var (
13- HttpSchemes = []string {"https" , "http" }
14- )
14+ var commonHttpPorts = []string {
15+ "80" ,
16+ "8080" ,
17+ }
18+ var defaultHttpSchemes = []string {
19+ "https" ,
20+ "http" ,
21+ }
22+ var httpFirstSchemes = []string {
23+ "http" ,
24+ "https" ,
25+ }
26+
27+ // determineSchemeOrder for the input
28+ func determineSchemeOrder (input string ) []string {
29+ // if input has port that is commonly used for HTTP, return http then https
30+ if _ , port , err := net .SplitHostPort (input ); err == nil {
31+ if sliceutil .Contains (commonHttpPorts , port ) {
32+ return httpFirstSchemes
33+ }
34+ }
35+
36+ return defaultHttpSchemes
37+ }
1538
16- // ProbeURL probes the scheme for a URL. first HTTPS is tried
17- // and if any errors occur http is tried. If none succeeds, probing
18- // is abandoned for such URLs.
39+ // ProbeURL probes the scheme for a URL.
40+ // http schemes are selected with heuristics
41+ // If none succeeds, probing is abandoned for such URLs.
1942func ProbeURL (input string , httpxclient * httpx.HTTPX ) string {
20- for _ , scheme := range HttpSchemes {
43+ schemes := determineSchemeOrder (input )
44+ for _ , scheme := range schemes {
2145 formedURL := fmt .Sprintf ("%s://%s" , scheme , input )
2246 req , err := httpxclient .NewRequest (http .MethodHead , formedURL )
2347 if err != nil {
@@ -39,7 +63,7 @@ type inputLivenessChecker struct {
3963 client * httpx.HTTPX
4064}
4165
42- // ProbeURL probes the scheme for a URL. first HTTPS is tried
66+ // ProbeURL probes the scheme for a URL.
4367func (i * inputLivenessChecker ) ProbeURL (input string ) (string , error ) {
4468 return ProbeURL (input , i .client ), nil
4569}
0 commit comments