AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 559994
Accepted
codeScriber
codeScriber
Asked: 2013-12-09 07:36:48 +0800 CST2013-12-09 07:36:48 +0800 CST 2013-12-09 07:36:48 +0800 CST

嗅探移动流量数据

  • 772

我现在正在为我们的移动部门准备一个自动化测试实验室,主要由安卓设备组成。

对于第一阶段,我需要 HTTP 设备嗅探,我无法在设备上进行,因为它们并非全部植根,而且并非所有设备都是 4.0 及更高版本,因此它们可以使用基于 VPN 的解决方案。

我正在考虑一个将在设备wifi“高级设置”中定义的代理,并且应该使用请求响应标头+正文创建.txt文件(因为它没有特殊格式并且是纯文本对我来说应该可以正常工作) .

HTTPS 如果需要,我将在稍后解决。

我的问题是哪个代理服务器将是最快的设置和编写这样一个动作的脚本?我想一次可以发出请求的设备不会超过 10 到 15 个,在我的设置中加载不会是什么大问题,但要确保每个设备都有自己的数据打印到文件中。

我知道 squid 存在并且 tinyproxy 我知道 apache 有一个 proxy_mod 可以解决问题,但不确定它是否适合我的需要。服务器机器是 linux,所以没有提琴手会来帮助我。

linux
  • 1 1 个回答
  • 696 Views

1 个回答

  • Voted
  1. Best Answer
    Mike Pennington
    2013-12-09T08:02:33+08:002013-12-09T08:02:33+08:00

    我可以想到两个选择:

    • 带有wireshark的linux HTTP代理
    • 网络捕获

    听起来您更喜欢使用 linux HTTP 代理方法,但我也包括网络捕获信息。

    HTTP 代理捕获

    使用python-proxy,以及我在页面底部添加的源代码修改。默认情况下,python-proxy 仅侦听 localhost。他们的脚本中的一个小改动使它监听所有端口:

    if __name__ == '__main__':
        start_server(host='0.0.0.0')
    

    将文件保存在 linux 中后,您可以作为 unpriv 用户执行,python PythonProxy.py 现在将您的 android 客户端配置为通过 tcp/8080 上的 linux 服务器的 IP 进行代理。

    python-proxy不支持 HTTPS。还有其他类似的 python 代理项目mitmproxy确实支持 https,但我在它们方面没有取得太大的成功(再说一次,我通常将所有东西都部署在virtualenv中,这与一些 python 项目不能很好地配合)。

    在 Linux 上代理 SSL 流量的另一个选项是CharlesProxy,但我从未使用过它。虽然是商业产品...

    网络捕获

    许多托管交换机(即 Cisco / Juniper / HP / 等)将一个以太网端口的流量镜像到另一个以太网端口,在交换机上进行非常简单的配置。

               |               |
               | <--  wifi --> |
    +-------+  |               |  +---------+ Eth     +-----------------+
    | phone |--+               +--| Wifi AP |---------| Ethernet Switch |
    +-------+                     +---------+         +-----------------+
    
                                                    ^^^^^^ Sniff here
    

    此方法不支持解密 https 捕获。


    ### PythonProxy.py
    
    # <PythonProxy.py>
    #
    #Copyright (c) <2009> <Fábio Domingues - fnds3000 in gmail.com>
    #
    #Permission is hereby granted, free of charge, to any person
    #obtaining a copy of this software and associated documentation
    #files (the "Software"), to deal in the Software without
    #restriction, including without limitation the rights to use,
    #copy, modify, merge, publish, distribute, sublicense, and/or sell
    #copies of the Software, and to permit persons to whom the
    #Software is furnished to do so, subject to the following
    #conditions:
    #
    #The above copyright notice and this permission notice shall be
    #included in all copies or substantial portions of the Software.
    #
    #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    #OTHER DEALINGS IN THE SOFTWARE.
    
    """\
    Copyright (c) <2009> <Fábio Domingues - fnds3000 in gmail.com> <MIT Licence>
    
                      **************************************
                     *** Python Proxy - A Fast HTTP proxy ***
                      **************************************
    
    Neste momento este proxy é um Elie Proxy.
    
    Suporta os métodos HTTP:
     - OPTIONS;
     - GET;
     - HEAD;
     - POST;
     - PUT;
     - DELETE;
     - TRACE;
     - CONENCT.
    
    Suporta:
     - Conexões dos cliente em IPv4 ou IPv6;
     - Conexões ao alvo em IPv4 e IPv6;
     - Conexões todo o tipo de transmissão de dados TCP (CONNECT tunneling),
         p.e. ligações SSL, como é o caso do HTTPS.
    
    A fazer:
     - Verificar se o input vindo do cliente está correcto;
       - Enviar os devidos HTTP erros se não, ou simplesmente quebrar a ligação;
     - Criar um gestor de erros;
     - Criar ficheiro log de erros;
     - Colocar excepções nos sítios onde é previsível a ocorrência de erros,
         p.e.sockets e ficheiros;
     - Rever tudo e melhorar a estrutura do programar e colocar nomes adequados nas
         variáveis e métodos;
     - Comentar o programa decentemente;
     - Doc Strings.
    
    Funcionalidades futuras:
     - Adiconar a funcionalidade de proxy anónimo e transparente;
     - Suportar FTP?.
    
    
    (!) Atenção o que se segue só tem efeito em conexões não CONNECT, para estas o
     proxy é sempre Elite.
    
    Qual a diferença entre um proxy Elite, Anónimo e Transparente?
     - Um proxy elite é totalmente anónimo, o servidor que o recebe não consegue ter
         conhecimento da existência do proxy e não recebe o endereço IP do cliente;
     - Quando é usado um proxy anónimo o servidor sabe que o cliente está a usar um
         proxy mas não sabe o endereço IP do cliente;
         É enviado o cabeçalho HTTP "Proxy-agent".
     - Um proxy transparente fornece ao servidor o IP do cliente e um informação que
         se está a usar um proxy.
         São enviados os cabeçalhos HTTP "Proxy-agent" e "HTTP_X_FORWARDED_FOR".
    
    """
    
    import socket, thread, select
    
    __version__ = '0.1.0 Draft 1'
    BUFLEN = 8192
    VERSION = 'Python Proxy/'+__version__
    HTTPVER = 'HTTP/1.1'
    
    class ConnectionHandler:
        def __init__(self, connection, address, timeout):
            self.client = connection
            self.client_buffer = ''
            self.timeout = timeout
            self.method, self.path, self.protocol = self.get_base_header()
            if self.method=='CONNECT':
                self.method_CONNECT()
            elif self.method in ('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT',
                                 'DELETE', 'TRACE'):
                self.method_others()
            self.client.close()
            self.target.close()
    
        def get_base_header(self):
            while 1:
                self.client_buffer += self.client.recv(BUFLEN)
                end = self.client_buffer.find('\n')
                if end!=-1:
                    break
            print '%s'%self.client_buffer[:end]#debug
            data = (self.client_buffer[:end+1]).split()
            self.client_buffer = self.client_buffer[end+1:]
            return data
    
        def method_CONNECT(self):
            self._connect_target(self.path)
            self.client.send(HTTPVER+' 200 Connection established\n'+
                             'Proxy-agent: %s\n\n'%VERSION)
            self.client_buffer = ''
            self._read_write()        
    
        def method_others(self):
            self.path = self.path[7:]
            i = self.path.find('/')
            host = self.path[:i]        
            path = self.path[i:]
            self._connect_target(host)
            self.target.send('%s %s %s\n'%(self.method, path, self.protocol)+
                             self.client_buffer)
            self.client_buffer = ''
            self._read_write()
    
        def _connect_target(self, host):
            i = host.find(':')
            if i!=-1:
                port = int(host[i+1:])
                host = host[:i]
            else:
                port = 80
            (soc_family, _, _, _, address) = socket.getaddrinfo(host, port)[0]
            self.target = socket.socket(soc_family)
            self.target.connect(address)
    
        def _read_write(self):
            time_out_max = self.timeout/3
            socs = [self.client, self.target]
            count = 0
            while 1:
                count += 1
                (recv, _, error) = select.select(socs, [], socs, 3)
                if error:
                    break
                if recv:
                    for in_ in recv:
                        data = in_.recv(BUFLEN)
                        if in_ is self.client:
                            out = self.target
                        else:
                            out = self.client
                        if data:
                            out.send(data)
                            count = 0
                if count == time_out_max:
                    break
    
    def start_server(host='localhost', port=8080, IPv6=False, timeout=60,
                      handler=ConnectionHandler):
        if IPv6==True:
            soc_type=socket.AF_INET6
        else:
            soc_type=socket.AF_INET
        soc = socket.socket(soc_type)
        soc.bind((host, port))
        print "Serving on %s:%d."%(host, port)#debug
        soc.listen(0)
        while 1:
            thread.start_new_thread(handler, soc.accept()+(timeout,))
    
    if __name__ == '__main__':
        start_server(host='0.0.0.0')
    
    • 5

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve