Data Recovery
Data Recovery
Data recovery is the process of retrieving data from a storage medium that, for some reason, cannot be
accessed normally. This process may be used to recover data from a variety of storage media, such as:
hard disk drives, solid-state drives, other flash storage (such as USB drives, SD cards), or other disk
storage (such as CDs, DVDs). The damage that causes data to be lost typically falls into one of two
categories: physical damage (where the hardware is damaged or is malfunctioning), or logical damage
(where part of the software and/or file system prevents the data from being accessed by the host
operating system.) We’ll discuss these different types of storage damage in greater depth a bit later.
The term “data recovery” can also be organized into two different contexts: personal data recovery, and
forensic data recovery. Personal data recovery is what we normally associate with this topic. It simply
refers to the retrieval of data that has been involuntarily lost or made inaccessible due to, for example,
damaged storage media. By contrast, forensic data recovery often deals with retrieving data that has
been purposely encrypted or hidden to prevent others (such as forensic investigators) from accessing
the data.
While some of the content this presentation will apply to both contexts of the term, will focus primarily
on the more common (and applicable) topic of personal data recovery.
COMMON SCENARIOS
Here, we’ve included some common scenarios where data recovery procedures would be necessary:
There has been an operating system failure or some critical operating system files have been
damaged, causing the device to not be able to boot up properly. In this case, a simple solution
would be to use a Live USB to boot up from another operating system so that you can access the
data from the storage medium.
There has been a hard disk failure and there is physical damage to the storage medium. In this
case, you may be able to repair the hardware, but the storage medium is often beyond repair
and the focus is more on a one-time recovery in an attempt to salvage any data you can. This
will often require the services of a specialized data recovery company.
Files have been deleted from a storage medium. As we will discuss later in the presentation,
when an operating system “deletes” files, often times the data is not immediately removed
from the drive. This allows tools such as file carvers to recover this data.
TYPES OF STORAGE DAMAGE
Physical Damage
This type of storage damage occurs when the physical hardware of the storage medium is damaged. An
example of this is when a hard disk drive suffers from a mechanical failure such as a head crash.
A head crash is a hard drive disk failure that occurs when a read-write head comes in contact with its
rotating platter. This results in permanent, and usually irreparable, damage to the hard drive. It’s
typically caused by a sudden jolt of motion, for example: dropping a laptop while it’s operating. To
defend against this, modern laptops have what’s known as “active hard-drive protection”, which usually
consists of accelerometers that alert the system when excess acceleration is detected. The software will
tell the hard drive to unload/park its heads to prevent them from coming in contact with the platter.
Physical damage will almost always cause data loss, and in many cases leads to damage of the
supporting operating system and/or file system.
It is usually recommended that physical damage should not be repaired by end users, as these types of
recovery situations may require the use of specific hardware or specialized technical expertise. It’s also
suggested that any physical repairing should be done in a dust-free and static-free environment to
ensure that further damage is not done during the recovery process.
Data recovery companies may use various techniques to attempt to repair storage media, for example
they may replace damaged or malfunctioning parts in the hard disk. However, even if this repairs the
disk and makes the storage device usable, there may still be damage to the file system or operating
system that prevents it from functioning properly. At this point, they may use a disk-imaging procedure
to recover surviving data and transfer it to a reliable medium, so that the image can be analyzed and
possibly reconstructed to a working state.
Logical Damage
This type damage refers to damage that has occurred at the software-level, causing errors or complete
loss of access to data.
Damaged Filesystems
In some cases, data on a storage medium may be unreadable due to damage to the filesystem. In this
case, using a data recovery tool (such as Testdisk) can repair the damaged filesystem to restore access
to the data. If the filesystem can’t be repaired, other tools (such as dd rescue) can be used to image
storage media despite having filesystem damage. This type of data recovery can be performed by
anyone, as it doesn’t require any specialized physical equipment or access to inner hardware
components.
If data has been damaged in such a way that it cannot be repaired, a procedure known as file carving
can be used to recover parts of damaged files. File carving is the process of reassembling computer files
from fragments in the absence of filesystem metadata.
Deleted Data
HDD:
For most operating systems, when a file is deleted on a Hard Disk Drive, the contents of the file are not
immediately removed from the drive. Instead, to improve performance, they simply remove references
to the file in the directory structure and mark the space that they occupy as available so that other data
can be written to it later. This means that the original data remains on the disk and may be recoverable
using specialized tools such as a file carver.
SSD:
Data recovery on an SSD is much different than that of a HDD due to a command and hardware
supported process called TRIM.
The TRIM command is designed to enable the operating system to notify the SSD which pages no longer
contain valid data due to erases either by the user or operating system itself. During a delete operation,
the OS will mark the sectors as free for new data and send a TRIM command to the SSD to mark them as
not containing valid data. After that the SSD knows not to preserve the contents of the block when
writing a page, resulting in fewer writes to the flash, higher write speed, and increased drive life.
Similarly to both storage mediums when an item is deleted simply the meta-data is removed while the
bulk of data is left untouched, however the space that data occupied is marked as free-space. On a
traditional HDD this is a suitable method since when new data is sent to be written on the drive it can
simply overwrite the sectors whether or not they are occupied.
SSD's use NAND flash memory to store and transfer information; free space is made up of blocks, within
the blocks there are pages. Data is written to pages but only blocks may be erased. When a write
request is sent to the SSD all the free pages are grouped together and cleared, which impacts the
efficiency of the drive since the erasing is done at that time. To alleviate the slowed performance TRIM
support was introduced. Pages that are marked for deletion are now handled before you need them.
The SSD and OS are in communication about which pages have been cleared and therefore can be
reused by the OS efficiently.
This now means that modern OS' and SSD's will be pre-emptively clearing the data on the drive upon
deletion making it much harder if not impossible to recover. On the one hand it is harder for the
attacker to break confidentiality; on the other it is harder as the defender to restore availability on
accidentally deleted or lost data.
The shortcoming has been overcome in the Serial ATA revision 3.1.
This outlines the general process for recovering data. Some steps, in particular Step 1, may not be
necessary depending on the situation.
A simple technique to regain access to data that is on a storage media that won’t boot (due to, for
example, logical damage to the operating system) is to mount it to another computer, or use a Live
USB/CD to boot another operating system on the machine.
Another solution is to use a tool such as Testdisk to try and recover lost partitions and/or make non-
booting disks bootable again.
There are also a number of closed-source and/or commercial software solutions for data recovery, as
well as some non-commercial and/or open-source tools.
PHOTOREC
PhotoRec is a free and open-source file carving tool designed to recover lost files.
As mentioned earlier, file carving is the process of reassembling computer files from fragments in the
absence of filesystem metadata.
It can recover data from various storage media, including: SD cards, USB flash drives, hard drive disks,
CDs, and DD disk image files.
It recovers most common photo formats (like JPEG images), audio files (such as MP3), videos (for
example, MP4 files), document formats (including OpenDocument, Microsoft Office, PDF, and text files),
and archive formats (such as ZIP). In all, it recognizes over 440 file extensions.
It’s a multi-platform tool, so it’s compatible with most Linux distributions and most versions of Windows
and OS X.
PhotoRec ignores the file system, so it works even if the file system is severely damaged. It’s able to
recover data from several common filesystem formats including FAT, NTFS, and ext2/ext3/ext4.
To recover lost files, PhotoRec first tries to find the data block size. If the filesystem is not corrupted,
this value can read from the superblock (for ext2/ext3/ext4) or volume boot record (for FAT, NTFS).
Otherwise, the program tries to calculate the block size by reading the media and searching for files to
compare with. Once the block size is known, the tool reads the media block by block, comparing each
block against a signature database.
For example, PhotoRec identifies a JPEG file when a block begins with:
0xff, 0xd8, 0xff, 0xe0
or
0xff, 0xd8, 0xff, 0xe1
or
0xff, 0xd8, 0xff, 0xfe
Finally, once a file is recovered successfully, the program checks any previous data blocks to see if some
fragmented files can also be recovered.
PHOTOREC DEMO
To run PhotoRec:
>> photorec
GUTMANN METHOD
When deleting data from a hard disk (HDD), there are two common methods:
Fast method: Meta data is deleted and the space is marked as free space. This is the
most common way for operating systems to delete data, as it is much faster.
Gutmann method: Commonly referred to as a [1-35] pass erase. It involves erasing a
drive using a special algorithm to increase the difficulty of retrieving the original content
on the drive. At this point only special extraction tools may have any chance of
retrieving the data.
In our demonstration, we also showed how the shred command was used to securely delete
(overwrite with 0s) data from the SD Card after it was “erased” by the digital camera.
RESTORING C.I.A. IN THE EVENT OF DATA LOSS
Here are some guidelines to follow when attempting to mitigate the impact of data loss and/or protect
against data loss. The symbol next to each recommendation outlines which aspect of C.I.A.
(Confidentiality, Integrity, and Availability) is either maintained or restored.
(A) Use data recovery tools and techniques to retrieve lost data
In the case of an emergency, where data has already been lost, this allows the user to
restore Availability since you regain access to lost data.