Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
access_point.h
Go to the documentation of this file.
1#ifndef SNIFF_AP
2#define SNIFF_AP
3
4#include "channel.h"
5#include "decrypter.h"
6#include "recording.h"
7#include <filesystem>
8#include <optional>
9#include <tins/ethernetII.h>
10#include <tins/tins.h>
11#include <vector>
12
13#include "database.h"
14
15namespace yarilo {
16
21public:
26 enum class NetworkSecurity {
27 OPEN,
28 WEP,
29 WPA,
34 };
35
45
46 /*
47 * @brief WiFi standard that is supported by an access point, there can be
48 * many of them for a given access point
49 */
50 enum class WiFiStandard {
51 Dot11A, // Legacy standards
52 Dot11B, // Legacy standards
53 Dot11G, // Legacy standards
54 Dot11N, // Wi-Fi 4 or HT (High Throughput)
55 Dot11AC, // Wi-Fi 5 or HVT (Very High Throughput)
56 Dot11AX, // Wi-Fi 6 or HE (High Efficiency)
57 };
58
59 /*
60 * @brief WiFi modulation type used
61 */
62 enum class Modulation {
63 CCK, // Complementary code keying (802.11b)
64 BPSK, // Binary phase shift keying
65 QPSK, // Quadrature phase shift keying
66 QAM16, // Quadrature amplitude modulation
67 QAM64,
68 QAM256,
69 QAM1024,
70 };
71
72 /*
73 * @brief WiFi channel width used
74 */
75 enum class ChannelWidth {
76 CHAN20,
77 CHAN40,
78 CHAN80,
80 CHAN160,
81 };
82
92 std::set<uint8_t> mcs_supported_idx; // Indices of MCS
93 std::set<Modulation> modulation_supported;
94 std::set<uint8_t>
95 spatial_streams_supported; // Spatial stream configurations for MIMO,
96 // for example 3 means that the network
97 // supports 3 spatial streams, or 3x3
98 std::set<ChannelWidth> channel_widths_supported;
99 };
100
104 struct client_info {
105 std::string hwaddr;
106 std::string hostname;
107 std::string ipv4;
108 std::string ipv6;
109 uint32_t sent_unicast;
110 uint32_t sent_total;
111 uint32_t received;
112 int8_t rrsi;
113 int8_t noise;
114 int8_t snr;
115 };
116
122 bool is_ccmp = false;
123 bool pmf = false;
124 std::optional<Tins::RSNInformation::CypherSuites> pairwise_cipher;
125 };
126
133 AccessPoint(const MACAddress &bssid, const SSID &ssid, int wifi_channel,
134 Database &db);
135
141 bool handle_pkt(Tins::Packet *pkt);
142
150 DecryptionState add_password(const std::string &psk);
151
156 SSID get_ssid() const;
157
162 MACAddress get_bssid() const;
163
168 int get_wifi_channel() const;
169
174 std::vector<wifi_standard_info> standards_supported() const;
175
179 std::shared_ptr<PacketChannel> get_decrypted_channel();
180
184 void close_all_channels();
185
194 bool send_deauth(const Tins::NetworkInterface &iface, const MACAddress &addr);
195
201 bool has_working_password() const;
202
207 std::vector<NetworkSecurity> security_supported() const;
208
213 bool unicast_decryption_supported() const;
214
219 bool group_decryption_supported() const;
220
225 bool client_decryption_supported(const MACAddress &client);
226
227 /*
228 * Get if the network can protect its management frames
229 * @return True if 802.11w is in place
230 */
232
233 /*
234 * Get if the network must protect its management frames
235 * @return True if 802.11w is in place
236 */
238
239 /*
240 * Get if the network protects its management frames for a specific client
241 * @return True if 802.11w is enforced for a client
242 */
243 bool protected_management(const MACAddress &client);
244
250
255 const std::set<MACAddress> get_clients() {
256 std::set<MACAddress> result;
257 for (const auto &[addr, _] : clients)
258 result.insert(addr);
259 return result;
260 }
261
266 const std::optional<client_info> get_client(MACAddress addr) {
267 if (!clients.count(addr))
268 return std::nullopt;
269 return clients[addr];
270 }
271
276 const std::optional<client_security> get_client_security(MACAddress addr) {
277 if (!clients_security.count(addr))
278 return std::nullopt;
279 return clients_security[addr];
280 }
281
286 uint32_t raw_packet_count() const;
287
292 uint32_t decrypted_packet_count() const;
293
301 std::optional<Recording::info>
302 save_traffic(const std::filesystem::path &save_path, const std::string &name);
303
310 std::optional<Recording::info>
311 save_decrypted_traffic(const std::filesystem::path &save_path,
312 const std::string &name);
313
317 void set_vendor();
318
323 std::string get_vendor() const;
324
329 std::string get_oid() const;
330
331 std::string supported_security_text() const;
332
333private:
338 bool handle_data(Tins::Packet *pkt);
339
344 bool handle_management(Tins::Packet *pkt);
345
351 void update_client_metadata(const Tins::Packet &pkt);
352
357 std::vector<NetworkSecurity>
358 detect_security_modes(const Tins::Dot11ManagementFrame &mgmt) const;
359
364 std::vector<wifi_standard_info>
365 detect_wifi_capabilities(const Tins::Dot11ManagementFrame &mgmt) const;
366
372 bool check_pmf_capable(const Tins::Dot11ManagementFrame &mgmt) const;
373
379 bool check_pmf_required(const Tins::Dot11ManagementFrame &mgmt) const;
380
385 bool is_ccmp(const Tins::Dot11ManagementFrame &mgmt) const;
386
387 uint32_t count = 0;
388 uint32_t decrypted_pkt_count = 0;
389 std::shared_ptr<spdlog::logger> logger;
390 const SSID ssid;
391 const MACAddress bssid;
392 int wifi_channel = 0;
393 std::vector<Tins::Packet *> captured_packets;
394 WPA2Decrypter decrypter;
395 std::vector<std::shared_ptr<PacketChannel>> converted_channels;
396 std::vector<wifi_standard_info> wifi_stds_supported;
397
398 // Used for deauth, we need to "copy" the behaviour of the radiotap layer
399 uint8_t radio_length = 0;
400 uint8_t radio_channel_freq = 0;
401 uint8_t radio_channel_type = 0;
402 uint8_t radio_antenna = 0;
403
404 bool capabilities_detected = false;
405 std::vector<NetworkSecurity> security_modes;
406 bool pmf_supported = false; // 802.11w
407 bool pmf_required = false; // 802.11w
408 bool uses_ccmp = false;
409 std::unordered_map<MACAddress, client_info> clients;
410 std::unordered_map<MACAddress, client_security> clients_security;
411 Database &db;
412 std::string vendor;
413 std::string oid;
414};
415
416} // namespace yarilo
417
418#endif // SNIFF_AP
Access Point in a basic service set (BSS) network.
Definition access_point.h:20
NetworkSecurity
Network security protocol used. A network can support multiple ways to connect and secure data.
Definition access_point.h:26
std::optional< Recording::info > save_decrypted_traffic(const std::filesystem::path &save_path, const std::string &name)
Definition access_point.cpp:199
std::optional< Recording::info > save_traffic(const std::filesystem::path &save_path, const std::string &name)
Definition access_point.cpp:191
MACAddress get_bssid() const
Definition access_point.cpp:45
const std::optional< client_security > get_client_security(MACAddress addr)
Definition access_point.h:276
uint32_t decrypted_packet_count() const
Definition access_point.cpp:186
const std::optional< client_info > get_client(MACAddress addr)
Definition access_point.h:266
bool unicast_decryption_supported() const
Definition access_point.cpp:146
bool handle_pkt(Tins::Packet *pkt)
Definition access_point.cpp:33
AccessPoint(const MACAddress &bssid, const SSID &ssid, int wifi_channel, Database &db)
Definition access_point.cpp:24
DecryptionState
Current state of decryption.
Definition access_point.h:39
SSID get_ssid() const
Definition access_point.cpp:43
bool protected_management_required() const
Definition access_point.cpp:172
std::vector< wifi_standard_info > standards_supported() const
Definition access_point.cpp:49
std::shared_ptr< PacketChannel > get_decrypted_channel()
Definition access_point.cpp:53
DecryptionState add_password(const std::string &psk)
Definition access_point.cpp:73
bool client_decryption_supported(const MACAddress &client)
Definition access_point.cpp:158
bool protected_management_supported() const
Definition access_point.cpp:168
std::vector< NetworkSecurity > security_supported() const
Definition access_point.cpp:142
std::string get_oid() const
Definition access_point.cpp:740
WiFiStandard
Definition access_point.h:50
void set_vendor()
Definition access_point.cpp:730
WPA2Decrypter & get_decrypter()
Definition access_point.cpp:180
Modulation
Definition access_point.h:62
const std::set< MACAddress > get_clients()
Definition access_point.h:255
bool group_decryption_supported() const
Definition access_point.cpp:151
std::string supported_security_text() const
bool send_deauth(const Tins::NetworkInterface &iface, const MACAddress &addr)
Definition access_point.cpp:100
bool protected_management(const MACAddress &client)
Definition access_point.cpp:174
bool has_working_password() const
Definition access_point.cpp:138
std::string get_vendor() const
Definition access_point.cpp:739
uint32_t raw_packet_count() const
Definition access_point.cpp:182
int get_wifi_channel() const
Definition access_point.cpp:47
ChannelWidth
Definition access_point.h:75
void close_all_channels()
Definition access_point.cpp:68
Definition database.h:14
Decrypts unicast, multicast and broadcast WPA2 packets.
Definition decrypter.h:25
Definition access_point.cpp:22
std::string SSID
Definition decrypter.h:19
Tins::HWAddress< 6 > MACAddress
Definition decrypter.h:20
Client information.
Definition access_point.h:104
int8_t noise
Definition access_point.h:113
std::string ipv4
Definition access_point.h:107
std::string hostname
Definition access_point.h:106
int8_t snr
Definition access_point.h:114
uint32_t sent_total
Definition access_point.h:110
std::string hwaddr
Definition access_point.h:105
uint32_t received
Definition access_point.h:111
int8_t rrsi
Definition access_point.h:112
uint32_t sent_unicast
Definition access_point.h:109
std::string ipv6
Definition access_point.h:108
Connection security info of a specific client.
Definition access_point.h:120
bool is_ccmp
Definition access_point.h:122
NetworkSecurity security
Definition access_point.h:121
bool pmf
Definition access_point.h:123
std::optional< Tins::RSNInformation::CypherSuites > pairwise_cipher
Definition access_point.h:124
WiFi standard capabilities for the network.
Definition access_point.h:86
WiFiStandard std
Definition access_point.h:87
bool single_beamformer_support
Definition access_point.h:88
std::set< ChannelWidth > channel_widths_supported
Definition access_point.h:98
std::set< Modulation > modulation_supported
Definition access_point.h:93
bool single_beamformee_support
Definition access_point.h:89
std::set< uint8_t > mcs_supported_idx
Definition access_point.h:92
std::set< uint8_t > spatial_streams_supported
Definition access_point.h:95
bool multi_beamformer_support
Definition access_point.h:90
bool multi_beamformee_support
Definition access_point.h:91