mirror of https://github.com/daffainfo/nuclei.git
Template folder exists changes (#1825)
parent
5ddc37e8d7
commit
ce79a8dc57
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
|
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
|
||||||
|
@ -13,6 +14,8 @@ func getTemplatePath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var templatesPathTestCases = map[string]testutils.TestCase{
|
var templatesPathTestCases = map[string]testutils.TestCase{
|
||||||
|
//template folder path issue
|
||||||
|
"http/get.yaml": &folderPathTemplateTest{},
|
||||||
//cwd
|
//cwd
|
||||||
"./dns/cname-fingerprint.yaml": &cwdTemplateTest{},
|
"./dns/cname-fingerprint.yaml": &cwdTemplateTest{},
|
||||||
//relative path
|
//relative path
|
||||||
|
@ -25,15 +28,10 @@ type cwdTemplateTest struct{}
|
||||||
|
|
||||||
// Execute executes a test case and returns an error if occurred
|
// Execute executes a test case and returns an error if occurred
|
||||||
func (h *cwdTemplateTest) Execute(filePath string) error {
|
func (h *cwdTemplateTest) Execute(filePath string) error {
|
||||||
var routerErr error
|
|
||||||
|
|
||||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if routerErr != nil {
|
|
||||||
return routerErr
|
|
||||||
}
|
|
||||||
return expectResultsCount(results, 1)
|
return expectResultsCount(results, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,15 +39,10 @@ type relativePathTemplateTest struct{}
|
||||||
|
|
||||||
// Execute executes a test case and returns an error if occurred
|
// Execute executes a test case and returns an error if occurred
|
||||||
func (h *relativePathTemplateTest) Execute(filePath string) error {
|
func (h *relativePathTemplateTest) Execute(filePath string) error {
|
||||||
var routerErr error
|
|
||||||
|
|
||||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if routerErr != nil {
|
|
||||||
return routerErr
|
|
||||||
}
|
|
||||||
return expectResultsCount(results, 1)
|
return expectResultsCount(results, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +50,23 @@ type absolutePathTemplateTest struct{}
|
||||||
|
|
||||||
// Execute executes a test case and returns an error if occurred
|
// Execute executes a test case and returns an error if occurred
|
||||||
func (h *absolutePathTemplateTest) Execute(filePath string) error {
|
func (h *absolutePathTemplateTest) Execute(filePath string) error {
|
||||||
var routerErr error
|
|
||||||
|
|
||||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if routerErr != nil {
|
|
||||||
return routerErr
|
|
||||||
}
|
|
||||||
return expectResultsCount(results, 1)
|
return expectResultsCount(results, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type folderPathTemplateTest struct{}
|
||||||
|
|
||||||
|
// Execute executes a test case and returns an error if occurred
|
||||||
|
func (h *folderPathTemplateTest) Execute(filePath string) error {
|
||||||
|
results, err := testutils.RunNucleiBinaryAndGetCombinedOutput(debug, []string{"-t", filePath, "-target", "http://example.com"})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.Contains(results, "installing") {
|
||||||
|
return fmt.Errorf("couldn't find template path,re-installing")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (r *Runner) updateTemplates() error { // TODO this method does more than ju
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var noTemplatesFound bool
|
var noTemplatesFound bool
|
||||||
if !fileutil.FileExists(r.templatesConfig.TemplatesDirectory) {
|
if !fileutil.FolderExists(r.templatesConfig.TemplatesDirectory) {
|
||||||
noTemplatesFound = true
|
noTemplatesFound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,21 @@ func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, debug bool, args
|
||||||
}
|
}
|
||||||
return matches[0][1], nil
|
return matches[0][1], nil
|
||||||
}
|
}
|
||||||
|
func RunNucleiBinaryAndGetCombinedOutput(debug bool, args []string) (string, error) {
|
||||||
|
cmd := exec.Command("./nuclei", args...)
|
||||||
|
if debug {
|
||||||
|
cmd.Args = append(cmd.Args, "-debug")
|
||||||
|
fmt.Println(cmd.String())
|
||||||
|
}
|
||||||
|
data, err := cmd.CombinedOutput()
|
||||||
|
if debug {
|
||||||
|
fmt.Println(string(data))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(data), nil
|
||||||
|
}
|
||||||
|
|
||||||
// TestCase is a single integration test case
|
// TestCase is a single integration test case
|
||||||
type TestCase interface {
|
type TestCase interface {
|
||||||
|
|
Loading…
Reference in New Issue