ClientsockThread.h
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:4k
源码类别:
游戏
开发平台:
Visual C++
- // clientsockthread.cpp (uses Winsock calls only)
- #include "stdafx.h"
- #include "blocksock.h"
- #include "global.h"
- #define MAXBUF 50000
- struct _tagHost host[MAXSITE];
- struct _tagThread thread[nTotalNum];
- UINT ClientSocketThreadProc(LPVOID pParam)
- {
- CHttpBlockingSocket sClient;
- char* buffer = new char[MAXBUF];
- int nBytesReceived = 0;
- CString pMsg;
- CString Ip;
- char *lpszTemp=new char[50]; //NULL;
- bool bFlag=false;
- _tagThread * pThread=(_tagThread*)pParam;
- Ip=pThread->pHost->strIP;
- pMsg.Format("%s:Nomal End",Ip);
- char request[] = "GET %s%s%s HTTP/1.0rn";
- char headers[] =
- "User-Agent: Mozilla/1.22 (Windows; U; 32bit)rn"
- "Accept: */*rn"
- "Accept: image/gifrn"
- "Accept: image/x-xbitmaprn"
- "Accept: image/jpegrnrn";
- CSockAddr saServer, saTest, saClient;
- try {
- sClient.Create();
- /*if(g_bUseProxy)
- {
- saServer = CBlockingSocket::GetHostByName(g_strProxy, 80);
- }
- else
- { if(g_strServerIP.IsEmpty()) {
- saServer = CBlockingSocket::GetHostByName(g_strServerName, g_nPort);}
- else {saServer = CSockAddr(g_strServerIP, g_nPort); }
- }
- */
- saServer = CSockAddr(LPCSTR(pThread->pHost->strIP) ,pThread->pHost->uPort);
- TRACE("IP:%s,port %d",pThread->pHost->strIP,pThread->pHost->uPort );
- sClient.Connect(saServer);
- sClient.GetSockAddr(saTest);
- TRACE("SOCK CLIENT: GetSockAddr = %s, %dn", saTest.DottedDecimal(), saTest.Port());
- sprintf(buffer,request,"/","","");
- sClient.Write(buffer, strlen(buffer), 10);
- sClient.Write(headers, strlen(headers), 10);
- CString strTemp,strTemp1;
- // 读出所有的头
- do {
- nBytesReceived = sClient.ReadHttpHeaderLine(buffer, MAXBUF, 10);
- TRACE("SOCK CLIENT: %s", buffer);
- strTemp+=buffer ;
- if (!blnRunning) throw new CBlockingSocketException("exit");
- } while(strcmp(buffer, "rn"));
- //取出其中的server
- int nPos;
- strTemp1=strTemp;
- nPos=strTemp.Find("rn");
- strTemp=strTemp.Left(nPos);
- strTemp=strTemp.Left(12);
- if (strTemp=="HTTP/1.1 200") bFlag=true;
- if (bFlag) //发送服务器标识
- {
- nPos=strTemp1.Find("rn");
- strTemp1=strTemp1.Mid(nPos+2);
- nPos=strTemp1.Find("rn");
- strTemp1=strTemp1.Left(nPos);
- //strcpy(lpszTemp,LPCSTR(strTemp1));
- sprintf(lpszTemp,"%s:%s",LPCSTR(Ip),LPCSTR(strTemp1));
- ::SendMessage(hwnd,WM_SCAN,0,(LPARAM)lpszTemp);
- }
- else//发送错误信息
- {
- strcpy(lpszTemp,LPCSTR(strTemp));
- throw new CBlockingSocketException(lpszTemp);
- }
- // 读出首页面
- nBytesReceived = sClient.ReadHttpResponse(buffer, MAXBUF, 10);
- TRACE("SOCK CLIENT: bytes received = %dn", nBytesReceived);
- if(nBytesReceived == 0) {
- pMsg.Format("无法读取%s页面内容",LPCSTR(Ip));
- strcpy(lpszTemp,LPCSTR(strTemp));
- throw new CBlockingSocketException(lpszTemp);
- bFlag=false;
- }
- else
- {
- buffer[nBytesReceived] = ' ';
- //取出其中banner
- strTemp=buffer;
- strTemp.MakeUpper();
- nPos=strTemp.Find("<HEAD>");
- strTemp=strTemp.Mid(nPos+6);
- nPos=strTemp.Find("</HEAD>");
- strTemp=strTemp.Left(nPos);
- strTemp=Ip+ "BANNER:" + strTemp;
- //sprintf(lpszTemp,"%s:%s",LPCSTR(Ip),LPCSTR(strTemp1));
- ::SendMessage(hwnd,WM_SCAN,0,(LPARAM)(LPCSTR(strTemp)));
- //可以进一步扫描漏洞
- bFlag=true;
- }
- }
- catch(CBlockingSocketException* e) {
- LogBlockingSocketException(pParam, "CLIENT:", e);
- e->GetErrorMessage(lpszTemp,50,NULL);
- pMsg.Format("%s:%s",LPCSTR(Ip),lpszTemp);
- e->Delete();
- }
- sClient.Close();
- session.Lock();
- nThreadCount--;
- session.Unlock();
- pThread->strMsg =pMsg;
- TRACE1("ID=%d",pThread->nThreadNum );
- ::SendMessage(hwnd,WM_SCANOVER,(WPARAM)pThread,0);
- delete [] buffer;
- return 0;
- }