-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackr.go
80 lines (74 loc) · 2.06 KB
/
crackr.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
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"fmt"
"golang.org/x/crypto/sha3"
)
func getHash(hashType string, plaintext string) string {
switch hashingAlgo := hashType; hashingAlgo {
case "sha1":
hasher := sha1.New()
sha1 := hashText(hasher, plaintext)
return sha1
case "md5":
hasher := md5.New()
md5 := hashText(hasher, plaintext)
return md5
case "sha256":
hasher := sha256.New()
sha256 := hashText(hasher, plaintext)
return sha256
case "sha512":
hasher := sha512.New()
sha512 := hashText(hasher, plaintext)
return sha512
case "sha3_256":
hasher := sha3.New256()
sha3_256 := hashText(hasher, plaintext)
return sha3_256
case "sha3_512":
hasher := sha3.New512()
sha3_512 := hashText(hasher, plaintext)
return sha3_512
default:
panic("Hash type not supported!")
}
}
func checkFoundPasswords(foundPasswords *[]string, hashedPassword string) bool {
for _, foundPassword := range *foundPasswords {
if foundPassword == hashedPassword {
return true
}
}
return false
}
func checkPassword(passwords []string, foundPasswords *[]string, hash string) {
// for each password, check all hash algorithms
for _, password := range passwords {
hashAlgorithims := []string{"sha1", "md5", "sha256", "sha512", "sha3_256", "sha3_512"}
for _, hashAlgorithim := range hashAlgorithims {
hashedPassword := getHash(hashAlgorithim, password)
if len(*foundPasswords) > 0 {
// check if a password has already been found
if !checkFoundPasswords(foundPasswords, hashedPassword) {
if hashedPassword == hash {
fmt.Println("Matched!")
fmt.Println(password, hashAlgorithim)
writeCSV(ResultsFile, []string{password, hashedPassword, hashAlgorithim})
*foundPasswords = append(*foundPasswords, hashedPassword)
}
}
} else {
if hashedPassword == hash {
fmt.Println("Match!")
fmt.Println(password, hashAlgorithim)
writeCSV(ResultsFile, []string{password, hashedPassword, hashAlgorithim})
*foundPasswords = append(*foundPasswords, hashedPassword)
}
}
}
}
}