-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
111 lines (85 loc) · 2.6 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
110
111
package main
import (
"flag"
"fmt"
"os"
"runtime"
"sync"
"time"
hel "github.com/thejini3/go-helper"
"golang.org/x/crypto/bcrypt"
)
var started time.Time
// 12345 = $2y$12$APew2qEmu/1YDnHmdPUT5.idVsU3lN2gE17srB3lC7Jiqsdf2qg9m
func main() {
started = time.Now()
wordlist := flag.String("w", "", "(Required) wordlist file path")
hash := flag.String("h", "", "(Required) hash string that need to be found")
core := flag.Int("c", -1, "(Optional) number of cpu core, -1 = all core")
thread := flag.Int("t", 50, "(Optional) number of concurrent thread")
flag.Parse()
if *wordlist == "" || *hash == "" {
flag.PrintDefaults()
os.Exit(1)
}
if *core == 0 {
*core = 1
} else if *core > runtime.NumCPU() || *core == -1 {
*core = runtime.NumCPU()
}
passes := hel.StrToArr(hel.FileStrMust(*wordlist), "\n")
hashByte := []byte(*hash)
var wg sync.WaitGroup
var c = make(chan int, *thread)
var checked = 0
var totalToBeChecked = len(passes)
hel.Pl("CPU core(s):", runtime.GOMAXPROCS(*core))
hel.Pl("Concurrent threads:", *thread)
hel.Pl("Wordlist:", *wordlist, "(", totalToBeChecked/1000.0, "K )")
hel.Pl("Hash To Find:", *hash)
for i, p := range passes {
wg.Add(1)
go func(hashByte []byte, pass []byte, i int) {
c <- i
if bcrypt.CompareHashAndPassword(hashByte, pass) == nil {
fmt.Printf("\n\nFound pass `" + string(pass) + "`\n\n")
done()
}
checked++
fmt.Printf("\rChecked - %d ", checked)
if totalToBeChecked == checked {
fmt.Printf("\n\nNot found probably... :/")
}
<-c
wg.Done()
}(hashByte, []byte(p), i)
}
wg.Wait()
close(c)
done()
}
func done() {
hel.Pl("Done in:", time.Since(started))
os.Exit(0)
}
// // HashAndSalt get a hash for given string
// func hashAndSalt(pwd string) string {
// // Use GenerateFromPassword to hash & salt pwd.
// // MinCost is just an integer constant provided by the bcrypt
// // package along with DefaultCost & MaxCost.
// // The cost can be any value you want provided it isn't lower
// // than the MinCost (4)
// hash, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.MinCost)
// if err != nil {
// hel.Pl("error hassing", err)
// }
// // GenerateFromPassword returns a byte slice so we need to
// // convert the bytes to a string and return it
// return string(hash)
// }
// // ComparePasswords compare a hash for given string
// func compareHash(hashedPwd string, pwd string) bool {
// // Since we'll be getting the hashed password from the DB it
// // will be a string so we'll need to convert it to a byte slice
// return bcrypt.CompareHashAndPassword([]byte(hashedPwd), []byte(pwd)) == nil
// }