-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrack.go
98 lines (82 loc) · 1.7 KB
/
crack.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
package main
import (
"bytes"
"fmt"
"io"
"time"
"github.com/yeka/zip"
)
func findPWD(pwdCh, result chan string) {
for pwd := range pwdCh {
if verbose {
SayInfo(fmt.Sprintf("Check %v", pwd))
// SayInfo(fmt.Sprintf("go routine count: %v", runtime.NumGoroutine()))
}
flag := unZip(zipfile, pwd)
if flag {
// notice controller that find the password
result <- pwd
close(result)
}
wg.Done()
}
}
func BruteForce(pwdCh, result chan string, payload []string, min, max int) string {
for i := min; i <= max; i++ {
var payloads [][]string
payloads = genPayloads(payload, i)
pwd := bruteforceFactory(pwdCh, result, payloads...)
if pwd != "" {
return pwd
}
}
// wait a moment for gorutine execute over when all payload running over.
select {
case pwd := <-result:
return pwd
case <-time.After(WAITTIME):
return ""
}
}
func DictionaryAttack(pwdCh, result chan string, filename string) string {
pwd := dictionaryFactory(pwdCh, result, filename)
if pwd != "" {
OutputResult("Brute-Force", pwd)
if output != "" {
WritePWD2File(output, zipfile, pwd)
}
return pwd
}
// wait a moment for gorutine execute over
select {
case pwd := <-result:
return pwd
case <-time.After(WAITTIME):
return ""
}
}
func unZip(filename string, password string) bool {
r, err := zip.OpenReader(filename)
if err != nil {
return false
}
defer r.Close()
buffer := new(bytes.Buffer)
for _, f := range r.File {
if f.FileInfo().IsDir() || !f.IsEncrypted() {
continue
}
f.SetPassword(password)
r, err := f.Open()
if err != nil {
return false
}
defer r.Close()
n, err := io.Copy(buffer, r)
if n == 0 || err != nil {
return false
}
break
}
return true
}