123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #ifndef TCPAPPENDCHANNEL_H
- #define TCPAPPENDCHANNEL_H
- #include "CovertChannel.h"
- #include "CovertProtocolBidirectional.hpp"
- template <int N, bool PASSIVE> class TCPAppendChannel : public CovertChannel {
- public:
-
- TCPAppendChannel(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) {}
-
- virtual ~TCPAppendChannel() {}
-
- virtual bool sendFile(const std::string &fileName) {
- if constexpr (PASSIVE) {
- return false;
- } else {
- return protocol.sendFile(fileName);
- }
- }
- protected:
-
- virtual bool handleChannelFromOuter(Tins::PDU &pdu) {
- Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
-
- Tins::RawPDU *raw = tcp.find_pdu<Tins::RawPDU>();
- if (raw != nullptr) {
- Tins::RawPDU::payload_type &payload = raw->payload();
-
- std::size_t size = payload.size();
- uint8_t *data = &payload.front();
- data += size - N;
- protocol.receive(data);
-
- payload.resize(size - N);
- }
- innerSender.send(pdu);
- return true;
- }
-
- virtual bool handleChannelFromInner(Tins::PDU &pdu) {
- Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
-
- Tins::RawPDU *raw = tcp.find_pdu<Tins::RawPDU>();
- if (raw != nullptr) {
- Tins::RawPDU::payload_type &payload = raw->payload();
-
- std::size_t size = payload.size();
- payload.resize(size + N);
-
- uint8_t *data = &payload.front();
- data += size;
- protocol.send(data);
- }
- outerSender.send(pdu);
- return true;
- }
-
- CovertProtocolBidirectional<N, PASSIVE> protocol;
- };
- #endif
|