-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
executable file
·268 lines (203 loc) · 5.54 KB
/
main.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package main
import (
"fmt"
"github.com/gorilla/mux"
"html/template"
"net/http"
"os/exec"
// "io"
"code.google.com/p/gcfg"
"io/ioutil"
"labix.org/v2/mgo/bson"
"strconv"
"strings"
)
type Config struct {
Settings struct {
Port string
Location string
Addr string
Password string
}
}
func main() {
var cfg Config
err := gcfg.ReadFileInto(&cfg, "settings.gcfg")
if err != nil {
fmt.Println("Test")
panic(err)
}
WEB_PORT := cfg.Settings.Addr + ":" + cfg.Settings.Port
r := mux.NewRouter()
// Web Routes
r.HandleFunc("/input_job", InputJobDisplay).Methods("GET")
r.HandleFunc("/input_job", InputJobSubmit).Methods("POST")
r.HandleFunc("/", mainJobPage) // Lists all the jobs
r.HandleFunc("/jobs/{job_id}/tasks", jobTasks) // Lists all the tasks for a job
r.HandleFunc("/jobs/{job_id}/results", jobResults) // Lists all the results for a job
// Serve static files.
r.PathPrefix("/static/").Handler(http.StripPrefix("/static", http.FileServer(http.Dir("static/"))))
// API Routes
s := r.PathPrefix("/api/jobs").Subrouter()
s.HandleFunc("/", ListJobs)
s.HandleFunc("", ListJobs)
s.HandleFunc("/fetch", fetchJob)
s.HandleFunc("/{job_id}", ShowJob)
s.HandleFunc("/{job_id}/results", JobIsDone)
s.HandleFunc("/{job_id}/fetch", FetchTask)
s.HandleFunc("/{job_id}/tasks", ListTasks)
s.HandleFunc("/{job_id}/pause_toggle", PauseToggle)
s.HandleFunc("/{job_id}/tasks/{task_id}", ShowTask)
s.HandleFunc("/{job_id}/tasks/{task_id}/results", ReportResults).Methods("POST")
s.HandleFunc("/{job_id}/tasks/{task_id}/done", FinishTask)
http.Handle("/", r)
http.ListenAndServe(WEB_PORT, nil)
}
func InputJobSubmit(w http.ResponseWriter, r *http.Request) {
var cfg Config
err := gcfg.ReadFileInto(&cfg, "settings.gcfg")
if err != nil {
fmt.Println("ERROR: Reading Config File.")
panic(err)
}
// name := r.PostFormValue("name")
r.ParseMultipartForm(32 << 20)
file, _, err := r.FormFile("hashfile")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
output, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
return
}
attack, err := strconv.Atoi(r.FormValue("attack"))
if err != nil {
fmt.Println(err)
return
}
hashtype, err := strconv.Atoi(r.FormValue("hashtype"))
if err != nil {
fmt.Println(err)
return
}
if r.FormValue("passcode") != cfg.Settings.Password {
fmt.Println("No Auth.")
}
maxLimit := runHashcat(attack, hashtype, r.FormValue("mask"))
createJob(attack, hashtype, output, r.FormValue("mask"), maxLimit, r.FormValue("name"), getConnection())
fmt.Fprintf(w, "")
}
func InputJobDisplay(w http.ResponseWriter, r *http.Request) {
t := template.New("Job Input")
t, err := template.ParseFiles("templates/job_input.html")
if err != nil {
panic(err)
}
t.Execute(w, nil)
}
func runHashcat(attackMode int, hashMode int, mask string) (result int) {
var cfg Config
err := gcfg.ReadFileInto(&cfg, "settings.gcfg")
if err != nil {
fmt.Println("Test")
panic(err)
}
fmt.Println("Starting hashcat task to get mask tasks.")
command := cfg.Settings.Location
result = 1
// fmt.Println(command + " -a " + attackMode + " -m " + hashMode + " input.txt " + mask + " --force " + "--keyspace")
out, err := exec.Command(command, "-a", strconv.Itoa(attackMode), "-m", strconv.Itoa(hashMode), "input.txt", mask, "--force", "--keyspace").CombinedOutput()
if err != nil {
fmt.Println(err)
}
output := string(out)
result, err = strconv.Atoi(strings.Split(output, "\n")[2])
if err != nil {
fmt.Println(err)
}
fmt.Println("Got a length of ", result)
return
}
// Used only to keep calculations out of the template.
// Should never been in the db, only calculated on the fly.
type DisplayJob struct {
Id int
Name string
TasksDispatched int
Progress float64
ResultsFound int
Complete bool
Paused bool
}
func mainJobPage(w http.ResponseWriter, r *http.Request) {
t := template.New("Jobs List")
t, err := template.ParseFiles("templates/index.html")
if err != nil {
panic(err)
}
// Fetch all the jobs
var results []Job
session, c := getCollection("tasks")
defer session.Close()
err = c.Find(bson.M{}).All(&results)
if err != nil {
fmt.Println(err)
}
displayResults := make([]DisplayJob, len(results))
// Create a display array for the webpage
for i := 0; i < len(results); i++ {
progress := (float64(results[i].Start) / float64(results[i].Finish)) * 100
displayResults[i] = DisplayJob{
results[i].Id,
results[i].Name,
len(results[i].Tasks),
progress,
//float64(int(progress * 10)) / 10,
len(results[i].Results),
results[i].IsDone(),
results[i].IsPaused(),
}
}
data := struct {
DisplayJobs []DisplayJob
}{displayResults}
t.Execute(w, data)
return
}
func jobTasks(w http.ResponseWriter, r *http.Request) {
t := template.New("Task List")
t, err := template.ParseFiles("templates/tasks.html")
if err != nil {
panic(err)
}
// Fetch the job
session, _ := getCollection("tasks")
defer session.Close()
jobId := jobId(r, "job_id")
job := loadJob(jobId, session)
data := struct {
Tasks []Task
}{job.Tasks}
t.Execute(w, data)
return
}
func jobResults(w http.ResponseWriter, r *http.Request) {
t := template.New("Results List")
t, err := template.ParseFiles("templates/results.html")
if err != nil {
panic(err)
}
// Fetch the job
session, _ := getCollection("tasks")
defer session.Close()
jobId := jobId(r, "job_id")
job := loadJob(jobId, session)
data := struct {
Results []Result
}{job.Results}
t.Execute(w, data)
return
}