PcapPlusPlus  24.09
FtpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "PayloadLayer.h"
5 
7 
12 namespace pcpp
13 {
14 
19  {
20  protected:
21  FtpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
22  : SingleCommandTextProtocol(data, dataLen, prevLayer, packet, FTP) {};
23  FtpLayer(const std::string& command, const std::string& option)
24  : SingleCommandTextProtocol(command, option, FTP) {};
25 
26  public:
31  static bool isFtpPort(uint16_t port)
32  {
33  return port == 21;
34  }
35 
40  static bool isFtpDataPort(uint16_t port)
41  {
42  return port == 20;
43  }
44 
45  // overridden methods
46 
49  {}
50 
54  size_t getHeaderLen() const
55  {
56  return m_DataLen;
57  }
58 
61  {}
62 
67  {
69  }
70  };
71 
75  class FtpRequestLayer : public FtpLayer
76  {
77  public:
81  enum class FtpCommand : int
82  {
84  UNK,
86  ABOR = ('A') | ('B' << 8) | ('O' << 16) | ('R' << 24),
88  ACCT = ('A') | ('C' << 8) | ('C' << 16) | ('T' << 24),
90  ADAT = ('A') | ('D' << 8) | ('A' << 16) | ('T' << 24),
92  ALLO = ('A') | ('L' << 8) | ('L' << 16) | ('O' << 24),
94  APPE = ('A') | ('P' << 8) | ('P' << 16) | ('E' << 24),
96  AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
98  AVBL = ('A') | ('V' << 8) | ('B' << 16) | ('L' << 24),
100  CCC = ('C') | ('C' << 8) | ('C' << 16),
102  CDUP = ('C') | ('D' << 8) | ('U' << 16) | ('P' << 24),
104  CONF = ('C') | ('O' << 8) | ('N' << 16) | ('F' << 24),
106  CSID = ('C') | ('S' << 8) | ('I' << 16) | ('D' << 24),
108  CWD = ('C') | ('W' << 8) | ('D' << 16),
110  DELE = ('D') | ('E' << 8) | ('L' << 16) | ('E' << 24),
112  DSIZ = ('D') | ('S' << 8) | ('I' << 16) | ('Z' << 24),
114  ENC = ('E') | ('N' << 8) | ('C' << 16),
116  EPRT = ('E') | ('P' << 8) | ('R' << 16) | ('T' << 24),
118  EPSV = ('E') | ('P' << 8) | ('S' << 16) | ('V' << 24),
120  FEAT = ('F') | ('E' << 8) | ('A' << 16) | ('T' << 24),
122  HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
124  HOST = ('H') | ('O' << 8) | ('S' << 16) | ('T' << 24),
126  LANG = ('L') | ('A' << 8) | ('N' << 16) | ('G' << 24),
129  LIST = ('L') | ('I' << 8) | ('S' << 16) | ('T' << 24),
131  LPRT = ('L') | ('P' << 8) | ('R' << 16) | ('T' << 24),
133  LPSV = ('L') | ('P' << 8) | ('S' << 16) | ('V' << 24),
135  MDTM = ('M') | ('D' << 8) | ('T' << 16) | ('M' << 24),
137  MFCT = ('M') | ('F' << 8) | ('C' << 16) | ('T' << 24),
139  MFF = ('M') | ('F' << 8) | ('F' << 16),
141  MFMT = ('M') | ('F' << 8) | ('M' << 16) | ('T' << 24),
143  MIC = ('M') | ('I' << 8) | ('C' << 16),
145  MKD = ('M') | ('K' << 8) | ('D' << 16),
147  MLSD = ('M') | ('L' << 8) | ('S' << 16) | ('D' << 24),
150  MLST = ('M') | ('L' << 8) | ('S' << 16) | ('T' << 24),
152  MODE = ('M') | ('O' << 8) | ('D' << 16) | ('E' << 24),
154  NLST = ('N') | ('L' << 8) | ('S' << 16) | ('T' << 24),
156  NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
158  OPTS = ('O') | ('P' << 8) | ('T' << 16) | ('S' << 24),
160  PASS = ('P') | ('A' << 8) | ('S' << 16) | ('S' << 24),
162  PASV = ('P') | ('A' << 8) | ('S' << 16) | ('V' << 24),
164  PBSZ = ('P') | ('B' << 8) | ('S' << 16) | ('Z' << 24),
166  PORT = ('P') | ('O' << 8) | ('R' << 16) | ('T' << 24),
168  PROT = ('P') | ('R' << 8) | ('O' << 16) | ('T' << 24),
170  PWD = ('P') | ('W' << 8) | ('D' << 16),
172  QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
174  REIN = ('R') | ('E' << 8) | ('I' << 16) | ('N' << 24),
176  REST = ('R') | ('E' << 8) | ('S' << 16) | ('T' << 24),
178  RETR = ('R') | ('E' << 8) | ('T' << 16) | ('R' << 24),
180  RMD = ('R') | ('M' << 8) | ('D' << 16),
182  RMDA = ('R') | ('M' << 8) | ('D' << 16) | ('A' << 24),
184  RNFR = ('R') | ('N' << 8) | ('F' << 16) | ('R' << 24),
186  RNTO = ('R') | ('N' << 8) | ('T' << 16) | ('O' << 24),
189  SITE = ('S') | ('I' << 8) | ('T' << 16) | ('E' << 24),
191  SIZE = ('S') | ('I' << 8) | ('Z' << 16) | ('E' << 24),
193  SMNT = ('S') | ('M' << 8) | ('N' << 16) | ('T' << 24),
196  SPSV = ('S') | ('P' << 8) | ('S' << 16) | ('V' << 24),
198  STAT = ('S') | ('T' << 8) | ('A' << 16) | ('T' << 24),
200  STOR = ('S') | ('T' << 8) | ('O' << 16) | ('R' << 24),
202  STOU = ('S') | ('T' << 8) | ('O' << 16) | ('U' << 24),
204  STRU = ('S') | ('T' << 8) | ('R' << 16) | ('U' << 24),
206  SYST = ('S') | ('Y' << 8) | ('S' << 16) | ('T' << 24),
208  THMB = ('T') | ('H' << 8) | ('M' << 16) | ('B' << 24),
210  TYPE = ('T') | ('Y' << 8) | ('P' << 16) | ('E' << 24),
212  USER = ('U') | ('S' << 8) | ('E' << 16) | ('R' << 24),
214  XCUP = ('X') | ('C' << 8) | ('U' << 16) | ('P' << 24),
216  XMKD = ('X') | ('M' << 8) | ('K' << 16) | ('D' << 24),
218  XPWD = ('X') | ('P' << 8) | ('W' << 16) | ('D' << 24),
220  XRCP = ('X') | ('R' << 8) | ('C' << 16) | ('P' << 24),
222  XRMD = ('X') | ('R' << 8) | ('M' << 16) | ('D' << 24),
224  XRSQ = ('X') | ('R' << 8) | ('S' << 16) | ('Q' << 24),
226  XSEM = ('X') | ('S' << 8) | ('E' << 16) | ('M' << 24),
228  XSEN = ('X') | ('S' << 8) | ('E' << 16) | ('N' << 24)
229  };
230 
237  FtpRequestLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
238  : FtpLayer(data, dataLen, prevLayer, packet) {};
239 
245  explicit FtpRequestLayer(const FtpCommand& command, const std::string& option = "")
246  : FtpLayer(getCommandAsString(command), option) {};
247 
253  bool setCommand(FtpCommand code);
254 
260 
265  std::string getCommandString() const;
266 
272  bool setCommandOption(const std::string& value);
273 
279  std::string getCommandOption(bool removeEscapeCharacters = true) const;
280 
286  static std::string getCommandInfo(FtpCommand code);
287 
293  static std::string getCommandAsString(FtpCommand code);
294 
295  // overridden methods
296 
300  std::string toString() const;
301  };
302 
306  class FtpResponseLayer : public FtpLayer
307  {
308  public:
312  enum class FtpStatusCode : int
313  {
315  UNKNOWN,
317  RESTART_MARKER = 110,
319  SERVICE_READY_IN_MIN = 120,
323  FILE_OK = 150,
325  COMMAND_OK = 200,
329  SYSTEM_STATUS = 211,
331  DIR_STATUS = 212,
333  FILE_STATUS = 213,
335  HELP_MESSAGE = 214,
337  NAME_SYSTEM_TYPE = 215,
343  DATA_OPEN_NO_TRANSFER = 225,
345  CLOSING_DATA = 226,
347  ENTERING_PASSIVE = 227,
351  USER_LOG_IN_PROCEED = 230,
359  REQ_FILE_OK_COMPLETE = 250,
361  PATHNAME_CREATED = 257,
363  USER_OK_NEED_PASSWORD = 331,
365  NEED_ACCOUNT = 332,
367  REQ_SEC_MECHANISM_OK = 334,
369  SEC_IS_ACCEPTABLE = 335,
373  FILE_PENDING_ACTION = 350,
375  SERVICE_NOT_AVAILABLE = 421,
379  CONNECTION_CLOSED = 426,
385  REQ_ACTION_ABORTED = 451,
387  REQ_ACTION_NOT_TAKEN = 452,
395  BAD_SEQUENCE_COMMANDS = 503,
401  NOT_LOGGED_IN = 530,
407  REQUEST_DENIED = 534,
409  FAILED_SEC_CHECK = 535,
415  FILE_UNAVAILABLE = 550,
417  PAGE_TYPE_UNKNOWN = 551,
421  FILENAME_NOT_ALLOWED = 553,
423  INTEGRITY_PROTECTED = 631,
428  };
429 
436  FtpResponseLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
437  : FtpLayer(data, dataLen, prevLayer, packet) {};
438 
444  explicit FtpResponseLayer(const FtpStatusCode& code, const std::string& option = "")
445  : FtpLayer(std::to_string(int(code)), option) {};
446 
453 
459 
464  std::string getStatusCodeString() const;
465 
471  bool setStatusOption(const std::string& value);
472 
478  std::string getStatusOption(bool removeEscapeCharacters = true) const;
479 
485  static std::string getStatusCodeAsString(FtpStatusCode code);
486 
487  // overridden methods
488 
492  std::string toString() const;
493  };
494 
498  class FtpDataLayer : public PayloadLayer
499  {
500  public:
507  FtpDataLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
508  : PayloadLayer(data, dataLen, prevLayer, packet)
509  {
510  m_Protocol = FTP;
511  };
512 
516  std::string toString() const;
517  };
518 } // namespace pcpp
Definition: FtpLayer.h:499
FtpDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:507
std::string toString() const
Definition: FtpLayer.h:19
static bool isFtpDataPort(uint16_t port)
Definition: FtpLayer.h:40
void parseNextLayer()
FTP is the always last so does nothing for this layer.
Definition: FtpLayer.h:48
OsiModelLayer getOsiModelLayer() const
Definition: FtpLayer.h:66
static bool isFtpPort(uint16_t port)
Definition: FtpLayer.h:31
void computeCalculateFields()
Does nothing for this layer.
Definition: FtpLayer.h:60
size_t getHeaderLen() const
Definition: FtpLayer.h:54
Definition: FtpLayer.h:76
bool setCommandOption(const std::string &value)
static std::string getCommandAsString(FtpCommand code)
std::string toString() const
FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:237
FtpRequestLayer(const FtpCommand &command, const std::string &option="")
Definition: FtpLayer.h:245
FtpCommand getCommand() const
std::string getCommandOption(bool removeEscapeCharacters=true) const
FtpCommand
Definition: FtpLayer.h:82
@ 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 getCommandString() const
bool setCommand(FtpCommand code)
static std::string getCommandInfo(FtpCommand code)
Definition: FtpLayer.h:307
FtpStatusCode getStatusCode() const
std::string toString() const
FtpResponseLayer(const FtpStatusCode &code, const std::string &option="")
Definition: FtpLayer.h:444
FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:436
std::string getStatusOption(bool removeEscapeCharacters=true) const
bool setStatusCode(FtpStatusCode code)
static std::string getStatusCodeAsString(FtpStatusCode code)
std::string getStatusCodeString() const
bool setStatusOption(const std::string &value)
FtpStatusCode
Definition: FtpLayer.h:313
@ 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:70
Definition: Packet.h:27
Definition: PayloadLayer.h:19
Definition: SingleCommandTextProtocol.h:19
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368
const ProtocolType FTP
Definition: ProtocolType.h:273