public fhl_hunting_instance(fhl_hunting_result_type r, fhl_hunting_type t, fhl_logfile_instance_node s, string sign) { final_attack = r; type = t; request = s; signature = sign; }
public static void doHuntind(object sender, DoWorkEventArgs e) { results = new List <fhl_hunting_instance>(); // int i = 0; // error_5xx = new List<fhl_logfile_instance_node>(); for (int iterFile = 0; iterFile < fhl_core.Files.Count; iterFile++) { /// Если это веб сервер NGINX for (int iterRequest = 0; iterRequest < fhl_core.Files[iterFile].rows.Count; iterRequest++) { fhl_logfile_instance_node tempRequest = fhl_core.Files[iterFile].rows[iterRequest]; var REMOTE_ADDR = tempRequest.params_list.Find(item => item.var == "$remote_addr").value; // Если IP входит в белый список исключений, то пропускаем итерацию. if (fhl_core.FilteringOnHunting) { if (fhl_core.WhiteIPList.Any(s => s.Contains(REMOTE_ADDR))) { // MessageBox.Show("Пропущен запрос с ip адреса: " + REMOTE_ADDR); continue; } } int HTTP_CODE = Int32.Parse(tempRequest.params_list.Find(item => item.var == "$status").value); var REQUEST = tempRequest.params_list.Find(item => item.var == "$request"); // Проверка на доступ к админ панели foreach (string cp in fhl_dic_admin_panels.list) { if (REQUEST.value.IndexOf(cp) != -1) { // MessageBox.Show(REQUEST.value); switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.PredictableResourceLocation, tempRequest, "Предсказуемое расположение ресурсов")); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.PredictableResourceLocation, tempRequest, "Предсказуемое расположение ресурсов")); break; } ; } } // Проверка на php шелы. foreach (string ab in fhl_dic_php_shell.list) { if (REQUEST.value.IndexOf(ab) != -1) { switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.BackdoorExecute, tempRequest, ab)); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.BackdoorExecute, tempRequest, ab)); break; } ; } } // Проверка на ASP шелы. foreach (string ab in fhl_dic_asp_shell.list) { if (REQUEST.value.IndexOf(ab) != -1) { switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.BackdoorExecute, tempRequest, ab)); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.BackdoorExecute, tempRequest, ab)); break; } ; } } // Проверка на выполнение универсальных комманд ОС foreach (string ab in fhl_dic_os_commanding.list) { if ((ab.Length > 4) ? (REQUEST.value.IndexOf(ab) != -1) : (REQUEST.value.IndexOf(ab + " ") != -1) || (REQUEST.value.IndexOf(ab + "%20") != -1)) { switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; } ; } } // Проверка на выполнение Unix комманд ОС foreach (string ab in fhl_dic_os_unix.list) { // if (REQUEST.value.IndexOf(ab) != -1) if ((ab.Length > 4) ? (REQUEST.value.IndexOf(ab) != -1) : (REQUEST.value.IndexOf(ab + " ") != -1) || (REQUEST.value.IndexOf(ab + "%20") != -1)) { switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; } ; } } // Проверка на выполнение Windows комманд ОС foreach (string ab in fhl_dic_os_windows.list) { if ((ab.Length > 4) ? (REQUEST.value.IndexOf(ab) != -1) : (REQUEST.value.IndexOf(ab + " ") != -1) || (REQUEST.value.IndexOf(ab + "%20") != -1)) { switch (HTTP_CODE) { case 500: case 200: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Success, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; case 301: case 302: case 400: case 404: fhl_hunting.results.Add(new fhl_hunting_instance(fhl_hunting_result_type.Failed, fhl_hunting_type.OSCommanding, tempRequest, ab)); break; } ; } } } } }
public static void ParseFiles_RunWorker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; int allRequestIter = 0; // Счетчик обработанных запросов // Файлы логов будет обрабатываться параллельно foreach (fhl_logfile_instance f in fhl_core.Files) { var rangeRequestPartitioner = Partitioner.Create(0, f.sourceRows.Count, fhl_core.ThreadParse); //var rangePartitioner = Partitioner.Create(0, _dArray.Length, _dArray.Length / Environment.ProcessorCount); Parallel.ForEach(rangeRequestPartitioner, (range, loopState) => { if (!worker.CancellationPending) { for (int iter0 = range.Item1; iter0 < range.Item2; iter0++) { if (worker.CancellationPending == true) { e.Cancel = true; break; } else { Regex rg = new Regex(fhl_core.ws_cfg.log_format_regxPattern); // Создаем экземпляр Regex MatchCollection matchedAuthors = rg.Matches(f.sourceRows[iter0]); // Получаем все совпадения List <fhl_websrv_var> req = new List <fhl_websrv_var>(); // Массив с результатами //MessageBox.Show(f.sourceRows[iter0]); for (int count = 0; count < matchedAuthors.Count; count++) { for (int j = 1, param_iter = 0; j < matchedAuthors[count].Groups.Count; j++, param_iter++) { req.Add(new fhl_websrv_var(fhl_core.ws_cfg.existVariable[param_iter].var, matchedAuthors[count].Groups[j].Value)); } } // Фильтрация запросов по IP на этапе забора строк. bool continue_request = false; if (fhl_core.FilteringOnOpeningFiles) { foreach (string wip in fhl_core.WhiteIPList) { if (f.sourceRows[iter0].IndexOf(wip) != -1) { continue_request = true; } } } if (continue_request) { continue; } fhl_logfile_instance_node t1 = new fhl_logfile_instance_node(f.sourceRows[iter0]); t1.params_list = req; f.rows.Add(t1); worker.ReportProgress(allRequestIter++); } } } else { fhl_core.Files.Clear(); // Чистим список загруженных файлов. fhl_dispatcher.messages.Add("Задача (подготовки лог файлов) отменена пользователем!"); worker.ReportProgress(allRequestIter++); loopState.Break(); } }); } }