LinuxSecurity.com
Share your story
The central voice for Linux and Open Source security news
Home News Topics Advisories HOWTOs Features Newsletters About Register

Welcome!
Sign up!
EnGarde Community
Login
Polls
How strictly do your users obey your security policies?
 
Advisories
Community
Linux Events
Linux User Groups
Link to Us
Security Center
Book Reviews
Security Dictionary
Security Tips
SELinux
White Papers
Featured Blogs
Emily Ratliff: OS Security
DanWalsh LiveJournal
Security Bloggers Network
Latest Newsletters
Linux Security Week: November 17th, 2008
Linux Advisory Watch: November 14th, 2008
Subscribe
LinuxSecurity Newsletters
E-mail:
Choose Lists:
About our Newsletters
RSS Feeds
Get the LinuxSecurity news you want faster with RSS
Powered By

  
Linux Data Hiding and Recovery Print E-mail
User Rating:      How can I rate this item?
Features Just when you thought your data was removed forever, Anton Chuvakin shows us how to recover data and even how data can surruptitiously be hidden within space on the filesystem.

It is common knowledge that what is deleted from the computer can sometimes be brought back. Recent analysis of security implications of "alternative datastreams" on Windows NT by Kurt Seifried has shown that Windows NTFS filesystem allows data hiding in "alternative datastreams" connected to files. These datastreams are not destroyed by many file wiping utilities that promise irrecoverable removal of information. Wiping the file means "securely" deleting it from disk (unlike the usual removal of file entries from directories), so that file restoration becomes extremely expensive or impossible.

Some overview of what remains on disk after file deletion, how it can be discovered and how such discovery can be prevented are provided in Secure Deletion of Data from Magnetic and Solid-State Memory by Peter Gutmann. The author recommends overwriting files multiple times with special patterns. Against casual adversaries, simply overwriting the file with zeros once will help.

Linux has no alternative data streams, but files removed using /bin/rm still remain on the disk. Most Linux systems uses the ext2 filesystem (or its journaling version, ext3 by Red Hat). A casual look at the design of the ext2 filesystem shows several places where data can be hidden.

Let us start with the classic method to hide material on UNIX filesystems (not even ext2 specific). Run a process that keeps the file open and then remove the file. The file contents are still on disk and the space will not be reclaimed by other programs. It is worthwhile to note that if an executable erases itself, its contents can be retrieved from /proc memory image: command "cp /proc/$PID/exe /tmp/file" creates a copy of a file in /tmp.

If the file is removed by /bin/rm, its content still remains on disk, unless overwritten by other files. Several Linux unerase utilities including e2undel recover attempt automated recovery of files. They are based on Linux Ext2fs Undeletion mini-HOWTO that provides a nice guide to file recovery from Linux partitions. Recovery can also be performed manually using debugfs Linux utility (as described in the above HOWTO).

Overall, if recovery is attempted shortly after file removal and the partition is promptly unmounted, chances of complete recovery are high. If the system was heavily used, the probability of successful data undeletion significantly decreases. However, if we are to look at the problem from the forensics point of view, the chances of recovering something (such as a small part of the illegal image for the prosecution) is still very high. It was reported that sometimes parts of files from several years ago are found by forensic examiners.

Thus files can be hidden in free space. If many copies of the same file are saved and then erased, the chance of getting the contents back becomes higher using the above recovery methods. However, due to the intricacies of ext2 filesystem, the process can only be reliably automated for small files.

A more detailed look at ext2 internals reveals the existence of slack space. Filesystem uses addressable parts of disk called blocks, that have the same size. Ext2 filesystems typically use 1,2 or 4 KB blocks. If a file is smaller than the block size, the remaining space is wasted. It is called slack space. This problem long plagued early Windows 9x users with FAT16 filesystems, which had to use block sizes of up to 32K, thus wasting a huge amount of space if storing small files.

On a 4GB Linux partition, the block size is typically 4K (chosen automatically when the mke2fs utility is run to create a filesystem). Thus one can reliably hide up to 4KB of data per file if using a small file. The data will be invulnerable to disk usage, invisible from the filesystem, and, which is more exciting for some people, undetectable by file integrity checkers using file checksumming algorithms and MAC times. Ext2 floppy (with a block size of 1KB) allows hiding data as well, albeit in smaller chunks.

The obscure tool bmap exists to jam data in slack space, take it out and also wipe the slack space, if needed. Some of the examples follow:

# echo "evil data is here" | bmap --mode putslack /etc/passwd
puts the data in slack space produced by /etc/passwd file

# bmap --mode slack /etc/passwd
getting from block 887048
file size was: 9428
slack size: 2860
block size: 4096
evil data is here
shows the data:

# bmap --mode wipeslack /etc/passwd
cleans the slack space.

Hiding data in slack space can be used to store secrets, plant evidence (forensics software will find it, but the suspect probably will not) and maybe hide tools from integrity checkers (if automated splitting of the larger file into slack-sized chunks is implemented).

Now lets turn to discovering what is out there on the vast expanses of the disk drive? If looking for strings of text, a simple "strings /dev/hdaX | grep 'string we need'" will confirm the presence of string on the partition (the process *will* take along time). Using a hex editor on the raw partition can sometimes shed some light on the disk contents, but the process is extremely messy. Thus further analysis puts us firmly in the field of computer forensics. The best tool for snooping around on the disk is The Coroner's Toolkit by Dan Farmer and Wietse Venema and the tctutils set of utilities for it. The software provides functionality for gathering forensics data, recovering files, analyzing drive contents for changes (using file timestamps), locating content on disks (using inode and block numbers) and for other fun forensics tasks. Detailed description of the toolkit goes well beyond the scope of this paper.

Now lets briefly review how to prevent the adversaries from finding private data. Several Linux file cleansing utilities exist. All but one can only be used to wipe files, rather than empty disk space. GNU shred (by Colin Plumb), srm (by Todd Burgess), wipe (by Tom Vier) and srm from thc kit (by THC group, see http://packetstorm.linuxsecurity.com/groups/thc/). Some use the multiple random passes as recommended in the above paper and some simply overwrite the file with zeros once. Some does not work under certain circumstances or for specific filesystems. As reported in shred man page "shred relies on a very important assumption: that the filesystem overwrites data in place". If this condition is not met, no secure deletion will be performed (with no error message!).

To eliminate the traces of old removed files, one might want to wipe the empty space. The simple method is to use a standard Linux "dd" utility. To wipe the empty space on /home partition use:

  1. dd if=/dev/zero of=/home/bigfile
  2. sync
  3. rm /home/bigfile
  4. sync
The commands will zero out the empty space on the partition. Doing the same for /tmp partition might cause some applications to crash, thus one must be cautious. Utility "sfill" from thc THC secure_delete package (available at http://packetstorm.linuxsecurity.com/groups/thc/) can overwrite empty space using more stringent algorithm.

It should be noted that swap space can also contain pieces of private data and should be wiped as well if additional security is desired. Another program (sswap) from THC toolkit can be utilized for the purpose.

The important fact to note is that when empty space is wiped, slack space for all files remains intact. If file is wiped (at least using current version of GNU shred), the associated slack space is NOT wiped with it!

The article briefly touches upon hiding, finding and destroying data on Linux filesystems. It should become clear that the area of computer forensics, aimed at recovering the evidence from captured disk drives, has many challenges, requiring knowledge of hardware, operating systems and application software.

About the Author

Anton Chuvakin, Ph.D. is a Senior Security Analyst with netForensics (http://www.netforensics.com), a security information management company that provides real-time network security monitoring solutions.

Comments
Prof.Written by Le John on 2006-06-13 14:15:11
So after all you said could you email me in detail how to erase all the files I have accessed in the past several years online. If there is another site with details, I will go there. 
 
Regards 
 
John
Great articleWritten by John Douglas on 2006-08-06 12:22:22
Really enjoyed this - but would like a bit more detail. Also it would be nice to see some inclusion of steg tools currently available for Linux and methods/tools available to asist in detection of steg. 
 
Kind regard, 
John.
Written by Donovan on 2006-12-27 03:15:54
Thanks so much for these commands. Now that all the empty space has been written with zeros, taking a ghost image of Linux compresses so much better. Down from 9 GB to just over 1 GB. 
 
Bucketfuls of thanks!
File size limitWritten by Olivier Berger on 2007-06-25 07:45:54
dd if=/dev/zero won't produce big anough files if the empty space is over the max size of a single fle,so you may need to do it several times until all free space is filled.
WOW ! Can we do the same for hiding a usWritten by kuldeep singh on 2007-09-22 18:03:55
Dear Anton Chuvakin, 
 
It was really a very informative article, MANY THANKS FOR THAT !!  
I wonder whether it is possible to hide a specific user account and complete files / folder structures ( In my scenario - I install / configure RHEL5 WS on laptops of my company's programmers and they normally operate it with root's permission - strange but most of them know how to break the root password using single mode or by booting from 1st CD. :-) 
 
Now I put some specific data like drivers and some static data on each of the laptops in my own folders. I wish to hide those folders from the users so that they do not mess with that data. Let me tell you that I have tried . (dot) prefix and permissions ( zero permissions like 000) and things like that. My query is that Is it possible in linux to have such a hidden file / folder and a hidden user account. please illustrate. - thanks
Slack spaceWritten by Sam on 2008-01-30 12:34:40
great article!! just one question. could you explain how you would get data off slack space? 
 
Thank you so much

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site.. Such material will be removed.
Name:
Title:
Comment:

Code:* Code

Powered by AkoComment!

 
< Prev   Next >
    
Partner:

 

Latest Features
A Secure Nagios Server
Never Installed a Firewall on Ubuntu? Try Firestarter
Review: Hacking Exposed Linux, Third Edition
Security Features of Firefox 3.0
Review: The Book of Wireless
April 2008 Open Source Tool of the Month: sudo
Open Source Tool of March: ZoneMinder
Yesterday's Edition
Analyzing Malicious SSH Login Attempts

QuickLinks: Comunity , HOWTOs , Blogs , Features , Book Reviews , Networking ,
  Security Projects ,   Latest News ,  Newsletters ,  SELinux ,  Privacy ,  Home,
 Hardening ,   About Us,   Advertise,   Legal Notice,   RSS,   Guardian Digital

(c)Copyright 2008 Guardian Digital, Inc. All rights reserved.