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

VirtualAlloc / Ошибка с доступом к памяти при сокрытии импорта

1692058182734.png
 
Good day. ran into the problem below. If you don't touch anything, it works perfectly. Designed a universal good for this case. Everything works with msjboxes, open processes, etc.
But when allocating memory with VirtualAlloc, an error occurs, which is not present with a standard call. Maybe someone knows, tell me please.

C++:
LPVOID(__stdcall* MyVirtualAlloc)(LPVOID, SIZE_T, DWORD, DWORD);

int(__stdcall* MyMessageBoxA)(HWND, LPCSTR, LPCSTR, UINT);

FARPROC LoadFunction(const char* libraryName, const char* functionName) {
    HMODULE hLibrary = GetModuleHandleA(libraryName);
    if (!hLibrary) {
        hLibrary = LoadLibraryA(libraryName);
        if (hLibrary) {
            return GetProcAddress(hLibrary, functionName);
        }
    }
    return nullptr;
}
void connect() {
    MyVirtualAlloc = reinterpret_cast<LPVOID(__stdcall*)(LPVOID, SIZE_T, DWORD, DWORD)>(LoadFunction("kernel32.dll", "VirtualAlloc"));
    MyMessageBoxA = reinterpret_cast<int(__stdcall*)(HWND, LPCSTR, LPCSTR, UINT)>(LoadFunction("user32.dll", "MessageBoxA"));
}

Посмотреть вложение 63274
Hello.
Your code doesn't provide enough information to explain why it is failing. Based on the error message it appears it is saying MyVirtualAlloc is an invalid pointer. You need to check the return value of LoadFunction.

C++:
void connect() {

    MyVirtualAlloc = reinterpret_cast<LPVOID(__stdcall*)(LPVOID, SIZE_T, DWORD, DWORD)>(LoadFunction("kernel32.dll", "VirtualAlloc"));

    MyMessageBoxA = reinterpret_cast<int(__stdcall*)(HWND, LPCSTR, LPCSTR, UINT)>(LoadFunction("user32.dll", "MessageBoxA"));
    
    if(!MyVirtualAlloc || !MyMessageBoxA)
    {
        //handle error here
        return;
    }
    
}

I have done something in my VX-API. Here is a snippet of my code:

C++:
BOOL IsIntelHardwareBreakpointPresent(VOID)
{
    BOOL bFlag = FALSE;
    PCONTEXT Context = NULL;

    Context = (PCONTEXT)VirtualAlloc(NULL, sizeof(CONTEXT), MEM_COMMIT, PAGE_READWRITE);
    if (Context == NULL)
        return FALSE;

    RtlZeroMemory(Context, sizeof(Context));

    Context->ContextFlags = CONTEXT_DEBUG_REGISTERS;

    if (!GetThreadContext(GetCurrentThreadNoForward(), Context))
        goto EXIT_ROUTINE;

    if (Context->Dr0 || Context->Dr1 || Context->Dr2 || Context->Dr3)
        bFlag = TRUE;

EXIT_ROUTINE:

    if (Context)
        VirtualFree(Context, 0, MEM_RELEASE);

    return bFlag;
}
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Очевидно же. GetModuleHandle возвращает не NULL для kernel32.dll, но в этом случае функция LoadFunction возвращает NULL, что неверно.
 
Спасибо. разобрался. не актуально.
Это хорошо что ты разобрался, но, для чего удалять было вопрос и почему не напишешь решения для других пользователей?
 
Это хорошо что ты разобрался, но, для чего удалять было вопрос и почему не напишешь решения для других пользователей?
А короче. Я просто убрал те ифы, которые не нужны.
 


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