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
|
|
|
"""
|
2024-03-06 20:54:11 +00:00
|
|
|
|
2022-11-13 18:04:34 +00:00
|
|
|
from __future__ import annotations
|
2022-11-29 13:28:41 +00:00
|
|
|
|
2022-09-17 13:41:54 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from mitmproxy import flowfilter
|
2022-11-29 13:28:41 +00:00
|
|
|
from mitmproxy import http
|
2023-10-31 15:03:53 +00:00
|
|
|
from mitmproxy.addonmanager import Loader
|
2015-04-07 22:21:49 +00:00
|
|
|
|
2016-07-22 23:57:31 +00:00
|
|
|
|
|
|
|
class Filter:
|
2022-11-13 18:04:34 +00:00
|
|
|
filter: flowfilter.TFilter
|
2017-04-25 23:45:15 +00:00
|
|
|
|
|
|
|
def configure(self, updated):
|
2021-10-08 15:43:52 +00:00
|
|
|
if "flowfilter" in updated:
|
2022-11-13 18:04:34 +00:00
|
|
|
self.filter = flowfilter.parse(".")
|
2017-04-25 23:45:15 +00:00
|
|
|
|
2023-10-31 15:03:53 +00:00
|
|
|
def load(self, loader: Loader):
|
|
|
|
loader.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):
|
2022-09-17 13:41:54 +00:00
|
|
|
logging.info("Flow matches filter:")
|
|
|
|
logging.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()]
|