Repository navigation
Expand file tree
/
Copy pathconfig.go
More file actions
61 lines (51 loc) · 1.39 KB
/
Copy pathconfig.go
File metadata and controls
61 lines (51 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package alterx
import (
"os"
"strings"
_ "embed"
"github.com/projectdiscovery/gologger"
fileutil "github.com/projectdiscovery/utils/file"
"gopkg.in/yaml.v3"
)
//go:embed permutations.yaml
var DefaultPermutationsBin []byte
// DefaultConfig contains default patterns and payloads
var DefaultConfig Config
type Config struct {
Patterns []string `yaml:"patterns"`
Payloads map[string][]string `yaml:"payloads"`
}
// NewConfig reads config from file
func NewConfig(filePath string) (*Config, error) {
bin, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
var cfg Config
if err = yaml.Unmarshal(bin, &cfg); err != nil {
return nil, err
}
// Process file paths for all payload keys
for payloadKey, payloadValues := range cfg.Payloads {
var processedValues []string
for _, p := range payloadValues {
if !fileutil.FileExists(p) {
processedValues = append(processedValues, p)
} else {
wordBytes, err := os.ReadFile(p)
if err != nil {
gologger.Error().Msgf("failed to read wordlist from %v got %v", p, err)
continue
}
processedValues = append(processedValues, strings.Fields(string(wordBytes))...)
}
}
cfg.Payloads[payloadKey] = processedValues
}
return &cfg, nil
}
func init() {
if err := yaml.Unmarshal(DefaultPermutationsBin, &DefaultConfig); err != nil {
gologger.Error().Msgf("default wordlist not found: got %v", err)
}
}