Skip to content

Commit

Permalink
Process injector.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demion committed Feb 2, 2018
1 parent 14ff160 commit b57d7cf
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion nodevfee/Source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Windows.h>
#include <TlHelp32.h>
#include <stdio.h>

static void Error(const char *format, int result)
Expand Down Expand Up @@ -26,7 +27,7 @@ static void InjectDll(HANDLE process, const wchar_t *dllName)

if (remoteString != 0)
{
if (WriteProcessMemory(process, remoteString, dllName, length - sizeof(wchar_t), 0))
if (WriteProcessMemory(process, remoteString, dllName, length, 0))
{
HANDLE thread = CreateRemoteThread(process, 0, 0, (LPTHREAD_START_ROUTINE) loadLibrary, remoteString, 0, 0);

Expand All @@ -53,6 +54,8 @@ static void InjectDll(HANDLE process, const wchar_t *dllName)
Error("WaitForSingleObject error #%X", GetLastError());
}

VirtualFreeEx(process, remoteString, 0, MEM_RELEASE);

CloseHandle(thread);
}
else
Expand Down Expand Up @@ -108,6 +111,76 @@ int wmain(int argc, wchar_t *argv[])
Error("CreateProcessW error #%X", GetLastError());
}
}
else
{
FILE *injectFile = fopen("nodevfeeInject.txt", "r");

if (injectFile)
{
wchar_t processName[256] = {0};

fscanf(injectFile, "%ls", processName);

fclose(injectFile);

if (wcslen(processName) > 0)
{
unsigned int processId = 0;

while (true)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (snapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32W entry = {0};

entry.dwSize = sizeof(entry);

if (Process32FirstW(snapshot, &entry))
{
do
{
if (wcscmp(entry.szExeFile, processName) == 0)
{
if (entry.th32ProcessID != processId)
{
processId = entry.th32ProcessID;

HANDLE process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, false, processId);

if (process != 0)
{
InjectDll(process, L"nodevfeeDll.dll");

CloseHandle(process);

printf("\"%ls\" [%d] -> \"nodevfeeDll.dll\"\n", processName, processId);
}
else
{
Error("OpenProcess error #%X", GetLastError());
}
}
}
}
while (Process32NextW(snapshot, &entry));
}
else
{
Error("Process32FirstW error #%X", GetLastError());
}
}
else
{
Error("CreateToolhelp32Snapshot error #%X", GetLastError());
}

Sleep(1000);
}
}
}
}

return EXIT_SUCCESS;
}

0 comments on commit b57d7cf

Please # to comment.