-
Notifications
You must be signed in to change notification settings - Fork 15
/
md5Crack.go
82 lines (66 loc) · 1.47 KB
/
md5Crack.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
package main
//golang code to crack md5
// with goroutine
// to do : add hash algo
import (
"bufio"
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"time"
"flag"
)
func GetMD5Hash(text string, hash string, sem chan bool) {
defer func() { <-sem }()
h := md5.Sum([]byte(text))
res := hex.EncodeToString(h[:])
//fmt.Println(text," ",res, " ", hash)
//time.Sleep(1 * time.Second)
if res == hash {
fmt.Println(text)
os.Exit(0)
}
}
func main() {
hashPtr := flag.String("m","","Md5 hash value")
threadPtr := flag.Int("t",10,"Number of concurrente process to calculate hashes")
filePtr := flag.String("f","","Dictionnary file (one word/line)")
flag.Parse()
if *hashPtr == "" {
fmt.Println("Need to enter a md5 hash")
os.Exit(1)
}
if *filePtr == "" {
fmt.Println("Need to set a dictionnary file")
os.Exit(2)
}
fmt.Println("start")
start := time.Now()
hash := *hashPtr
file, err := os.Open(*filePtr)
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Println("try to crack : " + hash)
concurrency := *threadPtr
fmt.Println("concurrency goroutine: ", concurrency)
sem := make(chan bool, concurrency)
fileScanner := bufio.NewScanner(file)
for fileScanner.Scan() {
sem <- true
go GetMD5Hash(fileScanner.Text(), hash, sem)
}
//wait sem to be empty before continue/quite
for {
if len(sem) == 0 {
break
}
time.Sleep(1 * time.Millisecond)
}
fmt.Println("done")
elapsed := time.Since(start)
fmt.Println("crack took ", elapsed)
}