RpcView简介

admin 2021年10月27日06:56:42评论170 views字数 7524阅读25分4秒阅读模式
创建: 2021-10-27 09:57
http://scz.617.cn:8/windows/202110270957.txt
☆ RpcView
    1) 下载RpcView源码
    2) Visual Studio 2019 社区版
    3) Qt 5.15.2
    4) 编译RpcView源码
        4.1) 编译64位RpcView
        4.2) 运行自编译64位RpcView
        4.3) 编译32位RpcView
        4.4) 运行自编译32位RpcView
    5) 为什么需要编译RpcView源码
    6) Patch RpcView
    7) 使用RpcView
☆ 参考资源

☆ RpcView

参[3],RpcView可以逆向生成RPC接口所对应的IDL

1) 下载RpcView源码

先用git下载RpcView源码,大概13MB。

https_proxy=socks5://<ip>:<port> git clone https://github.com/silverf0x/RpcView.git RpcView

2) Visual Studio 2019 社区版

https://visualstudio.microsoft.com/zh-hans/downloads/

VS 2019社区版自带git、cmake,不需要下载安装它们,就用自带的。没让它们出现在PATH环境变量中,不喜欢动动辄往PATH中加东西。

3) Qt 5.15.2

参[4]

不确认其他Qt版本行不行,反正RpcView作者写的是VS 2019+Qt 5.15.2。

Qt 5.15不再提供离线安装包。有人从5.15.2源码自行编译,编译Windows版比较费劲,没这刚需,我选用在线安装包。

https://www.qt.io/download-qt-installer

在线安装包大约23MB。在线安装需要user/pass

RpcView简介

为编译RpcView只需很少的Qt组件,选中这些项

I have read and approve the obligations of using Open Source Qt
Disable sending pseudonymous usage statistics in Qt Creator
Associate common file types with Qt Creator (清空)
Custom installation
Archive
LTS
Qt 5.15.2
  MSVC 2019 32-bit
  MSVC 2019 64-bit
Developer and Designer Tools (不装任何子项)

RpcView简介

安装到C:Qt,装完大约2.3GB。在线安装结束后想补充安装或卸载组件,双击执行C:QtMaintenanceTool.exe

4) 编译RpcView源码

$ tree /f /a .
Z:workRpcView
|   CMakeLists.txt          // 将来需要修改
|   ...
|
+---Build                   // 自行创建的子目录
|   +---x64
|   ---x86
+---Qt
|       Qt.h
|
+---RpcCommon
|       ...
|
+---RpcCore
|   |   ...
|   |
...
|   |
|   +---RpcCore4_32bits
|   |       RpcInternals.h  // 将来需要修改
|   |
|   ---RpcCore4_64bits
|           RpcInternals.h  // 将来需要修改
|
+---RpcDecompiler
|       ....
|
---RpcView
        ...

在源码根目录自行创建Build子目录,其下有x86、x64两个子目录。

mkdir Buildx86
mkdir Buildx64

4.1) 编译64位RpcView

我不想动PATH环境变量,用VS 2019自带cmake,为编译RpcView只需cl这些命令行工具,用不上GUI。打开"x64 Native Tools Command Prompt for VS 2019"

cd /d Z:workRpcViewBuildx64
set CMAKE_PREFIX_PATH=C:Qt5.15.2msvc2019_64
cmake ../../ -A x64
cmake --build . --config Release

实际只能生成RpcView.exe,最重要的RpcDecompiler.dll未能生成,编译时提示

RpcView简介

就是说,当前代码页是936,但internalRpcDecompTypeDefs.h的698行附近出现超范围字符。这本来是"warning C4819",由于启用了/WX编译选项,变成"error C2220",导致RpcDecompiler.dll未能生成。

检视源码发现,超范围字符都在注释中,不影响二进制。最简办法是修改源码根目录下的CMakeLists.txt,删掉/WX编译选项

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
#set(CMAKE_CXX_FLAGS_RELEASE "/W4 /WX /O2 /Oi /Ot /Gy /MD /EHsc /MP")
#set(CMAKE_C_FLAGS_RELEASE "/W4 /WX /O2 /Oi /Ot /Gy /MD /EHsc /MP")
set(CMAKE_CXX_FLAGS_RELEASE "/W4 /O2 /Oi /Ot /Gy /MD /EHsc /MP")
set(CMAKE_C_FLAGS_RELEASE "/W4 /O2 /Oi /Ot /Gy /MD /EHsc /MP")

下面几种办法无法解决上述问题

chcp 437
chcp 65001
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")

执行第二条cmake命令重新编译

4.2) 运行自编译64位RpcView

cd /d Z:workRpcViewBuildx64binRelease
mkdir Greenplatforms
copy *.exe Green
copy *.dll Green
copy C:Qt5.15.2msvc2019_64binQt5Core.dll Green
copy C:Qt5.15.2msvc2019_64binQt5Gui.dll Green
copy C:Qt5.15.2msvc2019_64binQt5Widgets.dll Green
copy C:Qt5.15.2msvc2019_64binQt5WinExtras.dll Green
copy C:Qt5.15.2msvc2019_64pluginsplatformsqwindows.dll Greenplatforms
Z:workRpcViewBuildx64binReleaseGreenRpcView.exe
$ tree /f /a Green
|   Qt5Core.dll
|
   Qt5Gui.dll
|   Qt5Widgets.dll
|
   Qt5WinExtras.dll
|   RpcCore1_32bits.dll
|
   RpcCore2_32bits.dll
|   RpcCore2_64bits.dll
|
   RpcCore3_32bits.dll
|   RpcCore3_64bits.dll
|
   RpcCore4_32bits.dll
|   RpcCore4_64bits.dll
|
   RpcDecompiler.dll
|   RpcView.exe
|

---platforms
        qwindows.dll

参[5],作者演示了一种偷懒的布署方式

cd /d Z:workRpcViewBuildx64binRelease
mkdir RpcView64
copy *.exe RpcView64
copy *.dll RpcView64
C:Qt5.15.2msvc2019_64binwindeployqt.exe --release RpcView64

windeployqt.exe会向RpcView64子目录复制Qt的库文件,用不用得上都复制过去。

4.3) 编译32位RpcView

假设已经修改过根目录下的CMakeLists.txt

打开"x86 Native Tools Command Prompt for VS 2019"

cd /d Z:workRpcViewBuildx86
set CMAKE_PREFIX_PATH=C:Qt5.15.2msvc2019
cmake ../../ -A win32
cmake --build . --config Release

4.4) 运行自编译32位RpcView

cd /d Z:workRpcViewBuildx86binRelease
mkdir Greenplatforms
copy *.exe Green
copy *.dll Green
copy C:Qt5.15.2msvc2019binQt5Core.dll Green
copy C:Qt5.15.2msvc2019binQt5Gui.dll Green
copy C:Qt5.15.2msvc2019binQt5Widgets.dll Green
copy C:Qt5.15.2msvc2019binQt5WinExtras.dll Green
copy C:Qt5.15.2msvc2019pluginsplatformsqwindows.dll Greenplatforms
Z:workRpcViewBuildx86binReleaseGreenRpcView.exe
$ tree /f /a Green
|   Qt5Core.dll
|
   Qt5Gui.dll
|   Qt5Widgets.dll
|
   Qt5WinExtras.dll
|   RpcCore1_32bits.dll
|
   RpcCore2_32bits.dll
|   RpcCore3_32bits.dll
|
   RpcCore4_32bits.dll
|   RpcDecompiler.dll
|
   RpcView.exe
|
---platforms
        qwindows.dll

5) 为什么需要编译RpcView源码

https://github.com/silverf0x/RpcView

此处提供预编译好的RpcView,若在测试环境中直接可用,则无需自编译源码。参[5],执行预编译版本很可能遭遇这个提示

RpcView简介

修改这几个文件

Z:workRpcViewRpcCoreRpcCore4_64bitsRpcInternals.h
Z:workRpcViewRpcCoreRpcCore4_32bitsRpcInternals.h

假设测试环境中rpcrt4.dll的版本是10.0.14393.4704,需要在如下数组中增加这个版本信息

RpcView简介

这是某个Win10环境,若是其他OS其他rpcrt*.dll,找相应文件做类似修改。

RpcCore1 for Windows XP
RpcCore2 for Windows 7
RpcCore3 for Windows 8
RpcCore4 for Windows 8.1 and 10

cmake --build . --config Release

重新编译、运行。

6) Patch RpcView

RpcView简介

RpcView的版本检查相当保守。该软件在做Hacking,这么保守可以理解,避免进程崩溃么。但它这种搞法,每打一次rpcrt4.dll相关的补丁,就得自编译,有些受不了。

作者提到

How to add a new RPC runtime

Basically you have two possibilities to support a new RPC runtime
(rpcrt4.dll) version:

The easy way: just edit the RpcInternals.h file in the corresponding
RpcCore directories (32 and 64-bit versions) to add your runtime version
in the RPC_CORE_RUNTIME_VERSION table.

The best way: reverse the rpcrt4.dll to define the required structures
used by RpcView, e.g. RPC_SERVER, RPC_INTERFACE and RPC_ADDRESS.

对于Win10,在可以想见的相当长的时间范围内,都不需要重新逆向rpcrt4.dll去适配相关数据结构,仅仅是一个版本检查的事儿。假设手头有预编译版RpcView,着急在测试环境中用,完全可以进行二进制Patch。

$ ls -l RpcCore4*.dll
-rwxrwxrwx 1 scz scz 27648 Nov  9  2017 RpcCore4_32bits.dll
-rwxrwxrwx 1 scz scz 27648 Nov  9  2017 RpcCore4_64bits.dll

$ sha256sum RpcCore4*.dll
3a7ec71fc68fd5644269961187c7fc5e27f97c8655435cf0775670d348dbb327  RpcCore4_32bits.dll
3ec945caaeab442477823125d23b9f0f80bb1ec1e8c1581dd5ecd6c0965a0cca  RpcCore4_64bits.dll

将10.0.10240.16384这种古老版本换成10.0.14393.4704

0xA000028004000LL,  //10.0.10240.16384
0xA000038391260LL,  //10.0.14393.4704

$ python3 -c "import sys;x=sys.argv[1];print(''.join(map(str.__add__,x[-2::-2],x[-1::-2])))" 0A000028004000
0040002800000A

$ python3 -c "import sys;x=sys.argv[1];print(''.join(map(str.__add__,x[-2::-2],x[-1::-2])))" 0A000038391260
6012393800000A

用WinHex打开RpcCore4_64bits.dll、RpcCore4_32bits.dll,搜索"0040002800000A",将之替换成"6012393800000A"。

$ fc /b RpcCore4_32bits.dll.orig RpcCore4_32bits.dll
00005AC0: 00 60
00005AC1: 40 12
00005AC2: 00 39
00005AC3: 28 38

$ fc /b RpcCore4_64bits.dll.orig RpcCore4_64bits.dll
00005AC0: 00 60
00005AC1: 40 12
00005AC2: 00 39
00005AC3: 28 38

执行Patch过的预编译RpcView成功。

7) 使用RpcView

参[5],我是看到这篇才注意到RpcView的,毕竟很多年不挖洞。

RpcView简介

a) 以管理员身份运行RpcView.exe,在Process框中找目标进程,比如lsass.exe
b) 在Interfaces框中选接口,Procedures框中出现相应接口的远程过程列表
c) 在Interfaces框中选中某个接口后,右键Decompile,在Decompilation框中出现
   相应接口的IDL
d) RpcView支持微软符号,[5]的作者说不支持符号服务器,只支持符号目录,可能得提前下载符号Options->Configure Symbols->srv*z:sym*http://msdl.microsoft.com/download/symbols

RpcView生成的IDL不错。十几年前自己写过rpcdig.idc,用来挖MS/DCE RPC的洞。后来开发Nessus的Tenable公司公开过一个IDA插件mIDA,从PE中逆向生成IDL,效果非常好,风靡一时。

https://github.com/tenable/mIDA
https://github.com/sourceincite/tools/tree/master/pymsrpc/mIDA

mIDA is an IDA plugin which extracts RPC interfaces and recreates the
associated IDL file. mIDA supports inline, interpreted and fully
interpreted server stubs.

mIDA only works with the Windows GUI version of IDA (5.2 or later).

mIDA是C++写的,后来没再更新过,估计早已不能适配高版本IDA。RpcView是个很不错的替代品。

我现在拿RpcView当交互式调试工具用,不挖洞、不Fuzz,但更多人可能有RPC挖洞需求,[5]值得一阅,早看过的当我没说。

下次举例写一下如何用RpcView辅助调试。

☆ 参考资源

[3] RpcView
    https://github.com/silverf0x/RpcView

[4] Qt
    https://download.qt.io/archive/qt/5.15/5.15.2/
    https://www.qt.io/download-qt-installer

[5] 尝试进行RPC漏洞挖掘 - houjingyi [2019-01-09]
    https://cert.360.cn/report/detail?id=44669690fc7a8daab42472cebd8cfb88


原文始发于微信公众号(青衣十三楼飞花堂):RpcView简介

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年10月27日06:56:42
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   RpcView简介http://cn-sec.com/archives/600753.html

发表评论

匿名网友 填写信息