PcapPlusPlus  23.09
FtpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_FTP_LAYER
2 #define PACKETPP_FTP_LAYER
3 
5 #include "PayloadLayer.h"
6 
8 
13 namespace pcpp
14 {
15 
20  {
21  protected:
22  FtpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : SingleCommandTextProtocol(data, dataLen, prevLayer, packet) { m_Protocol = FTP; };
23  FtpLayer(const std::string &command, const std::string &option) : SingleCommandTextProtocol(command, option) { m_Protocol = FTP; };
24 
25  public:
26 
31  static bool isFtpPort(uint16_t port) { return port == 21; }
32 
37  static bool isFtpDataPort(uint16_t port) { return port == 20; }
38 
39  // overridden methods
40 
42  void parseNextLayer() {}
43 
47  size_t getHeaderLen() const { return m_DataLen; }
48 
51 
56 
57  };
58 
62  class FtpRequestLayer : public FtpLayer
63  {
64  public:
65 
69  enum class FtpCommand : int
70  {
72  UNK,
74  ABOR = ('A') | ('B' << 8) | ('O' << 16) | ('R' << 24),
76  ACCT = ('A') | ('C' << 8) | ('C' << 16) | ('T' << 24),
78  ADAT = ('A') | ('D' << 8) | ('A' << 16) | ('T' << 24),
80  ALLO = ('A') | ('L' << 8) | ('L' << 16) | ('O' << 24),
82  APPE = ('A') | ('P' << 8) | ('P' << 16) | ('E' << 24),
84  AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
86  AVBL = ('A') | ('V' << 8) | ('B' << 16) | ('L' << 24),
88  CCC = ('C') | ('C' << 8) | ('C' << 16),
90  CDUP = ('C') | ('D' << 8) | ('U' << 16) | ('P' << 24),
92  CONF = ('C') | ('O' << 8) | ('N' << 16) | ('F' << 24),
94  CSID = ('C') | ('S' << 8) | ('I' << 16) | ('D' << 24),
96  CWD = ('C') | ('W' << 8) | ('D' << 16),
98  DELE = ('D') | ('E' << 8) | ('L' << 16) | ('E' << 24),
100  DSIZ = ('D') | ('S' << 8) | ('I' << 16) | ('Z' << 24),
102  ENC = ('E') | ('N' << 8) | ('C' << 16),
104  EPRT = ('E') | ('P' << 8) | ('R' << 16) | ('T' << 24),
106  EPSV = ('E') | ('P' << 8) | ('S' << 16) | ('V' << 24),
108  FEAT = ('F') | ('E' << 8) | ('A' << 16) | ('T' << 24),
110  HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
112  HOST = ('H') | ('O' << 8) | ('S' << 16) | ('T' << 24),
114  LANG = ('L') | ('A' << 8) | ('N' << 16) | ('G' << 24),
116  LIST = ('L') | ('I' << 8) | ('S' << 16) | ('T' << 24),
118  LPRT = ('L') | ('P' << 8) | ('R' << 16) | ('T' << 24),
120  LPSV = ('L') | ('P' << 8) | ('S' << 16) | ('V' << 24),
122  MDTM = ('M') | ('D' << 8) | ('T' << 16) | ('M' << 24),
124  MFCT = ('M') | ('F' << 8) | ('C' << 16) | ('T' << 24),
126  MFF = ('M') | ('F' << 8) | ('F' << 16),
128  MFMT = ('M') | ('F' << 8) | ('M' << 16) | ('T' << 24),
130  MIC = ('M') | ('I' << 8) | ('C' << 16),
132  MKD = ('M') | ('K' << 8) | ('D' << 16),
134  MLSD = ('M') | ('L' << 8) | ('S' << 16) | ('D' << 24),
136  MLST = ('M') | ('L' << 8) | ('S' << 16) | ('T' << 24),
138  MODE = ('M') | ('O' << 8) | ('D' << 16) | ('E' << 24),
140  NLST = ('N') | ('L' << 8) | ('S' << 16) | ('T' << 24),
142  NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
144  OPTS = ('O') | ('P' << 8) | ('T' << 16) | ('S' << 24),
146  PASS = ('P') | ('A' << 8) | ('S' << 16) | ('S' << 24),
148  PASV = ('P') | ('A' << 8) | ('S' << 16) | ('V' << 24),
150  PBSZ = ('P') | ('B' << 8) | ('S' << 16) | ('Z' << 24),
152  PORT = ('P') | ('O' << 8) | ('R' << 16) | ('T' << 24),
154  PROT = ('P') | ('R' << 8) | ('O' << 16) | ('T' << 24),
156  PWD = ('P') | ('W' << 8) | ('D' << 16),
158  QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
160  REIN = ('R') | ('E' << 8) | ('I' << 16) | ('N' << 24),
162  REST = ('R') | ('E' << 8) | ('S' << 16) | ('T' << 24),
164  RETR = ('R') | ('E' << 8) | ('T' << 16) | ('R' << 24),
166  RMD = ('R') | ('M' << 8) | ('D' << 16),
168  RMDA = ('R') | ('M' << 8) | ('D' << 16) | ('A' << 24),
170  RNFR = ('R') | ('N' << 8) | ('F' << 16) | ('R' << 24),
172  RNTO = ('R') | ('N' << 8) | ('T' << 16) | ('O' << 24),
174  SITE = ('S') | ('I' << 8) | ('T' << 16) | ('E' << 24),
176  SIZE = ('S') | ('I' << 8) | ('Z' << 16) | ('E' << 24),
178  SMNT = ('S') | ('M' << 8) | ('N' << 16) | ('T' << 24),
180  SPSV = ('S') | ('P' << 8) | ('S' << 16) | ('V' << 24),
182  STAT = ('S') | ('T' << 8) | ('A' << 16) | ('T' << 24),
184  STOR = ('S') | ('T' << 8) | ('O' << 16) | ('R' << 24),
186  STOU = ('S') | ('T' << 8) | ('O' << 16) | ('U' << 24),
188  STRU = ('S') | ('T' << 8) | ('R' << 16) | ('U' << 24),
190  SYST = ('S') | ('Y' << 8) | ('S' << 16) | ('T' << 24),
192  THMB = ('T') | ('H' << 8) | ('M' << 16) | ('B' << 24),
194  TYPE = ('T') | ('Y' << 8) | ('P' << 16) | ('E' << 24),
196  USER = ('U') | ('S' << 8) | ('E' << 16) | ('R' << 24),
198  XCUP = ('X') | ('C' << 8) | ('U' << 16) | ('P' << 24),
200  XMKD = ('X') | ('M' << 8) | ('K' << 16) | ('D' << 24),
202  XPWD = ('X') | ('P' << 8) | ('W' << 16) | ('D' << 24),
204  XRCP = ('X') | ('R' << 8) | ('C' << 16) | ('P' << 24),
206  XRMD = ('X') | ('R' << 8) | ('M' << 16) | ('D' << 24),
208  XRSQ = ('X') | ('R' << 8) | ('S' << 16) | ('Q' << 24),
210  XSEM = ('X') | ('S' << 8) | ('E' << 16) | ('M' << 24),
212  XSEN = ('X') | ('S' << 8) | ('E' << 16) | ('N' << 24)
213  };
214 
221  FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};
222 
228  explicit FtpRequestLayer(const FtpCommand &command, const std::string &option = "") : FtpLayer(getCommandAsString(command), option) {};
229 
235  bool setCommand(FtpCommand code);
236 
241  FtpCommand getCommand() const;
242 
247  std::string getCommandString() const;
248 
254  bool setCommandOption(const std::string &value);
255 
261  std::string getCommandOption(bool removeEscapeCharacters = true) const;
262 
268  static std::string getCommandInfo(FtpCommand code);
269 
275  static std::string getCommandAsString(FtpCommand code);
276 
277  // overridden methods
278 
282  std::string toString() const;
283  };
284 
288  class FtpResponseLayer : public FtpLayer
289  {
290  public:
291 
295  enum class FtpStatusCode : int
296  {
298  UNKNOWN,
300  RESTART_MARKER = 110,
302  SERVICE_READY_IN_MIN = 120,
304  DATA_ALREADY_OPEN_START_TRANSFER = 125,
306  FILE_OK = 150,
308  COMMAND_OK = 200,
310  COMMAND_NOT_IMPLEMENTED_SUPERFLUOUS = 202,
312  SYSTEM_STATUS = 211,
314  DIR_STATUS = 212,
316  FILE_STATUS = 213,
318  HELP_MESSAGE = 214,
320  NAME_SYSTEM_TYPE = 215,
322  SERVICE_READY_FOR_USER = 220,
324  SERVICE_CLOSING_CONTROL = 221,
326  DATA_OPEN_NO_TRANSFER = 225,
328  CLOSING_DATA = 226,
330  ENTERING_PASSIVE = 227,
332  ENTERING_EXTENDED_PASSIVE = 229,
334  USER_LOG_IN_PROCEED = 230,
336  USER_LOG_IN_AUTHORIZED = 232,
338  SEC_DATA_EXCHANGE_COMPLETE = 234,
340  SEC_DATA_EXCHANGE_COMPLETE_SUCCESS = 235,
342  REQ_FILE_OK_COMPLETE = 250,
344  PATHNAME_CREATED = 257,
346  USER_OK_NEED_PASSWORD = 331,
348  NEED_ACCOUNT = 332,
350  REQ_SEC_MECHANISM_OK = 334,
352  SEC_IS_ACCEPTABLE = 335,
354  USER_OK_NEED_PASS_CHALLENGE = 336,
356  FILE_PENDING_ACTION = 350,
358  SERVICE_NOT_AVAILABLE = 421,
360  CANT_OPEN_DATA_CONNECTION = 425,
362  CONNECTION_CLOSED = 426,
364  NEED_UNAVAILABLE_RESOURCE_TO_SEC = 431,
366  REQ_FILE_ACTION_NOT_TAKEN = 450,
368  REQ_ACTION_ABORTED = 451,
370  REQ_ACTION_NOT_TAKEN = 452,
372  SYNTAX_ERROR_COMMAND_UNRECOGNIZED = 500,
374  SYNTAX_ERROR_PARAMETER_OR_ARGUMENT = 501,
376  COMMAND_NOT_IMPLEMENTED = 502,
378  BAD_SEQUENCE_COMMANDS = 503,
380  COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504,
382  NETWORK_PROTOCOL_NOT_SUPPORTED = 522,
384  NOT_LOGGED_IN = 530,
386  NEED_ACCOUNT_FOR_STORE_FILE = 532,
388  COMMAND_PROTECTION_DENIED = 533,
390  REQUEST_DENIED = 534,
392  FAILED_SEC_CHECK = 535,
394  REQ_PROT_LEVEL_NOT_SUPPORTED = 536,
396  COMMAND_PROTECTION_LEVEL_NOT_SUPPORTED = 537,
398  FILE_UNAVAILABLE = 550,
400  PAGE_TYPE_UNKNOWN = 551,
402  EXCEED_STORAGE_ALLOCATION = 552,
404  FILENAME_NOT_ALLOWED = 553,
406  INTEGRITY_PROTECTED = 631,
408  CONFIDENTIALITY_AND_INTEGRITY_PROTECTED = 632,
410  CONFIDENTIALITY_PROTECTED = 633
411  };
412 
419  FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};
420 
426  explicit FtpResponseLayer(const FtpStatusCode &code, const std::string &option = "") : FtpLayer(std::to_string(int(code)), option) {};
427 
433  bool setStatusCode(FtpStatusCode code);
434 
439  FtpStatusCode getStatusCode() const;
440 
445  std::string getStatusCodeString() const;
446 
452  bool setStatusOption(const std::string &value);
453 
459  std::string getStatusOption(bool removeEscapeCharacters = true) const;
460 
466  static std::string getStatusCodeAsString(FtpStatusCode code);
467 
468  // overridden methods
469 
473  std::string toString() const;
474  };
475 
479  class FtpDataLayer : public PayloadLayer
480  {
481  public:
482 
489  FtpDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : PayloadLayer(data, dataLen, prevLayer, packet) { m_Protocol = FTP; };
490 
494  std::string toString() const;
495  };
496 } // namespace pcpp
497 
498 #endif /* PACKETPP_FTP_LAYER */
FtpResponseLayer(const FtpStatusCode &code, const std::string &option="")
Definition: FtpLayer.h:426
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
size_t getHeaderLen() const
Definition: FtpLayer.h:47
static bool isFtpPort(uint16_t port)
Definition: FtpLayer.h:31
Definition: SingleCommandTextProtocol.h:19
static bool isFtpDataPort(uint16_t port)
Definition: FtpLayer.h:37
FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:221
FtpDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:489
Definition: ProtocolType.h:348
Definition: Layer.h:70
Definition: Packet.h:26
Definition: FtpLayer.h:479
STL namespace.
Definition: FtpLayer.h:19
FtpRequestLayer(const FtpCommand &command, const std::string &option="")
Definition: FtpLayer.h:228
FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: FtpLayer.h:419
FtpStatusCode
Definition: FtpLayer.h:295
void parseNextLayer()
FTP is the always last so does nothing for this layer.
Definition: FtpLayer.h:42
Definition: FtpLayer.h:288
Definition: PayloadLayer.h:19
FtpCommand
Definition: FtpLayer.h:69
virtual std::string toString() const =0
const ProtocolType FTP
Definition: ProtocolType.h:268
void computeCalculateFields()
Does nothing for this layer.
Definition: FtpLayer.h:50
OsiModelLayer getOsiModelLayer() const
Definition: FtpLayer.h:55
Definition: FtpLayer.h:62