-
Notifications
You must be signed in to change notification settings - Fork 24
/
verify_wpad.bro
executable file
·138 lines (121 loc) · 3.6 KB
/
verify_wpad.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Initial Developer of the Original Code is
# Mozilla Corporation
# Portions created by the Initial Developer are Copyright (C) 2014
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Michal Purzynski [email protected]
#
# TODO: application/x-ns-proxy-autoconfig
# "site-local" option 252 ("auto-proxy-config")
# maybe check for HTTP download from DNS answers only
# proxy.pac
@load policy/frameworks/files/hash-all-files
@load base/frameworks/notice
@load base/protocols/http
@load base/protocols/dns
module MozillaVerifyWPAD;
export {
redef enum Notice::Type += {
New_WPAD_In_DNS,
New_WPAD_In_HTTP,
};
global whitelist_hosts: set[string] &redef;
global wpad_dat_sum: set[string] &redef;
const ignore_subnets: set[subnet] &redef;
}
event file_hash(f: fa_file, kind: string, hash: string)
{
local is_whitelisted: bool;
local error_code: int;
local lastconn: connection;
for ( cid in f$conns ) {
if ( cid$resp_h in ignore_subnets )
return;
if ( cid$orig_h in ignore_subnets )
return;
if ( ! f$conns[cid]?$http )
return;
if ( ! f$conns[cid]$http?$method )
return;
lastconn = f$conns[cid];
if ( f$conns[cid]$http$method != "GET" )
return;
else {
if ( /^\/wpad\.dat/ ! in f$conns[cid]$http$uri ) {
return;
}
}
}
for ( cid in f$conns ) {
if ( cat(cid$resp_h) in whitelist_hosts ) {
is_whitelisted = T;
error_code = 0;
} else {
is_whitelisted = F;
error_code = 1;
break;
}
}
if ( is_whitelisted == T ) {
if ( hash ! in wpad_dat_sum )
error_code = 2;
}
local message: string;
if ( error_code == 0 )
return;
else if ( error_code == 1 )
message = "Unknown HTTP server";
else if ( error_code == 2 )
message = "WPAD checksum fail";
else
message = "Something went wrong";
NOTICE([$note=New_WPAD_In_HTTP,
$msg=fmt("Unauthorized WPAD detected"),
$sub=message,
$uid=lastconn$uid,
$id=lastconn$id,
$identifier=cat(lastconn$uid)]);
}
event DNS::log_dns(rec: DNS::Info)
{
local is_whitelisted: bool;
if ( ! rec?$qtype_name )
return;
if ( ! rec?$query )
return;
if ( ! rec?$answers )
return;
if ( /CNAME|^A|AAAA/ ! in rec$qtype_name )
return;
# put your domain name in here
if ( /^wpad\..*mozilla\.(net|org|com)/ ! in rec$query )
return;
for ( vecidx in rec$answers ) {
if ( rec$answers[vecidx] in whitelist_hosts )
is_whitelisted = T;
else {
is_whitelisted = F;
break;
}
}
if ( is_whitelisted == T )
return;
else {
NOTICE([$note=New_WPAD_In_DNS,
$msg=fmt("Unauthorized WPAD detected"),
$sub=fmt("Host %s sends WPAD answers with unknown proxies", cat(rec$id$resp_h)),
$uid=rec$uid,
$id=rec$id,
$identifier=cat(rec$uid)]);
}
}