Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
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
17namespace yarilo {
18
19typedef std::string SSID;
20typedef Tins::HWAddress<6> MACAddress;
21
26public:
27 typedef std::vector<uint8_t> ptk_type;
28 typedef std::vector<uint8_t> gtk_type;
29
36 Tins::Timestamp start;
37 Tins::Timestamp end;
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 {
51 Tins::Timestamp start;
52 Tins::Timestamp end;
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>
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
137 uint32_t count_all_group_windows() const;
138
147 std::optional<std::string> extract_hc22000(const client_window &client);
148
153 static std::string readable_hex(const std::vector<uint8_t> &vec);
154
155private:
162 bool decrypt_unicast(Tins::Packet *pkt, const MACAddress &client);
163
170 bool handle_pairwise_eapol(Tins::Packet *pkt, const MACAddress &client);
171
178 bool handle_group_eapol(Tins::Packet *pkt, const MACAddress &client);
179
187 void try_generate_keys(client_window &window);
188
194 bool decrypt_group(Tins::Packet *pkt);
195
202 void try_insert_gtk(const gtk_type &gtk, const Tins::Timestamp &ts);
203
211 Tins::SNAP *decrypt_group_data(const Tins::Dot11Data &data, Tins::RawPDU &raw,
212 const gtk_type &gtk) const;
213
222 std::optional<gtk_type> exctract_key_data(const Tins::RSNEAPOL &eapol,
223 const ptk_type &ptk) const;
224
230 static std::optional<uint8_t>
231 eapol_pairwise_hs_num(const Tins::RSNEAPOL &eapol);
232
238 static std::optional<uint8_t> eapol_group_hs_num(const Tins::RSNEAPOL &eapol);
239
240 std::shared_ptr<spdlog::logger> logger;
241 std::unordered_map<MACAddress, Tins::Packet *> group_rekey_first_messages;
242 std::unordered_map<MACAddress, std::vector<Tins::Packet *>> client_handshakes;
243 const SSID ssid;
244 const MACAddress bssid;
245 std::string psk = "";
246 bool working_psk = false;
247 std::unordered_map<MACAddress, std::vector<client_window>> client_windows;
248 std::vector<group_window> group_windows;
249 Tins::Crypto::WPA2Decrypter unicast_decrypter;
250};
251
252} // namespace yarilo
253
254#endif // SNIFF_DECRYPTER
Decrypts unicast, multicast and broadcast WPA2 packets.
Definition decrypter.h:25
WPA2Decrypter(const MACAddress &bssid, const SSID &ssid)
Definition decrypter.cpp:16
void add_password(const std::string &psk)
Definition decrypter.cpp:52
std::optional< std::string > extract_hc22000(const client_window &client)
Definition decrypter.cpp:110
std::optional< std::string > get_password() const
Definition decrypter.cpp:70
bool can_generate_keys() const
Definition decrypter.cpp:43
std::optional< std::vector< client_window > > get_all_client_windows(const MACAddress &client)
Definition decrypter.cpp:91
std::vector< uint8_t > gtk_type
Definition decrypter.h:28
group_window get_current_group_window() const
Definition decrypter.cpp:97
bool decrypt(Tins::Packet *pkt)
Definition decrypter.cpp:21
std::vector< group_window > get_all_group_windows() const
Definition decrypter.cpp:101
uint32_t count_all_group_windows() const
Definition decrypter.cpp:105
bool has_working_password() const
Definition decrypter.cpp:68
static std::string readable_hex(const std::vector< uint8_t > &vec)
Definition decrypter.cpp:179
std::vector< uint8_t > ptk_type
Definition decrypter.h:27
std::set< MACAddress > get_clients() const
Definition decrypter.cpp:76
std::optional< client_window > get_current_client_window(const MACAddress &client)
Definition decrypter.cpp:84
Definition access_point.cpp:22
std::string SSID
Definition decrypter.h:19
Tins::HWAddress< 6 > MACAddress
Definition decrypter.h:20
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