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