PcapPlusPlus  22.11
FtpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_FTP_LAYER
2 #define PACKETPP_FTP_LAYER
3 
5 
7 
12 namespace pcpp
13 {
14 
19  {
20  protected:
21  FtpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : SingleCommandTextProtocol(data, dataLen, prevLayer, packet) { m_Protocol = FTP; };
22  FtpLayer(std::string command, std::string option) : SingleCommandTextProtocol(command, option) { m_Protocol = FTP; };
23 
24  public:
25 
30  static bool isFtpPort(uint16_t port) { return port == 21; }
31 
32  // overridden methods
33 
35  void parseNextLayer() {}
36 
40  size_t getHeaderLen() const { return m_DataLen; }
41 
44 
49 
50  };
51 
55  class FtpRequestLayer : public FtpLayer
56  {
57  public:
58 
62  enum class FtpCommand : int
63  {
65  UNK,
67  ABOR = ('A') | ('B' << 8) | ('O' << 16) | ('R' << 24),
69  ACCT = ('A') | ('C' << 8) | ('C' << 16) | ('T' << 24),
71  ADAT = ('A') | ('D' << 8) | ('A' << 16) | ('T' << 24),
73  ALLO = ('A') | ('L' << 8) | ('L' << 16) | ('O' << 24),
75  APPE = ('A') | ('P' << 8) | ('P' << 16) | ('E' << 24),
77  AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
79  AVBL = ('A') | ('V' << 8) | ('B' << 16) | ('L' << 24),
81  CCC = ('C') | ('C' << 8) | ('C' << 16),
83  CDUP = ('C') | ('D' << 8) | ('U' << 16) | ('P' << 24),
85  CONF = ('C') | ('O' << 8) | ('N' << 16) | ('F' << 24),
87  CSID = ('C') | ('S' << 8) | ('I' << 16) | ('D' << 24),
89  CWD = ('C') | ('W' << 8) | ('D' << 16),
91  DELE = ('D') | ('E' << 8) | ('L' << 16) | ('E' << 24),
93  DSIZ = ('D') | ('S' << 8) | ('I' << 16) | ('Z' << 24),
95  ENC = ('E') | ('N' << 8) | ('C' << 16),
97  EPRT = ('E') | ('P' << 8) | ('R' << 16) | ('T' << 24),
99  EPSV = ('E') | ('P' << 8) | ('S' << 16) | ('V' << 24),
101  FEAT = ('F') | ('E' << 8) | ('A' << 16) | ('T' << 24),
103  HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
105  HOST = ('H') | ('O' << 8) | ('S' << 16) | ('T' << 24),
107  LANG = ('L') | ('A' << 8) | ('N' << 16) | ('G' << 24),
109  LIST = ('L') | ('I' << 8) | ('S' << 16) | ('T' << 24),
111  LPRT = ('L') | ('P' << 8) | ('R' << 16) | ('T' << 24),
113  LPSV = ('L') | ('P' << 8) | ('S' << 16) | ('V' << 24),
115  MDTM = ('M') | ('D' << 8) | ('T' << 16) | ('M' << 24),
117  MFCT = ('M') | ('F' << 8) | ('C' << 16) | ('T' << 24),
119  MFF = ('M') | ('F' << 8) | ('F' << 16),
121  MFMT = ('M') | ('F' << 8) | ('M' << 16) | ('T' << 24),
123  MIC = ('M') | ('I' << 8) | ('C' << 16),
125  MKD = ('M') | ('K' << 8) | ('D' << 16),
127  MLSD = ('M') | ('L' << 8) | ('S' << 16) | ('D' << 24),
129  MLST = ('M') | ('L' << 8) | ('S' << 16) | ('T' << 24),
131  MODE = ('M') | ('O' << 8) | ('D' << 16) | ('E' << 24),
133  NLST = ('N') | ('L' << 8) | ('S' << 16) | ('T' << 24),
135  NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
137  OPTS = ('O') | ('P' << 8) | ('T' << 16) | ('S' << 24),
139  PASS = ('P') | ('A' << 8) | ('S' << 16) | ('S' << 24),
141  PASV = ('P') | ('A' << 8) | ('S' << 16) | ('V' << 24),
143  PBSZ = ('P') | ('B' << 8) | ('S' << 16) | ('Z' << 24),
145  PORT = ('P') | ('O' << 8) | ('R' << 16) | ('T' << 24),
147  PROT = ('P') | ('R' << 8) | ('O' << 16) | ('T' << 24),
149  PWD = ('P') | ('W' << 8) | ('D' << 16),
151  QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
153  REIN = ('R') | ('E' << 8) | ('I' << 16) | ('N' << 24),
155  REST = ('R') | ('E' << 8) | ('S' << 16) | ('T' << 24),
157  RETR = ('R') | ('E' << 8) | ('T' << 16) | ('R' << 24),
159  RMD = ('R') | ('M' << 8) | ('D' << 16),
161  RMDA = ('R') | ('M' << 8) | ('D' << 16) | ('A' << 24),
163  RNFR = ('R') | ('N' << 8) | ('F' << 16) | ('R' << 24),
165  RNTO = ('R') | ('N' << 8) | ('T' << 16) | ('O' << 24),
167  SITE = ('S') | ('I' << 8) | ('T' << 16) | ('E' << 24),
169  SIZE = ('S') | ('I' << 8) | ('Z' << 16) | ('E' << 24),
171  SMNT = ('S') | ('M' << 8) | ('N' << 16) | ('T' << 24),
173  SPSV = ('S') | ('P' << 8) | ('S' << 16) | ('V' << 24),
175  STAT = ('S') | ('T' << 8) | ('A' << 16) | ('T' << 24),
177  STOR = ('S') | ('T' << 8) | ('O' << 16) | ('R' << 24),
179  STOU = ('S') | ('T' << 8) | ('O' << 16) | ('U' << 24),
181  STRU = ('S') | ('T' << 8) | ('R' << 16) | ('U' << 24),
183  SYST = ('S') | ('Y' << 8) | ('S' << 16) | ('T' << 24),
185  THMB = ('T') | ('H' << 8) | ('M' << 16) | ('B' << 24),
187  TYPE = ('T') | ('Y' << 8) | ('P' << 16) | ('E' << 24),
189  USER = ('U') | ('S' << 8) | ('E' << 16) | ('R' << 24),
191  XCUP = ('X') | ('C' << 8) | ('U' << 16) | ('P' << 24),
193  XMKD = ('X') | ('M' << 8) | ('K' << 16) | ('D' << 24),
195  XPWD = ('X') | ('P' << 8) | ('W' << 16) | ('D' << 24),
197  XRCP = ('X') | ('R' << 8) | ('C' << 16) | ('P' << 24),
199  XRMD = ('X') | ('R' << 8) | ('M' << 16) | ('D' << 24),
201  XRSQ = ('X') | ('R' << 8) | ('S' << 16) | ('Q' << 24),
203  XSEM = ('X') | ('S' << 8) | ('E' << 16) | ('M' << 24),
205  XSEN = ('X') | ('S' << 8) | ('E' << 16) | ('N' << 24)
206  };
207 
214  FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};
215 
221  FtpRequestLayer(const FtpCommand &command, const std::string &option = "") : FtpLayer(getCommandAsString(command), option) {};
222 
228  bool setCommand(FtpCommand code);
229 
234  FtpCommand getCommand() const;
235 
240  std::string getCommandString() const;
241 
247  bool setCommandOption(const std::string &value);
248 
254  std::string getCommandOption(bool removeEscapeCharacters = true) const;
255 
261  static std::string getCommandInfo(FtpCommand code);
262 
268  static std::string getCommandAsString(FtpCommand code);
269 
270  // overridden methods
271 
275  std::string toString() const;
276  };
277 
281  class FtpResponseLayer : public FtpLayer
282  {
283  public:
284 
288  enum class FtpStatusCode : int
289  {
291  UNKNOWN,
293  RESTART_MARKER = 110,
295  SERVICE_READY_IN_MIN = 120,
297  DATA_ALREADY_OPEN_START_TRANSFER = 125,
299  FILE_OK = 150,
301  COMMAND_OK = 200,
303  COMMAND_NOT_IMPLEMENTED_SUPERFLUOUS = 202,
305  SYSTEM_STATUS = 211,
307  DIR_STATUS = 212,
309  FILE_STATUS = 213,
311  HELP_MESSAGE = 214,
313  NAME_SYSTEM_TYPE = 215,
315  SERVICE_READY_FOR_USER = 220,
317  SERVICE_CLOSING_CONTROL = 221,
319  DATA_OPEN_NO_TRANSFER = 225,
321  CLOSING_DATA = 226,
323  ENTERING_PASSIVE = 227,
325  ENTERING_EXTENDED_PASSIVE = 229,
327  USER_LOG_IN_PROCEED = 230,
329  USER_LOG_IN_AUTHORIZED = 232,
331  SEC_DATA_EXCHANGE_COMPLETE = 234,
333  SEC_DATA_EXCHANGE_COMPLETE_SUCCESS = 235,
335  REQ_FILE_OK_COMPLETE = 250,
337  PATHNAME_CREATED = 257,
339  USER_OK_NEED_PASSWORD = 331,
341  NEED_ACCOUNT = 332,
343  REQ_SEC_MECHANISM_OK = 334,
345  SEC_IS_ACCEPTABLE = 335,
347  USER_OK_NEED_PASS_CHALLENGE = 336,
349  FILE_PENDING_ACTION = 350,
351  SERVICE_NOT_AVAILABLE = 421,
353  CANT_OPEN_DATA_CONNECTION = 425,
355  CONNECTION_CLOSED = 426,
357  NEED_UNAVAILABLE_RESOURCE_TO_SEC = 431,
359  REQ_FILE_ACTION_NOT_TAKEN = 450,
361  REQ_ACTION_ABORTED = 451,
363  REQ_ACTION_NOT_TAKEN = 452,
365  SYNTAX_ERROR_COMMAND_UNRECOGNIZED = 500,
367  SYNTAX_ERROR_PARAMETER_OR_ARGUMENT = 501,
369  COMMAND_NOT_IMPLEMENTED = 502,
371  BAD_SEQUENCE_COMMANDS = 503,
373  COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504,
375  NETWORK_PROTOCOL_NOT_SUPPORTED = 522,
377  NOT_LOGGED_IN = 530,
379  NEED_ACCOUNT_FOR_STORE_FILE = 532,
381  COMMAND_PROTECTION_DENIED = 533,
383  REQUEST_DENIED = 534,
385  FAILED_SEC_CHECK = 535,
387  REQ_PROT_LEVEL_NOT_SUPPORTED = 536,
389  COMMAND_PROTECTION_LEVEL_NOT_SUPPORTED = 537,
391  FILE_UNAVAILABLE = 550,
393  PAGE_TYPE_UNKNOWN = 551,
395  EXCEED_STORAGE_ALLOCATION = 552,
397  FILENAME_NOT_ALLOWED = 553,
399  INTEGRITY_PROTECTED = 631,
401  CONFIDENTIALITY_AND_INTEGRITY_PROTECTED = 632,
403  CONFIDENTIALITY_PROTECTED = 633
404  };
405 
412  FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};
413 
419  FtpResponseLayer(const FtpStatusCode &code, const std::string &option = "") : FtpLayer(std::to_string(int(code)), option) {};
420 
426  bool setStatusCode(FtpStatusCode code);
427 
432  FtpStatusCode getStatusCode() const;
433 
438  std::string getStatusCodeString() const;
439 
445  bool setStatusOption(const std::string &value);
446 
452  std::string getStatusOption(bool removeEscapeCharacters = true) const;
453 
459  static std::string getStatusCodeAsString(FtpStatusCode code);
460 
461  // overridden methods
462 
466  std::string toString() const;
467  };
468 } // namespace pcpp
469 
470 #endif /* PACKETPP_FTP_LAYER */
FtpResponseLayer(const FtpStatusCode &code, const std::string &option="")
Definition: FtpLayer.h:419
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:298
size_t getHeaderLen() const
Definition: FtpLayer.h:40
static bool isFtpPort(uint16_t port)
Definition: FtpLayer.h:30
Definition: SingleCommandTextProtocol.h:19
FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:214
Definition: ProtocolType.h:313
Definition: Layer.h:70
Definition: Packet.h:26
STL namespace.
Definition: FtpLayer.h:18
FtpRequestLayer(const FtpCommand &command, const std::string &option="")
Definition: FtpLayer.h:221
FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:412
FtpStatusCode
Definition: FtpLayer.h:288
void parseNextLayer()
FTP is the always last so does nothing for this layer.
Definition: FtpLayer.h:35
Definition: FtpLayer.h:281
FtpCommand
Definition: FtpLayer.h:62
virtual std::string toString() const =0
const ProtocolType FTP
Definition: ProtocolType.h:268
void computeCalculateFields()
Does nothing for this layer.
Definition: FtpLayer.h:43
OsiModelLayer getOsiModelLayer() const
Definition: FtpLayer.h:48
Definition: FtpLayer.h:55