TCPOptionTimestampChannel.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef TCPOPTIONTIMESTAMPCHANNEL_H
  2. #define TCPOPTIONTIMESTAMPCHANNEL_H
  3. #include "../BidirectionalChannels.hpp"
  4. #include <utility>
  5. /**
  6. * @class TCPOptionTimestampChannel
  7. *
  8. * A CovertChannel which hides data in the TCP timestamp option field.
  9. *
  10. * @warning Only use on connections which will never use the timestamp option on their own!!!
  11. *
  12. * @param PASSIVE true - server only reacts to incoming channel | false - server initiates channel
  13. */
  14. template <bool PASSIVE> class TCPOptionTimestampChannel : public BidirectionalChannels<8, PASSIVE> {
  15. public:
  16. /**
  17. * Sets up a CovertChannel.
  18. *
  19. * Creates a CovertChannel, sets the network interfaces for sniffing and sending and sets the filter.
  20. *
  21. * @param innerInterface name of the interface of the inner network
  22. * @param outerInterface name of the interface of the outer network
  23. * @param targetIP IP of the target server
  24. * @param targetPort Port of the target server
  25. */
  26. TCPOptionTimestampChannel(const std::string &innerInterface, const std::string &outerInterface, const std::string &targetIP, const std::string &targetPort)
  27. : BidirectionalChannels<8, PASSIVE>(innerInterface, outerInterface, targetIP, targetPort) {}
  28. /**
  29. * Destroys the CovertChannel.
  30. */
  31. virtual ~TCPOptionTimestampChannel() {}
  32. protected:
  33. /**
  34. * Handler for sniffed packets filterd to forward from the outer network.
  35. *
  36. * Handles incoming packets and forwards them.
  37. *
  38. * @param pdu sniffed packet
  39. *
  40. * @return false = stop loop | true = continue loop
  41. */
  42. virtual bool handleChannelFromOuter(Tins::PDU &pdu) {
  43. Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
  44. std::pair<uint32_t, uint32_t> timestamp = tcp.timestamp();
  45. uint64_t data = ((uint64_t)timestamp.first) << 32 | timestamp.second;
  46. BidirectionalChannels<8, PASSIVE>::protocol.receive((uint8_t *)(&data));
  47. tcp.remove_option(Tins::TCP::OptionTypes::TSOPT);
  48. BidirectionalChannels<8, PASSIVE>::innerSender.send(pdu);
  49. return true;
  50. }
  51. /**
  52. * Handler for sniffed packets filterd to forward from the inner network.
  53. *
  54. * Handles incoming packets and forwards them.
  55. *
  56. * @param pdu sniffed packet
  57. *
  58. * @return false = stop loop | true = continue loop
  59. */
  60. virtual bool handleChannelFromInner(Tins::PDU &pdu) {
  61. Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
  62. uint64_t data = 0;
  63. BidirectionalChannels<8, PASSIVE>::protocol.send((uint8_t *)(&data));
  64. tcp.timestamp(data >> 32, data);
  65. BidirectionalChannels<8, PASSIVE>::outerSender.send(pdu);
  66. return true;
  67. }
  68. };
  69. #endif