【问题标题】:Capture ftp hostname and uri using tshark (wireshark)使用 tshark (wireshark) 捕获 ftp 主机名和 uri
【发布时间】:2011-07-09 02:10:12
【问题描述】:

我想查看 ftp 流量并找出 tshark 正在访问哪些 ftp url。对于http流量,我可以使用

tshark -i eth0 -f 'port 80' -l -t ad -n -R 'http.request' -T fields -e http.host -e http.request.uri

Wireshark 的显示过滤器包含字段 http.request.uri 和 http.host 见:http://www.wireshark.org/docs/dfref/h/http.html 但这些选项不适用于 ftp 流量。 http://www.wireshark.org/docs/dfref/f/ftp.html

我能做什么?

【问题讨论】:

    标签: ftp wireshark


    【解决方案1】:

    问题在于 FTP 不是像 HTTP 那样的无状态事务协议 - 使用 HTTP,客户端执行单个请求,详细说明传递文件所需的所有参数,服务器以包含所有元数据和文件内容。

    相比之下,FTP 是一种聊天式协议:要完成某事,您打开与服务器的连接并开始与服务器聊天 - 登录、切换到某个目录、列出文件、获取此文件等。

    你可以像这样使用wireshark收听这个对话:

    tshark  -i lo -f 'port 21' -l -t ad -n -R ftp.request.command -T fields -e ftp.request.command -e ftp.request.arg 
    

    当用户尝试从 FTP 服务器检索文件(在本示例中使用客户端软件 curl)时收到的输出可能如下所示:

    USER    username
    PASS    password
    PWD
    CWD     Documents
    EPSV
    TYPE    I
    SIZE    somefile.ext
    RETR    somefile.ext
    QUIT
    

    对它进行一些处理可能会为您提供一个类似于文件检索日志的 URL。例如,我用 perl 想出了这个东西:

    tshark  -i lo -f 'port 21' -l -t ad -n -R ftp.request.command \
      -T fields -e ftp.request.command -e ftp.request.arg | \
      perl -nle '
        m|CWD\s*(\S+)| and do { 
          $dir=$1; 
          if ($dir =~ m,^/,) { $cwd=$dir } else { $cwd .= "/$dir"; } 
        }; 
        m|RETR\s*(\S+)| and print "$cwd/$1";'
    

    对于上述相同的 FTP 会话,此脚本将产生一行输出:

    /Documents/somefile.ext
    

    希望对你有帮助。

    【讨论】:

    • 是的,我已经实现了这样的解决方案。无论如何感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    相关资源
    最近更新 更多