- #include <winsock.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <fcntl.h>
- void yaz(char *);
- void abc(char *p);
- void searcht(void);
- void try(char*);
- void hata(char*);
- void tamam(char*);
- void bekle(int);
- void gett(void);
- char Head1[]="GET /challenges/programming5/solution.php?solution=";
- char Head2[]="GET /challenges/programming5/tryout.php HTTP/1.0\r\n";
- char Head3[]="Host: www.bright-shadows.net\r\nUser-Agent: mynick/4.61 [ja] (X11; I; mynick 2.2.13-33cmc1 i686)\r\n";
- char Ref[80]="Referer: www.bright-shadows.net/challenges/programming5/programming5.php\r\n";
- char Head4[]="Cookie: PHPSESSID=a7388a264f0efb81da11a2255c9e300d\r\nCookie2: $Version=1\r\nConnection: keep-alive\r\n\r\n";
- char text[150];
- 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];
- // char HELO[]="user me \"me\" me :me \r\nnick tests \r\n\r\n";
- 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();
- yaz(text);
- system("perl -w perl.txt");
- gett();
- 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/programming5/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]==34)
- {
- x++;
- y=x-x;
- while(buff[x]!=34)
- {
- text[y]=buff[x];
- x++;
- y++;
- }
- text[y]='\0';
- printf("***%s***",text);
- break;
- }
- x++;
- }
- fclose(fsrc);
- }
- void yaz(char *text)
- {
- FILE *fp;
- int x;
- int app[6];
- int bra=0;
- fp=fopen("perl.txt","w");
- fprintf(fp,"$res1=1;\n$res2=2;\n");
- fprintf(fp,"open(Resfile, \">resfile.txt\");\n");
- for(x=0;x<6;x++) app[x]=0;
- for(x=0;x<strlen(text);x++)
- {
- if(text[x]==97 &&app[0]==0) { fprintf(fp,"for($a=0;$a<=9;$a++){\n"); bra++; app[0]++;}
- if(text[x]==98 &&app[1]==0) {fprintf(fp,"for($b=0;$b<=9;$b++){\n"); bra++; app[1]++;}
- if(text[x]==99 &&app[2]==0) {fprintf(fp,"for($c=0;$c<=9;$c++){\n"); bra++; app[2]++;}
- if(text[x]==100 &&app[3]==0){ fprintf(fp,"for($d=0;$d<=9;$d++){\n"); bra++; app[3]++;}
- if(text[x]==101 &&app[4]==0) {fprintf(fp,"for($e=0;$e<=9;$e++){\n"); bra++; app[4]++;}
- if(text[x]==102 &&app[5]==0) {fprintf(fp,"for($f=0;$f<=9;$f++){\n"); bra++; app[5]++;}
- if(text[x]==103) { printf("Zaman yetmez"); exit(1);}
- }
- x=0;
- fprintf(fp,"$res1=");
- for(x=0;x<strlen(text);x++)
- {
- if(text[x]==43) fprintf(fp,"+");
- if(text[x]==42) fprintf(fp,"*");
- if(text[x]==47) fprintf(fp,"/");
- if(text[x]==45) fprintf(fp,"-");
- if(text[x]==97) fprintf(fp,"($a");
- if(text[x]==98) fprintf(fp,"($b");
- if(text[x]==99) fprintf(fp,"($c");
- if(text[x]==100)fprintf(fp,"($d");
- if(text[x]==101)fprintf(fp,"($e");
- if(text[x]==102)fprintf(fp,"($f");
- if(text[x]==61) fprintf(fp,";\n$res2=");
- if(text[x]==95) fprintf(fp,"**%c)",text[x+1]);
- if(text[x]>=48 && (text[x]<=57) && text[x-1]!=95) fprintf(fp,"%c",text[x]);
- }
- x=0;
- fprintf(fp,";\nif($res1==$res2) { \n print Resfile (\"" );
- for(x=0;x<6;x++)
- {
- if(x==0 && app[x]!=0) fprintf(fp,"$a");
- if(x==1 && app[x]!=0) fprintf(fp,"$b");
- if(x==2 && app[x]!=0) fprintf(fp,"$c");
- if(x==3 && app[x]!=0) fprintf(fp,"$d");
- if(x==4 && app[x]!=0) fprintf(fp,"$e");
- if(x==5 && app[x]!=0) fprintf(fp,"$f");
- //if(x==0 && app[x]!=0) fprintf(fp,"g:$g ");
- }
- fprintf(fp," \");\n ");
- fprintf(fp,"close (Resfile);\n");
- fprintf(fp,"die();\n");
- for(x=0;x<=bra;x++)
- {
- fprintf(fp,"}\n");
- }
- fclose(fp);
- }
- void gett(void)
- {
- FILE *fpr;
- char res[8];
- if((fpr=fopen("resfile.txt","r"))==NULL) {printf("\nerror\n"); exit(1); }
- fscanf(fpr,"%s",res);
- strcpy(text,res);
- printf("\n\n******%s****\n\n",res);
- fclose(fpr);
- }
Posted by Anonymous on Mon 15th Jan 03:14
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.