Intro
This time I was in the mood for the low level stuff. The entire repository is in GitHub. It includes the installer, the actual malware program, and the uninstaller that removes it completely from your system. The malware program does nothing more severe than simply showing 3 message boxes - one by one - and exits all 3 were presented. The malware installer copies the actual malware program to C:\Windows\system32 and adds a registry key SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\SampleMalware with the value pointing to the system32. Also, the package contains the uninistaller that removes the file from the system folder and deletes the aforementioned registry key.
Code
SampleMalware.cpp:
#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow) {
for (int i = 0; i < 3; i++) {
MessageBoxW(NULL, L"This is SampleMalware.exe!", L"", MB_OK);
}
return 0;
}
SampleMalwareInstaller.cpp:
#include <Windows.h>
#include <fstream>
#include <iostream>
using std::ofstream;
void CopyFile() {
std::ifstream ifs;
std::ofstream ofs;
ifs.open("SampleMalware.exe", std::ios::binary);
ofs.open("C:\\Windows\\system32\\SampleMalware.exe", std::ios::binary);
char c;
while (true) {
c = ifs.get();
if (ifs.eof()) {
break;
}
ofs.put(c);
}
ifs.close();
ofs.close();
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Install to registry:
HKEY hKey;
LSTATUS lStatus1 =
RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0,
KEY_ALL_ACCESS,
&hKey);
if (lStatus1 != ERROR_SUCCESS) {
return 1;
}
WCHAR path[] = L"%windir%\\system32\\SampleMalware.exe";
LSTATUS lStatus2 =
RegSetValueExW(hKey,
L"SampleMalware",
0,
REG_EXPAND_SZ,
(LPBYTE) path,
sizeof(path));
if (lStatus2 != ERROR_SUCCESS) {
RegCloseKey(hKey);
return 2;
}
RegCloseKey(hKey);
// Copy SampleMalware.exe to %windir%\system32\SampleMalware.exe:
CopyFile();
return 0;
}
SampleMalwareUninstaller.cpp:
#include <Windows.h>
#include <iostream>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow) {
remove("C:\\Windows\\system32\\SoftwareMalware.exe");
RegDeleteKeyW(
HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\SampleMalware");
return 0;
}
Critique request
As always, I would like to hear any comment regarding my attempt.