Linux Intro to Linux Forensics
Linux Intro to Linux Forensics
This course will give you the foundation needed to be more effective as a
forensic investigator.
https://www.nowsecure.com/apptesting/community/#download
To run Santoku, you must install virtual machine (VM) software. Download
the appropriate version of VirtualBox for your host machine (Windows, OSX,
or Linux) here:
https://www.virtualbox.org/wiki/Downloads
Note: If you have viaExtract 2.1.1 or later, you can use your viaExtract OS as
well.
To get Santoku Linux to run on the VirtualBox, you need to have it attached
to your newly created Virtual Machine. This is equivalent to inserting a
Windows Install CD (for example) into a CD-ROM drive to boot for the first
time you are installing the new OS.
You can now click Start on the main VirtualBox screen to load the VM. Select
to either boot from the live DVD or install. If you have created this in a VM,
choose install-start the installer directly.
Note: If you are choosing this option and you are not installing Santoku in a
VM (you are installing it directly to your hard drive), choosing this will ERASE
YOUR HARD DRIVE.
Click Continue.
After the Installation is complete, reboot when prompted, and then log in
using the username and password you created during the installation
process.
● Tools Folder:
https://downloads.nowsecure.com/direct/opt-via-folder.zip
In addition, you will need various files for this training that are more easily-
accessed from your host machine.
If you are using VMware follow the instructions in the next section.
TAB will be your friend throughout this training so use the tab key to
autocomplete the command!
NOTE: To open a terminal window, hover your mouse over the lower portion
of the screen and wait for the shortcuts to appear. Click on the black
terminal shortcut:
sudo sh ./VBoxLinuxAdditions.run
Take the time now to download the remaining files and save them to this
directory.
Once you have finished downloading all the required course files your setup
is complete!
Developers can customize their distribution by adding their own tools and
programs to each individual build.
Red Hat
Debian Gentoo Arch Linux Slackware
Ent.
Manjaro
Knoppix Funtoo Fedora Slax
Linux
Ubuntu Mandriva
The user space is where apps are executed and the kernel space is where
the Linux kernel exists.
In the next few slides we’ll discuss these spaces a little bit more in depth.
• Process management
• Virtual File System
• Network Stack
• Device Drivers
• Architecture definition
(explained on the next slide)
In Linux, all files are part of the same file structure, as compared to Windows
which has separate drives (C: - hard disk; A: - floppy, etc.).
D:
C:
/etc – contains the configuration files for the system. These configuration
files are stored in text documents and can be edited if necessary.
etc
dev
Any files relating to a specific user are secure in his/her profile as long as the
files or folders are stored in the /home directory. This is also the default path
when you open a new terminal window… /home/<username>
home
Some examples of what you might find in the /usr directory include
application documentation (/usr/doc), source code for installed applications
(/usr/src), and any files that might be shared among several applications
(/usr/share).
usr
Some examples include system log files (/var/log), documents that are
spooled for printing (/var/spool), and even incoming and outgoing mail
(/var/mail).
var
cd /dev
(cd means change directories. Since the terminal by default starts in the
home directory we had to change over to the /dev directory before we could
run the next step)
ls
(ls means list. This lists out the contents of a directory in a very basic
output. There are some options that will present you with more information
such as ls –l, which uses a long listing format showing file permissions
and MAC information. In this case a simple ls did the trick). lt is the same
as doing a dir in a Windows command prompt.
You will see that there are several devices attached to the system, which all
play an important role in how the system functions. In the next slide we will
examine some of the more important ones.
Note: Since our Ubuntu workstation is running within a virtual machine you
will not see an entry for hda because it is using a virtual disk on the host
computer.
To access the device (drive) information go to the main menu in your Linux
distribution (mouse icon in Ubuntu) and select settings and then Disk Utility.
A screenshot of what the Disk Utility looks like is on the next slide so you
can see how the system organizes the attached drives, as well as the device
name.
In our example we are running Ubuntu in a virtual machine so the main hard
drive is recognized as /dev/sda, if you are not using our virtual machine your
system may be different. The Linux partition is /dev/sda1.
Linux partition is
/dev/sda1
As demonstrated in the previous slides you can see that there is a fairly
robust GUI interface that allows the user to accomplish most tasks with ease.
For example, similar to Windows, you can right click a file in Linux and
display the properties of that file. From there, you can perform a few
functions, such as view and modify file permissions.
That said, we will focus primarily on the command line interface since many
of the commands we run in the mobile forensics environment will be in a
terminal session.
You remember from a previous exercise that ls means listing and when we
add the –l switch it means long listing format. The other switches are as
follows:
-t means sort by modification time
-r means reverse order while sorting
-h means convert the sizes to human readable (i.e 4.0M, 230k, etc.)
If only a user is given, the owner will change (not the group).
This is essentially the same as using the “chgrp” (change group) command:
In Linux we use what is called sudo. Sudo is short for “super user do,” which
is essentially saying do this command as admin. The system will prompt for
your password when executing a command as sudo.
analyst@ubuntu:~$
You are now ready to take the quiz for this section and then move on to the
next module, “Basic Linux Commands.”
You perform a long directory listing and see the following permissions
associated with an object:
-rw--r--r--
11. What command would you use to change the permissions of this file?
A. chown
B. sudo
C. chmod
D. ls –cp
These next commands are very basic, but they will be your core foundation
for everything you do in Linux. Be sure you understand the commands
before moving on as it will make it easier as we progress through the
training.
Now type cd, hit the spacebar, then tap the tab key twice. You should see
that it lists all the possible directories under /var.
If there were only one folder under /var, it would auto populate the directory
name as the only choice.
If you hit the tab key twice, it will list all the possibilities within the current
directory.
Try to make a habit of using the tab key, because the entry will not
autocomplete if the path or filename doesn’t exist. This will ultimately save
you time!
You can use the up arrow to select a previous command, then use the left
arrow to go to any point of the command that needs to be modified!
This is a useful tool if you find yourself in a never-ending process! When all
else fails, ctrl + c your way out!
$ man –k zip
© Copyright 2014 NowSecure, Inc. All Rights Reserved. Do not distribute.
Help
Help is another good way to figure out the syntax or options of a specific
command. If you are not sure how to run a command, simply ask for help!
Standard syntax:
$ mount –h
Give it a try in
your virtual
or
machine!
$ mount --help
Remember that if you are ever wondering how a command works, just ask
for help by typing –h after your command!
Next, we’ll cover some more information on relative paths and advanced
commands!
/home/jsmith/Desktop/folder
Notice how the path starts with a /. Anytime there is a / in the beginning of
the path Linux will start at the root.
analyst@ubuntu:~$ cd /etc
A. $ cd ..
B. $ dir ..
C. $ cd..
D. $ cd ../..
A. $ cd ~
B. $ cd
C. $ cd /home/analyst (or current user name)
D. all the above
Comments on Question 1:
You found that only one of these commands will take you back one
directory. Don’t be confused by cd.. as that is a Windows command! Linux
requires the space between cd and the ..!
To view the contents of a file there are two options: output to screen or
output to a file.
$ cat old.txt
As a side note, you can also use the redirect symbol for other functions such
as listing out the results of a search in a file:
Thankfully, there is a way to view the contents one page at a time – using
the less and more commands.
more can be used to view the contents of a file, similar to the cat command,
but displaying only one page at a time. An example of the syntax is:
$ more default.prop
$ less default.prop
Take a few minutes to try to use the less and more commands in your
terminal window. You can run the command against scripts, text files, or
anything that contains human readable text.
Tip: When running the less command you may find the q key to be useful
for exiting!
This is useful if you would like one command to be sent to another for
further processing, such as with the less command. Here’s an example:
In the above example, the contents of file.txt will be output to the screen one
page at a time.
Let’s say we want to list out all the files and their path in the users’
documents folder. The following command returns all files and paths,
including hidden files.
$ find /home/analyst/Documents
Again, if you are ever not sure on what those switches mean you can type
find --help for quick reference OR man find for a full manual of the
command.
Follow along in your terminal window by first starting out in your home
directory (remember how to get to your home directory?) and typing the
following commands:
mkdir Linux
The above command will create a Linux directory inside of your home
directory.
mkdir –p Linux/Forensics/Training
In this example, both the Forensics folder and the Training folder were
created in one command.
To start, let’s delete a folder that has data in it. Start by backing out into your
home directory (just type cd and hit enter):
$ rmdir Linux
cd ~/Linux/Forensics
pico
Now type some text in the file and select CTRL+x, type Y when prompted to
save, and save it as test1.txt.
$ rmdir –p Linux/Forensics/Training
Since you already removed all the files with the last command the rm *
command doesn’t have anything to do but just know that it will remove
everything within the current directory!
Remember that the system generated an error stating that the directory
wasn’t empty and we told you that there was a way around it? By placing a –
r or –R after the command, it will recursively remove all the contents,
including subfolders.
In our example, we could have typed the following and all the files and
subdirectories would have been deleted:
rm –r ~/Linux
There is one last thing to point out about removing files through the
command line. As discussed, the files do not ever hit the trash folder, but
they are still recoverable using undelete software or forensic methods. If you
desire to remove the files permanently you can use the shred command.
The shred command will not only remove the file but will overwrite it
repeatedly, making it difficult if not impossible to recover.
A copy will simply copy a file from one location into a specified location.
Again, you can do this in the GUI by right clicking the file and selecting
copy/paste but we are going to show you how to manage this through the
command line interface.
$ cp –p image.dd ~/Desktop/client/case/
The file metadata will be preserved as it’s copied to the new location as –p
means preserve.
$ mv image.dd ~/Desktop/client/case/
$ mv /data/local/12m /data/local/12m.bak
This is the same as right clicking the file in windows and renaming it from
12m to 12m.bak.
In essence, a symbolic link allows you to have several instances of the same
file in different directories that don’t take up any space.
/mnt/hgfs/linux.txt
/home/jsmith/linux.txt
$ mv /data/local/12m /data/local/12m.bak
$ mv /data/local/12m /data/local/12m.bak
$ ln -s /data /data/local/12m
$ ln -s /data /data/local/12m
Writes a symbolic link file that contains the reference /data and will redirect
anything that references /data/local/12m to the new location.
Another use of a symbolic link is to store multiple “copies” of the same file
that all reference the original file. When you delete a symbolic link the
original file remains intact.
A. ln –I /home/analyst/linux.txt /opt/via/Linux.txt
B. ln –s /home/analyst/linux.txt /opt/via/linux.txt
C. ln –s /home/analyst/linux.txt /opt/via/Linux.txt
D. None of the above
2. True or false: the two types of links used in Linux are symbolic and
virtual.
We didn’t cover hard links in detail but here are some basic differences:
1. Hard links cannot be used to link to a directory, whereas symbolic links
can.
2. Hard links cannot cross file system boundaries, making them useless in
a large scale network environment where multiple file systems exist.
For example, Ubuntu has a software center that you can check out here:
https://apps.ubuntu.com/cat/applications/software-center/
$ which fls
$ which hexedit
In the examples above, you will see that fls is installed in /usr/local/bin/fls but
hexedit is not installed as it returns nothing to the prompt.
All of the results will be displayed. See the graphic on the next slide.
Let’s practice installing hexedit, a useful hex editor, from source code.
Be sure not to mistype anything or Linux will generate an error. Hit enter on
the installation prompts to accept the default.
When executing a program from the current directory you need to use a ./
in front of the command.
For example, to run mactime you would go to the containing directory and
type ./mactimexor ./flsxto run the fls program. If you are not in the
containing directory then you can just type the full path to the executable:
/Downloads/sleuthkit-3.2.3/tools/mactime
You may have noticed that when you ran the “which” command that all of
the utilities so far have been installed to /usr/local/bin by default.
$ ./fastboot …
$ /<full>/<path>/<to>/fastboot …
A. ./scalpel …
B. scalpel …
C. tools/scalpel …
D. Either scalpel or tools/scalpel will work
A. Type cd Linux-course, type nano, type the word “test”, hit ctrl-x
to exit, Y to save, type exam1.txt as the file name and hit enter
B. Type nano, type the word “test”, hit ctrl-x to exit, Y to save, type
exam1.txt as the file name and hit enter
C. Type cd Linux-course, type ./nano, type the word “test”, hit
ctrl-x to exit, Y to save, type exam1.txt as the file name and hit enter
D. Type ./nano, type the word “test”, hit ctrl-x to exit, Y to save, type
exam1.txt as the file name and hit enter
A. rmdir Linux-course/
B. rmdir ../Linux-course/
C. rm Linux-course/
D. rm -r ../Linux-course/
A. ln –s /usr/games/gnome-sudoku
B. ln –r /usr/games/gnome-sudoku
C. ln –s /Desktop /usr/games/gnome-sudoku
D. ln –s /usr/games/gnome-sudoku ~/Desktop
A. rm <filename>
B. rmdir <filename>
C. shred <filename>
D. None of the above
A. dir /boot/abi-3.0.0-12-genericrmdir
B. cat /boot/abi-3.0.0-12-generic
C. open /boot/abi-3.0.0-12-generic
D. rm /boot/abi-3.0.0-12-generic
Additional comments for 4: Sudo chown root: will change the owner and
group, but we just want to change the owner.
$ mmls /dev/sdb
$ mmls image.dd
Remember that in Linux if you were looking at a partition using mmls that
you would need to add the partition number, i.e. sdb1, sdb2, etc.
$ dd if=/path/to/source of=/path/to/destination
$ dd if=/dev/sdb of=~/Desktop/SD-Card/image.dd
The syntax is simple, if= stands for input file and of= is the destination
image file that you want to create.
dd and dc3dd can image either an entire disk, or just a specific partition. In
computer forensics it’s more common to get an entire disk whereas in
mobile forensics it is more likely to image a specific partition.
$ md5sum /dev/sdb
After the device is imaged, the syntax is the same, but the path will point to
the new image file. The hash signatures should match or something was
modified during the imaging process!
$ md5sum /home/analyst/image.dd
There are several ways to parse and view the data but for now let’s focus on
using a simple hex editor to take a quick look at the contents.
Earlier you went through the process of installing hexedit, which is a simple
free hex editor that will run great in your Linux command line environment.
We will now go over some hexedit essentials so you can find your way
around.
To launch hexedit you simply would type hexedit followed by the path to the
image file:
$ hexedit /home/analyst/android-userdata.dd
You will get some practical experience with this later but for now we just
want to cover some basics.
Notice where the green cursor is in the screenshot above. If we hit the “/”
key now, the search will look through hex strings for your search terms. The
TAB key will put the cursor to the ASCII side of things.
In this example, we just search for a phone number, but you can look for
anything!
Just remember that a hex editor will only display the raw hex and ASCII data.
It’s not a very useful way to look at the contents of files contained within the
disk image.
If the image file is of an entire disk it will likely contain multiple partitions.
mmls tells you the sector size, which plays an important role because we
have to tell mount where the partition starts in order to mount it properly.
We do this by calculating an offset.
In this example, we will want to image the “NTFS” partition as it is the largest
(note: look at the “length” column in the output). With 512 byte sectors we
would multiply the partition start by 512 (224910 x 512) to get an offset of
115153920.
Hard drive:
SD Card image:
Notice the ro switch for READ ONLY! You must also specify a mount
location so be sure that you have created a mount directory first, as in this
case ~/Desktop/mount.
You can see that mounting an image file in Linux is not that complicated.
Certain file systems can make the task slightly more difficult, such as
YAFFS2 in Android, but Linux supports many of the basic file systems that
you will run across as a forensic examiner.
If the configuration editor is not installed you will have to install it first by
using sudo apt-get install dconf-tools or software center.
Next, let's explore some of the great tools that you can use to extract data
from the image file.
You can run strings against a file or a full disk image. The next slide will walk
you through a few examples of executing the command.
$ strings sms.db
Remember that the pipe command tells Linux that there is more than one
task to be performed. In this case we first run strings, then we search for
viaForensics. Let’s talk a bit more about grep and how to use it.
First off, grep is case sensitive by default so you need to make sure you use
the appropriate case when entering the search parameters. Here’s an
example:
You can add the –i switch to make the command case-insensitive but the
search is more time consuming:
In this example we are grabbing the 3 lines before every instance of HDTA
and 8 lines after HDTA giving us a complete picture of the results.
For example, we will grep through all files on user’s desktop for “via”:
Scalpel is a useful utility that allows you to carve image files for specific files
such as .jpg, .doc, .xls, or virtually any other file. Scalpel is installed as part of
the sleuth kit or can be installed separately through the software center or
source download as described previously. We have already installed it for
you on your virtual machine so it will not be necessary to install it again for
the purpose of this course.
In some cases the file may not have a footer in which case the file size will
be important as it will start carving at the header and either end at the footer
or defined file size.
The trick is that you must have a logical file to examine in a hex editor in
order to get the file header/footer information. A good habit would be to
grab the header and footer from random files when you have the
opportunity since a future investigation might not have any logical files
available for the file type you are looking for!
$ which scalpel
The terminal will return the path for you to confirm that it is in /usr/local/bin.
After defining the configuration file you simply specify the path to the raw
image, as in our example ~/Desktop/lab1/image.dd
One other important factor to note about the scalpel-output directory is that
once it’s created scalpel will not run in the same directory until the folder is
renamed or deleted. This is a built-in feature that prevents you from
overwriting scalpel-output by accidentally running scalpel again against a
different raw image file.
Many files and directories within a raw image have times associated with
them. A timeline is essential as it will provide a high-level look at system
activity, such as when files were compiled and when archives were opened.
1. Using the “fls” tool, data is gathered from sources such as file
systems, registries, logs, etc. and saved to a the “body file” format
2. The “mactime” script is then used to sort and merge this data into a
timeline
Note: In the command above, there is a single space between -r and ~/Desktop
$ mactime -b ~/Desktop/harddrive-timeline.body -z
CST6CDT -d > ~/Desktop/harddrive-timeline.csv
Note: In the command above, there is a single space between -z and CST6CDT
To see all the file types that log2timeline supports run the following
command:
$ log2timeline –f list
Once the body file is created you can import it into other tools to generate
the actual timeline, such as mactime.
When you see a file of interest in the timeline, you can track it down in the
mounted image. The full path is displayed in the timeline so locating it in the
image file will be simple in most cases. For example, you see a picture
called “IMG_001.jpg” was created at a certain time. Go to the image file to
locate the photo and see what the picture contains.
You are now on your way to getting some hands-on experience with all of
these new commands in the lab portion of this training. But first, let’s take a
short quiz to see how much you’ve learned!
Keep in mind the commands in these questions will not work on your VM
since the paths are different. This quiz is intended to get you thinking about
each command logically rather than just testing them until you find one that
works!
A. Scalpel
B. Fls
C. Fdisk
D. mmls
E. Both C and D
A. dd of=/home/analyst/disk-image.dd if=/sdb2
B. dd if=/dev/sdb2 of=/dev/home/disk-image.dd
C. dd if=/etc/sdb2 of=/home/analyst/disk-image.dd
D. dd if=/dev/sdb2 of=~/disk-image.dd
A. /opt/via/scalpel-data
B. /opt/via/scalpel-output
C. /home/analyst
D. ~/
A. fls
B. log2timeline
C. Neither
To manually mount the image file you must first go into the disk utility
(under Applications/Preferences) to see how Linux defines the external
media. In our case it is /dev/sdc but it may be different on your system.
$ sudo dd if=~/Desktop/linux-training-sdcard-image.dd
of=~/Desktop/lab1/sdimage.dd
Note that you will need to replace /Desktop/linux with the actual
download point of your image... as you determined in the previous step.
First you need to create a mount folder. Remember that the mount
command requires a location to mount the image so create that first. It can
be created anywhere and named anything you wish. In this example we
created a folder on our desktop called mount.
Once the folder is created run the mount command using the offset
calculated previously. Also, if file system was FAT16 or FAT32, you can use
“vfat” os the file system type.
5. Since we are not going to process any of the logical files in this lab,
unmount the image from Linux
You may not feel like a Linux expert, but you should feel comfortable with
the material before moving on.
1. Run Scalpel against the image file to carve the files. You can use
the default Scalpel configuration file located in /opt/via.
$ mkdir ~/Desktop/lab1/scalpel
$ scalpel –c /opt/via/scalpel.conf
~/Desktop/lab1/sdimage.dd –o ~/Desktop/lab1/scalpel/
Remember that if you were to run scalpel again you would need to rename
the scalpel-output directory or direct the output to another location since
Scalpel is designed to not overwrite the scalpel-output directory.
2. Using fls and mactime, create a timeline of the SD card image file.
A. The ACCESS timestamps are zero and were lost during the timeline
creation
B. The ACCESS timestamps are zero because FAT doesn’t track
ACCESS events to the hour/minute, only by the day
C. The MODIFIED timestamps are zero and were lost during the
timeline creation
D. The MODIFIED timestamps are zero because FAT doesn’t track
CREATED events to the hour/minute, only by the day
A. 16:48 February 14
B. 04:48 February 14
C. 21:48 February 14
D. 09:48 February 14
Click here!
$ hexedit /opt/via/sms.db
You have to first use the TAB key to get the cursor to the
ASCII side of the file, then hit the “/” key to initiate the
search. Once the search field is displayed simply type
Italian and hit enter.
In this case, you can see that rows 1, 2, and 10 are missing! To determine
whether any messages at the end are missing, select the "sqlite_sequence"
table from sms.db. It will display the most recently assigned ROWID listed
next to "message." In this case, 17 was the last assigned ROWID, so we can
verify that there were no additional messages deleted after ROWID 17.
A. 1
B. 2
C. 3
D. 4
This command will return one more result for a total of two
text messages with the word Italian.
7. Search for: “you” (a common word) and show the results one screen
at a time.
If you have any questions about the material feel free to review this training
again, or contact us with more specific questions.
The goal of this course was to familiarize you with Linux and some
powerful tools and commands that can be used as a forensic
investigative tool.
Want great #Linux tips and tutorials? Check out “Linux for Mobile
Forensics” from @NowSecureMobile:
https://www.nowsecure.com/resources/linux-forensics-training/
If you like this training, you will love our other resources:
NowSecure Support
[email protected]
312-878-1100