|
@@ -0,0 +1,52 @@
|
|
|
+#include "../include/CovertChannel.h"
|
|
|
+#include <cstdlib>
|
|
|
+#include <iostream>
|
|
|
+#include <thread>
|
|
|
+
|
|
|
+CovertChannel::CovertChannel(const std::string &innerInterface, const std::string &outerInterface) : innerSender(innerInterface), outerSender(outerInterface) {
|
|
|
+ Tins::SnifferConfiguration config;
|
|
|
+ config.set_promisc_mode(true);
|
|
|
+ config.set_immediate_mode(true);
|
|
|
+ config.set_direction(PCAP_D_IN);
|
|
|
+ config.set_snap_len(1500);
|
|
|
+
|
|
|
+ try {
|
|
|
+ innerSniffer = new Tins::Sniffer(innerInterface, config);
|
|
|
+ outerSniffer = new Tins::Sniffer(outerInterface, config);
|
|
|
+ } catch (const Tins::pcap_error &e) {
|
|
|
+ std::cerr << "An error accured setting up the sniffer: " << e.what() << std::endl;
|
|
|
+ std::exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+CovertChannel::~CovertChannel() {
|
|
|
+ innerSniffer->stop_sniff();
|
|
|
+ outerSniffer->stop_sniff();
|
|
|
+ delete (innerSniffer);
|
|
|
+ delete (outerSniffer);
|
|
|
+}
|
|
|
+
|
|
|
+void CovertChannel::startSniffing() {
|
|
|
+ std::thread innerSnifferThread(&CovertChannel::startInnerSniffing, this);
|
|
|
+ std::thread outerSnifferThread(&CovertChannel::startOuterSniffing, this);
|
|
|
+ innerSnifferThread.detach();
|
|
|
+ outerSnifferThread.detach();
|
|
|
+}
|
|
|
+
|
|
|
+void CovertChannel::startInnerSniffing() { innerSniffer->sniff_loop(make_sniffer_handler(this, &CovertChannel::handleForwardToOuter)); }
|
|
|
+
|
|
|
+void CovertChannel::startOuterSniffing() { outerSniffer->sniff_loop(make_sniffer_handler(this, &CovertChannel::handleForwardToInner)); }
|
|
|
+
|
|
|
+void CovertChannel::setFilter(const std::string &filterString) { innerSniffer->set_filter(filterString); }
|
|
|
+
|
|
|
+bool CovertChannel::handleForwardToInner(Tins::PDU &pdu) {
|
|
|
+ innerSender.send(pdu);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool CovertChannel::handleForwardToOuter(Tins::PDU &pdu) {
|
|
|
+ outerSender.send(pdu);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|