#ifndef BIDIRECTIONALCHANNELS_H #define BIDIRECTIONALCHANNELS_H #include "CovertChannel.h" #include "Protocols/CovertProtocolBidirectional.hpp" /** * @class BidirectionalChannels * * Abstract class which implements the methods and constructors which are equal in all bidirectional channels. * * @param N number of bytes which can be used to transmit data * @param PASSIVE true - server only reacts to incoming channel | false - server initiates channel */ template class BidirectionalChannels : public CovertChannel { public: /** * Sets up a CovertChannel. * * Creates a CovertChannel, sets the network interfaces for sniffing and sending and sets the filter. * * @param innerInterface name of the interface of the inner network * @param outerInterface name of the interface of the outer network * @param ownIP IP of this server * @param targetIP IP of the target server * @param targetPort Port of the target server */ BidirectionalChannels(const std::string &innerInterface, const std::string &outerInterface, const std::string &ownIP, const std::string &targetIP, const std::string &targetPort) : CovertChannel(innerInterface, outerInterface, "(not (tcp and " + std::string(PASSIVE ? "src" : "dst") + " host " + targetIP + " and " + std::string(PASSIVE ? "src" : "dst") + " port " + targetPort + ")) and (not (dst host " + ownIP + "))", "(not (tcp and " + std::string(PASSIVE ? "dst" : "src") + " host " + targetIP + " and " + std::string(PASSIVE ? "dst" : "src") + " port " + targetPort + ")) and (not (dst host " + ownIP + "))", "tcp and " + std::string(PASSIVE ? "src" : "dst") + " host " + targetIP + " and " + std::string(PASSIVE ? "src" : "dst") + " port " + targetPort, "tcp and " + std::string(PASSIVE ? "dst" : "src") + " host " + targetIP + " and " + std::string(PASSIVE ? "dst" : "src") + " port " + targetPort) {} /** * Destroys the CovertChannel. */ virtual ~BidirectionalChannels() {} /** * Send a file over the covert channel. * * @param fileName name of the file in the file directory * @return true - file will be sent | false - file was not accepted */ virtual bool sendFile(const std::string &fileName) { if constexpr (PASSIVE) { return false; } else { transferStart = std::time(nullptr); return protocol.sendFile(fileName); } } /** * Get the progress * * @return progress counters */ virtual std::pair getProgress() { if (isTransferRunning()) { return protocol.getProgress(); } else { return std::pair(0, 0); } } /** * Test if a transfer is running * * @return true - a transfer runs | false - no transfer runs */ virtual bool isTransferRunning() { return protocol.isTransferRunning(); } protected: /** * protocol used to transmit data */ CovertProtocolBidirectional protocol; }; #endif