#include // this program uses brute force hacking to decrypt a file // encrypted using the standard "crypt" command in UNIX. It // assumes that the key is a 4 ASCII character key which // contains only characters a to z and numbers 0 to 9. The // decrypted file is stored in temp.txt each time and if the // first 3 characters match [a-z0-9] then its stored in the // file named decryptedfile%key%.txt, where %key% is the key // used for that particular decryption. int main(int argc, char *argv[]) { if(argc!=2) { printf("Usage: BruteForceHacker encrypted_filename"); exit(1); } int i,j,k,l,w,x,y,z; int keybase[36]; // contains the characters a-z and numbers 0-9 for(i=0;i<26;i++) keybase[i] = i+97; for(i=26;i<36;i++) keybase[i] = i+22; char command[50], key[5]; // command contains the crypt command each time around // key contains the key each time around // looping which takes care of all possible combinations of characters in the keybase for(w=0;w<36;w++) for(x=0;x<36;x++) for(y=0;y<36;y++) for(z=0;z<36;z++) { key[0] = keybase[w]; key[1] = keybase[x]; key[2] = keybase[y]; key[3] = keybase[z]; key[4] = '\0'; printf("%s\n",key); sprintf(command,"crypt %s < %s > temp.txt",key,argv[1]); //printf("%s\n",command); system(command); // the decrypted characters are placed in temp.txt // reading the decrypted file char decryptedtext[1000]; char onechar[1]; int dtptr = 0; FILE *fp; fp = fopen("temp.txt","r"); while(1) { if(fread(onechar,1,1,fp)==0) break; decryptedtext[dtptr++] = onechar[0]; } fclose(fp); int flag; // checking whether the first 3 characters of the decrypted file contains english characters only for(i=0;i<3;i++) { flag = 0; for(j=0;j<36;j++) { if(decryptedtext[i]==keybase[j] || decryptedtext[i]==' ') { flag = 1; break; } } if(flag==0) { flag = 2; break; } } if(flag!=2) {// there was no mismatch printf("\n\ngotcha!\t\t%s\n",key); char movecommand[40]; // store the possible decrypted file in decryptedfile%key%.txt sprintf(movecommand,"mv temp.txt decryptedfile%s.txt",key); system(movecommand); } } }