-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.zeek@ALT-one-unit@
79 lines (63 loc) · 1.75 KB
/
main.zeek@ALT-one-unit@
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
module @ANALYZER@;
export {
## Log stream identifier.
redef enum Log::ID += { LOG };
## Record type containing the column fields of the @ANALYZER@ log.
type Info: record {
## Timestamp for when the activity happened.
ts: time &log;
## Unique ID for the connection.
uid: string &log;
## The connection's 4-tuple of endpoint addresses/ports.
id: conn_id &log;
# TODO: Adapt subsequent fields as needed.
## Request-side payload.
request: string &optional &log;
## Response-side payload.
reply: string &optional &log;
};
## Default hook into @ANALYZER@ logging.
global log_@ANALYZER_LOWER@: event(rec: Info);
}
redef record connection += {
@ANALYZER_LOWER@: Info &optional;
};
const ports = {
# TODO: Replace with actual port(s).
12345/@PROTOCOL_LOWER@ # adapt port number in @ANALYZER_LOWER@.evt accordingly
};
redef likely_server_ports += { ports };
event zeek_init() &priority=5
{
Log::create_stream(@ANALYZER@::LOG, [$columns=Info, $ev=log_@ANALYZER_LOWER@, $path="@ANALYZER_LOWER@"]);
}
# Initialize logging state.
hook set_session(c: connection)
{
if ( c?$@ANALYZER_LOWER@ )
return;
c$@ANALYZER_LOWER@ = Info($ts=network_time(), $uid=c$uid, $id=c$id);
}
function emit_log(c: connection)
{
if ( ! c?$@ANALYZER_LOWER@ )
return;
Log::write(@ANALYZER@::LOG, c$@ANALYZER_LOWER@);
delete c$@ANALYZER_LOWER@;
}
# Example event defined in @ANALYZER_LOWER@.evt.
event @ANALYZER@::message(c: connection, is_orig: bool, payload: string)
{
hook set_session(c);
local info = c$@ANALYZER_LOWER@;
if ( is_orig )
info$request = payload;
else
info$reply = payload;
}
event connection_state_remove(c: connection) &priority=-5
{
# TODO: For UDP protocols, you may want to do this after every request
# and/or reply.
emit_log(c);
}