Skip to content
API Documentation
BastionGuard™
AntiPhishingEngine.cpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#include "Resource.hpp"
23#include <iostream>
24#include <fstream>
25#include <regex>
26#include <filesystem>
27#include <chrono>
28#include <thread>
29#include <glib/gi18n.h>
30
32 std::string path = resource("phishing/blacklist.txt");
33 std::ifstream f(path);
34
35 if (!f.is_open()) {
36 std::cerr << "⚠ " << _("Impossibile aprire blacklist phishing: ") << path << "\n";
37 return;
38 }
39
40 std::string url;
41 while (std::getline(f, url)) {
42 if (!url.empty()) blacklist_.push_back(url);
43 }
44 f.close();
45
46 if (blacklist_.empty()) {
47 std::cerr << "⚠ " << _("Blacklist phishing vuota o non caricata da ") << path << "\n";
48 } else {
49 std::cout << "✔ " << blacklist_.size() << " "
50 << _("voci caricate da blacklist phishing in ") << path << "\n";
51 }
52}
53
57
59 if (running_) return;
60 running_ = true;
61 worker_ = std::thread(&AntiPhishingEngine::run, this);
62}
63
65 running_ = false;
66 if (worker_.joinable()) worker_.join();
67}
68
69bool AntiPhishingEngine::check_url(const std::string& url) {
70 if (is_blacklisted(url)) {
71 sig_event_.emit(_("⚠ URL in blacklist: ") + url);
72 return true;
73 }
74 if (is_suspicious(url)) {
75 sig_event_.emit(_("⚠ URL sospetto (phishing euristico): ") + url);
76 return true;
77 }
78 return false;
79}
80
81bool AntiPhishingEngine::is_blacklisted(const std::string& url) {
82 for (auto& bad : blacklist_) {
83 if (url.find(bad) != std::string::npos) return true;
84 }
85 return false;
86}
87
88bool AntiPhishingEngine::is_suspicious(const std::string& url) {
89 static const std::regex suspicious(R"((g00gle|faceb00k|paypa1|micros0ft))");
90 return std::regex_search(url, suspicious);
91}
92
94 sig_event_.emit(_(">>> AntiPhishing avviato"));
95 while (running_) {
96 std::this_thread::sleep_for(std::chrono::seconds(30));
97 }
98 sig_event_.emit(_(">>> AntiPhishing fermato"));
99}
100
101sigc::signal<void(const std::string&)>& AntiPhishingEngine::signal_event() {
102 return sig_event_;
103}
#define _(s)
std::vector< std::string > blacklist_
bool is_blacklisted(const std::string &url)
sigc::signal< void(const std::string &)> sig_event_
sigc::signal< void(const std::string &)> & signal_event()
std::atomic< bool > running_
bool check_url(const std::string &url)
bool is_suspicious(const std::string &url)
std::string resource(const std::string &rel)
Definition Resource.hpp:31