- #include <winsock.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <fcntl.h>
- void abc(char *p);
- void searcht(void);
- void try(char*);
- void hata(char*);
- void tamam(char*);
- void bekle(int);
- char Head1[]="GET /challenges/programming1/solution.php?solution=";
- char Head2[]="GET /challenges/programming1/tryout.php HTTP/1.0\r\n";
- char Head3[]="Host: www.bright-shadows.net\r\nUser-Agent: secret/4.61 [ja] (X11; I; secret 2.2.13-33cmc1 i686)\r\n";
- char Ref[80]="Referer: www.bright-shadows.net/challenges/programming1/programming1.php\r\n";
- /*you have recive sessionid someotherway then you can use it here*/
- char Head4[]="Cookie: PHPSESSID=569ec8bd9a2bb1bb28722326b045fcf9\r\nCookie2: $Version=1\r\nConnection: keep-alive\r\n\r\n";
- char text[40];
- int main(int argc,char *argv[])
- {
- int say;
- int sockfd;
- int bufsize=1000;
- char *buf=malloc(bufsize);
- struct sockaddr_in server;
- struct hostent *h;
- char ip[20];
- char HELO[510];
- char Cookie[80];
- WSADATA ws;
- WSAStartup(MAKEWORD(2,2),&ws);
- strcat(HELO,Head2);
- strcat(HELO,Head3);
- strcat(HELO,Ref);
- strcat(HELO,Head4);
- if (argc < 3)
- {
- printf("Eksik parametre");
- exit(1);
- }
- if((h=gethostbyname(argv[1]))==NULL) hata("gethostbyname");
- else {
- tamam("gethostbyname");
- printf("Host name:%s\n",h->h_name);
- printf("Host ip:%s\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
- strcpy(ip,inet_ntoa(*((struct in_addr *)h->h_addr)));
- }
- if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) hata("socket");
- else tamam("socket");
- server.sin_family=AF_INET;
- server.sin_port=htons(atoi(argv[2]));
- server.sin_addr.s_addr=inet_addr(ip);
- memset(&(server.sin_zero),'\0',8);
- if((connect(sockfd,(struct sockaddr*)&server,sizeof(server)))==-1) hata("connect");
- else tamam("connect");
- strcpy(buf,HELO);
- send(sockfd,buf,strlen(buf),0);
- printf("Sent data:\n");
- puts(buf);
- say=1;
- memset(buf,'\0',1000);
- say=1;
- while(say!=0)
- {
- say=recv(sockfd,buf,sizeof(buf),0);
- //puts(buf);
- abc(buf);
- }
- closesocket(sockfd);
- searcht();
- if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) hata("socket");
- else tamam("socket");
- server.sin_family=AF_INET;
- server.sin_port=htons(atoi(argv[2]));
- server.sin_addr.s_addr=inet_addr(ip);
- memset(&(server.sin_zero),'\0',8);
- if((connect(sockfd,(struct sockaddr*)&server,sizeof(server)))==-1) hata("connect");
- else tamam("connect");
- strcpy(Ref,"Referer: www.bright-shadows.net/challenges/programming1/tryout.php\r\n");
- strcpy(HELO,Head1);
- strcat(HELO,text);
- strcat(HELO," HTTP/1.0\r\n");
- strcat(HELO,Head3);
- strcat(HELO,Ref);
- strcat(HELO,Head4);
- strcat(HELO,Head3);
- strcpy(buf,HELO);
- send(sockfd,buf,strlen(buf),0);
- printf("Sent data:\n");
- puts(buf);
- say=1;
- memset(buf,'\0',1000);
- say=1;
- while(say!=0)
- {
- say=recv(sockfd,buf,sizeof(buf),0);
- puts(buf);
- abc(buf);
- }
- closesocket(sockfd);
- WSACleanup();
- return 0;
- }
- void try(char *msg)
- {
- printf("Trying %s()....\n",msg);
- }
- void hata(char *msg)
- {
- printf("Call to %s() failed",msg);
- exit(1);
- }
- void tamam(char *msg)
- {
- printf("Call to %s() is succesfull\n",msg);
- }
- void bekle(int secs)
- {
- clock_t x,y,z;
- x=clock();
- while(z!=secs)
- {
- y=clock();
- z=(y-x)/CLK_TCK;
- }
- }
- void abc(char *p)
- {
- FILE *fp = fopen("b.txt","a+");
- fprintf(fp,"%s",p);
- fclose(fp);
- }
- void searcht()
- {
- char buff[1000];
- int y,x=0,tmp;
- FILE *fsrc=fopen("b.txt","r");
- printf("Searching ....");
- while(!feof(fsrc) || buff[x]==NULL)
- {
- buff[x]=fgetc(fsrc);
- x++;
- }
- buff[x]='\0';
- tmp=x;
- x=0;
- printf("tmp:%d",tmp);
- while(x<tmp)
- {
- if(buff[x]==39)
- {
- x++;
- y=x-x;
- while(buff[x]!=39)
- {
- text[y]=buff[x];
- x++;
- y++;
- }
- text[y]='\0';
- printf("***%s***",text);
- break;
- }
- x++;
- }
- fclose(fsrc);
- }
Posted by Anonymous on Mon 15th Jan 03:11
download | new post
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.