Wireshark之FTP协议分析(一)

最近项目需求,需要抓取并还原网络中通过ftp传输的文件。故对ftp协议进行了简单学习,总结如下。

1. ftp协议概述

这部分内容我参考的百度文库的一篇文档:

https://wenku.baidu.com/view/fef7d6d658fb770bf68a55ae.html

里面讲的很详细。在此对重点的部分进行总结一下。

1)ftp服务端的用到两个端口20和21。

2)FTP使用不同的端口号传输不同的内容,会建立不同的TCP连接。首先,使用 TCP 生成一个虚拟连接用于控制信息,然后再生成一个单独的 TCP 连接用于数据传输。

3)FTP有两种工作模式,分别是主动模式(PORT)和被动模式(PASV)两种模式,这两种模式是按照FTP服务器的“角度”来说的,更通俗一点说就是:在传输数据时,如果是服务器主动连接客户端,那就是主动模式;如果是客户端主动连接服务器,那就是被动模式。主动模式下,服务端采用端口20做数据连接。

4)目前ftp客户端与服务端的 传输方式为流方式,传输类型为ASCII或是二进制,传输结构为文件结构(文件被认为一个连续的字节流)。

5)ftp命令

    ftp命令和应答在客户和服务端的控制连接上以NVT ASCII码(百度了解)形式传输。

     从客户发送给服务端的ftp命令超过30种,这些命令都是3或4个字节的大写ASCII字符,其中一些带选项参数。我从Wikipedia中拷贝过来如下:

CommandRFCDescription
ABOR Abort an active file transfer.
ACCT Account information.
ADATRFC 2228Authentication/Security Data
ALLO Allocate sufficient disk space to receive a file.
APPE Append (with create)
AUTHRFC 2228Authentication/Security Mechanism
AVBLStreamlined FTP Command ExtensionsGet the available space
CCCRFC 2228Clear Command Channel
CDUP Change to Parent Directory.
CONFRFC 2228Confidentiality Protection Command
CSIDStreamlined FTP Command ExtensionsClient / Server Identification
CWDRFC 697Change working directory.
DELE Delete file.
DSIZStreamlined FTP Command ExtensionsGet the directory size
ENCRFC 2228Privacy Protected Channel
EPRTRFC 2428Specifies an extended address and port to which the server should connect.
EPSVRFC 2428Enter extended passive mode.
FEATRFC 2389Get the feature list implemented by the server.
HELP Returns usage documentation on a command if specified, else a general help document is returned.
HOSTRFC 7151Identify desired virtual host on server, by name.
LANGRFC 2640Language Negotiation
LIST Returns information of a file or directory if specified, else information of the current working directory is returned.
LPRTRFC 1639Specifies a long address and port to which the server should connect.
LPSVRFC 1639Enter long passive mode.
MDTMRFC 3659Return the last-modified time of a specified file.
MFCTThe 'MFMT', 'MFCT', and 'MFF' Command Extensions for FTPModify the creation time of a file.
MFFThe 'MFMT', 'MFCT', and 'MFF' Command Extensions for FTPModify fact (the last modification time, creation time, UNIX group/owner/mode of a file).
MFMTThe 'MFMT', 'MFCT', and 'MFF' Command Extensions for FTPModify the last modification time of a file.
MICRFC 2228Integrity Protected Command
MKD Make directory.
MLSDRFC 3659Lists the contents of a directory if a directory is named.
MLSTRFC 3659Provides data about exactly the object named on its command line, and no others.
MODE Sets the transfer mode (Stream, Block, or Compressed).
NLST Returns a list of file names in a specified directory.
NOOP No operation (dummy packet; used mostly on keepalives).
OPTSRFC 2389Select options for a feature (for example OPTS UTF8 ON).
PASS Authentication password.
PASV Enter passive mode.
PBSZRFC 2228Protection Buffer Size
PORT Specifies an address and port to which the server should connect.
PROTRFC 2228Data Channel Protection Level.
PWD Print working directory. Returns the current directory of the host.
QUIT Disconnect.
REIN Re initializes the connection.
RESTRFC 3659Restart transfer from the specified point.
RETR Retrieve a copy of the file
RMD Remove a directory.
RMDAStreamlined FTP Command ExtensionsRemove a directory tree
RNFR Rename from.
RNTO Rename to.
SITE Sends site specific commands to remote server (like SITE IDLE 60 or SITE UMASK 002). Inspect SITE HELP output for complete list of supported commands.
SIZERFC 3659Return the size of a file.
SMNT Mount file structure.
SPSVFTP Extension Allowing IP Forwarding (NATs)Use single port passive mode (only one TCP port number for both control connections and passive-mode data connections)
STAT Returns the current status.
STOR Accept the data and to store the data as a file at the server site
STOU Store file uniquely.
STRU Set file transfer structure.
SYST Return system type.
THMBStreamlined FTP Command ExtensionsGet a thumbnail of a remote image file
TYPE Sets the transfer mode (ASCII/Binary).
USER Authentication username.
XCUPRFC 775Change to the parent of the current working directory
XMKDRFC 775Make a directory
XPWDRFC 775Print the current working directory
XRCPRFC 743 
XRMDRFC 775Remove the directory
XRSQRFC 743 
XSEMRFC 737Send, mail if cannot
XSENRFC 737Send to terminal

6)ftp应答

ftp应答都是ASCII码形式的3位数字,并跟有报文选项。应答3位码中每一位数字都有不同的含义,这里就不详细列出(脑袋记不住)。直接拷贝Wikipedia的常见的应答码,如下:

CodeExplanation
100 SeriesThe requested action is being initiated, expect another reply before proceeding with a new command.
110Restart marker replay . In this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy = mmmm where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and "=").
120Service ready in nnn minutes.
125Data connection already open; transfer starting.
150File status okay; about to open data connection.
200 SeriesThe requested action has been successfully completed.
202Command not implemented, superfluous at this site.
211System status, or system help reply.
212Directory status.
213File status.
214Help message. Explains how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user.
215NAME system type. Where NAME is an official system name from the registry kept by IANA.
220Service ready for new user.
221Service closing control connection.
225Data connection open; no transfer in progress.
226Closing data connection. Requested file action successful (for example, file transfer or file abort).
227Entering Passive Mode (h1,h2,h3,h4,p1,p2).
228Entering Long Passive Mode (long address, port).
229Entering Extended Passive Mode (|||port|).
230User logged in, proceed. Logged out if appropriate.
231User logged out; service terminated.
232Logout command noted, will complete when transfer done.
234Specifies that the server accepts the authentication mechanism specified by the client, and the exchange of security data is complete. A higher level nonstandard code created by Microsoft.
250Requested file action okay, completed.
257"PATHNAME" created.
300 SeriesThe command has been accepted, but the requested action is on hold, pending receipt of further information.
331User name okay, need password.
332Need account for login.
350Requested file action pending further information
400 SeriesThe command was not accepted and the requested action did not take place, but the error condition is temporary and the action may be requested again.
421Service not available, closing control connection. This may be a reply to any command if the service knows it must shut down.
425Can't open data connection.
426Connection closed; transfer aborted.
430Invalid username or password
434Requested host unavailable.
450Requested file action not taken.
451Requested action aborted. Local error in processing.
452Requested action not taken. Insufficient storage space in system.File unavailable (e.g., file busy).
500 SeriesSyntax error, command unrecognized and the requested action did not take place. This may include errors such as command line too long.
501Syntax error in parameters or arguments.
502Command not implemented.
503Bad sequence of commands.
504Command not implemented for that parameter.
530Not logged in.
532Need account for storing files.
534Could Not Connect to Server - Policy Requires SSL
550Requested action not taken. File unavailable (e.g., file not found, no access).
551Requested action aborted. Page type unknown.
552Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
553Requested action not taken. File name not allowed.
600 SeriesReplies regarding confidentiality and integrity
631Integrity protected reply.
632Confidentiality and integrity protected reply.
633Confidentiality protected reply.
10000 SeriesCommon Winsock Error Codes[2] (These are not FTP return codes)
10054Connection reset by peer. The connection was forcibly closed by the remote host.
10060Cannot connect to remote server.
10061Cannot connect to remote server. The connection is actively refused by the server.
10066Directory not empty.
10068Too many users, server is full.

总结这么多,还是得抓包实际分析来看,下一节以实际抓包来分析ftp的整个连接过程。

 

参考:

《TCP/IP详解 卷1:协议》

https://wenku.baidu.com/view/fef7d6d658fb770bf68a55ae.html

https://en.wikipedia.org/wiki/List_of_FTP_commands

https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes

 

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值