forked from averagesecurityguy/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_partial.go
87 lines (66 loc) · 1.48 KB
/
mysql_partial.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
package main
import (
"os"
"fmt"
"sync"
"bytes"
"bufio"
"crypto/sha1"
"encoding/hex"
)
const thread_count = 16
var wait sync.WaitGroup
func catch_panic() {
r := recover()
if r != nil {
fmt.Printf("[-] %s\n", r)
}
}
func hash(pwds chan string, partial []byte) {
defer wait.Done()
for pwd := range pwds {
h1 := sha1.Sum([]byte(pwd))
h2 := sha1.Sum(h1[:])
if bytes.Compare(h2[:len(partial)], partial) == 0 {
fmt.Printf("[+] %s: %x\n", pwd, h2[:])
}
}
}
func add(pwd_chan chan string, file *os.File) {
fmt.Println("[*] Loading words...")
count := 0
pscan := bufio.NewScanner(file)
for pscan.Scan() {
pwd_chan <- pscan.Text()
count++
}
close(pwd_chan)
fmt.Printf("[*] %d words loaded.\n", count)
}
func main() {
defer catch_panic()
if len(os.Args) != 3 {
panic("Usage: mysql_partial pass_file partial_hash")
}
partial, err := hex.DecodeString(os.Args[2])
if err != nil {
panic("The partial hash must be a hex string. (Ex: 001c2f)")
}
filename := os.Args[1]
fmt.Printf("[*] Opening password file: %s\n", filename)
pass_file, err := os.Open(filename)
if err != nil {
panic(fmt.Sprintf("Could not open %s", filename))
}
defer pass_file.Close()
// Create Channels
pwd_chan := make(chan string, thread_count)
wait.Add(thread_count)
// Start the hashing threads.
for i := 0; i < thread_count; i++ {
go hash(pwd_chan, partial)
}
// Add passwords to the channel then wait for the goroutines to finish.
add(pwd_chan, pass_file)
wait.Wait()
}