-
Notifications
You must be signed in to change notification settings - Fork 50
/
app.go
187 lines (154 loc) · 3.72 KB
/
app.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package hashcatlauncher
import (
"log"
"net"
"os"
"path/filepath"
"runtime"
"github.com/fsnotify/fsnotify"
"github.com/zserge/lorca"
)
var (
Version string = "dev"
)
type App struct {
Server net.Listener
UI lorca.UI
Watcher *fsnotify.Watcher
Dir string
HashcatDir string
HashesDir string
DictionariesDir string
RulesDir string
MasksDir string
ExportedDir string
Hashcat *Hashcat
Hashes []string
Dictionaries []string
Rules []string
Masks []string
Tasks map[string]*Task
TaskAddCallback func(TaskUpdate)
TaskUpdateCallback func(TaskUpdate)
TaskPreProcessCallback func(TaskUpdate)
TaskPostProcessCallback func(TaskUpdate)
TaskDeleteCallback func(string)
WatcherHashcatCallback func()
WatcherHashesCallback func()
WatcherDictionariesCallback func()
WatcherRulesCallback func()
WatcherMasksCallback func()
Settings *Settings
}
func (a *App) Init() error {
exe, err := os.Executable()
if err != nil {
return err
}
a.Dir, _ = filepath.Split(exe)
a.HashcatDir = filepath.Join(a.Dir, "hashcat")
err = os.MkdirAll(a.HashcatDir, 0o755)
if err != nil {
return err
}
a.HashesDir = filepath.Join(a.HashcatDir, "hashes")
err = os.MkdirAll(a.HashesDir, 0o755)
if err != nil {
return err
}
a.DictionariesDir = filepath.Join(a.HashcatDir, "dictionaries")
err = os.MkdirAll(a.DictionariesDir, 0o755)
if err != nil {
return err
}
a.RulesDir = filepath.Join(a.HashcatDir, "rules")
err = os.MkdirAll(a.RulesDir, 0o755)
if err != nil {
return err
}
a.MasksDir = filepath.Join(a.HashcatDir, "masks")
err = os.MkdirAll(a.MasksDir, 0o755)
if err != nil {
return err
}
a.ExportedDir = filepath.Join(a.Dir, "exported")
err = os.MkdirAll(a.ExportedDir, 0o755)
if err != nil {
return err
}
a.Hashcat = &Hashcat{}
if runtime.GOOS == "windows" {
a.Hashcat.BinaryFile = filepath.Join(a.HashcatDir, "hashcat.exe")
} else {
a.Hashcat.BinaryFile = filepath.Join(a.HashcatDir, "hashcat.bin")
}
if err := a.Scan(); err != nil {
log.Println(err)
}
a.Tasks = make(map[string]*Task)
a.TaskAddCallback = func(taskUpdate TaskUpdate) {
a.UI.Eval(`eventBus.dispatch("taskUpdate",` + MarshalJSONS(taskUpdate) + `)`)
}
a.TaskUpdateCallback = func(taskUpdate TaskUpdate) {
a.UI.Eval(`eventBus.dispatch("taskUpdate",` + MarshalJSONS(taskUpdate) + `)`)
}
a.TaskPreProcessCallback = func(taskUpdate TaskUpdate) {}
a.TaskPostProcessCallback = func(taskUpdate TaskUpdate) {
a.UI.Eval(`eventBus.dispatch("taskUpdate",` + MarshalJSONS(taskUpdate) + `)`)
}
a.TaskDeleteCallback = func(taskID string) {
a.UI.Eval(`eventBus.dispatch("taskDelete",` + MarshalJSONS(taskID) + `)`)
}
a.WatcherHashcatCallback = func() {
a.Hashcat.LoadAlgorithms()
a.UI.Eval(`data.getAlgorithms()`)
}
a.WatcherHashesCallback = func() {
a.ScanHashes()
a.UI.Eval(`data.getHashes()`)
}
a.WatcherDictionariesCallback = func() {
a.ScanDictionaries()
a.UI.Eval(`data.getDictionaries()`)
}
a.WatcherRulesCallback = func() {
a.ScanRules()
a.UI.Eval(`data.getRules()`)
}
a.WatcherMasksCallback = func() {
a.ScanMasks()
a.UI.Eval(`data.getMasks()`)
}
if err := a.LoadSettings(); err != nil {
log.Println(err)
}
if err := a.Bundle(); err != nil {
log.Println(err)
}
return nil
}
func (a *App) Clean() error {
if err := a.SaveSettings(); err != nil {
log.Println(err)
}
return nil
}
func (a *App) Scan() (err error) {
a.Hashcat.LoadAlgorithms()
if err = a.ScanHashes(); err != nil {
return
}
if err = a.ScanDictionaries(); err != nil {
return
}
if err = a.ScanRules(); err != nil {
return
}
if err = a.ScanMasks(); err != nil {
return
}
return
}
func NewApp() *App {
return &App{}
}