Contents

[从零开始的免杀生活]05.销声匿迹·上

0x00.序

上篇介绍了分离免杀,但是只是给了个思路,后续我会将代码打包到 Github 上 这期讲讲 SRDI

0x01.什么是sRDI?

官方Github介绍

sRDI allows for the conversion of DLL files to position independent shellcode. It attempts to be a fully functional PE loader supporting proper section permissions, TLS callbacks, and sanity checks. It can be thought of as a shellcode PE loader strapped to a packed DLL.

翻译:

sRDI 允许将 DLL 文件转换为位置独立的 shellcode。它试图成为一个功能齐全的 PE 加载器,支持适当的部分权限、TLS 回调和健全性检查。它可以被认为是绑定到打包 DLL 的 shellcode PE 加载器。

一般认为就是将dll在内存中加载,相当于模拟win系统加载dll的操作。我们可以将恶意代码写成dll 然后用 sRdi 转成Shellcode 这样就省一步我们写ShellCode。毕竟手写Shellcode还是比较麻烦的,毕竟还需要自己定义函数然后还要避开常量字符串。但如果有想了解手搓Shellcode的可以看我博客的另一篇文章,最近在github还上传了x64版本的代码,有兴趣的可以给个star。Github链接:https://github.com/Tupler/ShellCodeGet

0x02.使用方法

srdi的Github:https://github.com/monoxgas/sRDI 这里就不详细说内部代码是如何写的了。毕竟这个专栏是讲免杀,sRDI原理涉及 PE WINAPI 等等内容。感兴趣的可以自行看他的代码

主要讲讲使用,官方github提供usage

这里使用Python版本的usage

 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    usage: ConvertToShellcode.py [-h] [-v] [-f FUNCTION_NAME] [-u USER_DATA] [-c] [-b] [-i] [-d IMPORT_DELAY]
                                [-of OUTPUT_FORMAT]
                                input_dll

    RDI Shellcode Converter

    positional arguments:
    input_dll             DLL to convert to shellcode

    options:
    -h, --help            show this help message and exit
    -v, --version         show program's version number and exit
    -f FUNCTION_NAME, --function-name FUNCTION_NAME
                            The function to call after DllMain
    -u USER_DATA, --user-data USER_DATA
                            Data to pass to the target function
    -c, --clear-header    Clear the PE header on load
    -b, --pass-shellcode-base
                            Pass shellcode base address to exported function
    -i, --obfuscate-imports
                            Randomize import dependency load order
    -d IMPORT_DELAY, --import-delay IMPORT_DELAY
                            Number of seconds to pause between loading imports
    -of OUTPUT_FORMAT, --output-format OUTPUT_FORMAT
                            Output format of the shellcode (e.g. raw,string)

下图是我们的测试DLL代码 https://z1.ax1x.com/2023/09/20/pP5h4vq.jpg

先默认转换 DllMain

python ConvertToShellcode.py .\export.dll

转换后会生成 文件名.binraw Shellcode 也就是纯二进制版本的shellcode,我们可以用hex编辑软件或者自己写脚本将内容转为代码.

转换后用加载器加载,由于没有那种方便的测试的加载器,我就自己用MFC手搓了一个。

https://z1.ax1x.com/2023/09/20/pP5vN90.jpg

可以看到成功加载了我们的DLL

注意: 在DllMain中是无法继续调用LoadLibrary ,在加载DLL时操作系统会使用LdrpLoaderLock 给DllMain的线程上锁

使用导出函数

可以在导出函数中写上我们要执行的恶意代码 例子:

EXTERN_C __declspec(dllexport) void Test() {

MessageBox(NULL, TEXT("导出函数~"),TEXT("Export!"), MB_OK);
}

转换命令为:

python ConvertToShellcode.py -f bypass .\export.dll

可以加上-i -c 来混淆, -i 为混淆导入表 -c 为在加载的时候清除PE头信息

https://z1.ax1x.com/2023/09/20/pPICDHO.jpg

0x03.总结

sRdi配合前几篇的内容可以很好的对杀软进行致盲。