ftp - 使用 tshark (wireshark) 捕获 ftp 主机名和 uri

标签 ftp wireshark

我想查看 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 不是像 HTTP 那样的无状态事务协议(protocol) - 使用 HTTP 时,客户端执行单个请求,其中详细说明传送文件所需的所有参数,服务器以包含所有元数据和文件内容。

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

您可以像这样使用 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 session ,此脚本将产生一行输出:

/Documents/somefile.ext

希望对您有所帮助。

关于ftp - 使用 tshark (wireshark) 捕获 ftp 主机名和 uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6357215/

相关文章:

udp - 特定 UDP 字节的 wireshark 捕获过滤器

wireshark - 如何使用 wireshark 从 tcpdump 获取到特定主机的连接数(计数)

c++ - 如何编写监听网络流量的程序? (即 wireshark)

c - 未收到 ARP 请求,wireshark 无法读取 arp header

networking - 使用lua读取pcap文件

c++ - C/C++ ftplib : Undefined reference to _imp__FtpInit

Python 显式 FTP 不协商 TLS

sql - 转储 postgresql 数据库并通过 ftp 访问它们

javascript - 无法使用 AngularJS 和 PHP 在 FTP 上上传图像。返回 403

file-upload - 如何检测文件正在通过 FTP 上传