Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
sniffer.h
Go to the documentation of this file.
1#ifndef SNIFF_SNIFFER
2#define SNIFF_SNIFFER
3
4#include "access_point.h"
5#include "database.h"
6#include "decrypter.h"
7#include "net_card_manager.h"
8#include "recording.h"
9#include <list>
10#include <tins/network_interface.h>
11#include <tins/sniffer.h>
12#include <unordered_map>
13
14namespace yarilo {
16 FOCUSED, // We are focused on one network and following its channel
17 GENERAL // We are hopping through the spectrum
18};
19
24class Sniffer {
25public:
26 typedef std::pair<MACAddress, SSID> network_name;
28
33 Sniffer(std::unique_ptr<Tins::FileSniffer> sniffer,
34 const std::filesystem::path &filepath, Database &db);
35
41 Sniffer(std::unique_ptr<Tins::Sniffer> sniffer,
42 const Tins::NetworkInterface &iface, Database &db);
43
47 void start();
48
53 std::set<network_name> all_networks();
54
60 std::optional<MACAddress> get_bssid(const SSID &ssid);
61
69 std::optional<std::shared_ptr<AccessPoint>> get_network(const SSID &ssid);
70
77 std::optional<std::shared_ptr<AccessPoint>>
78 get_network(const MACAddress &bssid);
79
84 void add_ignored_network(const SSID &ssid);
85
90 void add_ignored_network(const MACAddress &bssid);
91
96 std::unordered_map<MACAddress, SSID> ignored_networks();
97
101 void shutdown();
102
107 std::optional<std::string> iface();
108
113 std::optional<std::filesystem::path> file();
114
121 std::optional<uint32_t> focus_network(const SSID &ssid);
122
129 std::optional<uint32_t> focus_network(const MACAddress &bssid);
130
135 std::optional<std::shared_ptr<AccessPoint>> focused_network();
136
140 void stop_focus();
141
148 std::optional<Recording::info>
149 save_traffic(const std::filesystem::path &saves_path,
150 const std::string &name);
151
158 std::optional<Recording::info>
159 save_decrypted_traffic(const std::filesystem::path &save_path,
160 const std::string &name);
161
167 static std::vector<Recording::info>
168 available_recordings(const std::filesystem::path &save_path);
169
178 static std::optional<std::string>
179 detect_interface(std::shared_ptr<spdlog::logger> log,
180 const std::string &ifname);
181
183 if (!filemode)
184 net_manager.disconnect();
185 }
186
187private:
193 bool handle_pkt(Tins::Packet &pkt);
194
200 bool handle_data(Tins::Packet &pkt);
201
207 bool handle_management(Tins::Packet &pkt);
208
215 Tins::Packet *save_pkt(Tins::Packet &pkt);
216
223 void hopper(int phy_idx, const std::vector<uint32_t> &channels);
224
225 std::shared_ptr<spdlog::logger> logger;
226 std::list<Tins::Packet> packets;
227 std::atomic<ScanMode> scan_mode = GENERAL;
228
229 NetCardManager net_manager;
230 MACAddress focused;
231 bool filemode = true;
232 int count = 0;
233 int current_channel = 1;
234 std::unique_ptr<Tins::Crypto::WPA2Decrypter> decrypter;
235 std::unordered_map<MACAddress, std::shared_ptr<AccessPoint>> aps;
236 Tins::NetworkInterface send_iface;
237 std::string iface_name = "";
238 std::filesystem::path filepath;
239 std::unordered_map<MACAddress, SSID> ignored_nets;
240 std::set<MACAddress> ignored_nets_bssid_only; // Wait for SSID to show up
241 std::set<SSID> ignored_nets_ssid_only; // Wait for BSSID to show up
242 std::unique_ptr<Tins::BaseSniffer> sniffer;
243 std::atomic<bool> finished;
244 Database &db;
245};
246
247} // namespace yarilo
248
249#endif // SNIFF_SNIFFER
Definition database.h:14
Manager for network card information gathering and state control.
Definition net_card_manager.h:58
void disconnect()
Definition net_card_manager.cpp:88
Packet sniffer and handler in charge of tracking, information gathering and decrypting passing data.
Definition sniffer.h:24
std::optional< Recording::info > save_decrypted_traffic(const std::filesystem::path &save_path, const std::string &name)
Definition sniffer.cpp:277
std::optional< std::shared_ptr< AccessPoint > > get_network(const SSID &ssid)
Definition sniffer.cpp:122
std::optional< Recording::info > save_traffic(const std::filesystem::path &saves_path, const std::string &name)
Definition sniffer.cpp:215
void stop_focus()
Definition sniffer.cpp:207
std::set< network_name > all_networks()
Definition sniffer.cpp:107
std::optional< std::shared_ptr< AccessPoint > > focused_network()
Definition sniffer.cpp:199
~Sniffer()
Definition sniffer.h:182
std::optional< uint32_t > focus_network(const SSID &ssid)
Definition sniffer.cpp:182
Sniffer(std::unique_ptr< Tins::FileSniffer > sniffer, const std::filesystem::path &filepath, Database &db)
Definition sniffer.cpp:25
std::optional< MACAddress > get_bssid(const SSID &ssid)
Definition sniffer.cpp:114
static std::vector< Recording::info > available_recordings(const std::filesystem::path &save_path)
void add_ignored_network(const SSID &ssid)
Definition sniffer.cpp:136
std::optional< std::filesystem::path > file()
Definition sniffer.cpp:176
std::unordered_map< MACAddress, SSID > ignored_networks()
Definition sniffer.cpp:160
std::pair< MACAddress, SSID > network_name
Definition sniffer.h:26
static MACAddress NoAddress
Definition sniffer.h:27
static std::optional< std::string > detect_interface(std::shared_ptr< spdlog::logger > log, const std::string &ifname)
Definition sniffer.cpp:462
std::optional< std::string > iface()
Definition sniffer.cpp:170
void shutdown()
Definition sniffer.cpp:164
void start()
Definition sniffer.cpp:46
Definition access_point.cpp:22
std::string SSID
Definition decrypter.h:19
ScanMode
Definition sniffer.h:15
@ GENERAL
Definition sniffer.h:17
@ FOCUSED
Definition sniffer.h:16
Tins::HWAddress< 6 > MACAddress
Definition decrypter.h:20