-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZipCrack.go
131 lines (110 loc) · 4.16 KB
/
ZipCrack.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"bufio"
"fmt"
"os"
"flag"
"io/ioutil"
"log"
"bytes"
"encoding/json"
"errors"
"net/http"
"time"
"github.com/alexmullins/zip"
)
var start = time.Now()
type SlackRequestBody struct {
Text string `json:"text"`
}
func slack(webhookUrl string, msg string) error {
//From https://golangcode.com/send-slack-messages-without-a-library/
slackBody, _ := json.Marshal(SlackRequestBody{Text: msg})
req, err := http.NewRequest(http.MethodPost, webhookUrl, bytes.NewBuffer(slackBody))
if err != nil {
return err
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return err
}
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
if buf.String() != "ok" {
return errors.New("Non-ok response returned from Slack")
}
return nil
}
func decrypt(r *zip.ReadCloser, password string, slackHook *string) {
for _, f := range r.File {
f.SetPassword(password)
rc, err := f.Open()
if err != nil {
continue
}
buf, err := ioutil.ReadAll(rc)
if err != nil {
continue
}
rc.Close()
r.Close()
elapsed := time.Since(start)
log.Printf("Size of %v: %v byte(s)\n", f.Name, len(buf))
log.Printf("!============= Found password: %s in %s =============!", password, elapsed)
message := fmt.Sprintf(":heavy_check_mark: Found password *%s* for *%s* in *%s* :heavy_check_mark:", password, f.Name, elapsed)
if *slackHook != "" {
log.Printf("Sending solution to slack.")
slack(*slackHook, message)
if err != nil {
log.Fatal(err)
}
}
os.Exit(0)
}
}
func main() {
banner :=
`
▒███████▒ ██▓ ██▓███ ▄████▄ ██▀███ ▄▄▄ ▄████▄ ██ ▄█▀
▒ ▒ ▒ ▄▀░▓██▒▓██░ ██▒▒██▀ ▀█ ▓██ ▒ ██▒▒████▄ ▒██▀ ▀█ ██▄█▒
░ ▒ ▄▀▒░ ▒██▒▓██░ ██▓▒▒▓█ ▄ ▓██ ░▄█ ▒▒██ ▀█▄ ▒▓█ ▄ ▓███▄░
▄▀▒ ░░██░▒██▄█▓▒ ▒▒▓▓▄ ▄██▒▒██▀▀█▄ ░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄
▒███████▒░██░▒██▒ ░ ░▒ ▓███▀ ░░██▓ ▒██▒ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄
░▒▒ ▓░▒░▒░▓ ▒▓▒░ ░ ░░ ░▒ ▒ ░░ ▒▓ ░▒▓░ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒
░░▒ ▒ ░ ▒ ▒ ░░▒ ░ ░ ▒ ░▒ ░ ▒░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░
░ ░ ░ ░ ░ ▒ ░░░ ░ ░░ ░ ░ ▒ ░ ░ ░░ ░
░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ░
░ ░ ░
`
fmt.Println(banner)
filePtr := flag.String("zip", "", "Path to zip file.")
wordlistPtr := flag.String("wordlist", "", "Path to wordlist.")
slackHook := flag.String("slack", "", "Slack web hook url. (Optional)")
flag.Parse()
if *filePtr == "" {
log.Fatal("Zip file not found.")
}
if *wordlistPtr == "" {
log.Fatal("Wordlist not found.")
}
log.Printf("Contending %s against %s", *filePtr, *wordlistPtr)
file, _ := os.Open(*wordlistPtr)
fscanner := bufio.NewScanner(file)
r, err := zip.OpenReader(*filePtr)
if err != nil {
log.Fatal(err)
}
for fscanner.Scan() {
go decrypt(r, fscanner.Text(), slackHook)
}
log.Printf("Password not found.")
message := ":no_entry_sign: Password not found :no_entry_sign:"
if *slackHook != "" {
slack(*slackHook, message)
if err != nil {
log.Fatal(err)
}
}
}