×ðÁú¿­Ê±¹ÙÍøµÇ¼

mitmproxyÓëpythonʹÓý̳Ì

mitmproxyÊÇÒ»¿îÇ¿Ê¢µÄhttpÊðÀí¹¤¾ß£¬¿ÉÓëpythonÍŽáʹÓÃʵÏÖ×Ô¶¯»¯ºÍ¶¨ÖÆ¡£Æä½¹µã¹¦Ð§°üÀ¨£º×°Öãºpip install mitmproxyÔËÐУºmitmproxy –host –port python¾ç±¾£ºµ¼Èëmitmproxy¿â½¨Éè¼ÌÐø×Ômitmproxy.http.httpflowµÄÊÂÎñ´¦Àí³ÌÐòÀàÔÚmitmproxy½»»¥Ê½¿ØÖÆ̨ÖÐ×¢²áÊÂÎñ´¦Àí³ÌÐòÀà¸ß¼¶Ó÷¨£ºÇëÇó×èµ²ºÍÐÞ¸ÄÁ÷ÖØ·Åtls½âÃÜ×Ô½ç˵¾ç±¾

mitmproxy Óë Python ʹÓý̳Ì

¼ò½é

mitmproxy ÊÇÒ»¿î¹¦Ð§Ç¿Ê¢µÄ HTTP ÊðÀí¹¤¾ß£¬ÔÊÐíÓû§×èµ²¡¢Ð޸ĺÍÖØ·Å HTTP ÇëÇóºÍÏìÓ¦¡£ËüÆÕ±éÓ¦ÓÃÓÚ Web ¿ª·¢¡¢²âÊÔºÍÇå¾²ÁìÓò¡£Óë Python ÍŽáʹÓÃʱ£¬mitmproxy ¿ÉÒÔʵÏÖÇ¿Ê¢µÄ×Ô¶¯»¯ºÍ¶¨ÖÆ¡£

×°ÖÃ

Á¬Ã¦Ñ§Ï°¡°PythonÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ҪװÖà mitmproxy£¬ÇëʹÓÃÒÔÏÂÏÂÁ

pip install mitmproxy

µÇ¼ºó¸´ÖÆ

Ê×´ÎÔËÐÐ

Ê×´ÎÔËÐÐ mitmproxy ʱ£¬ÏÂÁîÐÐÖл᷺ÆðÒ»¸ö½»»¥Ê½¿ØÖÆ̨£º

mitmproxy --host <hostname> --port <port></port></hostname>

µÇ¼ºó¸´ÖÆ

ÆäÖУº

  • ÊÇÒª¼àÌýµÄ IP µØµã»òÖ÷»úÃû£¨Ä¬ÒÔΪ 0.0.0.0£©
  • ÊÇÒª¼àÌýµÄ¶Ë¿ÚºÅ£¨Ä¬ÒÔΪ 8080£©

ʹÓà Python ¾ç±¾

mitmproxy Ö§³ÖʹÓà Python ¾ç±¾À©Õ¹Æ书Ч¡£ÒªÔÚ Python ¾ç±¾ÖÐʹÓà mitmproxy£¬ÇëÖ´ÐÐÒÔÏ°취£º

  1. µ¼Èë mitmproxy ¿â£º

    import mitmproxy

    µÇ¼ºó¸´ÖÆ

  2. ½¨ÉèÒ»¸öÐ嵀 mitmproxy ÊÂÎñ´¦Àí³ÌÐòÀ࣬¸ÃÀà¼ÌÐø×Ô mitmproxy.http.HTTPFlow£º

    class MyEventHandler(mitmproxy.http.HTTPFlow):
        def __init__(self, flow):
            super().__init__(flow)
    
        def request(self):
            # ÔÚÊÕµ½ÇëÇóʱִÐдËÒªÁì
            pass
    
        def response(self):
            # ÔÚÊÕµ½ÏìӦʱִÐдËÒªÁì
            pass

    µÇ¼ºó¸´ÖÆ

  3. ÔÚ mitmproxy ½»»¥Ê½¿ØÖÆ̨ÖУ¬Ê¹Óà event_hooks.load º¯Êý×¢²áÊÂÎñ´¦Àí³ÌÐòÀࣺ

    event_hooks.load("my_module.MyEventHandler")

    µÇ¼ºó¸´ÖÆ

    ÆäÖÐ my_module ÊÇ°üÀ¨ÊÂÎñ´¦Àí³ÌÐòÀàµÄ Python ¾ç±¾µÄÃû³Æ¡£

ʾÀý¾ç±¾

ÒÔÏÂÊÇÒ»¸öʾÀý Python ¾ç±¾£¬ËüÐÞ¸Ä¶Ô example.com µÄËùÓÐ HTTP ÇëÇó£º

import mitmproxy

class ModifyRequest(mitmproxy.http.HTTPFlow):
    def request(self):
        if self.request.host == "example.com":
            self.request.headers["User-Agent"] = "My Custom User Agent"

event_hooks.load("modify_request.ModifyRequest")

µÇ¼ºó¸´ÖÆ

¸ß¼¶Ó÷¨

mitmproxy ºÍ Python ÍŽáʹÓÃʱ£¬ÌṩÁËÐí¶à¸ß¼¶¹¦Ð§£¬ÀýÈ磺

  • ÇëÇó×èµ²ºÍÐ޸ģº×èµ²ºÍÐÞ¸Ä HTTP ÇëÇóºÍÏìÓ¦£¬ÒÔ¾ÙÐе÷ÊÔ»òÇå¾²²âÊÔ¡£
  • Á÷ÖØ·Å£º²¶»ñºÍÖØ·Å HTTP Á÷Á¿£¬ÒÔ¾ÙÐвâÊÔ»ò¹ÊÕÏɨ³ý¡£
  • TLS ½âÃÜ£º½âÃÜ HTTPS Á÷Á¿£¬ÒÔÆÊÎöºÍÐÞ¸ÄÇå¾²Á÷Á¿¡£
  • ×Ô½ç˵¾ç±¾£º±àд×Ô½ç˵ Python ¾ç±¾ÒÔÀ©Õ¹ mitmproxy µÄ¹¦Ð§¡£

ͨ¹ýÏàʶ mitmproxy ºÍ Python µÄÇ¿Ê¢¹¦Ð§£¬¿ª·¢Ö°Ô±¿ÉÒÔ½¨ÉèÇ¿Ê¢µÄ¹¤¾ßºÍ×Ô¶¯»¯£¬ÒÔÌá¸ß Web ¿ª·¢¡¢²âÊÔºÍÇå¾²Á÷³ÌµÄЧÂÊ¡£

ÒÔÉϾÍÊÇmitmproxyÓëpythonʹÓý̵̳ÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ