-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrachHash.go
125 lines (100 loc) · 2.55 KB
/
CrachHash.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
package main
import (
"errors"
"log"
"net/url"
"strings"
)
func CrackHash(expectedHash string, dataItems, separators []string) (string, string, error) {
// 1) Prepare plain and mutated data strings
needles := PrepareDataNeedles(dataItems, separators)
//log.Printf("NEEDLES: %d", len(needles))
log.Printf("%6d needles for %q", len(needles), dataItems)
N := len(expectedHash)
// 2) Hash and check
for _, s := range needles {
//fmt.Printf(".")
hashes := []string{
//hashMD4(s),
hashMD5(s),
hashSHA1(s),
hashSHA256(s),
hashSHA512(s),
hashSHA224(s),
hashSHA384(s),
hashSHA3_256(s),
hashSHA3_512(s),
hashSHA512_224(s),
hashSHA512_256(s),
}
for _, checkHash := range hashes {
if compareHash(s, expectedHash, checkHash) {
return checkHash, s, nil
}
if N > len(checkHash) {
continue
}
n := len(checkHash)
for i := 0; i <= n-N; i++ {
if i > n {
continue
}
partHash := checkHash[i : i+N]
if compareHash(s, expectedHash, partHash) {
return checkHash, s, nil
}
}
}
}
return "", "", errors.New("NOT FOUND")
}
func PrepareDataNeedles(dataItems, separators []string) []string {
var needles []string
if len(separators) == 0 {
separators = []string{""}
}
// permutations: same length
for _, perms := range permutations(dataItems) {
for _, sep := range separators {
needles = append(needles, strings.Join(perms, sep))
}
}
// combinations: different length
for _, comb := range combinations(dataItems) {
for _, perms := range permutations(comb) {
for _, sep := range separators {
needles = append(needles, strings.Join(perms, sep))
}
}
}
// basic transformations
for _, s := range dataItems {
needles = append(needles, s)
needles = append(needles, reverse(s))
needles = append(needles, splitToNeedles(s)...)
needles = append(needles, splitToNeedles(reverse(s))...)
}
// URL encoded/decoded
for _, s := range needles {
needles = append(needles, url.QueryEscape(s)) // " " => "+"
needles = append(needles, url.PathEscape(s)) // " " => "%20"
sDecoded, _ := url.QueryUnescape(s)
needles = append(needles, sDecoded)
sDecoded, _ = url.PathUnescape(s)
needles = append(needles, sDecoded)
}
// Lowercase
for _, s := range needles {
needles = append(needles, strings.ToLower(s))
}
// Uppercase
for _, s := range needles {
needles = append(needles, strings.ToUpper(s))
}
// LAST) add suffixes
for _, s := range needles {
needles = append(needles, s+"\n")
needles = append(needles, s+"\r\n")
}
return uniqueSlice(needles)
}