TCPOptionTimestampChannel.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 ownIP IP of this server
  24. * @param targetIP IP of the target server
  25. * @param targetPort Port of the target server
  26. */
  27. TCPOptionTimestampChannel(const std::string &innerInterface, const std::string &outerInterface, const std::string &ownIP, const std::string &targetIP,
  28. const std::string &targetPort)
  29. : BidirectionalChannels<8, PASSIVE>(innerInterface, outerInterface, ownIP, targetIP, targetPort) {}
  30. /**
  31. * Destroys the CovertChannel.
  32. */
  33. virtual ~TCPOptionTimestampChannel() {}
  34. protected:
  35. /**
  36. * Handler for sniffed packets filterd to forward from the outer network.
  37. *
  38. * Handles incoming packets and forwards them.
  39. *
  40. * @param pdu sniffed packet
  41. *
  42. * @return false = stop loop | true = continue loop
  43. */
  44. virtual bool handleChannelFromOuter(Tins::PDU &pdu) {
  45. Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
  46. std::pair<uint32_t, uint32_t> timestamp = tcp.timestamp();
  47. uint64_t data = ((uint64_t)timestamp.first) << 32 | timestamp.second;
  48. BidirectionalChannels<8, PASSIVE>::protocol.receive((uint8_t *)(&data));
  49. tcp.remove_option(Tins::TCP::OptionTypes::TSOPT);
  50. BidirectionalChannels<8, PASSIVE>::innerSender.send(pdu);
  51. return true;
  52. }
  53. /**
  54. * Handler for sniffed packets filterd to forward from the inner network.
  55. *
  56. * Handles incoming packets and forwards them.
  57. *
  58. * @param pdu sniffed packet
  59. *
  60. * @return false = stop loop | true = continue loop
  61. */
  62. virtual bool handleChannelFromInner(Tins::PDU &pdu) {
  63. Tins::TCP &tcp = pdu.rfind_pdu<Tins::TCP>();
  64. uint64_t data = 0;
  65. BidirectionalChannels<8, PASSIVE>::protocol.send((uint8_t *)(&data));
  66. tcp.timestamp(data >> 32, data);
  67. BidirectionalChannels<8, PASSIVE>::outerSender.send(pdu);
  68. return true;
  69. }
  70. };
  71. #endif