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

Added colors to output #22

Merged
merged 1 commit into from
Jun 15, 2020
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
Added colors to output
  • Loading branch information
Ice3man543 committed Jun 15, 2020
commit 5fe086ef44e6084c80b94b549c2720d705c35597
51 changes: 47 additions & 4 deletions cmd/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -56,6 +57,7 @@ func main() {
scanopts.StoreResponseDirectory = options.StoreResponseDir
scanopts.Method = options.Method
scanopts.OutputServerHeader = options.OutputServerHeader
scanopts.OutputWithNoColor = options.NoColor
scanopts.ResponseInStdout = options.responseInStdout

// Try to create output folder if it doesnt exist
Expand Down Expand Up @@ -180,7 +182,8 @@ type scanOptions struct {
StoreResponse bool
StoreResponseDirectory string
OutputServerHeader bool
ResponseInStdout bool
OutputWithNoColor bool
ResponseInStdout bool
}

func analyze(hp *httpx.HTTPX, protocol string, domain string, port int, scanopts *scanOptions, output chan Result) {
Expand Down Expand Up @@ -229,16 +232,56 @@ retry:
builder.WriteString(fullURL)

if scanopts.OutputStatusCode {
builder.WriteString(fmt.Sprintf(" [%d]", resp.StatusCode))
builder.WriteString(" [")

if !scanopts.OutputWithNoColor {
// Color the status code based on its value
switch {
case resp.StatusCode >= 200 && resp.StatusCode < 300:
builder.WriteString("\033[38;2;0;128;0m")
case resp.StatusCode >= 300 && resp.StatusCode < 400:
builder.WriteString("\033[38;2;255;165;0m")
case resp.StatusCode >= 400 && resp.StatusCode < 500:
builder.WriteString("\033[38;2;255;0;0m")
case resp.StatusCode > 500:
builder.WriteString("\033[38;2;255;255;0m")
}
}

builder.WriteString(strconv.Itoa(resp.StatusCode))
if !scanopts.OutputWithNoColor {
builder.WriteString("\u001b[0m")
}
builder.WriteRune(']')
}

if scanopts.OutputContentLength {
builder.WriteString(fmt.Sprintf(" [%d]", resp.ContentLength))
builder.WriteString(" [")

if !scanopts.OutputWithNoColor {
builder.WriteString("\033[38;2;138;43;226m")
}
builder.WriteString(strconv.Itoa(resp.ContentLength))

if !scanopts.OutputWithNoColor {
builder.WriteString("\u001b[0m")
}
builder.WriteRune(']')
}

title := httpx.ExtractTitle(resp)
if scanopts.OutputTitle {
builder.WriteString(fmt.Sprintf(" [%s]", title))
builder.WriteString(" [")

if !scanopts.OutputWithNoColor {
builder.WriteString("\033[38;2;34;215;211m")
}
builder.WriteString(title)

if !scanopts.OutputWithNoColor {
builder.WriteString("\u001b[0m")
}
builder.WriteRune(']')
}

serverHeader := resp.GetHeader("Server")
Expand Down
54 changes: 27 additions & 27 deletions cmd/httpx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ import (

// Options contains configuration options for chaos client.
type Options struct {
RawRequestFile string
VHost bool
Smuggling bool
ExtractTitle bool
StatusCode bool
ContentLength bool
Retries int
Threads int
Timeout int
CustomHeaders customheader.CustomHeaders
CustomPorts customport.CustomPorts
Output string
FollowRedirects bool
StoreResponse bool
StoreResponseDir string
HttpProxy string
SocksProxy string
JSONOutput bool
InputFile string
Method string
Silent bool
Version bool
Verbose bool
NoColor bool
OutputServerHeader bool
responseInStdout bool
FollowHostRedirects bool
RawRequestFile string
VHost bool
Smuggling bool
ExtractTitle bool
StatusCode bool
ContentLength bool
Retries int
Threads int
Timeout int
CustomHeaders customheader.CustomHeaders
CustomPorts customport.CustomPorts
Output string
FollowRedirects bool
StoreResponse bool
StoreResponseDir string
HttpProxy string
SocksProxy string
JSONOutput bool
InputFile string
Method string
Silent bool
Version bool
Verbose bool
NoColor bool
OutputServerHeader bool
responseInStdout bool
FollowHostRedirects bool
}

// ParseOptions parses the command line options for application
Expand Down