projectdiscovery / nuclei

Fast and customizable vulnerability scanner based on simple YAML based DSL.
https://docs.projectdiscovery.io/tools/nuclei
MIT License
18.89k stars 2.38k forks source link

Execute nuclei context deadline exceeded #5207

Open mnd5756242 opened 2 months ago

mnd5756242 commented 2 months ago

The following is the execution code

  1. InitExecutorOptions `func InitExecutorOptions(rate int, timeout int) (err error) {

    gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug) options := types.DefaultOptions() options.Timeout = 18 mockProgress := &testutils.MockProgressClient{} reportingClient, _ := reporting.New(&reporting.Options{}, "") defer reportingClient.Close()

    outputWriter := testutils.NewMockOutputWriter(options.OmitTemplate) //outputWriter := testutils.NewMockOutputWriter(options.OmitTemplate) outputWriter.WriteCallback = func(event *output.ResultEvent) { logger.Infof("load POC: %v", event.Info.Name) if event.MatcherStatus { logger.Infof(": %v", event.TemplateID) result := &goby.Result{ Source: "nuclei", Level: event.Info.SeverityHolder.Severity.String(), PocName: event.TemplateID, Extractors: strings.Join(event.ExtractedResults, "\n"), } Results = append(Results, result) } }

    = protocolstate.Init(options) = protocolinit.Init(options)

    interactOpts := interactsh.DefaultOptions(outputWriter, reportingClient, mockProgress) interactOpts.CooldownPeriod = 1 time.Second interactOpts.PollDuration = 2 time.Second interactClient, err := interactsh.New(interactOpts) if err != nil { return } defer interactClient.Close()

    catalog := disk.NewCatalog("")

    ExecuterOptions = protocols.ExecutorOptions{ Output: outputWriter, Options: options, Progress: mockProgress, Catalog: catalog, IssuesClient: reportingClient, Interactsh: interactClient, RateLimiter: ratelimit.New(context.Background(), 150, time.Second), //HostErrorsCache: cache, Colorizer: aurora.NewAurora(true), ResumeCfg: types.NewResumeCfg(), }

    return }`

  2. func (r Runner) ExecuteNucleiPoc(target string, poc nuclei.Template) (results []*output.ResultEvent, err error) { e := poc.Executer ctx := scan.NewScanContext(contextargs.NewWithInput(target))

    ctx.OnResult = func(event output.InternalWrappedEvent) { // 将 InternalWrappedEvent 转换为 ResultEvent if resultValue, ok := event.InternalEvent["result"]; ok { if result, ok := resultValue.(output.ResultEvent); ok { results = append(results, result) } } }

    results, err = e.ExecuteWithResults(ctx) if err != nil { return nil, err }

    return results, err }

An error will be reported during batch execution: [aem-gql-servlet] Could not execute request for http://xb7wk3.jjdsb-per.buzz: context deadline exceeded

I am using the nuclei v3 version. What causes this?

Mzack9999 commented 2 months ago

@mnd5756242 I tried to build the example that you provided, but there is some syntax error. I would recommend to attempt using the SDK to run nuclei as a library (see examples at https://github.com/projectdiscovery/nuclei/tree/dev/examples)

mnd5756242 commented 2 months ago

@Mzack9999 The entire process execution is like this

The first is the initial configuration: optionsError := nuclei.InitExecutorOptions(150, 10)

The definition of goby.Result in the InitExecutorOptions code is as follows type Result struct { Source string Level string PocName string Extractors string }

Load the template and store it in the map. The code for loading the template is as follows: `type Template = templates.Template

func LoadOnePoc(data string) (Template, error) { var poc Template plugCode, _ := base64.StdEncoding.DecodeString(data) poc, err := templates.ParseTemplateFromReader(bytes.NewReader(plugCode), nil, ExecuterOptions) if err != nil { logger.Error(err) return nil, err } return poc, nil }`

Then it traverses the stored template map and calls the ExecuteNucleiPoc function in batches. The problem of context deadline exceeded occurs, and after the context deadline exceeded occurs, all template requests time out.

So I want to ask if there is no configuration reason that causes context deadline exceeded.