2020-08-29 13:26:11 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
2020-12-29 12:32:45 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
|
|
|
|
"github.com/remeh/sizedwaitgroup"
|
|
|
|
"go.uber.org/atomic"
|
2020-08-29 13:26:11 +00:00
|
|
|
)
|
|
|
|
|
2020-12-29 12:32:45 +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
|
|
|
|
2020-12-29 12:32:45 +00:00
|
|
|
r.hostMap.Scan(func(k, _ []byte) error {
|
2020-11-15 23:40:32 +00:00
|
|
|
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()
|
2020-12-29 12:32:45 +00:00
|
|
|
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)
|
2020-11-15 23:40:32 +00:00
|
|
|
return nil
|
|
|
|
})
|
2020-08-29 13:26:11 +00:00
|
|
|
wg.Wait()
|
2020-12-29 12:32:45 +00:00
|
|
|
return results.Load()
|
2020-08-29 13:26:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 12:32:45 +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
|
|
|
|
2020-12-29 12:32:45 +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()
|
2020-12-29 12:32:45 +00:00
|
|
|
match, err := template.RunWorkflow(URL)
|
2020-08-29 13:26:11 +00:00
|
|
|
if err != nil {
|
2020-12-29 12:32:45 +00:00
|
|
|
gologger.Warning().Msgf("[%s] Could not execute step: %s\n", r.colorizer.BrightBlue(template.ID), err)
|
|
|
|
} else {
|
|
|
|
results.CAS(false, match)
|
2020-09-19 15:55:05 +00:00
|
|
|
}
|
2020-12-29 12:32:45 +00:00
|
|
|
}(URL)
|
2020-11-15 23:40:32 +00:00
|
|
|
return nil
|
|
|
|
})
|
2020-08-29 13:26:11 +00:00
|
|
|
wg.Wait()
|
2020-12-29 12:32:45 +00:00
|
|
|
return results.Load()
|
2020-08-29 13:26:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 10:08:14 +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) {
|
2020-12-29 10:08:14 +00:00
|
|
|
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)
|
|
|
|
}
|