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

pythonʹÓÃmitmproxy½Ì³Ì

mitmproxyÊÇÒ»¿îÓÃpython±àдµÄ¸ß¼¶httpÊðÀí¹¤¾ß £¬ÌṩÁËÇ¿Ê¢µÄapiÀ´ÊµÏÖ×Ô½ç˵µÄÊðÀíÐÐΪ£º×°ÖúÍÉèÖãºÊ¹ÓÃpip×°ÖÃmitmproxy £¬È»ºóͨ¹ýmitmproxyÏÂÁîÆô¶¯Ð§ÀÍ¡£×èµ²Á÷Á¿£º½¨Éèpython¾ç±¾²¢Ê¹ÓÃmitmproxy apiµÄrequest()ºÍresponse()º¯ÊýÀ´×èµ²ºÍ´¦ÀíhttpÇëÇóºÍÏìÓ¦¡£Ð޸ĺÍÖØ·ÅÇëÇó£ºÔÚrequest()º¯ÊýÖиüÐÂÇëÇ󹤾ßÒÔÐÞ¸ÄÇëÇó £¬²¢Ê¹ÓÃreplay()º¯ÊýÖØ·ÅÇëÇ󡣸߼¶¹¦Ð§£ºmitmproxy»¹ÌṩÁËwebsocketsÖ§³Ö¡¢t

Python ʹÓà mitmproxy ½Ì³Ì

ÏÈÈÝ

mitmproxy ÊÇÒ»¿îÇ¿Ê¢µÄ HTTP ÊðÀí¹¤¾ß £¬¿ÉÓÃÓÚ×èµ²¡¢Ð޸ĺÍÖØ·Å HTTP Á÷Á¿¡£ËüÔÚ Python Öбàд £¬Îª¹¹½¨×Ô½ç˵ÊðÀí¾ç±¾ÌṩÁ˸߶ȵĿɶ¨ÖÆÐÔ¡£±¾ÎĽ«Ö¸µ¼ÄúÔõÑùʹÓà Python ÉèÖúÍʹÓà mitmproxy¡£

×°ÖÃ

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

ʹÓà pip ×°Öà mitmproxy£º

pip install mitmproxy

µÇ¼ºó¸´ÖÆ

ÉèÖÃÊðÀí

ÒªÉèÖÃÊðÀí £¬ÇëÔËÐÐÒÔÏÂÏÂÁ

mitmproxy

µÇ¼ºó¸´ÖÆ

Õ⽫Æô¶¯ mitmproxy ЧÀÍ £¬²¢½«ÆäÓÃ×÷ÍâµØÊðÀí¡£Äú¿ÉÒÔÔÚä¯ÀÀÆ÷»òÆäËûÓ¦ÓóÌÐòÖÐÉèÖÃÊðÀíÉèÖÃÀ´Ê¹ÓôËÊðÀí¡£

×èµ²ÇëÇóºÍÏìÓ¦

mitmproxy ÌṩÁËÇ¿Ê¢µÄ API £¬ÓÃÓÚ×èµ²ºÍÐÞ¸Ä HTTP ÇëÇóºÍÏìÓ¦¡£Äú¿ÉÒÔ±àд×Ô½ç˵½ÅÔ­À´ÊµÏÖËùÐèµÄ²Ù×÷¡£

ÒªÔÚ Python ÖÐ×èµ²Á÷Á¿ £¬Ç뽨ÉèÒÔϾ籾£º

from mitmproxy import http

def request(flow: http.HTTPFlow):
    # ÔÚ´ËËæ´¦ÀíÇëÇó
    print(flow.request.url)

def response(flow: http.HTTPFlow):
    # ÔÚ´ËËæ´¦ÀíÏìÓ¦
    print(flow.response.text)

µÇ¼ºó¸´ÖÆ

½«´Ë¾ç±¾ÉúÑÄÔÚÎļþÖÐ £¬ÀýÈç my_script.py £¬È»ºóͨ¹ýÒÔÏÂÏÂÁîÔËÐÐ mitmproxy ²¢¼ÓÔؾ籾£º

mitmproxy --set addons=my_script.py

µÇ¼ºó¸´ÖÆ

Ð޸ĺÍÖØ·ÅÇëÇó

³ýÁË×èµ²Á÷Á¿ £¬Äú»¹¿ÉÒÔʹÓà mitmproxy Ð޸ĺÍÖØ·ÅÇëÇó¡£

ÒªÐÞ¸ÄÇëÇó £¬ÇëÔÚ request() º¯ÊýÖиüÐÂÇëÇ󹤾ߣº

def request(flow: http.HTTPFlow):
    flow.request.url = "https://example.com/"

µÇ¼ºó¸´ÖÆ

ÒªÖØ·ÅÇëÇó £¬ÇëʹÓà replay() º¯Êý£º

from mitmproxy import script

class ReplayFlow(script.Abstraction):
    def replay(self, flow):
        self.master.replay_request(flow)

µÇ¼ºó¸´ÖÆ

¸ß¼¶¹¦Ð§

mitmproxy ÌṩÁËÆÕ±éµÄ¸ß¼¶¹¦Ð§ £¬°üÀ¨£º

  • WebSockets Ö§³Ö
  • TCP ÊðÀí
  • WebSocket ÖÕ¶Ë
  • Á÷Á¿×ª´¢ºÍÖز¥

Äú¿ÉÒÔͨ¹ý¹Ù·½ÎĵµÉó²éÕâЩ¹¦Ð§µÄÏêϸÐÅÏ¢£ºhttps://docs.mitmproxy.org/

½áÂÛ

Python ÖÐµÄ mitmproxy Ϊ¿ª·¢×Ô½ç˵ HTTP ÊðÀí¾ç±¾ÌṩÁËÇ¿Ê¢µÄ¹¤¾ß¡£±¾½Ì³ÌÌṩÁËÉèÖúÍʹÓà mitmproxy µÄ»ù´¡ÖªÊ¶ £¬ÏêϸÏÈÈÝÁË×èµ²¡¢Ð޸ĺÍÖØ·ÅÁ÷Á¿µÄÊÖÒÕ¡£ÕÆÎÕÁËÕâЩ»ù´¡ÖªÊ¶ £¬Äú¾Í¿ÉÒÔ¹¹½¨ÖØ´óµÄÊðÀí½ÅÔ­À´Öª×ãÖÖÖÖÐèÇó¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ