Skip to content
API Documentation
BastionGuard™
AntiPhishingEngine Class Reference

#include <AntiPhishingEngine.hpp>

Public Member Functions

 AntiPhishingEngine ()
 ~AntiPhishingEngine ()
void start ()
void stop ()
bool check_url (const std::string &url)
sigc::signal< void(const std::string &)> & signal_event ()

Private Member Functions

void run ()
bool is_blacklisted (const std::string &url)
bool is_suspicious (const std::string &url)

Private Attributes

std::thread worker_
std::atomic< bool > running_
sigc::signal< void(const std::string &)> sig_event_
std::vector< std::string > blacklist_

Detailed Description

Definition at line 28 of file AntiPhishingEngine.hpp.

Constructor & Destructor Documentation

◆ AntiPhishingEngine()

AntiPhishingEngine::AntiPhishingEngine ( )

Definition at line 31 of file AntiPhishingEngine.cpp.

31 : running_(false) {
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}
#define _(s)
std::vector< std::string > blacklist_
std::atomic< bool > running_
std::string resource(const std::string &rel)
Definition Resource.hpp:31

References _, blacklist_, resource(), and running_.

◆ ~AntiPhishingEngine()

AntiPhishingEngine::~AntiPhishingEngine ( )

Definition at line 54 of file AntiPhishingEngine.cpp.

54 {
55 stop();
56}

References stop().

Member Function Documentation

◆ check_url()

bool AntiPhishingEngine::check_url ( const std::string & url)

Definition at line 69 of file AntiPhishingEngine.cpp.

69 {
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}
bool is_blacklisted(const std::string &url)
sigc::signal< void(const std::string &)> sig_event_
bool is_suspicious(const std::string &url)

References _, is_blacklisted(), is_suspicious(), and sig_event_.

◆ is_blacklisted()

bool AntiPhishingEngine::is_blacklisted ( const std::string & url)
private

Definition at line 81 of file AntiPhishingEngine.cpp.

81 {
82 for (auto& bad : blacklist_) {
83 if (url.find(bad) != std::string::npos) return true;
84 }
85 return false;
86}

References blacklist_.

Referenced by check_url().

◆ is_suspicious()

bool AntiPhishingEngine::is_suspicious ( const std::string & url)
private

Definition at line 88 of file AntiPhishingEngine.cpp.

88 {
89 static const std::regex suspicious(R"((g00gle|faceb00k|paypa1|micros0ft))");
90 return std::regex_search(url, suspicious);
91}

Referenced by check_url().

◆ run()

void AntiPhishingEngine::run ( )
private

Definition at line 93 of file AntiPhishingEngine.cpp.

93 {
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}

References _, running_, and sig_event_.

Referenced by start().

◆ signal_event()

sigc::signal< void(const std::string &)> & AntiPhishingEngine::signal_event ( )

Definition at line 101 of file AntiPhishingEngine.cpp.

101 {
102 return sig_event_;
103}

References sig_event_.

◆ start()

void AntiPhishingEngine::start ( )

Definition at line 58 of file AntiPhishingEngine.cpp.

58 {
59 if (running_) return;
60 running_ = true;
61 worker_ = std::thread(&AntiPhishingEngine::run, this);
62}

References run(), running_, and worker_.

◆ stop()

void AntiPhishingEngine::stop ( )

Definition at line 64 of file AntiPhishingEngine.cpp.

64 {
65 running_ = false;
66 if (worker_.joinable()) worker_.join();
67}

References running_, and worker_.

Referenced by ~AntiPhishingEngine().

Member Data Documentation

◆ blacklist_

std::vector<std::string> AntiPhishingEngine::blacklist_
private

Definition at line 51 of file AntiPhishingEngine.hpp.

Referenced by AntiPhishingEngine(), and is_blacklisted().

◆ running_

std::atomic<bool> AntiPhishingEngine::running_
private

Definition at line 48 of file AntiPhishingEngine.hpp.

Referenced by AntiPhishingEngine(), run(), start(), and stop().

◆ sig_event_

sigc::signal<void(const std::string&)> AntiPhishingEngine::sig_event_
private

Definition at line 49 of file AntiPhishingEngine.hpp.

Referenced by check_url(), run(), and signal_event().

◆ worker_

std::thread AntiPhishingEngine::worker_
private

Definition at line 47 of file AntiPhishingEngine.hpp.

Referenced by start(), and stop().


The documentation for this class was generated from the following files: