PyInjector - Inject python-code into any python process or spawn interactive python-shell inside the target process. Based on PyInjector by @call-042PE
-
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
- on 64-bit platform
-
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.
-
Inject PyInjector DLL into the target process by using:
- Injector (Download)
- System Informer (Download)
- Process Hacker (Download)
- or any other DLL injection tool
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.
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).
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.
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.
- In this video @call-042PE is unpacking a function in a pyarmor protected script with PyInjector.
- Solving Reverse Engineering CTF tasks using PyInjector (writeup by @kos0ng)
- Article: How to dump packed Python code (by Ziyue / Equinox-shame)
- 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.