BidirectionalChannels.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BIDIRECTIONALCHANNELS_H
  2. #define BIDIRECTIONALCHANNELS_H
  3. #include "CovertChannel.h"
  4. #include "Protocols/CovertProtocolBidirectional.hpp"
  5. /**
  6. * @class BidirectionalChannels
  7. *
  8. * Abstract class which implements the methods and constructors which are equal in all bidirectional channels.
  9. *
  10. * @param N number of bytes which can be used to transmit data
  11. * @param PASSIVE true - server only reacts to incoming channel | false - server initiates channel
  12. */
  13. template <int N, bool PASSIVE> class BidirectionalChannels : public 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 ownIP IP of this server
  23. * @param targetIP IP of the target server
  24. * @param targetPort Port of the target server
  25. */
  26. BidirectionalChannels(const std::string &innerInterface, const std::string &outerInterface, const std::string &ownIP, const std::string &targetIP,
  27. const std::string &targetPort)
  28. : CovertChannel(innerInterface, outerInterface,
  29. "(not (tcp and " + std::string(PASSIVE ? "src" : "dst") + " host " + targetIP + " and " + std::string(PASSIVE ? "src" : "dst") +
  30. " port " + targetPort + ")) and (not (dst host " + ownIP + "))",
  31. "(not (tcp and " + std::string(PASSIVE ? "dst" : "src") + " host " + targetIP + " and " + std::string(PASSIVE ? "dst" : "src") +
  32. " port " + targetPort + ")) and (not (dst host " + ownIP + "))",
  33. "tcp and " + std::string(PASSIVE ? "src" : "dst") + " host " + targetIP + " and " + std::string(PASSIVE ? "src" : "dst") + " port " +
  34. targetPort,
  35. "tcp and " + std::string(PASSIVE ? "dst" : "src") + " host " + targetIP + " and " + std::string(PASSIVE ? "dst" : "src") + " port " +
  36. targetPort) {}
  37. /**
  38. * Destroys the CovertChannel.
  39. */
  40. virtual ~BidirectionalChannels() {}
  41. /**
  42. * Send a file over the covert channel.
  43. *
  44. * @param fileName name of the file in the file directory
  45. * @return true - file will be sent | false - file was not accepted
  46. */
  47. virtual bool sendFile(const std::string &fileName) {
  48. if constexpr (PASSIVE) {
  49. return false;
  50. } else {
  51. transferStart = std::time(nullptr);
  52. return protocol.sendFile(fileName);
  53. }
  54. }
  55. /**
  56. * Get the progress
  57. *
  58. * @return progress counters
  59. */
  60. virtual std::pair<uint32_t, uint32_t> getProgress() {
  61. if (isTransferRunning()) {
  62. return protocol.getProgress();
  63. } else {
  64. return std::pair<uint32_t, uint32_t>(0, 0);
  65. }
  66. }
  67. /**
  68. * Test if a transfer is running
  69. *
  70. * @return true - a transfer runs | false - no transfer runs
  71. */
  72. virtual bool isTransferRunning() { return protocol.isTransferRunning(); }
  73. protected:
  74. /**
  75. * protocol used to transmit data
  76. */
  77. CovertProtocolBidirectional<N, PASSIVE> protocol;
  78. };
  79. #endif