2019-11-03 16:38:17 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2019-11-07 01:40:19 +01:00
|
|
|
|
using System.Threading;
|
2019-11-03 16:38:17 +01:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Toolbox.Library.Forms;
|
2019-11-07 01:40:19 +01:00
|
|
|
|
using Toolbox.Library;
|
2019-11-03 16:38:17 +01:00
|
|
|
|
|
|
|
|
|
namespace Toolbox
|
|
|
|
|
{
|
|
|
|
|
public partial class HashCalculatorForm : STForm
|
|
|
|
|
{
|
|
|
|
|
private bool IsHex => chkUseHex.Checked;
|
|
|
|
|
|
|
|
|
|
public HashCalculatorForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
hashTypeCB.Items.Add("NLG_Hash");
|
2019-11-22 03:46:51 +01:00
|
|
|
|
hashTypeCB.Items.Add("FNV64A1");
|
|
|
|
|
hashTypeCB.Items.Add("CRC32");
|
|
|
|
|
|
2019-11-03 16:38:17 +01:00
|
|
|
|
hashTypeCB.SelectedIndex = 0;
|
2019-11-07 01:40:19 +01:00
|
|
|
|
|
|
|
|
|
maxLengthUD.Value = 3;
|
2019-11-03 16:38:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stTextBox1_TextChanged(object sender, EventArgs e) {
|
|
|
|
|
UpdateHash();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateHash()
|
|
|
|
|
{
|
2019-11-22 03:46:51 +01:00
|
|
|
|
ulong Hash = CalculateHash(hashTypeCB.GetSelectedText(), stringTB.Text);
|
2019-11-03 16:38:17 +01:00
|
|
|
|
if (IsHex)
|
|
|
|
|
resultTB.Text = Hash.ToString("X");
|
|
|
|
|
else
|
|
|
|
|
resultTB.Text = Hash.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void chkUseHex_CheckedChanged(object sender, EventArgs e) {
|
|
|
|
|
UpdateHash();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 03:46:51 +01:00
|
|
|
|
public static ulong CalculateHash(string type, string text)
|
|
|
|
|
{
|
|
|
|
|
if (type == "NLG_Hash")
|
|
|
|
|
return StringToHash(text);
|
|
|
|
|
else if (type == "FNV64A1")
|
2019-11-25 23:18:15 +01:00
|
|
|
|
return FNV64A1.Calculate(text);
|
2019-11-22 03:46:51 +01:00
|
|
|
|
else if (type == "CRC32")
|
|
|
|
|
return Toolbox.Library.Security.Cryptography.Crc32.Compute(text);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-03 16:38:17 +01:00
|
|
|
|
public static uint StringToHash(string name, bool caseSensative = false)
|
|
|
|
|
{
|
|
|
|
|
//From (Works as tested comparing hashbin strings/hashes
|
|
|
|
|
//https://gist.github.com/RoadrunnerWMC/f4253ef38c8f51869674a46ee73eaa9f
|
|
|
|
|
byte[] data = Encoding.Default.GetBytes(name);
|
|
|
|
|
|
|
|
|
|
int h = -1;
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int c = (int)data[i];
|
|
|
|
|
if (caseSensative && ((c - 65) & 0xFFFFFFFF) <= 0x19)
|
|
|
|
|
c |= 0x20;
|
|
|
|
|
|
|
|
|
|
h = (int)((h * 33 + c) & 0xFFFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (uint)h;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 01:40:19 +01:00
|
|
|
|
private bool CancelOperation = false;
|
|
|
|
|
|
|
|
|
|
private bool UseSpeialcase => true;
|
2019-11-09 19:40:48 +01:00
|
|
|
|
private bool UseNumbered => chkSearchNumbered.Checked;
|
2019-11-07 01:40:19 +01:00
|
|
|
|
private bool UseLowercase => true;
|
|
|
|
|
private bool UseUppercase => searchUppercase.Checked;
|
|
|
|
|
|
|
|
|
|
private char[] SetupCharacters()
|
|
|
|
|
{
|
|
|
|
|
List<char> chars = new List<char>();
|
|
|
|
|
if (UseLowercase)
|
|
|
|
|
chars.AddRange(CharacterSetLower);
|
|
|
|
|
// if (UseUppercase)
|
|
|
|
|
// chars.AddRange(CharacterSetUpper);
|
|
|
|
|
// if (UseSpeialcase)
|
|
|
|
|
// chars.AddRange(Special);
|
|
|
|
|
return chars.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stButton1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
STProgressBar progressBar = new STProgressBar();
|
|
|
|
|
progressBar.FormClosed += OnProgressBarExist;
|
|
|
|
|
progressBar.Show();
|
|
|
|
|
progressBar.Task = $"Searching characters";
|
|
|
|
|
|
2019-11-22 03:46:51 +01:00
|
|
|
|
string hashType = hashTypeCB.GetSelectedText();
|
|
|
|
|
|
2019-11-07 01:40:19 +01:00
|
|
|
|
Thread Thread = new Thread((ThreadStart)(() =>
|
|
|
|
|
{
|
2019-11-22 03:46:51 +01:00
|
|
|
|
BruteForceHashes(progressBar, hashType);
|
2019-11-07 01:40:19 +01:00
|
|
|
|
}));
|
|
|
|
|
Thread.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 03:46:51 +01:00
|
|
|
|
private void BruteForceHashes(STProgressBar progressBar, string hashType)
|
2019-11-07 01:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
if (bruteForceHashTB.Text.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var characterSet = SetupCharacters();
|
|
|
|
|
|
|
|
|
|
CancelOperation = false;
|
|
|
|
|
|
2019-11-22 03:46:51 +01:00
|
|
|
|
List<ulong> hashes = new List<ulong>();
|
2019-11-07 01:40:19 +01:00
|
|
|
|
foreach (var line in bruteForceHashTB.Lines)
|
|
|
|
|
{
|
2019-11-22 03:46:51 +01:00
|
|
|
|
ulong hash = 0;
|
|
|
|
|
ulong.TryParse(line, out hash);
|
2019-11-07 01:40:19 +01:00
|
|
|
|
if (hash == 0) continue;
|
|
|
|
|
|
|
|
|
|
hashes.Add(hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashes.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maxLength = (int)maxLengthUD.Value;
|
|
|
|
|
|
|
|
|
|
char lastChar = 'z';
|
|
|
|
|
var firstChar = characterSet.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
int charIndex = 0;
|
|
|
|
|
bool useSpace = true;
|
|
|
|
|
for (int length = 1; length <= maxLength; ++length)
|
|
|
|
|
{
|
|
|
|
|
UpdateProgressbar(progressBar, length, maxLength);
|
|
|
|
|
|
|
|
|
|
StringBuilder Sb = new StringBuilder(new String(' ', length));
|
|
|
|
|
while (true && CancelOperation == false && hashes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
String value = Sb.ToString();
|
2019-11-09 19:40:48 +01:00
|
|
|
|
|
2019-11-22 03:46:51 +01:00
|
|
|
|
ulong calculatedHash = CalculateHash(hashType, $"{characterStartTB.Text}{value}");
|
2019-11-07 01:40:19 +01:00
|
|
|
|
if (hashes.Contains(calculatedHash))
|
|
|
|
|
{
|
2019-11-09 19:40:48 +01:00
|
|
|
|
UpdateTextbox($"{characterStartTB.Text}{value}");
|
2019-11-07 01:40:19 +01:00
|
|
|
|
hashes.Remove(calculatedHash);
|
|
|
|
|
|
|
|
|
|
if (hashes.Count == 0)
|
|
|
|
|
{
|
2019-11-07 02:06:22 +01:00
|
|
|
|
if (progressBar.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
progressBar.Invoke((MethodInvoker)delegate {
|
|
|
|
|
progressBar.Close();
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-07 01:40:19 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 19:40:48 +01:00
|
|
|
|
foreach (var line in characterStartTB.Lines)
|
|
|
|
|
{
|
2019-11-22 03:46:51 +01:00
|
|
|
|
ulong calculatedHash2 = CalculateHash(hashType, $"{line}{value}");
|
2019-11-09 19:40:48 +01:00
|
|
|
|
if (hashes.Contains(calculatedHash2))
|
|
|
|
|
{
|
|
|
|
|
UpdateTextbox($"{line}{value}");
|
|
|
|
|
hashes.Remove(calculatedHash2);
|
|
|
|
|
|
|
|
|
|
if (hashes.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
if (progressBar.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
progressBar.Invoke((MethodInvoker)delegate {
|
|
|
|
|
progressBar.Close();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 01:40:19 +01:00
|
|
|
|
if (value.All(item => item == lastChar))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Add one: aaa -> aab -> ... aaz -> aba -> ... -> zzz
|
|
|
|
|
for (int i = length - 1; i >= 0; --i)
|
|
|
|
|
if (Sb[i] == ' ')
|
2019-11-07 02:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
Sb[i] = '/';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (Sb[i] == '/')
|
2019-11-09 19:40:48 +01:00
|
|
|
|
{
|
|
|
|
|
if (UseNumbered)
|
|
|
|
|
Sb[i] = '0';
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (UseUppercase)
|
|
|
|
|
Sb[i] = 'A';
|
|
|
|
|
else
|
|
|
|
|
Sb[i] = 'a';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (Sb[i] == '0') { Sb[i] = '1'; break; }
|
|
|
|
|
else if (Sb[i] == '1') { Sb[i] = '2'; break; }
|
|
|
|
|
else if (Sb[i] == '2') { Sb[i] = '3'; break; }
|
|
|
|
|
else if (Sb[i] == '3') { Sb[i] = '4'; break; }
|
|
|
|
|
else if (Sb[i] == '4') { Sb[i] = '5'; break; }
|
|
|
|
|
else if (Sb[i] == '5') { Sb[i] = '6'; break; }
|
|
|
|
|
else if (Sb[i] == '6') { Sb[i] = '7'; break; }
|
|
|
|
|
else if (Sb[i] == '7') { Sb[i] = '8'; break; }
|
|
|
|
|
else if (Sb[i] == '8') { Sb[i] = '9'; break; }
|
|
|
|
|
else if (Sb[i] == '9')
|
2019-11-07 01:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
if (UseUppercase)
|
|
|
|
|
Sb[i] = 'A';
|
|
|
|
|
else
|
|
|
|
|
Sb[i] = 'a';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (Sb[i] == 'Z')
|
|
|
|
|
{
|
|
|
|
|
Sb[i] = 'a';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (Sb[i] != lastChar)
|
|
|
|
|
{
|
|
|
|
|
Sb[i] = (Char)(Sb[i] + 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Sb[i] = ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progressBar.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateProgressbar(STProgressBar progressBar, int length, int maxLength)
|
|
|
|
|
{
|
|
|
|
|
if (progressBar.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
progressBar.Invoke((MethodInvoker)delegate {
|
|
|
|
|
progressBar.Task = $"Searching characters {length} of max {maxLength}";
|
|
|
|
|
progressBar.Value = ((length * 100) / maxLength);
|
|
|
|
|
progressBar.Refresh();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateTextbox(string text)
|
|
|
|
|
{
|
|
|
|
|
if (bruteForceStringTB.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
bruteForceStringTB.Invoke((MethodInvoker)delegate {
|
2019-11-09 19:40:48 +01:00
|
|
|
|
if (bruteForceStringTB.Text.Length == 0)
|
|
|
|
|
bruteForceStringTB.Text = text;
|
|
|
|
|
else
|
|
|
|
|
bruteForceStringTB.AppendText("\r\n" + text);
|
2019-11-07 01:40:19 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bruteForceStringTB.AppendText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private char[] Special = new char[]
|
|
|
|
|
{ ' ', };
|
|
|
|
|
|
|
|
|
|
private char[] Digits = new char[]
|
|
|
|
|
{ '0','1','2','3','4','5','6','7','8','9' };
|
|
|
|
|
|
|
|
|
|
private char[] CharacterSetLower = new char[]
|
|
|
|
|
{ 'a','b','c','d','e','f','g','h','i','j',
|
|
|
|
|
'k','l','m','n','o','p','q','r','s',
|
|
|
|
|
't','u','v','w', 'x', 'y', 'z'};
|
|
|
|
|
|
|
|
|
|
private char[] CharacterSetUpper = new char[]
|
|
|
|
|
{ 'A','B','C','D','E','F','G','H','I','J',
|
|
|
|
|
'K','L','M','N','O','P','Q','R','S',
|
|
|
|
|
'T','U','V','W', 'X', 'Y', 'Z'};
|
|
|
|
|
|
|
|
|
|
private void OnProgressBarExist(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CancelOperation = true;
|
|
|
|
|
}
|
2019-11-22 03:46:51 +01:00
|
|
|
|
|
|
|
|
|
private void hashTypeCB_SelectedIndexChanged(object sender, EventArgs e) {
|
|
|
|
|
UpdateHash();
|
|
|
|
|
}
|
2019-11-03 16:38:17 +01:00
|
|
|
|
}
|
|
|
|
|
}
|