nuclei/v2/internal/runner/processor.go

69 lines
1.8 KiB
Go
Raw Normal View History

2020-08-29 13:26:11 +00:00
package runner
import (
"fmt"
"os"
"path"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/remeh/sizedwaitgroup"
"go.uber.org/atomic"
2020-08-29 13:26:11 +00:00
)
// processTemplateWithList process a template on the URL list
func (r *Runner) processTemplateWithList(template *templates.Template) bool {
results := &atomic.Bool{}
2020-10-12 18:15:21 +00:00
wg := sizedwaitgroup.New(r.options.BulkSize)
2020-08-29 13:26:11 +00:00
r.hostMap.Scan(func(k, _ []byte) error {
URL := string(k)
2020-10-12 18:15:21 +00:00
wg.Add()
2020-08-29 13:26:11 +00:00
go func(URL string) {
defer wg.Done()
match, err := template.Executer.Execute(URL)
if err != nil {
gologger.Warning().Msgf("[%s] Could not execute step: %s\n", r.colorizer.BrightBlue(template.ID), err)
} else {
results.CAS(false, match)
2020-08-29 13:26:11 +00:00
}
2020-10-09 21:11:07 +00:00
}(URL)
return nil
})
2020-08-29 13:26:11 +00:00
wg.Wait()
return results.Load()
2020-08-29 13:26:11 +00:00
}
// processTemplateWithList process a template on the URL list
func (r *Runner) processWorkflowWithList(template *templates.Template) bool {
results := &atomic.Bool{}
2020-10-12 18:15:21 +00:00
wg := sizedwaitgroup.New(r.options.BulkSize)
2020-08-29 13:26:11 +00:00
r.hostMap.Scan(func(k, _ []byte) error {
URL := string(k)
wg.Add()
go func(URL string) {
2020-08-29 13:26:11 +00:00
defer wg.Done()
match, err := template.RunWorkflow(URL)
2020-08-29 13:26:11 +00:00
if err != nil {
gologger.Warning().Msgf("[%s] Could not execute step: %s\n", r.colorizer.BrightBlue(template.ID), err)
} else {
results.CAS(false, match)
}
}(URL)
return nil
})
2020-08-29 13:26:11 +00:00
wg.Wait()
return results.Load()
2020-08-29 13:26:11 +00:00
}
// resolvePathWithBaseFolder resolves a path with the base folder
2020-08-29 13:26:11 +00:00
func resolvePathWithBaseFolder(baseFolder, templateName string) (string, error) {
templatePath := path.Join(baseFolder, templateName)
if _, err := os.Stat(templatePath); !os.IsNotExist(err) {
gologger.Debug().Msgf("Found template in current directory: %s\n", templatePath)
2020-08-29 13:26:11 +00:00
return templatePath, nil
}
return "", fmt.Errorf("no such path found: %s", templateName)
}