PcapPlusPlus  21.05
SSHLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SSH_LAYER
2 #define PACKETPP_SSH_LAYER
3 
4 #include "Layer.h"
5 
62 namespace pcpp
63 {
64 
72  class SSHLayer : public Layer
73  {
74  public:
86  static SSHLayer* createSSHMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
87 
95  static bool isSSHPort(uint16_t portSrc, uint16_t portDst) { return portSrc == 22 || portDst == 22; }
96 
97  // implement abstract methods
98 
103  void parseNextLayer();
104 
109 
111 
112  protected:
113  // protected c'tor, this class cannot be instanciated
114  SSHLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = SSH; }
115 
116  private:
117  // this layer supports only parsing
118  SSHLayer();
119  };
120 
121 
122 
131  {
132  public:
136  std::string getIdentificationMessage();
137 
148  static SSHIdentificationMessage* tryParse(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
149 
150  // implement abstract methods
151 
155  size_t getHeaderLen() const { return m_DataLen; }
156 
157  std::string toString() const;
158 
159  private:
160  // this layer supports only parsing
162 
163  // private c'tor, this class cannot be instanciated
164  SSHIdentificationMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : SSHLayer(data, dataLen, prevLayer, packet) {}
165 
166  };
167 
168 
190  {
191  public:
196  {
198  SSH_MSG_KEX_INIT = 20,
200  SSH_MSG_NEW_KEYS = 21,
202  SSH_MSG_KEX_DH_INIT = 30,
204  SSH_MSG_KEX_DH_REPLY = 31,
206  SSH_MSG_KEX_DH_GEX_INIT = 32,
208  SSH_MSG_KEX_DH_GEX_REPLY = 33,
210  SSH_MSG_KEX_DH_GEX_REQUEST = 34,
212  SSH_MSG_UNKNOWN = 999
213  };
214 
218  SSHHandshakeMessageType getMessageType() const;
219 
223  std::string getMessageTypeStr() const;
224 
228  uint8_t* getSSHHandshakeMessage() const;
229 
235  size_t getSSHHandshakeMessageLength() const;
236 
240  size_t getPaddingLength() const;
241 
253  static SSHHandshakeMessage* tryParse(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
254 
255  // implement abstract methods
256 
260  size_t getHeaderLen() const;
261 
262  std::string toString() const;
263 
264  protected:
265 
269  #pragma pack(push, 1)
271  {
272  uint32_t packetLength;
273  uint8_t paddingLength;
274  uint8_t messageCode;
275  };
276  #pragma pack(pop)
277 
278  // this layer supports only parsing
280 
281  // private c'tor, this class cannot be instanciated
282  SSHHandshakeMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : SSHLayer(data, dataLen, prevLayer, packet) {}
283 
284  ssh_message_base* getMsgBaseHeader() const { return (ssh_message_base*)m_Data; }
285  };
286 
287 
295  {
296  public:
305  SSHKeyExchangeInitMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
306 
313  uint8_t* getCookie();
314 
321  std::string getCookieAsHexStream();
322 
327  std::string getKeyExchangeAlgorithms() { return getFieldValue(0); }
328 
333  std::string getServerHostKeyAlgorithms() { return getFieldValue(1); }
334 
339  std::string getEncryptionAlgorithmsClientToServer() { return getFieldValue(2); }
340 
345  std::string getEncryptionAlgorithmsServerToClient() { return getFieldValue(3); }
346 
351  std::string getMacAlgorithmsClientToServer() { return getFieldValue(4); }
352 
357  std::string getMacAlgorithmsServerToClient() { return getFieldValue(5); }
358 
363  std::string getCompressionAlgorithmsClientToServer() { return getFieldValue(6); }
364 
369  std::string getCompressionAlgorithmsServerToClient() { return getFieldValue(7); }
370 
375  std::string getLanguagesClientToServer() { return getFieldValue(8); }
376 
381  std::string getLanguagesServerToClient() { return getFieldValue(9); }
382 
388  bool isFirstKexPacketFollows();
389 
390  private:
391  size_t m_FieldOffsets[11];
392  bool m_OffsetsInitialized;
393 
394  void parseMessageAndInitOffsets();
395 
396  std::string getFieldValue(int fieldOffsetIndex);
397  };
398 
399 
409  {
410  public:
411 
416  SSHEncryptedMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : SSHLayer(data, dataLen, prevLayer, packet) {}
417 
418  // implement abstract methods
419 
423  size_t getHeaderLen() const { return m_DataLen; }
424 
425  std::string toString() const;
426  };
427 
428 }
429 
430 #endif // PACKETPP_SSH_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:253
std::string getCompressionAlgorithmsServerToClient()
Definition: SSHLayer.h:369
SSHHandshakeMessageType
Definition: SSHLayer.h:195
std::string getMacAlgorithmsServerToClient()
Definition: SSHLayer.h:357
std::string getServerHostKeyAlgorithms()
Definition: SSHLayer.h:333
Definition: ProtocolType.h:268
Definition: SSHLayer.h:189
std::string getLanguagesClientToServer()
Definition: SSHLayer.h:375
Definition: Layer.h:70
Definition: Packet.h:26
std::string getMacAlgorithmsClientToServer()
Definition: SSHLayer.h:351
const ProtocolType SSH
Definition: ProtocolType.h:233
std::string getEncryptionAlgorithmsServerToClient()
Definition: SSHLayer.h:345
Definition: SSHLayer.h:294
size_t getHeaderLen() const
Definition: SSHLayer.h:423
std::string getEncryptionAlgorithmsClientToServer()
Definition: SSHLayer.h:339
size_t getHeaderLen() const
Definition: SSHLayer.h:155
static bool isSSHPort(uint16_t portSrc, uint16_t portDst)
Definition: SSHLayer.h:95
std::string getCompressionAlgorithmsClientToServer()
Definition: SSHLayer.h:363
void computeCalculateFields()
Definition: SSHLayer.h:108
SSHEncryptedMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSHLayer.h:416
std::string getKeyExchangeAlgorithms()
Definition: SSHLayer.h:327
static SSHLayer * createSSHMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
OsiModelLayer getOsiModelLayer() const
Definition: SSHLayer.h:110
virtual std::string toString() const =0
Definition: SSHLayer.h:72
std::string getLanguagesServerToClient()
Definition: SSHLayer.h:381
Definition: SSHLayer.h:130
Definition: SSHLayer.h:408
virtual size_t getHeaderLen() const =0
void parseNextLayer()