c++ - 加载飞 map 像 "A device attached to the system is not functioning"

标签 c++ enclave

我正在尝试将已签名的 DLL 加载到 VBS 飞地中,但 LoadEnclaveImage 正在返回 A device attached to the system is not functioning

Hyper-V、安全启动和 TPM 2.0 都在运行,所以我不太确定错误指的是什么。

示例代码:

if (IsEnclaveTypeSupported(ENCLAVE_TYPE_VBS))
{
    DWORD lpError = 0;
    ENCLAVE_CREATE_INFO_VBS vci = { 0 };
    vci.Flags = 1;

    PVOID enclave = CreateEnclave(GetCurrentProcess(),
        NULL,
        1024 * 1024 * 2,
        NULL,
        ENCLAVE_TYPE_VBS,
        &vci,
        sizeof(ENCLAVE_CREATE_INFO_VBS),
        &lpError);

    if (enclave != NULL)
    {
        auto lib = LoadLibrary(L"kernelbase.dll");
        auto addr = (__LoadEnclaveImage)GetProcAddress(lib, "LoadEnclaveImageW");

        if (addr(enclave, L"...\testme.dll"))
        {
            printf("Worked!\n");
        }
        else {
            printf("Failed to load image\n");
            printf(GetLastErrorAsString().c_str());
        }

    }
    else
    {
        printf(GetLastErrorAsString().c_str());
    }
}
else {
    printf("VBS not supported\n");
}

最佳答案

我在加载已签名的 DLL 时遇到了同样的一般错误,因此我使用 Static Import Finder 在其他系统二进制文件中查找 LoadEnclaveImageW 的用法| ,并在加载“SgrmEnclave_secure.dll”的 SgrmBroker.exe 中找到它。尝试对该 DLL 使用 LoadEnclaveImageW 成功。

深入挖掘“SgrmEnclave_secure.dll”文件的PE结构,我们可以看到在IMAGE_LOAD_CONFIG_DIRECTORY64 structure中为EnclaveConfigurationPointer定义了一个值。 (参见 PE-bear 的 screenshot)。

这个指针指向一个IMAGE_ENCLAVE_CONFIG64 structure还有这个screenshot显示在 Ghidra 中解析时的样子。 ImportList 成员是一系列 IMAGE_ENCLAVE_IMPORT structures 的 RVA .

所以看起来这些结构需要在PE中定义。这可以使用链接器中的 /ENCLAVE 选项来完成。不确定是否有额外要求。如果您对此有更深入的了解,我很想知道。

关于c++ - 加载飞 map 像 "A device attached to the system is not functioning",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50901125/

相关文章:

c++ - 基本混淆程序

iOS:越狱手机上的安全可靠的用户响应?

windows - 将图像加载到 enclave 内存中

SGX 飞地边缘函数的 C++ 参数

c++ - 如何在 UML 中对两个 C++ 类(在不同线程中)之间的消息接口(interface)进行建模?

c++ - return *this 在 C++ 中安全吗?

c++ - 函数参数中的按位或 (|)

c++ - 为什么我的串行通过串行监视器在 Arduino IDE 上打印两次?

ios - 安全飞地 : update SecAccessControlCreateFlags after key creation

c++ - 将 2D vector 转换为 C 类型的最佳方法(对于 SGX enclave)