CovertChannel.h 3.7 KB

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