Login Register






Handling huge wordlists filter_list
Author
Message
RE: Handling huge wordlists #11
This depends specifically on what you are doing. We would have to see your code. All the loading should be done on a main thread, and the chunks passed off to separate threads to take action, which callback to something else to determine whether all other threads can stop (because you found the one that worked).
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Handling huge wordlists #12
Ignore the GOTOs and the use of controls in different threads without delegates, it's an old code.

Code:
Imports System.Text Imports System.Security.Cryptography Public Class frmMain Public Enum Hash MD5 SHA1 End Enum Dim col As New System.Collections.Generic.Queue(Of String) Dim curTotal, realTotal As Integer Dim StartCount As Boolean Dim strCurWord As String = "" Dim bmp As Bitmap Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cHash.Text = cHash.Items(0).ToString CheckForIllegalCrossThreadCalls = False bmp = New Bitmap(toolProgress.Width, toolProgress.Height) End Sub Private Sub btnHash_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnHash.Click txtHash.Text = GetHash(txtInput.Text, CType(cHash.SelectedIndex, Hash)) End Sub Private Function GetHash(ByVal strToHash As String, ByVal TheHash As Hash) As String Dim array As Byte() = Encoding.ASCII.GetBytes(strToHash) If TheHash = Hash.SHA1 Then Dim sHA1CryptoServiceProvider As New SHA1CryptoServiceProvider() array = sHA1CryptoServiceProvider.ComputeHash(array) Else Dim mD5CryptoServiceProvider As New MD5CryptoServiceProvider() array = mD5CryptoServiceProvider.ComputeHash(array) End If Dim stringBuilder As New StringBuilder() Dim array2 As Byte() = array For i As Integer = 0 To array2.Length - 1 Dim b As Byte = array2(i) stringBuilder.Append(b.ToString("x2")) Next Return stringBuilder.ToString() End Function Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLoad.Click Dim openDialog As New OpenFileDialog() openDialog.Filter = "Text Document|*.txt|All Files (*.*)|*.*" If openDialog.ShowDialog = DialogResult.OK Then btnLoad.Tag = openDialog.FileName Dim loadThread As New Threading.Thread(AddressOf loadWords) loadThread.IsBackground = True loadThread.Start() 'btnBrute.Visible = True 'btnBrute.Text = "Stop" 'btnBrute.PerformClick() End If End Sub Private Sub loadWords() Try Dim ArrBrute As String() = IO.File.ReadAllLines(btnLoad.Tag.ToString) For intI As Integer = 0 To ArrBrute.GetUpperBound(0) - 1 col.Enqueue(ArrBrute(intI)) Next ArrBrute = Nothing toolWordCount.Text = col.Count.ToString & " words Loaded" btnBrute.Enabled = If(col.Count > 0, True, False) Catch ex As Exception Debug.Print("Count - " & ex.Message) End Try End Sub Private Sub btnBrute_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBrute.Click If cHash.Text = "MD5" Then If txtHash.TextLength <> 32 Then txtHash.Text = "Invalid MD5 hash" Exit Sub End If Else If txtHash.TextLength <> 40 Then txtHash.Text = "Invalid SHA1 hash" Exit Sub End If End If If btnBrute.Text <> "Stop" Then txtResult.Visible = True 'btnLoad.Enabled = False 'btnHash.Enabled = False 'numThreads.Enabled = False toolStatus.Text = "Trying" curTotal = col.Count realTotal = col.Count StartCount = True Dim t As New Threading.Thread(AddressOf CountWPS) t.Start() For intT As Integer = 0 To CInt(numThreads.Value) - 1 Dim thread As New Threading.Thread(AddressOf Brute) thread.Start(If(txtHash.TextLength = 32, Hash.MD5, Hash.SHA1)) Next btnBrute.Text = "Stop" Else StartCount = False btnBrute.Text = "Start" 'btnLoad.Enabled = True 'btnHash.Enabled = True 'numThreads.Enabled = True toolWordCount.Text = "" txtResult.Visible = False End If End Sub Public Sub Brute(ByVal theHash As Hash) Try Do While col.Count > 0 strCurWord = col.Dequeue If GetHash(strCurWord, theHash) = txtHash.Text Then toolStatus.Text = "Match found!" txtResult.Text = strCurWord GoTo ExitThis Else If btnBrute.Text = "Start" Then toolStatus.Text = "Cancelled by the user" GoTo ExitThis End If End If Loop If col.Count = 0 Then toolStatus.Text = "Hash could not be decoded" ExitThis: btnBrute.Text = "Start" txtResult.Visible = False toolWordCount.Text = "" curTotal = 0 toolProgress.Tag = 0 Catch ex As Exception Debug.Print("Brute - " & ex.Message) End Try End Sub Private Sub DownloadProgress(ByVal aControl As ToolStripStatusLabel, ByVal Value As Integer, ByVal Max As Integer, _ ByVal Color1 As Color, ByVal Color2 As Color, ByVal Color3 As Color, ByVal Color4 As Color, _ Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical) Dim widthVal As Integer = CInt((aControl.Width / Max) * Value) bmp = New Bitmap(aControl.Width, 15) Dim g As Graphics = Graphics.FromImage(bmp) Dim Rect1 As New RectangleF(0, 0, widthVal, bmp.Height) Dim Rect2 As New RectangleF(widthVal, 0, aControl.Width, bmp.Height) Dim lineGBrush2 As New System.Drawing.Drawing2D.LinearGradientBrush(Rect2, Color3, Color4, mode) g.FillRectangle(lineGBrush2, New RectangleF(0, 0, aControl.Width, bmp.Height)) g.DrawRectangle(Pens.White, New Rectangle(1, 1, aControl.Width - 3, bmp.Height - 3)) If Value > 0 Then Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(200, Color1), Color.FromArgb(200, Color2), mode) g.FillRectangle(lineGBrush, New RectangleF(0, 0, widthVal, bmp.Height)) lineGBrush = New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(Color2.R, Color2.G - 100, Color2.B), Color.FromArgb(Color1.R - 80, Color1.G - 80, Color1.B), mode) g.FillRectangle(lineGBrush, New RectangleF(0, bmp.Height / 2, widthVal, bmp.Height / 2)) lineGBrush = New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(100, Color2), Color.FromArgb(100, Color1), Drawing2D.LinearGradientMode.Horizontal) g.FillRectangle(lineGBrush, New RectangleF(0, 0, widthVal, bmp.Height)) g.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(100, Color1.R - 120, Color1.G - 80, Color1.B - 40))), New Rectangle(1, 1, widthVal - 2, bmp.Height - 3)) End If g.DrawRectangle(Pens.DarkGray, New Rectangle(0, 0, aControl.Width - 1, bmp.Height - 1)) bmp.SetPixel(0, 0, Color.Transparent) bmp.SetPixel(0, bmp.Height - 1, Color.Transparent) bmp.SetPixel(bmp.Width - 1, 0, Color.Transparent) bmp.SetPixel(bmp.Width - 1, bmp.Height - 1, Color.Transparent) aControl.Image = bmp g.Dispose() End Sub Private Sub SeekFromFile(ByVal filename As String) Using reader As New IO.StreamReader(filename) Const blockSize As Integer = 10000000 Dim buffer(blockSize - 1) As Char Dim charCount As Integer Dim builder As New System.Text.StringBuilder Do Until reader.EndOfStream 'Read the next 1,000,000 characters of the file. charCount = reader.ReadBlock(buffer, 0, blockSize) builder.Clear() builder.Append(buffer, 0, charCount) If charCount = blockSize Then 'Read up to the next line break and append to the block just read. builder.Append(reader.ReadLine()) End If col.Enqueue(builder.ToString()) realTotal = col.Count btnBrute.Enabled = If(col.Count > 0, True, False) Loop End Using End Sub Private Sub CountWPS() Try Do While StartCount = True Threading.Thread.Sleep(1000) Dim intDiff As Integer = curTotal - col.Count toolWordCount.Tag = Math.Round(((realTotal - curTotal) * 100) / realTotal, 2).ToString toolWordCount.Text = intDiff.ToString & " wps (" & toolWordCount.Tag.ToString & "%)" If Me.WindowState = FormWindowState.Normal Then DownloadProgress(toolProgress, CInt(toolWordCount.Tag), 100, Color.Aquamarine, Color.CadetBlue, Color.AliceBlue, Color.LightGray) lblRemaining.Text = "Time remaining: " & TimeSpan.FromSeconds(CDbl(CInt(realTotal / intDiff) * 60)).ToString txtResult.Text = strCurWord curTotal = col.Count If StartCount = False Then Exit Do Loop ExitThis: toolWordCount.Text = "" toolProgress.Visible = False Catch ex As Exception Debug.Print("CountWPS - " & ex.Message) End Try End Sub Private Sub lblSite_Click(ByVal sender As Object, ByVal e As EventArgs) Process.Start(toolSite.Tag.ToString) End Sub Private Sub txtHash_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHash.TextChanged btnLoad.Enabled = If(txtHash.TextLength = 0, False, True) End Sub Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing StartCount = False btnBrute.Text = "Start" txtResult.Visible = False End Sub End Class
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: Handling huge wordlists #13
There's lots of things bad about that code other than just the things you've mentioned though... That entire thing I would just rewrite.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply