Python Forensics Tutorial
Python Forensics Tutorial
Python Forensics Tutorial
Audience
This tutorial is meant for all those readers who seek to increase their understanding in digital or
computational forensics through the use of Python. It will help you understand how to integrate
Python in computational forensics.
Prerequisites
Before starting with this tutorial, it is important that you understand the basic concepts of
computational forensics. And, it will definitely help if you have prior exposure to Python.
All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt.
Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any
contents or a part of contents of this e-book in any manner without written consent of the
publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd.
provides no guarantee regarding the accuracy, timeliness or completeness of our website or its
contents including this tutorial. If you discover any errors on our website or in this tutorial,
please notify us at contact@tutorialspoint.com
i
Python Forensics
Table of Contents
About the Tutorial............................................................................................................................................... i
Audience ............................................................................................................................................................. i
Prerequisites ....................................................................................................................................................... i
ii
Python Forensics
iii
1. Python Forensics ─ Introduction
Python Forensics
Python is a general-purpose programming language with easy, readable code that can be
easily understood by both professional developers as well as novice programmers. Python
comprises of many useful libraries that can be used with any stack framework. Many
laboratories rely on Python to build basic models for predictions and to run experiments.
It also helps to control critical operational systems.
Python has built-in capabilities to support digital investigation and protect the integrity of
evidence during an investigation. In this tutorial, we will explain the fundamental concepts
of applying Python in digital or computation forensics.
Computation Forensics includes a broad range of subjects which has objects, substances,
and processes investigated, mainly based on pattern evidence, such as toolmarks,
fingerprints, shoeprints, documents etc., and also includes physiological and behavioral
patterns, DNA, and digital evidence at crime scenes.
The following diagram shows the broad range of subjects covered under Computational
Forensics.
Computational forensics involves diverse digital methods. The best solution to ease all
digital methods in forensics is to use a general-purpose programming language like
Python.
1
2. Python Forensics ─ Installation of Python
Python Forensics
As we need Python for all the activities of computational forensics, let us move step by
step and understand how to install it.
Step 2: After downloading the package/installer, click on the exe file to start the
installation process.
2
Python Forensics
You will get to see the following screen after the installation is complete.
Step 3: The next step is to set the environment variables of Python in your system.
3
Python Forensics
Step 4: Once the environment variables are set, type the command "python" on the
command prompt to verify whether the installation was successful or not.
If the installation was successful, then you will get the following output on the console.
4
3. Python Forensics ─ Overview of Python
Python Forensics
The codes written in Python look quite similar to the codes written in other conventional
programming languages such as C or Pascal. It is also said that the syntax of Python is
heavily borrowed from C. This includes many of the Python keywords which are similar to
C language.
Python includes conditional and looping statements, which can be used to extract the data
accurately for forensics. For flow control, it provides if/else, while, and a high-level for
statement that loops over any "iterable" object.
if a < b:
max = b
else:
max = a
The major area where Python differs from other programming languages is in its use of
dynamic typing. It uses variable names that refer to objects. These variables need not
be declared.
Data Types
Python includes a set of built-in data types such as strings, Boolean, numbers, etc. There
are also immutable types, which means the values which cannot be changed during the
execution.
Python also has compound built-in data types that includes tuples which are immutable
arrays, lists, and dictionaries which are hash tables. All of them are used in digital
forensics to store values while gathering evidence.
Python includes an extensive standard library, which is one of the main reasons for its
popularity in computational forensics.
If there are no syntax errors, then the code is compiled to produce a bytecode
and sent to PVM (Python Virtual Machine).
The PVM checks the bytecode for any runtime or logical errors. In case the PVM
finds any runtime errors, then they are reported immediately as error messages.
If the bytecode is error-free, then the code gets processed and you get its output.
5
Python Forensics
The following illustration shows in a graphical manner how the Python code is first
interpreted to produce a bytecode and how the bytecode gets processed by the PVM to
produce the output.
6
4. Python Forensics ─ Basic Forensic Application
Python Forensics
Naming Conventions
During the development of Python forensics applications, the rules and conventions to be
followed are described in the following table.
Object name Prefix ob_ lowercase with bumpy caps Example: ob_myTempRecorder
It is practically impossible to create a new binary input that will generate a given message
digest. Even a single bit of the binary input data, if changed, will generate a unique
message, which is different than the previous one.
Example
Take a look at the following sample program which follows the above-mentioned
conventions.
7
Python Forensics
md5_object.update(line)
print md5_object.hexdigest() # Prints the output as per the hashing algorithm i.e. md5
exit
In this program, the Python script accepts the input (your full name) and converts it as
per the md5 hashing algorithm. It encrypts the data and secures the information, if
required. As per forensic guidelines, the name of evidences or any other proofs can be
secured in this pattern.
8
5. Python Forensics ─ Hash Function
Python Forensics
A hash function is defined as the function that maps on a large amount of data to a fixed
value with a specified length. This function ensures that the same input results in the same
output, which is actually defined as a hash sum. Hash sum includes a characteristic with
specific information.
This function is practically impossible to revert. Thus, any third party attack like brute
force attack is practically impossible. Also, this kind of algorithm is called one-way
cryptographic algorithm.
It must be easy to compute the hash value for any given input.
It must be infeasible to generate the original input from its hash.
It must be infeasible to modify the input without changing the hash.
It must be infeasible to find two different inputs with the same hash.
Example
Consider the following example which helps in matching passwords using characters in
hexadecimal format.
import uuid
import hashlib
def hash_password(password):
# userid is used to generate a random number
salt = uuid.uuid4().hex #salt is stored in hexadecimal value
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
9
Python Forensics
Flowchart
We have explained the logic of this program with the help of the following flowchart:
10
Python Forensics
Output
Our code will produce the following output:
The password entered twice matches with the hash function. This ensures that the
password entered twice is accurate, which helps in gathering useful data and save them
in an encrypted format.
11
6. Python Forensics ─ Cracking an Encryption
Python Forensics
In this chapter, we will learn about cracking a text data fetched during analysis and
evidence.
A plain text in cryptography is some normal readable text, such as a message. A cipher text,
on the other hand, is the output of an encryption algorithm fetched after you enter plain text.
Simple algorithm of how we turn a plain text message into a cipher text is the Caesar cipher,
invented by Julius Caesar to keep the plain text secret from his enemies. This cipher involves
shifting every letter in the message "forward" by three places in the alphabet.
a -> D
b -> E
c -> F
....
w -> Z
x -> A
y -> B
z -> C
Example
A message entered when you run a Python script gives all the possibilities of characters,
which is used for pattern evidence.
Every biometric data comprises of vector data, which we need to crack to gather full-proof evidence.
The following Python code shows how you can produce a cipher text from plain text:
import sys
def decrypt(k,cipher):
plaintext = ''
for each in cipher:
p = (ord(each)-k) % 126
if p < 32:
p+=95
plaintext += chr(p)
print plaintext
def main(argv):
12
Python Forensics
if (len(sys.argv) != 1):
sys.exit('Usage: cracking.py')
cipher = raw_input('Enter message: ')
for i in range(1,95,1):
decrypt(i,cipher)
if __name__ == "__main__":
main(sys.argv[1:])
Output
Now, check the output of this code. When we enter a simple text "Radhika", the program
will produce the following cipher text.
13
7. Python Forensics ─ Virtualization
Python Forensics
The following figure explains the two main types of system virtualization used.
Virtualization has been used in computational forensics in a number of ways. It helps the
analyst in such a way that the workstation can be used in a validated state for each
investigation. Data recovery is possible by attaching the dd image of a drive as a secondary
drive on a virtual machine particularly. The same machine can be used as a recovery
software to gather the evidences.
The following example helps in understanding the creation of a virtual machine with the
help of Python programming language.
Every virtual machine must have 512 MB of memory in minimum capacity, expressed in
bytes.
Step 2: The virtual machine must be attached to the default cluster, which has been
calculated.
vm_cluster = api.clusters.get(name="Default")
Step 3: The virtual machine must boot from the virtual hard disk drive.
vm_os = params.OperatingSystem(boot=[params.Boot(dev="hd")])
All the options are combined into a virtual machine parameter object, before using the add
method of the vms collection to the virtual machine.
14
Python Forensics
Example
Following is the complete Python script for adding a virtual machine.
vm_name = "dummy1"
vm_memory = 512 * 1024 * 1024 #calculating the memory in bytes
vm_cluster = api.clusters.get(name="Default")
vm_template = api.templates.get(name="Blank")
vm_os = params.OperatingSystem(boot=[params.Boot(dev="hd")]) #assigning the
parameters to operating system
vm_params = params.VM(name=vm_name,
memory=vm_memory,
cluster=vm_cluster,
template=vm_template)
os=vm_os)
try:
api.vms.add(vm=vm_params)
print "Virtual machine '%s' added." % vm_name #output if it is successful.
except Exception as ex:
print "Adding virtual machine '%s' failed: %s" % (vm_name, ex)
api.disconnect()
15
Python Forensics
Output
Our code will produce the following output:
16
8. Python Forensics ─ Network Forensics
Python Forensics
The scenario of modern network environments is such that investigating can be fraught
due to a number of difficulties. This can happen whether you are responding to a breach
support, investigating insider activities, performing assessments related to vulnerability,
or validating a regulatory compliance.
WebSockets: WebSockets provide a protocol between the client and the server,
which runs over a persistent TCP connection. Through this, bi-directional messages
can be sent between the TCP socket connection (simultaneously).
WebSockets come after many other technologies that allow the servers to send information
to the client. Other than handshaking the Upgrade Header, WebSockets is independent
from HTTP.
These protocols are used to validate the information which is sent or received by the third
party users. As encryption is one of the methods used for securing messages, it is also
important to secure the channel through which the messages have been transferred.
17
Python Forensics
Consider the following Python program, which the client uses for handshaking.
# client.py
import socket
port = 8080
Output
It will produce the following output:
18
Python Forensics
The server accepting the request for communication channel will include the following
script.
# server.py
import socket
import time
port = 8080
# queue up to 5 requests
serversocket.listen(5)
while True:
# establish a connection
clientsocket,addr = serversocket.accept()
The client and server created with the help of Python programming listen to the host
number. Initially, the client sends a request to the server with respect to data sent in the
host number and the server accepts the request and sends a response immediately. This
way, we can have a secure channel of communication.
19
9. Python Forensics ─ Python Modules
Python Forensics
Modules in Python programs help in organizing the code. They help in grouping related
code into a single module, which makes it easier to understand and use. It includes
arbitrarily named values, which can be used for binding and reference. In simple words, a
module is a file consisting of Python code which includes functions, classes, and variables.
The Python code for a module (file) is saved with .py extension which is compiled as and
when needed.
Example
def print_hello_func( par ):
print "Hello : ", par
return
Import Statement
The Python source file can be used as a module by executing an import statement which
imports other packages or third-party libraries. The syntax used is as follows:
When the Python interpreter encounters the import statement, it imports the module
specified which is present in the search path.
Example
Consider the following example.
#!/usr/bin/python
20
Python Forensics
A module is loaded only once, regardless of the number of times it has been imported by
Python code.
From...import statement
From attribute helps to import specific attributes from a module into a current namespace.
Here is its syntax.
Example
To import the function fibonacci from the module fib, use the following statement.
Locating Modules
When the module is being imported, the Python interpreter searches for the following
sequences:
If the module does not exist, Python then searches each directory in the shell
variable PYTHONPATH.
If the shell variable location fails, Python checks the default path.
Computational forensics use Python modules and third-party modules to get the
information and extract evidence with better ease. Further chapters focus on the
implementation of modules to get the necessary output.
21
10. Python Forensics ─ Dshell and Scapy
Python Forensics
DShell
Dshell is a Python-based network forensic analysis toolkit. This toolkit was developed by
the US Army Research Laboratory. The release of this open source toolkit was in the year
2014. The major focus of this toolkit is to make forensic investigations with ease.
The toolkit consists of large number of decoders which are listed in the following table.
The US Army Laboratory has maintained the clone repository in GitHub in the following link:
https://github.com/USArmyResearchLab/Dshell
The clone consists of a script install-ubuntu.py () used for installation of this toolkit.
Once the installation is successful, it will automatically build the executables and
dependencies that will be used later.
22
Python Forensics
dependencies = {
"Crypto": "crypto",
"dpkt": "dpkt",
"IPy": "ipy",
"pcap": "pypcap"
}
This toolkit can be used against the pcap (packet capture) files, which is usually recorded
during the incidents or during the alert. These pcap files is either created by libpcap on
Linux platform or WinPcap on Windows platform.
Scapy
Scapy is a Python-based tool used to analyze and manipulate the network traffic.
Following is the link for Scapy toolkit:
http://www.secdev.org/projects/scapy/
This toolkit is used to analyze packet manipulation. It is very capable to decode packets
of a wide number of protocols and capture them. Scapy differs from the Dshell toolkit by
providing a detailed description to the investigator about network traffic. These
descriptions have been recorded in real time.
This script gives the detailed description of the country details in the network packet, who
are communicating with each other.
23
Python Forensics
24
11. Python Forensics ─ SearchingPython Forensics
Searching a keyword from the message plays a vital role in forensics, when we search for
an evidence with the help of a keyword. The knowledge of what is to be searched in a
particular file along with the ones in deleted files requires both experience and knowledge.
Python has various built-in mechanisms with standard library modules to support search
operation. Fundamentally, investigators use the search operation to find answers to
questions such as "who", "what", "where", "when", etc.
Example
In the following example, we have declared two strings and then, we have used the find
function to check whether the first string contains the second string or not.
print str1.find(str2)
print str1.find(str2, 10)
print str1.find(str2, 40)
25
12. Python Forensics ─ Indexing Python Forensics
Indexing actually provides the investigator have a complete look at a file and gather
potential evidence from it. The evidence could be contained within a file, a disk image, a
memory snapshot, or a network trace.
Indexing helps in reducing time for time-consuming tasks such as keyword searching.
Forensic investigation also involves interactive searching phase, where the index is used
to rapidly locate keywords.
Example
The following example shows how you can use indexing in Python.
26
13. Python Forensics ─ Python Imaging Library
Python Forensics
Extracting valuable information from the resources available is a vital part of digital
forensics. Getting access to all the information available is essential for an investigation
process as it helps in retrieving appropriate evidence.
Resources that contain data can be either simple data structures such as databases or
complex data structures such as a JPEG image. Simple data structures can be easily
accessed using simple desktop tools, while extracting information from complex data
structures require sophisticated programming tools.
The following illustration shows the complete flow diagram of extracting data from images
(complex data structures) in PIL.
27
Python Forensics
Example
Now, let’s have a programming example to understand how it actually works.
Step 1: Suppose we have the following image from where we need to extract information.
Step 2: When we open this image using PIL, it will first note the necessary points required
for extracting evidence, which includes various pixel values. Here is the code to open the
image and record its pixel values:
Step 3: Our code will produce the following output, after extracting the pixel values of the image.
The output delivered represents the pixel values of RGB combination, which gives a better picture
of what data is needed for evidence. The data fetched is represented in the form of an array.
28
14. Python Forensics ─ Mobile Forensics
Python Forensics
Forensic investigation and analysis of standard computer hardware such as hard disks
have developed into a stable discipline and is followed with the help of techniques to
analyze non-standard hardware or transient evidence.
Although smartphones are increasingly being used in digital investigations, they are still
considered as non-standard.
Forensic Analysis
Forensic investigations search for data such as received calls or dialed numbers from the
smartphone. It can include text messages, photos, or any other incriminating evidence. Most
smartphones have screen-locking features using passwords or alphanumeric characters.
Here, we will take an example to show how Python can help crack the screen-locking
password to retrieve data from a smartphone.
Manual Examination
Android supports password lock with PIN number or alphanumeric password. The limit of
both passphrases are required to be between 4 and 16 digits or characters. The password
of a smartphone is stored in the Android system in a special file called password.key in
/data/system.
It is not feasible to crack the password with the help of dictionary attack as the hashed
password is stored in a salt file. This salt is a string of hexadecimal representation of a random
integer of 64 bit. It is easy to access the salt by using Rooted Smartphone or JTAG Adapter.
29
Python Forensics
Rooted Smartphone
The dump of the file /data/system/password.key is stored in SQLite database under
the lockscreen.password_salt key. Under settings.db, the password is stored and the
value is clearly visible in the following screenshot.
JTAG Adapter
A special hardware known as JTAG (Joint Test Action Group) adapter can be used to access
the salt. Similarly, a Riff-Box or a JIG-Adapter can also be used for the same
functionality.
Using the information obtained from Riff-box, we can find the position of the encrypted
data, i.e., the salt. Following are the rules:
The byte represents the actual width of the salt, which is its length.
This is the length which is actually searched for to get the stored password/pin of
the smartphones.
30
15. Python Forensics ─ Network Time Protocol
Python Forensics
The most widely used protocol for synchronizing time and which has been widely accepted
as a practice is done through Network Time Protocol (NTP).
NTP uses the User Datagram Protocol (UDP) which uses minimum time to communicate
the packets between the server and the client who wish to synchronize with the given time
source.
The NTP protocol standard is governed by the IETF and the Proposed Standard is
RFC 5905, titled “Network Time Protocol Version 4: Protocol and Algorithms
Specification” [NTP RFC]
In this chapter, we will focus on the usage of NTP with Python, which is feasible from third-
party Python Library ntplib. This library efficiently handles the heavy lifting, which
compares the results to my local system clock.
31
Python Forensics
The library provides a simple interface to NTP servers with the help of methods that can
translate NTP protocol fields. This helps access other key values such as leap seconds.
import ntplib
import time
NIST='nist1-macon.macon.ga.us'
ntp=ntplib.NTPClient()
ntpResponse=ntp.request(NIST)
if (ntpResponse):
now=time.time()
diff=now-ntpResponse.tx_time
print diff;
32
Python Forensics
The difference in time is calculated in the above program. These calculations help in
forensic investigations. The network data obtained is fundamentally different than the
analysis of data found on the hard drive.
The difference in time zones or getting accurate time zones can help in gathering evidence
for capturing the messages through this protocol.
33
16. Python Forensics ─ Multiprocessing Support
Python Forensics
Forensic specialists normally find it difficult to apply digital solutions to analyze the
mountains of digital evidence in common crimes. Most digital investigation tools are single
threaded and they can execute only one command at a time.
In this chapter, we will focus on the multiprocessing capabilities of Python, which can
relate to the common forensic challenges.
Multiprocessing
Multiprocessing is defined as the computer system's ability to support more than one
process. The operating systems that support multiprocessing enable several programs to
run concurrently.
Example
The following code shows how different processes are listed internally in Python programming.
import random
import multiprocessing
if __name__ == "__main__":
size = 999
procs = 2
34
Python Forensics
Here, the function list_append() helps in listing the set of processes in the system.
Output
Our code will produce the following output:
35
17. Python Forensics ─ Memory & Forensics
Python Forensics
In this chapter, we will focus on investigating the volatile memory with the help of
Volatility, a Python-based forensics framework applicable on the following platforms:
Android and Linux.
Volatile Memory
Volatile memory is a type of storage where the contents get erased when the system's
power is turned off or interrupted. RAM is the best example of a volatile memory. It means,
if you were working on a document that has not been saved to a non-volatile memory,
such as a hard drive, and the computer lost power, then all the data will be lost.
In general, volatile memory forensics follow the same pattern as other forensic
investigations:
The basic volatility plugins which are used for Android gathers RAM dump for analysis.
Once the RAM dump is gathered for analysis, it is important to start hunting for malware
in RAM.
YARA Rules
YARA is a popular tool which provides a robust language, is compatible with Perl-based
Regular Expressions, and is used to examine the suspected files/directories and match
strings.
In this section, we will use YARA based on the pattern matching implementation and
combine them with utility power. The complete process will be beneficial for forensic
analysis.
Example
Consider the following code. This code helps in extracting the code.
import operator
import os
import sys
sys.path.insert(0, os.getcwd())
import plyara.interp as interp
# Plyara is a script that lexes and parses a file consisting of one more Yara
rules into a python dictionary representation.
36
Python Forensics
if __name__ == '__main__':
file_to_analyze = sys.argv[1]
rulesDict = interp.parseString(open(file_to_analyze).read())
authors = {}
imps = {}
meta_keys = {}
max_strings = []
max_string_len = 0
tags = {}
rule_count = 0
# Imports
if 'imports' in rule:
for imp in rule['imports']:
imp = imp.replace('"','')
if imp in imps:
imps[imp] += 1
else:
imps[imp] = 1
# Tags
if 'tags' in rule:
for tag in rule['tags']:
if tag in tags:
tags[tag] += 1
else:
tags[tag] = 1
# Metadata
if 'metadata' in rule:
for key in rule['metadata']:
if key in meta_keys:
meta_keys[key] += 1
37
Python Forensics
else:
meta_keys[key] = 1
if key in ['Author', 'author']:
if rule['metadata'][key] in authors:
authors[rule['metadata'][key]] += 1
else:
authors[rule['metadata'][key]] = 1
#Strings
if 'strings' in rule:
for strr in rule['strings']:
if len(strr['value']) > max_string_len:
max_string_len = len(strr['value'])
max_strings = [(rule['rule_name'], strr['name'], strr['value'])]
elif len(strr['value']) == max_string_len:
max_strings.append((rule['rule_name'], strr['key'], strr['value']))
The number of YARA rules implemented helps in giving a better picture of the suspected
files. Indirectly, the list of suspected files help in gathering appropriate information for
forensics.
38
18. Python Forensics ─ Forensics in Linux
Python Forensics
The major concern of digital investigations is to secure important evidences or data with
encryption or any other format. The basic example is storing the passwords. It is therefore
necessary to understand the usage of Linux operating system for digital forensic
implementation to secure these valuable data.
Information for all the local users are mostly stored in the following two files:
/etc/passwd
etc/shadow
The first one is mandatory, which stores all the passwords. The second file is optional and
it stores information about the local users including the hashed passwords.
Issues arise regarding the security issue of storing the password information in a file,
which is readable by every user. Therefore, hashed passwords are stored in
/etc/passwd, where the content is replaced by a special value "x".
Both the text files in Linux include one entry per line and the entry consists of multiple
fields, separated by colons.
Field
Description
Name
If the hash password is saved as empty, then the corresponding user will not require any
password to log into the system. If this field contains a value that cannot be generated by
the hash algorithm, such as an exclamation mark, then the user cannot log on using a
password.
A user with a locked password can still log on using other authentication mechanisms, for
example, SSH keys. As mentioned earlier, the special value "x" means that the password
hash has to be found in the shadow file.
Encrypted salt: The encrypted salt helps maintain the screen locks, pins, and
passwords.
Numerical user ID: This field denotes the ID of the user. The Linux kernel assigns
this user ID to the system.
39
Python Forensics
Numerical group ID: This field refers to the primary group of the user.
Home directory: The new processes are started with a reference of this directory.
Command shell: This optional field denotes the default shell that is to be started
after a successful login to the system.
Using Python, all of this information can be automatically analyzed for the Indicators of
Analysis, reconstructing the recent system activity. Tracking is simple and easy with the
implementation of Linux Shell.
def main(argv):
print '\nUser & Password Storage Program in Linux for forensic detection v.01\n'
try:
file_conn = open(sys.argv[1],'w')
file_conn.write(user_name + '\n')
file_conn.write(password + '\n')
file_conn.close()
except:
sys.exit('There was a problem writing the passwords to file!')
if __name__ == "__main__":
main(sys.argv[1:])
40
Python Forensics
Output
The password is stored in a hexadecimal format in pass_db.txt as shown in the following
screenshot. The text files are saved for further use in computational forensics.
41
19. Python Forensics ─ Indicators of Compromise
Python Forensics
Indicators of Compromise (IOC) is defined as "pieces of forensic data, which includes data
found in system log entries or files, that identify potentially malicious activity on a system
or network."
By monitoring for IOC, organizations can detect attacks and act quickly to prevent such
breaches from occurring or limit damages by stopping attacks in earlier stages.
There are some use-cases, which allow querying the forensic artifacts such as:
The combination of all the above provides better results in searching artifacts. As
mentioned above, Windows registry gives a perfect platform in generating and maintaining
IOC, which directly helps in computational forensics.
Methodology
Look for the locations in the file system and specifically for now into Windows
registry.
Search for the set of artifacts, which have been designed by forensic tools.
Look for the signs of any adverse activities.
Stage 2: Create IOCs for Host & Network ─ Following the data collected, the
IOC is created, which is easily possible with Windows registry. The flexibility of
OpenIOC gives limitless number of permutations on how an Indicator can be
crafted.
Stage 3: Deploy IOCs in the Enterprise ─ Once the specified IOC has been
created, the investigator will deploy these technologies with the help of API in
Windows registers.
Stage 5: Collect and Analyze Evidence ─ Evidences against the suspects are
gathered and analyzed accordingly.
42
Python Forensics
Stage 6: Refine & Create New IOCs ─ The investigative team can create new
IOCs based of their evidences and data found in the enterprise and additional
intelligence, and continue to refine their cycle.
43
20. Python Forensics ─ Implementation of Cloud
Python Forensics
Cloud computing can be defined as a collection of hosted services provided to users over
the Internet. It enables organizations to consume or even compute the resource, which
includes Virtual Machines (VMs), storage, or an application as a utility.
One of the interesting perspectives is creating a cloud base with the generation of
Rainbow tables. It helps in integrating single and multiprocessing versions of the
application, which requires some considerations.
Pi Cloud
Pi Cloud is the cloud computing platform, which integrates Python programming language
with the computing power of Amazon Web Services.
Rainbow Tables
A rainbow table is defined as a listing of all possible plain text permutations of encrypted
passwords specific to a given hash algorithm.
Rainbow tables follow a standard pattern, which creates a list of hashed passwords.
A text file is used to generate passwords, which include characters or plain text of
passwords to be encrypted.
The file is used by Pi cloud, which calls the main function to be stored.
This algorithm can be used to save passwords in the database as well and have a backup
storage in the cloud system.
44
Python Forensics
The following in-built program creates a list of encrypted passwords in a text file.
import os
import random
import hashlib
import string
import enchant #Rainbow tables with enchant
import cloud #importing pi-cloud
def randomword(length):
return ''.join(random.choice(string.lowercase) for i in range(length))
while True:
randomword0 = randomword(6)
if engdict.check(randomword0) == True:
randomkey0 = randomword0+str(random.randint(0,99))
elif engdict.check(randomword0) == False:
englist = engdict.suggest(randomword0)
if len(englist) > 0:
randomkey0 = englist[0]+str(random.randint(0,99))
else:
randomkey0 = randomword0+str(random.randint(0,99))
randomword3 = randomword(5)
if engdict.check(randomword3) == True:
randomkey3 = randomword3+str(random.randint(0,99))
elif engdict.check(randomword3) == False:
englist = engdict.suggest(randomword3)
if len(englist) > 0:
randomkey3 = englist[0]+str(random.randint(0,99))
else:
randomkey3 = randomword3+str(random.randint(0,99))
45
Python Forensics
Output
This code will produce the following output:
46
Python Forensics
The passwords are stored in the text files, which is visible, as shown in the following
screenshot.
47