visualstudio 一键 RCE

admin 2023年10月31日01:30:40评论33 views字数 2058阅读6分51秒阅读模式

技术原理

在打开一个项目后,VisualStudio会在项目的根目录中自动生成一个.vs文件夹,其中包含一个名为.soo的特殊二进制文件。

  1. 当环境打开.soo文件时,它会枚举当前加载的所有VSPackages。如果VSPackage实现IVsPersistSolutionOpts接口,则环境会调用VSPackage上的LoadUserOptions方法,要求它从.suo文件加载所有数据。

参考文档地址:https://learn.microsoft.com/en-us/visualstudio/extensibility/internals/solution-user-options-dot-suo-file?view=vs-2022

这意味着加载.suo文件时将调用IVsPersistSolutionOpts#LoadUserOptions函数。通过检查实现OnLoadOptions的VSPackage,我们可以找到VSCorePackage。

  1. // Microsoft.VisualStudio.dll

  2. // Microsoft.VisualStudio.VSCorePackage

  3. protected override void OnLoadOptions(string name, Stream stream)

  4. {

  5. if (name.Equals(typeof(VsToolboxService).Name))

  6. {

  7. VsToolboxService vsToolboxService = this.GetService(typeof(IToolboxService)) as VsToolboxService;

  8. if (vsToolboxService != null)

  9. {

  10. vsToolboxService.LoadOptions(stream); // [1]

  11. }

  12. }

  13. }

VSCorePackage将把Stream传递给OptionService并调用vsToolboxService.OnLoadOptions

  1. // Microsoft.VisualStudio.Toolbox.VsToolboxService

  2. internal void LoadOptions(Stream stream)

  3. {

  4. BinaryReader binaryReader = new BinaryReader(stream);

  5. BinaryFormatter binaryFormatter = new BinaryFormatter();

  6. int num = binaryReader.ReadInt32();

  7. for (int i = 0; i < num; i++)

  8. {

  9. string text = binaryReader.ReadString();

  10. int num2 = binaryReader.ReadInt32();

  11. for (int j = 0; j < num2; j++)

  12. {

  13. string text2 = this.Links.Read(stream);

  14. VsToolboxService.ToolboxItemContainer toolboxItemContainer = (VsToolboxService.ToolboxItemContainer)binaryFormatter.Deserialize(stream); // [2]

  15. if (text2 != null && File.Exists(text2))

  16. {

  17. toolboxItemContainer.LinkFile = text2;

  18. this.Links.TrackLink(text2);

  19. this.Items.GetFilteredList(text).Add(toolboxItemContainer);

  20. }

  21. }

  22. }

  23. }

然后LoadOptions调用BinaryFormatter.Descialize从Stream中获取对象。这是BinaryFormatter反序列化的常见用法。由于类型限制不足,我们可以直接使用ysosserial.net生成有效负载,并尝试将其写入.suo文件。在Visual Studio中打开项目时,恶意的.suo文件将自动加载并触发calc.exe的执行。

Exp构造

项目结构:

  1. $ tree -a

  2. .

  3. ├── App1

  4.    └── Form1.cs

  5. ├── App1.sln

  6. └── .vs

  7. └── App1

  8. └── v17

  9. └── .suo

理论上,这个项目可能会更小,但就目前而言,这应该已经足够了。与纯文本.sln或.csproj文件相比,.suo是隐藏的(默认情况下,文件资源管理器中不会显示以.开头的文件夹和文件),其内容更难读取。描述该文件结构的文档也很有限,即使仔细检查也很容易忽略。

此外,由于Visual Studio在关闭时将新内容保存到.suo文件中的行为,exp内容被清除,从而为这种利用技术提供了自然的隐藏。此外,此特性可确保漏洞不会被多次触发。

visualstudio 一键 RCE


公众号内回复:visual_stdio_rce,获取pof,技术分享供学习为主。

原文始发于微信公众号(TIPFactory情报工厂):visualstudio 一键 RCE

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年10月31日01:30:40
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   visualstudio 一键 RCEhttps://cn-sec.com/archives/2160540.html

发表评论

匿名网友 填写信息