Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static injEctHelper.imports;
  10. using injEctHelper;
  11. using System.ComponentModel;
  12.  
  13. namespace injEctHelper
  14. {
  15.     class injector
  16.     {
  17.         // privileges
  18.         const int PROCESS_CREATE_THREAD = 0x0002;
  19.         const int PROCESS_QUERY_INFORMATION = 0x0400;
  20.         const int PROCESS_VM_OPERATION = 0x0008;
  21.         const int PROCESS_VM_WRITE = 0x0020;
  22.         const int PROCESS_VM_READ = 0x0010;
  23.  
  24.         IntPtr pHandle;
  25.         IntPtr Libaddr;
  26.         // used for memory allocation
  27.         const uint MEM_COMMIT = 0x00001000;
  28.         const uint MEM_RESERVE = 0x00002000;
  29.         const uint PAGE_READWRITE = 4;
  30.  
  31.         public injector(string proc_name)
  32.         {
  33.             Process proc = Process.GetProcessesByName(proc_name)[0];
  34.             Console.WriteLine("pId: "+proc.Id);
  35.             IntPtr pHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, proc.Id);
  36.             Console.WriteLine("Proc handle: "+ pHandle.ToString());
  37.             IntPtr Libaddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  38.         }
  39.      
  40.         public void Injector(string dll)
  41.         {
  42.  
  43.             try
  44.             {
  45.                 IntPtr allocMem = VirtualAllocEx(pHandle, IntPtr.Zero, (uint)((dll.Length + 1) * Marshal.SizeOf(typeof(char))), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  46.                 UIntPtr bytesWritten;
  47.                 WriteProcessMemory(pHandle, allocMem, Encoding.Default.GetBytes(dll), (uint)((dll.Length + 1) * Marshal.SizeOf(typeof(char))), out bytesWritten);
  48.  
  49.                 CreateRemoteThread(pHandle, IntPtr.Zero, 0, Libaddr, allocMem, 0, IntPtr.Zero);
  50.             }
  51.             catch
  52.             {
  53.                 throw new Win32Exception(Marshal.GetLastWin32Error());
  54.             }
  55.            
  56.         }
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement