Friday, January 11, 2013

Crack Word Password With Brute-Force

In the previous posts I explained basics about including Word in C#, about a method to automatically check password of a word document as well as a password generator.
Today now I want to combine these things and present a program, which finds out passwords of Word documents by checking all pssoibilites.
The passwords are created with the password generator and the program then tries to open the document with these passwords.
The code should be self explaining in connection with the previous posts.
I admit, the program is pretty slow, who knows tricks to improve the performance is welcome!


            Object oMissing = System.Reflection.Missing.Value;

            bool Found = false;

            PasswordGenerator Generator = new PasswordGenerator(true, true, true, 1, 2);
            Thread.Sleep(1000);
            string pw = Generator.Dequeue();

            Word.Application WordApp = new Word.Application();
            Word.Document ExistingDocument;

            while (pw != "" && !Found)
            {
                try
                {
                    ExistingDocument = WordApp.Documents.Open(Dateiname, oMissing, false, oMissing, pw);
                    Found = true;
                    WordApp.Quit();
                    MessageBox.Show("The password is: " + pw);
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                }
                pw = Generator.Dequeue();
            }

            if (!Found)
                MessageBox.Show("No matching password found.");
        }