-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
215 lines (205 loc) · 8.75 KB
/
Program.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
214
215
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace OS_Practice_2
{
/// <summary>
/// Class for thread. Thread for guess. Guess for fun
/// </summary>
class OS_Thread
{
readonly Thread thread;
public static readonly List<string> OS_PASSWORDS = new List<string>();
readonly int OS_ThreadNumber;
readonly int OS_ThreadCount;
static int OS_ThreadRemaining;
static bool OS_Cancel;
static DateTime startBruteforce = DateTime.Parse("01.01.2001 00:00");
static DateTime endBruteforce;
/// <summary>
/// This constructor creates new thread and runs it
/// </summary>
/// <param name="hash">What hash do you want to bruteforce</param>
/// <param name="threadNum">Number of current thread</param>
/// <param name="threads">Count of threads for one bruteforcing</param>
public OS_Thread(string hash, int threadNum, int threads)
{
thread = new Thread(this.OS_Bruteforce);
OS_ThreadNumber = threadNum;
OS_ThreadCount = OS_ThreadRemaining = threads;
OS_Cancel = false;
thread.Start(hash);
}
/// <summary>
/// This function HACKS your password!!!
/// </summary>
/// <param name="num">Hash to bruteforce</param>
public void OS_Bruteforce(object num)
{
if (startBruteforce == DateTime.Parse("01.01.2001 00:00"))
startBruteforce = DateTime.Now;
string OS_Current_Hash = num.ToString();
int OS_Start = 11881376 / OS_ThreadCount * OS_ThreadNumber;
int OS_Limit = 11881376 / OS_ThreadCount * (OS_ThreadNumber + 1);
if (OS_Limit > 11881376) OS_Limit = 11881376;
var crypt = new System.Security.Cryptography.SHA256Managed();
for (int OS_Counter = OS_Start; OS_Counter <= OS_Limit; OS_Counter++)
{
if (OS_Cancel) return;
string password = OS_PASSWORDS[OS_Counter];
//Раскомментируйте строчку ниже, чтобы видеть ход брутфорса
//Console.WriteLine("Поток [" + OS_ThreadNumber.ToString() + "]: пароль " + password);
var hash = new System.Text.StringBuilder();
byte[] crypto = crypt.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
if (hash.ToString() == OS_Current_Hash)
{
endBruteforce = DateTime.Now;
Console.WriteLine("\n\n Password found > " + password);
Console.WriteLine(" Time required > " + endBruteforce.Subtract(startBruteforce).ToString());
Console.WriteLine(" Press any key to return to the menu");
OS_Cancel = true;
startBruteforce = DateTime.Parse("01.01.2001 00:00");
return;
}
}
if (--OS_ThreadRemaining <= 0)
{
endBruteforce = DateTime.Now;
Console.WriteLine("\n\n Password not found :( ");
Console.WriteLine(" Time passed > " + endBruteforce.Subtract(startBruteforce).ToString());
Console.WriteLine(" Press any key to return to the menu");
OS_Cancel = true;
startBruteforce = DateTime.Parse("01.01.2001 00:00");
return;
}
}
}
class Program
{
/// <summary>
/// This function converts string to its SHA-256 hash
/// </summary>
/// <param name="hashString">Password to hash</param>
/// <returns>Hash</returns>
static string OS_ComputeHash(string hashString)
{
var crypt = new System.Security.Cryptography.SHA256Managed();
var hash = new System.Text.StringBuilder();
byte[] crypto = crypt.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hashString));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
return hash.ToString();
}
/// <summary>
/// This function makes a list with all possible 5-letters passwords
/// </summary>
static void OS_ComputePasswords()
{
Console.WriteLine(" Please wait... Program will start soon");
for (char a = 'a'; a <= 'z'; a++)
for (char b = 'a'; b <= 'z'; b++)
for (char c = 'a'; c <= 'z'; c++)
for (char d = 'a'; d <= 'z'; d++)
for (char e = 'a'; e <= 'z'; e++)
OS_Thread.OS_PASSWORDS.Add(a.ToString() + b.ToString() + c.ToString() + d.ToString() + e.ToString());
}
/// <summary>
/// This function requests hash to bruteforce
/// </summary>
/// <returns>Hash from user</returns>
static string OS_HashToBruteforce()
{
Console.Clear();
Console.WriteLine("\n\n This program guesses the password that matches the hash value");
Console.WriteLine(" What hash do you want to bruteforce?\n");
Console.WriteLine(" [1]: 1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad");
Console.WriteLine(" [2]: 3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b");
Console.WriteLine(" [3]: 74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f");
Console.WriteLine(" [4]: Your (from file)");
Console.WriteLine(" [5]: Your (from keyboard)");
Console.WriteLine("\n [6]: (dev) Password to hash");
Console.Write(" [7]: Exit\n\n > ");
string r = Console.ReadLine();
if (r == "1")
return "1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad";
if (r == "2")
return "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b";
if (r == "3")
return "74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f";
if (r == "4")
{
Console.Write(" Enter file path > ");
string OS_Path = Console.ReadLine();
FileStream file = new FileStream(OS_Path, FileMode.OpenOrCreate);
byte[] array = new byte[file.Length];
file.Read(array, 0, array.Length);
string textFromFile = System.Text.ASCIIEncoding.ASCII.GetString(array);
Console.WriteLine(" hash > " + textFromFile);
return textFromFile;
}
if (r == "5")
{
Console.Write(" Enter hash > ");
return Console.ReadLine();
}
if (r == "6")
{
Console.Write(" Enter string (exactly 5 letters) > ");
Console.WriteLine(OS_ComputeHash(Console.ReadLine()));
return OS_ComputeHash(Console.ReadLine());
}
return "";
}
/// <summary>
/// This function requests number of threads that need to use
/// </summary>
/// <returns>Number of threads</returns>
static int OS_Threads()
{
_OS_incorrect_input_threads:
Console.Write("\n How many threads do you want to use?\n > ");
int x;
try
{
x = Int32.Parse(Console.ReadLine());
if (x < 1) throw new Exception();
}
catch
{
goto _OS_incorrect_input_threads;
}
return x;
}
/// <summary>
/// This function creates threads for guessing your password
/// </summary>
/// <param name="hash">Hash to guess</param>
/// <param name="threads">Number of threads</param>
static void OS_Bruteforce(string hash, int threads)
{
List<OS_Thread> myThread = new List<OS_Thread>();
for (int i = 0; i < threads; i++)
myThread.Add(new OS_Thread(hash, i, threads));
Console.WriteLine("\n Password bruteforcing is in progress...");
}
static void Main()
{
OS_ComputePasswords();
_OS_start:
string OS_Hash = OS_HashToBruteforce();
if (OS_Hash == "") return;
int OS_ThreadsNumber = OS_Threads();
OS_Bruteforce(OS_Hash, OS_ThreadsNumber);
Console.ReadKey();
goto _OS_start;
}
}
}