Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
import json
from mitmproxy import ctx
from mitmproxy import command
class Analysis:
def __init__(self):
self.info = {}
def request(self, flow):
source = flow.client_conn.address[0]
self.ensure_counter(source)
counter = self.info.get(source)
size = len(str(flow.request.headers))
size += len(flow.request.raw_content)
counter['upload'] += size
ctx.log.info(f'{source} upload cost {size} bytes')
def ensure_counter(self, ip):
self.info.setdefault(ip, {'upload': 0, 'download': 0})
def response(self, flow):
source = flow.client_conn.address[0]
self.ensure_counter(source)
counter = self.info.get(source)
size = len(str(flow.response.headers))
size += len(flow.response.raw_content)
counter['download'] += size
ctx.log.info(f"{source} download cost {size} bytes")
def done(self):
with open('/tmp/flow_bytes.log', 'w') as file:
file.write(json.dumps(self.info))
@command.command("analysis.show_info")
def show_info(self):
ctx.log.info(json.dumps(self.info))
addons = [
Analysis()
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment