Giter Club home page Giter Club logo

dllhook's Introduction

dllhook

PyPI version
dllhook is a tool for hooking Windows x86 applications. This tools injects embedded Python interpreter (Python DLL) to the application and executes your script. And also this provides a convenient hooking library to use in your script.
This tool uses mayhem python_injector as injector.
See https://github.com/zeroSteiner/mayhem/blob/master/tools/python_injector.py
When you clone this repository, you must also clone submodule mayhem.
This tool is tested on Python 3.6-3.11.

Installation

Make sure you use 32-bit version of Python.

To install dllhook:

pip install dllhook

Usage

  • Write your python script to inject.
import ctypes
import dllhook

# @dllhook.hook_dll('Kernel32.dll', 0x00014510) also works
@dllhook.hook_dll('Kernel32.dll', b'CreateProcessW')
def see_process(arg1):
    if arg1 != 0:
        print("<hooked> ", ctypes.wstring_at(arg1))
  • Save it as a file. (e.g. C:\Users\example\Desktop\see_process.py)

  • Execute the module dllhook with the target program and your script as the arguments.

python -mdllhook "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" C:\Users\example\Desktop\see_process.py

Console output:

[+] Opened a handle to pid: 24308
[*] Found Python library at: C:\Users\example\AppData\Local\Programs\Python\Python36-32\python36.dll
[*] Injecting Python into the process...
[+] Loaded C:\Users\example\AppData\Local\Programs\Python\Python36-32\python36.dll with handle 0x69ee0000
[*] Resolved addresses:
  - Py_InitializeEx:    0x6a061cc0
  - PyRun_SimpleString: 0x6a07b1c0
[*] Initialized Python in the host process
[*] Waiting for client to connect on \\.\pipe\mayhem
[*] Client connected on named pipe
target: 0x75ae4510
invoke: 0x6c401df0
callbacker: 0x6620fdc
<hooked> C:/Program Files (x86)/Adobe/Acrobat Reader DC/Reader/ARH.exe
<hooked> C:\Program Files (x86)\Common Files\Adobe\ARM\1.0\AdobeARM.exe

Author

cosine0 @github

dllhook's People

Contributors

cosine0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dllhook's Issues

OSError: [WinError 6] ERROR_INVALID_HANDLE

(py37u32) K:\Program\Code\Python\Others>python -mdllhook "C:\Program Files (x86)\RedisDesktopManager\rdm.exe" test.py
[+] Opened a handle to pid: 11908
[] Found Python library at: C:\ProgramData\Anaconda3\envs\py37u32\python37.dll
[
] Injecting Python into the process...
[+] Loaded C:\ProgramData\Anaconda3\envs\py37u32\python37.dll with handle 0x5ea30000
[*] Resolved addresses:

  • Py_InitializeEx: 0x5eb80994
  • PyRun_SimpleString: 0x5eb91507
    [] Initialized Python in the host process
    [
    ] Waiting for client to connect on \.\pipe\mayhem
    Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\envs\py37u32\lib\site-packages\dllhook\mayhem\tools\python_injector.py", line 214, in
    main()
    File "C:\ProgramData\Anaconda3\envs\py37u32\lib\site-packages\dllhook\mayhem\tools\python_injector.py", line 202, in main
    client = NamedPipeClient.from_named_pipe(PIPE_NAME)
    File "C:\ProgramData\Anaconda3\envs\py37u32\lib\site-packages\dllhook\mayhem\tools\python_injector.py", line 139, in from_named_pipe
    raise ctypes.WinError()
    OSError: [WinError 6] ERROR_INVALID_HANDLE。

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.