PcapPlusPlus  Next
SSHLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
63 namespace pcpp
64 {
65 
73  class SSHLayer : public Layer
74  {
75  public:
87  static SSHLayer* createSSHMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
88 
96  static bool isSSHPort(uint16_t portSrc, uint16_t portDst)
97  {
98  return portSrc == 22 || portDst == 22;
99  }
100 
101  // implement abstract methods
102 
107  void parseNextLayer() override;
108 
112  void computeCalculateFields() override
113  {}
114 
116  {
118  }
119 
120  protected:
121  // protected c'tor, this class cannot be instantiated
122  SSHLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
123  : Layer(data, dataLen, prevLayer, packet, SSH)
124  {}
125 
126  private:
127  // this layer supports only parsing
128  SSHLayer();
129  };
130 
140  {
141  public:
146 
157  static SSHIdentificationMessage* tryParse(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
158 
159  // implement abstract methods
160 
164  size_t getHeaderLen() const override
165  {
166  return m_DataLen;
167  }
168 
169  std::string toString() const override;
170 
171  private:
172  // this layer supports only parsing
174 
175  // private c'tor, this class cannot be instantiated
176  SSHIdentificationMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
177  : SSHLayer(data, dataLen, prevLayer, packet)
178  {}
179  };
180 
204  {
205  public:
210  {
226  SSH_MSG_UNKNOWN = 999
227  };
228 
233 
237  std::string getMessageTypeStr() const;
238 
242  uint8_t* getSSHHandshakeMessage() const;
243 
250 
254  size_t getPaddingLength() const;
255 
267  static SSHHandshakeMessage* tryParse(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
268 
269  // implement abstract methods
270 
274  size_t getHeaderLen() const override;
275 
276  std::string toString() const override;
277 
278  protected:
279 #pragma pack(push, 1)
284  {
285  uint32_t packetLength;
286  uint8_t paddingLength;
287  uint8_t messageCode;
288  };
289 #pragma pack(pop)
290 
291  // this layer supports only parsing
293 
294  // private c'tor, this class cannot be instantiated
295  SSHHandshakeMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
296  : SSHLayer(data, dataLen, prevLayer, packet)
297  {}
298 
299  ssh_message_base* getMsgBaseHeader() const
300  {
301  return reinterpret_cast<ssh_message_base*>(m_Data);
302  }
303  };
304 
312  {
313  public:
322  SSHKeyExchangeInitMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
323 
330  uint8_t* getCookie();
331 
338  std::string getCookieAsHexStream();
339 
345  {
346  return getFieldValue(0);
347  }
348 
354  {
355  return getFieldValue(1);
356  }
357 
363  {
364  return getFieldValue(2);
365  }
366 
372  {
373  return getFieldValue(3);
374  }
375 
381  {
382  return getFieldValue(4);
383  }
384 
390  {
391  return getFieldValue(5);
392  }
393 
399  {
400  return getFieldValue(6);
401  }
402 
408  {
409  return getFieldValue(7);
410  }
411 
417  {
418  return getFieldValue(8);
419  }
420 
426  {
427  return getFieldValue(9);
428  }
429 
436 
437  private:
438  size_t m_FieldOffsets[11];
439  bool m_OffsetsInitialized;
440 
441  void parseMessageAndInitOffsets();
442 
443  std::string getFieldValue(int fieldOffsetIndex);
444  };
445 
456  {
457  public:
462  SSHEncryptedMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
463  : SSHLayer(data, dataLen, prevLayer, packet)
464  {}
465 
466  // implement abstract methods
467 
471  size_t getHeaderLen() const override
472  {
473  return m_DataLen;
474  }
475 
476  std::string toString() const override;
477  };
478 
479 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: SSHLayer.h:456
size_t getHeaderLen() const override
Definition: SSHLayer.h:471
SSHEncryptedMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSHLayer.h:462
std::string toString() const override
Definition: SSHLayer.h:204
size_t getHeaderLen() const override
std::string toString() const override
size_t getPaddingLength() const
std::string getMessageTypeStr() const
SSHHandshakeMessageType
Definition: SSHLayer.h:210
@ SSH_MSG_KEX_DH_INIT
Definition: SSHLayer.h:216
@ SSH_MSG_UNKNOWN
Definition: SSHLayer.h:226
@ SSH_MSG_KEX_DH_GEX_REPLY
Definition: SSHLayer.h:222
@ SSH_MSG_KEX_DH_GEX_REQUEST
Definition: SSHLayer.h:224
@ SSH_MSG_NEW_KEYS
Definition: SSHLayer.h:214
@ SSH_MSG_KEX_INIT
Definition: SSHLayer.h:212
@ SSH_MSG_KEX_DH_REPLY
Definition: SSHLayer.h:218
@ SSH_MSG_KEX_DH_GEX_INIT
Definition: SSHLayer.h:220
uint8_t * getSSHHandshakeMessage() const
SSHHandshakeMessageType getMessageType() const
static SSHHandshakeMessage * tryParse(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
size_t getSSHHandshakeMessageLength() const
Definition: SSHLayer.h:140
size_t getHeaderLen() const override
Definition: SSHLayer.h:164
std::string getIdentificationMessage()
std::string toString() const override
static SSHIdentificationMessage * tryParse(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSHLayer.h:312
std::string getCompressionAlgorithmsClientToServer()
Definition: SSHLayer.h:398
std::string getKeyExchangeAlgorithms()
Definition: SSHLayer.h:344
std::string getEncryptionAlgorithmsClientToServer()
Definition: SSHLayer.h:362
std::string getServerHostKeyAlgorithms()
Definition: SSHLayer.h:353
std::string getLanguagesClientToServer()
Definition: SSHLayer.h:416
std::string getCompressionAlgorithmsServerToClient()
Definition: SSHLayer.h:407
std::string getMacAlgorithmsClientToServer()
Definition: SSHLayer.h:380
std::string getMacAlgorithmsServerToClient()
Definition: SSHLayer.h:389
std::string getLanguagesServerToClient()
Definition: SSHLayer.h:425
std::string getEncryptionAlgorithmsServerToClient()
Definition: SSHLayer.h:371
SSHKeyExchangeInitMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSHLayer.h:74
void computeCalculateFields() override
Definition: SSHLayer.h:112
static SSHLayer * createSSHMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
OsiModelLayer getOsiModelLayer() const override
Definition: SSHLayer.h:115
void parseNextLayer() override
static bool isSSHPort(uint16_t portSrc, uint16_t portDst)
Definition: SSHLayer.h:96
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelApplicationLayer
Definition: ProtocolType.h:378
const ProtocolType SSH
Definition: ProtocolType.h:238