CovertChannel.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. */
  26. CovertChannel(const std::string &innerInterface, const std::string &outerInterface, const std::string &innerForwardFilter = "",
  27. const std::string &outerForwardFilter = "", const std::string &innerChannelFilter = "", const std::string &outerChannelFilter = "");
  28. /**
  29. * Destroys the CovertChannel.
  30. */
  31. virtual ~CovertChannel();
  32. /**
  33. * Send a file over the covert channel.
  34. *
  35. * @param fileName name of the file in the file directory
  36. * @return true - file will be sent | false - file was not accepted
  37. */
  38. virtual bool sendFile(const std::string &fileName);
  39. /**
  40. * Start sniffing on the interface.
  41. *
  42. * Starts a sniffing loop which calls handle. The loop will only be stopped if
  43. * handle returns false.
  44. */
  45. void startSniffing();
  46. /**
  47. * Sets a filter for the sniffers.
  48. *
  49. * Sets the filter for the forward and channel sniffers with a pcap filter string. E.g. "host 8.8.8.8".
  50. * The forward filter is the negated filter.
  51. *
  52. * @param filter pcap filter string which will be set for the channel sniffers and negated for the forward sniffers
  53. */
  54. void setFilter(const std::string &innerForwardFilter = "", const std::string &outerForwardFilter = "", const std::string &innerChannelFilter = "",
  55. const std::string &outerChannelFilter = "");
  56. protected:
  57. /**
  58. * Handler for sniffed packets filterd to forward from the outer network.
  59. *
  60. * Handles incoming packets and forwards them.
  61. *
  62. * @param pdu sniffed packet
  63. *
  64. * @return false = stop loop | true = continue loop
  65. */
  66. bool handleForwardFromOuter(Tins::PDU &pdu);
  67. /**
  68. * Handler for sniffed packets filterd to forward from the inner network.
  69. *
  70. * Handles incoming packets and forwards them.
  71. *
  72. * @param pdu sniffed packet
  73. *
  74. * @return false = stop loop | true = continue loop
  75. */
  76. bool handleForwardFromInner(Tins::PDU &pdu);
  77. /**
  78. * Handler for sniffed packets filterd to use as channel from the outer network.
  79. *
  80. * Handles incoming packets and redirets them.
  81. *
  82. * @param pdu sniffed packet
  83. *
  84. * @return false = stop loop | true = continue loop
  85. */
  86. virtual bool handleChannelFromOuter(Tins::PDU &pdu) = 0;
  87. /**
  88. * Handler for sniffed packets filterd to use as channel from the outer network.
  89. *
  90. * Handles incoming packets and redirets them.
  91. *
  92. * @param pdu sniffed packet
  93. *
  94. * @return false = stop loop | true = continue loop
  95. */
  96. virtual bool handleChannelFromInner(Tins::PDU &pdu) = 0;
  97. /**
  98. * Starts the sniffing loop of the inner forward sniffer.
  99. */
  100. void startInnerForwardSniffing();
  101. /**
  102. * Starts the sniffing loop of the outer forward sniffer.
  103. */
  104. void startOuterForwardSniffing();
  105. /**
  106. * Starts the sniffing loop of the inner channel sniffer.
  107. */
  108. void startInnerChannelSniffing();
  109. /**
  110. * Starts the sniffing loop of the outer channel sniffer.
  111. */
  112. void startOuterChannelSniffing();
  113. /**
  114. * Tins Sniffer to filter packets to which should be forwarded
  115. */
  116. Tins::Sniffer *innerForwardSniffer;
  117. /**
  118. * Tins Sniffer to filter packets to which should be forwarded
  119. */
  120. Tins::Sniffer *outerForwardSniffer;
  121. /**
  122. * Tins Sniffer to filter packets to which should be used for the covert channel
  123. */
  124. Tins::Sniffer *innerChannelSniffer;
  125. /**
  126. * Tins Sniffer to filter packets to which should be used for the covert channel
  127. */
  128. Tins::Sniffer *outerChannelSniffer;
  129. /**
  130. * Tins PacketSender which sends packets to the inner network
  131. */
  132. Tins::PacketSender innerSender;
  133. /**
  134. * Tins PacketSender which sends packets to the outer network
  135. */
  136. Tins::PacketSender outerSender;
  137. };
  138. #endif