Newbie ftp brute force attack

Newbie ftp brute force attack

Post by MonkeyNut on Mon Mar 02, 2009 4:45 pm
([msg=19069]see Newbie ftp brute force attack[/msg])

Hi all

I'm a newbie to this whole hacking stuff so please bear with me. I'm writing a program in C that does a brute force attack on an FTP server (it's part of a project for a network security module that i'm studying). The program works by using two text files, one with a list of usernames and one with a list of passwords for the attack.

I've established a connection with the server and got the program to open and read both text files. I'm now at the stage were i need to send the data from the two text files, however in being a novice in c programming i'm struggling with this part. I'm guessing I have to create two loops, one for the username file and one for the password file? but i'm a bit stumped on how to do it.

Hope i've made some sense!
Any replies would be much appreciated!

Thanks
MonkeyNut
New User
New User
 
Posts: 7
Joined: Mon Mar 02, 2009 4:40 pm
Blog: View Blog (0)


Re: Newbie ftp brute force attack

Post by cen on Mon Mar 02, 2009 5:01 pm
([msg=19071]see Re: Newbie ftp brute force attack[/msg])

Sounds like you got the basic idea...

warning - Semi-Pseudocode (not real code):

Code: Select all
bool found=false;

for(x=0; names[x]; x++)
{  for(y=0; passwords[y]; y++)
   {  if(tryHack(names[x], passwords[y]))
      {  found=true;
         break;
      }
   }

   if(found) break;
}

if(found)
{  name=names[x];
   pass=passwords[y];
}


Good Luck!
User avatar
cen
Experienced User
Experienced User
 
Posts: 77
Joined: Mon Jun 30, 2008 1:06 pm
Blog: View Blog (0)


Re: Newbie ftp brute force attack

Post by MonkeyNut on Mon Mar 02, 2009 5:19 pm
([msg=19076]see Re: Newbie ftp brute force attack[/msg])

cen wrote:Sounds like you got the basic idea...

warning - Semi-Pseudocode (not real code):

Code: Select all
bool found=false;

for(x=0; names[x]; x++)
{  for(y=0; passwords[y]; y++)
   {  if(tryHack(names[x], passwords[y]))
      {  found=true;
         break;
      }
   }

   if(found) break;
}

if(found)
{  name=names[x];
   pass=passwords[y];
}


Good Luck!


Hi cen thanks for the reply.

Just a quick query about your code. If i have say 10 possible usernames and 10 possible passwords would i start a loop by sending the first username with the 10 passwords, then second username with the ten passwords, etc, etc?
MonkeyNut
New User
New User
 
Posts: 7
Joined: Mon Mar 02, 2009 4:40 pm
Blog: View Blog (0)


Re: Newbie ftp brute force attack

Post by cen on Mon Mar 02, 2009 5:28 pm
([msg=19077]see Re: Newbie ftp brute force attack[/msg])

If i have say 10 possible usernames and 10 possible passwords would i start a loop by sending the first username with the 10 passwords, then second username with the ten passwords, etc, etc?


It actually doesn't matter in this situation which loop you decide to use first (user or pass)... But yeah, for 'ease of reading' at least, I would do it like you've stated...
User avatar
cen
Experienced User
Experienced User
 
Posts: 77
Joined: Mon Jun 30, 2008 1:06 pm
Blog: View Blog (0)


Re: Newbie ftp brute force attack

Post by MonkeyNut on Mon Mar 02, 2009 5:39 pm
([msg=19080]see Re: Newbie ftp brute force attack[/msg])

Ok, thanks for the help!

-- Wed Mar 04, 2009 12:20 pm --

Hi all

Still absolutely stumped when it comes to creating the loop for my username and password files. I tried implementing some of the code given above but just got tons of errors. I'm pretty rubbish at C, but basically i've established a connection with the server and got it to open and read both the username and passwords files. Basically i'm wondering does anyone have any input on how to do the next stage, i.e. creating the loop for the username and password files or have any decent resources for this information?

Sorry if the code is messy!


Code: Select all

    /* Establish the connection to the echo server */
    if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
        DieWithError("connect() failed");

echoStringLen = strlen(echoString);

if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send() sent a differnet number of bytes then expected");

totalBytesRcvd = 0;
printf("Received: ");
while (totalBytesRcvd < echoStringLen)
{
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE -1, 0)) <=0 )
DieWithError("recv() failed or connection closed prematurely");
totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
printf(echoBuffer);
}

printf("\n");

    HandleTCPServer(sock, argv);

    close(sock);
  printf("Enter the name of the username file you want to read data from: ");
        scanf("%s", userfile);
        if (!(fp=fopen(userfile,"r"))) {
                perror(userfile);
                exit(1);
        }

        /* count the number of comment lines, and data lines */
        while (fgets(templine,sizeof(templine),fp)!=NULL) {
                if (templine[0]=='#') {
                        comment++;
                } else {
                        nrows++;
                }
        }
        printf("\nThere are %u comments and %u rows", comment, nrows);

        /* allocate string array to write all the lines from the file */
        buff=malloc((comment+nrows)*sizeof(*buff));
        if (buff==NULL) {
                printf("\nCould not allocate  pointer array");
        }
        for (i=0; i<(comment+nrows); i++) {
                buff[i]=malloc(linelen*sizeof(*buff[i]));
                if (buff[i]==NULL) {
                        printf("\nCould not allocate array %u", i);
                }
        }

        /* read all lines into buffer, and print to screen */
        rewind(fp);
        for (i=0; i<(comment+nrows); i++) {
                fgets(buff[i],linelen*sizeof(buff[i]),fp);
                printf("%s", buff[i]);
        }

        /* clean up memory */
        fclose(fp);
        for (i=0; i<(comment+nrows); i++) {
                free(buff[i]);
        }
        free(buff);


/* open a file to read */
        printf("Enter the name of the password file you want to read data from: ");
        scanf("%s", passfile);
        if (!(fp1=fopen(passfile,"r"))) {
                perror(passfile);
                exit(1);
        }

        /* count the number of comment lines, and data lines */
        while (fgets(templine1,sizeof(templine1),fp1)!=NULL) {
                if (templine1[0]=='#') {
                        comment1++;
                } else {
                        nrows1++;
                }
        }
        printf("\nThere are %u comments and %u rows", comment1, nrows1);

        /* allocate string array to write all the lines from the file */
        buff1=malloc((comment1+nrows1)*sizeof(*buff1));
        if (buff1==NULL) {
                printf("\nCould not allocate  pointer array");
        }
        for (j=0; j<(comment1+nrows1); j++) {
                buff1[j]=malloc(linelen1*sizeof(*buff1[j]));
                if (buff1[j]==NULL) {
                        printf("\nCould not allocate array %u", j);
                }
        }

        /* read all lines into buffer, and print to screen */
        rewind(fp1);
        for (j=0; j<(comment1+nrows1); j++) {
                fgets(buff1[j],linelen1*sizeof(buff1[j]),fp1);
                printf("%s", buff1[j]);
        }

        /* clean up memory */
        fclose(fp1);
        for (j=0; j<(comment1+nrows1); j++) {
                free(buff1[j]);
        }
        free(buff1);

        return 0;

exit(0);
}




Thanks
MonkeyNut
New User
New User
 
Posts: 7
Joined: Mon Mar 02, 2009 4:40 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests