/
md5bruteforce.go
56 lines (54 loc) · 1.06 KB
/
md5bruteforce.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
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"strconv"
"strings"
)
func md5v(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func main() {
if len(os.Args) == 1 {
fmt.Println(`
usage: command captcha
`)
os.Exit(0)
}
candidates := []string{}
for i := 0; i < 10; i++ {
candidates = append(candidates, strconv.Itoa(i))
}
for i := 0; i < 26; i++ {
candidates = append(candidates, string(rune('a'+i)))
candidates = append(candidates, string(rune('A'+i)))
}
solve(candidates)
//fmt.Println(md5v("00vKcX"))
}
func solve(candidates []string) {
prefix := strings.TrimSpace(os.Args[1])
for _, i := range candidates {
for _, j := range candidates {
for _, k := range candidates {
for _, l := range candidates {
for _, m := range candidates {
for _, n := range candidates {
plain := i + j + k + l + m + n
s := md5v(plain)
if strings.HasPrefix(s, prefix) {
fmt.Println(plain, s, prefix)
goto out
}
}
}
}
}
}
}
out:
}