2016-11-21 01:16:20 +00:00
|
|
|
"""
|
2020-06-22 23:53:39 +00:00
|
|
|
Use mitmproxy's filter pattern in scripts.
|
2016-11-21 01:16:20 +00:00
|
|
|
"""
|
2016-10-01 10:44:17 +00:00
|
|
|
from mitmproxy import flowfilter
|
2017-04-28 21:56:14 +00:00
|
|
|
from mitmproxy import ctx, http
|
2015-04-07 22:21:49 +00:00
|
|
|
|
2016-07-22 23:57:31 +00:00
|
|
|
|
|
|
|
class Filter:
|
2017-04-25 23:45:15 +00:00
|
|
|
def __init__(self):
|
2018-04-14 23:24:41 +00:00
|
|
|
self.filter: flowfilter.TFilter = None
|
2017-04-25 23:45:15 +00:00
|
|
|
|
|
|
|
def configure(self, updated):
|
2021-10-08 15:43:52 +00:00
|
|
|
if "flowfilter" in updated:
|
|
|
|
self.filter = flowfilter.parse(ctx.options.flowfilter)
|
2017-04-25 23:45:15 +00:00
|
|
|
|
|
|
|
def load(self, l):
|
2022-04-26 11:53:35 +00:00
|
|
|
l.add_option("flowfilter", str, "", "Check that flow matches filter.")
|
2016-07-22 23:57:31 +00:00
|
|
|
|
2017-04-28 21:56:14 +00:00
|
|
|
def response(self, flow: http.HTTPFlow) -> None:
|
2016-10-21 23:47:19 +00:00
|
|
|
if flowfilter.match(self.filter, flow):
|
2018-05-07 23:23:52 +00:00
|
|
|
ctx.log.info("Flow matches filter:")
|
|
|
|
ctx.log.info(flow)
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
|
2017-04-25 23:45:15 +00:00
|
|
|
addons = [Filter()]
|