-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathconfig.go
57 lines (48 loc) · 1.22 KB
/
config.go
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
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
}
var words []string
for _, p := range cfg.Payloads["word"] {
if !fileutil.FileExists(p) {
words = append(words, p)
} else {
wordBytes, err := os.ReadFile(p)
if err != nil {
gologger.Error().Msgf("failed to read wordlist from %v got %v", p, err)
continue
}
words = append(words, strings.Fields(string(wordBytes))...)
}
}
cfg.Payloads["word"] = words
return &cfg, nil
}
func init() {
if err := yaml.Unmarshal(DefaultPermutationsBin, &DefaultConfig); err != nil {
gologger.Error().Msgf("default wordlist not found: got %v", err)
}
}