-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnamebuster.go
163 lines (133 loc) · 3.97 KB
/
namebuster.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"fmt"
"io/ioutil"
"github.com/benbusby/namebuster/utils"
"os"
"strings"
)
var usage = `
Usage: namebuster <text|url|file>
Example (names): namebuster "We appreciate it very much, Tim Apple."
Example (url): namebuster https://sauna.htb
Example (file): namebuster carlton_banks_dance.txt
Full Example (using kerbrute):
$ namebuster "Fergus Smith" > usernames.txt
$ kerbrute_linux_amd64 userenum usernames.txt -d DOMAIN.LOCAL --dc domain.com
`
// Namebuster acts as the primary method for the CLI tool.
// @input: Either a string of text, file, or URL to read from.
// returns: Slice of string usernames
func Namebuster(input string) []string {
var parsedNames []string
var result []string
var names []string
if utils.ValidUrl(input) {
// Find names on website
names = utils.FindNames(utils.FetchSiteContent(input))
} else if _, err := os.Stat(input); err == nil {
// Find names in file
buf, err := ioutil.ReadFile(input)
if err == nil {
names = utils.FindNames(string(buf))
} else {
panic(err)
}
} else {
// Find names in string
names = utils.FindNames(input)
}
for _, name := range names {
// Skip if the results already contain the full first and last name
fullName := strings.ReplaceAll(name, " ", "")
if contains(parsedNames, fullName) {
continue
}
parsedNames = append(parsedNames, fullName)
result = append(result, generateUsernames(name)...)
}
return result
}
func contains(items []string, target string) bool {
for _, item := range items {
if item == target {
return true
}
}
return false
}
func combineNames(left []string, right []string) []string {
left = append(left, addSeparators(left)...)
return stringProduct(left, right)
}
func addSeparators(nameList []string) []string {
var result []string
for _, element := range nameList {
result = append(result, element+".")
result = append(result, element+"_")
result = append(result, element+"+")
result = append(result, element+"-")
}
return result
}
func stringProduct(left []string, right []string) []string {
var result []string
for _, elementL := range left {
for _, elementR := range right {
result = append(result, elementL+elementR)
}
}
return result
}
func generateUsernames(name string) []string {
var result []string
splitNames := strings.Split(name, " ")
if len(splitNames) < 2 {
return result
}
firstName := splitNames[0]
lastName := splitNames[1]
// Common first name variations
firstNames := []string{
strings.ToLower(firstName),
strings.Title(strings.ToLower(firstName)),
strings.ToUpper(firstName),
}
// Common last name variations
lastNames := []string{
strings.ToLower(lastName),
strings.Title(strings.ToLower(lastName)),
strings.ToUpper(lastName),
}
// Add first name only and last name only options as usernames
result = append(result, firstNames...)
result = append(result, lastNames...)
// Add username alternatives with symbol and name variations
// 1 -- Full first and last name, plus first initial and last name
result = append(result, combineNames(
append(firstNames, []string{strings.ToLower(string(firstName[0])), strings.ToUpper(string(firstName[0]))}...),
lastNames)...)
// 2 -- Full last and first name, plus last initial and first name
result = append(result, combineNames(
append(lastNames, []string{strings.ToLower(string(lastName[0])), strings.ToUpper(string(lastName[0]))}...),
firstNames)...)
// 3 -- First name then last initial combinations
result = append(result, combineNames(
firstNames,
[]string{strings.ToLower(string(lastName[0])), strings.ToUpper(string(lastName[0]))})...)
// 4 -- Last name then first initial combinations
result = append(result, combineNames(
lastNames,
[]string{strings.ToLower(string(firstName[0])), strings.ToUpper(string(firstName[0]))})...)
return result
}
func main() {
if len(os.Args) != 2 {
fmt.Print(usage)
os.Exit(1)
}
result := Namebuster(os.Args[1])
for _, value := range result {
fmt.Println(value)
}
}