-
Notifications
You must be signed in to change notification settings - Fork 1
/
weakpass.go
287 lines (252 loc) · 8.59 KB
/
weakpass.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package utils
import (
"encoding/json"
"fmt"
"strconv"
"time"
"regexp"
"strings"
"github.com/godspeedcurry/godscan/common"
"github.com/spf13/viper"
"github.com/Chain-Zhang/pinyin"
"github.com/Lofanmi/chinese-calendar-golang/calendar"
)
func MightBeIdentityCard(IdentityCard string) bool {
result, _ := regexp.MatchString(`^(\d{17})([0-9]|X|x)$`, IdentityCard)
return result
}
func MightBeChineseName(Name string) bool {
result, _ := regexp.MatchString("^[\u4e00-\u9fa5]+$", Name)
return result
}
func MightBePhone(Phone string) bool {
// 也有可能是qq号 生日什么的
result, _ := regexp.MatchString(`^\d{6,11}$`, Phone)
return result
}
func TranslateToEnglish(Name string) (string, string, string, string) {
str, err := pinyin.New(Name).Split(" ").Mode(pinyin.WithoutTone).Convert()
if err != nil {
fmt.Println(err)
return "", "", "", ""
}
// 首字母
onlyFirst := ""
// 姓全称其他只取首字母
firstComplete := ""
// 所有拼音首字母大写
firstUpper := ""
for idx, x := range strings.Split(str, " ") {
onlyFirst = onlyFirst + string(x[0])
firstUpper = firstUpper + strings.Title(x)
if idx == 0 {
firstComplete += x
} else {
firstComplete += string(x[0])
}
}
return onlyFirst, firstComplete, strings.ReplaceAll(str, " ", ""), firstUpper
}
func FirstCharToUpper(Name string) string {
return strings.ToUpper(Name[:1]) + Name[1:]
}
func HalfCharToUpper(Name string) string {
return strings.ToUpper(Name[:len(Name)>>1]) + Name[len(Name)>>1:]
}
func LastCharToUpper(Name string) string {
if len(Name) > 0 {
return Name[:len(Name)-1] + strings.ToUpper(Name[len(Name)-1:])
}
return ""
}
func AddStringToString(x string, seps []string, y string) []string {
var mylist = []string{}
for _, first := range []string{x, FirstCharToUpper(x), strings.ToUpper(x), LastCharToUpper(x)} {
for _, sep := range seps {
for _, last := range []string{y, FirstCharToUpper(y), strings.ToUpper(y), LastCharToUpper(y)} {
mylist = append(mylist, first+sep+last)
}
}
}
notDuplicated, _ := RemoveDuplicateElement(mylist)
return notDuplicated.([]string)
}
func getLunar(keyword string) string {
year, _ := strconv.ParseInt(keyword[6:10], 10, 64)
month, _ := strconv.ParseInt(keyword[10:12], 10, 64)
day, _ := strconv.ParseInt(keyword[12:14], 10, 64)
c := calendar.BySolar(year, month, day, 12, 0, 0)
bytes, _ := c.ToJSON()
var data map[string]interface{}
err := json.Unmarshal(bytes, &data)
if err != nil {
Fatal("%s", err)
}
// 获得农历生日
lunar := fmt.Sprintf("%02d%02d", int(data["lunar"].(map[string]interface{})["month"].(float64)), int(data["lunar"].(map[string]interface{})["day"].(float64)))
return lunar
}
func ReplaceWithTable(input string) string {
var tmp = input
for _, char := range tmp {
switch char {
case 'a':
tmp = strings.ReplaceAll(tmp, string(char), "@")
case 'o':
tmp = strings.ReplaceAll(tmp, string(char), "0")
case 'i':
tmp = strings.ReplaceAll(tmp, string(char), "1")
case 'l':
tmp = strings.ReplaceAll(tmp, string(char), "!")
}
}
return tmp
}
func generateVariants(input string) []string {
variants := []string{}
variants = append(variants, strings.ReplaceAll(input, "a", "@"))
variants = append(variants, strings.ReplaceAll(input, "s", "5"))
variants = append(variants, strings.ReplaceAll(input, "o", "0"))
variants = append(variants, strings.ReplaceAll(input, "i", "1"))
variants = append(variants, strings.ReplaceAll(input, "l", "!"))
variants = append(variants, ReplaceWithTable(input))
return variants
}
func getSuffixList() []string {
var SuffixList = []string{""}
if viper.GetBool("full") {
SuffixList = append(SuffixList, common.SuffixTop...)
}
year := time.Now().Year() + 5
for i := year - 15; i <= year; i++ {
SuffixList = append(SuffixList, strconv.Itoa(i))
}
if viper.GetBool("full") {
for i := year - 50; i < year-15; i++ {
SuffixList = append(SuffixList, strconv.Itoa(i))
}
}
SuffixList = append(SuffixList, strings.Split(viper.GetString("suffix"), ",")...)
SuffixList = removeDuplicatesString(SuffixList)
return SuffixList
}
func getKeywordList() []string {
var KeywordList = []string{"admin"}
if viper.GetBool("full") {
KeywordList = append(KeywordList, common.KeywordTop...)
}
KeywordList = append(KeywordList, strings.Split(viper.GetString("keyword"), ",")...)
KeywordList = removeDuplicatesString(KeywordList)
return KeywordList
}
func getSepList() []string {
var SepList = []string{""}
if viper.GetBool("full") {
SepList = append(SepList, common.SeparatorTop...)
}
SepList = append(SepList, strings.Split(viper.GetString("sep"), ",")...)
SepList = removeDuplicatesString(SepList)
return SepList
}
func getPrefixList() []string {
var PrefixList = []string{""}
if viper.GetBool("full") {
PrefixList = append(PrefixList, common.PrefixTop...)
}
PrefixList = append(PrefixList, strings.Split(viper.GetString("prefix"), ",")...)
PrefixList = removeDuplicatesString(PrefixList)
return PrefixList
}
func processIdentityCard(keyword string) []string {
arr := []string{}
lunar := getLunar(keyword)
arr = append(arr, keyword[6:10])
// 生日
arr = append(arr, keyword[10:14])
// 后六位
arr = append(arr, keyword[12:18])
// 年份后两位 + 生日
arr = append(arr, keyword[8:14])
// 年份后两位 + 农历生日
arr = append(arr, keyword[8:10]+lunar)
// 年份 + 农历生日
arr = append(arr, keyword[6:10]+lunar)
return arr
}
func outputListFormat(UniqPasswordList []string) {
if viper.GetBool("list") {
var quotedStrings []string
for _, str := range UniqPasswordList {
quotedStrings = append(quotedStrings, strconv.Quote(str))
}
output := "[" + strings.Join(quotedStrings, ", ") + "]"
fmt.Println(output)
} else {
fmt.Println(strings.Join(UniqPasswordList, "\n"))
}
}
func combination(prefixList []string, keywordList []string, sepList []string, suffixList []string) []string {
PasswordList := []string{}
for _, pre := range prefixList {
for _, keyword := range keywordList {
for _, sep := range sepList {
for _, suffix := range suffixList {
PasswordList = append(PasswordList, pre+keyword+sep+suffix)
}
}
}
}
return PasswordList
}
func GenerateWeakPassword() []string {
var PasswordList = []string{}
var KeywordList = getKeywordList()
var SuffixList = getSuffixList()
var SepList = getSepList()
var PrefixList = getPrefixList()
var idcard, onlyFirst, firstComplete, completeName, firstUpper string
PasswordList = append(PasswordList, common.Passwords...)
KeywordTmpList := []string{}
for _, keyword := range KeywordList {
if MightBeIdentityCard(keyword) {
idcard = keyword
KeywordTmpList = append(KeywordList, processIdentityCard(keyword)...)
} else if MightBeChineseName(keyword) {
onlyFirst, firstComplete, completeName, firstUpper = TranslateToEnglish(keyword)
// 也可以作为前后缀
names := []string{onlyFirst, firstComplete, completeName}
for _, name := range names {
KeywordTmpList = append(KeywordTmpList, name, FirstCharToUpper(name), LastCharToUpper(name), strings.ToUpper(name), HalfCharToUpper(name))
}
KeywordTmpList = append(KeywordTmpList, firstUpper)
if viper.GetBool("variant") {
KeywordTmpList = append(KeywordTmpList, generateVariants(completeName)...)
KeywordTmpList = append(KeywordTmpList, generateVariants(onlyFirst+"adm")...)
KeywordTmpList = append(KeywordTmpList, generateVariants(onlyFirst+"admin")...)
KeywordTmpList = append(KeywordTmpList, generateVariants(FirstCharToUpper(onlyFirst+"adm"))...)
KeywordTmpList = append(KeywordTmpList, generateVariants(FirstCharToUpper(onlyFirst+"admin"))...)
}
} else {
KeywordTmpList = append(KeywordTmpList, keyword, FirstCharToUpper(keyword), LastCharToUpper(keyword), strings.ToUpper(keyword))
if viper.GetBool("variant") {
KeywordTmpList = append(KeywordTmpList, generateVariants(keyword)...)
}
}
}
// sep keyword sep suffix sep
PasswordList = append(PasswordList, combination(PrefixList, KeywordTmpList, SepList, SuffixList)...)
if idcard != "" && completeName != "" {
arr := []string{onlyFirst, firstComplete, completeName, FirstCharToUpper(onlyFirst), LastCharToUpper(onlyFirst), strings.ToUpper(onlyFirst), FirstCharToUpper(firstComplete), LastCharToUpper(completeName), strings.ToUpper(completeName)}
for _, k := range arr {
PasswordList = append(PasswordList, k+idcard[10:14], k+idcard[8:14], k+idcard[12:18], k+idcard[6:10], k+idcard[6:14])
}
}
UniqPasswordList, err := RemoveDuplicateElement(PasswordList)
if err != nil {
Error("%s", err)
return []string{}
}
outputListFormat(UniqPasswordList.([]string))
println("total:", len(UniqPasswordList.([]string)))
return UniqPasswordList.([]string)
}