forked from michalpurzynski/bro-gramming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_headers_lb.bro
executable file
·101 lines (90 loc) · 3.15 KB
/
http_headers_lb.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
# Script to extract value of various HTTP headers provided by load balancers
# and add it to the HTTP log stream
# Inspired by policy/protocols/http/header-names.bro
#
# 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):
# Anthony Verez [email protected]
# Michal Purzynski [email protected]
@load base/protocols/http/main
module MozillaHTTPHeaders;
export {
redef record Intel::Info += {
## True client IP address added by our ZLBs
cluster_client_ip: string &log &optional;
};
redef record Intel::Seen += {
## Log value of the X-CLUSTER-CLIENT-IP
## True client IP address added by our ZLBs
cluster_client_ip: string &log &optional;
};
redef record HTTP::Info += {
## Log value of the X-CLUSTER-CLIENT-IP
## True client IP address added by our ZLBs
cluster_client_ip: string &log &optional;
## Log which backend server handled the connection.
## Might be useful to know where to look for more logs or which server might be under the load
backend_server: string &log &optional;
version: string &log &optional;
redirect_dst: string &log &optional;
};
redef enum Intel::Where += {
HTTP::IN_X_CLUSTER_CLIENT_IP_HEADER,
HTTP::IN_X_BACKEND_SERVER_HEADER,
};
## A boolean value to determine if you log the value of X-CLUSTER-CLIENT-IP headers
const log_cluster_client_ip = T &redef;
## A boolean value to determine if you log the value of X-BACKEND-SERVER headers
const log_backend_server = T &redef;
}
event Intel::match(s: Intel::Seen, items: set[Intel::Item])
{
if ( ( s?$conn ) && ( s$conn?$http ) && ( s$conn$http?$cluster_client_ip ) )
s$cluster_client_ip = s$conn$http$cluster_client_ip;
}
event http_header(c: connection, is_orig: bool, name: string, value: string)
{
if (!c?$http)
return;
if (name == "LOCATION") {
c$http$redirect_dst = value;
# Intel::seen([$host=to_addr(value),
# $indicator_type=Intel::DOMAIN,
# $conn=c,
# $where=HTTP::IN_X_BACKEND_SERVER_HEADER]);
}
if (name == "X-CLUSTER-CLIENT-IP" ) {
#if (is_valid_ip(value)) {
c$http$cluster_client_ip = value;
Intel::seen([$host=to_addr(value),
$indicator_type=Intel::ADDR,
$conn=c,
$where=HTTP::IN_X_CLUSTER_CLIENT_IP_HEADER]);
#}
}
if (name == "X-BACKEND-SERVER") {
c$http$backend_server = value;
# this has no right to be true. EVER.
# Intel::seen([$host=to_addr(value),
# $indicator_type=Intel::DOMAIN,
# $conn=c,
# $where=HTTP::IN_X_BACKEND_SERVER_HEADER]);
}
}
event http_request(c: connection, method: string, original_URI: string, unescaped_URI: string, version: string)
{
c$http$version = version;
}