pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

paste-bin - collaborative debugging tool View Help


Posted by Anonymous on Mon 15th Jan 03:11
download | new post

  1. #include <winsock.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <fcntl.h>
  7.  
  8. void abc(char *p);
  9. void searcht(void);
  10. void try(char*);
  11. void hata(char*);
  12. void tamam(char*);
  13. void bekle(int);
  14.  
  15. char Head1[]="GET /challenges/programming1/solution.php?solution=";
  16. char Head2[]="GET /challenges/programming1/tryout.php HTTP/1.0\r\n";
  17. char Head3[]="Host: www.bright-shadows.net\r\nUser-Agent: secret/4.61 [ja] (X11; I; secret 2.2.13-33cmc1 i686)\r\n";
  18. char Ref[80]="Referer: www.bright-shadows.net/challenges/programming1/programming1.php\r\n";
  19. /*you have recive sessionid someotherway then you can use it here*/
  20. char Head4[]="Cookie: PHPSESSID=569ec8bd9a2bb1bb28722326b045fcf9\r\nCookie2: $Version=1\r\nConnection: keep-alive\r\n\r\n";
  21. char text[40];
  22. int main(int argc,char *argv[])
  23. {
  24.         int say;
  25.         int sockfd;
  26.         int bufsize=1000;
  27.         char *buf=malloc(bufsize);
  28.         struct sockaddr_in server;
  29.         struct hostent *h;
  30.         char ip[20];
  31.         char HELO[510];
  32.         char Cookie[80];
  33.  
  34.         WSADATA ws;
  35.         WSAStartup(MAKEWORD(2,2),&ws);
  36. strcat(HELO,Head2);
  37. strcat(HELO,Head3);
  38. strcat(HELO,Ref);
  39. strcat(HELO,Head4);
  40.  
  41.          if (argc < 3)
  42.          {
  43.                  printf("Eksik parametre");
  44.                  exit(1);
  45.          }
  46.         if((h=gethostbyname(argv[1]))==NULL) hata("gethostbyname");
  47.         else {
  48.                         tamam("gethostbyname");
  49.                         printf("Host name:%s\n",h->h_name);
  50.                         printf("Host ip:%s\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
  51.  
  52.                         strcpy(ip,inet_ntoa(*((struct in_addr *)h->h_addr)));
  53.  
  54.  
  55.  
  56.                 }
  57.  
  58.  
  59.         if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) hata("socket");
  60.         else tamam("socket");
  61.  
  62.         server.sin_family=AF_INET;
  63.         server.sin_port=htons(atoi(argv[2]));
  64.         server.sin_addr.s_addr=inet_addr(ip);
  65.         memset(&(server.sin_zero),'\0',8);
  66.  
  67.  
  68.         if((connect(sockfd,(struct sockaddr*)&server,sizeof(server)))==-1) hata("connect");
  69.         else tamam("connect");
  70.        
  71.  
  72.         strcpy(buf,HELO);
  73.         send(sockfd,buf,strlen(buf),0);
  74.  
  75.         printf("Sent data:\n");
  76.         puts(buf);
  77.         say=1;
  78.         memset(buf,'\0',1000);
  79.  
  80.         say=1;
  81.         while(say!=0)
  82.         {
  83.         say=recv(sockfd,buf,sizeof(buf),0);
  84.         //puts(buf);
  85.         abc(buf);
  86.         }
  87.  
  88. closesocket(sockfd);
  89.  
  90.  
  91.  
  92. searcht();
  93.         if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) hata("socket");
  94.         else tamam("socket");
  95.  
  96.         server.sin_family=AF_INET;
  97.         server.sin_port=htons(atoi(argv[2]));
  98.         server.sin_addr.s_addr=inet_addr(ip);
  99.         memset(&(server.sin_zero),'\0',8);
  100.  
  101.         if((connect(sockfd,(struct sockaddr*)&server,sizeof(server)))==-1) hata("connect");
  102.         else tamam("connect");
  103.  
  104. strcpy(Ref,"Referer: www.bright-shadows.net/challenges/programming1/tryout.php\r\n");
  105. strcpy(HELO,Head1);
  106. strcat(HELO,text);
  107. strcat(HELO," HTTP/1.0\r\n");
  108. strcat(HELO,Head3);
  109. strcat(HELO,Ref);
  110. strcat(HELO,Head4);
  111.  
  112. strcat(HELO,Head3);
  113.  
  114.         strcpy(buf,HELO);
  115.         send(sockfd,buf,strlen(buf),0);
  116.  
  117.         printf("Sent data:\n");
  118.         puts(buf);
  119.         say=1;
  120.         memset(buf,'\0',1000);
  121.  
  122.         say=1;
  123.         while(say!=0)
  124.         {
  125.         say=recv(sockfd,buf,sizeof(buf),0);
  126.         puts(buf);
  127.         abc(buf);
  128.         }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.         closesocket(sockfd);
  135.         WSACleanup();
  136.        
  137.  
  138.         return 0;
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145. void try(char *msg)
  146. {
  147.         printf("Trying %s()....\n",msg);
  148. }
  149. void hata(char *msg)
  150. {
  151.         printf("Call to %s() failed",msg);
  152.         exit(1);
  153. }
  154. void tamam(char *msg)
  155. {
  156.         printf("Call  to %s() is succesfull\n",msg);
  157. }
  158.  
  159.  
  160. void bekle(int secs)
  161. {
  162.  
  163. clock_t x,y,z;
  164. x=clock();
  165. while(z!=secs)
  166.         {
  167. y=clock();
  168. z=(y-x)/CLK_TCK;
  169. }
  170. }
  171.  
  172.  
  173. void abc(char *p)
  174. {
  175.         FILE *fp = fopen("b.txt","a+");
  176.         fprintf(fp,"%s",p);
  177.         fclose(fp);
  178. }
  179.  
  180.  
  181. void searcht()
  182. {
  183.         char buff[1000];
  184.         int y,x=0,tmp;
  185.  
  186.         FILE *fsrc=fopen("b.txt","r");
  187.  
  188.                 printf("Searching ....");
  189.  
  190.         while(!feof(fsrc) || buff[x]==NULL)
  191.         {
  192.                 buff[x]=fgetc(fsrc);
  193.                 x++;
  194.         }
  195.         buff[x]='\0';
  196.         tmp=x;
  197.         x=0;
  198.         printf("tmp:%d",tmp);
  199.         while(x<tmp)
  200.         {
  201.                 if(buff[x]==39)
  202.                 {
  203.                         x++;
  204.                         y=x-x;
  205.                         while(buff[x]!=39)
  206.                         {
  207.                         text[y]=buff[x];
  208.                         x++;
  209.                         y++;
  210.                         }
  211.                         text[y]='\0';
  212.                         printf("***%s***",text);
  213.                         break;
  214.                 }
  215.  
  216.                 x++;
  217.         }
  218.         fclose(fsrc);
  219. }

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.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings