Few questions

Looking into using mitmproxy for a filtering script for a few locations.

I was wondering if there is a way to program mitmproxy to block images from loading on a webpage? I did look at the examples and saw one that flip images around, but I was not able to get this script to work. I have been able to get others to work and I am currently writing a new one already.

Next question would be how do I get the user_agent? I like to know if the data traffic is coming a mobile device or a desktop computer (windows, mac, linxus, etc)

Last question, is there a way to get the IP or maybe link the flow to a connection/user so we may limit or open permissions base off the connection? We may already have a way to read the packets and pull some information off the packets to assign user permission level access, but need a way to link said information to the IP that is talking.

You can call flow.kill() on resources you want to stop from loading.

flow.request.headers["user-agent"]

You can either use the proxyauth addon (stores credentials in flow.metadata or take a look at the client information in ´flow.client_conn`.

Thank you so much! Got it all working on this part.

One more question, is there a way to add to the ignore list while on the fly? We’re making a web portal for easy access. From there, I am allowing users on the fly control of the proxy. That part is working - but not sure if you have a “safe” expose way to add items to the ignore list on the fly for example for hsts certificate pinning locations?

With the next release you’ll hopefully be able to just add entries to options.ignore_hosts, but I don’t think we expose functionality for this yet. If it doesn’t work with 3.0, you are welcome to file an issue for this on GitHub!

Oh I see… mmm is there not a way to pass the master “self” to the -s option? From there I could just link into the self.check_ignore option by reloading it.

you are looking for from mitmproxy.ctx import master I think. :slight_smile:

Got it! Thanks so much!

1 Like

Sorry xD Two more of the one more questions then I think I have everything I will ever want working:

One) How do I disable the log or redirect it?
Two) is there a way for http.HTTPResponse.make to work with HTTPS? Or do I just have to redirect each time change the url instead?