Browse Source

Changable config + chinnel initialization in own method

Jonas Pflanzer 4 years ago
parent
commit
111f047f62
1 changed files with 42 additions and 47 deletions
  1. 42 47
      daemon/src/main.cpp

+ 42 - 47
daemon/src/main.cpp

@@ -13,87 +13,82 @@
 
 using namespace std;
 
-int main(int argc, char *argv[]) {
-	// load config int namespace
-	if (!Config::init("config.txt")) {
-		cerr << "configuration could not be loaded properly" << endl;
-		exit(EXIT_FAILURE);
-	}
-
+/**
+ * Creates the covert channel
+ *
+ * @return covert channel pointer | nullptr if no channel
+ */
+CovertChannel * createChannel() {
 	CovertChannel *covertchannel = nullptr;
-	const std::string covertChannelMode = Config::getValue("covertChannelMode");
-	if (covertChannelMode == "tcpurgency") {
-		const string innerInterface = Config::getValue("innerInterface");
-		const string outerInterface = Config::getValue("outerInterface");
 
-		const string targetIP = Config::getValue("targetIP");
-		const string targetPort = Config::getValue("targetPort");
-		const string passiveMode = Config::getValue("passiveMode");
+	const std::string covertChannelMode = Config::getValue("covertChannelMode");
+	const string innerInterface = Config::getValue("innerInterface");
+	const string outerInterface = Config::getValue("outerInterface");
+	const string targetIP = Config::getValue("targetIP");
+	const string targetPort = Config::getValue("targetPort");
+	const string passiveMode = Config::getValue("passiveMode");
 
+	if (covertChannelMode == "tcpurgency") {
 		if (passiveMode == "true") {
 			covertchannel = new TCPUrgencyChannel<true>(innerInterface, outerInterface, targetIP, targetPort);
 		} else {
 			covertchannel = new TCPUrgencyChannel<false>(innerInterface, outerInterface, targetIP, targetPort);
 		}
-
-		// covertchannel = new ForwardChannel(innerInterface, outerInterface);
 		covertchannel->startSniffing();
-	} else if (covertChannelMode == "tcpappend") {
-		const string innerInterface = Config::getValue("innerInterface");
-		const string outerInterface = Config::getValue("outerInterface");
-
-		const string targetIP = Config::getValue("targetIP");
-		const string targetPort = Config::getValue("targetPort");
-		const string passiveMode = Config::getValue("passiveMode");
 
+	} else if (covertChannelMode == "tcpappend") {
 		if (passiveMode == "true") {
 			covertchannel = new TCPAppendChannel<8, true>(innerInterface, outerInterface, targetIP, targetPort);
 		} else {
 			covertchannel = new TCPAppendChannel<8, false>(innerInterface, outerInterface, targetIP, targetPort);
 		}
-
-		// covertchannel = new ForwardChannel(innerInterface, outerInterface);
 		covertchannel->startSniffing();
-	} else if (covertChannelMode == "tcpoptiontimestamp") {
-		const string innerInterface = Config::getValue("innerInterface");
-		const string outerInterface = Config::getValue("outerInterface");
-
-		const string targetIP = Config::getValue("targetIP");
-		const string targetPort = Config::getValue("targetPort");
-		const string passiveMode = Config::getValue("passiveMode");
 
+	} else if (covertChannelMode == "tcpoptiontimestamp") {
 		if (passiveMode == "true") {
 			covertchannel = new TCPOptionTimestampChannel<true>(innerInterface, outerInterface, targetIP, targetPort);
 		} else {
 			covertchannel = new TCPOptionTimestampChannel<false>(innerInterface, outerInterface, targetIP, targetPort);
 		}
-
-		// covertchannel = new ForwardChannel(innerInterface, outerInterface);
 		covertchannel->startSniffing();
-	} else if (covertChannelMode == "tcpoptioncustom") {
-		const string innerInterface = Config::getValue("innerInterface");
-		const string outerInterface = Config::getValue("outerInterface");
-
-		const string targetIP = Config::getValue("targetIP");
-		const string targetPort = Config::getValue("targetPort");
-		const string passiveMode = Config::getValue("passiveMode");
 
+	} else if (covertChannelMode == "tcpoptioncustom") {
 		if (passiveMode == "true") {
 			covertchannel = new TCPOptionCustomChannel<8, true>(innerInterface, outerInterface, targetIP, targetPort);
 		} else {
 			covertchannel = new TCPOptionCustomChannel<8, false>(innerInterface, outerInterface, targetIP, targetPort);
 		}
-
-		// covertchannel = new ForwardChannel(innerInterface, outerInterface);
 		covertchannel->startSniffing();
-	} else if (covertChannelMode == "forward") {
-		const string innerInterface = Config::getValue("innerInterface");
-		const string outerInterface = Config::getValue("outerInterface");
 
+	} else if (covertChannelMode == "forward") {
 		covertchannel = new ForwardChannel(innerInterface, outerInterface);
 		covertchannel->startSniffing();
 	}
 
+	return covertchannel;
+}
+
+int main(int argc, char *argv[]) {
+
+	std::string configFile = "config.txt";
+	if(argc >= 2) {
+		if(std::string(argv[1]) == "help") {
+			std::cout << "Usage " << argv[0] << " [config-file]" << std::endl;
+			return 0;
+		}
+
+		configFile = argv[1];
+	}
+
+	// load config in namespace
+	std::cout << "Loading config file \"" << configFile << "\"." << std::endl;
+	if (!Config::init(configFile)) {
+		cerr << "configuration could not be loaded properly" << endl;
+		exit(EXIT_FAILURE);
+	}
+
+	CovertChannel *covertchannel = createChannel();
+
 	// check if userStorage is add specified location
 	// if not create one
 	UserManager::init(Config::getValue("userdatabase"));
@@ -109,7 +104,7 @@ int main(int argc, char *argv[]) {
 		cerr << e.what() << endl;
 	}
 
-	if (covertchannel == nullptr) {
+	if (covertchannel != nullptr) {
 		delete (covertchannel);
 	}