-
Notifications
You must be signed in to change notification settings - Fork 4
/
bodies.bro
66 lines (50 loc) · 1.52 KB
/
bodies.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
##! This script reassembles full HTTP bodies and raises an event with the
##! complete contents.
module HTTP;
export {
redef record Info += {
body: string &optional;
reassemble_body: bool &default=F;
};
## Flag that indicates whether to hook request bodies.
const hook_request_bodies = F &redef;
## Flag that indicates whether to hook reply bodies.
const hook_reply_bodies = T &redef;
## The pattern applies
const hook_host_pattern = /.*/ &redef;
## Do not buffer more than this amount of bytes per HTTP message.
const max_body_size = 50000000;
}
## Users write a handler for this event to process the current HTTP body.
event http_body_complete(c: connection) &priority=-5
{
delete c$http$body;
}
event http_begin_entity(c: connection, is_orig: bool)
{
if ( (is_orig && ! hook_request_bodies) ||
(! is_orig && ! hook_reply_bodies) )
return;
if ( hook_host_pattern !in c$http$host )
return;
c$http$body = "";
c$http$reassemble_body = T;
}
event http_entity_data(c: connection, is_orig: bool, length: count,
data: string)
{
if ( ! c$http?$body )
return;
c$http$body += data;
if ( c$http$response_body_len < max_body_size )
return;
c$http$reassemble_body = F;
event http_body_complete(c);
}
event http_end_entity(c: connection, is_orig: bool)
{
if ( ! c$http?$body )
return;
c$http$reassemble_body = F;
event http_body_complete(c);
}