From 407a89acd2cb61d04df8e3d6a77f8e426fc2ff6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Zamanillo?= Date: Sat, 19 Sep 2020 17:55:05 +0200 Subject: [PATCH] Fix for return workflow results Fixes #307 --- internal/runner/processor.go | 22 +++++++++++++++++++--- internal/runner/runner.go | 3 +-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/runner/processor.go b/internal/runner/processor.go index 03cc4839..1bc722c8 100644 --- a/internal/runner/processor.go +++ b/internal/runner/processor.go @@ -118,12 +118,14 @@ func (r *Runner) processTemplateWithList(ctx context.Context, p progress.IProgre } // ProcessWorkflowWithList coming from stdin or list of targets -func (r *Runner) processWorkflowWithList(p progress.IProgress, workflow *workflows.Workflow) { +func (r *Runner) processWorkflowWithList(p progress.IProgress, workflow *workflows.Workflow) bool { + result := false + workflowTemplatesList, err := r.preloadWorkflowTemplates(p, workflow) if err != nil { gologger.Warningf("Could not preload templates for workflow %s: %s\n", workflow.ID, err) - return + return result } logicBytes := []byte(workflow.Logic) @@ -143,13 +145,18 @@ func (r *Runner) processWorkflowWithList(p progress.IProgress, workflow *workflo script := tengo.NewScript(logicBytes) script.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...)) + variables := make(map[string]*workflows.NucleiVar) + for _, workflowTemplate := range *workflowTemplatesList { - err := script.Add(workflowTemplate.Name, &workflows.NucleiVar{Templates: workflowTemplate.Templates, URL: targetURL}) + name := workflowTemplate.Name + variable := &workflows.NucleiVar{Templates: workflowTemplate.Templates, URL: targetURL} + err := script.Add(name, variable) if err != nil { gologger.Errorf("Could not initialize script for workflow '%s': %s\n", workflow.ID, err) continue } + variables[name] = variable } _, err := script.RunContext(context.Background()) @@ -157,11 +164,20 @@ func (r *Runner) processWorkflowWithList(p progress.IProgress, workflow *workflo gologger.Errorf("Could not execute workflow '%s': %s\n", workflow.ID, err) } + for _, variable := range variables { + result = variable.IsFalsy() + if result { + break + } + } + <-r.limiter }(targetURL) } wg.Wait() + + return result } func (r *Runner) preloadWorkflowTemplates(p progress.IProgress, workflow *workflows.Workflow) (*[]workflowTemplates, error) { diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 2d20e608..f548c5a4 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -254,8 +254,7 @@ func (r *Runner) RunEnumeration() { results.Or(r.processTemplateWithList(ctx, p, tt, request)) } case *workflows.Workflow: - workflow := template.(*workflows.Workflow) - r.processWorkflowWithList(p, workflow) + results.Or(r.processWorkflowWithList(p, template.(*workflows.Workflow))) } }(t) }