Skip to content

Latest commit

 

History

History
87 lines (61 loc) · 5.46 KB

README.md

File metadata and controls

87 lines (61 loc) · 5.46 KB

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:

Compatibilities

Requirements:

  • Target process must use Python 3 (any version) or Python 2 (implemented only limited support)
  • OS: Windows 7 or later
    (for Windows XP support: you still can compile it with Visual Studio 2015 or use precompiled binaries from PyInjector 1.1)

Limits:

  • Release binaries are compiled for Windows 7+, please use Visual Studio 2015 to build solution with Windows XP support.
  • Python 2 support limits:
    • Only processes, which have more than a one thread are supported (because multithreading support should be initialized in the main thread. See example)
    • SpawnShell mode: stdout is locked while processing raw_input(), so target output of the target application will be suspended until you press enter.

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

Examples

How to build

  • Open solution PyInjector.sln in Visual Studio 2015 / 2017 / 2019 / 2022, select required configuration and platform (for example "Release" "x64") and run "Build / Build Solution".
  • Or just open "Developer Command Prompt" or "Native Tools Command Prompt for VS 20xx" and run build.windows.ps1 from the project directory.