mirror of
https://github.com/SleepingBag945/dddd.git
synced 2025-06-21 18:30:15 +00:00
87 lines
1.9 KiB
Go
Executable File
87 lines
1.9 KiB
Go
Executable File
package testutils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// RunNucleiAndGetResults returns a list of results for a template
|
|
func RunHttpxAndGetResults(url string, debug bool, extra ...string) ([]string, error) {
|
|
cmd := exec.Command("bash", "-c")
|
|
cmdLine := `echo "` + url + `" | ./httpx `
|
|
cmdLine += strings.Join(extra, " ")
|
|
if debug {
|
|
cmdLine += " -debug"
|
|
cmd.Stderr = os.Stderr
|
|
} else {
|
|
cmdLine += " -silent"
|
|
}
|
|
|
|
cmd.Args = append(cmd.Args, cmdLine)
|
|
|
|
data, err := cmd.Output()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
parts := []string{}
|
|
items := strings.Split(string(data), "\n")
|
|
for _, i := range items {
|
|
if i != "" {
|
|
parts = append(parts, i)
|
|
}
|
|
}
|
|
return parts, nil
|
|
}
|
|
|
|
// RunNucleiAndGetResults returns a list of results for a template
|
|
func RunHttpxAndGetCombinedResults(url string, debug bool, extra ...string) (string, error) {
|
|
cmd := exec.Command("bash", "-c")
|
|
cmdLine := `echo "` + url + `" | ./httpx `
|
|
cmdLine += strings.Join(extra, " ")
|
|
if debug {
|
|
cmdLine += " -debug"
|
|
} else {
|
|
cmdLine += " -silent"
|
|
}
|
|
|
|
cmd.Args = append(cmd.Args, cmdLine)
|
|
data, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
}
|
|
func RunHttpxBinaryAndGetResults(target string, httpxBinary string, debug bool, args []string) ([]string, error) {
|
|
cmd := exec.Command("bash", "-c")
|
|
cmdLine := fmt.Sprintf(`echo %s | %s `, target, httpxBinary)
|
|
cmdLine += strings.Join(args, " ")
|
|
if debug {
|
|
cmdLine += " -debug"
|
|
cmd.Stderr = os.Stderr
|
|
} else {
|
|
cmdLine += " -silent"
|
|
}
|
|
|
|
cmd.Args = append(cmd.Args, cmdLine)
|
|
data, err := cmd.Output()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
parts := []string{}
|
|
items := strings.Split(string(data), "\n")
|
|
for _, i := range items {
|
|
if i != "" {
|
|
parts = append(parts, i)
|
|
}
|
|
}
|
|
return parts, nil
|
|
}
|
|
|
|
// TestCase is a single integration test case
|
|
type TestCase interface {
|
|
// Execute executes a test case and returns any errors if occurred
|
|
Execute() error
|
|
}
|