# http multi-part

**URL:** <https://community.zeek.org/t/http-multi-part/5000>\
**Category:** Zeek\
**Created:** [August 25, 2017, 1:55am UTC](https://community.zeek.org/t/http-multi-part/5000 "2017-08-25T01:55:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dk\_Jack](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dk\_Jack](https://community.zeek.org/u/Dk_Jack)\
**Post date:** [August 25, 2017, 1:55am UTC](https://community.zeek.org/t/http-multi-part/5000/1 "2017-08-25T01:55:36Z")

</div>

Hi,  
I am trying to perform some analysis on the HTTP body. For regular messages I am accumulating the http body using http\_entity\_data and http\_end\_entity events. However, this doesn’t seem to work for multi-part post message. How do I accumulate multi-part post messages. Any help is appreciated. Thanks.

Dk.

---

<div class="post-metadata">

**Author:** ![Jim\_Mellander](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jim\_Mellander](https://community.zeek.org/u/Jim_Mellander)\
**Post date:** [August 25, 2017, 6:21pm UTC](https://community.zeek.org/t/http-multi-part/5000/2 "2017-08-25T18:21:42Z")

</div>

Hi:

The attached policy should help you. It assembles multipart HTTP POSTs, and performs regular expression matching on the POST contents.

Jim

[http-sensitive\_POSTs.bro](https://community.zeek.org/uploads/short-url/4A4JjsIw0SuryuU24OP57wwLhLp.bro) (2.77 KB)

---

<div class="post-metadata">

**Author:** ![Dk\_Jack](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dk\_Jack](https://community.zeek.org/u/Dk_Jack)\
**Post date:** [August 25, 2017, 11:52pm UTC](https://community.zeek.org/t/http-multi-part/5000/3 "2017-08-25T23:52:12Z")

</div>

Hi Jim,  
I am doing something very similar to what you are doing in your script. However, I am unable to capture the body when the content-type is:

Content-Type: multipart/form-data; boundary=----WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n

When I use entity\_data and end\_entity event functions, what I accumulate for body when I receive a multi-part body is just a small string:

YWFhYWFh

However, I know my body is much larger. I’ve copy pasted the wireshark output of the multi-part content to the end of this email.

I see there are mime\_xxx functions. Should I be using them to capture multi-part content. If they should be used, any help in how they should be used would be most appreciated. Thanks.

Dk.

[HTTP request 1/1]  
File Data: 736 bytes  
MIME Multipart Media Encapsulation, Type: multipart/form-data, Boundary: “---- WebKitFormBoundarygsgnAl2Dz3rduY2p”  
[Type: multipart/form-data]  
First boundary: ------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“success\_url”\r\n\r\n  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“error\_url”\r\n\r\n  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“firstname”\r\n\r\n  
Data (1 byte)

0000 61 a  
[Length: 1]  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“lastname”\r\n\r\n  
Data (1 byte)

0000 62 b  
[Length: 1]  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“email”\r\n\r\n  
Data (7 bytes)

0000 62 40 63 2e 63 6f 6d [b@c.com](mailto:b@c.com)  
[Length: 7]  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:

Content-Disposition: form-data; name=“password”\r\n\r\n  
Data (6 bytes)

0000 61 61 61 61 61 61 aaaaaa  
[Length: 6]  
Boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p\r\n  
Encapsulated multipart part:  
Content-Disposition: form-data; name=“confirmation”\r\n\r\n  
Data (6 bytes)

0000 61 61 61 61 61 61 aaaaaa  
[Length: 6]  
Last boundary: \r\n------WebKitFormBoundarygsgnAl2Dz3rduY2p–\r\n

---

<div class="post-metadata">

**Author:** ![Jim\_Mellander](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jim\_Mellander](https://community.zeek.org/u/Jim_Mellander)\
**Post date:** [August 26, 2017, 5:41pm UTC](https://community.zeek.org/t/http-multi-part/5000/4 "2017-08-26T17:41:02Z")

</div>

Perhaps posting the script you are using and a sample pcap might help to debug the issue you are having.

Cheers,

Jim

---

<div class="post-metadata">

**Author:** ![Dk\_Jack](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dk\_Jack](https://community.zeek.org/u/Dk_Jack)\
**Post date:** [August 28, 2017, 6:13pm UTC](https://community.zeek.org/t/http-multi-part/5000/5 "2017-08-28T18:13:30Z")

</div>

I did some more investigation and it seems like my understanding how bro works  
was incomplete.

What I observed is, for each entity/boundary in a multipart form request, Bro is  
raising a unique pair http\_entity\_data and http\_end\_entity events. For example,  
if you send a curl request as shown below:

curl -v --form “key1=value1” --form “key2=value2”, --form “key3=value3”

then bro is raising three pairs of http\_entity\_data and http\_end\_entity events. I was

assuming I’d just get one pair of events. Since I was expecting only one event, I was  
over writing the body I had saved from the previous event. As a result, my body  
variable was retaining only the last part of the multi-part form.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:45pm UTC](https://community.zeek.org/t/http-multi-part/5000/6 "2022-05-06T15:45:14Z")

</div>

Closed on May 6, 2022, 3:45pm UTC


