-
Notifications
You must be signed in to change notification settings - Fork 24
/
weak_ciphers.bro
executable file
·85 lines (74 loc) · 3.12 KB
/
weak_ciphers.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
#! SslWeakCiphers give percentage of SSL weak ciphers used (< 2048 bits key except for ECDHE)
#! Depends on protocols/ssl/client_ciphers.bro
# Original author lost in the battle - either Johanna Amann, Bro/ICSI - [email protected] or Michal Purzynski
@load base/protocols/ssl
module SslWeakCiphers;
export {
redef enum Log::ID += { LOG };
type Info: record {
## Timestamp when the log line was finished and written.
ts: time &log;
## Time interval that the log line covers.
ts_delta: interval &log;
## Percentage of weak SSL ciphers used
percent_weak_ciphers: double &log;
};
## The frequency of logging the stats collected by this script.
const break_interval = 15mins &redef;
## Monitored hosts for weak SSL ciphers
const cert_tracking = ALL_HOSTS &redef;
}
redef record SSL::Info += {
## Ciphers available for the client
weak_cipher: bool &log &optional;
};
event bro_init() &priority=3
{
Log::create_stream(SslWeakCiphers::LOG, [$columns=Info]);
local r1: SumStats::Reducer = [$stream="ssl_weak_ciphers.weak_hits", $apply=set(SumStats::UNIQUE)];
local r2: SumStats::Reducer = [$stream="ssl_weak_ciphers.ssl_hits", $apply=set(SumStats::UNIQUE)];
SumStats::create([$name="ssl_weak_ciphers-metrics",
$epoch=break_interval,
$reducers=set(r1,r2),
$epoch_result(ts: time, key: SumStats::Key, result: SumStats::Result) =
{
local l: Info;
l$ts = network_time();
l$ts_delta = break_interval;
if ("ssl_weak_ciphers.weak_hits" in result && "ssl_weak_ciphers.ssl_hits" in result)
l$percent_weak_ciphers = result["ssl_weak_ciphers.weak_hits"]$num * 100 / result["ssl_weak_ciphers.ssl_hits"]$num;
else
l$percent_weak_ciphers = 0;
Log::write(LOG, l);
}]);
}
event ssl_established(c: connection)
{
# Only look at monitored hosts
if (addr_matches_host(c$id$resp_h, cert_tracking))
{
local strong_key = F;
c$ssl$weak_cipher = F;
SumStats::observe("ssl_weak_ciphers.ssl_hits", [], []);
# If the cipher key used is weak
if ( !(/256/ in c$ssl$cipher) && !(/ECDHE/ in c$ssl$cipher) )
{
# Does the client browser support 256 bytes SSL/TLS cipher key?
local client_browser_weak = F;
for(cipher in c$ssl$available_ciphers_client)
{
if(/256/ in cipher || /ECDHE/ in cipher)
{
client_browser_weak = T;
break;
}
}
# If the server does not support strong SSL/TLS cipher but client does
if (!client_browser_weak)
{
SumStats::observe("ssl_weak_ciphers.weak_hits", [], []);
c$ssl$weak_cipher = T;
}
}
}
}