Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <crypt.h>
  7.  
  8. int dictionary(char *file1, char *file2){
  9. FILE *fp, *fp2, *fp3;
  10. fp3 = fopen("dicfile","w");
  11. char buffer1[60],buffer2[60];
  12. char *token, *salt, *usr, *res;
  13. char salty[12];
  14. int cnt=0;
  15. int i , y, flag;
  16. fp = fopen("shadow_2018.txt","r");
  17. if (fp==NULL){
  18. printf("Could not open your file. Please try again.\n");
  19. exit(1);
  20. }
  21. fp2 = fopen("words.english.txt","r");
  22. if (fp2==NULL){
  23. printf("Could not open your file. Please try again.\n");
  24. exit(1);
  25. }
  26. printf("PLEASE STAND BY...\n");
  27. while((fscanf(fp2,"%s",buffer1)) != EOF){
  28. while((fscanf(fp,"%s",buffer2)) != EOF){
  29. token = strtok(buffer2,":");
  30. for(i = 0; i < 2; i++){
  31. if(i==0){
  32. usr=token;
  33. }
  34. else if(i==1){
  35. salt=token;
  36. for(y=0; y < 12; y++){
  37. salty[y] = salt[y];
  38. }
  39. }
  40. token = strtok(NULL,":");
  41.  
  42. }
  43. res = crypt(buffer1,salty);
  44. flag = strcmp(res,salt);
  45. if(flag==0){
  46. fprintf(fp3,"Username: %s Password: %s\n",usr,buffer1);
  47. printf("Username: %s Password %s \n", usr, buffer1);
  48. }
  49. }
  50. rewind(fp);
  51. }
  52. fclose(fp);
  53. fclose(fp2);
  54. fclose(fp3);
  55. return 1;
  56. }
  57.  
  58. int bruteforce(char *username, char *password, char *salt)
  59. {
  60. char symbols[]={"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^*()_&?"}, words[5];
  61. char key[100];
  62. int l1, l2;
  63. int flag;
  64. int i, j, k, l;
  65. int t=0;
  66. unsigned long min=0,sec=0;
  67.  
  68. FILE *file;
  69. flag=0;
  70.  
  71. file=fopen("brutefile","w");
  72. clock_t start=clock();
  73.  
  74. l1=sizeof(symbols);
  75.  
  76. for(i=0;i<l1;i++)
  77. for(j=0;j<l1;j++)
  78. for(k=0;k<l1;k++)
  79. for(l=0;l<l1;l++)
  80. {
  81. words[0]=symbols[l];
  82. words[1]=symbols[k];
  83. words[2]=symbols[j];
  84. words[3]=symbols[i];
  85. words[4]='\0';
  86.  
  87. l2=sizeof(words);
  88.  
  89. if(l2>3)
  90. {
  91. strcpy(key, crypt(words, salt));
  92. if (strcmp(password, key)== 0)
  93. {
  94. clock_t finish=clock();
  95. flag=1;
  96. fprintf(file,"== BRUTE FORCE ==\n");
  97. fprintf(file,"Username: %s\n", username);
  98. fprintf(file,"Password: %s\n", words);
  99. fprintf(file,"Encrypted Password: %s\n",password);
  100. sec=(int)(finish-start) /CLOCKS_PER_SEC;
  101. if(sec>60)
  102. {
  103. min=sec/60;
  104. sec=sec % 60;
  105. }
  106. fprintf(file,"MISSION COMPLETE\nDURATION: %lu Minutes %lu Seconds.\n", min,sec);
  107. fclose(file);
  108. return flag;
  109. }
  110. }
  111. }
  112.  
  113. return flag;
  114. }
  115.  
  116.  
  117. int main(int argc, char *argv[]){
  118. int ch;
  119. printf("=== WELCOME TO CODEHAX ===\n\nFEATURES:\n1. BRUTE FORCE\n2. DICTIONARY\n");
  120. printf("Please select a method: \n");
  121. scanf("%d",&ch);
  122. switch(ch){
  123. case 1:
  124. {
  125. FILE *fil;
  126. char line[200], token[200], name[20], usr[20], salt[50], nline[100], pswd[100];
  127. int i,j,found, found2;
  128.  
  129. fil=fopen("shadow_2018.txt","r");
  130. if (fil==NULL)
  131. {
  132. printf("Error: File cannot be opened \n");
  133. exit(0);
  134. }
  135. else
  136. {
  137. printf("Name The Target: ");
  138. scanf("%s",name);
  139. while(!feof(fil)) {
  140. fgets(line,sizeof(line),fil);
  141. strcpy(token, line);
  142. strcpy(usr, strtok(token,":"));
  143.  
  144. if(strcmp(name,usr)==0) {
  145. strcpy(nline, strchr(line,'$'));
  146. j=0;
  147. for(i=0;i<34;i++){
  148. pswd[j]=nline[i];
  149. j++;
  150. }
  151. pswd[j]='\0';
  152.  
  153.  
  154. j=0;
  155. for(i=0;i<11;i++)
  156. {
  157. salt[j]=nline[i];
  158. j++;
  159. }
  160. salt[j]='\0';
  161.  
  162. found=bruteforce(usr, pswd, salt);
  163.  
  164. if(found == 0)
  165. printf("MISSION FAILED\nWe'll get them next time\n");
  166. }
  167. break;
  168. }
  169. }
  170. fclose(fil);
  171. }
  172. break;
  173. case 2:
  174. {
  175. int flag=0;
  176. flag = dictionary(argv[1],argv[2]);
  177. if(flag==1)
  178. printf("MISSION COMPLETE\nThank you for using our program\n");
  179. else
  180. printf("MISSION FAILED\nWe'll get them next time\n");
  181. }
  182. break;
  183. default:
  184. printf("Wrong Input. Please Try Again\n");
  185. printf("Please select a method: \n");
  186. scanf("%d",&ch);
  187. }
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement