From d14bac3a142a1cf503b8eb2719830c974b1a9648 Mon Sep 17 00:00:00 2001 From: oct Date: Tue, 8 Apr 2025 01:08:24 +0000 Subject: [PATCH 1/2] my_udp() --- src/DosAtk.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/src/DosAtk.cpp b/src/DosAtk.cpp index 725ef8f..3f45caa 100644 --- a/src/DosAtk.cpp +++ b/src/DosAtk.cpp @@ -9,6 +9,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include // ====== DCL ====== // @@ -25,6 +32,10 @@ std::chrono::system_clock::time_point start_timestamp; std::string log_msg; std::string fin_msg; std::string msg; +extern const char* global_ip; +extern int status; +extern int n_ok_requests; +extern int n_fail_requests; int my_check_params(int argc, char **argv) { @@ -109,6 +120,62 @@ int my_check_params(int argc, char **argv) return status; } +void my_udp() { + // Выполняет UDP портовое сканирование well-known портов + int sockfd = -1; // Дескриптор сокета + struct sockaddr_in target_addr; // Адрес цели + static int port_idx = 0; // Текущий индекс порта + static const int ports[] = { // Список портов + 53, 67, 68, 69, 123, 161, 162, 389, 443, 500, 514, 520, 1900, 4500 + }; + static const int ports_total = sizeof(ports)/sizeof(ports[0]); + int curr_port = ports[port_idx]; // Текущий порт + const char dummy_data[] = "SCAN"; // Данные для отправки + ssize_t send_result; // Результат отправки + + // Инициализация структуры адреса + memset(&target_addr, 0, sizeof(target_addr)); + target_addr.sin_family = AF_INET; + target_addr.sin_port = htons(curr_port); + + // Преобразование IP + if (inet_pton(AF_INET, global_ip, &target_addr.sin_addr) <= 0) { + n_fail_requests++; + status = -501; // Код ошибки: неверный IP + goto cleanup; + } + + // Создание сокета + sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sockfd < 0) { + n_fail_requests++; + status = -502; // Ошибка создания сокета + goto cleanup; + } + + // Отправка данных + send_result = sendto(sockfd, dummy_data, sizeof(dummy_data), 0, + (struct sockaddr*)&target_addr, sizeof(target_addr)); + if (send_result < 0) { + n_fail_requests++; + status = -503; // Ошибка отправки + } else { + n_ok_requests++; + status = 0; // Успешная отправка + } + + // Проверка общего числа запросов + if (n_ok_requests + n_fail_requests >= 1000) { + status = 2; // Условие завершения + } + + // Переход к следующему порту + port_idx = (port_idx + 1) % ports_total; + +cleanup: + if (sockfd != -1) close(sockfd); +} + void my_diag(int status) { printf("begin my_diag (status: %i)\n", status); @@ -141,6 +208,15 @@ void my_diag(int status) case -600: printf("Error: To use telegram integration both telegram_id and telegram_token have to be provided!\n.--help for info\n"); break; + case -501: + printf("Error: Invalid target IP address\n"); + break; + case -502: + printf("Error: Failed to create UDP socket\n"); + break; + case -503: + printf("Error: UDP packet send failed\n"); + break; } printf("end my_diag\n"); } @@ -199,11 +275,6 @@ int my_tcp_syn() return 2; } -int my_udp() -{ - return 2; -} - int main(int argc, char **argv) { int check_params_status; @@ -237,7 +308,7 @@ int main(int argc, char **argv) dns_status = my_dns(); if (dns_status == 0) { - while (udp_status = my_udp()) + while (true) { if (udp_status == 2) { -- 2.40.1 From 0988f1716949724f2667bf0b73174278a65ae9a5 Mon Sep 17 00:00:00 2001 From: oct Date: Mon, 28 Apr 2025 17:43:44 +0000 Subject: [PATCH 2/2] my_msg --- src/DosAtk.cpp | 60 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/src/DosAtk.cpp b/src/DosAtk.cpp index 3f45caa..dabd7ea 100644 --- a/src/DosAtk.cpp +++ b/src/DosAtk.cpp @@ -29,8 +29,6 @@ std::string telegram_token; int n_ok_requests; int n_fail_requests; std::chrono::system_clock::time_point start_timestamp; -std::string log_msg; -std::string fin_msg; std::string msg; extern const char* global_ip; extern int status; @@ -120,17 +118,47 @@ int my_check_params(int argc, char **argv) return status; } -void my_udp() { - // Выполняет UDP портовое сканирование well-known портов - int sockfd = -1; // Дескриптор сокета +int my_udp() { + int sockfd; + int port_idx; + int curr_port; + int ports_total; + int ports[14]; + char dummy_data[5]; + + sockfd = -1; // Дескриптор сокета struct sockaddr_in target_addr; // Адрес цели - static int port_idx = 0; // Текущий индекс порта - static const int ports[] = { // Список портов - 53, 67, 68, 69, 123, 161, 162, 389, 443, 500, 514, 520, 1900, 4500 - }; - static const int ports_total = sizeof(ports)/sizeof(ports[0]); - int curr_port = ports[port_idx]; // Текущий порт - const char dummy_data[] = "SCAN"; // Данные для отправки + port_idx = 0; // Текущий индекс порта + + // Выполняет UDP портовое сканирование well-known портов + + ports[0] = 53; // DNS + ports[1] = 67; // DHCP (сервер) + ports[2] = 68; // DHCP (клиент) + ports[3] = 69; // TFTP + ports[4] = 123; // NTP + ports[5] = 161; // SNMP + ports[6] = 162; // SNMP Trap + ports[7] = 389; // LDAP + ports[8] = 443; // HTTPS + ports[9] = 500; // IPSec + ports[10] = 514; // Syslog + ports[11] = 520; // RIP + ports[12] = 1900; // SSDP + ports[13] = 4500; // NAT-T + + ports_total = sizeof(ports)/sizeof(ports[0]); + curr_port = ports[port_idx]; // Текущий порт + + + // Данные для отправки + // Поэлементная инициализация + dummy_data[0] = 'S'; + dummy_data[1] = 'C'; + dummy_data[2] = 'A'; + dummy_data[3] = 'N'; + dummy_data[4] = '\0'; // Обязательный терминатор строки + ssize_t send_result; // Результат отправки // Инициализация структуры адреса @@ -142,7 +170,7 @@ void my_udp() { if (inet_pton(AF_INET, global_ip, &target_addr.sin_addr) <= 0) { n_fail_requests++; status = -501; // Код ошибки: неверный IP - goto cleanup; + if (sockfd != -1) close(sockfd); } // Создание сокета @@ -150,7 +178,7 @@ void my_udp() { if (sockfd < 0) { n_fail_requests++; status = -502; // Ошибка создания сокета - goto cleanup; + if (sockfd != -1) close(sockfd); } // Отправка данных @@ -171,9 +199,7 @@ void my_udp() { // Переход к следующему порту port_idx = (port_idx + 1) % ports_total; - -cleanup: - if (sockfd != -1) close(sockfd); + return status; } void my_diag(int status) -- 2.40.1