forked from owasp-amass/amass
/
wordlist.go
69 lines (60 loc) · 1.57 KB
/
wordlist.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
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2017-2021 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package config
import (
"fmt"
"strings"
)
const (
maskLetters = "abcdefghijklmnopqrstuvwxyz"
maskDigits = "0123456789"
maskSpecial = "-"
)
// ExpandMask will return a slice of words that a "hashcat-style" mask matches.
func ExpandMask(word string) ([]string, error) {
var expanded []string
var chars string
if strings.Count(word, "?") > 3 {
return expanded, fmt.Errorf("Exceeded maximum mask size (3): %s", word)
}
parts := strings.SplitN(word, "?", 2)
if len(parts) > 1 {
if len(parts[1]) > 0 {
switch parts[1][0] {
case 'a':
chars = maskLetters + maskDigits + maskSpecial
case 'd':
chars = maskDigits
case 'u':
fallthrough
case 'l':
chars = maskLetters
case 's':
chars = maskSpecial
default:
return expanded, fmt.Errorf("Improper mask used: %s", word)
}
for _, ch := range chars {
newWord := parts[0] + string(ch) + parts[1][1:]
nextRound, err := ExpandMask(newWord)
if err != nil {
return expanded, err
}
expanded = append(expanded, nextRound...)
}
}
} else {
expanded = append(expanded, word)
}
return expanded, nil
}
// ExpandMaskWordlist performs ExpandMask on a slice of words.
func ExpandMaskWordlist(wordlist []string) ([]string, error) {
var newWordlist []string
for _, word := range wordlist {
if words, err := ExpandMask(word); err == nil {
newWordlist = append(newWordlist, words...)
}
}
return newWordlist, nil
}