mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 23:05:26 +00:00
* chore: fix non-constant fmt string in call Signed-off-by: Dwi Siswanto <git@dw1.io> * build: bump all direct modules Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(hosterrorscache): update import path Signed-off-by: Dwi Siswanto <git@dw1.io> * fix(charts): break changes Signed-off-by: Dwi Siswanto <git@dw1.io> * build: pinned `github.com/zmap/zcrypto` to v0.0.0-20240512203510-0fef58d9a9db Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: golangci-lint auto fixes Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: satisfy lints Signed-off-by: Dwi Siswanto <git@dw1.io> * build: migrate `github.com/xanzy/go-gitlab` => `gitlab.com/gitlab-org/api/client-go` Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(json): update build constraints Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: dont panicking on close err Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package generators
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
pkgTypes "github.com/projectdiscovery/nuclei/v3/pkg/types"
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
// loadPayloads loads the input payloads from a map to a data map
|
|
func (generator *PayloadGenerator) loadPayloads(payloads map[string]interface{}, templatePath string) (map[string][]string, error) {
|
|
loadedPayloads := make(map[string][]string)
|
|
|
|
for name, payload := range payloads {
|
|
switch pt := payload.(type) {
|
|
case string:
|
|
elements := strings.Split(pt, "\n")
|
|
//golint:gomnd // this is not a magic number
|
|
if len(elements) >= 2 {
|
|
loadedPayloads[name] = elements
|
|
} else {
|
|
file, err := generator.options.LoadHelperFile(pt, templatePath, generator.catalog)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not load payload file")
|
|
}
|
|
payloads, err := generator.loadPayloadsFromFile(file)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not load payloads")
|
|
}
|
|
loadedPayloads[name] = payloads
|
|
}
|
|
case interface{}:
|
|
loadedPayloads[name] = cast.ToStringSlice(pt)
|
|
}
|
|
}
|
|
return loadedPayloads, nil
|
|
}
|
|
|
|
// loadPayloadsFromFile loads a file to a string slice
|
|
func (generator *PayloadGenerator) loadPayloadsFromFile(file io.ReadCloser) ([]string, error) {
|
|
var lines []string
|
|
defer func() {
|
|
_ = file.Close()
|
|
}()
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
for scanner.Scan() {
|
|
text := scanner.Text()
|
|
if text == "" {
|
|
continue
|
|
}
|
|
lines = append(lines, text)
|
|
}
|
|
if err := scanner.Err(); err != nil && !errors.Is(err, pkgTypes.ErrNoMoreRequests) {
|
|
return lines, scanner.Err()
|
|
}
|
|
return lines, nil
|
|
}
|