Yarilo  v0.9
WPA2 Decrypter & Packet Analyzer
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 namespace yarilo {
14 
18 class AccessPoint {
19 public:
24  enum class NetworkSecurity {
25  OPEN,
26  WEP,
27  WPA,
32  };
33 
37  enum class DecryptionState {
38  DECRYPTED,
42  };
43 
44  /*
45  * @brief WiFi standard that is supported by an access point, there can be
46  * many of them for a given access point
47  */
48  enum class WiFiStandard {
49  Dot11A, // Legacy standards
50  Dot11B, // Legacy standards
51  Dot11G, // Legacy standards
52  Dot11N, // Wi-Fi 4 or HT (High Throughput)
53  Dot11AC, // Wi-Fi 5 or HVT (Very High Throughput)
54  Dot11AX, // Wi-Fi 6 or HE (High Efficiency)
55  };
56 
57  /*
58  * @brief WiFi modulation type used
59  */
60  enum class Modulation {
61  CCK, // Complementary code keying (802.11b)
62  BPSK, // Binary phase shift keying
63  QPSK, // Quadrature phase shift keying
64  QAM16, // Quadrature amplitude modulation
65  QAM64,
66  QAM256,
67  QAM1024,
68  };
69 
70  /*
71  * @brief WiFi channel width used
72  */
73  enum class ChannelWidth {
74  CHAN20,
75  CHAN40,
76  CHAN80,
77  CHAN80_80,
78  CHAN160,
79  };
80 
90  std::set<uint8_t> mcs_supported_idx; // Indices of MCS
91  std::set<Modulation> modulation_supported;
92  std::set<uint8_t>
93  spatial_streams_supported; // Spatial stream configurations for MIMO,
94  // for example 3 means that the network
95  // supports 3 spatial streams, or 3x3
96  std::set<ChannelWidth> channel_widths_supported;
97  };
98 
102  struct client_info {
103  std::string hwaddr;
104  std::string hostname;
105  std::string ipv4;
106  std::string ipv6;
107  uint32_t sent_unicast;
108  uint32_t sent_total;
109  uint32_t received;
110  int8_t rrsi;
111  int8_t noise;
112  int8_t snr;
113  };
114 
120  bool is_ccmp = false;
121  bool pmf = false;
122  std::optional<Tins::RSNInformation::CypherSuites> pairwise_cipher;
123  };
124 
131  AccessPoint(const MACAddress &bssid, const SSID &ssid, int wifi_channel);
132 
138  bool handle_pkt(Tins::Packet *pkt);
139 
147  DecryptionState add_password(const std::string &psk);
148 
153  SSID get_ssid() const;
154 
159  MACAddress get_bssid() const;
160 
165  int get_wifi_channel() const;
166 
171  std::vector<wifi_standard_info> standards_supported() const;
172 
176  std::shared_ptr<PacketChannel> get_decrypted_channel();
177 
181  void close_all_channels();
182 
191  bool send_deauth(const Tins::NetworkInterface &iface, const MACAddress &addr);
192 
198  bool has_working_password() const;
199 
204  std::vector<NetworkSecurity> security_supported() const;
205 
210  bool unicast_decryption_supported() const;
211 
216  bool group_decryption_supported() const;
217 
222  bool client_decryption_supported(const MACAddress &client);
223 
224  /*
225  * Get if the network can protect its management frames
226  * @return True if 802.11w is in place
227  */
228  bool protected_management_supported() const;
229 
230  /*
231  * Get if the network must protect its management frames
232  * @return True if 802.11w is in place
233  */
234  bool protected_management_required() const;
235 
236  /*
237  * Get if the network protects its management frames for a specific client
238  * @return True if 802.11w is enforced for a client
239  */
240  bool protected_management(const MACAddress &client);
241 
247 
252  const std::set<MACAddress> get_clients() {
253  std::set<MACAddress> result;
254  for (const auto &[addr, _] : clients)
255  result.insert(addr);
256  return result;
257  }
258 
263  const std::optional<client_info> get_client(MACAddress addr) {
264  if (!clients.count(addr))
265  return std::nullopt;
266  return clients[addr];
267  }
268 
273  const std::optional<client_security> get_client_security(MACAddress addr) {
274  if (!clients_security.count(addr))
275  return std::nullopt;
276  return clients_security[addr];
277  }
278 
283  uint32_t raw_packet_count() const;
284 
289  uint32_t decrypted_packet_count() const;
290 
298  std::optional<Recording::info>
299  save_traffic(const std::filesystem::path &save_path, const std::string &name);
300 
307  std::optional<Recording::info>
308  save_decrypted_traffic(const std::filesystem::path &save_path,
309  const std::string &name);
310 
311 private:
316  bool handle_data(Tins::Packet *pkt);
317 
322  bool handle_management(Tins::Packet *pkt);
323 
329  void update_client_metadata(const Tins::Packet &pkt);
330 
335  std::vector<NetworkSecurity>
336  detect_security_modes(const Tins::Dot11ManagementFrame &mgmt) const;
337 
342  std::vector<wifi_standard_info>
343  detect_wifi_capabilities(const Tins::Dot11ManagementFrame &mgmt) const;
344 
350  bool check_pmf_capable(const Tins::Dot11ManagementFrame &mgmt) const;
351 
357  bool check_pmf_required(const Tins::Dot11ManagementFrame &mgmt) const;
358 
363  bool is_ccmp(const Tins::Dot11ManagementFrame &mgmt) const;
364 
365  uint32_t count = 0;
366  uint32_t decrypted_pkt_count = 0;
367  std::shared_ptr<spdlog::logger> logger;
368  const SSID ssid;
369  const MACAddress bssid;
370  int wifi_channel = 0;
371  std::vector<Tins::Packet *> captured_packets;
372  WPA2Decrypter decrypter;
373  std::vector<std::shared_ptr<PacketChannel>> converted_channels;
374  std::vector<wifi_standard_info> wifi_stds_supported;
375 
376  // Used for deauth, we need to "copy" the behaviour of the radiotap layer
377  uint8_t radio_length = 0;
378  uint8_t radio_channel_freq = 0;
379  uint8_t radio_channel_type = 0;
380  uint8_t radio_antenna = 0;
381 
382  bool capabilities_detected = false;
383  std::vector<NetworkSecurity> security_modes;
384  bool pmf_supported = false; // 802.11w
385  bool pmf_required = false; // 802.11w
386  bool uses_ccmp = false;
387  std::unordered_map<MACAddress, client_info> clients;
388  std::unordered_map<MACAddress, client_security> clients_security;
389 };
390 
391 } // namespace yarilo
392 
393 #endif // SNIFF_AP
Access Point in a basic service set (BSS) network.
Definition: access_point.h:18
NetworkSecurity
Network security protocol used. A network can support multiple ways to connect and secure data.
Definition: access_point.h:24
std::optional< Recording::info > save_decrypted_traffic(const std::filesystem::path &save_path, const std::string &name)
Definition: access_point.cpp:202
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_info > get_client(MACAddress addr)
Definition: access_point.h:263
uint32_t decrypted_packet_count() const
Definition: access_point.cpp:186
bool unicast_decryption_supported() const
Definition: access_point.cpp:146
bool handle_pkt(Tins::Packet *pkt)
Definition: access_point.cpp:33
DecryptionState
Current state of decryption.
Definition: access_point.h:37
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
WiFiStandard
Definition: access_point.h:48
WPA2Decrypter & get_decrypter()
Definition: access_point.cpp:180
Modulation
Definition: access_point.h:60
bool group_decryption_supported() const
Definition: access_point.cpp:151
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
const std::optional< client_security > get_client_security(MACAddress addr)
Definition: access_point.h:273
uint32_t raw_packet_count() const
Definition: access_point.cpp:182
int get_wifi_channel() const
Definition: access_point.cpp:47
AccessPoint(const MACAddress &bssid, const SSID &ssid, int wifi_channel)
Definition: access_point.cpp:24
ChannelWidth
Definition: access_point.h:73
const std::set< MACAddress > get_clients()
Definition: access_point.h:252
void close_all_channels()
Definition: access_point.cpp:68
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:102
int8_t noise
Definition: access_point.h:111
std::string ipv4
Definition: access_point.h:105
std::string hostname
Definition: access_point.h:104
int8_t snr
Definition: access_point.h:112
uint32_t sent_total
Definition: access_point.h:108
std::string hwaddr
Definition: access_point.h:103
uint32_t received
Definition: access_point.h:109
int8_t rrsi
Definition: access_point.h:110
uint32_t sent_unicast
Definition: access_point.h:107
std::string ipv6
Definition: access_point.h:106
Connection security info of a specific client.
Definition: access_point.h:118
bool is_ccmp
Definition: access_point.h:120
NetworkSecurity security
Definition: access_point.h:119
bool pmf
Definition: access_point.h:121
std::optional< Tins::RSNInformation::CypherSuites > pairwise_cipher
Definition: access_point.h:122
WiFi standard capabilities for the network.
Definition: access_point.h:84
WiFiStandard std
Definition: access_point.h:85
bool single_beamformer_support
Definition: access_point.h:86
std::set< ChannelWidth > channel_widths_supported
Definition: access_point.h:96
std::set< Modulation > modulation_supported
Definition: access_point.h:91
bool single_beamformee_support
Definition: access_point.h:87
std::set< uint8_t > mcs_supported_idx
Definition: access_point.h:90
std::set< uint8_t > spatial_streams_supported
Definition: access_point.h:93
bool multi_beamformer_support
Definition: access_point.h:88
bool multi_beamformee_support
Definition: access_point.h:89