BidirectionalChannels.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* ChannelControls */
  42. /**
  43. * Starts sending a file.
  44. *
  45. * Starts sending a file if no transmission is running and the file exists.
  46. *
  47. * @param fileName name of the file in the file directory
  48. * @return true - file will be sent | false - file was not accepted
  49. */
  50. virtual bool sendFile(const std::string &fileName) { return protocol.sendFile(fileName); }
  51. /**
  52. * Get the progress
  53. *
  54. * @return progress counters
  55. */
  56. virtual std::pair<uint32_t, uint32_t> getProgress() { return protocol.getProgress(); }
  57. /**
  58. * Test if a transfer is running
  59. *
  60. * @return true - a transfer runs | false - no transfer runs
  61. */
  62. virtual bool isTransferRunning() { return protocol.isTransferRunning(); }
  63. /**
  64. * Resets state and sets reset flag so a reset signal is sent in the next packet
  65. */
  66. virtual void reset() { protocol.reset(); }
  67. /**
  68. * Test if a transfer is running
  69. *
  70. * @return true - a transfer runs | false - no transfer runs
  71. */
  72. virtual std::time_t getTransferStart() { return protocol.getTransferStart(); }
  73. /**
  74. * Get file name of the file which is currently be sent or received.
  75. *
  76. * @return file name
  77. */
  78. virtual std::string getFileName() { return protocol.getFileName(); };
  79. /* =============== */
  80. protected:
  81. /**
  82. * protocol used to transmit data
  83. */
  84. CovertProtocolBidirectional<N, PASSIVE> protocol;
  85. };
  86. #endif