CovertChannel.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. * Send a file over the covert channel.
  36. *
  37. * @param fileName name of the file in the file directory
  38. * @return true - file will be sent | false - file was not accepted
  39. */
  40. virtual bool sendFile(const std::string &fileName);
  41. /**
  42. * Start sniffing on the interface.
  43. *
  44. * Starts a sniffing loop which calls handle. The loop will only be stopped if
  45. * handle returns false.
  46. */
  47. void startSniffing();
  48. /**
  49. * Sets a filter for the sniffers.
  50. *
  51. * Sets the filter for the forward and channel sniffers with a pcap filter string. E.g. "host 8.8.8.8".
  52. * The forward filter is the negated filter.
  53. *
  54. * @param filter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  55. */
  56. void setFilter(const std::string &innerForwardFilter = "", const std::string &outerForwardFilter = "", const std::string &innerChannelFilter = "",
  57. const std::string &outerChannelFilter = "");
  58. /**
  59. * Get the progress
  60. *
  61. * @return progress counters
  62. */
  63. virtual std::pair<uint32_t, uint32_t> getProgress() = 0;
  64. /**
  65. * Test if a transfer is running
  66. *
  67. * @return true - a transfer runs | false - no transfer runs
  68. */
  69. virtual bool isTransferRunning();
  70. protected:
  71. /**
  72. * Handler for sniffed packets filterd to forward from the outer network.
  73. *
  74. * Handles incoming packets and forwards them.
  75. *
  76. * @param pdu sniffed packet
  77. *
  78. * @return false = stop loop | true = continue loop
  79. */
  80. bool handleForwardFromOuter(Tins::PDU &pdu);
  81. /**
  82. * Handler for sniffed packets filterd to forward from the inner network.
  83. *
  84. * Handles incoming packets and forwards them.
  85. *
  86. * @param pdu sniffed packet
  87. *
  88. * @return false = stop loop | true = continue loop
  89. */
  90. bool handleForwardFromInner(Tins::PDU &pdu);
  91. /**
  92. * Handler for sniffed packets filterd to use as channel from the outer network.
  93. *
  94. * Handles incoming packets and redirets them.
  95. *
  96. * @param pdu sniffed packet
  97. *
  98. * @return false = stop loop | true = continue loop
  99. */
  100. virtual bool handleChannelFromOuter(Tins::PDU &pdu) = 0;
  101. /**
  102. * Handler for sniffed packets filterd to use as channel from the outer network.
  103. *
  104. * Handles incoming packets and redirets them.
  105. *
  106. * @param pdu sniffed packet
  107. *
  108. * @return false = stop loop | true = continue loop
  109. */
  110. virtual bool handleChannelFromInner(Tins::PDU &pdu) = 0;
  111. /**
  112. * Starts the sniffing loop of the inner forward sniffer.
  113. */
  114. void startInnerForwardSniffing();
  115. /**
  116. * Starts the sniffing loop of the outer forward sniffer.
  117. */
  118. void startOuterForwardSniffing();
  119. /**
  120. * Starts the sniffing loop of the inner channel sniffer.
  121. */
  122. void startInnerChannelSniffing();
  123. /**
  124. * Starts the sniffing loop of the outer channel sniffer.
  125. */
  126. void startOuterChannelSniffing();
  127. /**
  128. * Tins Sniffer to filter packets to which should be forwarded
  129. */
  130. Tins::Sniffer *innerForwardSniffer;
  131. /**
  132. * Tins Sniffer to filter packets to which should be forwarded
  133. */
  134. Tins::Sniffer *outerForwardSniffer;
  135. /**
  136. * Tins Sniffer to filter packets to which should be used for the covert channel
  137. */
  138. Tins::Sniffer *innerChannelSniffer;
  139. /**
  140. * Tins Sniffer to filter packets to which should be used for the covert channel
  141. */
  142. Tins::Sniffer *outerChannelSniffer;
  143. /**
  144. * Tins PacketSender which sends packets to the inner network
  145. */
  146. Tins::PacketSender innerSender;
  147. /**
  148. * Tins PacketSender which sends packets to the outer network
  149. */
  150. Tins::PacketSender outerSender;
  151. private:
  152. /**
  153. * Thread for the inner forward sniffer
  154. */
  155. std::thread innerForwardSnifferThread;
  156. /**
  157. * Thread for the outer forward sniffer
  158. */
  159. std::thread outerForwardSnifferThread;
  160. /**
  161. * Thread for the inner channel sniffer
  162. */
  163. std::thread innerChannelSnifferThread;
  164. /**
  165. * Thread for the outer channel sniffer
  166. */
  167. std::thread outerChannelSnifferThread;
  168. };
  169. #endif