Example #1
0
        bool Crack(string[] toCrack, int index, int length, int threads, ICheckPassword check)
        {
            if (threads <= 1)
            {
                for (int x = index, max = index + length; x < max; x++)
                {
                    string w = toCrack[x];
                    if (check.CheckPassword(w))
                    {
                        EndProgress();
                        WriteInfo("Password Found! ", w, ConsoleColor.Green);
                        Beep();

                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                bool found = false;
                CancellationTokenSource cts = new CancellationTokenSource();

                try
                {
                    // Use ParallelOptions instance to store the CancellationToken
                    ParallelOptions po = new ParallelOptions();
                    po.CancellationToken      = cts.Token;
                    po.MaxDegreeOfParallelism = threads;

                    ParallelLoopResult res = Parallel.For(index, index + length, x =>
                    {
                        string w = toCrack[x];
                        if (check.CheckPassword(w))
                        {
                            found = true;

                            EndProgress();
                            WriteInfo("Password Found! ", w, ConsoleColor.Green);
                            Beep();

                            cts.Cancel();
                            return;
                        }

                        po.CancellationToken.ThrowIfCancellationRequested();
                    });
                }
                catch { }
                finally { cts.Dispose(); }

                return(found);
            }
        }
Example #2
0
        public override bool Run()
        {
            ICheckPassword check = (ICheckPassword)this.Payload;

            if (!check.PreRun())
            {
                check.PostRun();
                return(false);
            }

            try
            {
                if (!WordListFile.Exists)
                {
                    return(false);
                }

                int  readBlock = Math.Max(1, ReadBlock);
                int  threads   = Math.Max(1, Threads);
                bool save      = SaveState;

                using (StreamReader reader = new StreamReader(WordListFile.FullName))
                {
                    string[] toCrack = new string[readBlock];
                    int      index   = 0;

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // Fill
                        toCrack[index] = line;
                        index++;

                        if (index == readBlock)
                        {
                            // Crack
                            if (Crack(toCrack, 0, index, threads, check, check.AllowMultipleOk))
                            {
                                index = 0;

                                if (!check.AllowMultipleOk)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                index = 0;
                            }
                            if (save)
                            {
                                // Write position
                            }
                        }
                    }

                    if (index != 0)
                    {
                        // Sobras
                        if (Crack(toCrack, 0, index, threads, check, check.AllowMultipleOk))
                        {
                            index = 0;
                        }
                        if (save)
                        {
                            // End
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                check.PostRun();
            }

            return(true);
        }
Example #3
0
        public override bool Run()
        {
            ICheckPassword check = (ICheckPassword)this.Payload;

            if (!check.PreRun())
            {
                check.PostRun();
                return(false);
            }

            FileStream stream   = null;
            bool       found    = false;
            string     tempFile = null;

            try
            {
                if (!WordListFile.Exists)
                {
                    return(false);
                }

                int readBlock = Math.Max(1, ReadBlock);
                int threads   = Math.Max(1, Threads);

                stream = File.OpenRead(WordListFile.FullName);

                if (FileHelper.DetectFileFormat(stream, true, true) == FileHelper.EFileFormat.Gzip)
                {
                    WriteInfo("Decompress gzip wordlist");
                    WriteInfo("Compressed size", StringHelper.Convert2KbWithBytes(stream.Length), ConsoleColor.Green);

                    stream.Close();
                    stream.Dispose();

                    using (FileStream streamR = File.OpenRead(WordListFile.FullName))
                        using (GZipStream gz = new GZipStream(streamR, CompressionMode.Decompress))
                        {
                            // decompress
                            tempFile = Path.GetTempFileName();
                            stream   = File.Open(tempFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                            gz.CopyTo(stream);
                            stream.Seek(0, SeekOrigin.Begin);
                        }

                    WriteInfo("Decompressed size", StringHelper.Convert2KbWithBytes(stream.Length), ConsoleColor.Green);
                }

                using (StreamLineReader reader = new StreamLineReader(stream))
                {
                    WriteInfo("Start counting file");
                    int hay = reader.GetCount(StartAtLine);

                    WriteInfo("Total lines", hay.ToString(), ConsoleColor.Green);
                    StartProgress(Math.Max(0, hay - StartAtLine));

                    string[] toCrack = new string[readBlock];
                    int      index   = 0;

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // Fill
                        toCrack[index] = line;
                        index++;

                        if (index == readBlock)
                        {
                            // Crack
                            if (Crack(toCrack, 0, index, threads, check))
                            {
                                index = 0;
                                found = true;
                                break;
                            }
                            else
                            {
                                index = 0;
                            }

                            if (SaveState)
                            {
                                StartAtLine = reader.CurrentLine;
                                CopyPropertiesToActiveModule("StartAtLine");
                            }
                            WriteProgress(reader.CurrentLine);
                        }
                    }

                    if (index != 0)
                    {
                        // Sobras
                        if (Crack(toCrack, 0, index, threads, check))
                        {
                            index = 0;
                            found = true;
                        }

                        if (SaveState)
                        {
                            StartAtLine = reader.CurrentLine;
                            CopyPropertiesToActiveModule("StartAtLine");
                        }
                        WriteProgress(reader.CurrentLine);
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
                if (tempFile != null)
                {
                    File.Delete(tempFile);
                }
                EndProgress();
                check.PostRun();
            }

            return(found);
        }
Example #4
0
        bool Crack(string[] toCrack, int index, int length, int threads, ICheckPassword check, bool allowMultipleOk)
        {
            bool found = false;

            CancellationTokenSource cts = new CancellationTokenSource();

            try
            {
                // Use ParallelOptions instance to store the CancellationToken
                ParallelOptions po = new ParallelOptions();
                po.CancellationToken = cts.Token;
                po.MaxDegreeOfParallelism = threads;

                ParallelLoopResult res = Parallel.For(index, index + length, x =>
                    {
                        string w = toCrack[x];
                        if (check.CheckPassword(w))
                        {
                            found = true;

                            WriteInfo("Password Found! ", w, ConsoleColor.Green);
                            Beep();

                            cts.Cancel();
                            return;
                        }

                        po.CancellationToken.ThrowIfCancellationRequested();
                    });
            }
            catch { }
            finally
            {
                cts.Dispose();
            }
            return found;
        }