mitmproxy ¾ç±¾±à³Ì½Ì³Ì
mitmproxy ÊÇÒ»¸ö http/https ÊðÀí£¬¿Éͨ¹ý¾ç±¾À©Õ¹Æ书Ч¡£Ê¹Óà mitmproxy ¾ç±¾£¬Óû§¿ÉÒÔ×èµ²¡¢Ð޸ĺÍÖØ·ÅÍøÂçÇëÇóºÍÏìÓ¦£¬ÓÃÓÚµ÷ÊÔ¡¢²âÊÔºÍÇå¾²ÆÊÎö¡£mitmproxy ¾ç±¾¿ÉÒÔͨ¹ý±àд×Ô½ç˵ python ¾ç±¾ÊµÏÖ£¬ÕâЩ¾ç±¾¿ÉÒÔ´¦Öóͷ£ÒÔÏÂÊÂÎñ£ºrequest_headers£º·¢ËÍÇëÇóͷʱ´¥·¢response_headers£ºÎüÊÕµ½ÏìӦͷʱ´¥·¢request_body£º·¢ËÍÇëÇóÖ÷Ìåʱ´¥·¢response_body£ºÎüÊÕµ½ÏìÓ¦Ö÷Ìåʱ´¥·¢Óû§¿Éͨ¹ý flow ¹¤¾ß»á¼ûÕýÔÚ´¦Öóͷ£
mitmproxy ¾ç±¾±à³Ì½Ì³Ì
ʲôÊÇ mitmproxy£¿
mitmproxy ÊÇÒ»¸ö¹¦Ð§Ç¿Ê¢µÄ¿ªÔ´ HTTP/HTTPS ÊðÀí£¬ÔÊÐíÓû§×èµ²¡¢Ð޸ĺÍÖØ·ÅÍøÂçÇëÇóºÍÏìÓ¦¡£ËüÆÕ±éÓÃÓÚµ÷ÊÔ¡¢²âÊÔºÍÇå¾²ÆÊÎö¡£
ΪʲôҪʹÓà mitmproxy ¾ç±¾£¿
mitmproxy ¾ç±¾ÔÊÐíÓû§Í¨¹ý±àд×Ô½ç˵ Python ¾ç±¾À©Õ¹ÊðÀíµÄ¹¦Ð§¡£ÕâЩ¾ç±¾¿ÉÒÔÖ´ÐФµ¤Þ¤¶¤Þ¤ÊʹÃü£¬ÀýÈ磺
- ÐÞ¸ÄÇëÇó»òÏìÓ¦ÒÔ¾ÙÐвâÊÔ
- ×èµ²²¢ÉúÑÄÌض¨ÇëÇó»òÏìÓ¦¾ÙÐÐÆÊÎö
- ÔÚÇëÇó»òÏìÓ¦ÖÐ×¢Èë»ò¸ü¸Ä±êÍ·
½¨Éè mitmproxy ¾ç±¾
- ×°Öà mitmproxy£º pip install mitmproxy
- ½¨Éè¾ç±¾Îļþ£º ʹÓÃÄúϲ»¶µÄÎı¾±à¼Æ÷½¨ÉèÒ»¸öÐ嵀 Python Îļþ¡£
- µ¼Èë mitmproxy API£º Ôھ籾ÎļþµÄ¶¥²¿µ¼Èë mitmproxy.http Ä£¿é£¬Ëü°üÀ¨ÓÃÓÚ´¦Öóͷ£ HTTP ÇëÇóºÍÏìÓ¦µÄÀàºÍº¯Êý¡£
- ±àдÄúµÄ¾ç±¾£º ƾ֤ÄúµÄÐèÒª±àд Python ´úÂëÀ´´¦Öóͷ£ÇëÇó»òÏìÓ¦¡£
´¦Öóͷ£ÊÂÎñ
mitmproxy ¾ç±¾Í¨¹ý´¦Öóͷ£ÒÔÏÂÊÂÎñÓëÊðÀí¾ÙÐн»»¥£º
- request_headers£º ÔÚ·¢ËÍÇëÇóͷʱ´¥·¢¡£
- response_headers£º ÔÚÎüÊÕµ½ÏìӦͷʱ´¥·¢¡£
- request_body£º ÔÚ·¢ËÍÇëÇóÖ÷Ìåʱ´¥·¢¡£
- response_body£º ÔÚÎüÊÕµ½ÏìÓ¦Ö÷Ìåʱ´¥·¢¡£
ʾÀý¾ç±¾
ÒÔÏÂʾÀý¾ç±¾×èµ²ËùÓаüÀ¨Ìض¨±êÍ·µÄÇëÇó²¢´òÓ¡ÇëÇóºÍÏìÓ¦ÐÅÏ¢£º
from mitmproxy.http import HTTPFlow def request(flow: HTTPFlow): if "My-Custom-Header" in flow.request.headers: print(f"Request: {flow.request.method} {flow.request.url}") def response(flow: HTTPFlow): if "My-Custom-Header" in flow.request.headers: print(f"Response: {flow.response.status_code} {flow.response.reason}")
µÇ¼ºó¸´ÖÆ
ʹÓþ籾
½«ÄúµÄ¾ç±¾ÎļþÉúÑÄΪ .py Îļþ£¬È»ºóʹÓÃÒÔÏÂÏÂÁîÔËÐÐ mitmproxy£º
mitmproxy -s /path/to/your_script.py
mitmproxy ½«¼ÓÔØÄúµÄ¾ç±¾²¢×èµ²ËùÓд«ÈëµÄÁ÷Á¿¡£
ÌáÐÑ
- ¾ç±¾¿ÉÒÔ»á¼û flow ¹¤¾ß£¬Ëü°üÀ¨ÓйØÕýÔÚ´¦Öóͷ£µÄÇëÇóºÍÏìÓ¦µÄÏêϸÐÅÏ¢¡£
- ʹÓà flow.kill() ¿ÉÒÔÑïÆúÇëÇó»òÏìÓ¦£¬´Ó¶ø×èÖ¹ËüÃDZ»·¢ËÍ»òÎüÊÕ¡£
- Óйظü¶àÐÅÏ¢£¬Çë²ÎÔÄ mitmproxy Îĵµ¡£
ÒÔÉϾÍÊÇmitmproxy ¾ç±¾±à³Ì½Ì³ÌµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡