ClientsockThread.h
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. // clientsockthread.cpp (uses Winsock calls only)
  2. #include "stdafx.h"
  3. #include "blocksock.h"
  4. #include "global.h"
  5. #define MAXBUF 50000
  6. struct _tagHost host[MAXSITE];
  7. struct _tagThread thread[nTotalNum];
  8. UINT ClientSocketThreadProc(LPVOID pParam)
  9. {
  10.  
  11. CHttpBlockingSocket sClient;
  12. char* buffer = new char[MAXBUF];
  13. int nBytesReceived = 0;
  14. CString pMsg;
  15. CString Ip;
  16. char *lpszTemp=new char[50]; //NULL;
  17.     bool bFlag=false;
  18. _tagThread * pThread=(_tagThread*)pParam;
  19. Ip=pThread->pHost->strIP;  
  20. pMsg.Format("%s:Nomal End",Ip);
  21. char request[] = "GET %s%s%s HTTP/1.0rn";
  22. char headers[] =
  23. "User-Agent: Mozilla/1.22 (Windows; U; 32bit)rn"
  24. "Accept: */*rn"
  25. "Accept: image/gifrn"
  26. "Accept: image/x-xbitmaprn"
  27. "Accept: image/jpegrnrn";
  28. CSockAddr saServer, saTest, saClient;
  29. try {
  30. sClient.Create();
  31. /*if(g_bUseProxy)
  32. {
  33. saServer = CBlockingSocket::GetHostByName(g_strProxy, 80);
  34. }
  35. else
  36. { if(g_strServerIP.IsEmpty()) {
  37. saServer = CBlockingSocket::GetHostByName(g_strServerName, g_nPort);}
  38. else {saServer = CSockAddr(g_strServerIP, g_nPort); }
  39. }
  40. */
  41. saServer = CSockAddr(LPCSTR(pThread->pHost->strIP) ,pThread->pHost->uPort);
  42. TRACE("IP:%s,port %d",pThread->pHost->strIP,pThread->pHost->uPort );
  43. sClient.Connect(saServer);
  44. sClient.GetSockAddr(saTest);
  45. TRACE("SOCK CLIENT: GetSockAddr = %s, %dn", saTest.DottedDecimal(), saTest.Port());
  46. sprintf(buffer,request,"/","","");
  47. sClient.Write(buffer, strlen(buffer), 10);
  48. sClient.Write(headers, strlen(headers), 10);
  49. CString strTemp,strTemp1;
  50. // 读出所有的头
  51. do {
  52. nBytesReceived = sClient.ReadHttpHeaderLine(buffer, MAXBUF, 10);
  53. TRACE("SOCK CLIENT: %s", buffer);
  54. strTemp+=buffer ;
  55. if (!blnRunning)  throw new CBlockingSocketException("exit");
  56. } while(strcmp(buffer, "rn"));
  57. //取出其中的server
  58. int nPos;
  59. strTemp1=strTemp;
  60. nPos=strTemp.Find("rn");
  61. strTemp=strTemp.Left(nPos);
  62. strTemp=strTemp.Left(12);
  63. if (strTemp=="HTTP/1.1 200") bFlag=true;
  64. if (bFlag) //发送服务器标识
  65. {
  66. nPos=strTemp1.Find("rn");
  67. strTemp1=strTemp1.Mid(nPos+2);
  68. nPos=strTemp1.Find("rn");
  69. strTemp1=strTemp1.Left(nPos);
  70. //strcpy(lpszTemp,LPCSTR(strTemp1));
  71. sprintf(lpszTemp,"%s:%s",LPCSTR(Ip),LPCSTR(strTemp1));
  72. ::SendMessage(hwnd,WM_SCAN,0,(LPARAM)lpszTemp);
  73. }
  74. else//发送错误信息
  75. {
  76. strcpy(lpszTemp,LPCSTR(strTemp));
  77. throw new CBlockingSocketException(lpszTemp);
  78. }
  79. // 读出首页面
  80. nBytesReceived = sClient.ReadHttpResponse(buffer, MAXBUF, 10);
  81. TRACE("SOCK CLIENT: bytes received = %dn", nBytesReceived);
  82. if(nBytesReceived == 0) {
  83. pMsg.Format("无法读取%s页面内容",LPCSTR(Ip));
  84. strcpy(lpszTemp,LPCSTR(strTemp));
  85. throw new CBlockingSocketException(lpszTemp);
  86.         bFlag=false;
  87. }
  88. else
  89. {
  90. buffer[nBytesReceived] = '';
  91. //取出其中banner
  92. strTemp=buffer;
  93. strTemp.MakeUpper();
  94. nPos=strTemp.Find("<HEAD>");
  95. strTemp=strTemp.Mid(nPos+6);
  96. nPos=strTemp.Find("</HEAD>");
  97. strTemp=strTemp.Left(nPos);
  98. strTemp=Ip+ "BANNER:" + strTemp;
  99.      //sprintf(lpszTemp,"%s:%s",LPCSTR(Ip),LPCSTR(strTemp1));
  100. ::SendMessage(hwnd,WM_SCAN,0,(LPARAM)(LPCSTR(strTemp)));
  101. //可以进一步扫描漏洞
  102.             bFlag=true;
  103. }
  104. }
  105. catch(CBlockingSocketException* e) {
  106. LogBlockingSocketException(pParam, "CLIENT:", e);
  107. e->GetErrorMessage(lpszTemp,50,NULL); 
  108. pMsg.Format("%s:%s",LPCSTR(Ip),lpszTemp);
  109. e->Delete();
  110. }
  111. sClient.Close();
  112. session.Lock();
  113. nThreadCount--;
  114. session.Unlock();
  115. pThread->strMsg =pMsg;
  116. TRACE1("ID=%d",pThread->nThreadNum );
  117. ::SendMessage(hwnd,WM_SCANOVER,(WPARAM)pThread,0);
  118. delete [] buffer;
  119. return 0;
  120. }