Advertisement
Guest User

mitmproxystartstop.py

a guest
Jan 24th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import logging
  2.  
  3. from mitmproxy.tools.dump import DumpMaster
  4. from mitmproxy import options
  5. from mitmproxy import http
  6. import asyncio
  7.  
  8. logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  9. logger = logging.getLogger(__name__)
  10.  
  11. # sudo lsof -i :8080
  12. # sudo kill -9 PID
  13.  
  14. class ProxyManager:
  15. def __init__(self, port=8080):
  16. self.port = port
  17. self.master = None
  18.  
  19. def start_proxy(self):
  20. """Start MITMproxy"""
  21. opts = options.Options(
  22. listen_host='0.0.0.0', # Listen on all interfaces
  23. listen_port=self.port,
  24. mode='regular', # Explicit proxy mode
  25. ssl_insecure=True # Allow insecure connections
  26.  
  27. )
  28. logger.info(f"Starting proxy on 0.0.0.0:{self.port}")
  29.  
  30. async def run_proxy():
  31. self.master = DumpMaster(opts)
  32. await self.master.run()
  33.  
  34. asyncio.run(run_proxy())
  35.  
  36.  
  37. def view_request(self, url, flow:http.HTTPFlow) -> None:
  38. """View a specific request based on url."""
  39.  
  40. if flow.request.pretty_url == url:
  41. logger.info(f"Found the URL: {flow.request.pretty_url}")
  42. logger.info(f"Request Method: {flow.request.method}")
  43. logger.info(f"Request Headers: {flow.request.headers}")
  44. logger.info(f"Request Body: {flow.request.content}")
  45.  
  46.  
  47. def capture_url_request(self, url):
  48. """
  49. This should return a request that is specific to a url.
  50.  
  51.  
  52. :parameter: url - Url to watch for.
  53. :return: The request
  54. """
  55.  
  56. pass
  57.  
  58. def alter_request_header(self, url, header:dict):
  59. """Alter a header of the request, send it and return the response."""
  60.  
  61. pass
  62.  
  63. def alter_request_content(self, url, content: dict):
  64. """Alter a part of the request, send it and return the response."""
  65.  
  66. pass
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement