UNIT 4 CS Notes As Per New Syllabus
UNIT 4 CS Notes As Per New Syllabus
Procedure
The procedure starts with identifying the devices used and collecting the preliminary evidence
on the crime scene. Then the court warrant is obtained for the seizure of the evidence which
leads to the seizure of the evidence. The evidence are then transported to the forensics lab for
further investigations and the procedure of transportation of the evidence from the crime scene
to labs are called chain of custody. The evidence are then copied for analysis and the original
evidence is kept safe because analysis are always done on the copied evidence and not the
original evidence.
The analysis is then done on the copied evidence for suspicious activities and accordingly, the
findings are documented in a nontechnical tone. The documented findings are then presented
in a court of law for further investigations.
Some Tools used for Investigation:
Tools for Laptop or PC –
COFFEE – A suite of tools for Windows developed by Microsoft.
The Coroner’s Toolkit – A suite of programs for Unix analysis.
The Sleuth Kit – A library of tools for both Unix and Windows.
Tools for Memory :
Volatility
WindowsSCOPE
Tools for Mobile Device :
MicroSystemation XRY/XACT
Applications
Intellectual Property theft
Industrial espionage
Employment disputes
Fraud investigations
Misuse of the Internet and email in the workplace
Forgeries related matters
Bankruptcy investigations
Issues concerned the regulatory compliance
Advantages of Computer Forensics:
To produce evidence in the court, which can lead to the punishment of the culprit.
It helps the companies gather important information on their computer systems or
networks potentially being compromised.
Efficiently tracks down cyber criminals from anywhere in the world.
Helps to protect the organization’s money and valuable time.
Allows to extract, process, and interpret the factual evidence, so it proves the
cybercriminal action’s in the court.
Disadvantages
Before the digital evidence is accepted into court it must be proved that it is not
tampered with.
Producing and keeping electronic records safe is expensive.
Legal practitioners must have extensive computer knowledge.
Need to produce authentic and convincing evidence.
If the tool used for digital forensics is not according to specified standards, then in a
court of law, the evidence can be disapproved by justice.
A lack of technical knowledge by the investigating officer might not offer the desired
result.
Digital Forensics Science
Digital Forensics is a branch of forensic science which includes the identification, collection,
analysis and reporting any valuable digital information in the digital devices related to the
computer crimes, as a part of the investigation. In simple words, Digital Forensics is the process
of identifying, preserving, analyzing and presenting digital evidences. The first computer
crimes were recognized in the 1978 Florida computers act and after this, the field of digital
forensics grew pretty fast in the late 1980-90’s. It includes the area of analysis like storage
media, hardware, operating system, network and applications. It consists of 5 steps at high
level:
1. Identification of evidence: It includes of identifying evidences related to the digital
crime in storage media, hardware, operating system, network and/or applications. It is
the most important and basic step.
2. Collection: It includes preserving the digital evidences identified in the first step so
that they doesn’t degrade to vanish with time. Preserving the digital evidences is very
important and crucial.
3. Analysis: It includes analyzing the collected digital evidences of the committed
computer crime in order to trace the criminal and possible path used to breach into the
system.
4. Documentation: It includes the proper documentation of the whole digital
investigation, digital evidences, loop holes of the attacked system etc. so that the case
can be studied and analysed in future also and can be presented in the court in a proper
format.
5. Presentation: It includes the presentation of all the digital evidences and
documentation in the court in order to prove the digital crime committed and identify
the criminal.
Branches of Digital Forensics
Media Forensics: It is the branch of digital forensics which includes identification,
collection, analysis and presentation of audio, video and image evidences during the
investigation process.
Cyber Forensics: It is the branch of digital forensics which includes identification,
collection, analysis and presentation of digital evidences during the investigation of a
cyber crime.
Mobile Forensics: It is the branch of digital forensics which includes identification,
collection, analysis and presentation of digital evidences during the investigation of a
crime committed through a mobile device like mobile phones, GPS device, tablet,
laptop.
Software Forensics: It is the branch of digital forensics which includes identification,
collection, analysis and presentation of digital evidences during the investigation of a
crime related to softwares only.
Cyber Forensics
Cyber forensics is a process of extracting data as proof for a crime (that involves electronic
devices) while following proper investigation rules to nab the culprit by presenting the evidence
to the court. Cyber forensics is also known as computer forensics. The main aim of cyber
forensics is to maintain the thread of evidence and documentation to find out who did the crime
digitally. Cyber forensics can do the following:
It can recover deleted files, chat logs, emails, etc
It can also get deleted SMS, Phone calls.
It can get recorded audio of phone conversations.
It can determine which user used which system and for how much time.
It can identify which user ran which program.
Why is cyber forensics important?
In todays technology driven generation, the importance of cyber forensics is immense.
Technology combined with forensic forensics paves the way for quicker investigations and
accurate results. Below are the points depicting the importance of cyber forensics:
Cyber forensics helps in collecting important digital evidence to trace the criminal.
Electronic equipment stores massive amounts of data that a normal person fails to see.
For example: in a smart house, for every word we speak, actions performed by smart
devices, collect huge data which is crucial in cyber forensics.
It is also helpful for innocent people to prove their innocence via the evidence collected
online.
It is not only used to solve digital crimes but also used to solve real-world crimes like
theft cases, murder, etc.
Businesses are equally benefitted from cyber forensics in tracking system breaches and
finding the attackers.
The Process Involved in Cyber Forensics
1. Obtaining a digital copy of the system that is being or is required to be inspected.
2. Authenticating and verifying the reproduction.
3. Recovering deleted files (using Autopsy Tool).
4. Using keywords to find the information you need.
5. Establishing a technical report.
How did Cyber Forensics Experts work?
Cyber forensics is a field that follows certain procedures to find the evidence to reach
conclusions after proper investigation of matters. The procedures that cyber forensic experts
follow are:
1. Identification: The first step of cyber forensics experts are to identify what evidence
is present, where it is stored, and in which format it is stored.
2. Preservation: After identifying the data the next step is to safely preserve the data and
not allow other people to use that device so that no one can tamper data.
3. Analysis: After getting the data, the next step is to analyze the data or system. Here the
expert recovers the deleted files and verifies the recovered data and finds the evidence
that the criminal tried to erase by deleting secret files. This process might take several
iterations to reach the final conclusion.
4. Documentation: Now after analyzing data a record is created. This record contains all
the recovered and available (not deleted) data which helps in recreating the crime scene
and reviewing it.
5. Presentation: This is the final step in which the analyzed data is presented in front of
the court to solve cases.
Techniques that cyber forensic investigators use
Cyber forensic investigators use various techniques and tools to examine the data and some of
the commonly used techniques are:
Reverse Steganography: Steganography is a method of hiding important data inside
the digital file, image, etc. So, cyber forensic experts do reverse steganography to
analyze the data and find a relation with the case.
Stochastic Forensics: In Stochastic forensics, the experts analyze and reconstruct
digital activity without using digital artifacts. Here, artifacts mean unintended
alterations of data that occur from digital processes.
Cross-drive Analysis: In this process, the information found on multiple computer
drives is correlated and cross-references to analyze and preserve information that is
relevant to the investigation.
Live Analysis: In this technique, the computer of criminals is analyzed from within the
OS in running mode. It aims at the volatile data of RAM to get some valuable
information.
Deleted File Recovery: This includes searching for memory to find fragments of a
partially deleted file in order to recover it for evidence purposes.
Advantages of Cyber Forensics
Cyber forensics ensures the integrity of the computer.
Through cyber forensics, many people, companies, etc get to know about such crimes,
thus taking proper measures to avoid them.
Cyber forensics find evidence from digital devices and then present them in court,
which can lead to the punishment of the culprit.
They efficiently track down the culprit anywhere in the world.
They help people or organizations to protect their money and time.
The relevant data can be made trending and be used in making the public aware of it.
What are the required set of skills needed to be a cyber forensic expert?
The following skills are required to be a cyber forensic expert:
As we know, cyber forensic based on technology. So, knowledge of various
technologies, computers, mobile phones, network hacks, security breaches, etc. is
required.
The expert should be very attentive while examining a large amount of data to identify
proof/evidence.
The expert must be aware of criminal laws, a criminal investigation, etc.
As we know, over time technology always changes, so the experts must be updated
with the latest technology.
Cyber forensic experts must be able to analyse the data, derive conclusions from it and
make proper interpretations.
The communication skill of the expert must be good so that while presenting evidence
in front of the court, everyone understands each detail with clarity.
The expert must have strong knowledge of basic cyber security.
Digital Evidence
Digital Evidence Collection in Cybersecurity
In the early 80s PCs became more popular and easily accessible to the general population, this
also led to the increased use of computers in all fields and criminal activities were no exception
to this. As more and more computer-related crimes began to surface like computer frauds,
software cracking, etc. the computer forensics discipline emerged along with it. Today digital
evidence collection is used in the investigation of a wide variety of crimes such as fraud,
espionage, cyberstalking, etc. The knowledge of forensic experts and techniques are used to
explain the contemporaneous state of the digital artifacts from the seized evidence such as
computer systems, storage devices (like SSDs, hard disks, CD-ROM, USB flash drives, etc.),
or electronic documents such as emails, images, documents, chat logs, phone logs, etc.
Process involved in Digital Evidence Collection:
The main processes involved in digital evidence collection are given below:
Data collection: In this process data is identified and collected for investigation.
Examination: In the second step the collected data is examined carefully.
Analysis: In this process, different tools and techniques are used and the collected
evidence is analyzed to reach some conclusion.
Reporting: In this final step all the documentation, reports are compiled so that they
can be submitted in court.
In this section, we will learn how to extract information from MSG file using Outlook API.
Note that the following Python script will work only on Windows. For this, we need to install
third party Python library named pywin32 as follows −
pip install pywin32
Now, import the following libraries using the commands shown −
from __future__ import print_function
from argparse import ArgumentParser
import os
import win32com.client
import pywintypes
Now, let us provide an argument for command-line handler. Here it will accept two arguments
one would be the path to MSG file and other would be the desired output folder as follows −
if __name__ == '__main__':
parser = ArgumentParser(‘Extracting information from MSG file’)
parser.add_argument("MSG_FILE", help="Path to MSG file")
parser.add_argument("OUTPUT_DIR", help="Path to output folder")
args = parser.parse_args()
out_dir = args.OUTPUT_DIR
if not os.path.exists(out_dir):
os.makedirs(out_dir)
main(args.MSG_FILE, args.OUTPUT_DIR)
Now, we need to define main() function in which we will call win32com library for setting up
Outlook API which further allows access to the MAPI namespace.
def main(msg_file, output_dir):
mapi = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = mapi.OpenSharedItem(os.path.abspath(args.MSG_FILE))
display_msg_attribs(msg)
display_msg_recipients(msg)
extract_msg_body(msg, output_dir)
extract_attachments(msg, output_dir)
Now, define different functions which we are using in this script. The code given below shows
defining the display_msg_attribs() function that allow us to display various attributes of a
message like subject, to , BCC, CC, Size, SenderName, sent, etc.
def display_msg_attribs(msg):
attribs = [
'Application', 'AutoForwarded', 'BCC', 'CC', 'Class',
'ConversationID', 'ConversationTopic', 'CreationTime',
'ExpiryTime', 'Importance', 'InternetCodePage', 'IsMarkedAsTask',
'LastModificationTime', 'Links','ReceivedTime', 'ReminderSet',
'ReminderTime', 'ReplyRecipientNames', 'Saved', 'Sender',
'SenderEmailAddress', 'SenderEmailType', 'SenderName', 'Sent',
'SentOn', 'SentOnBehalfOfName', 'Size', 'Subject',
'TaskCompletedDate', 'TaskDueDate', 'To', 'UnRead'
]
print("\nMessage Attributes")
for entry in attribs:
print("{}: {}".format(entry, getattr(msg, entry, 'N/A')))
Now, define the display_msg_recipeints() function that iterates through the messages and
displays the recipient details.
def display_msg_recipients(msg):
recipient_attrib = ['Address', 'AutoResponse', 'Name', 'Resolved', 'Sendable']
i=1
while True:
try:
recipient = msg.Recipients(i)
except pywintypes.com_error:
break
print("\nRecipient {}".format(i))
print("=" * 15)
for entry in recipient_attrib:
print("{}: {}".format(entry, getattr(recipient, entry, 'N/A')))
i += 1
Next, we define extract_msg_body() function that extracts the body content, HTML as well as
Plain text, from the message.
def extract_msg_body(msg, out_dir):
html_data = msg.HTMLBody.encode('cp1252')
outfile = os.path.join(out_dir, os.path.basename(args.MSG_FILE))
open(outfile + ".body.html", 'wb').write(html_data)
print("Exported: {}".format(outfile + ".body.html"))
body_data = msg.Body.encode('cp1252')
open(outfile + ".body.txt", 'wb').write(body_data)
print("Exported: {}".format(outfile + ".body.txt"))
Next, we shall define the extract_attachments() function that exports attachment data into
desired output directory.
def extract_attachments(msg, out_dir):
attachment_attribs = ['DisplayName', 'FileName', 'PathName', 'Position', 'Size']
i = 1 # Attachments start at 1
while True:
try:
attachment = msg.Attachments(i)
except pywintypes.com_error:
break
Once all the functions are defined, we will print all the attributes to the console with the
following line of codes −
print("\nAttachment {}".format(i))
print("=" * 15)
for entry in attachment_attribs:
print('{}: {}'.format(entry, getattr(attachment, entry,"N/A")))
outfile = os.path.join(os.path.abspath(out_dir),os.path.split(args.MSG_FILE)[-1])
if not os.path.exists(outfile):
os.makedirs(outfile)
outfile = os.path.join(outfile, attachment.FileName)
attachment.SaveAsFile(outfile)
print("Exported: {}".format(outfile))
i += 1
After running the above script, we will get the attributes of message and its attachments in the
console window along with several files in the output directory.
Structuring MBOX files from Google Takeout using Python
MBOX files are text files with special formatting that split messages stored within. They are
often found in association with UNIX systems, Thunderbolt, and Google Takeouts.
In this section, you will see a Python script, where we will be structuring MBOX files got from
Google Takeouts. But before that we must know that how we can generate these MBOX files
by using our Google account or Gmail account.
Acquiring Google Account Mailbox into MBX Format
Acquiring of Google account mailbox implies taking backup of our Gmail account. Backup
can be taken for various personal or professional reasons. Note that Google provides backing
up of Gmail data. To acquire our Google account mailbox into MBOX format, you need to
Follow the steps given below −
Open My account dashboard.
Go to Personal info & privacy section and select Control your content link.
You can create a new archive or can manage existing one. If we click, CREATE
ARCHIVE link, then we will get some check boxes for each Google product we wish
to include.
After selecting the products, we will get the freedom to choose file type and maximum
size for our archive along with the delivery method to select from list.
Finally, we will get this backup in MBOX format.
Python Code
Now, the MBOX file discussed above can be structured using Python as shown below −
First, need to import Python libraries as follows −
from __future__ import print_function
from argparse import ArgumentParser
import mailbox
import os
import time
import csv
from tqdm import tqdm
import base64
All the libraries have been used and explained in earlier scripts, except the mailbox library
which is used to parse MBOX files.
Now, provide an argument for command-line handler. Here it will accept two arguments− one
would be the path to MBOX file, and the other would be the desired output folder.
if __name__ == '__main__':
parser = ArgumentParser('Parsing MBOX files')
parser.add_argument("MBOX", help="Path to mbox file")
parser.add_argument(
"OUTPUT_DIR",help = "Path to output directory to write report ""and exported content")
args = parser.parse_args()
main(args.MBOX, args.OUTPUT_DIR)
Now, will define main() function and call mbox class of mailbox library with the help of which
we can parse a MBOX file by providing its path −
def main(mbox_file, output_dir):
print("Reading mbox file")
mbox = mailbox.mbox(mbox_file, factory=custom_reader)
print("{} messages to parse".format(len(mbox)))
Now, define a reader method for mailbox library as follows −
def custom_reader(data_stream):
data = data_stream.read()
try:
content = data.decode("ascii")
except (UnicodeDecodeError, UnicodeEncodeError) as e:
content = data.decode("cp1252", errors="replace")
return mailbox.mboxMessage(content)
Now, create some variables for further processing as follows −
parsed_data = []
attachments_dir = os.path.join(output_dir, "attachments")
if not os.path.exists(attachments_dir):
os.makedirs(attachments_dir)
columns = [
"Date", "From", "To", "Subject", "X-Gmail-Labels", "Return-Path", "Received",
"Content-Type", "Message-ID","X-GM-THRID", "num_attachments_exported",
"export_path"]
Next, use tqdm to generate a progress bar and to track the iteration process as follows −
for message in tqdm(mbox):
msg_data = dict()
header_data = dict(message._headers)
for hdr in columns:
msg_data[hdr] = header_data.get(hdr, "N/A")
Now, check weather message is having payloads or not. If it is having then we will define
write_payload() method as follows −
if len(message.get_payload()):
export_path = write_payload(message, attachments_dir)
msg_data['num_attachments_exported'] = len(export_path)
msg_data['export_path'] = ", ".join(export_path)
Now, data need to be appended. Then we will call create_report() method as follows −
parsed_data.append(msg_data)
create_report(
parsed_data, os.path.join(output_dir, "mbox_report.csv"), columns)
def write_payload(msg, out_dir):
pyld = msg.get_payload()
export_path = []
if msg.is_multipart():
for entry in pyld:
export_path += write_payload(entry, out_dir)
else:
content_type = msg.get_content_type()
if "application/" in content_type.lower():
content = base64.b64decode(msg.get_payload())
export_path.append(export_content(msg, out_dir, content))
elif "image/" in content_type.lower():
content = base64.b64decode(msg.get_payload())
export_path.append(export_content(msg, out_dir, content))
if isinstance(content_data, str):
open(file_name, 'w').write(content_data)
else:
open(file_name, 'wb').write(content_data)
return file_name
Now, let us define a function to extract filenames from the message to accurately represent
the names of these files as follows −
def get_filename(msg):
if 'name=' in msg.get("Content-Disposition", "N/A"):
fname_data = msg["Content-Disposition"].replace("\r\n", " ")
fname = [x for x in fname_data.split("; ") if 'name=' in x]
file_name = fname[0].split("=", 1)[-1]
elif 'name=' in msg.get("Content-Type", "N/A"):
fname_data = msg["Content-Type"].replace("\r\n", " ")
fname = [x for x in fname_data.split("; ") if 'name=' in x]
file_name = fname[0].split("=", 1)[-1]
else:
file_name = "NO_FILENAME"
fchars = [x for x in file_name if x.isalnum() or x.isspace() or x == "."]
return "".join(fchars)
Now, we can write a CSV file by defining the create_report() function as follows −
Chain of custody indicates the collection, sequence of control, transfer and analysis.
It also documents details of each person who handled the evidence, date and time it was
collected or transferred, and the purpose of the transfer.
It demonstrates trust to the courts and to the client that the evidence has not tampered.
Digital evidence is acquired from the myriad of devices like a vast number of IoT devices,
audio evidence, video recordings, images, and other data stored on hard drives, flash drives,
and other physical media.
Importance of maintaining Chain of Custody?
Importance to Examiner:
To preserve the integrity of the evidence.
To prevent the evidence from contamination, which can alter the state of the evidence.
In case you obtained metadata for a piece of evidence but unable to extract any
meaningful information from the metadata. In such a case, the chain of custody helps
to show where possible evidence might lie, where it came from, who created it, and the
type of equipment used. This will help you to generate an exemplar and compare it to
the evidence to confirm the evidence properties.
Importance to the Court: If not preserved, the evidence submitted in the court might be
challenged and ruled inadmissible.
Chain of Custody Process
In order to preserve digital evidence, the chain of custody should span from the first step of
data collection to examination, analysis, reporting, and the time of presentation to the Courts.
This is very important to avoid the possibility of any suggestion that the evidence has been
compromised in any way.
Reporting: The process of documenting the findings of the analysis and presenting
them in a clear and concise manner. This can include creating a detailed report, as well
as providing expert testimony in court.
Tools Used in Digital Forensics
Forensic Software: Specialized software that can analyze and extract data from digital
devices and networks. Some examples include EnCase, FTK, and X-Ways Forensics.
Data Storage: The sheer amount of data that can be stored on modern digital devices
can make it difficult for forensic investigators to locate relevant information. This can
require specialized data carving techniques to extract relevant information.