Fatal1ty Posted August 23, 2006 Report Posted August 23, 2006 NOTICE: This article' s intention is not to influenceillegal activity but to educate the user of the theorybehind brute forcing.This is a very important topic. Many software tools todayutilise brute force techniques to acccomplish their task.Whether it be a portscanner, ip scanner, phreaking scanneror finally what interests us most(password cracker). Ithas many legitimate uses in society, particularly toolsinvolved in security analysis. Now before we start, thispaper is not a paper covering a huge topic so it will befairly short.Brute force is simply taken to mean to try every possiblecombination of characters or nos in use in what we aredealing with until theres no more to try. For example saywe have a secret number that has to be 2 nos. To know itwe will need to try every no from 00-99(assuming base 10)until we encounter the correct one or one of those in thecase of password cracking will be the correct password.Each digit could have anything from 0-9.An ip scanner will scan every node in a specific subnet/s.Each subnet has 255 nodes. That would be brute forcingthe subnet.Three factors influence how long it will taketo try every combination and they are:1. The number base (or char range in our ascii passwd)2. The length of the character string we are cracking3. What the minimum pass length we start at and end with.This rule applies to either remote cracking or local.Obviously cpu speed and bandwidth would account butthe above are more important and should be abided forany box fast or slow or speed of your communication.Now lets get to the point.Password cracking(brute force) is very similar to ipscanning. Except we increment the ASCII character codefor each character at some point instead of the node no.In ip scanning, you know the way when the last octet ofip has reached 255 ? That the octet next to it isincremented by 1 and last octet set to 0 again and thiscontinues on until 255 has been reached again and thewhole cycle repeats itself. Checking for 255 is thecondition used to determine when we have to reset thenode back to 1 again. Well thats similar withpassword cracking also but because its not directly noswe are dealing with it will be slightly different.As a practical example lets try and crack a 3 char pass.To start off we must set each char to an ASCII code of32(anything below this is control characters) and thenstop at 127 because this is all our byte allowsus(non extended ASCII), which is all of the possiblechars allowed on our keyboard includingmeta-symbols(special chars).for(x=0; x<=passlen-1; x++)pass[x]=32;Now that thats done. Heres an example of what the bruteforce cycle must look like. INside the brackets representour ASCII code.char 2(32) char 1(32) char 0(32) <----- first trychar 2(32) char 1(32) char 0(33) <----- second try*we will skip and assume 127 of char 0 has been reached*char 2(32) char 1(32) char 0(127) <----- 95th try^|________ Max allowed codechar 2(32) char 1(33) char 0(32) <----- 96th try^ ^| || ------- set back to 32----------- incremented by 1char 2(32) char 1(33) char 0(33) <------ 97th try^|------ incremented by 1*we will now skip and assume char 1 has reached 127*char 2(32) char 1(127) char 0(127)char 2(33) char 1(32) char 0(32)^|------------------- Notice the changeNot only have we changed position 2 but we also havereverted char 0 and 1 to code 32 again. This is howpassword cracking must be done in order to try allpossible combinations.This will keep going in these steps. Once one of thechars has reached 127 then the char next to the leftwill get incremented by one and the char before oneto left and all previous chars set back to 32 again.Now it should be plain to see that to brute force theabove with a bitta maths in order it would takeapproximatelly (127-32)^3= 884736 trys.As the string length is increased, so is how long itwill take to brute force. Can you imagine crackinga 12 char pass which would take around..(127-32)^12= 540360087662636962890625 possiblecombinationsAnd this is assuming you know the password is exactly12 chars. If you start at a minimum of 8 and try everypossible combination for each string length until 12has been reached that is:(127-32)^8+(127-32)^9+(127-32)^10+(127-32)^11+(127-32)^12Now this process is not very considerable if youintend to make a remote password cracker(but itis a realistic approach over a period of time), butif you have a local encryption string you can bruteforce it(with the speed of your own cpu cycles) ifyou know the encryption scheme being used andassuming its one way.You also have to rememeber if the password is storedin encrypted form then each combination generated inour iteration must be encrypted, tryed and checkedagainst the ciphertext to see if it matches correctpass. This is the only methodology we can make usesince all passwords used in authentication are oneway. Although i do not do this in ma example. I dohowever show how to try every possible combinationand the rules involved to achieve this.You could also reduce the time to brute it by reducingthe char range from 32 - 127 to something like a rangethat only has uppercase and lowercase letters of thealphabet but we will not go into that here. Its justa possibility.Heres the final brute force engine i wrote for thepurpose of this example.---- cut ------/*No of trys was 15264728..Time elapsed = 0.751000 secondsCPU: intel celeron 1.2ghzALso, a 5 char pass took amazingly 75 secondsNo of trys was 1355121658..Time elapsed = 75.208000 secondsTrys per second was 18018317.971492When you add the encryption algorithm the timerequired to crack should be drasticallyincreased.*/#include#include#include#include#includechar *bruteforce(int passmax, int passmin);int count=0;char *passwd;#define MAXCHAR 127#define MINCHAR 33/* this code is copyrighted by Hi_tech_assassin, see pscode.com */char *bruteforce(int passmax, int passmin){char *pass=(char*)malloc(passmin);int position,x,found;/* since we can only do one increment periteration we need a way of controling this*/memset(pass, MINCHAR, passmin);pass[passmin]=' ';for(x=passmin;x<=passmax;x++){if(x>passmin){realloc(pass, x);memset(pass, MINCHAR, x);pass[x]=' ';}while(pass[0]", argv[0]);return 0;}start = clock();passwd=argv[1];printf("Attempting to brute force "%s"",passwd);printf("Should take approximatelly around %.0f trys",pow(MAXCHAR-MINCHAR,strlen(passwd)));if(pass=bruteforce(strlen(passwd),strlen(passwd)))printf("The correct password is "%s"", pass);elseprintf("Hard luck");printf("No of trys was %d", count);end = clock();elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;printf("Time elapsed = %f seconds",elapsed);if(elapsed >= 1)printf("Trys per second was %f", count / elapsed);else printf("");return 0;}---- cut -----Should give you an idea of what we are talking about.Do remember when selecting passwords make sure theyare as long as possible. The chars should be bothuppercase and lowercase along with a few metasymbols.There is a trick actually that would make it almostimpossible to crack ANY password. Most crackers donot include chars below 32 in brute force mode. Sinceits difficult to include these at any login prompt.But by doing so you have a way of eluding most bruteforce tools today if your password has one of thesebut it is very inconvenient. Quote