Code Monkey home page Code Monkey logo

Comments (2)

kubo avatar kubo commented on May 20, 2024

Here is a sample.
It may not work because I have not tested it.
It doesn't work when the bitness (64-bit or 32-bit) of the injector process is different from that of the target process.

    DWORD pid = ...process id of the target process...;

    // find the base address of the library in the target process.
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
    if (hSnapshot == INVALID_HANDLE_VALUE) {
        ...error handling...
    }
    MODULEENTRY32 me;
    me.dwSize = sizeof(me);
    BOOL ok;
    for (ok = Module32FirstW(hSnapshot, &me); ok; ok = Module32NextW(hSnapshot, &me)) {
        if (...check `me.szModule` or `me.szExePath`...) {
            break;
        }
    }
    if (!ok) {
        ...error handling...
    }
    CloseHandle(hSnapshot);
    // `me.modBaseAddr` is the base address of the library to be uninjected.

    // Call FreeLibarry in the target process.
    HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD, FALSE, pid);
    if (hProcess == NULL) {
        ...error handling...
    }
    HMODULE kernel32 = GetModuleHandleA("kernel32");
    LPTHREAD_START_ROUTINE func_addr = (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32, "FreeLibrary");
    HANDLE hThread = CreateRemoteThead(hProcess, NULL, 0,  func_addr, me.modBaseAddr, 0, NULL);
    if (hThread == NULL) {
        ...error handling...
    }
    WaitForSingleObject(hThread, INFINITE);
    DWORD exit_code;
    GetExitCodeThread(hThread, &exit_code);
    if (exit_code == 0) {
        // FreeLibrary in the target process failed.
        ...error handling...
    }
    CloseHandle(hThread);
    CloseHandle(hProcess);

from injector.

huhuang03 avatar huhuang03 commented on May 20, 2024

Sorry for so late replay, After test, it works.

But in one situation, it does not work: the injected dll start new thread and the thread is running. In this situation, seem like did nothing.

from injector.

Related Issues (20)

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.