dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Brute force password cracker.

  1. #1
    Join Date
    Feb 2018
    Posts
    4

    Brute force password cracker.

    Hi
    I am currently building a brute force password cracker, currently I have a program that allows the user to enter a password (Only in lowercase) and the program will run through all possible options for this password, for example a password of 5 characters is entered it will start with (aaaaa) then (aaaab) then (aaaac) and the so. However, I currently unsure of how to incorporate uppercase characters and special characters into this process so the user can enter a password with all 3 of these and the program will attempt to solve it.

    Here is the code i currently have
    Code:
    #include "stdafx.h" 
    #include <iostream> 
    #include <limits>  
    using namespace std;
    # include "string"  
    
    int main()
    {
    	string password;
    	string programPass;
    
    	cout << "Please enter a password to test" << endl;
    	cin >> password;
    
    	char lowerDigitArray[] = { 'a' - 1,'a','a','a','a','a','a','a','a','a' };
    
    	while (password.compare(programPass) != 0) {
    
    		lowerDigitArray[0]++;
    		for (int x = 0; x <password.length(); x++) {   
    			if (lowerDigitArray[x] == 'z' + 1)
    			{
    				lowerDigitArray[x] = 'a';
    				lowerDigitArray[x + 1]++;
    			}
    		}   
    
    		// creating the string with those digits
    		programPass = lowerDigitArray[password.length() - 1]; // i set the first one here
    
    		for (int i = password.length() - 2; i >= 0; i--)
    			programPass += lowerDigitArray[i]; // now i add other digits to next to first digit
    
    		cout << programPass << endl; // i put it to test how it looks
    
    	}
    
    	cout << "This is your password " << programPass << endl; // gives the result 
    	return 0;
    }
    Thanks for any help you offer.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,410

    Re: Brute force password cracker.

    Based upon your algorithm one extension to cater for any required chars is to have a string of these and then to make lowerDigitArray into an array of indexes into the string. The idea is something like this

    Code:
    const char allowchars[] = "abcdABCD!$0123";
    ...
    int charIndex[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    So the elements of charIndex are indexes into allowchars. So in this exmaple, 0 would be a, 4 would be A etc. So the lowest valid value would be 0 (for a) and the highest valid value would be (sizeof(allowchars) / sizeof(allowchars[0]) - 1) (calculate once after allowchars has been defined). With a few minor changes the algorithm would be the same.
    Last edited by 2kaud; February 21st, 2018 at 12:45 PM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.4)

  3. #3
    Join Date
    Feb 2018
    Posts
    4

    Re: Brute force password cracker.

    Hi, thanks for your reply I'm not sure I completely understand what you mean,

    Code:
    const char allowchars[] = "abcdABCD!$0123";
    Are you suggesting that this line of code replace my current lowerdigitalarray.

    Also for the second line of code you suggested would this function in the same way where it begins at lowercase and through the while loop, I have added 1 each loop so it goes to b then c and so on.

    Cheers

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,410

    Re: Brute force password cracker.

    Code:
    const char allowchars[] = "abcdABCD!$0123";
    const size_t allowSize = sizeof(allowchars) / sizeof(allowchars[0]);

    allowchars contains the characters you want allowed. The index starts at 0 and ends at allowSize - 1.

    In your code in post #1, the array lowerDigitArray contains chars representing the password to try. Each element is incremented by 1 (to get b, c, d etc) . Once it reaches after z it is reset to a and the next element is then incremented. This is fine if the required chars are sequential (like all the lower case chars etc). But for the set of chars you want they are not. So instead of having an array that contains the chars, you have an array that contains indexes into allowchars. So the first element starts at 0 (for a), then is incremented which would be b etc. In the example 14 would be 3. When the value exceeds allowSize it is reset to 0 and the next element in the array is incremented as in your original code.

    Code:
    for (int i = password.length() - 2; i >= 0; i--)
    			programPass += lowerDigitArray[i]; // now i add other digits to next to first digi
    would become
    Code:
    for (int i = password.length() - 2; i >= 0; i--)
    			programPass += allowchars[DigitArray[i]]; // now i add other digits to next to first digi
    where DigitArray is the array of indexes into allowchars.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.4)

  5. #5
    Join Date
    Feb 2018
    Posts
    4

    Re: Brute force password cracker.

    Hi

    thanks for your help so far, I have implemented the changes you suggested and it works great, however, is their a possibility of specifying the symbols inside that array the list preferably would just be limited to this list (" !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~?)

    However its incorporated symbols such as these and other like smiley and angry face which wouldn't really be used in this program https://imgur.com/a/edt8T, so would it be possible to just specify the symbol list shown above.

    Thanks
    Last edited by Alex1598540; February 21st, 2018 at 01:21 PM.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,521

    Re: Brute force password cracker.

    Are you sure you want to help somebody with no history here write a password cracker?

  7. #7
    Join Date
    Feb 2018
    Posts
    4

    Re: Brute force password cracker.

    Hi

    It's not for nefarious purposes its a college project my tutor suggested as I'm interested in this area of computing.

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,410

    Re: Brute force password cracker.

    Quote Originally Posted by Alex1598540 View Post
    Hi

    thanks for your help so far, I have implemented the changes you suggested and it works great, however, is their a possibility of specifying the symbols inside that array the list preferably would just be limited to this list (" !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~?)

    However its incorporated symbols such as these and other like smiley and angry face which wouldn't really be used in this program https://imgur.com/a/edt8T, so would it be possible to just specify the symbol list shown above.

    Thanks
    allowchars can contain any symbol that can be represented as a type char (8 bits in this case). If you want to include a non-printable char, then just use its ascii code instead.

    eg

    Code:
    const char allowchars[] = {250, 251, 252, 4, 6, 8, 'a', 'b', 'A', 'Z', '0'};
    But then you have the issue of input....

    PS If you want non-ascii chars then allowchars could be of type wchar_t (16 bits) to enable UCS2 chars to be used (see https://en.wikipedia.org/wiki/C_string_handling#wchar_t https://en.wikipedia.org/wiki/Univer..._Character_Set)
    Last edited by 2kaud; February 22nd, 2018 at 10:39 AM. Reason: PS
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.4)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)