CovertChannel.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef COVERTCHANNEL_H
  2. #define COVERTCHANNEL_H
  3. #include <tins/tins.h>
  4. /**
  5. * @class CovertChannel
  6. *
  7. * Sniffs the network, redirects traffic and handles filtered traffic.
  8. *
  9. * CovertChannel class which will sniff on two network interfacees. It handles filtered traffic with a virtual handler
  10. * function.
  11. */
  12. class CovertChannel {
  13. public:
  14. /**
  15. * Sets up a CovertChannel.
  16. *
  17. * Creates a CovertChannel, sets the network interfaces for sniffing and sending and sets the filter.
  18. *
  19. * @param innerInterface name of the interface of the inner network
  20. * @param outerInterface name of the interface of the outer network
  21. * @param innerForwardFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  22. * @param outerForwardFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  23. * @param innerChannelFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  24. * @param outerChannelFilter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  25. * @param outerPartnerFilter 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. const std::string &outerPartnerFilter = "");
  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 = "", const std::string &outerPartnerFilter = "");
  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. * Handler for sniffed packets filterd to use as channel from the outer network.
  94. *
  95. * Handles incoming packets and redirets them.
  96. *
  97. * @param pdu sniffed packet
  98. *
  99. * @return false = stop loop | true = continue loop
  100. */
  101. virtual bool handlePartnerFromOuter(Tins::PDU &pdu) = 0;
  102. /**
  103. * Starts the sniffing loop of the inner forward sniffer.
  104. */
  105. void startInnerForwardSniffing();
  106. /**
  107. * Starts the sniffing loop of the outer forward sniffer.
  108. */
  109. void startOuterForwardSniffing();
  110. /**
  111. * Starts the sniffing loop of the inner channel sniffer.
  112. */
  113. void startInnerChannelSniffing();
  114. /**
  115. * Starts the sniffing loop of the outer channel sniffer.
  116. */
  117. void startOuterChannelSniffing();
  118. /**
  119. * Starts the sniffing loop of the outer partner sniffer.
  120. */
  121. void startOuterPartnerSniffing();
  122. /**
  123. * Tins Sniffer to filter packets to which should be forwarded
  124. */
  125. Tins::Sniffer *innerForwardSniffer;
  126. /**
  127. * Tins Sniffer to filter packets to which should be forwarded
  128. */
  129. Tins::Sniffer *outerForwardSniffer;
  130. /**
  131. * Tins Sniffer to filter packets to which should be used for the covert channel
  132. */
  133. Tins::Sniffer *innerChannelSniffer;
  134. /**
  135. * Tins Sniffer to filter packets to which should be used for the covert channel
  136. */
  137. Tins::Sniffer *outerChannelSniffer;
  138. /**
  139. * Tins Sniffer to filter packets to which should be used for the covert channel
  140. */
  141. Tins::Sniffer *outerPartnerSniffer;
  142. /**
  143. * Tins PacketSender which sends packets to the inner network
  144. */
  145. Tins::PacketSender innerSender;
  146. /**
  147. * Tins PacketSender which sends packets to the outer network
  148. */
  149. Tins::PacketSender outerSender;
  150. };
  151. #endif