CovertChannel.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef COVERTCHANNEL_H
  2. #define COVERTCHANNEL_H
  3. #include <thread>
  4. #include <tins/tins.h>
  5. #include "ChannelControls.h"
  6. /**
  7. * @class CovertChannel
  8. *
  9. * Sniffs the network, redirects traffic and handles filtered traffic.
  10. *
  11. * CovertChannel class which will sniff on two network interfacees. It handles filtered traffic with a virtual handler
  12. * function.
  13. */
  14. class CovertChannel : public ChannelControls {
  15. public:
  16. /**
  17. * Sets up a CovertChannel.
  18. *
  19. * Creates a CovertChannel, sets the network interfaces for sniffing and sending and sets the filter.
  20. *
  21. * @param innerInterface name of the interface of the inner network
  22. * @param outerInterface name of the interface of the outer network
  23. * @param innerForwardFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  24. * @param outerForwardFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  25. * @param innerChannelFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  26. * @param outerChannelFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  27. */
  28. CovertChannel(const std::string &innerInterface, const std::string &outerInterface, const std::string &innerForwardFilter = "",
  29. const std::string &outerForwardFilter = "", const std::string &innerChannelFilter = "", const std::string &outerChannelFilter = "");
  30. /**
  31. * Destroys the CovertChannel.
  32. */
  33. virtual ~CovertChannel();
  34. /**
  35. * Start sniffing on the interface.
  36. *
  37. * Starts a sniffing loop which calls handle. The loop will only be stopped if
  38. * handle returns false.
  39. */
  40. void startSniffing();
  41. /**
  42. * Sets a filter for the sniffers.
  43. *
  44. * Sets the filter for the forward and channel sniffers with a pcap filter string. E.g. "host 8.8.8.8".
  45. * The forward filter is the negated filter.
  46. *
  47. * @param filter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  48. */
  49. void setFilter(const std::string &innerForwardFilter = "", const std::string &outerForwardFilter = "", const std::string &innerChannelFilter = "",
  50. const std::string &outerChannelFilter = "");
  51. protected:
  52. /**
  53. * Handler for sniffed packets filterd to forward from the outer network.
  54. *
  55. * Handles incoming packets and forwards them.
  56. *
  57. * @param pdu sniffed packet
  58. *
  59. * @return false = stop loop | true = continue loop
  60. */
  61. bool handleForwardFromOuter(Tins::PDU &pdu);
  62. /**
  63. * Handler for sniffed packets filterd to forward from the inner network.
  64. *
  65. * Handles incoming packets and forwards them.
  66. *
  67. * @param pdu sniffed packet
  68. *
  69. * @return false = stop loop | true = continue loop
  70. */
  71. bool handleForwardFromInner(Tins::PDU &pdu);
  72. /**
  73. * Handler for sniffed packets filterd to use as channel from the outer network.
  74. *
  75. * Handles incoming packets and redirets them.
  76. *
  77. * @param pdu sniffed packet
  78. *
  79. * @return false = stop loop | true = continue loop
  80. */
  81. virtual bool handleChannelFromOuter(Tins::PDU &pdu) = 0;
  82. /**
  83. * Handler for sniffed packets filterd to use as channel from the outer network.
  84. *
  85. * Handles incoming packets and redirets them.
  86. *
  87. * @param pdu sniffed packet
  88. *
  89. * @return false = stop loop | true = continue loop
  90. */
  91. virtual bool handleChannelFromInner(Tins::PDU &pdu) = 0;
  92. /**
  93. * Starts the sniffing loop of the inner forward sniffer.
  94. */
  95. void startInnerForwardSniffing();
  96. /**
  97. * Starts the sniffing loop of the outer forward sniffer.
  98. */
  99. void startOuterForwardSniffing();
  100. /**
  101. * Starts the sniffing loop of the inner channel sniffer.
  102. */
  103. void startInnerChannelSniffing();
  104. /**
  105. * Starts the sniffing loop of the outer channel sniffer.
  106. */
  107. void startOuterChannelSniffing();
  108. /**
  109. * Tins Sniffer to filter packets to which should be forwarded
  110. */
  111. Tins::Sniffer *innerForwardSniffer;
  112. /**
  113. * Tins Sniffer to filter packets to which should be forwarded
  114. */
  115. Tins::Sniffer *outerForwardSniffer;
  116. /**
  117. * Tins Sniffer to filter packets to which should be used for the covert channel
  118. */
  119. Tins::Sniffer *innerChannelSniffer;
  120. /**
  121. * Tins Sniffer to filter packets to which should be used for the covert channel
  122. */
  123. Tins::Sniffer *outerChannelSniffer;
  124. /**
  125. * Tins PacketSender which sends packets to the inner network
  126. */
  127. Tins::PacketSender innerSender;
  128. /**
  129. * Tins PacketSender which sends packets to the outer network
  130. */
  131. Tins::PacketSender outerSender;
  132. private:
  133. /**
  134. * Thread for the inner forward sniffer
  135. */
  136. std::thread innerForwardSnifferThread;
  137. /**
  138. * Thread for the outer forward sniffer
  139. */
  140. std::thread outerForwardSnifferThread;
  141. /**
  142. * Thread for the inner channel sniffer
  143. */
  144. std::thread innerChannelSnifferThread;
  145. /**
  146. * Thread for the outer channel sniffer
  147. */
  148. std::thread outerChannelSnifferThread;
  149. };
  150. #endif