CovertChannel.h 5.0 KB

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