2022-03-08 09:50:08 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2022-04-11 01:29:22 -05:00
|
|
|
"strings"
|
2022-03-08 09:50:08 -06:00
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
|
2022-03-08 09:50:08 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func getTemplatePath() string {
|
2023-04-19 21:58:48 +05:30
|
|
|
return config.DefaultConfig.TemplatesDirectory
|
2022-03-08 09:50:08 -06:00
|
|
|
}
|
|
|
|
|
|
2023-07-28 18:50:57 +03:00
|
|
|
var templatesPathTestCases = []TestCaseInfo{
|
2022-04-11 01:29:22 -05:00
|
|
|
//template folder path issue
|
2023-08-04 20:21:22 +05:30
|
|
|
{Path: "protocols/http/get.yaml", TestCase: &folderPathTemplateTest{}},
|
2022-03-08 09:50:08 -06:00
|
|
|
//cwd
|
2023-09-02 14:34:05 +05:30
|
|
|
{Path: "./dns/detect-dangling-cname.yaml", TestCase: &cwdTemplateTest{}},
|
2022-03-08 09:50:08 -06:00
|
|
|
//relative path
|
2023-07-30 15:32:50 +08:00
|
|
|
{Path: "dns/dns-saas-service-detection.yaml", TestCase: &relativePathTemplateTest{}},
|
2022-03-08 09:50:08 -06:00
|
|
|
//absolute path
|
2023-07-30 15:32:50 +08:00
|
|
|
{Path: fmt.Sprintf("%v/dns/dns-saas-service-detection.yaml", getTemplatePath()), TestCase: &absolutePathTemplateTest{}},
|
2022-03-08 09:50:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type cwdTemplateTest struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *cwdTemplateTest) Execute(filePath string) error {
|
2023-10-17 17:44:13 +05:30
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug, "-ms")
|
2022-03-08 09:50:08 -06:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type relativePathTemplateTest struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *relativePathTemplateTest) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type absolutePathTemplateTest struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *absolutePathTemplateTest) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
2022-04-11 01:29:22 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|