我想观看ftp流量并找到使用tshark访问哪些ftp网址.对于我可以使用的http流量
tshark -i eth0 -f 'port 80' -l -t ad -n -R 'http.request' -T fields -e http.host -e http.request.uri
Run Code Online (Sandbox Code Playgroud)
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这样的无状态事务协议 - 使用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
Run Code Online (Sandbox Code Playgroud)
当用户尝试从FTP服务器(在此示例中使用客户端软件curl)检索文件时收到的输出可能如下所示:
USER username
PASS password
PWD
CWD Documents
EPSV
TYPE I
SIZE somefile.ext
RETR somefile.ext
QUIT
Run Code Online (Sandbox Code Playgroud)
对此进行一些处理可能会为您提供类似文件检索日志的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";'
Run Code Online (Sandbox Code Playgroud)
对于上面相同的FTP会话,此脚本将产生一行输出:
/Documents/somefile.ext
Run Code Online (Sandbox Code Playgroud)
我希望有所帮助.