@@ -97,6 +97,7 @@ type Runner struct {
9797 tmpDir string
9898 parser parser.Parser
9999 httpApiEndpoint * httpapi.Server
100+ fuzzStats * fuzzStats.Tracker
100101 dastServer * server.DASTServer
101102}
102103
@@ -244,14 +245,6 @@ func New(options *types.Options) (*Runner, error) {
244245 }
245246 runner .inputProvider = inputProvider
246247
247- // Create the output file if asked
248- outputWriter , err := output .NewStandardWriter (options )
249- if err != nil {
250- return nil , errors .Wrap (err , "could not create output file" )
251- }
252- // setup a proxy writer to automatically upload results to PDCP
253- runner .output = runner .setupPDCPUpload (outputWriter )
254-
255248 if options .JSONL && options .EnableProgressBar {
256249 options .StatsJSON = true
257250 }
@@ -344,6 +337,42 @@ func New(options *types.Options) (*Runner, error) {
344337 runner .tmpDir = tmpDir
345338 }
346339
340+ if options .DASTReport || options .DASTServer {
341+ var err error
342+ runner .fuzzStats , err = fuzzStats .NewTracker ()
343+ if err != nil {
344+ return nil , errors .Wrap (err , "could not create fuzz stats db" )
345+ }
346+ if ! options .DASTServer {
347+ dastServer , err := server .NewStatsServer (runner .fuzzStats )
348+ if err != nil {
349+ return nil , errors .Wrap (err , "could not create dast server" )
350+ }
351+ runner .dastServer = dastServer
352+ }
353+ }
354+
355+ // Create the output file if asked
356+ outputWriter , err := output .NewStandardWriter (options )
357+ if err != nil {
358+ return nil , errors .Wrap (err , "could not create output file" )
359+ }
360+ if runner .fuzzStats != nil {
361+ outputWriter .RequestHook = func (request * output.JSONLogRequest ) {
362+ if request .Error == "none" || request .Error == "" {
363+ return
364+ }
365+ runner .fuzzStats .RecordErrorEvent (fuzzStats.ErrorEvent {
366+ TemplateID : request .Template ,
367+ URL : request .Input ,
368+ Error : request .Error ,
369+ })
370+ }
371+ }
372+
373+ // setup a proxy writer to automatically upload results to PDCP
374+ runner .output = runner .setupPDCPUpload (outputWriter )
375+
347376 return runner , nil
348377}
349378
@@ -453,6 +482,7 @@ func (r *Runner) RunEnumeration() error {
453482 Colorizer : r .colorizer ,
454483 Parser : r .parser ,
455484 TemporaryDirectory : r .tmpDir ,
485+ FuzzStatsDB : r .fuzzStats ,
456486 }
457487 dastServer , err := server .New (& server.Options {
458488 Address : r .options .DASTServerAddress ,
@@ -513,13 +543,6 @@ func (r *Runner) RunEnumeration() error {
513543 FuzzParamsFrequency : fuzzFreqCache ,
514544 GlobalMatchers : globalmatchers .New (),
515545 }
516- if r .options .DASTScanName != "" {
517- var err error
518- executorOpts .FuzzStatsDB , err = fuzzStats .NewTracker (r .options .DASTScanName )
519- if err != nil {
520- return errors .Wrap (err , "could not create fuzz stats db" )
521- }
522- }
523546
524547 if config .DefaultConfig .IsDebugArgEnabled (config .DebugExportURLPattern ) {
525548 // Go StdLib style experimental/debug feature switch
@@ -663,6 +686,12 @@ func (r *Runner) RunEnumeration() error {
663686 Retries : r .options .Retries ,
664687 }, "" )
665688
689+ if r .dastServer != nil {
690+ if err := r .dastServer .Start (); err != nil {
691+ r .dastServer .Start ()
692+ }
693+ }
694+
666695 enumeration := false
667696 var results * atomic.Bool
668697 results , err = r .runStandardEnumeration (executorOpts , store , executorEngine )
0 commit comments