topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Recovering from Proc

May 7, 2002, 12:00 AM —  ITworld — 

I was sitting on my laptop looking at a movie [1] of my daughter Reegen
in her hula skirt on our trip to Hawaii this January. She and Allison,
the daughter of one of our friends, were playing "Ring around the
Rosey" and it was terribly cute.

Unfortunately, in a not-rare-enough multitasking mistake, I
accidentally deleted the movie I was watching! I was in the /movies
directory, and wanted to delete mvi_051*.avi and accidentally typed 'rm
mvi_051 *.avi', wiping out all my movies! No! It's not fair! I hadn't
made backups of the file yet and hadn't yet posted it to my Web site. A
beautiful moment lost. What was I to do? [2]

No problem, lsof and /proc to the rescue. I had lsof (List Open Files,
one of the must-haves in your UNIX administration and security
toolboxes) show me the open files for the mplayer [3] process:

$ lsof -c mplayer | grep avi
mplayer 10153 bri 10r REG 3,7 2545962 26708 /movies/hula.avi
(deleted)

This shows that mplayer (process 10153) has /movies/hula.avi opened on
file descriptor 10. (The rest of the data describe the device it's on,
size of file, etc....) The '(deleted)' at the end signifies that the
file has been deleted from disk. However, Linux files aren't actually
removed from the disk until all open file descriptors are closed and
all hard links to the data are removed. Thus, the file was still there;
I just couldn't get it by looking in the /movies directory because the
hula.avi name had been removed.

However it's still possible to get at the file. All I needed to do was:

$ cp /proc/10153/fd/10 /tmp/hula_recoved.avi

The /proc filesystem is not an actual directory on disk like /usr
or /home. Instead, /proc is a directory-based view of information the
kernel makes available to you. The programs ps or top, for example,
look in this directory for process ids and program names, and then
presents them in a pretty form. The files and directories in
the /proc/10153 directory refer to the process 10153 (mplayer). A quick
list shows us:

$ ls -F /proc/10153/fd
0@ 1@ 10@ 12@ 2@ 3@ 4@ 5@ 6@ 7@ 8@ 9@

$ ls -l /proc/10153/fd/10
lr-x------ 1 bri hle Apr 30 10:39 10 -> /tmp/reegen_hula.avi
(deleted)

The fd (file descriptor) directory has maps to the files open by the
program. So you can see that there are many file descriptors open (0,
1, 2... 10, and 12), /proc tries to show information in the most useful
UNIX-like way. Although it looks like /proc/10153/fd/10 is a symlink to
the file '/tmp/reegen_hula.avi (deleted)', when you try to copy this
file, it will give you the actual bits still on disk because the file
hasn't been permanently removed from the hard drive.

So, what does this have to do with security?

One common trick malicious hackers use is to open a file and
immediately delete it, such that the file is not visible on the machine
to tools like find/locate/etc. This also means that, if the machine is
rebooted, then the file disappears as well. Until the program stops,
the file is still completely usable to itself. It may be a temporary
storage space for lists of machines to compromise, copies of newly
downloaded attack scripts, or captured passwords to be sent back to the
attacker. Using deleted files is an easy method to avoid detection from
most administrators, and automatically removes any incriminating files
in the event an admin figures something is amiss and kills the process
or reboots the machine.

Next week, I'll show you a few other related /proc and lsof tidbits
that can be useful at preventing people from using this trick against
you. But for now, remember that if you delete something but still have
it open, you have an alternative to misery. In the event that the
deleted item is a cute movie of your daughter, you'll understand the
need.

NOTES
[1] http://www.hackinglinuxexposed.com/articles/hula.html
[2] If this drive were an ext filesystem, I may have been able to
recover all the files using e2undel
(http://e2undel.sourceforge.net/) or other similar tools.
Unfortunately I have most of my partitions formatted with
ReiserFS. Fortunately, the rest of the movies were already
backed up.
[3] Mplayer, a great Linux movie player, at
http://www.mplayerhq.hu/homepage/

» posted by ITworld staff

ITworld

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources