Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Adding new status flag #323

Merged
merged 8 commits into from
Jul 23, 2021
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
4 changes: 2 additions & 2 deletions runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const banner = `
/ __ \/ __/ __/ __ \| /
/ / / / /_/ /_/ /_/ / |
/_/ /_/\__/\__/ .___/_/|_|
/_/ v1.1.0
/_/ v1.1.1
`

// Version is the current version of httpx
const Version = `v1.1.0`
const Version = `v1.1.1`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
2 changes: 2 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type Options struct {
Allow customlist.CustomList
MaxResponseBodySize int
OutputExtractRegex string
Status bool
}

// ParseOptions parses the command line options for application
Expand Down Expand Up @@ -242,6 +243,7 @@ func ParseOptions() *Options {
flag.Var(&options.Deny, "deny", "Denylist ip/cidr")
flag.IntVar(&options.MaxResponseBodySize, "max-response-body-size", math.MaxInt32, "Maximum response body size")
flag.StringVar(&options.OutputExtractRegex, "extract-regex", "", "Extract Regex")
flag.BoolVar(&options.Status, "probe", false, "Display probe status")

flag.Parse()

Expand Down
44 changes: 36 additions & 8 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (r *Runner) RunEnumeration() {
}
for resp := range output {
if resp.err != nil {
gologger.Debug().Msgf("Failure '%s': %s\n", resp.URL, resp.err)
gologger.Debug().Msgf("Failed '%s': %s\n", resp.URL, resp.err)
}
if resp.str == "" {
continue
Expand Down Expand Up @@ -605,7 +605,37 @@ retry:
}

resp, err := hp.Do(req)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-status should work along with other options, unfortunately in this position we are unable to perform retries from https to http. I would refactor it as follows:

resp, err := hp.Do(req)

	fullURL := req.URL.String()

	builder := &strings.Builder{}
	builder.WriteString(stringz.RemoveURLDefaultPort(fullURL))

	if r.options.Status {
		builder.WriteString(" [")
		outputStatus := "success"

		if err != nil {
			outputStatus = "failure"
		}

		switch {
		case !scanopts.OutputWithNoColor && err != nil:
			builder.WriteString(aurora.Red(outputStatus).String())
		case !scanopts.OutputWithNoColor && err == nil:
			builder.WriteString(aurora.Green(outputStatus).String())
		default:
			builder.WriteString(outputStatus)
		}

		builder.WriteRune(']')
	}

	errString := ""
	if err != nil {
		errString = err.Error()
		splitErr := strings.Split(errString, ":")
		errString = strings.TrimSpace(splitErr[len(splitErr)-1])
	}

	if err != nil {
		if !retried && origProtocol == httpx.HTTPorHTTPS {
			if protocol == httpx.HTTPS {
				protocol = httpx.HTTP
			} else {
				protocol = httpx.HTTPS
			}
			retried = true
			goto retry
		}
		return Result{URL: URL.String(), Input: domain, Timestamp: time.Now(), err: err, Failed: err != nil, Error: errString, str: builder.String()}
	}

fullURL := req.URL.String()
builder := &strings.Builder{}
builder.WriteString(stringz.RemoveURLDefaultPort(fullURL))

if r.options.Status {
builder.WriteString(" [")
outputStatus := "SUCCESS"

if err != nil {
outputStatus = "FAILED"
}

switch {
case !scanopts.OutputWithNoColor && err != nil:
builder.WriteString(aurora.Red(outputStatus).String())
case !scanopts.OutputWithNoColor && err == nil:
builder.WriteString(aurora.Green(outputStatus).String())
default:
builder.WriteString(outputStatus)
}

builder.WriteRune(']')
}

if err != nil {
errString := ""
errString = err.Error()
splitErr := strings.Split(errString, ":")
errString = strings.TrimSpace(splitErr[len(splitErr)-1])

if !retried && origProtocol == httpx.HTTPorHTTPS {
if protocol == httpx.HTTPS {
protocol = httpx.HTTP
Expand All @@ -615,19 +645,13 @@ retry:
retried = true
goto retry
}
return Result{URL: URL.String(), err: err}
return Result{URL: URL.String(), Input: domain, Timestamp: time.Now(), err: err, Failed: err != nil, Error: errString, str: builder.String()}
}

var fullURL string

if resp.StatusCode >= 0 {
fullURL = req.URL.String()
}

builder := &strings.Builder{}

builder.WriteString(stringz.RemoveURLDefaultPort(fullURL))

if scanopts.OutputStatusCode {
builder.WriteString(" [")
for i, chainItem := range resp.Chain {
Expand Down Expand Up @@ -903,6 +927,7 @@ retry:
HeaderSHA256: headersSha,
raw: resp.Raw,
URL: fullURL,
Input: domain,
ContentLength: resp.ContentLength,
ChainStatusCodes: chainStatusCodes,
Chain: chainItems,
Expand Down Expand Up @@ -944,10 +969,12 @@ type Result struct {
CNAMEs []string `json:"cnames,omitempty"`
raw string
URL string `json:"url,omitempty"`
Input string `json:"input,omitempty"`
Location string `json:"location,omitempty"`
Title string `json:"title,omitempty"`
str string
err error
Error string `json:"error,omitempty"`
WebServer string `json:"webserver,omitempty"`
ResponseBody string `json:"response-body,omitempty"`
ContentType string `json:"content-type,omitempty"`
Expand All @@ -967,6 +994,7 @@ type Result struct {
Technologies []string `json:"technologies,omitempty"`
Chain []httpx.ChainItem `json:"chain,omitempty"`
FinalURL string `json:"final-url,omitempty"`
Failed bool `json:"failed"`
}

// JSON the result
Expand Down