-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhandlers.go
134 lines (117 loc) · 3.37 KB
/
handlers.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
package gocat
// #include "wrapper.h"
import "C"
import (
"fmt"
"strings"
"time"
)
const (
// InfoMessage is a log message from hashcat with the id of EVENT_LOG_INFO
InfoMessage LogLevel = iota
// WarnMessage is a log message from hashcat with the id of EVENT_LOG_WARNING
WarnMessage
// ErrorMessage is a log message from hashcat with the id of EVENT_LOG_ERROR
ErrorMessage
// AdviceMessage is a log message from hashcat with the id of EVENT_LOG_ADVICE
AdviceMessage
)
// LogPayload defines the structure of an event log message from hashcat and sent to the user via the callback
type LogPayload struct {
Level LogLevel
Message string
Error error
}
// TaskInformationPayload includes information about the task that hashcat is getting ready to process. This includes deduplicated hashes, etc.
type TaskInformationPayload struct {
NumHashes uint32
NumHashesUnique uint32
NumSalts uint32
}
// ActionPayload defines the structure of a generic hashcat event and sent to the user via the callback.
// An example of this would be the numerous PRE/POST events.
type ActionPayload struct {
HashcatEvent uint32
LogPayload
}
// CrackedPayload defines the structure of a cracked message from hashcat and sent to the user via the callback
type CrackedPayload struct {
IsPotfile bool
Hash string
Value string
CrackedAt time.Time
}
// FinalStatusPayload is returned at the end of the cracking session
type FinalStatusPayload struct {
Status *Status
EndedAt time.Time
// AllHashesCracked is set when all hashes either exist in a potfile or are considered "weak"
AllHashesCracked bool
}
// ErrCrackedPayload is raised whenever we get a cracked password callback but was unable to parse the message from hashcat
type ErrCrackedPayload struct {
Separator string
CrackedMsg string
}
func (e ErrCrackedPayload) Error() string {
return fmt.Sprintf("Could not locate separator `%s` in msg", e.Separator)
}
// LogLevel indicates the type of log message from hashcat
type LogLevel int8
func (s LogLevel) String() string {
switch s {
case InfoMessage:
return "INFO"
case WarnMessage:
return "WARN"
case ErrorMessage:
return "ERROR"
case AdviceMessage:
return "ADVICE"
default:
return "UNKNOWN"
}
}
// logMessageCbFromEvent is called whenever hashcat sends a INFO/WARN/ERROR message
func logMessageCbFromEvent(ctx *C.hashcat_ctx_t, lvl LogLevel) LogPayload {
ectx := ctx.event_ctx
return LogPayload{
Level: lvl,
Message: C.GoStringN(&ectx.msg_buf[0], C.int(ectx.msg_len)),
}
}
func logMessageWithError(id uint32, err error) LogPayload {
return LogPayload{
Level: ErrorMessage,
Message: err.Error(),
Error: err,
}
}
func logHashcatAction(id uint32, msg string) ActionPayload {
return ActionPayload{
LogPayload: LogPayload{
Level: InfoMessage,
Message: msg,
},
HashcatEvent: id,
}
}
func getCrackedPassword(id uint32, msg string, sep string) (pl CrackedPayload, err error) {
// Some messages can have multiple variations of the separator (example: kerberos 13100)
// so we find the last one and use that to separate the original hash and it's value
idx := strings.LastIndex(msg, sep)
if idx == -1 {
err = ErrCrackedPayload{
Separator: sep,
CrackedMsg: msg,
}
return
}
pl = CrackedPayload{
Hash: msg[:idx],
Value: msg[idx+1:],
IsPotfile: id == C.EVENT_POTFILE_HASH_SHOW,
CrackedAt: time.Now().UTC(),
}
return
}