Here's a loader made in C#
Code:
private unsafe void SuspendInjectResume(PROCESS_INFORMATION pProcessInfo, string Dll)
{
uint Length = (uint)(Dll.Length + 1);
// Get the LoadLibrary address
UIntPtr hLoadLibrary = Native.GetProcAddress(Native.GetModuleHandle("Kernel32.dll"), "LoadLibraryA");
// Allocate space for DLL.
IntPtr pDllLocation = Native.VirtualAllocEx(pProcessInfo.hProcess, IntPtr.Zero, Length, 0x1000, 0x40);
if (pDllLocation != IntPtr.Zero)
{
// Write DLL path to process memory.
Native.WriteProcessMemory(pProcessInfo.hProcess, pDllLocation, Dll, Length, IntPtr.Zero);
}
byte[] ShellCode = {
0x9C, // PUSH ALL FLAGS
0x60, // PUSH ALL REGISTERS
0x68, 0xAA, 0xAA, 0xAA, 0xAA, // PUSH DLL ADDRESS
0xB8, 0xBB, 0xBB, 0xBB, 0xBB, // MOV EAX, pLoadLib
0xFF, 0xD0, // CALL EAX (pLoadLib)
0x61, // POP ALL REGISTERS
0x9D, // POP ALL FLAGS
0xC3 // RET
};
uint pLoadLibAddress = hLoadLibrary.ToUInt32();
uint pDllAddress = (uint)pDllLocation.ToInt32();
// Load our DLL address to the Shell Code
ShellCode[3] = (byte)(pDllAddress & 0xFF);
ShellCode[4] = (byte)((pDllAddress >> 8) & 0xFF);
ShellCode[5] = (byte)((pDllAddress >> 16) & 0xFF);
ShellCode[6] = (byte)((pDllAddress >> 24) & 0xFF);
// Load LoadLibraryA to the Shell Code
ShellCode[8] = (byte)(pLoadLibAddress & 0xFF);
ShellCode[9] = (byte)((pLoadLibAddress >> 8) & 0xFF);
ShellCode[10] = (byte)((pLoadLibAddress >> 16) & 0xFF);
ShellCode[11] = (byte)((pLoadLibAddress >> 24) & 0xFF);
// Suspend the main thread, allows us to hijack it.
Native.SuspendThread(pProcessInfo.hThread);
CONTEXT context = new CONTEXT();
context.ContextFlags = (uint)CONTEXT_FLAGS.CONTEXT_FULL;
// Get the thread context. Allows us to get access to EIP and ESP.
if (Native.GetThreadContext(pProcessInfo.hThread, ref context))
{
// Write EIP (address of next operation) to ESP-4 (stack).
UIntPtr lpBaseAddress = new UIntPtr(context.Esp - 4);
Native.WriteProcessMemory(pProcessInfo.hProcess, lpBaseAddress, &context.Eip, sizeof(uint), null);
// Allocate space for our shell code
IntPtr ShellCodeAddress = Native.VirtualAllocEx(pProcessInfo.hProcess, IntPtr.Zero, (uint)ShellCode.Length, 0x1000, 0x40);
if (ShellCodeAddress != IntPtr.Zero)
{
// Write our shell code to the application
IntPtr lpNumberBytesWritten = IntPtr.Zero;
Native.WriteProcessMemory(pProcessInfo.hProcess, ShellCodeAddress, ShellCode, ShellCode.Length, out lpNumberBytesWritten);
// Set EIP (address of next operation) to our shell code address
context.Eip = (uint)ShellCodeAddress.ToInt32();
// Update the thread flags / registers
Native.SetThreadContext(pProcessInfo.hThread, ref context);
// Resume thread from our shell code.
Native.ResumeThread(pProcessInfo.hThread);
// Executes our code and then jumps back to original code once our shellcode is done.
}
}
}
Which is used like this:
Code:
string CommandLine = PathTextBox.Text + "\\Conquer.exe blacknull";
SECURITY_ATTRIBUTES ProcessAttributes = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES ThreadAttributes = new SECURITY_ATTRIBUTES();
STARTUPINFO StartupInformation = new STARTUPINFO();
PROCESS_INFORMATION ProcessInformation = new PROCESS_INFORMATION();
Native.CreateProcess(null, CommandLine, ref ProcessAttributes, ref ThreadAttributes, false, 0x00000004, IntPtr.Zero, PathTextBox.Text, ref StartupInformation, out ProcessInformation);
Native.ResumeThread(ProcessInformation.hThread);
Native.Sleep(2000);
SuspendInjectResume(ProcessInformation, HookTextBox.Text);
And here is the Native class
Code:
using System;
using System.Runtime.InteropServices;
namespace ConquerProxy
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public unsafe struct STARTUPINFO
{
public Int32 cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public Int32 dwX;
public Int32 dwY;
public Int32 dwXSize;
public Int32 dwYSize;
public Int32 dwXCountChars;
public Int32 dwYCountChars;
public Int32 dwFillAttribute;
public Int32 dwFlags;
public Int16 wShowWindow;
public Int16 cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public unsafe byte* lpSecurityDescriptor;
public int bInheritHandle;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public uint dwProcessId;
public uint dwThreadId;
}
public enum CONTEXT_FLAGS : uint
{
CONTEXT_i386 = 0x10000,
CONTEXT_i486 = 0x10000, // same as i386
CONTEXT_CONTROL = CONTEXT_i386 | 0x01, // SS:SP, CS:IP, FLAGS, BP
CONTEXT_INTEGER = CONTEXT_i386 | 0x02, // AX, BX, CX, DX, SI, DI
CONTEXT_SEGMENTS = CONTEXT_i386 | 0x04, // DS, ES, FS, GS
CONTEXT_FLOATING_POINT = CONTEXT_i386 | 0x08, // 387 state
CONTEXT_DEBUG_REGISTERS = CONTEXT_i386 | 0x10, // DB 0-3,6,7
CONTEXT_EXTENDED_REGISTERS = CONTEXT_i386 | 0x20, // cpu specific extensions
CONTEXT_FULL = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS,
CONTEXT_ALL = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS
}
[StructLayout(LayoutKind.Sequential)]
public struct FLOATING_SAVE_AREA
{
public uint ControlWord;
public uint StatusWord;
public uint TagWord;
public uint ErrorOffset;
public uint ErrorSelector;
public uint DataOffset;
public uint DataSelector;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
public byte[] RegisterArea;
public uint Cr0NpxState;
}
[StructLayout(LayoutKind.Sequential)]
public struct CONTEXT
{
public uint ContextFlags; //set this to an appropriate value
// Retrieved by CONTEXT_DEBUG_REGISTERS
public uint Dr0;
public uint Dr1;
public uint Dr2;
public uint Dr3;
public uint Dr6;
public uint Dr7;
// Retrieved by CONTEXT_FLOATING_POINT
public FLOATING_SAVE_AREA FloatSave;
// Retrieved by CONTEXT_SEGMENTS
public uint SegGs;
public uint SegFs;
public uint SegEs;
public uint SegDs;
// Retrieved by CONTEXT_INTEGER
public uint Edi;
public uint Esi;
public uint Ebx;
public uint Edx;
public uint Ecx;
public uint Eax;
// Retrieved by CONTEXT_CONTROL
public uint Ebp;
public uint Eip;
public uint SegCs;
public uint EFlags;
public uint Esp;
public uint SegSs;
// Retrieved by CONTEXT_EXTENDED_REGISTERS
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] ExtendedRegisters;
}
public unsafe partial class Native
{
[DllImport("Kernel32.dll")]
public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, UIntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out uint lpThreadId);
[DllImport("Kernel32.dll")]
public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, Int32 dwProcessId);
[DllImport("Kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hObject);
[DllImport("Kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint dwFreeType);
[DllImport("Kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
public static extern UIntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("Kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport("Kernel32.dll")]
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, string lpBuffer, uint nSize, IntPtr lpNumberOfBytesWritten);
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("Kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern Int32 WaitForSingleObject(IntPtr handle, Int32 milliseconds);
[DllImport("kernel32.dll")]
public static extern uint ResumeThread(IntPtr hThread);
[DllImport("Kernel32.dll")]
public static extern void Sleep(uint milliSeconds);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int SuspendThread(IntPtr hThread);
[DllImport("kernel32.dll")]
public static extern bool GetThreadContext(IntPtr hThread, ref CONTEXT lpContext);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
[DllImport("kernel32.dll")]
public static extern bool SetThreadContext(IntPtr hThread,
[In] ref CONTEXT lpContext);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool WriteProcessMemory(
IntPtr hProcess,
IntPtr lpBaseAddress,
byte[] lpBuffer,
int nSize,
out IntPtr lpNumberOfBytesWritten);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool WriteProcessMemory(
IntPtr hProcess,
UIntPtr lpBaseAddress,
void *lpBuffer,
int nSize,
void *lpNumberOfBytesWritten);
[DllImport("Kernel32.dll")]
public static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CreateProcess(string lpApplicationName,
string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles,
uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,
[In] ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);
}
}
And if you need a DLL, you can check this post:
[Only registered and activated users can see links. Click Here To Register...]