DEV Community

Cover image for Inject code in Python process
petercour
petercour

Posted on

Inject code in Python process

Python is widely used for software development. By universities, companies and many more. So is Python an utopia that will solve all computer problems?

Did you know you can inject code into a running Python process? You can use Pyrasite for that. This needs Python 2.4 or higher.

You can watch a demo here: demo

It comes with several programs, including a shell

$ pyrasite-shell
Usage: pyrasite-shell <PID>
Enter fullscreen mode Exit fullscreen mode

So you can inject a payload

$ pyrasite <PID> payload.py
Enter fullscreen mode Exit fullscreen mode

You can find some example payloads here.

So if you have the process id , you can inject anything into the running program.

There's also a GUI. It lets you easily monitor, analyze, introspect, and alter running Python programs.

Related links:

Top comments (0)