my_udp #16
|
@ -21,8 +21,12 @@
|
|||
#include <getopt.h> // Для struct option и getopt_long()
|
||||
#include <curl/curl.h> // Основной заголовок libcurl
|
||||
#include <iostream> // стандартный input output
|
||||
#include <iomanip>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <iomanip> // Форматированный ввод/вывод
|
||||
#include <nlohmann/json.hpp>// Работа с JSON
|
||||
#include <stdio.h> // Стандартный ввод/вывод (C)
|
||||
#include <stdlib.h> // Базовые функции (C)
|
||||
#include <string.h> // Работа со строками (C)
|
||||
#include <netinet/in.h> // Сетевые функции, интернет-адреса
|
||||
|
||||
/*
|
||||
██████╗ ██████╗██╗ ██╗ ██╗ █████╗ ██████╗ ███████╗
|
||||
|
@ -209,6 +213,15 @@ void my_diag()
|
|||
case -600: // Неполные данные для Telegram-уведомлений
|
||||
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"); // debug
|
||||
|
@ -566,8 +579,67 @@ int my_tcp_syn() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int my_udp() {
|
||||
return 0;
|
||||
void my_udp() {
|
||||
// Выполняет UDP портовое сканирование well-known портов
|
||||
int status;
|
||||
int sockfd; // Дескриптор сокета
|
||||
struct sockaddr_in target_addr; // Адрес цели
|
||||
static int port_idx; // Текущий индекс порта
|
||||
static const int ports[]; // Список портов
|
||||
static const int ports_total;
|
||||
int curr_port; // Текущий порт
|
||||
const char dummy_data[]; // Данные для отправки
|
||||
ssize_t send_result; // Результат отправки
|
||||
|
||||
// Инициализация структуры адреса
|
||||
memset(&target_addr, 0, sizeof(target_addr));
|
||||
curr_port = ports[port_idx];
|
||||
dummy_data[] = "SCAN";
|
||||
target_addr.sin_family = AF_INET;
|
||||
target_addr.sin_port = htons(curr_port);
|
||||
ports_total = sizeof(ports)/sizeof(ports[0])
|
||||
sockfd = -1;
|
||||
port_idx = 0;
|
||||
ports = { // Список портов
|
||||
53, 67, 68, 69, 123, 161, 162, 389, 443, 500, 514, 520, 1900, 4500
|
||||
};
|
||||
|
||||
// Преобразование IP
|
||||
if (inet_pton(AF_INET, ip, &target_addr.sin_addr) <= 0) {
|
||||
n_fail_requests++;
|
||||
status = -501; // Код ошибки: неверный IP
|
||||
if (sockfd != -1) close(sockfd);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Создание сокета
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sockfd < 0) {
|
||||
n_fail_requests++;
|
||||
status = -502; // Ошибка создания сокета
|
||||
if (sockfd != -1) close(sockfd);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Отправка данных
|
||||
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;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Callback для записи ответа от сервера
|
||||
|
|
Loading…
Reference in New Issue