TCPUrgencyChannel.hpp 2.2 KB

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