nuclei icon indicating copy to clipboard operation
nuclei copied to clipboard

Nuclei SDK Stats don't get to 100% and never stop printing even after the scan is done

Open stan-threatmate opened this issue 2 years ago • 0 comments

Nuclei version:

github.com/projectdiscovery/nuclei/v3 v3.0.3

Current Behavior:

I setup a stats ticker as follows:

		statsTicker, err := progress.NewStatsTicker(5, true, false, false, 11111)
		if err != nil {
			return nil, fmt.Errorf("failed to create the progress: %w", err)
		}
		defer statsTicker.Stop()
		nuclei.UseStatsWriter(statsTicker)
		opts = append(opts, nuclei.EnableStatsWithOpts(nuclei.StatsOptions{
			Interval:         5,
			JSON:             false,
			MetricServerPort: 11111,
		}))

And run nuclei like this

	ne, err := nuclei.NewNucleiEngine(opts...)
	if err != nil {
		return nil, fmt.Errorf("error starting the nuclei engine: %w", err)
	}
	defer ne.Close()

	ne.LoadTargets(n.LiveHosts, n.ProbeNonHttpTargets)
	err = ne.LoadAllTemplates()
	if err != nil {
		return nil, fmt.Errorf("error loading the nuclei templates: %w", err)
	}
	var events []*output.ResultEvent
	err = ne.ExecuteWithCallback(func(event *output.ResultEvent) {
		events = append(events, event)
	})
	if err != nil {
		return nil, fmt.Errorf("error executing the nuclei scan: %w", err)
	}

The stats print but they never go to 100% and after the function returns the stats continue to print since they are handled in a different goroutine. ne.Close() should stop that go routine. Also there should be a way to cancel the scan by accepting a context which should also stop the stats.

Expected Behavior:

After ne.Close() is called the stats should stop printing.

Steps To Reproduce:

Use the code above to reproduce the issue.

stan-threatmate avatar Nov 19 '23 14:11 stan-threatmate