mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 18:15:28 +00:00
Debug req/resp mode support
This commit is contained in:
parent
92b4495f84
commit
ab2bb0226f
@ -76,7 +76,7 @@ func init() {
|
||||
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().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.Output, "output", "o", "", "File to write output to (optional)")
|
||||
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().StringSliceVarP(&options.CustomHeaders, "header", "H", []string{}, "Custom Header.")
|
||||
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().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")
|
||||
|
||||
@ -31,7 +31,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", resp.String())
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
|
||||
}
|
||||
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)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", dataStr)
|
||||
}
|
||||
|
||||
@ -223,13 +223,13 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
|
||||
dumpedRequest []byte
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
fmt.Fprintf(os.Stderr, "%s", string(dumpedRequest))
|
||||
}
|
||||
@ -279,7 +279,7 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
|
||||
duration := time.Since(timeStart)
|
||||
// Dump response - Step 1 - Decompression not yet handled
|
||||
var dumpedResponse []byte
|
||||
if r.options.Options.Debug {
|
||||
if r.options.Options.Debug || r.options.Options.DebugResponse {
|
||||
var dumpErr error
|
||||
dumpedResponse, dumpErr = httputil.DumpResponse(resp, true)
|
||||
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)
|
||||
if r.options.Options.Debug {
|
||||
if r.options.Options.Debug || r.options.Options.DebugResponse {
|
||||
dumpedResponse = bytes.ReplaceAll(dumpedResponse, dataOrig, data)
|
||||
gologger.Info().Msgf("[%s] Dumped HTTP response for %s\n\n", r.options.TemplateID, formedURL)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", string(dumpedResponse))
|
||||
|
||||
@ -97,7 +97,7 @@ func (r *Request) executeAddress(actualAddress, address, input string, callback
|
||||
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)
|
||||
|
||||
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)
|
||||
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)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", resp)
|
||||
}
|
||||
|
||||
@ -8,6 +8,10 @@ type Options struct {
|
||||
Metrics bool
|
||||
// Debug mode allows debugging request/responses for the engine
|
||||
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 bool
|
||||
// Version specifies if we should just show version and exit
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user