Merge pull request #22 from projectdiscovery/iceman-add-colors

Added colors to output
This commit is contained in:
Ice3man 2020-06-15 10:29:45 -07:00 committed by GitHub
commit 1ba45c0d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 31 deletions

View File

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"strconv"
"strings" "strings"
"time" "time"
@ -56,6 +57,7 @@ func main() {
scanopts.StoreResponseDirectory = options.StoreResponseDir scanopts.StoreResponseDirectory = options.StoreResponseDir
scanopts.Method = options.Method scanopts.Method = options.Method
scanopts.OutputServerHeader = options.OutputServerHeader scanopts.OutputServerHeader = options.OutputServerHeader
scanopts.OutputWithNoColor = options.NoColor
scanopts.ResponseInStdout = options.responseInStdout scanopts.ResponseInStdout = options.responseInStdout
// Try to create output folder if it doesnt exist // Try to create output folder if it doesnt exist
@ -180,7 +182,8 @@ type scanOptions struct {
StoreResponse bool StoreResponse bool
StoreResponseDirectory string StoreResponseDirectory string
OutputServerHeader bool OutputServerHeader bool
ResponseInStdout bool OutputWithNoColor bool
ResponseInStdout bool
} }
func analyze(hp *httpx.HTTPX, protocol string, domain string, port int, scanopts *scanOptions, output chan Result) { func analyze(hp *httpx.HTTPX, protocol string, domain string, port int, scanopts *scanOptions, output chan Result) {
@ -229,16 +232,56 @@ retry:
builder.WriteString(fullURL) builder.WriteString(fullURL)
if scanopts.OutputStatusCode { 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 { 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) title := httpx.ExtractTitle(resp)
if scanopts.OutputTitle { 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") serverHeader := resp.GetHeader("Server")

View File

@ -12,33 +12,33 @@ import (
// Options contains configuration options for chaos client. // Options contains configuration options for chaos client.
type Options struct { type Options struct {
RawRequestFile string RawRequestFile string
VHost bool VHost bool
Smuggling bool Smuggling bool
ExtractTitle bool ExtractTitle bool
StatusCode bool StatusCode bool
ContentLength bool ContentLength bool
Retries int Retries int
Threads int Threads int
Timeout int Timeout int
CustomHeaders customheader.CustomHeaders CustomHeaders customheader.CustomHeaders
CustomPorts customport.CustomPorts CustomPorts customport.CustomPorts
Output string Output string
FollowRedirects bool FollowRedirects bool
StoreResponse bool StoreResponse bool
StoreResponseDir string StoreResponseDir string
HttpProxy string HttpProxy string
SocksProxy string SocksProxy string
JSONOutput bool JSONOutput bool
InputFile string InputFile string
Method string Method string
Silent bool Silent bool
Version bool Version bool
Verbose bool Verbose bool
NoColor bool NoColor bool
OutputServerHeader bool OutputServerHeader bool
responseInStdout bool responseInStdout bool
FollowHostRedirects bool FollowHostRedirects bool
} }
// ParseOptions parses the command line options for application // ParseOptions parses the command line options for application