forked from jbaggs/anomalous-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathan-dns-connection.zeek
52 lines (46 loc) · 1.24 KB
/
an-dns-connection.zeek
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
##! AnomalousDNS: connection submodule.
##!
##! DNS "connections" are typically short and consist of few packets.
##! These events firing are a good indication something is not right.
##!
##! Author: Jeremy Baggs
module AnomalousDNS;
export {
redef enum Notice::Type += {
Conn_Duration,
Conn_Packets,
};
## Connection duration limit
const conn_duration_limit = 45secs &redef;
## Connection packets limit, measured on origin
const conn_pkts_limit = 12 &redef;
}
event dns_message(c: connection, is_orig: bool, msg: dns_msg, len: count)
{
if (c$duration > conn_duration_limit)
{
event AnomalousDNS::conn_duration_exceeded(c);
if(conn_notice)
{
NOTICE([$note=Conn_Duration,
$conn=c,
$msg=fmt("Connection duration (%ss) exceeded limit.", c$duration),
$identifier=cat(c$id$orig_h,c$id$resp_h),
$suppress_for=30min
]);
}
}
if (c$orig?$num_pkts && c$orig$num_pkts > conn_pkts_limit)
{
event AnomalousDNS::conn_packets_exceeded(c);
if (conn_notice)
{
NOTICE([$note=Conn_Packets,
$conn=c,
$msg=fmt("Connection packets (%s) exceeded limit.", c$orig$num_pkts),
$identifier=cat(c$id$orig_h,c$id$resp_h),
$suppress_for=30min
]);
}
}
}