-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNERSC.udpflood.bro
96 lines (74 loc) · 1.98 KB
/
NERSC.udpflood.bro
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
##! UDP Flood Detection
# ..Authors: Scott Campbell
#
# Track large volumes of UDP flows, logging at threshold
# conn/sec and notice at 5*threshold.
#
@load base/frameworks/notice
@load base/frameworks/sumstats
@load base/utils/time
module Flood;
export {
redef enum Log::ID += { LOG };
redef enum Notice::Type += {
## UDP Flood
UDP_Flood,
};
## UDP packets are measured over this interval
const flood_test_interval = 1sec &redef;
# Threshold to define what is an "interesting" number of UDP pkts/conns per sec
# If value 5x the threshold, send a notice otherwise just log.
#
const flood_threshold = 500.0 &redef;
global Flood::data_collect: hook();
type udp_rate: record {
ts: time &log;
host: addr &log;
rate: double &log;
};
}
event bro_init() &priority=5
{
local r1 = SumStats::Reducer($stream="udp-conn",
$apply=set(SumStats::SUM));
SumStats::create([$name="udp-flood",
$epoch=1sec,
$reducers=set(r1),
$threshold = flood_threshold,
$threshold_val(key: SumStats::Key, result: SumStats::Result) =
{
return result["udp-conn"]$sum;
},
$threshold_crossed(key: SumStats::Key, result: SumStats::Result) =
{
local ur: udp_rate;
ur$ts = network_time();
ur$rate = result["udp-conn"]$sum;
ur$host = key$host;
Log::write(LOG, ur);
if ( result["udp-conn"]$sum > 5 * flood_threshold )
{
NOTICE( [$note=UDP_Flood,
$msg=fmt("UDP stream exceeds %s/sec. COUNT @ SIP: %s @ %s",
5 * flood_threshold, result["udp-conn"]$sum, key$host ) ]);
}
} # end threshold_crossed
]);
Log::create_stream(Flood::LOG, [$columns=udp_rate]);
}
function add_sumstats(id: conn_id)
{
if ( hook Flood::data_collect() ) {
SumStats::observe("udp-conn",
SumStats::Key($host=id$orig_h),
SumStats::Observation($num=1) );
}
}
event udp_request(c: connection)
{
add_sumstats(c$id);
}
event udp_reply(c: connection)
{
add_sumstats(c$id);
}