-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
109 lines (92 loc) · 2.89 KB
/
main.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
package main
import (
"encoding/csv"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
"strings"
)
func printUsage() {
flag.Usage()
fmt.Println("Example: crackr -h my-hash -f my-dictionary.txt")
fmt.Println("Example 2: crackr -hf my-file-of-hashes.txt -d my-directory-of-dictionaries")
os.Exit(1)
}
const ResultsFile = "found_passwords"
func main() {
runtime.GOMAXPROCS(1)
// NOTE: https://markhneedham.com/blog/2017/01/31/go-multi-threaded-writing-csv-file/
// Create results CSV
file, err := os.Create(ResultsFile + ".csv")
checkError("Cannot create file", err)
headers := [][]string{{"plaintext", "ciphertext", "hashing_algorithm"}}
csv.NewWriter(file).WriteAll(headers)
file.Close()
hash := flag.String("h", "nil", "This is the hash of the password")
hashes := flag.String("hf", "nil", "This is a file that contains multiple hashes to crack")
dictionary := flag.String("f", "nil", "A single dictionary file with passwords to test")
dictionaries := flag.String("d", "nil", "A directory with dictionary files")
flag.Parse()
if flag.NFlag() == 0 {
printUsage()
}
if *hash == "nil" && *hashes == "nil" {
panic("A hash is required to use crackr")
}
if *hash != "nil" && *hashes != "nil" {
panic("Only one type of hash can be used!")
}
if *dictionary == "nil" && *dictionaries == "nil" {
panic("A dictionary is required to use crackr")
}
if *dictionary != "nil" && *dictionaries != "nil" {
panic("Only one type of dictionary can be used!")
}
var foundPasswords []string
// Handle combintation of single dictionary file and either a single hash or a hash file
if *dictionary != "nil" && (*hash != "nil" || *hashes != "nil") {
if *hash != "nil" {
lowerCaseHash := strings.ToLower(*hash)
passwords := readAndSplitFile(dictionary)
checkPassword(passwords, &foundPasswords, lowerCaseHash)
}
if *hashes != "nil" {
hashedPasswords := readAndSplitFile(hashes)
for _, password := range hashedPasswords {
lowerCaseHash := strings.ToLower(password)
passwords := readAndSplitFile(dictionary)
checkPassword(passwords, &foundPasswords, lowerCaseHash)
}
}
}
// Handle combintation of a directory of dictionaries
if *dictionaries != "nil" && (*hash != "nil" || *hashes != "nil") {
passwordDicts, err := ioutil.ReadDir(*dictionaries)
if err != nil {
log.Fatal(err)
}
for _, dict := range passwordDicts {
fileName := dict.Name()
filePath := *dictionaries + "/" + fileName
passwords := readAndSplitFile(&filePath)
if *hash != "nil" {
lowerCaseHash := strings.ToLower(*hash)
checkPassword(passwords, &foundPasswords, lowerCaseHash)
}
if *hashes != "nil" {
hashedPasswords := readAndSplitFile(hashes)
for _, password := range hashedPasswords {
lowerCaseHash := strings.ToLower(password)
if err != nil {
fmt.Println(err)
}
checkPassword(passwords, &foundPasswords, lowerCaseHash)
}
}
}
}
os.Exit(0)
}