Coder Social home page Coder Social logo

htp's People

Contributors

ek0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

htp's Issues

Implement interlock var access

The return_stack unordered_map can be dangerous with multiple threads:

e.g:

void CreateFileWHook(HTPContext* ctx)
{
}


void CreateFileWPostHook(HTPContext* ctx)
{
}

void NtCreateFileHook(HTPContext* ctx)
{
}


void NtCreateFilePostHook(HTPContext* ctx)
{
}

VOID MyThreadFunction(VOID)
{
    Sleep(1);
    HANDLE hFile = CreateFile("roux.bmp",
            GENERIC_WRITE,
            0,
            NULL,
            CREATE_NEW,
            FILE_ATTRIBUTE_NORMAL,
            NULL);
    Sleep(1);
    printf("[%d] Bye bye\n", GetCurrentThreadId());
}

/*
....
*/
int main(int argc, char** argv)
{
    HTPHandle handle;

    HTPInit(&handle);
    SetupInlineHook(&handle, "kernel32.dll", "CreateFileW", CreateFileWHook, CreateFileWPostHook);
    SetupInlineHook(&handle, "ntdll.dll", "NtCreateFile", NtCreateFileHook, NtCreateFilePostHook);

    std::queue<HANDLE> thqueue;
    for (int i = 0; i < 0x2000; i++) {
        DWORD dwThreadId;
        HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MyThreadFunction, NULL, 0, &dwThreadId);
        if (hThread != NULL) {
            thqueue.push(hThread);
        }
    }
    while (!thqueue.empty()) {
        WaitForSingleObject(thqueue.front(), INFINITE);
        thqueue.pop();
    }
    printf("GOOD!\n");
}

edge cases

Problème de reconstruction des instructions lors du setup d'un hook:

Exemple 1 (BRANCH):

test rcx, rcx
jz XXXX

Exemple 2 (RIP relatif):

mov    REG, QWORD PTR [rip+0x4241]

Type confusion in RemoveInlineHookInternal leads to memory corruption

The following cast is made in RemoveInlineHookInternal:

trampoline = (HTPTrampoline*)hook_entry->trampoline_address;

However, the trampoline in question can be of two types, either HTPTrampoline or HTPReturnTrampoline.
These two types have different memory layouts so the following line might copy garbage when the removed trampoline is of type HTPReturnTrampoline:

memcpy((char*)hook_address, trampoline->saved_opcodes, hook_entry->number_of_opcodes);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.