-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweird.bro
63 lines (57 loc) · 1.42 KB
/
weird.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
@load ./main
@load base/utils/directions-and-hosts
module Netbase;
export {
redef record Netbase::observation += {
weirds_sent: count &default=0 &log;
weirds_recvd: count &default=0 &log;
};
}
event Weird::log_weird(rec: Weird::Info)
{
local orig = 0.0.0.0;
local resp = 0.0.0.0;
local pkg = observables();
if ( rec?$conn )
{
orig = rec$conn$id$orig_h;
resp = rec$conn$id$resp_h;
}
else if ( rec?$id )
{
orig = rec$id$orig_h;
resp = rec$id$resp_h;
}
else
{
return;
}
if ( addr_matches_host(orig, LOCAL_HOSTS) )
{
pkg[orig] = set([$name="weirds_sent"]);
}
if ( addr_matches_host(orig, LOCAL_HOSTS) )
{
pkg[resp] = set([$name="weirds_recvd"]);
}
}
# Handler to load observables into the observations table
# This event is executed every time a node calls the SEND()
# function. Proxies only in cluster mode.
@if ( ! Cluster::is_enabled() || Cluster::local_node_type() == Cluster::PROXY )
event Netbase::add_observables(ip: addr, obs: set[observable])
{
for ( o in obs )
{
switch o$name
{
case "weirds_sent":
++observations[ip]$weirds_sent;
break;
case "weirds_recvd":
++observations[ip]$weirds_recvd;
break;
}
}
}
@endif