Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MITM Proxy, getting entire request and response string

I am using mitmproxy for intercepting traffic. What I want is to be able to get the entire request and response in a string. I know that you have def response(context, flow) and that the HTTPFlow object has the request and response objects. What I want is simply something like this in a string

GET http://www.google-analytics.com/collect?v=1& HTTP/1.1
Header 1: value
Header 2: value

request body

and this

HTTP/1.1 301 Moved Permanently
Header 1: value
Header 2: value

response body

Now I've been trying this by joing the different parts and bits of the requests and responses but that is prone to errors. Is there a better way to do this?

Also, does mitm handle Gzip encoded response bodies?

like image 960
Rabee Avatar asked Oct 15 '25 17:10

Rabee


1 Answers

If some one bumps into this; the above answer does not work for mitmproxy 4. Instead one can use this:

from mitmproxy.net.http.http1.assemble import assemble_request

def response(flow):
    print(assemble_request(flow.request).decode('utf-8'))
like image 127
securisec Avatar answered Oct 18 '25 06:10

securisec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!