Skip to content

PyInjector - Inject python-code into any python process or spawn interactive python-shell inside the target process.

License

Notifications You must be signed in to change notification settings

Stanislav-Povolotsky/PyInjector

Repository files navigation

PyInjector

PyInjector - Inject python-code into any python process or spawn interactive python-shell inside the target process. Based on PyInjector by @call-042PE

How to use it?

  1. Find out what platform uses the target process (where you will inject your python code or in which context you want to spawn shell).
    You can find out it by checking "Platform" column in the task manager.
    Then select the correct version of the PyInjector:

    • on 64-bit platform
      • PyInjector_x64.dll to inject you own python code
      • PyInjector_x64_shell.dll to spawn shell in the context of the target process
    • on 32-bit platform
      • PyInjector_x86.dll to inject you own python code
      • PyInjector_x86_shell.dll to spawn shell in the context of the target process
    • on ARM64 platform
      • PyInjector_arm.dll to inject you own python code
      • PyInjector_arm_shell.dll to spawn shell in the context of the target process
  2. If you want to inject your own custom python code, write it into a file called code.py and place it in the same folder where PyInjector DLLs are located or in the current folder of the target app.

  3. Inject PyInjector DLL into the target process by using:

Why would somebody need to inject Python code into a Python script?

This project is made for reverse-engineer and malware analyst, the main aspect of this project is to reverse-engineer any python script/executable easily.
I put some usefull script in the py-code-examples/ folder that can be used to reverse-engineer any script (even with pyarmor).

Injecting own python code

You have prepared your own code.py and placed it in the same folder where PyInjector DLLs are located or in the current folder of the target app?
Perfect! Now just inject (load) PyInjector_x64.dll in the target process and and code.py will be executed.
Reminder: if the target process have no console window, do not try to print something on the screen, you will see nothing. Just open the file and write output there.

Demo: injecting code.py with System Informer

injecting code.py with Process Hacker

Demo: injecting code.py with Process Hacker

injecting code.py with Process Hacker

Spawning python-shell

Spawning interactive python shell in the any python process is easy - just inject PyInjector_x64_shell.dll / PyInjector_x86_shell.dll DLL in the target process. It should be enough to see interactive console window with python shell.
You can spawn interactive python shell even in GUI applications.

Demo: spawning python-shell with System Informer

spawning python shell with System Informer

Demo: spawning python-shell with Process Hacker

spawning python shell with Process Hacker

Compatibilities

Requirements:

  • OS: Windows 7 or later.
  • Target process must use Python3 (any version)

Example

In this video @call-042PE is unpacking a function in a pyarmor protected script with PyInjector.