mitmproxy allows you to choose the format to display when displaying the contents of the request response.
The mechanism for displaying each format is called ** content view ** in mitmproxy.
Basic things such as html, css, json are prepared as standard.
Since mimproxy can be extended with Python, you can also create your own ** content view **!
Examples in the official github repository So, let's take that code as an example.
An example of this is ** "Display the contents of the request / response in a different case" **.
custom_contentview.py
from mitmproxy import contentviews
# contentviews.Create a class that inherits View
class ViewSwapCase(contentviews.View):
name = "swapcase"
#Specify a shortcut key to apply this display when started with CUI
prompt = ("swap case text", "z")
content_types = ["text/plain"]
#Put the main content rewriting process here
# data:Contents of request / response
# metadata: metadata["headers"]You can see the HTTP headers at
def __call__(self, data, **metadata):
return "case-swapped text", contentviews.format_text(data.swapcase())
view = ViewSwapCase()
def load(l):
contentviews.add(view)
def done():
contentviews.remove(view)
I couldn't read it well with my own mitmproxy as it is.
As a result of looking at the source code of mitmproxy and doing various things, I succeeded in loading by changing def load (l)
to def start ()
.
-def load(l):
+def start():
contentviews.add(view)
Looking at mitmproxy's github, it seems that the version you are running is different because it was rewritten from start
to load
on the way.
addon loader: add boot_into, which replaces returning from start()
You can add the script file path by adding -s
to the argument of the mitmproxy
(or mitmweb
, mitmdump
) command.
I use mitmweb
because I can't use mitmproxy
in a Windows environment.
mitmweb -s custom_contentview.py
This is successful if ** swapcase ** is added to the request / response format selection.
Overview — mitmproxy 2.0.2 documentation
Recommended Posts