Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <time.h>
- #include <crypt.h>
- int dictionary(char *file1, char *file2){
- FILE *fp, *fp2, *fp3;
- fp3 = fopen("dicfile","w");
- char buffer1[60],buffer2[60];
- char *token, *salt, *usr, *res;
- char salty[12];
- int cnt=0;
- int i , y, flag;
- fp = fopen("shadow_2018.txt","r");
- if (fp==NULL){
- printf("Could not open your file. Please try again.\n");
- exit(1);
- }
- fp2 = fopen("words.english.txt","r");
- if (fp2==NULL){
- printf("Could not open your file. Please try again.\n");
- exit(1);
- }
- printf("PLEASE STAND BY...\n");
- while((fscanf(fp2,"%s",buffer1)) != EOF){
- while((fscanf(fp,"%s",buffer2)) != EOF){
- token = strtok(buffer2,":");
- for(i = 0; i < 2; i++){
- if(i==0){
- usr=token;
- }
- else if(i==1){
- salt=token;
- for(y=0; y < 12; y++){
- salty[y] = salt[y];
- }
- }
- token = strtok(NULL,":");
- }
- res = crypt(buffer1,salty);
- flag = strcmp(res,salt);
- if(flag==0){
- fprintf(fp3,"Username: %s Password: %s\n",usr,buffer1);
- printf("Username: %s Password %s \n", usr, buffer1);
- }
- }
- rewind(fp);
- }
- fclose(fp);
- fclose(fp2);
- fclose(fp3);
- return 1;
- }
- int bruteforce(char *username, char *password, char *salt)
- {
- char symbols[]={"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^*()_&?"}, words[5];
- char key[100];
- int l1, l2;
- int flag;
- int i, j, k, l;
- int t=0;
- unsigned long min=0,sec=0;
- FILE *file;
- flag=0;
- file=fopen("brutefile","w");
- clock_t start=clock();
- l1=sizeof(symbols);
- for(i=0;i<l1;i++)
- for(j=0;j<l1;j++)
- for(k=0;k<l1;k++)
- for(l=0;l<l1;l++)
- {
- words[0]=symbols[l];
- words[1]=symbols[k];
- words[2]=symbols[j];
- words[3]=symbols[i];
- words[4]='\0';
- l2=sizeof(words);
- if(l2>3)
- {
- strcpy(key, crypt(words, salt));
- if (strcmp(password, key)== 0)
- {
- clock_t finish=clock();
- flag=1;
- fprintf(file,"== BRUTE FORCE ==\n");
- fprintf(file,"Username: %s\n", username);
- fprintf(file,"Password: %s\n", words);
- fprintf(file,"Encrypted Password: %s\n",password);
- sec=(int)(finish-start) /CLOCKS_PER_SEC;
- if(sec>60)
- {
- min=sec/60;
- sec=sec % 60;
- }
- fprintf(file,"MISSION COMPLETE\nDURATION: %lu Minutes %lu Seconds.\n", min,sec);
- fclose(file);
- return flag;
- }
- }
- }
- return flag;
- }
- int main(int argc, char *argv[]){
- int ch;
- printf("=== WELCOME TO CODEHAX ===\n\nFEATURES:\n1. BRUTE FORCE\n2. DICTIONARY\n");
- printf("Please select a method: \n");
- scanf("%d",&ch);
- switch(ch){
- case 1:
- {
- FILE *fil;
- char line[200], token[200], name[20], usr[20], salt[50], nline[100], pswd[100];
- int i,j,found, found2;
- fil=fopen("shadow_2018.txt","r");
- if (fil==NULL)
- {
- printf("Error: File cannot be opened \n");
- exit(0);
- }
- else
- {
- printf("Name The Target: ");
- scanf("%s",name);
- while(!feof(fil)) {
- fgets(line,sizeof(line),fil);
- strcpy(token, line);
- strcpy(usr, strtok(token,":"));
- if(strcmp(name,usr)==0) {
- strcpy(nline, strchr(line,'$'));
- j=0;
- for(i=0;i<34;i++){
- pswd[j]=nline[i];
- j++;
- }
- pswd[j]='\0';
- j=0;
- for(i=0;i<11;i++)
- {
- salt[j]=nline[i];
- j++;
- }
- salt[j]='\0';
- found=bruteforce(usr, pswd, salt);
- if(found == 0)
- printf("MISSION FAILED\nWe'll get them next time\n");
- }
- break;
- }
- }
- fclose(fil);
- }
- break;
- case 2:
- {
- int flag=0;
- flag = dictionary(argv[1],argv[2]);
- if(flag==1)
- printf("MISSION COMPLETE\nThank you for using our program\n");
- else
- printf("MISSION FAILED\nWe'll get them next time\n");
- }
- break;
- default:
- printf("Wrong Input. Please Try Again\n");
- printf("Please select a method: \n");
- scanf("%d",&ch);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement