开发者

How to modify external process using Python

Beginner here. I am trying to figure out how to modify a running process on a linux system using Python.

Example: I have a python program that takes in as an argument a PID. My goal is to use this PID and get info about the running process with that PID. (1) Find where it is located in memory (2) Where is the instruction pointer (3) Modify the program such that the next executed instruction is something else (4) Return the pointer back to the next legitimate instruction (5) Let the original process execute as it should have

I am trying to develop a POC to show how a small piece of code can be injected into a running process to just print 'hello' to stdout and not disturb the rest of the process.

I looked up trace and some other modules开发者_如何学Python but they all seem to do with following the currently executing python process. Also looked at pyhook, but its mainly to trap signals from keyboards etc.. additionally, I looked up pygdb a bit.

Can anyone please point me to some modules that might be useful, or some code samples. I tried googling for "python inspect process PID" etc.. did not get anything very useful.

Any help is very appreciated.

Thanks!


Also a newer python user. Can you do all these things with just the command line? If so then you could use os.system('[command]') or the subprocess module. For example you could use the pmap command to get the memory mappings. As for 2-5 I have no experience there. Good Luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜