basefiles.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. struct option
  2. {
  3. int proc = 0;
  4. int mode = 0;
  5. int log = 1;
  6. int high = 0;
  7. int mesh = 0;
  8. std::string str_search;
  9. std::string rgx_search;
  10. std::string outputfile;
  11. uint8_t raw_search[16];
  12. int sbt_size = 7; // 64 бита / 8 = 8 байт, нумерация с нуля => -1
  13. bool sbt_alarm = false; // для симпатичного вывода предупреждения
  14. };
  15. option conf;
  16. int config()
  17. {
  18. std::ifstream conffile ("sygcpp.conf");
  19. if(!conffile) // проверка наличия конфига
  20. {
  21. std::cout << " Configuration file not found... ";
  22. conffile.close();
  23. std::ofstream newconf ("sygcpp.conf"); // создание конфига
  24. if(!newconf)
  25. {
  26. std::cerr << "CREATION FAILED" << std::endl;
  27. return -1;
  28. }
  29. newconf << "####################################################################\n"
  30. << "# SimpleYggGen C++ configuration file. #\n"
  31. << "# If you have some errors, try delete this file and run SYG again. #\n"
  32. << "####################################################################\n\n"
  33. << " Parameter limited by processors count on PC.\n"
  34. << "* Count of thread: 16\n\n"
  35. << " 0 - IPv6 pattern, 1 - high address, 2 - search by pattern & high,\n"
  36. << " 3 - IPv6 regexp, 4 - meshname pattern, 5 - meshname regexp,\n"
  37. << " 6 - IPv6 subnet brute force mode :^)\n"
  38. << "* Mining option: 1\n\n"
  39. << " 0 - console output only, 1 - log to file.\n"
  40. << "* Logging mode: 1\n\n"
  41. << " High address search. Parameter is set in hexadecimal (0-9, a-f).\n"
  42. << "* Start position (2xx): 14\n\n"
  43. << " Used when \"Mining option\" set as 0, 2, 4 or 6.\n"
  44. << " - Meshname domains use base32 (RFC4648) alphabet symbols.\n"
  45. << " - In meshname domain use \"===\" instead \".meshname\".\n"
  46. << " - Subnet brute force understand \"3xx:\" and \"2xx:\" patterns.\n"
  47. << "* Pattern: ::\n\n"
  48. << " Used when \"Mining option\" set as 3 or 5. Extended grep type.\n"
  49. << " - Meshname domains use base32 (RFC4648) alphabet symbols.\n"
  50. << " - In meshname domain use \"===\" instead \".meshname\".\n"
  51. << "* Regexp: ^2.*.f{1,4}.*.ace:(6|9)$\n\n"
  52. << " 0 - disable, 1 - enable.\n"
  53. << "* Display meshname domains: 0";
  54. newconf.close();
  55. std::ifstream conffile ("sygcpp.conf");
  56. if(conffile)
  57. std::cout << "CREATED" << std::endl;
  58. config();
  59. return 0;
  60. } else { // чтение конфигурации
  61. std::string str_temp_read;
  62. std::string str_read;
  63. while(getline(conffile, str_temp_read))
  64. str_read += str_temp_read;
  65. conffile.close();
  66. struct check
  67. {
  68. bool proc = false;
  69. bool mode = false;
  70. bool log = false;
  71. bool high = false;
  72. bool mesh = false;
  73. bool str_search = false;
  74. bool rgx_search = false;
  75. bool ok()
  76. {
  77. return(proc & mode & log & high & mesh & str_search & rgx_search);
  78. }
  79. };
  80. check complete;
  81. std::istringstream ss_input(str_read); // чтение конфига
  82. while(!ss_input.eof())
  83. {
  84. ss_input >> str_temp_read;
  85. if(str_temp_read == "thread:") // поиск параметра по предыдущему слову
  86. {
  87. ss_input >> conf.proc; // запись в соответствующую переменную
  88. if(ss_input.fail())
  89. {
  90. std::cerr << " Count of thread value incorrect." << std::endl;
  91. return -2;
  92. }
  93. complete.proc = true;
  94. }
  95. if(str_temp_read == "option:")
  96. {
  97. ss_input >> conf.mode;
  98. if(ss_input.fail() || (conf.mode > 6 || conf.mode < 0))
  99. {
  100. std::cerr << " Mining option value incorrect." << std::endl;
  101. return -3;
  102. }
  103. complete.mode = true;
  104. }
  105. if(str_temp_read == "mode:")
  106. {
  107. ss_input >> conf.log;
  108. if(ss_input.fail() || (conf.log != 0 && conf.log != 1))
  109. {
  110. std::cerr << " Logging mode value incorrect." << std::endl;
  111. return -4;
  112. }
  113. complete.log = true;
  114. }
  115. if(str_temp_read == "(2xx):")
  116. {
  117. ss_input >> std::hex >> conf.high;
  118. if(ss_input.fail())
  119. {
  120. std::cerr << " Start position value incorrect." << std::endl;
  121. return -5;
  122. }
  123. complete.high = true;
  124. }
  125. if(str_temp_read == "Pattern:")
  126. {
  127. ss_input >> conf.str_search;
  128. if(ss_input.fail())
  129. {
  130. std::cerr << " Pattern value incorrect." << std::endl;
  131. return -6;
  132. }
  133. complete.str_search = true;
  134. }
  135. if(str_temp_read == "Regexp:")
  136. {
  137. ss_input >> conf.rgx_search;
  138. if(ss_input.fail())
  139. {
  140. std::cerr << " Regexp value incorrect." << std::endl;
  141. return -7;
  142. }
  143. complete.rgx_search = true;
  144. }
  145. if(str_temp_read == "domains:")
  146. {
  147. ss_input >> conf.mesh;
  148. if(ss_input.fail() || (conf.mesh != 0 && conf.mesh != 1))
  149. {
  150. std::cerr << " Meshname display value incorrect." << std::endl;
  151. return -8;
  152. }
  153. complete.mesh = true;
  154. }
  155. }
  156. if(!complete.ok())
  157. {
  158. std::cerr << " Corrupted configuration file. Some parameters not found." << std::endl;
  159. return -9;
  160. }
  161. }
  162. return 0;
  163. }
  164. void DisplayConfig()
  165. {
  166. // из-за регулирования количества потоков и countsize вызов функции обязателен
  167. unsigned int processor_count = std::thread::hardware_concurrency(); // кол-во процессоров
  168. if (conf.proc > (int)processor_count)
  169. conf.proc = (int)processor_count;
  170. countsize = 800 << __bsrq(conf.proc);
  171. std::cout << " Threads: " << conf.proc << ", ";
  172. if(conf.mode == 0)
  173. std::cout << "IPv6 pattern (" << conf.str_search << "), ";
  174. else if(conf.mode == 1)
  175. std::cout << "search high addresses (2" << std::setw(2) << std::setfill('0') <<
  176. std::hex << conf.high << std::dec << "+), ";
  177. else if(conf.mode == 2)
  178. std::cout << "search by pattern & high (" << conf.str_search << " & 2" <<
  179. std::setw(2) << std::setfill('0') << std::hex << conf.high << std::dec << "+), ";
  180. else if(conf.mode == 3)
  181. std::cout << "IPv6 regexp (" << conf.rgx_search << "), ";
  182. else if(conf.mode == 4)
  183. std::cout << "meshname pattern (" << conf.str_search << "), ";
  184. else if(conf.mode == 5)
  185. std::cout << "meshname regexp (" << conf.rgx_search << "), ";
  186. else if(conf.mode == 6)
  187. std::cout << "subnet brute force (" << conf.str_search << "/64), ";
  188. if(conf.log)
  189. std::cout << "logging to text file.";
  190. else
  191. std::cout << "console log only.";
  192. if((conf.mode == 4 || conf.mode == 5) && conf.mesh == 0)
  193. conf.mesh = 1; // принудительно включаем отображение мешнейм-доменов при их майнинге
  194. std::cout << std::endl << std::endl;
  195. }
  196. void testoutput()
  197. {
  198. if(conf.log) // проверка включено ли логирование
  199. {
  200. if(conf.mode == 0)
  201. conf.outputfile = "syg-ipv6-pattern.txt";
  202. else if(conf.mode == 1)
  203. conf.outputfile = "syg-ipv6-high.txt";
  204. else if(conf.mode == 2)
  205. conf.outputfile = "syg-ipv6-pattern-high.txt";
  206. else if(conf.mode == 3)
  207. conf.outputfile = "syg-ipv6-regexp.txt";
  208. else if(conf.mode == 4)
  209. conf.outputfile = "syg-meshname-pattern.txt";
  210. else if(conf.mode == 5)
  211. conf.outputfile = "syg-meshname-regexp.txt";
  212. else if(conf.mode == 6)
  213. conf.outputfile = "syg-subnet-brute-force.txt";
  214. std::ifstream test(conf.outputfile);
  215. if(!test) // проверка наличия выходного файла
  216. {
  217. test.close();
  218. std::ofstream output(conf.outputfile);
  219. output << "**************************************************************************\n"
  220. << "Change EncryptionPublicKey and EncryptionPrivateKey to your yggdrasil.conf\n"
  221. << "Windows: C:\\ProgramData\\Yggdrasil\\yggdrasil.conf\n"
  222. << "Debian: /etc/yggdrasil.conf\n"
  223. << "**************************************************************************\n";
  224. output.close();
  225. } else test.close();
  226. }
  227. }