Skip to content

Commit cc9ee63

Browse files
authored
Merge pull request #288 from projectdiscovery/dev
Minor bugfix
2 parents bbc8e48 + 25f6f8f commit cc9ee63

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

common/stringz/stringz.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
)
99

1010
// TrimProtocol removes the HTTP scheme from an URI
11-
func TrimProtocol(targetURL string) string {
11+
func TrimProtocol(targetURL string, addDefaultPort bool) string {
1212
URL := strings.TrimSpace(targetURL)
1313
if strings.HasPrefix(strings.ToLower(URL), "http://") || strings.HasPrefix(strings.ToLower(URL), "https://") {
14-
URL = AddURLDefaultPort(URL)
15-
URL = URL[strings.Index(URL, "//")+2:]
14+
if addDefaultPort {
15+
URL = AddURLDefaultPort(URL)
16+
URL = URL[strings.Index(URL, "//")+2:]
17+
}
1618
}
1719

1820
return URL

runner/banner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const banner = `
88
/ __ \/ __/ __/ __ \| /
99
/ / / / /_/ /_/ /_/ / |
1010
/_/ /_/\__/\__/ .___/_/|_|
11-
/_/ v1.0.7
11+
/_/ v1.0.8
1212
`
1313

1414
// Version is the current version of httpx
15-
const Version = `v1.0.7`
15+
const Version = `v1.0.8`
1616

1717
// showBanner is used to show the banner to the user
1818
func showBanner() {

runner/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type scanOptions struct {
5151
OutputResponseTime bool
5252
PreferHTTPS bool
5353
NoFallback bool
54+
NoFallbackScheme bool
5455
TechDetect bool
5556
StoreChain bool
5657
MaxResponseBodySize int
@@ -88,6 +89,7 @@ func (s *scanOptions) Clone() *scanOptions {
8889
OutputResponseTime: s.OutputResponseTime,
8990
PreferHTTPS: s.PreferHTTPS,
9091
NoFallback: s.NoFallback,
92+
NoFallbackScheme: s.NoFallbackScheme,
9193
TechDetect: s.TechDetect,
9294
StoreChain: s.StoreChain,
9395
OutputExtractRegex: s.OutputExtractRegex,
@@ -159,6 +161,7 @@ type Options struct {
159161
OutputCDN bool
160162
OutputResponseTime bool
161163
NoFallback bool
164+
NoFallbackScheme bool
162165
TechDetect bool
163166
TLSGrab bool
164167
protocol string
@@ -231,6 +234,7 @@ func ParseOptions() *Options {
231234
flag.BoolVar(&options.OutputCDN, "cdn", false, "Check if domain's ip belongs to known CDN (akamai, cloudflare, ..)")
232235
flag.BoolVar(&options.OutputResponseTime, "response-time", false, "Output the response time")
233236
flag.BoolVar(&options.NoFallback, "no-fallback", false, "If HTTPS on port 443 is successful on default configuration, probes also port 80 for HTTP")
237+
flag.BoolVar(&options.NoFallbackScheme, "no-fallback-scheme", false, "The tool will respect and attempt the scheme specified in the url (if HTTPS is specified no HTTP is attempted)")
234238
flag.BoolVar(&options.ShowStatistics, "stats", false, "Enable statistic on keypress (terminal may become unresponsive till the end)")
235239
flag.BoolVar(&options.RandomAgent, "random-agent", false, "Use randomly selected HTTP User-Agent header value")
236240
flag.BoolVar(&options.StoreChain, "store-chain", false, "Save chain to file (default 'output')")

runner/runner.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io/ioutil"
1111
"net/http"
1212
"net/http/httputil"
13+
"net/url"
1314
"os"
1415
"path"
1516
"regexp"
@@ -177,6 +178,7 @@ func New(options *Options) (*Runner, error) {
177178
scanopts.OutputCDN = options.OutputCDN
178179
scanopts.OutputResponseTime = options.OutputResponseTime
179180
scanopts.NoFallback = options.NoFallback
181+
scanopts.NoFallbackScheme = options.NoFallbackScheme
180182
scanopts.TechDetect = options.TechDetect
181183
scanopts.StoreChain = options.StoreChain
182184
scanopts.MaxResponseBodySize = options.MaxResponseBodySize
@@ -414,8 +416,10 @@ func (r *Runner) RunEnumeration() {
414416
var reqs int
415417
protocol := r.options.protocol
416418
// attempt to parse url as is
417-
if u, err := urlutil.Parse(t); err == nil {
418-
protocol = u.Scheme
419+
if u, err := url.Parse(t); err == nil {
420+
if r.options.NoFallbackScheme && u.Scheme == httpx.HTTP || u.Scheme == httpx.HTTPS {
421+
protocol = u.Scheme
422+
}
419423
}
420424

421425
if len(r.options.requestURIs) > 0 {
@@ -448,7 +452,7 @@ func (r *Runner) process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.
448452
if scanopts.NoFallback {
449453
protocols = []string{httpx.HTTPS, httpx.HTTP}
450454
}
451-
for target := range targets(stringz.TrimProtocol(t)) {
455+
for target := range targets(stringz.TrimProtocol(t, scanopts.NoFallback || scanopts.NoFallbackScheme)) {
452456
// if no custom ports specified then test the default ones
453457
if len(customport.Ports) == 0 {
454458
for _, method := range scanopts.Methods {
@@ -550,10 +554,13 @@ retry:
550554
URL, _ := urlutil.Parse(domain)
551555
URL.Scheme = protocol
552556

557+
if !strings.Contains(domain, URL.Port) {
558+
URL.Port = ""
559+
}
560+
553561
if !scanopts.Unsafe {
554562
URL.RequestURI += scanopts.RequestURI
555563
}
556-
557564
req, err := hp.NewRequest(method, URL.String())
558565
if err != nil {
559566
return Result{URL: URL.String(), err: err}

0 commit comments

Comments
 (0)