Re: NNTP client problem (BSD Sockets)



On 2008-03-18 06:27:14 +0000, David Schwartz <davids@xxxxxxxxxxxxx> said:

On Mar 17, 11:14 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:

But his problem is that he's not getting ANY reply to the AUTHINFO USER
command. His next call to recv() is not returning.

Yeah, I can't think of any obvious reason for this. My current belief
is that he has some bug in code that he hasn't show us. That or his
news server just isn't replying to that for some reason.

DS

Here is my full code. It is probably rubbish but I'm not that great at C just yet.

This one has me completely stumped. I have followed the RFC standard for NNTP and the used the relevant extention standard documents so everything should be correct.

#include <sys/types.h>
#include <sys/socket.h>

#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <stdlib.h>

#include "main.h"

int main (int argc, const char * argv[])
{
int errorReturn = 0;
size_t bufsize = 1024;
char *buffer = malloc(bufsize);

if(errorReturn != 0)
{
printf("Interface not initialised.\n");
exit(EXIT_FAILURE);
}

errorReturn = nntpOpenSocket();

if(errorReturn != 0)
{
exit(EXIT_FAILURE);
}

errorReturn = nntpConnection(buffer, bufsize);

if(errorReturn == 0)
{
errorReturn = nntpCheckWhatToDo(buffer, bufsize, sock);

if(errorReturn == 480)
{
printf("Attempting login\n");
nntpLogin(buffer, bufsize, sock);
}
else
{
printf("Unknown Server Response.\n");
exit(EXIT_FAILURE);
}
}
else
{
exit(EXIT_FAILURE);
}

nntpQuitServer(buffer, bufsize);

free(buffer);

exit(EXIT_SUCCESS);
}

int nntpOpenSocket(void)
{
const int port = 119;
int error = 0;

he = gethostbyname("news-europe.giganews.com");
sock = socket(PF_INET, SOCK_STREAM, 0);
if(sock < 0)
{
printf("Socket error.\n");
return -1;
}

their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(port);
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
memset(their_addr.sin_zero, '\0', sizeof(their_addr.sin_zero));
error = connect(sock, (struct sockaddr *) &their_addr, sizeof(their_addr));
if(error == -1)
{
printf("Connection error.\n");
return -1;
}

return 0;
}

int nntpConnection(char *buffer, size_t bufsize)
{
int recvStatus = 0, comCodeInt = 0;
char comCode[3];

recvStatus = recv(sock, buffer, bufsize, 0);

if(recvStatus == 0)
{
printf("Socket Blocking.\n");
return -1;
}
else if(recvStatus == -1)
{
printf("Error.\n");
return -1;
}

strncpy(comCode, buffer, 3);

comCodeInt = atoi(comCode);
printf("%d\n", comCodeInt);

if(comCodeInt == 200)
{
printf("Connection OK.\n");
}
else
{
printf("Unknown Response.\n");
return -1;
}

return 0;
}

void nntpQuitServer(char *buffer, size_t bufsize)
{
send(sock, "QUIT\r\n", 6, 0);
recv(sock, buffer, bufsize, 0);
close(sock);

printf("%s", buffer);
}

int nntpCheckWhatToDo(char *buffer, size_t bufsize, int sock)
{
char serverResponse[3];
int serverResponseProcessed = 0;

send(sock, "MODE READER\r\n", 14, 0);
recv(sock, buffer, bufsize, 0);

printf("%s", buffer);

strncpy(serverResponse, buffer, 3);
serverResponseProcessed = atoi(serverResponse);

return serverResponseProcessed;
}

int nntpLogin(char *buffer, size_t bufsize, int sock)
{
char loginName[] = "AUTHINFO USER <>\r\n";
char passwd[] = "AUTHINFO PASS <>\r\n";

send(sock, loginName, strlen(loginName), 0);
printf("Data sent\n");
recv(sock, buffer, bufsize, 0);
printf("%s", buffer);
send(sock, passwd, strlen(passwd), 0);
recv(sock, buffer, bufsize, 0);
printf("%s", buffer);

return 0;
}

.



Relevant Pages

  • [UNIX] Multiple Vulnerabilities in Citadel/UX
    ... could allow complete control over a vulnerable server. ... Citadel server as can be seen by this simplistic code snippet: ... configuration buffers, leading to the possibility of carrying out a buffer ... int connect_to_host; ...
    (Securiteam)
  • [NEWS] Outgun Multiple Vulnerabilities (Multiple DoS, Multiple Buffer Overflows)
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Multiple Buffer Overflows) ... The buffers in which the server stores these two strings have a size of 64 ... int alen, ulen; ...
    (Securiteam)
  • TCP transmission problem
    ... I want to write TCP server/client programming, ... programming running not receive client information. ... int main ... //recv(socket1, buffer, SIZE, 0); ...
    (microsoft.public.win32.programmer.networks)
  • Re: CLX/CMUCL: Event processing speed
    ... They are the ones that contain resizing information about your window. ... int type; ... At least in the C version, all the X-commands you do are placed in a buffer, and only XNextEventflushes the buffer to the server, goes fetch new events, and gives you the first one. ...
    (comp.lang.lisp)
  • [PATCH] Numerous fixes to kernel-doc info in source files.
    ... static inline int ffs ... @buffer: where the data must be copied. ... * struct kfifo with kfree. ... @timer: ...
    (Linux-Kernel)