Debug req/resp mode support

This commit is contained in:
Ice3man543 2021-01-12 17:18:08 +05:30
parent 92b4495f84
commit ab2bb0226f
6 changed files with 16 additions and 10 deletions

View File

@ -76,7 +76,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&options.Target, "target", "", "Target is a single target to scan using template") rootCmd.PersistentFlags().StringVar(&options.Target, "target", "", "Target is a single target to scan using template")
rootCmd.PersistentFlags().StringSliceVarP(&options.Templates, "templates", "t", []string{}, "Template input dir/file/files to run on host. Can be used multiple times. Supports globbing.") rootCmd.PersistentFlags().StringSliceVarP(&options.Templates, "templates", "t", []string{}, "Template input dir/file/files to run on host. Can be used multiple times. Supports globbing.")
rootCmd.PersistentFlags().StringSliceVar(&options.ExcludedTemplates, "exclude", []string{}, "Template input dir/file/files to exclude. Can be used multiple times. Supports globbing.") rootCmd.PersistentFlags().StringSliceVar(&options.ExcludedTemplates, "exclude", []string{}, "Template input dir/file/files to exclude. Can be used multiple times. Supports globbing.")
rootCmd.PersistentFlags().StringVar(&options.Severity, "severity", "", "Filter templates based on their severity and only run the matching ones. Comma-separated values can be used to specify multiple severities.") rootCmd.PersistentFlags().StringSliceVar(&options.Severity, "severity", []string{}, "Filter templates based on their severity and only run the matching ones. Comma-separated values can be used to specify multiple severities.")
rootCmd.PersistentFlags().StringVarP(&options.Targets, "list", "l", "", "List of URLs to run templates on") rootCmd.PersistentFlags().StringVarP(&options.Targets, "list", "l", "", "List of URLs to run templates on")
rootCmd.PersistentFlags().StringVarP(&options.Output, "output", "o", "", "File to write output to (optional)") rootCmd.PersistentFlags().StringVarP(&options.Output, "output", "o", "", "File to write output to (optional)")
rootCmd.PersistentFlags().StringVar(&options.ProxyURL, "proxy-url", "", "URL of the proxy server") rootCmd.PersistentFlags().StringVar(&options.ProxyURL, "proxy-url", "", "URL of the proxy server")
@ -90,6 +90,8 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&options.RandomAgent, "random-agent", false, "Use randomly selected HTTP User-Agent header value") rootCmd.PersistentFlags().BoolVar(&options.RandomAgent, "random-agent", false, "Use randomly selected HTTP User-Agent header value")
rootCmd.PersistentFlags().StringSliceVarP(&options.CustomHeaders, "header", "H", []string{}, "Custom Header.") rootCmd.PersistentFlags().StringSliceVarP(&options.CustomHeaders, "header", "H", []string{}, "Custom Header.")
rootCmd.PersistentFlags().BoolVar(&options.Debug, "debug", false, "Allow debugging of request/responses") rootCmd.PersistentFlags().BoolVar(&options.Debug, "debug", false, "Allow debugging of request/responses")
rootCmd.PersistentFlags().BoolVar(&options.DebugRequests, "debug-req", false, "Allow debugging of request")
rootCmd.PersistentFlags().BoolVar(&options.DebugResponse, "debug-resp", false, "Allow debugging of response")
rootCmd.PersistentFlags().BoolVar(&options.UpdateTemplates, "update-templates", false, "Update Templates updates the installed templates (optional)") rootCmd.PersistentFlags().BoolVar(&options.UpdateTemplates, "update-templates", false, "Update Templates updates the installed templates (optional)")
rootCmd.PersistentFlags().StringVar(&options.TraceLogFile, "trace-log", "", "File to write sent requests trace log") rootCmd.PersistentFlags().StringVar(&options.TraceLogFile, "trace-log", "", "File to write sent requests trace log")
rootCmd.PersistentFlags().StringVar(&options.TemplatesDirectory, "update-directory", templatesDirectory, "Directory to use for storing nuclei-templates") rootCmd.PersistentFlags().StringVar(&options.TemplatesDirectory, "update-directory", templatesDirectory, "Directory to use for storing nuclei-templates")

View File

@ -31,7 +31,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
return errors.Wrap(err, "could not build request") return errors.Wrap(err, "could not build request")
} }
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugRequests {
gologger.Info().Str("domain", domain).Msgf("[%s] Dumped DNS request for %s", r.options.TemplateID, domain) gologger.Info().Str("domain", domain).Msgf("[%s] Dumped DNS request for %s", r.options.TemplateID, domain)
fmt.Fprintf(os.Stderr, "%s\n", compiledRequest.String()) fmt.Fprintf(os.Stderr, "%s\n", compiledRequest.String())
} }
@ -48,7 +48,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
r.options.Output.Request(r.options.TemplateID, domain, "dns", err) r.options.Output.Request(r.options.TemplateID, domain, "dns", err)
gologger.Verbose().Msgf("[%s] Sent DNS request to %s", r.options.TemplateID, domain) gologger.Verbose().Msgf("[%s] Sent DNS request to %s", r.options.TemplateID, domain)
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugResponse {
gologger.Debug().Msgf("[%s] Dumped DNS response for %s", r.options.TemplateID, domain) gologger.Debug().Msgf("[%s] Dumped DNS response for %s", r.options.TemplateID, domain)
fmt.Fprintf(os.Stderr, "%s\n", resp.String()) fmt.Fprintf(os.Stderr, "%s\n", resp.String())
} }

View File

@ -41,7 +41,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
} }
dataStr := tostring.UnsafeToString(buffer) dataStr := tostring.UnsafeToString(buffer)
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugRequests {
gologger.Info().Msgf("[%s] Dumped file request for %s", r.options.TemplateID, data) gologger.Info().Msgf("[%s] Dumped file request for %s", r.options.TemplateID, data)
fmt.Fprintf(os.Stderr, "%s\n", dataStr) fmt.Fprintf(os.Stderr, "%s\n", dataStr)
} }

View File

@ -223,13 +223,13 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
dumpedRequest []byte dumpedRequest []byte
fromcache bool fromcache bool
) )
if r.options.Options.Debug || r.options.ProjectFile != nil { if r.options.Options.Debug || r.options.ProjectFile != nil || r.options.Options.DebugRequests {
dumpedRequest, err = dump(request, reqURL) dumpedRequest, err = dump(request, reqURL)
if err != nil { if err != nil {
return err return err
} }
} }
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugRequests {
gologger.Info().Msgf("[%s] Dumped HTTP request for %s\n\n", r.options.TemplateID, reqURL) gologger.Info().Msgf("[%s] Dumped HTTP request for %s\n\n", r.options.TemplateID, reqURL)
fmt.Fprintf(os.Stderr, "%s", string(dumpedRequest)) fmt.Fprintf(os.Stderr, "%s", string(dumpedRequest))
} }
@ -279,7 +279,7 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
duration := time.Since(timeStart) duration := time.Since(timeStart)
// Dump response - Step 1 - Decompression not yet handled // Dump response - Step 1 - Decompression not yet handled
var dumpedResponse []byte var dumpedResponse []byte
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugResponse {
var dumpErr error var dumpErr error
dumpedResponse, dumpErr = httputil.DumpResponse(resp, true) dumpedResponse, dumpErr = httputil.DumpResponse(resp, true)
if dumpErr != nil { if dumpErr != nil {
@ -305,7 +305,7 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
} }
// Dump response - step 2 - replace gzip body with deflated one or with itself (NOP operation) // Dump response - step 2 - replace gzip body with deflated one or with itself (NOP operation)
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugResponse {
dumpedResponse = bytes.ReplaceAll(dumpedResponse, dataOrig, data) dumpedResponse = bytes.ReplaceAll(dumpedResponse, dataOrig, data)
gologger.Info().Msgf("[%s] Dumped HTTP response for %s\n\n", r.options.TemplateID, formedURL) gologger.Info().Msgf("[%s] Dumped HTTP response for %s\n\n", r.options.TemplateID, formedURL)
fmt.Fprintf(os.Stderr, "%s\n", string(dumpedResponse)) fmt.Fprintf(os.Stderr, "%s\n", string(dumpedResponse))

View File

@ -97,7 +97,7 @@ func (r *Request) executeAddress(actualAddress, address, input string, callback
return errors.Wrap(err, "could not write request to server") return errors.Wrap(err, "could not write request to server")
} }
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugRequests {
gologger.Info().Str("address", actualAddress).Msgf("[%s] Dumped Network request for %s", r.options.TemplateID, actualAddress) gologger.Info().Str("address", actualAddress).Msgf("[%s] Dumped Network request for %s", r.options.TemplateID, actualAddress)
fmt.Fprintf(os.Stderr, "%s\n", reqBuilder.String()) fmt.Fprintf(os.Stderr, "%s\n", reqBuilder.String())
@ -114,7 +114,7 @@ func (r *Request) executeAddress(actualAddress, address, input string, callback
n, _ := conn.Read(buffer) n, _ := conn.Read(buffer)
resp := string(buffer[:n]) resp := string(buffer[:n])
if r.options.Options.Debug { if r.options.Options.Debug || r.options.Options.DebugResponse {
gologger.Debug().Msgf("[%s] Dumped Network response for %s", r.options.TemplateID, actualAddress) gologger.Debug().Msgf("[%s] Dumped Network response for %s", r.options.TemplateID, actualAddress)
fmt.Fprintf(os.Stderr, "%s\n", resp) fmt.Fprintf(os.Stderr, "%s\n", resp)
} }

View File

@ -8,6 +8,10 @@ type Options struct {
Metrics bool Metrics bool
// Debug mode allows debugging request/responses for the engine // Debug mode allows debugging request/responses for the engine
Debug bool Debug bool
// DebugRequests mode allows debugging request for the engine
DebugRequests bool
// DebugResponse mode allows debugging response for the engine
DebugResponse bool
// Silent suppresses any extra text and only writes found URLs on screen. // Silent suppresses any extra text and only writes found URLs on screen.
Silent bool Silent bool
// Version specifies if we should just show version and exit // Version specifies if we should just show version and exit