界面如下:
主要代码如下:
1 //对于每一个线程,传过去的参数 2 typedef struct ThreadParamStruct 3 { 4 CString strIP; //要扫描的IP地址 5 UINT uPort; //要扫描的端口 6 BOOL bNoOrder; //是否按照随机的顺序扫描 7 CPortScan_TCPDlg *ptr; //指向父线程的对话框 8 HTREEITEM TreeItem; //指向结果要显示的树型控件节点 9 }THREADPARAM;
1 UINT ThreadCSocketScan(LPVOID pParam) 2 { 3 THREADPARAM *threadparam = (THREADPARAM*)pParam; 4 CString strIP = threadparam->strIP; 5 UINT uPort = threadparam->uPort; 6 CPortScan_TCPDlg *ptr = threadparam->ptr; 7 HTREEITEM TreeItem = threadparam->TreeItem; 8 BOOL bNoOrder = threadparam->bNoOrder; 9 10 g_iTotalThreadCount++; 11 if (bNoOrder) 12 { 13 Sleep(rand() % 3000); 14 } 15 16 CSocket sock; 17 CString strTemp; 18 if (sock.Create()) 19 { 20 if (sock.Connect(strIP, uPort)) 21 { 22 if (uPort < 1024) 23 { 24 struct servent *se; 25 se = getservbyport(htons(uPort), _T("tcp")); 26 if (se != NULL) 27 { 28 strTemp.Format(_T("%d %s"), uPort, se->s_name); 29 } 30 else 31 { 32 strTemp.Format(_T("%d"), uPort); 33 } 34 } 35 else 36 { 37 strTemp.Format(_T("%d %s"), uPort, ptr->GetPortName(uPort, TRUE)); 38 } 39 40 ptr->m_wndTreeResult.InsertItem(strTemp, 2, 2, TreeItem); 41 sock.ShutDown(2); 42 } 43 sock.Close(); 44 } 45 46 g_iTotalThreadCount--; 47 return 0; 48 }
1 CString CPortScan_TCPDlg::GetPortName(UINT uPort, BOOL bIsTCP) 2 { 3 CString strRet; 4 if (bIsTCP) 5 { 6 switch (uPort) 7 { 8 case 1024: 9 case 1025: 10 case 1026:strRet = _T("常用动态分配的TCP端口"); break; 11 case 1080:strRet = _T("WinGate,IRC等防火墙管道"); break; 12 case 1243:strRet = _T("Sub-7木马"); break; 13 case 1433:strRet = _T("MSSQL数据库服务端口"); break; 14 case 1524:strRet = _T("ingreslock后门"); break; 15 case 2049:strRet = _T("NFS程序常用端口"); break; 16 case 3128:strRet = _T("Squid HTTP代理服务器"); break; 17 case 3306:strRet = _T("MySQL数据库服务端口"); break; 18 case 5632:strRet = _T("pcAnywere常用端口"); break; 19 case 31337:strRet = _T("Back Orifice"); break; 20 default:strRet = _T(""); break; 21 } 22 } 23 else 24 { 25 switch (uPort) 26 { 27 case 1024: 28 case 1025: 29 case 1026:strRet = _T("常用动态分配的UDP端口"); break; 30 case 31789:strRet = _T("Hack-a-tack远程访问木马"); break; 31 default:strRet = _T(""); break; 32 } 33 } 34 return strRet; 35 }
下载地址见后续博文。