Yarilo  v0.9
WPA2 Decrypter & Packet Analyzer
decrypter.h
Go to the documentation of this file.
1 #ifndef SNIFF_DECRYPTER
2 #define SNIFF_DECRYPTER
3 
4 #include <optional>
5 #include <set>
6 #include <spdlog/logger.h>
7 #include <tins/crypto.h>
8 #include <tins/dot11.h>
9 #include <tins/eapol.h>
10 #include <tins/hw_address.h>
11 #include <tins/packet.h>
12 #include <tins/pdu.h>
13 #include <tins/snap.h>
14 #include <tins/timestamp.h>
15 #include <vector>
16 
17 namespace yarilo {
18 
19 typedef std::string SSID;
20 typedef Tins::HWAddress<6> MACAddress;
21 
26 public:
27  typedef std::vector<uint8_t> ptk_type;
28  typedef std::vector<uint8_t> gtk_type;
29 
35  struct client_window {
38  bool ended = false;
39  bool decrypted = false;
41  std::vector<Tins::Packet *> packets;
42  std::vector<Tins::Packet *> auth_packets;
44  };
45 
50  struct group_window {
53  bool ended = false;
54  bool decrypted = false;
55  std::vector<Tins::Packet *> packets;
56  std::vector<Tins::Packet *> auth_packets;
58  };
59 
65  WPA2Decrypter(const MACAddress &bssid, const SSID &ssid);
66 
72  bool decrypt(Tins::Packet *pkt);
73 
79  bool can_generate_keys() const;
80 
85  void add_password(const std::string &psk);
86 
92  bool has_working_password() const;
93 
99  std::optional<std::string> get_password() const;
100 
105  std::set<MACAddress> get_clients() const;
106 
113  std::optional<client_window>
114  get_current_client_window(const MACAddress &client);
115 
122  std::optional<std::vector<client_window>>
123  get_all_client_windows(const MACAddress &client);
124 
130 
135  std::vector<group_window> get_all_group_windows() const;
136 
145  std::optional<std::string> extract_hc22000(const client_window &client);
146 
151  static std::string readable_hex(const std::vector<uint8_t> &vec);
152 
153 private:
160  bool decrypt_unicast(Tins::Packet *pkt, const MACAddress &client);
161 
168  bool handle_pairwise_eapol(Tins::Packet *pkt, const MACAddress &client);
169 
176  bool handle_group_eapol(Tins::Packet *pkt, const MACAddress &client);
177 
185  void try_generate_keys(client_window &window);
186 
192  bool decrypt_group(Tins::Packet *pkt);
193 
200  void try_insert_gtk(const gtk_type &gtk, const Tins::Timestamp &ts);
201 
209  Tins::SNAP *decrypt_group_data(const Tins::Dot11Data &data, Tins::RawPDU &raw,
210  const gtk_type &gtk) const;
211 
220  std::optional<gtk_type> exctract_key_data(const Tins::RSNEAPOL &eapol,
221  const ptk_type &ptk) const;
222 
228  static std::optional<uint8_t>
229  eapol_pairwise_hs_num(const Tins::RSNEAPOL &eapol);
230 
236  static std::optional<uint8_t> eapol_group_hs_num(const Tins::RSNEAPOL &eapol);
237 
238  std::shared_ptr<spdlog::logger> logger;
239  std::unordered_map<MACAddress, Tins::Packet *> group_rekey_first_messages;
240  std::unordered_map<MACAddress, std::vector<Tins::Packet *>> client_handshakes;
241  const SSID ssid;
242  const MACAddress bssid;
243  std::string psk = "";
244  bool working_psk = false;
245  std::unordered_map<MACAddress, std::vector<client_window>> client_windows;
246  std::vector<group_window> group_windows;
247  Tins::Crypto::WPA2Decrypter unicast_decrypter;
248 };
249 
250 } // namespace yarilo
251 
252 #endif // SNIFF_DECRYPTER
Decrypts unicast, multicast and broadcast WPA2 packets.
Definition: decrypter.h:25
WPA2Decrypter(const MACAddress &bssid, const SSID &ssid)
Definition: decrypter.cpp:15
void add_password(const std::string &psk)
Definition: decrypter.cpp:51
std::optional< std::string > extract_hc22000(const client_window &client)
Definition: decrypter.cpp:105
std::optional< std::string > get_password() const
Definition: decrypter.cpp:69
bool can_generate_keys() const
Definition: decrypter.cpp:42
std::optional< std::vector< client_window > > get_all_client_windows(const MACAddress &client)
Definition: decrypter.cpp:90
std::vector< uint8_t > gtk_type
Definition: decrypter.h:28
group_window get_current_group_window() const
Definition: decrypter.cpp:96
bool decrypt(Tins::Packet *pkt)
Definition: decrypter.cpp:20
std::vector< group_window > get_all_group_windows() const
Definition: decrypter.cpp:100
bool has_working_password() const
Definition: decrypter.cpp:67
static std::string readable_hex(const std::vector< uint8_t > &vec)
Definition: decrypter.cpp:174
std::vector< uint8_t > ptk_type
Definition: decrypter.h:27
std::set< MACAddress > get_clients() const
Definition: decrypter.cpp:75
std::optional< client_window > get_current_client_window(const MACAddress &client)
Definition: decrypter.cpp:83
Definition: access_point.cpp:22
std::string SSID
Definition: decrypter.h:19
Tins::HWAddress< 6 > MACAddress
Definition: decrypter.h:20
google::protobuf::Timestamp Timestamp
Definition: service.cpp:33
Represents a client window for tracking packet data within an encryption window. This window is defin...
Definition: decrypter.h:35
std::vector< Tins::Packet * > auth_packets
Definition: decrypter.h:42
std::vector< Tins::Packet * > packets
Definition: decrypter.h:41
MACAddress client
Definition: decrypter.h:40
bool ended
Definition: decrypter.h:38
bool decrypted
Definition: decrypter.h:39
ptk_type ptk
Definition: decrypter.h:43
Tins::Timestamp start
Definition: decrypter.h:36
Tins::Timestamp end
Definition: decrypter.h:37
Represents a group window for tracking multicast packet data. This window is defined as the state bet...
Definition: decrypter.h:50
std::vector< Tins::Packet * > packets
Definition: decrypter.h:55
Tins::Timestamp start
Definition: decrypter.h:51
gtk_type gtk
Definition: decrypter.h:57
bool ended
Definition: decrypter.h:53
Tins::Timestamp end
Definition: decrypter.h:52
std::vector< Tins::Packet * > auth_packets
Definition: decrypter.h:56
bool decrypted
Definition: decrypter.h:54