PcapPlusPlus  Next
FtpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "PayloadLayer.h"
5 
7 
10 namespace pcpp
11 {
14  {
15  protected:
16  FtpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
17  : SingleCommandTextProtocol(data, dataLen, prevLayer, packet, FTP) {};
18  FtpLayer(const std::string& command, const std::string& option)
19  : SingleCommandTextProtocol(command, option, FTP) {};
20 
21  public:
24  static bool isFtpPort(uint16_t port)
25  {
26  return port == 21;
27  }
28 
31  static bool isFtpDataPort(uint16_t port)
32  {
33  return port == 20;
34  }
35 
36  // overridden methods
37 
39  void parseNextLayer() override
40  {}
41 
43  size_t getHeaderLen() const override
44  {
45  return m_DataLen;
46  }
47 
49  void computeCalculateFields() override
50  {}
51 
54  {
56  }
57  };
58 
60  class FtpRequestLayer : public FtpLayer
61  {
62  public:
64  enum class FtpCommand : int
65  {
67  UNK,
69  ABOR = ('A') | ('B' << 8) | ('O' << 16) | ('R' << 24),
71  ACCT = ('A') | ('C' << 8) | ('C' << 16) | ('T' << 24),
73  ADAT = ('A') | ('D' << 8) | ('A' << 16) | ('T' << 24),
75  ALLO = ('A') | ('L' << 8) | ('L' << 16) | ('O' << 24),
77  APPE = ('A') | ('P' << 8) | ('P' << 16) | ('E' << 24),
79  AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
81  AVBL = ('A') | ('V' << 8) | ('B' << 16) | ('L' << 24),
83  CCC = ('C') | ('C' << 8) | ('C' << 16),
85  CDUP = ('C') | ('D' << 8) | ('U' << 16) | ('P' << 24),
87  CONF = ('C') | ('O' << 8) | ('N' << 16) | ('F' << 24),
89  CSID = ('C') | ('S' << 8) | ('I' << 16) | ('D' << 24),
91  CWD = ('C') | ('W' << 8) | ('D' << 16),
93  DELE = ('D') | ('E' << 8) | ('L' << 16) | ('E' << 24),
95  DSIZ = ('D') | ('S' << 8) | ('I' << 16) | ('Z' << 24),
97  ENC = ('E') | ('N' << 8) | ('C' << 16),
99  EPRT = ('E') | ('P' << 8) | ('R' << 16) | ('T' << 24),
101  EPSV = ('E') | ('P' << 8) | ('S' << 16) | ('V' << 24),
103  FEAT = ('F') | ('E' << 8) | ('A' << 16) | ('T' << 24),
105  HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
107  HOST = ('H') | ('O' << 8) | ('S' << 16) | ('T' << 24),
109  LANG = ('L') | ('A' << 8) | ('N' << 16) | ('G' << 24),
112  LIST = ('L') | ('I' << 8) | ('S' << 16) | ('T' << 24),
114  LPRT = ('L') | ('P' << 8) | ('R' << 16) | ('T' << 24),
116  LPSV = ('L') | ('P' << 8) | ('S' << 16) | ('V' << 24),
118  MDTM = ('M') | ('D' << 8) | ('T' << 16) | ('M' << 24),
120  MFCT = ('M') | ('F' << 8) | ('C' << 16) | ('T' << 24),
122  MFF = ('M') | ('F' << 8) | ('F' << 16),
124  MFMT = ('M') | ('F' << 8) | ('M' << 16) | ('T' << 24),
126  MIC = ('M') | ('I' << 8) | ('C' << 16),
128  MKD = ('M') | ('K' << 8) | ('D' << 16),
130  MLSD = ('M') | ('L' << 8) | ('S' << 16) | ('D' << 24),
133  MLST = ('M') | ('L' << 8) | ('S' << 16) | ('T' << 24),
135  MODE = ('M') | ('O' << 8) | ('D' << 16) | ('E' << 24),
137  NLST = ('N') | ('L' << 8) | ('S' << 16) | ('T' << 24),
139  NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
141  OPTS = ('O') | ('P' << 8) | ('T' << 16) | ('S' << 24),
143  PASS = ('P') | ('A' << 8) | ('S' << 16) | ('S' << 24),
145  PASV = ('P') | ('A' << 8) | ('S' << 16) | ('V' << 24),
147  PBSZ = ('P') | ('B' << 8) | ('S' << 16) | ('Z' << 24),
149  PORT = ('P') | ('O' << 8) | ('R' << 16) | ('T' << 24),
151  PROT = ('P') | ('R' << 8) | ('O' << 16) | ('T' << 24),
153  PWD = ('P') | ('W' << 8) | ('D' << 16),
155  QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
157  REIN = ('R') | ('E' << 8) | ('I' << 16) | ('N' << 24),
159  REST = ('R') | ('E' << 8) | ('S' << 16) | ('T' << 24),
161  RETR = ('R') | ('E' << 8) | ('T' << 16) | ('R' << 24),
163  RMD = ('R') | ('M' << 8) | ('D' << 16),
165  RMDA = ('R') | ('M' << 8) | ('D' << 16) | ('A' << 24),
167  RNFR = ('R') | ('N' << 8) | ('F' << 16) | ('R' << 24),
169  RNTO = ('R') | ('N' << 8) | ('T' << 16) | ('O' << 24),
172  SITE = ('S') | ('I' << 8) | ('T' << 16) | ('E' << 24),
174  SIZE = ('S') | ('I' << 8) | ('Z' << 16) | ('E' << 24),
176  SMNT = ('S') | ('M' << 8) | ('N' << 16) | ('T' << 24),
179  SPSV = ('S') | ('P' << 8) | ('S' << 16) | ('V' << 24),
181  STAT = ('S') | ('T' << 8) | ('A' << 16) | ('T' << 24),
183  STOR = ('S') | ('T' << 8) | ('O' << 16) | ('R' << 24),
185  STOU = ('S') | ('T' << 8) | ('O' << 16) | ('U' << 24),
187  STRU = ('S') | ('T' << 8) | ('R' << 16) | ('U' << 24),
189  SYST = ('S') | ('Y' << 8) | ('S' << 16) | ('T' << 24),
191  THMB = ('T') | ('H' << 8) | ('M' << 16) | ('B' << 24),
193  TYPE = ('T') | ('Y' << 8) | ('P' << 16) | ('E' << 24),
195  USER = ('U') | ('S' << 8) | ('E' << 16) | ('R' << 24),
197  XCUP = ('X') | ('C' << 8) | ('U' << 16) | ('P' << 24),
199  XMKD = ('X') | ('M' << 8) | ('K' << 16) | ('D' << 24),
201  XPWD = ('X') | ('P' << 8) | ('W' << 16) | ('D' << 24),
203  XRCP = ('X') | ('R' << 8) | ('C' << 16) | ('P' << 24),
205  XRMD = ('X') | ('R' << 8) | ('M' << 16) | ('D' << 24),
207  XRSQ = ('X') | ('R' << 8) | ('S' << 16) | ('Q' << 24),
209  XSEM = ('X') | ('S' << 8) | ('E' << 16) | ('M' << 24),
211  XSEN = ('X') | ('S' << 8) | ('E' << 16) | ('N' << 24)
212  };
213 
219  FtpRequestLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
220  : FtpLayer(data, dataLen, prevLayer, packet) {};
221 
225  explicit FtpRequestLayer(const FtpCommand& command, const std::string& option = "")
226  : FtpLayer(getCommandAsString(command), option) {};
227 
231  bool setCommand(FtpCommand code);
232 
236 
239  std::string getCommandString() const;
240 
244  bool setCommandOption(const std::string& value);
245 
249  std::string getCommandOption(bool removeEscapeCharacters = true) const;
250 
254  static std::string getCommandInfo(FtpCommand code);
255 
259  static std::string getCommandAsString(FtpCommand code);
260 
261  // overridden methods
262 
264  std::string toString() const override;
265  };
266 
268  class FtpResponseLayer : public FtpLayer
269  {
270  public:
272  enum class FtpStatusCode : int
273  {
275  UNKNOWN,
277  RESTART_MARKER = 110,
279  SERVICE_READY_IN_MIN = 120,
283  FILE_OK = 150,
285  COMMAND_OK = 200,
289  SYSTEM_STATUS = 211,
291  DIR_STATUS = 212,
293  FILE_STATUS = 213,
295  HELP_MESSAGE = 214,
297  NAME_SYSTEM_TYPE = 215,
303  DATA_OPEN_NO_TRANSFER = 225,
305  CLOSING_DATA = 226,
307  ENTERING_PASSIVE = 227,
311  USER_LOG_IN_PROCEED = 230,
319  REQ_FILE_OK_COMPLETE = 250,
321  PATHNAME_CREATED = 257,
323  USER_OK_NEED_PASSWORD = 331,
325  NEED_ACCOUNT = 332,
327  REQ_SEC_MECHANISM_OK = 334,
329  SEC_IS_ACCEPTABLE = 335,
333  FILE_PENDING_ACTION = 350,
335  SERVICE_NOT_AVAILABLE = 421,
339  CONNECTION_CLOSED = 426,
345  REQ_ACTION_ABORTED = 451,
347  REQ_ACTION_NOT_TAKEN = 452,
355  BAD_SEQUENCE_COMMANDS = 503,
361  NOT_LOGGED_IN = 530,
367  REQUEST_DENIED = 534,
369  FAILED_SEC_CHECK = 535,
375  FILE_UNAVAILABLE = 550,
377  PAGE_TYPE_UNKNOWN = 551,
381  FILENAME_NOT_ALLOWED = 553,
383  INTEGRITY_PROTECTED = 631,
388  };
389 
395  FtpResponseLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
396  : FtpLayer(data, dataLen, prevLayer, packet) {};
397 
401  explicit FtpResponseLayer(const FtpStatusCode& code, const std::string& option = "")
402  : FtpLayer(std::to_string(int(code)), option) {};
403 
408 
412 
415  std::string getStatusCodeString() const;
416 
420  bool setStatusOption(const std::string& value);
421 
425  std::string getStatusOption(bool removeEscapeCharacters = true) const;
426 
430  static std::string getStatusCodeAsString(FtpStatusCode code);
431 
432  // overridden methods
433 
435  std::string toString() const override;
436  };
437 
439  class FtpDataLayer : public PayloadLayer
440  {
441  public:
447  FtpDataLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
448  : PayloadLayer(data, dataLen, prevLayer, packet)
449  {
450  m_Protocol = FTP;
451  };
452 
454  std::string toString() const override;
455  };
456 } // namespace pcpp
Class for representing the data of FTP Layer.
Definition: FtpLayer.h:440
FtpDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:447
std::string toString() const override
Class for general FTP message.
Definition: FtpLayer.h:14
static bool isFtpDataPort(uint16_t port)
Definition: FtpLayer.h:31
void parseNextLayer() override
FTP is the always last so does nothing for this layer.
Definition: FtpLayer.h:39
void computeCalculateFields() override
Does nothing for this layer.
Definition: FtpLayer.h:49
OsiModelLayer getOsiModelLayer() const override
Definition: FtpLayer.h:53
size_t getHeaderLen() const override
Definition: FtpLayer.h:43
static bool isFtpPort(uint16_t port)
Definition: FtpLayer.h:24
Class for representing the request messages of FTP Layer.
Definition: FtpLayer.h:61
bool setCommandOption(const std::string &value)
static std::string getCommandAsString(FtpCommand code)
FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:219
FtpRequestLayer(const FtpCommand &command, const std::string &option="")
Definition: FtpLayer.h:225
FtpCommand getCommand() const
std::string getCommandOption(bool removeEscapeCharacters=true) const
FtpCommand
Enum for FTP command codes.
Definition: FtpLayer.h:65
@ APPE
Append (with create)
@ ALLO
Allocate sufficient disk space to receive a file.
@ PWD
Print working directory. Returns the current directory of the host.
@ AVBL
Get the available space.
@ MFCT
Modify the creation time of a file.
@ CDUP
Change to Parent Directory.
@ CSID
Client / Server Identification.
@ ABOR
Abort an active file transfer.
@ PBSZ
Protection Buffer Size.
@ USER
Authentication username.
@ PORT
Specifies an address and port to which the server should connect.
@ NLST
Returns a list of file names in a specified directory.
@ HELP
Returns usage documentation on a command if specified, else a general help document is returned.
@ FEAT
Get the feature list implemented by the server.
@ REST
Restart transfer from the specified point.
@ REIN
Re initializes the connection.
@ SIZE
Return the size of a file.
@ RETR
Retrieve a copy of the file.
@ XPWD
Print the current working directory.
@ THMB
Get a thumbnail of a remote image file.
@ NOOP
No operation (dummy packet; used mostly on keepalives).
@ STAT
Returns information on the server status, including the status of the current connection.
@ STRU
Set file transfer structure.
@ DSIZ
Get the directory size.
@ PASS
Authentication password.
@ LPRT
Specifies a long address and port to which the server should connect.
@ MDTM
Return the last-modified time of a specified file.
@ LANG
Language Negotiation.
@ CONF
Confidentiality Protection Command.
@ TYPE
Sets the transfer mode (ASCII/Binary).
@ PROT
Data Channel Protection Level.
@ MIC
Integrity Protected Command.
@ OPTS
Select options for a feature (for example OPTS UTF8 ON).
@ ACCT
Account information.
@ MLSD
Lists the contents of a directory in a standardized machine-readable format.
@ EPRT
Specifies an extended address and port to which the server should connect.
@ ENC
Privacy Protected Channel.
@ RMDA
Remove a directory tree.
@ MODE
Sets the transfer mode (Stream, Block, or Compressed).
@ XCUP
Change to the parent of the current working directory.
@ HOST
Identify desired virtual host on server, by name.
@ MFF
Modify fact (the last modification time, creation time, UNIX group/owner/mode of a file).
@ ADAT
Authentication/Security Data.
@ STOU
Store file uniquely.
@ EPSV
Enter extended passive mode.
@ CCC
Clear Command Channel.
@ XRMD
Remove the directory.
@ CWD
Change working directory.
@ SMNT
Mount file structure.
@ XSEM
Send, mail if cannot.
@ AUTH
Authentication/Security Mechanism.
@ MFMT
Modify the last modification time of a file.
@ LPSV
Enter long passive mode.
@ STOR
Accept the data and to store the data as a file at the server site.
std::string toString() const override
std::string getCommandString() const
bool setCommand(FtpCommand code)
static std::string getCommandInfo(FtpCommand code)
Class for representing the response messages of FTP Layer.
Definition: FtpLayer.h:269
FtpStatusCode getStatusCode() const
FtpResponseLayer(const FtpStatusCode &code, const std::string &option="")
Definition: FtpLayer.h:401
FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:395
std::string getStatusOption(bool removeEscapeCharacters=true) const
bool setStatusCode(FtpStatusCode code)
static std::string getStatusCodeAsString(FtpStatusCode code)
std::string toString() const override
std::string getStatusCodeString() const
bool setStatusOption(const std::string &value)
FtpStatusCode
Enum for FTP response codes.
Definition: FtpLayer.h:273
@ EXCEED_STORAGE_ALLOCATION
Requested file action aborted: Exceeded storage allocation.
@ COMMAND_PROTECTION_DENIED
Command protection level denied for policy reasons.
@ NEED_UNAVAILABLE_RESOURCE_TO_SEC
Need some unavailable resource to process security.
@ USER_OK_NEED_PASS_CHALLENGE
Username okay, need password. Challenge is ...
@ USER_LOG_IN_AUTHORIZED
User logged in, authorized by security data exchange.
@ SERVICE_CLOSING_CONTROL
Service closing control connection.
@ SERVICE_NOT_AVAILABLE
Service not available, closing control connection.
@ COMMAND_NOT_IMPLEMENTED
Command not implemented.
@ FILE_OK
File status okay; about to open data connection.
@ ENTERING_PASSIVE
Entering Passive Mode.
@ REQ_ACTION_ABORTED
Requested action aborted: local error in processing.
@ SEC_IS_ACCEPTABLE
Security data is acceptable, more is required.
@ INTEGRITY_PROTECTED
Integrity protected reply.
@ SEC_DATA_EXCHANGE_COMPLETE_SUCCESS
Security data exchange completed successfully.
@ SYSTEM_STATUS
System status, or system help reply.
@ USER_LOG_IN_PROCEED
User logged in, proceed.
@ ENTERING_EXTENDED_PASSIVE
Entering Extended Passive Mode.
@ DATA_OPEN_NO_TRANSFER
Data connection open; no transfer in progress.
@ FILENAME_NOT_ALLOWED
Requested action not taken: File name not allowed.
@ FILE_PENDING_ACTION
Requested file action pending further information.
@ SERVICE_READY_IN_MIN
Service ready in nnn minutes.
@ REQ_SEC_MECHANISM_OK
Requested security mechanism is ok.
@ CONNECTION_CLOSED
Connection closed; transfer aborted.
@ FILE_UNAVAILABLE
Requested action not taken: File unavailable.
@ USER_OK_NEED_PASSWORD
User name okay, need password.
@ SYNTAX_ERROR_COMMAND_UNRECOGNIZED
Syntax error, command unrecognized.
@ COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER
Command not implemented for that parameter.
@ NEED_ACCOUNT
Need account for login.
@ SYNTAX_ERROR_PARAMETER_OR_ARGUMENT
Syntax error in parameters or arguments.
@ REQUEST_DENIED
Request denied for policy reasons.
@ BAD_SEQUENCE_COMMANDS
Bad sequence of commands.
@ SEC_DATA_EXCHANGE_COMPLETE
Security data exchange complete.
@ CONFIDENTIALITY_PROTECTED
Confidentiality protected reply.
@ REQ_FILE_ACTION_NOT_TAKEN
Requested file action not taken.
@ NETWORK_PROTOCOL_NOT_SUPPORTED
Network protocol not supported.
@ COMMAND_NOT_IMPLEMENTED_SUPERFLUOUS
Command not implemented, superfluous at this site.
@ DATA_ALREADY_OPEN_START_TRANSFER
Data connection already open; transfer starting.
@ CLOSING_DATA
Closing data connection.
@ FAILED_SEC_CHECK
Failed security check (hash, sequence, etc)
@ SERVICE_READY_FOR_USER
Service ready for new user.
@ REQ_FILE_OK_COMPLETE
Requested file action okay, completed.
@ RESTART_MARKER
Restart marker reply.
@ NEED_ACCOUNT_FOR_STORE_FILE
Need account for storing files.
@ CONFIDENTIALITY_AND_INTEGRITY_PROTECTED
Confidentiality and integrity protected reply.
@ PAGE_TYPE_UNKNOWN
Requested action aborted: page type unknown.
@ CANT_OPEN_DATA_CONNECTION
Can't open data connection.
@ REQ_PROT_LEVEL_NOT_SUPPORTED
Requested PROT level not supported by mechanism.
@ COMMAND_PROTECTION_LEVEL_NOT_SUPPORTED
Command protection level not supported by security mechanism.
@ REQ_ACTION_NOT_TAKEN
Requested action not taken. Insufficient storage space in system.
Definition: Layer.h:60
Definition: Packet.h:22
Definition: PayloadLayer.h:14
Class for single command text based protocol (FTP, SMTP) messages.
Definition: SingleCommandTextProtocol.h:14
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:239
const ProtocolType FTP
File Transfer (FTP) Protocol.
Definition: ProtocolType.h:167