main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <iostream>
  2. #include "../include/Config.h"
  3. #include "../include/CovertChannel/Channels/TCPAppendChannel.hpp"
  4. #include "../include/CovertChannel/Channels/TCPOptionCustomChannel.hpp"
  5. #include "../include/CovertChannel/Channels/TCPOptionTimestampChannel.hpp"
  6. #include "../include/CovertChannel/Channels/TCPUrgencyChannel.hpp"
  7. #include "../include/CovertChannel/CovertChannel.h"
  8. #include "../include/CovertChannel/ForwardChannel.h"
  9. #include "../include/Queue.h"
  10. #include "../include/Server.h"
  11. #include "../include/UserManager.h"
  12. using namespace std;
  13. /**
  14. * Creates the covert channel
  15. *
  16. * @return covert channel pointer | nullptr if no channel
  17. */
  18. CovertChannel *createChannel() {
  19. CovertChannel *covertchannel = nullptr;
  20. const std::string covertChannelMode = Config::getValue("covertChannelMode");
  21. const string innerInterface = Config::getValue("innerInterface");
  22. const string outerInterface = Config::getValue("outerInterface");
  23. const string targetIP = Config::getValue("targetIP");
  24. const string targetPort = Config::getValue("targetPort");
  25. const string passiveMode = Config::getValue("passiveMode");
  26. if (covertChannelMode == "tcpurgency") {
  27. if (passiveMode == "true") {
  28. covertchannel = new TCPUrgencyChannel<true>(innerInterface, outerInterface, targetIP, targetPort);
  29. } else {
  30. covertchannel = new TCPUrgencyChannel<false>(innerInterface, outerInterface, targetIP, targetPort);
  31. }
  32. covertchannel->startSniffing();
  33. } else if (covertChannelMode == "tcpappend") {
  34. if (passiveMode == "true") {
  35. covertchannel = new TCPAppendChannel<8, true>(innerInterface, outerInterface, targetIP, targetPort);
  36. } else {
  37. covertchannel = new TCPAppendChannel<8, false>(innerInterface, outerInterface, targetIP, targetPort);
  38. }
  39. covertchannel->startSniffing();
  40. } else if (covertChannelMode == "tcpoptiontimestamp") {
  41. if (passiveMode == "true") {
  42. covertchannel = new TCPOptionTimestampChannel<true>(innerInterface, outerInterface, targetIP, targetPort);
  43. } else {
  44. covertchannel = new TCPOptionTimestampChannel<false>(innerInterface, outerInterface, targetIP, targetPort);
  45. }
  46. covertchannel->startSniffing();
  47. } else if (covertChannelMode == "tcpoptioncustom") {
  48. if (passiveMode == "true") {
  49. covertchannel = new TCPOptionCustomChannel<8, true>(innerInterface, outerInterface, targetIP, targetPort);
  50. } else {
  51. covertchannel = new TCPOptionCustomChannel<8, false>(innerInterface, outerInterface, targetIP, targetPort);
  52. }
  53. covertchannel->startSniffing();
  54. } else if (covertChannelMode == "forward") {
  55. covertchannel = new ForwardChannel(innerInterface, outerInterface);
  56. covertchannel->startSniffing();
  57. }
  58. return covertchannel;
  59. }
  60. int main(int argc, char *argv[]) {
  61. std::string configFile = "config.txt";
  62. if (argc >= 2) {
  63. if (std::string(argv[1]) == "help") {
  64. std::cout << "Usage " << argv[0] << " [config-file]" << std::endl;
  65. return 0;
  66. }
  67. configFile = argv[1];
  68. }
  69. // load config in namespace
  70. std::cout << "Loading config file \"" << configFile << "\"." << std::endl;
  71. if (!Config::init(configFile)) {
  72. cerr << "configuration could not be loaded properly" << endl;
  73. exit(EXIT_FAILURE);
  74. }
  75. CovertChannel *covertchannel = createChannel();
  76. // check if userStorage is add specified location
  77. // if not create one
  78. UserManager::init(Config::getValue("userdatabase"));
  79. // Init queue so the file transfers can be executed
  80. Queue::channel = covertchannel;
  81. try {
  82. io_service io_service;
  83. Server server(io_service);
  84. io_service.run();
  85. } catch (exception &e) {
  86. cerr << e.what() << endl;
  87. }
  88. if (covertchannel != nullptr) {
  89. delete (covertchannel);
  90. }
  91. return 0;
  92. }