首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绕过代理,在Python中使用mitmproxy使用HTTP GET请求从服务器捕获网页数据

绕过代理,在Python中使用mitmproxy使用HTTP GET请求从服务器捕获网页数据
EN

Stack Overflow用户
提问于 2015-03-16 15:02:44
回答 1查看 1.2K关注 0票数 1

我需要使用mitmproxy绕过代理,并使用GET请求捕获web数据。我使用的是Windows 7、python 2.7和mitmproxy python

我尝试了以下代码:

代码语言:javascript
复制
#!/usr/bin/env python
"""
    This example shows how to build a proxy based on mitmproxy's Flow
    primitives.

    Note that request and response messages are not automatically replied to,
    so we need to implement handlers to do this.
"""
import sys,os
import os
import cStringIO
import threading
import thread
import exceptions
import gc
from libmproxy import proxy, flow
from libmproxy.proxy import config
from libmproxy.proxy import server
from libmproxy.proxy.server import ProxyServer
from libmproxy.platform.windows import TransparentProxy


class MyMaster(flow.FlowMaster):
    def run(self):
        try:
            flow.FlowMaster.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def responseheaders(context, flow):
        ct = flow.response.headers["Content-Type"]
        if ct and len(ct) > 0 and ct[0].startswith("application/"):
            flow.stream = True
            print "streaming"

    def handle_request(self, r):
        print r
        f = flow.FlowMaster.handle_request(self, r)
        if f:
            def run():
                r.reply()
                return f
            threading.Thread(target=run).start()
        else:
            return null

    def handle_response(self, r):
        f = flow.FlowMaster.handle_response(self, r)
        if f:
            def run():
                r.reply()
                return f
            threading.Thread(target=run).start()
        else:
            return null


config = proxy.config.ProxyConfig(
    #ca_file=os.path.expanduser("~\.mitmproxy\mitmproxy-ca.pem")
    confdir=os.path.realpath('.\\conf')#, mode="transparent"
)

gc.enable()

gc.set_threshold(250, 10, 10)

print gc.get_threshold()

state = flow.State()
server = ProxyServer(config, 8080)
#server = TransparentProxy()
m = MyMaster(server, state)

TransparentProxy().setup()

#proxifier = TransparentProxy()

#proxifier.start()

print "got here"

m.run();

但得到了一些错误:

代码语言:javascript
复制
confdir=os.path.realpath(r'C:\Users\rnive\Documents\certificates')      ``#,mode="transparent"
TypeError: __init__() got an unexpected keyword argument 'confdir'

任何对纠正此错误的帮助。通过双击mitmproxy- CA -cert.p12文件导入mitmproxy ca,并在chrome浏览器中加载mitm.it,结果如下所示:

如果您可以看到这一点,则表明流量未通过mitmproxy。

有什么关于如何识别和纠正TypeError的帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2015-04-19 03:41:00

检查浏览器中的代理设置。错误消息'...没有通过mitmproxy的流量应该消失。在Firefox中,转到选项|高级|网络|设置。另请参见here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29071220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档