Compare commits
3 Commits
my_msg
...
nekitmilk_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bc97e71fe | ||
|
|
2b79163781 | ||
|
|
7493c803fa |
21
.vscode/c_cpp_properties.json
vendored
21
.vscode/c_cpp_properties.json
vendored
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Win32",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"_DEBUG",
|
|
||||||
"UNICODE",
|
|
||||||
"_UNICODE"
|
|
||||||
],
|
|
||||||
"windowsSdkVersion": "10.0.19041.0",
|
|
||||||
"compilerPath": "cl.exe",
|
|
||||||
"cStandard": "c17",
|
|
||||||
"cppStandard": "c++17",
|
|
||||||
"intelliSenseMode": "windows-msvc-x64"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
58
my_msg.cpp
58
my_msg.cpp
@@ -1,58 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <cctype>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
string telegram_id;
|
|
||||||
string bot_token;
|
|
||||||
|
|
||||||
int my_msg(const string& msg) {
|
|
||||||
cout << msg << endl;
|
|
||||||
|
|
||||||
CURL* curl = curl_easy_init();
|
|
||||||
if (!curl) return 6;
|
|
||||||
|
|
||||||
string escaped_msg = escape_json(msg);
|
|
||||||
|
|
||||||
string chat_id_field;
|
|
||||||
if (is_numeric(telegram_id)) {
|
|
||||||
chat_id_field = "\"chat_id\": " + telegram_id;
|
|
||||||
} else {
|
|
||||||
chat_id_field = "\"chat_id\": \"" + telegram_id + "\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
string json_data = "{" + chat_id_field + ", \"text\": \"" + escaped_msg + "\"}";
|
|
||||||
|
|
||||||
struct curl_slist* headers = nullptr;
|
|
||||||
headers = curl_slist_append(headers, "Content-Type: application/json");
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, ("https://api.telegram.org/bot" + bot_token + "/sendMessage").c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_data.c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/7.68.0");
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](void*, size_t size, size_t nmemb, void*) -> size_t {
|
|
||||||
return size * nmemb;
|
|
||||||
});
|
|
||||||
|
|
||||||
CURLcode res = curl_easy_perform(curl);
|
|
||||||
long http_code = 0;
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
|
||||||
|
|
||||||
curl_slist_free_all(headers);
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
|
|
||||||
if (res != CURLE_OK) return 5;
|
|
||||||
|
|
||||||
switch (http_code) {
|
|
||||||
case 200: return 0; // Успех
|
|
||||||
case 401: return 1; // Неверный токен
|
|
||||||
case 400: return 2; // Неверный chat_id
|
|
||||||
case 404: return 3; // Неверный URL (бот не найден)
|
|
||||||
default:
|
|
||||||
return 4; // Ошибка сервера (500)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
src/Makefile
Normal file
14
src/Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CXX = g++
|
||||||
|
CXXFLAGS = -Iinclude/
|
||||||
|
|
||||||
|
all: dos
|
||||||
|
|
||||||
|
# Сюда дописывать файлики для компиляции
|
||||||
|
dos:
|
||||||
|
$(CXX) $(CXXFLAGS) ./main.cpp ./my_check_params.cpp -o dos
|
||||||
|
|
||||||
|
rebuild:
|
||||||
|
rm -f ./dos && make dos
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ./dos
|
||||||
46
src/main.cpp
Normal file
46
src/main.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "my_check_params.hpp"
|
||||||
|
|
||||||
|
Options opts;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Компиляция из директории вызвать команду make my_app
|
||||||
|
// Запуск: ./my_app [флаги и аргументы к ним] (начать можно с флага --help)
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
int error = my_check_params(argc, argv);
|
||||||
|
if (error > 0)
|
||||||
|
{
|
||||||
|
if (opts.attack_type == "flood") {
|
||||||
|
cout << "type attack: " << opts.attack_type << "\n";
|
||||||
|
cout << "domain: " << opts.domain << "\n";
|
||||||
|
cout << "ip: " << opts.ip << "\n";
|
||||||
|
cout << "port: " << opts.port << "\n";
|
||||||
|
cout << "log file path: " << opts.log_file << "\n";
|
||||||
|
}
|
||||||
|
else if (opts.attack_type == "scan") {
|
||||||
|
cout << "type attack: " << opts.attack_type << "\n";
|
||||||
|
cout << "domain: " << opts.domain << "\n";
|
||||||
|
cout << "ip: " << opts.ip << "\n";
|
||||||
|
cout << "log file path: " << opts.log_file << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opts.telegram_id.empty()) {
|
||||||
|
cout << "telegram_id: " << opts.telegram_id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opts.telegram_token.empty()) {
|
||||||
|
cout << "telegram_token: " << opts.telegram_token << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "err code:" << error << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
117
src/my_check_params.cpp
Normal file
117
src/my_check_params.cpp
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#include "my_check_params.hpp"
|
||||||
|
|
||||||
|
// Гарантируется наличие минимума нужных аргументов для flood и scan
|
||||||
|
// Гарантируется, что после работы парсера мы получим только валидный тип атаки
|
||||||
|
|
||||||
|
// Добавить:
|
||||||
|
// 1. Валидацию IP, port
|
||||||
|
|
||||||
|
// Статус коды:
|
||||||
|
// 2 - Атака флуд, все нужные опции есть
|
||||||
|
// 1 - Атака порт скан, все нужные опции есть
|
||||||
|
// 0 - нужна помощь
|
||||||
|
// -1 - пользователь не ввел тип атаки или ввел неверный тип атаки
|
||||||
|
// -10 - Пользователь выбрал тип атаки порт сканнинг, но не ввел нужные параметры
|
||||||
|
// -20 - Пользователь выбрал тип атаки флуд, но не ввел нужные параметры
|
||||||
|
// -100 - неизвестная ошибка
|
||||||
|
// -101 - неизвестная опция или потерян аргумент, следует предложить вызвать флаг помощи
|
||||||
|
// -600 - пользователь ввел токен, но не id или наоборот
|
||||||
|
// Какие-то еще коды?
|
||||||
|
int my_check_params(int argc, char** argv) {
|
||||||
|
|
||||||
|
int status = -100;
|
||||||
|
// Короткие опции (с двоеточием для параметров)
|
||||||
|
const char* short_options = "a:d:i:p:l:t:b:h";
|
||||||
|
|
||||||
|
// Длинные опции
|
||||||
|
const struct option long_options[] = {
|
||||||
|
{"attack", required_argument, NULL, 'a'},
|
||||||
|
{"domain", required_argument, NULL, 'd'},
|
||||||
|
{"ip", required_argument, NULL, 'i'},
|
||||||
|
{"port", required_argument, NULL, 'p'},
|
||||||
|
{"log", required_argument, NULL, 'l'},
|
||||||
|
{"telegram", required_argument, NULL, 't'},
|
||||||
|
{"token", required_argument, NULL, 'b'},
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
opts.attack_type = optarg;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
opts.domain = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
opts.ip = optarg;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
opts.port = optarg;
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
opts.log_file = optarg;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
opts.telegram_id = optarg;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
opts.telegram_token = optarg;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
// std::cout << "Usage: " << argv[0] << " [options]\n"
|
||||||
|
// << "Required:\n"
|
||||||
|
// << " -a, --attack TYPE Type of attack (scan|flood)\n"
|
||||||
|
// << " -d, --domain DOMAIN Target domain\n"
|
||||||
|
// << " -i, --ip IP Target IP\n"
|
||||||
|
// << " -p, --port PORT Port. Required only for flood type!\n"
|
||||||
|
// << "Optional:\n"
|
||||||
|
// << " -l, --log FILE Log file\n"
|
||||||
|
// << " -t, --telegram ID Telegram ID\n"
|
||||||
|
// << " -b, --token TOKEN Telegram bot token\n";
|
||||||
|
status = 0;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
// std::cerr << "Unknown option!\n.--help for info\n";
|
||||||
|
status = -101;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
status = -100;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка обязательных параметров
|
||||||
|
|
||||||
|
if (status != 0 && status != -101)
|
||||||
|
{
|
||||||
|
if (opts.attack_type != "flood" && opts.attack_type != "scan") {
|
||||||
|
// std::cerr << "Error: Missing required parameters!\n--help for more info\n";
|
||||||
|
status = -1;
|
||||||
|
}
|
||||||
|
else if (opts.attack_type == "scan" && (opts.domain.empty() || opts.ip.empty())) {
|
||||||
|
// std::cerr << "Error: Missing required parameters!\n--help for more info\n";
|
||||||
|
status = -10;
|
||||||
|
}
|
||||||
|
else if (opts.attack_type == "flood" && (opts.domain.empty() || opts.ip.empty() || opts.port.empty())) {
|
||||||
|
// std::cerr << "Error: Missing required parameters!\n--help for more info\n";
|
||||||
|
status = -20;
|
||||||
|
}
|
||||||
|
else if ((!opts.telegram_id.empty() && opts.telegram_token.empty()) || (opts.telegram_id.empty() && !opts.telegram_token.empty())) {
|
||||||
|
status = -600;
|
||||||
|
}
|
||||||
|
else if (opts.attack_type == "scan" && !opts.domain.empty() && !opts.ip.empty()) {
|
||||||
|
// std::cerr << "Error: Missing required parameters!\n--help for more info\n";
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
else if (opts.attack_type == "flood" && !opts.domain.empty() && !opts.ip.empty() && !opts.port.empty()) {
|
||||||
|
// std::cerr << "Error: Missing required parameters!\n--help for more info\n";
|
||||||
|
status = 2;
|
||||||
|
}
|
||||||
|
// Какие-то еще коды?
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
22
src/my_check_params.hpp
Normal file
22
src/my_check_params.hpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <getopt.h> // Для struct option
|
||||||
|
|
||||||
|
|
||||||
|
struct Options {
|
||||||
|
std::string attack_type; // Обязательный параметр
|
||||||
|
std::string domain; // Обязательный параметр
|
||||||
|
std::string ip; // Обязательный параметр
|
||||||
|
std::string port; // Обязательный параметр (не обязательный для скана)
|
||||||
|
std::string log_file = "/var/logs/DosAtk"; // Значение по умолчанию, не обязательный
|
||||||
|
std::string telegram_id; // Не обязательный параметр
|
||||||
|
std::string telegram_token; // Не обязательный параметр
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Options opts; // Теперь это глобальная переменная, где она должна определяться?
|
||||||
|
|
||||||
|
// Прототип функции парсинга
|
||||||
|
int my_check_params(int argc, char** argv);
|
||||||
Reference in New Issue
Block a user