Recovery of a Running Process

Soldato
Joined
7 Apr 2004
Posts
4,212
Hi,

Just thought i would post how this is done as it saved me a lot of hassle today during some development work and its an interesting technique.

Situation: you have a program, executed and running in memory, and *stupidly* you delete its binary. So now you are left with the program running in memory, and no source executable. I read last month on some forensics thing its a pretty simple to get back the deleted source binary of a running process (try doing that on windows!, but i guess windows doesn't let you delete a running exe in the first place :p)

Anyway heres how to do it

Code:
Start program:
[jack@tmain ~]$ ./myprog&

Delete the binary:
[jack@tmain ~]$ rm myprog

Now recover it - find PID
[jack@tmain ~]$ ps -e | grep myprog
 7884 pts/1    00:00:00 myprog

Navigate to /proc/PID and:
[jack@tmain 7884]$ ls -la | grep exe
lrwxrwxrwx   1 jack users 0 2008-07-03 20:17 exe -> /home/jack/myprog (deleted)

exe (broken link) points to where the file used to be, so stream it out to an executable file
[jack@tmain 7884]$ cat exe > ~/myprog_recovered
[jack@tmain 7884]$ chmod +x ~/myprog_recovered

I guess its entirely possible the space could be overwritten before you do the recovery, just gotta be quick to avoid corruption :)
 
(try doing that on windows!, but i guess windows doesn't let you delete a running exe in the first place :p)

No, its doable on windows as well, just a bit more complex but as you say its not trivial to delete the binary and keep the process image in memory :-)...
 
Back
Top Bottom