This commit is contained in:
oct 2025-04-28 17:43:44 +00:00
parent d14bac3a14
commit 0988f17169
1 changed files with 43 additions and 17 deletions

View File

@ -29,8 +29,6 @@ std::string telegram_token;
int n_ok_requests; int n_ok_requests;
int n_fail_requests; int n_fail_requests;
std::chrono::system_clock::time_point start_timestamp; std::chrono::system_clock::time_point start_timestamp;
std::string log_msg;
std::string fin_msg;
std::string msg; std::string msg;
extern const char* global_ip; extern const char* global_ip;
extern int status; extern int status;
@ -120,17 +118,47 @@ int my_check_params(int argc, char **argv)
return status; return status;
} }
void my_udp() { int my_udp() {
// Выполняет UDP портовое сканирование well-known портов int sockfd;
int sockfd = -1; // Дескриптор сокета int port_idx;
int curr_port;
int ports_total;
int ports[14];
char dummy_data[5];
sockfd = -1; // Дескриптор сокета
struct sockaddr_in target_addr; // Адрес цели struct sockaddr_in target_addr; // Адрес цели
static int port_idx = 0; // Текущий индекс порта port_idx = 0; // Текущий индекс порта
static const int ports[] = { // Список портов
53, 67, 68, 69, 123, 161, 162, 389, 443, 500, 514, 520, 1900, 4500 // Выполняет UDP портовое сканирование well-known портов
};
static const int ports_total = sizeof(ports)/sizeof(ports[0]); ports[0] = 53; // DNS
int curr_port = ports[port_idx]; // Текущий порт ports[1] = 67; // DHCP (сервер)
const char dummy_data[] = "SCAN"; // Данные для отправки 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; // Результат отправки ssize_t send_result; // Результат отправки
// Инициализация структуры адреса // Инициализация структуры адреса
@ -142,7 +170,7 @@ void my_udp() {
if (inet_pton(AF_INET, global_ip, &target_addr.sin_addr) <= 0) { if (inet_pton(AF_INET, global_ip, &target_addr.sin_addr) <= 0) {
n_fail_requests++; n_fail_requests++;
status = -501; // Код ошибки: неверный IP status = -501; // Код ошибки: неверный IP
goto cleanup; if (sockfd != -1) close(sockfd);
} }
// Создание сокета // Создание сокета
@ -150,7 +178,7 @@ void my_udp() {
if (sockfd < 0) { if (sockfd < 0) {
n_fail_requests++; n_fail_requests++;
status = -502; // Ошибка создания сокета status = -502; // Ошибка создания сокета
goto cleanup; if (sockfd != -1) close(sockfd);
} }
// Отправка данных // Отправка данных
@ -171,9 +199,7 @@ void my_udp() {
// Переход к следующему порту // Переход к следующему порту
port_idx = (port_idx + 1) % ports_total; port_idx = (port_idx + 1) % ports_total;
return status;
cleanup:
if (sockfd != -1) close(sockfd);
} }
void my_diag(int status) void my_diag(int status)