Skip to content

Commit

Permalink
Merge pull request #20 from timoles/response_in_output
Browse files Browse the repository at this point in the history
Added option to include the raw response within the json output
  • Loading branch information
Mzack9999 authored Jun 9, 2020
2 parents 04a9f87 + 14aaf65 commit e742e0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ This will display help for the tool. Here are all the switches it supports.
| -verbose | Verbose Mode | httpx -verbose |
| -version | Prints current version of the httpx | httpx -version |
| -x | Request Method (default 'GET') | httpx -x HEAD |
| -response-in-stdout | Include response in stdout (only works with -json) | httpx -response-in-stdout |


# Installation Instructions
Expand Down
10 changes: 9 additions & 1 deletion cmd/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
scanopts.StoreResponseDirectory = options.StoreResponseDir
scanopts.Method = options.Method
scanopts.OutputServerHeader = options.OutputServerHeader
scanopts.ResponseInStdout = options.responseInStdout

// Try to create output folder if it doesnt exist
if options.StoreResponse && options.StoreResponseDir != "" && options.StoreResponseDir != "." {
Expand Down Expand Up @@ -179,6 +180,7 @@ type scanOptions struct {
StoreResponse bool
StoreResponseDirectory string
OutputServerHeader bool
ResponseInStdout bool
}

func analyze(hp *httpx.HTTPX, protocol string, domain string, port int, scanopts *scanOptions, output chan Result) {
Expand Down Expand Up @@ -244,6 +246,11 @@ retry:
builder.WriteString(fmt.Sprintf(" [%s]", serverHeader))
}

var serverResponseRaw = ""
if scanopts.ResponseInStdout {
serverResponseRaw = resp.Raw
}

// check for virtual host
isvhost := false
if scanopts.VHost {
Expand All @@ -263,7 +270,7 @@ retry:
}
}

output <- Result{URL: fullURL, ContentLength: resp.ContentLength, StatusCode: resp.StatusCode, Title: title, str: builder.String(), VHost: isvhost, WebServer: serverHeader}
output <- Result{URL: fullURL, ContentLength: resp.ContentLength, StatusCode: resp.StatusCode, Title: title, str: builder.String(), VHost: isvhost, WebServer: serverHeader, Response: serverResponseRaw}
}

// Result of a scan
Expand All @@ -276,6 +283,7 @@ type Result struct {
err error
VHost bool `json:"vhost"`
WebServer string `json:"webserver"`
Response string `json:"serverResponse,omitempty"`
}

// JSON the result
Expand Down
2 changes: 2 additions & 0 deletions cmd/httpx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Options struct {
Verbose bool
NoColor bool
OutputServerHeader bool
responseInStdout bool
FollowHostRedirects bool
}

Expand Down Expand Up @@ -67,6 +68,7 @@ func ParseOptions() *Options {
flag.BoolVar(&options.Verbose, "verbose", false, "Verbose Mode")
flag.BoolVar(&options.NoColor, "no-color", false, "No Color")
flag.BoolVar(&options.OutputServerHeader, "web-server", false, "Prints out the Server header content")
flag.BoolVar(&options.responseInStdout, "response-in-json", false, "Server response directly in the tool output (-json only)")
flag.Parse()

// Read the inputs and configure the logging
Expand Down

0 comments on commit e742e0f

Please sign in to comment.